From f3368079af75b14198eef065bd28588cbbdd30cf Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 26 Sep 2015 11:40:50 -0400 Subject: rename this file for consistency --- tests/hazmat/primitives/test_X963_vectors.py | 72 ---------------------------- tests/hazmat/primitives/test_x963_vectors.py | 72 ++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 tests/hazmat/primitives/test_X963_vectors.py create mode 100644 tests/hazmat/primitives/test_x963_vectors.py (limited to 'tests/hazmat') diff --git a/tests/hazmat/primitives/test_X963_vectors.py b/tests/hazmat/primitives/test_X963_vectors.py deleted file mode 100644 index 0332e601..00000000 --- a/tests/hazmat/primitives/test_X963_vectors.py +++ /dev/null @@ -1,72 +0,0 @@ -# This file is dual licensed under the terms of the Apache License, Version -# 2.0, and the BSD License. See the LICENSE file in the root of this repository -# for complete details. - -from __future__ import absolute_import, division, print_function - -import binascii -import os - -import pytest - -from cryptography import utils -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.backends.interfaces import HashBackend -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF - -from ...utils import load_vectors_from_file, load_x963_vectors - - -@utils.register_interface(hashes.HashAlgorithm) -class UnsupportedDummyHash(object): - name = "unsupported-dummy-hash" - block_size = None - digest_size = None - - -def _skip_hashfn_unsupported(backend, hashfn): - if not backend.hash_supported(hashfn): - pytest.skip( - "Hash {0} is not supported by this backend {1}".format( - hashfn.name, backend - ) - ) - - -@pytest.mark.requires_backend_interface(interface=HashBackend) -class TestX963(object): - _algorithms_dict = { - 'SHA-1': hashes.SHA1, - 'SHA-224': hashes.SHA224, - 'SHA-256': hashes.SHA256, - 'SHA-384': hashes.SHA384, - 'SHA-512': hashes.SHA512 - } - - @pytest.mark.parametrize( - ("vector"), - load_vectors_from_file( - os.path.join("KDF", "ansx963_2001.txt"), - load_x963_vectors - ) - ) - def test_x963(self, backend, vector): - hashfn = self._algorithms_dict[vector["hash"]] - _skip_hashfn_unsupported(backend, hashfn()) - - key = binascii.unhexlify(vector["Z"]) - sharedinfo = None - if vector["sharedinfo_length"] != 0: - sharedinfo = binascii.unhexlify(vector["sharedinfo"]) - key_data_len = vector["key_data_length"] // 8 - key_data = binascii.unhexlify(vector["key_data"]) - - xkdf = X963KDF(algorithm=hashfn(), - length=key_data_len, - sharedinfo=sharedinfo, - backend=default_backend()) - xkdf.verify(key, key_data) - - def test_unsupported_hash(self, backend): - _skip_hashfn_unsupported(backend, UnsupportedDummyHash()) diff --git a/tests/hazmat/primitives/test_x963_vectors.py b/tests/hazmat/primitives/test_x963_vectors.py new file mode 100644 index 00000000..0332e601 --- /dev/null +++ b/tests/hazmat/primitives/test_x963_vectors.py @@ -0,0 +1,72 @@ +# This file is dual licensed under the terms of the Apache License, Version +# 2.0, and the BSD License. See the LICENSE file in the root of this repository +# for complete details. + +from __future__ import absolute_import, division, print_function + +import binascii +import os + +import pytest + +from cryptography import utils +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.backends.interfaces import HashBackend +from cryptography.hazmat.primitives import hashes +from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF + +from ...utils import load_vectors_from_file, load_x963_vectors + + +@utils.register_interface(hashes.HashAlgorithm) +class UnsupportedDummyHash(object): + name = "unsupported-dummy-hash" + block_size = None + digest_size = None + + +def _skip_hashfn_unsupported(backend, hashfn): + if not backend.hash_supported(hashfn): + pytest.skip( + "Hash {0} is not supported by this backend {1}".format( + hashfn.name, backend + ) + ) + + +@pytest.mark.requires_backend_interface(interface=HashBackend) +class TestX963(object): + _algorithms_dict = { + 'SHA-1': hashes.SHA1, + 'SHA-224': hashes.SHA224, + 'SHA-256': hashes.SHA256, + 'SHA-384': hashes.SHA384, + 'SHA-512': hashes.SHA512 + } + + @pytest.mark.parametrize( + ("vector"), + load_vectors_from_file( + os.path.join("KDF", "ansx963_2001.txt"), + load_x963_vectors + ) + ) + def test_x963(self, backend, vector): + hashfn = self._algorithms_dict[vector["hash"]] + _skip_hashfn_unsupported(backend, hashfn()) + + key = binascii.unhexlify(vector["Z"]) + sharedinfo = None + if vector["sharedinfo_length"] != 0: + sharedinfo = binascii.unhexlify(vector["sharedinfo"]) + key_data_len = vector["key_data_length"] // 8 + key_data = binascii.unhexlify(vector["key_data"]) + + xkdf = X963KDF(algorithm=hashfn(), + length=key_data_len, + sharedinfo=sharedinfo, + backend=default_backend()) + xkdf.verify(key, key_data) + + def test_unsupported_hash(self, backend): + _skip_hashfn_unsupported(backend, UnsupportedDummyHash()) -- cgit v1.2.3