diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2019-01-17 15:53:16 -0600 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2019-01-17 16:53:16 -0500 |
commit | 62e22a5fb9d3e093f44b4075c7ddb5807d66409b (patch) | |
tree | d8b001ebeb9d26c731c14a441933b0045fd35f6a /tests/hazmat/primitives/test_hkdf.py | |
parent | 7f63e5b65d14dca6c4783d62fa5937a5a5c705e7 (diff) | |
download | cryptography-62e22a5fb9d3e093f44b4075c7ddb5807d66409b.tar.gz cryptography-62e22a5fb9d3e093f44b4075c7ddb5807d66409b.tar.bz2 cryptography-62e22a5fb9d3e093f44b4075c7ddb5807d66409b.zip |
Support byteslike in HKDF and PBKDF2HMAC (#4707)
* support byteslike in HKDF
* support byteslike in PBKDF2HMAC
* add missing docs
Diffstat (limited to 'tests/hazmat/primitives/test_hkdf.py')
-rw-r--r-- | tests/hazmat/primitives/test_hkdf.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_hkdf.py b/tests/hazmat/primitives/test_hkdf.py index 5d2d1867..195bfb3a 100644 --- a/tests/hazmat/primitives/test_hkdf.py +++ b/tests/hazmat/primitives/test_hkdf.py @@ -171,6 +171,21 @@ class TestHKDF(object): assert hkdf.derive(ikm) == binascii.unhexlify(vector["okm"]) + def test_buffer_protocol(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 = bytearray(binascii.unhexlify(vector["ikm"])) + + assert hkdf.derive(ikm) == binascii.unhexlify(vector["okm"]) + @pytest.mark.requires_backend_interface(interface=HMACBackend) class TestHKDFExpand(object): @@ -187,6 +202,19 @@ class TestHKDFExpand(object): assert binascii.hexlify(hkdf.derive(prk)) == okm + def test_buffer_protocol(self, backend): + prk = bytearray(binascii.unhexlify( + b"077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5" + )) + + okm = (b"3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c" + b"5bf34007208d5b887185865") + + info = binascii.unhexlify(b"f0f1f2f3f4f5f6f7f8f9") + hkdf = HKDFExpand(hashes.SHA256(), 42, info, backend) + + assert binascii.hexlify(hkdf.derive(prk)) == okm + def test_verify(self, backend): prk = binascii.unhexlify( b"077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5" |