Closed wilko77 closed 6 years ago
Thanks for the report. This is indeed a bug. We should allow longer output lengths. As for salt, that is a bug as well, but (fortuitously) is benign. An explanation:
None
salt case so we knew it was generating proper answers -- how could it be wrong?So we passed too few null bytes and OpenSSL obligingly (and in accordance with the spec) padded it out to the correct number of null bytes, thus making the call return the correct value despite the wrong input. (We will still fix it though!)
A PR will be forthcoming.
I think the computation of
max_length
insrc/cryptography/hazmat/primitives/kdf/hkdf.py
is wrong.RFC5869 states on page 3 that the input
L
of the HKDF-Expand function describes the "length of output keying material in octets (<= 255*HashLen)". An octet consists of 8 bit.Currently,
max_length
is computed as:The problem is, that
algorithm.digest_size
returns the size of the digest in bytes. (There are 8 bits per byte). Therefore, the division by 8 is wrong, and thus,max_length
is unnecessarily small.(same applies for the computation of
salt
as well (line 33), in the case wheresalt is None
)