aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2018-01-06 17:55:27 -0600
committerAlex Gaynor <alex.gaynor@gmail.com>2018-01-06 18:55:27 -0500
commit858a429d88c7e35ecd224a98bfda2c3dd428ae1f (patch)
treea0770fc5150d2b9918a5b99b94c146051dc9ab1e /tests
parent323f2ad66befb13ec3b31b5ab99c9448b9a6b067 (diff)
downloadcryptography-858a429d88c7e35ecd224a98bfda2c3dd428ae1f.tar.gz
cryptography-858a429d88c7e35ecd224a98bfda2c3dd428ae1f.tar.bz2
cryptography-858a429d88c7e35ecd224a98bfda2c3dd428ae1f.zip
The HKDF limit is actually 255 * digest_length_in_bytes (#4037)
* The HKDF limit is actually 255 * digest_length_in_bytes Previously we had a bug where we divided digest_size by 8...but HashAlgorithm.digest_size is already in bytes. * test longer output * changelog
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_hkdf.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/hazmat/primitives/test_hkdf.py b/tests/hazmat/primitives/test_hkdf.py
index a05fd752..5d2d1867 100644
--- a/tests/hazmat/primitives/test_hkdf.py
+++ b/tests/hazmat/primitives/test_hkdf.py
@@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function
import binascii
+import os
import pytest
@@ -15,13 +16,15 @@ from cryptography.hazmat.backends.interfaces import HMACBackend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.hkdf import HKDF, HKDFExpand
-from ...utils import raises_unsupported_algorithm
+from ...utils import (
+ load_nist_vectors, load_vectors_from_file, raises_unsupported_algorithm
+)
@pytest.mark.requires_backend_interface(interface=HMACBackend)
class TestHKDF(object):
def test_length_limit(self, backend):
- big_length = 255 * (hashes.SHA256().digest_size // 8) + 1
+ big_length = 255 * hashes.SHA256().digest_size + 1
with pytest.raises(ValueError):
HKDF(
@@ -153,6 +156,21 @@ class TestHKDF(object):
assert hkdf.derive(b"\x01" * 16) == b"gJ\xfb{"
+ def test_derive_long_output(self, backend):
+ vector = load_vectors_from_file(
+ os.path.join("KDF", "hkdf-generated.txt"), load_nist_vectors
+ )[0]
+ hkdf = HKDF(
+ hashes.SHA256(),
+ int(vector["l"]),
+ salt=vector["salt"],
+ info=vector["info"],
+ backend=backend
+ )
+ ikm = binascii.unhexlify(vector["ikm"])
+
+ assert hkdf.derive(ikm) == binascii.unhexlify(vector["okm"])
+
@pytest.mark.requires_backend_interface(interface=HMACBackend)
class TestHKDFExpand(object):