Clean up HashAlgorithm a bit.

This commit is contained in:
Coda Hale 2013-08-28 06:30:52 -07:00
parent 305d16d1de
commit da59853aa3
3 changed files with 8 additions and 9 deletions

View file

@ -230,7 +230,10 @@ func TestDSASignatures(t *testing.T) {
func testDsaFixture(f *dsaFixture, t *testing.T) {
t.Logf("Testing %s", f.name)
digest := f.alg.digest([]byte(f.message))
h := f.alg()
h.Write([]byte(f.message))
digest := h.Sum(nil)
g := f.key.subgroup / 8
if len(digest) > g {
digest = digest[0:g]

View file

@ -416,7 +416,10 @@ func ecdsaLoadInt(s string) (n *big.Int) {
func testEcsaFixture(f *ecdsaFixture, t *testing.T) {
t.Logf("Testing %s", f.name)
digest := f.alg.digest([]byte(f.message))
h := f.alg()
h.Write([]byte(f.message))
digest := h.Sum(nil)
g := f.key.subgroup / 8
if len(digest) > g {
digest = digest[0:g]

View file

@ -27,13 +27,6 @@ import (
// A function which provides a fresh Hash (e.g., sha256.New).
type HashAlgorithm func() hash.Hash
// digest returns a digest of the given message.
func (alg HashAlgorithm) digest(m []byte) []byte {
h := alg()
h.Write(m)
return h.Sum(nil)
}
// mac returns an HMAC of the given key and message.
func (alg HashAlgorithm) mac(k []byte, m []byte) []byte {
h := hmac.New(alg, k)