Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/Crypto/Protocol/KDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,10 @@ def SP800_108_Counter(master, key_len, prf, num_keys=None, label=b'', context=b'
By default, only 1 key is derived.
label (byte string):
Optional description of the purpose of the derived keys.
It must not contain zero bytes.
context (byte string):
Optional information pertaining to
the protocol that uses the keys, such as the identity of the
participants, nonces, session IDs, etc.
It must not contain zero bytes.

Return:
- a byte string (if ``num_keys`` is not specified), or
Expand All @@ -624,9 +622,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 context.find(b'\x00') != -1:
raise ValueError("Null byte found in context")

key_len_enc = long_to_bytes(key_len * num_keys * 8, 4)
output_len = key_len * num_keys

Expand Down
8 changes: 5 additions & 3 deletions lib/Crypto/SelfTest/Protocol/test_KDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,16 +716,18 @@ def load_hash_by_name(hash_name):

class SP800_108_Counter_Tests(unittest.TestCase):

def test_negative_zeroes(self):
def test_zeroes(self):
def prf(s, x):
return HMAC.new(s, x, SHA256).digest()

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')
try:
_ = SP800_108_Counter(b'0' * 16, 1, prf, context=b'A\x00B')
except ValueError:
self.fail('SP800_108_Counter failed with zero in context')

def test_multiple_keys(self):
def prf(s, x):
Expand Down
Loading