File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
src/cryptography/hazmat/primitives/kdf Expand file tree Collapse file tree 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):
91
91
output = [b"" ]
92
92
counter = 1
93
93
94
- while ( self ._algorithm .digest_size // 8 ) * len (output ) < self ._length :
94
+ while self ._algorithm .digest_size * ( len (output ) - 1 ) < self ._length :
95
95
h = hmac .HMAC (key_material , self ._algorithm , backend = self ._backend )
96
96
h .update (output [- 1 ])
97
97
h .update (self ._info )
Original file line number Diff line number Diff line change @@ -142,6 +142,17 @@ def test_unicode_typeerror(self, backend):
142
142
143
143
hkdf .verify (b"foo" , u"bar" )
144
144
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
+
145
156
146
157
@pytest .mark .requires_backend_interface (interface = HMACBackend )
147
158
class TestHKDFExpand (object ):
You can’t perform that action at this time.
0 commit comments