aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/utils.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-27 21:04:03 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-28 11:18:26 -0600
commit1050ddf44f0713a587cd0ba239e23c95064a39bc (patch)
tree336c1329b82370fda3050b8c787ed8a85d32dc1b /tests/hazmat/primitives/utils.py
parent1f8cd620cfbb854b0dfcdbf89c140160a8caba13 (diff)
downloadcryptography-1050ddf44f0713a587cd0ba239e23c95064a39bc.tar.gz
cryptography-1050ddf44f0713a587cd0ba239e23c95064a39bc.tar.bz2
cryptography-1050ddf44f0713a587cd0ba239e23c95064a39bc.zip
PBKDF2 support for OpenSSL backend
Diffstat (limited to 'tests/hazmat/primitives/utils.py')
-rw-r--r--tests/hazmat/primitives/utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py
index f27afe41..3a1d6d88 100644
--- a/tests/hazmat/primitives/utils.py
+++ b/tests/hazmat/primitives/utils.py
@@ -4,6 +4,7 @@ import os
import pytest
from cryptography.hazmat.primitives import hashes, hmac
+from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2
from cryptography.hazmat.primitives.ciphers import Cipher
from cryptography.exceptions import (
AlreadyFinalized, NotYetFinalized, AlreadyUpdated, InvalidTag,
@@ -211,6 +212,30 @@ def hmac_test(backend, algorithm, params):
assert h.finalize() == binascii.unhexlify(md.encode("ascii"))
+def generate_pbkdf2_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_pbkdf2(self, backend, params):
+ pbkdf2_test(backend, algorithm, params)
+ return test_pbkdf2
+
+
+def pbkdf2_test(backend, algorithm, params):
+ # Password and salt can contain \0, which should be loaded as a null char.
+ # The NIST loader loads them as literal strings so we replace with the
+ # proper value.
+ kdf = PBKDF2(
+ algorithm,
+ int(params["length"]),
+ params["salt"],
+ int(params["iterations"]),
+ backend
+ )
+ derived_key = kdf.derive(params["password"])
+ assert binascii.hexlify(derived_key) == params["derived_key"]
+
+
def generate_aead_exception_test(cipher_factory, mode_factory):
def test_aead_exception(self, backend):
aead_exception_test(backend, cipher_factory, mode_factory)