aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/utils.py
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2014-01-20 16:05:53 -0800
committerDavid Reid <dreid@dreid.org>2014-02-03 10:05:26 -0800
commit66c9cd928601725e27aa64255e56b3a7e481a08d (patch)
tree2d746623c5bdb603d62ec28a3a765a5b9fd4d20d /tests/hazmat/primitives/utils.py
parentab33266b16d9a1cd3cf6abcf0a7b80e86f915d95 (diff)
downloadcryptography-66c9cd928601725e27aa64255e56b3a7e481a08d.tar.gz
cryptography-66c9cd928601725e27aa64255e56b3a7e481a08d.tar.bz2
cryptography-66c9cd928601725e27aa64255e56b3a7e481a08d.zip
Refactor HKDF support and provide vectors for tests.
Diffstat (limited to 'tests/hazmat/primitives/utils.py')
-rw-r--r--tests/hazmat/primitives/utils.py31
1 files changed, 31 insertions, 0 deletions
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