From 5b6118e7f2945de32c4d21723797cdc1b04c3983 Mon Sep 17 00:00:00 2001 From: Luke Champine Date: Mon, 30 Mar 2020 10:57:36 -0400 Subject: [PATCH] ecies: Fix reps calculation NIST SP 800-56 specifies that reps should equal: ceil(keydatalen / hashlen) where hashlen is the length, in bits, of the output block of the hash function. In the hash.Hash interface, this value is given by Size() * 8, not BlockSize() * 8. (BlockSize is a confusingly-named method that relates to hash *input*, not output.) --- crypto/ecies/ecies.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crypto/ecies/ecies.go b/crypto/ecies/ecies.go index 1474181482..7df3d2618a 100644 --- a/crypto/ecies/ecies.go +++ b/crypto/ecies/ecies.go @@ -169,9 +169,8 @@ func concatKDF(hash hash.Hash, z, s1 []byte, kdLen int) (k []byte, err error) { s1 = make([]byte, 0) } - reps := ((kdLen + 7) * 8) / (hash.BlockSize() * 8) + reps := ((kdLen + 7) * 8) / (hash.Size() * 8) if big.NewInt(int64(reps)).Cmp(big2To32M1) > 0 { - fmt.Println(big2To32M1) return nil, ErrKeyDataTooLong }