From 4f77bb87f2da3ba37aab623dae2ab03480a05870 Mon Sep 17 00:00:00 2001 From: Julien Rische Date: Wed, 15 Nov 2023 16:14:59 +0100 Subject: [PATCH] Allow label for SP800_108_Counter to include null bytes --- lib/Crypto/Protocol/KDF.py | 3 --- lib/Crypto/SelfTest/Protocol/test_KDF.py | 6 ++++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Crypto/Protocol/KDF.py b/lib/Crypto/Protocol/KDF.py index afc581eb..202339fb 100644 --- a/lib/Crypto/Protocol/KDF.py +++ b/lib/Crypto/Protocol/KDF.py @@ -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") diff --git a/lib/Crypto/SelfTest/Protocol/test_KDF.py b/lib/Crypto/SelfTest/Protocol/test_KDF.py index 55dd19e2..8d736456 100644 --- a/lib/Crypto/SelfTest/Protocol/test_KDF.py +++ b/lib/Crypto/SelfTest/Protocol/test_KDF.py @@ -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')