]> Cypherpunks repositories - gostls13.git/commitdiff
toss crypto/block Digest in favor of hash.Hash
authorRuss Cox <rsc@golang.org>
Wed, 14 Oct 2009 16:33:15 +0000 (09:33 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 14 Oct 2009 16:33:15 +0000 (09:33 -0700)
R=r
DELTA=30  (8 added, 15 deleted, 7 changed)
OCL=35677
CL=35713

src/pkg/Make.deps
src/pkg/crypto/block/cipher.go
src/pkg/crypto/block/cmac.go
src/pkg/crypto/block/eax.go

index 99c97552321c97cc9468a50664ed2a2c174a5a0d..19942a9d99ba5bf51bb313cb0841513f437cf612 100644 (file)
@@ -13,7 +13,7 @@ container/list.install:
 container/ring.install:
 container/vector.install:
 crypto/aes.install: os.install strconv.install
-crypto/block.install: fmt.install io.install os.install strconv.install
+crypto/block.install: fmt.install hash.install io.install os.install strconv.install
 crypto/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install
 crypto/md5.install: hash.install os.install
 crypto/rc4.install: os.install strconv.install
index ed6db02f7b1cc11539e62a78b20d6b11a276e595..8bff1b87820e8769df8ea0b1ba7db87bb00ec534 100644 (file)
@@ -8,8 +8,6 @@
 // and NIST Special Publication 800-38A.
 package block
 
-import "io"
-
 // A Cipher represents an implementation of block cipher
 // using a given key.  It provides the capability to encrypt
 // or decrypt individual blocks.  The mode implementations
@@ -27,19 +25,6 @@ type Cipher interface {
        Decrypt(src, dst []byte);
 }
 
-// TODO(rsc): Digest belongs elsewhere.
-
-// A Digest is an implementation of a message digest algorithm.
-// Write data to it and then call Sum to retreive the digest.
-// Calling Reset resets the internal state, as though no data has
-// been written.
-type Digest interface {
-       io.Writer;
-       Sum() []byte;
-       Reset();
-}
-
-
 // Utility routines
 
 func shift1(src, dst []byte) byte {
index ff8d0b0fbe2adf1d10178ecf19523c716272d641..667dc7b3e5085dc9bbd1a0ecbea8687ad54652b5 100644 (file)
@@ -7,7 +7,10 @@
 
 package block
 
-import "os"
+import (
+       "hash";
+       "os";
+)
 
 const (
        // minimal irreducible polynomial of degree b
@@ -25,7 +28,7 @@ type cmac struct {
 
 // NewCMAC returns a new instance of a CMAC message authentication code
 // digest using the given Cipher.
-func NewCMAC(c Cipher) Digest {
+func NewCMAC(c Cipher) hash.Hash {
        var r byte;
        n := c.BlockSize();
        switch n {
@@ -98,3 +101,7 @@ func (d *cmac) Sum() []byte {
        d.c.Encrypt(d.digest, d.digest);
        return d.digest;
 }
+
+func (d *cmac) Size() int {
+       return len(d.digest);
+}
index e6dc39195c149f0f808a64889c5f26f9c91eaa4f..3992ea8f7a763a97339bacfec90c43075c403e9e 100644 (file)
@@ -16,6 +16,7 @@ package block
 
 import (
        "fmt";
+       "hash";
        "io";
        "os";
 )
@@ -32,7 +33,7 @@ func (e *EAXTagError) String() string {
        return fmt.Sprintf("crypto/block: EAX tag mismatch: read %x but computed %x", e.Read, e.Computed);
 }
 
-func setupEAX(c Cipher, iv, hdr []byte, tagBytes int) (ctrIV, tag []byte, cmac Digest) {
+func setupEAX(c Cipher, iv, hdr []byte, tagBytes int) (ctrIV, tag []byte, cmac hash.Hash) {
        n := len(iv);
        if n != c.BlockSize() {
                panicln("crypto/block: EAX: iv length", n, "!=", c.BlockSize());
@@ -63,7 +64,7 @@ func setupEAX(c Cipher, iv, hdr []byte, tagBytes int) (ctrIV, tag []byte, cmac D
        return;
 }
 
-func finishEAX(tag []byte, cmac Digest) {
+func finishEAX(tag []byte, cmac hash.Hash) {
        // Finish CMAC #2 and xor into tag.
        sum := cmac.Sum();
        for i := range tag {
@@ -75,7 +76,7 @@ func finishEAX(tag []byte, cmac Digest) {
 // Knows that cmac never returns write errors.
 type cmacWriter struct {
        w       io.Writer;
-       cmac    Digest;
+       cmac    hash.Hash;
 }
 
 func (cw *cmacWriter) Write(p []byte) (n int, err os.Error) {
@@ -133,7 +134,7 @@ func (x *eaxEncrypter) Close() os.Error {
 // but the latter half is trivial.
 type cmacReader struct {
        r       io.Reader;
-       cmac    Digest;
+       cmac    hash.Hash;
        tag     []byte;
        tmp     []byte;
 }