Skip to content

Commit

Permalink
Allow label for SP800_108_Counter to include null bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrisc authored and Legrandin committed Aug 18, 2024
1 parent e76a488 commit 4f77bb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 0 additions & 3 deletions lib/Crypto/Protocol/KDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,6 @@ def SP800_108_Counter(master, key_len, prf, num_keys=None, label=b'', context=b'
if num_keys is None:
num_keys = 1

if label.find(b'\x00') != -1:
raise ValueError("Null byte found in label")

if context.find(b'\x00') != -1:
raise ValueError("Null byte found in context")

Expand Down
6 changes: 4 additions & 2 deletions lib/Crypto/SelfTest/Protocol/test_KDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,10 @@ def test_negative_zeroes(self):
def prf(s, x):
return HMAC.new(s, x, SHA256).digest()

self.assertRaises(ValueError, SP800_108_Counter, b'0' * 16, 1, prf,
label=b'A\x00B')
try:
_ = SP800_108_Counter(b'0' * 16, 1, prf, label=b'A\x00B')
except ValueError:
self.fail('SP800_108_Counter failed with zero in label')
self.assertRaises(ValueError, SP800_108_Counter, b'0' * 16, 1, prf,
context=b'A\x00B')

Expand Down

0 comments on commit 4f77bb8

Please sign in to comment.