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.)
This commit is contained in:
Luke Champine 2020-03-30 10:57:36 -04:00 committed by GitHub
parent 84f4975520
commit 5b6118e7f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}