File tree 2 files changed +12
-1
lines changed
src/cryptography/hazmat/primitives/kdf
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ def _expand(self, key_material):
9191 output = [b"" ]
9292 counter = 1
9393
94- while ( self ._algorithm .digest_size // 8 ) * len (output ) < self ._length :
94+ while self ._algorithm .digest_size * ( len (output ) - 1 ) < self ._length :
9595 h = hmac .HMAC (key_material , self ._algorithm , backend = self ._backend )
9696 h .update (output [- 1 ])
9797 h .update (self ._info )
Original file line number Diff line number Diff line change @@ -142,6 +142,17 @@ def test_unicode_typeerror(self, backend):
142142
143143 hkdf .verify (b"foo" , u"bar" )
144144
145+ def test_derive_short_output (self , backend ):
146+ hkdf = HKDF (
147+ hashes .SHA256 (),
148+ 4 ,
149+ salt = None ,
150+ info = None ,
151+ backend = backend
152+ )
153+
154+ assert hkdf .derive (b"\x01 " * 16 ) == b"gJ\xfb {"
155+
145156
146157@pytest .mark .requires_backend_interface (interface = HMACBackend )
147158class TestHKDFExpand (object ):
You can’t perform that action at this time.
0 commit comments