File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
src/cryptography/hazmat/primitives/kdf Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -78,8 +78,9 @@ def _expand(self, key_material: utils.Buffer) -> bytes:
78
78
output = [b"" ]
79
79
counter = 1
80
80
81
+ h_prime = hmac .HMAC (key_material , self ._algorithm )
81
82
while self ._algorithm .digest_size * (len (output ) - 1 ) < self ._length :
82
- h = hmac . HMAC ( key_material , self . _algorithm )
83
+ h = h_prime . copy ( )
83
84
h .update (output [- 1 ])
84
85
h .update (self ._info )
85
86
h .update (bytes ([counter ]))
Original file line number Diff line number Diff line change
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from cryptography .hazmat .primitives import hashes
6
+ from cryptography .hazmat .primitives .kdf .hkdf import HKDF
7
+
8
+
9
+ def test_hkdf (benchmark ):
10
+ def bench ():
11
+ hkdf = HKDF (
12
+ hashes .SHA512 (),
13
+ 16000 ,
14
+ salt = b"salt" ,
15
+ info = b"info" ,
16
+ )
17
+ hkdf .derive (b"0" * 64 )
18
+
19
+ benchmark (bench )
You can’t perform that action at this time.
0 commit comments