Skip to content
Permalink
Browse files

Fixes #3211 -- fixed hkdf's output with short length (#3215)

  • Loading branch information...
alex authored and reaperhulk committed Nov 6, 2016
1 parent 21ac453 commit b924696b2e8731f39696584d12cceeb3aeb2d874
Showing with 12 additions and 1 deletion.
  1. +1 −1 src/cryptography/hazmat/primitives/kdf/hkdf.py
  2. +11 −0 tests/hazmat/primitives/test_hkdf.py
@@ -91,7 +91,7 @@ def _expand(self, key_material):
output = [b""]
counter = 1

while (self._algorithm.digest_size // 8) * len(output) < self._length:
while self._algorithm.digest_size * (len(output) - 1) < self._length:
h = hmac.HMAC(key_material, self._algorithm, backend=self._backend)
h.update(output[-1])
h.update(self._info)
@@ -142,6 +142,17 @@ def test_unicode_typeerror(self, backend):

hkdf.verify(b"foo", u"bar")

def test_derive_short_output(self, backend):
hkdf = HKDF(
hashes.SHA256(),
4,
salt=None,
info=None,
backend=backend
)

assert hkdf.derive(b"\x01" * 16) == b"gJ\xfb{"


@pytest.mark.requires_backend_interface(interface=HMACBackend)
class TestHKDFExpand(object):

0 comments on commit b924696

Please sign in to comment.
You can’t perform that action at this time.