mirror of
https://github.com/golang/go
synced 2024-11-25 05:57:57 -07:00
toss crypto/block Digest in favor of hash.Hash
R=r DELTA=30 (8 added, 15 deleted, 7 changed) OCL=35677 CL=35713
This commit is contained in:
parent
f6d67c9e95
commit
b7ef541f35
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user