From 66c9cd928601725e27aa64255e56b3a7e481a08d Mon Sep 17 00:00:00 2001 From: David Reid Date: Mon, 20 Jan 2014 16:05:53 -0800 Subject: Refactor HKDF support and provide vectors for tests. --- tests/hazmat/primitives/utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/hazmat/primitives/utils.py') diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py index 6b1d055d..e546fa79 100644 --- a/tests/hazmat/primitives/utils.py +++ b/tests/hazmat/primitives/utils.py @@ -6,6 +6,8 @@ import pytest from cryptography.hazmat.primitives import hashes, hmac from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.primitives.ciphers import Cipher +from cryptography.hazmat.primitives.kdf.hkdf import hkdf_derive + from cryptography.exceptions import ( AlreadyFinalized, NotYetFinalized, AlreadyUpdated, InvalidTag, ) @@ -297,3 +299,32 @@ def aead_tag_exception_test(backend, cipher_factory, mode_factory): ) with pytest.raises(ValueError): cipher.encryptor() + + +def hkdf_test(backend, algorithm, params): + ikm = params[0] + salt = params[1] + info = params[2] + length = params[3] + expected_okm = params[4] + + okm = hkdf_derive( + binascii.unhexlify(ikm), + length, + binascii.unhexlify(salt), + binascii.unhexlify(info), + algorithm, + backend=backend + ) + + assert binascii.hexlify(okm) == expected_okm + + +def generate_hkdf_test(param_loader, path, file_names, algorithm): + all_params = _load_all_params(path, file_names, param_loader) + + @pytest.mark.parametrize("params", all_params) + def test_hkdf(self, backend, params): + hkdf_test(backend, algorithm, params) + + return test_hkdf -- cgit v1.2.3