Commit b7ef541f authored by Russ Cox's avatar Russ Cox

toss crypto/block Digest in favor of hash.Hash

R=r
DELTA=30  (8 added, 15 deleted, 7 changed)
OCL=35677
CL=35713
parent f6d67c9e
...@@ -13,7 +13,7 @@ container/list.install: ...@@ -13,7 +13,7 @@ container/list.install:
container/ring.install: container/ring.install:
container/vector.install: container/vector.install:
crypto/aes.install: os.install strconv.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/hmac.install: crypto/md5.install crypto/sha1.install hash.install os.install
crypto/md5.install: hash.install os.install crypto/md5.install: hash.install os.install
crypto/rc4.install: os.install strconv.install crypto/rc4.install: os.install strconv.install
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
// and NIST Special Publication 800-38A. // and NIST Special Publication 800-38A.
package block package block
import "io"
// A Cipher represents an implementation of block cipher // A Cipher represents an implementation of block cipher
// using a given key. It provides the capability to encrypt // using a given key. It provides the capability to encrypt
// or decrypt individual blocks. The mode implementations // or decrypt individual blocks. The mode implementations
...@@ -27,19 +25,6 @@ type Cipher interface { ...@@ -27,19 +25,6 @@ type Cipher interface {
Decrypt(src, dst []byte); 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 // Utility routines
func shift1(src, dst []byte) byte { func shift1(src, dst []byte) byte {
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
package block package block
import "os" import (
"hash";
"os";
)
const ( const (
// minimal irreducible polynomial of degree b // minimal irreducible polynomial of degree b
...@@ -25,7 +28,7 @@ type cmac struct { ...@@ -25,7 +28,7 @@ type cmac struct {
// NewCMAC returns a new instance of a CMAC message authentication code // NewCMAC returns a new instance of a CMAC message authentication code
// digest using the given Cipher. // digest using the given Cipher.
func NewCMAC(c Cipher) Digest { func NewCMAC(c Cipher) hash.Hash {
var r byte; var r byte;
n := c.BlockSize(); n := c.BlockSize();
switch n { switch n {
...@@ -98,3 +101,7 @@ func (d *cmac) Sum() []byte { ...@@ -98,3 +101,7 @@ func (d *cmac) Sum() []byte {
d.c.Encrypt(d.digest, d.digest); d.c.Encrypt(d.digest, d.digest);
return d.digest; return d.digest;
} }
func (d *cmac) Size() int {
return len(d.digest);
}
...@@ -16,6 +16,7 @@ package block ...@@ -16,6 +16,7 @@ package block
import ( import (
"fmt"; "fmt";
"hash";
"io"; "io";
"os"; "os";
) )
...@@ -32,7 +33,7 @@ func (e *EAXTagError) String() string { ...@@ -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); 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); n := len(iv);
if n != c.BlockSize() { if n != c.BlockSize() {
panicln("crypto/block: EAX: iv length", 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 ...@@ -63,7 +64,7 @@ func setupEAX(c Cipher, iv, hdr []byte, tagBytes int) (ctrIV, tag []byte, cmac D
return; return;
} }
func finishEAX(tag []byte, cmac Digest) { func finishEAX(tag []byte, cmac hash.Hash) {
// Finish CMAC #2 and xor into tag. // Finish CMAC #2 and xor into tag.
sum := cmac.Sum(); sum := cmac.Sum();
for i := range tag { for i := range tag {
...@@ -75,7 +76,7 @@ func finishEAX(tag []byte, cmac Digest) { ...@@ -75,7 +76,7 @@ func finishEAX(tag []byte, cmac Digest) {
// Knows that cmac never returns write errors. // Knows that cmac never returns write errors.
type cmacWriter struct { type cmacWriter struct {
w io.Writer; w io.Writer;
cmac Digest; cmac hash.Hash;
} }
func (cw *cmacWriter) Write(p []byte) (n int, err os.Error) { func (cw *cmacWriter) Write(p []byte) (n int, err os.Error) {
...@@ -133,7 +134,7 @@ func (x *eaxEncrypter) Close() os.Error { ...@@ -133,7 +134,7 @@ func (x *eaxEncrypter) Close() os.Error {
// but the latter half is trivial. // but the latter half is trivial.
type cmacReader struct { type cmacReader struct {
r io.Reader; r io.Reader;
cmac Digest; cmac hash.Hash;
tag []byte; tag []byte;
tmp []byte; tmp []byte;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment