diff options
-rw-r--r-- | cryptography/exceptions.py | 4 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/kdf/hkdf.py | 9 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/kdf/pbkdf2.py | 7 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/twofactor/hotp.py | 7 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/twofactor/totp.py | 7 | ||||
-rw-r--r-- | docs/exceptions.rst | 6 | ||||
-rw-r--r-- | docs/hazmat/primitives/key-derivation-functions.rst | 8 | ||||
-rw-r--r-- | docs/hazmat/primitives/twofactor.rst | 6 | ||||
-rw-r--r-- | tasks.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_hkdf.py | 11 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_pbkdf2hmac.py | 9 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_hotp.py | 11 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_totp.py | 11 | ||||
-rw-r--r-- | tests/test_utils.py | 360 | ||||
-rw-r--r-- | tests/utils.py | 49 |
15 files changed, 497 insertions, 10 deletions
diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py index d7c867d6..88766cc1 100644 --- a/cryptography/exceptions.py +++ b/cryptography/exceptions.py @@ -60,3 +60,7 @@ class InvalidKey(Exception): class InvalidToken(Exception): pass + + +class UnsupportedInterface(Exception): + pass diff --git a/cryptography/hazmat/primitives/kdf/hkdf.py b/cryptography/hazmat/primitives/kdf/hkdf.py index 1a464413..95396fe1 100644 --- a/cryptography/hazmat/primitives/kdf/hkdf.py +++ b/cryptography/hazmat/primitives/kdf/hkdf.py @@ -16,13 +16,20 @@ from __future__ import absolute_import, division, print_function import six from cryptography import utils -from cryptography.exceptions import AlreadyFinalized, InvalidKey +from cryptography.exceptions import ( + AlreadyFinalized, InvalidKey, UnsupportedInterface +) +from cryptography.hazmat.backends.interfaces import HMACBackend from cryptography.hazmat.primitives import constant_time, hmac, interfaces @utils.register_interface(interfaces.KeyDerivationFunction) class HKDF(object): def __init__(self, algorithm, length, salt, info, backend): + if not isinstance(backend, HMACBackend): + raise UnsupportedInterface( + "Backend object does not implement HMACBackend") + self._algorithm = algorithm max_length = 255 * (algorithm.digest_size // 8) diff --git a/cryptography/hazmat/primitives/kdf/pbkdf2.py b/cryptography/hazmat/primitives/kdf/pbkdf2.py index 39427780..f70a7ddf 100644 --- a/cryptography/hazmat/primitives/kdf/pbkdf2.py +++ b/cryptography/hazmat/primitives/kdf/pbkdf2.py @@ -17,14 +17,19 @@ import six from cryptography import utils from cryptography.exceptions import ( - InvalidKey, UnsupportedHash, AlreadyFinalized + InvalidKey, UnsupportedHash, AlreadyFinalized, UnsupportedInterface ) +from cryptography.hazmat.backends.interfaces import PBKDF2HMACBackend from cryptography.hazmat.primitives import constant_time, interfaces @utils.register_interface(interfaces.KeyDerivationFunction) class PBKDF2HMAC(object): def __init__(self, algorithm, length, salt, iterations, backend): + if not isinstance(backend, PBKDF2HMACBackend): + raise UnsupportedInterface( + "Backend object does not implement PBKDF2HMACBackend") + if not backend.pbkdf2_hmac_supported(algorithm): raise UnsupportedHash( "{0} is not supported for PBKDF2 by this backend".format( diff --git a/cryptography/hazmat/primitives/twofactor/hotp.py b/cryptography/hazmat/primitives/twofactor/hotp.py index 83260225..34f820c0 100644 --- a/cryptography/hazmat/primitives/twofactor/hotp.py +++ b/cryptography/hazmat/primitives/twofactor/hotp.py @@ -17,13 +17,18 @@ import struct import six -from cryptography.exceptions import InvalidToken +from cryptography.exceptions import InvalidToken, UnsupportedInterface +from cryptography.hazmat.backends.interfaces import HMACBackend from cryptography.hazmat.primitives import constant_time, hmac from cryptography.hazmat.primitives.hashes import SHA1, SHA256, SHA512 class HOTP(object): def __init__(self, key, length, algorithm, backend): + if not isinstance(backend, HMACBackend): + raise UnsupportedInterface( + "Backend object does not implement HMACBackend") + if len(key) < 16: raise ValueError("Key length has to be at least 128 bits.") diff --git a/cryptography/hazmat/primitives/twofactor/totp.py b/cryptography/hazmat/primitives/twofactor/totp.py index 0630de69..08510ef5 100644 --- a/cryptography/hazmat/primitives/twofactor/totp.py +++ b/cryptography/hazmat/primitives/twofactor/totp.py @@ -13,13 +13,18 @@ from __future__ import absolute_import, division, print_function -from cryptography.exceptions import InvalidToken +from cryptography.exceptions import InvalidToken, UnsupportedInterface +from cryptography.hazmat.backends.interfaces import HMACBackend from cryptography.hazmat.primitives import constant_time from cryptography.hazmat.primitives.twofactor.hotp import HOTP class TOTP(object): def __init__(self, key, length, algorithm, time_step, backend): + if not isinstance(backend, HMACBackend): + raise UnsupportedInterface( + "Backend object does not implement HMACBackend") + self._time_step = time_step self._hotp = HOTP(key, length, algorithm, backend) diff --git a/docs/exceptions.rst b/docs/exceptions.rst index 48c4bca8..e5010ebe 100644 --- a/docs/exceptions.rst +++ b/docs/exceptions.rst @@ -56,3 +56,9 @@ Exceptions This is raised when the verify method of a one time password function's computed token does not match the expected token. +.. class:: UnsupportedInterface + + .. versionadded:: 0.3 + + This is raised when the provided backend does not support the required + interface. diff --git a/docs/hazmat/primitives/key-derivation-functions.rst b/docs/hazmat/primitives/key-derivation-functions.rst index 851dbb0b..174b68d2 100644 --- a/docs/hazmat/primitives/key-derivation-functions.rst +++ b/docs/hazmat/primitives/key-derivation-functions.rst @@ -84,6 +84,10 @@ Different KDFs are suitable for different tasks such as: :class:`~cryptography.hazmat.backends.interfaces.PBKDF2HMACBackend` provider. + :raises cryptography.exceptions.UnsupportedInterface: This is raised if the + provided ``backend`` does not implement + :class:`~cryptography.hazmat.backends.interfaces.PBKDF2HMACBackend` + .. method:: derive(key_material) :param bytes key_material: The input key material. For PBKDF2 this @@ -183,6 +187,10 @@ Different KDFs are suitable for different tasks such as: :class:`~cryptography.hazmat.backends.interfaces.HMACBackend` provider. + :raises cryptography.exceptions.UnsupportedInterface: This is raised if the + provided ``backend`` does not implement + :class:`~cryptography.hazmat.backends.interfaces.HMACBackend` + .. method:: derive(key_material) :param bytes key_material: The input key material. diff --git a/docs/hazmat/primitives/twofactor.rst b/docs/hazmat/primitives/twofactor.rst index 3912d483..124d0ef5 100644 --- a/docs/hazmat/primitives/twofactor.rst +++ b/docs/hazmat/primitives/twofactor.rst @@ -52,6 +52,9 @@ codes (HMAC). :class:`~cryptography.hazmat.primitives.hashes.SHA256()` or :class:`~cryptography.hazmat.primitives.hashes.SHA512()` or if the ``length`` parameter is not an integer. + :raises cryptography.exceptions.UnsupportedInterface: This is raised if the + provided ``backend`` does not implement + :class:`~cryptography.hazmat.backends.interfaces.HMACBackend` .. method:: generate(counter) @@ -148,6 +151,9 @@ similar to the following code. :class:`~cryptography.hazmat.primitives.hashes.SHA256()` or :class:`~cryptography.hazmat.primitives.hashes.SHA512()` or if the ``length`` parameter is not an integer. + :raises cryptography.exceptions.UnsupportedInterface: This is raised if the + provided ``backend`` does not implement + :class:`~cryptography.hazmat.backends.interfaces.HMACBackend` .. method:: generate(time) @@ -21,7 +21,7 @@ import invoke import requests -JENKINS_URL = "http://jenkins.cryptography.io/job/cryptography-wheel-builder" +JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder" def wait_for_build_completed(): diff --git a/tests/hazmat/primitives/test_hkdf.py b/tests/hazmat/primitives/test_hkdf.py index e3e2a9df..963fb69c 100644 --- a/tests/hazmat/primitives/test_hkdf.py +++ b/tests/hazmat/primitives/test_hkdf.py @@ -17,7 +17,9 @@ import six import pytest -from cryptography.exceptions import AlreadyFinalized, InvalidKey +from cryptography.exceptions import ( + AlreadyFinalized, InvalidKey, UnsupportedInterface +) from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.hkdf import HKDF @@ -145,3 +147,10 @@ class TestHKDF(object): ) hkdf.verify(b"foo", six.u("bar")) + + +def test_invalid_backend(): + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + HKDF(hashes.SHA256(), 16, None, None, pretend_backend) diff --git a/tests/hazmat/primitives/test_pbkdf2hmac.py b/tests/hazmat/primitives/test_pbkdf2hmac.py index f895935b..bf1e7f14 100644 --- a/tests/hazmat/primitives/test_pbkdf2hmac.py +++ b/tests/hazmat/primitives/test_pbkdf2hmac.py @@ -18,7 +18,7 @@ import six from cryptography import utils from cryptography.exceptions import ( - InvalidKey, UnsupportedHash, AlreadyFinalized + InvalidKey, UnsupportedHash, AlreadyFinalized, UnsupportedInterface ) from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC @@ -67,3 +67,10 @@ class TestPBKDF2HMAC(object): kdf = PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, default_backend()) with pytest.raises(TypeError): kdf.derive(six.u("unicode here")) + + +def test_invalid_backend(): + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + PBKDF2HMAC(hashes.SHA1(), 20, b"salt", 10, pretend_backend) diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py index bc907c9f..548c6264 100644 --- a/tests/hazmat/primitives/twofactor/test_hotp.py +++ b/tests/hazmat/primitives/twofactor/test_hotp.py @@ -17,7 +17,7 @@ import os import pytest -from cryptography.exceptions import InvalidToken +from cryptography.exceptions import InvalidToken, UnsupportedInterface from cryptography.hazmat.primitives.twofactor.hotp import HOTP from cryptography.hazmat.primitives import hashes from tests.utils import load_vectors_from_file, load_nist_vectors @@ -95,3 +95,12 @@ class TestHOTP(object): with pytest.raises(TypeError): HOTP(secret, b"foo", SHA1(), backend) + + +def test_invalid_backend(): + secret = b"12345678901234567890" + + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + HOTP(secret, 8, hashes.SHA1(), pretend_backend) diff --git a/tests/hazmat/primitives/twofactor/test_totp.py b/tests/hazmat/primitives/twofactor/test_totp.py index f3bddb88..294c19ab 100644 --- a/tests/hazmat/primitives/twofactor/test_totp.py +++ b/tests/hazmat/primitives/twofactor/test_totp.py @@ -15,7 +15,7 @@ from __future__ import absolute_import, division, print_function import pytest -from cryptography.exceptions import InvalidToken +from cryptography.exceptions import InvalidToken, UnsupportedInterface from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.twofactor.totp import TOTP from tests.utils import load_vectors_from_file, load_nist_vectors @@ -129,3 +129,12 @@ class TestTOTP(object): totp = TOTP(secret, 8, hashes.SHA1(), 30, backend) assert totp.generate(time) == b"94287082" + + +def test_invalid_backend(): + secret = b"12345678901234567890" + + pretend_backend = object() + + with pytest.raises(UnsupportedInterface): + TOTP(secret, 8, hashes.SHA1(), 30, pretend_backend) diff --git a/tests/test_utils.py b/tests/test_utils.py index cc57665b..433dab04 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -23,7 +23,8 @@ import pytest from .utils import ( load_nist_vectors, load_vectors_from_file, load_cryptrec_vectors, load_hash_vectors, check_for_iface, check_backend_support, - select_backends, load_pkcs1_vectors, load_rsa_nist_vectors + select_backends, load_pkcs1_vectors, load_rsa_nist_vectors, + load_fips_dsa_key_pair_vectors ) @@ -1101,3 +1102,360 @@ def test_load_rsa_nist_vectors(): "s": b"deadbeef0000" }, ] + + +def test_load_fips_dsa_key_pair_vectors(): + vector_data = textwrap.dedent(""" + # CAVS 11.1 + # "KeyPair" information + # Mod sizes selected: L=1024, N=160:: L=2048, N=224 :: L=2048, N=256 :: L +=3072, N=256 + # Generated on Wed May 04 08:50:52 2011 + + + [mod = L=1024, N=160] + + P = d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d4b725ef341eabb47cf8a7a\ +8a41e792a156b7ce97206c4f9c5ce6fc5ae7912102b6b502e59050b5b21ce263dddb2044b65223\ +6f4d42ab4b5d6aa73189cef1ace778d7845a5c1c1c7147123188f8dc551054ee162b634d60f097\ +f719076640e20980a0093113a8bd73 + Q = 96c5390a8b612c0e422bb2b0ea194a3ec935a281 + G = 06b7861abbd35cc89e79c52f68d20875389b127361ca66822138ce4991d2b862259d6b\ +4548a6495b195aa0e0b6137ca37eb23b94074d3c3d300042bdf15762812b6333ef7b07ceba7860\ +7610fcc9ee68491dbc1e34cd12615474e52b18bc934fb00c61d39e7da8902291c4434a4e2224c3\ +f4fd9f93cd6f4f17fc076341a7e7d9 + + X = 8185fee9cc7c0e91fd85503274f1cd5a3fd15a49 + Y = 6f26d98d41de7d871b6381851c9d91fa03942092ab6097e76422070edb71db44ff5682\ +80fdb1709f8fc3feab39f1f824adaeb2a298088156ac31af1aa04bf54f475bdcfdcf2f8a2dd973\ +e922d83e76f016558617603129b21c70bf7d0e5dc9e68fe332e295b65876eb9a12fe6fca9f1a1c\ +e80204646bf99b5771d249a6fea627 + + X = 85322d6ea73083064376099ca2f65f56e8522d9b + Y = 21f8690f717c9f4dcb8f4b6971de2f15b9231fcf41b7eeb997d781f240bfdddfd2090d\ +22083c26cca39bf37c9caf1ec89518ea64845a50d747b49131ffff6a2fd11ea7bacbb93c7d0513\ +7383a06365af82225dd3713ca5a45006316f53bd12b0e260d5f79795e5a4c9f353f12867a1d320\ +2394673ada8563b71555e53f415254 + + [mod = L=2048, N=224] + + P = 904ef8e31e14721910fa0969e77c99b79f190071a86026e37a887a6053960dbfb74390\ +a6641319fe0af32c4e982934b0f1f4c5bc57534e8e56d77c36f0a99080c0d5bc9022fa34f58922\ +81d7b1009571cb5b35699303f912b276d86b1b0722fc0b1500f0ffb2e4d90867a3bdca181a9734\ +617a8a9f991aa7c14dec1cf45ceba00600f8425440ed0c3b52c82e3aa831932a98b477da220867\ +eb2d5e0ca34580b33b1b65e558411ed09c369f4717bf03b551787e13d9e47c267c91c697225265\ +da157945cd8b32e84fc45b80533265239aa00a2dd3d05f5cb231b7daf724b7ecdce170360a8397\ +2e5be94626273d449f441be300a7345db387bebadad67d8060a7 + Q = d7d0a83e84d13032b830ed74a6a88592ec9a4cf42bf37080c6600aad + G = 2050b18d3c9f39fac396c009310d6616f9309b67b59aef9aee813d6b4f12ee29ba8a6b\ +350b11d4336d44b4641230002d870f1e6b1d8728bdd40262df0d2440999185ae077f7034c61679\ +f4360fbb5d181569e7cb8acb04371c11ba55f1bbd777b74304b99b66d4405303e7120dc8bc4785\ +f56e9533e65b63a0c77cce7bba0d5d6069df5edffa927c5a255a09405a008258ed93506a843366\ +2154f6f67e922d7c9788f04d4ec09581063950d9cde8e373ea59a58b2a6df6ba8663345574fabb\ +a9ca981696d83aeac1f34f14f1a813ba900b3f0341dea23f7d3297f919a97e1ae00ac0728c93fe\ +0a88b66591baf4eb0bc6900f39ba5feb41cbbeea7eb7919aa4d3 + + X = 3f19424da3b4f0cafca3fc5019fcd225dd7e496ffdf6b77e364f45be + Y = 7681ed0ac257ab7ff17c52de4638c0614749792707a0c0d23883697e34963df15c806f\ +a6206f7fafb3269018e7703bd1e6f518d13544331a017713dbbe0cee8da6c095271fbf24edb74a\ +44e18b1d3b835622f68d31921c67c83e8479d1972ed0cb106c68188fe22c044254251ebf880b90\ +49dc3b7958ef61e1e67d2f677d2a7d2ab6b7c42b70cc5dedc3e5de7459a2dbc70c69008553d7ff\ +b6bf81c012c8bd67bdddeaab9a4a4373027912a7c7d9cd9cfc6c81dffe0cc7a6d40c3b2065aee7\ +be80e3c35497d64c8045bc511edaf7314c84c56bd9f0fecf62262ea5b45b49a0cffb223713bdbd\ +3ad03a25a0bb2211eba41ffcd08ab0e1ad485c29a3fc25ee8359 + + X = 241396352dd26efe0e2e184da52fe2b61d9d51b91b5009674c447854 + Y = 2f07a3aa9884c65288e5fef56c7b7f4445632273290bae6fcaab87c90058b2bef81ad3\ +34958657cf649ffb976d618b34ce69ef6d68c0d8bfe275cf097a301e8dd5595958e0c668c15f67\ +b5c0b0d01983057ce61593635aab5e0564ed720b0336f055a86755c76be22df3b8487f16e2ba0b\ +5136fd30d7e3b1d30c3bd298d3acc0a1988a11756c94e9a53184d0d3edfbb649caf03eace3083d\ +e9933921e627f4b2e011d1c79e45d8ea1eb7e4e59a1cbd8382b3238474eb949749c985200fbb25\ +41e2dce080aa881945d4d935076e48a0846dc5513bb4da8563b946af54f546455931e79c065ce7\ +ca223a98f8fde40091d38eb2c3eb8e3b81d88374f3146b0afc42 + + [mod = L=2048, N=256] + + P = ea1fb1af22881558ef93be8a5f8653c5a559434c49c8c2c12ace5e9c41434c9cf0a8e9\ +498acb0f4663c08b4484eace845f6fb17dac62c98e706af0fc74e4da1c6c2b3fbf5a1d58ff82fc\ +1a66f3e8b12252c40278fff9dd7f102eed2cb5b7323ebf1908c234d935414dded7f8d244e54561\ +b0dca39b301de8c49da9fb23df33c6182e3f983208c560fb5119fbf78ebe3e6564ee235c6a15cb\ +b9ac247baba5a423bc6582a1a9d8a2b4f0e9e3d9dbac122f750dd754325135257488b1f6ecabf2\ +1bff2947fe0d3b2cb7ffe67f4e7fcdf1214f6053e72a5bb0dd20a0e9fe6db2df0a908c36e95e60\ +bf49ca4368b8b892b9c79f61ef91c47567c40e1f80ac5aa66ef7 + Q = 8ec73f3761caf5fdfe6e4e82098bf10f898740dcb808204bf6b18f507192c19d + G = e4c4eca88415b23ecf811c96e48cd24200fe916631a68a684e6ccb6b1913413d344d1d\ +8d84a333839d88eee431521f6e357c16e6a93be111a98076739cd401bab3b9d565bf4fb99e9d18\ +5b1e14d61c93700133f908bae03e28764d107dcd2ea7674217622074bb19efff482f5f5c1a86d5\ +551b2fc68d1c6e9d8011958ef4b9c2a3a55d0d3c882e6ad7f9f0f3c61568f78d0706b10a26f23b\ +4f197c322b825002284a0aca91807bba98ece912b80e10cdf180cf99a35f210c1655fbfdd74f13\ +b1b5046591f8403873d12239834dd6c4eceb42bf7482e1794a1601357b629ddfa971f2ed273b14\ +6ec1ca06d0adf55dd91d65c37297bda78c6d210c0bc26e558302 + + X = 405772da6e90d809e77d5de796562a2dd4dfd10ef00a83a3aba6bd818a0348a1 + Y = 6b32e31ab9031dc4dd0b5039a78d07826687ab087ae6de4736f5b0434e1253092e8a0b\ +231f9c87f3fc8a4cb5634eb194bf1b638b7a7889620ce6711567e36aa36cda4604cfaa601a4591\ +8371d4ccf68d8b10a50a0460eb1dc0fff62ef5e6ee4d473e18ea4a66c196fb7e677a49b48241a0\ +b4a97128eff30fa437050501a584f8771e7280d26d5af30784039159c11ebfea10b692fd0a5821\ +5eeb18bff117e13f08db792ed4151a218e4bed8dddfb0793225bd1e9773505166f4bd8cedbb286\ +ea28232972da7bae836ba97329ba6b0a36508e50a52a7675e476d4d4137eae13f22a9d2fefde70\ +8ba8f34bf336c6e76331761e4b0617633fe7ec3f23672fb19d27 + + X = 0e0b95e31fda3f888059c46c3002ef8f2d6be112d0209aeb9e9545da67aeea80 + Y = 778082b77ddba6f56597cc74c3a612abf2ddbd85cc81430c99ab843c1f630b9db01399\ +65f563978164f9bf3a8397256be714625cd41cd7fa0067d94ea66d7e073f7125af692ad01371d4\ +a17f4550590378f2b074030c20e36911598a1018772f61be3b24de4be5a388ccc09e15a92819c3\ +1dec50de9fde105b49eaa097b9d13d9219eeb33b628facfd1c78a7159c8430d0647c506e7e3de7\ +4763cb351eada72c00bef3c9641881e6254870c1e6599f8ca2f1bbb74f39a905e3a34e4544168e\ +6e50c9e3305fd09cab6ed4aff6fda6e0d5bf375c81ac9054406d9193b003c89272f1bd83d48250\ +134b65c77c2b6332d38d34d9016f0e8975536ad6c348a1faedb0 + + [mod = L=3072, N=256] + + P = f335666dd1339165af8b9a5e3835adfe15c158e4c3c7bd53132e7d5828c352f593a9a7\ +87760ce34b789879941f2f01f02319f6ae0b756f1a842ba54c85612ed632ee2d79ef17f06b77c6\ +41b7b080aff52a03fc2462e80abc64d223723c236deeb7d201078ec01ca1fbc1763139e25099a8\ +4ec389159c409792080736bd7caa816b92edf23f2c351f90074aa5ea2651b372f8b58a0a65554d\ +b2561d706a63685000ac576b7e4562e262a14285a9c6370b290e4eb7757527d80b6c0fd5df831d\ +36f3d1d35f12ab060548de1605fd15f7c7aafed688b146a02c945156e284f5b71282045aba9844\ +d48b5df2e9e7a5887121eae7d7b01db7cdf6ff917cd8eb50c6bf1d54f90cce1a491a9c74fea88f\ +7e7230b047d16b5a6027881d6f154818f06e513faf40c8814630e4e254f17a47bfe9cb519b9828\ +9935bf17673ae4c8033504a20a898d0032ee402b72d5986322f3bdfb27400561f7476cd715eaab\ +b7338b854e51fc2fa026a5a579b6dcea1b1c0559c13d3c1136f303f4b4d25ad5b692229957 + Q = d3eba6521240694015ef94412e08bf3cf8d635a455a398d6f210f6169041653b + G = ce84b30ddf290a9f787a7c2f1ce92c1cbf4ef400e3cd7ce4978db2104d7394b493c183\ +32c64cec906a71c3778bd93341165dee8e6cd4ca6f13afff531191194ada55ecf01ff94d6cf7c4\ +768b82dd29cd131aaf202aefd40e564375285c01f3220af4d70b96f1395420d778228f1461f5d0\ +b8e47357e87b1fe3286223b553e3fc9928f16ae3067ded6721bedf1d1a01bfd22b9ae85fce7782\ +0d88cdf50a6bde20668ad77a707d1c60fcc5d51c9de488610d0285eb8ff721ff141f93a9fb23c1\ +d1f7654c07c46e58836d1652828f71057b8aff0b0778ef2ca934ea9d0f37daddade2d823a4d8e3\ +62721082e279d003b575ee59fd050d105dfd71cd63154efe431a0869178d9811f4f231dc5dcf3b\ +0ec0f2b0f9896c32ec6c7ee7d60aa97109e09224907328d4e6acd10117e45774406c4c947da802\ +0649c3168f690e0bd6e91ac67074d1d436b58ae374523deaf6c93c1e6920db4a080b744804bb07\ +3cecfe83fa9398cf150afa286dc7eb7949750cf5001ce104e9187f7e16859afa8fd0d775ae + + X = b2764c46113983777d3e7e97589f1303806d14ad9f2f1ef033097de954b17706 + Y = 814824e435e1e6f38daa239aad6dad21033afce6a3ebd35c1359348a0f2418871968c2\ +babfc2baf47742148828f8612183178f126504da73566b6bab33ba1f124c15aa461555c2451d86\ +c94ee21c3e3fc24c55527e01b1f03adcdd8ec5cb08082803a7b6a829c3e99eeb332a2cf5c035b0\ +ce0078d3d414d31fa47e9726be2989b8d06da2e6cd363f5a7d1515e3f4925e0b32adeae3025cc5\ +a996f6fd27494ea408763de48f3bb39f6a06514b019899b312ec570851637b8865cff3a52bf5d5\ +4ad5a19e6e400a2d33251055d0a440b50d53f4791391dc754ad02b9eab74c46b4903f9d76f8243\ +39914db108057af7cde657d41766a99991ac8787694f4185d6f91d7627048f827b405ec67bf2fe\ +56141c4c581d8c317333624e073e5879a82437cb0c7b435c0ce434e15965db1315d64895991e6b\ +be7dac040c42052408bbc53423fd31098248a58f8a67da3a39895cd0cc927515d044c1e3cb6a32\ +59c3d0da354cce89ea3552c59609db10ee989986527436af21d9485ddf25f90f7dff6d2bae + + X = 52e3e040efb30e1befd909a0bdbcfd140d005b1bff094af97186080262f1904d + Y = a5ae6e8f9b7a68ab0516dad4d7b7d002126f811d5a52e3d35c6d387fcb43fd19bf7792\ +362f9c98f8348aa058bb62376685f3d0c366c520d697fcd8416947151d4bbb6f32b53528a01647\ +9e99d2cd48d1fc679027c15f0042f207984efe05c1796bca8eba678dfdd00b80418e3ea840557e\ +73b09e003882f9a68edba3431d351d1ca07a8150b018fdbdf6c2f1ab475792a3ccaa6594472a45\ +f8dc777b60bf67de3e0f65c20d11b7d59faedf83fbce52617f500d9e514947c455274c6e900464\ +767fb56599b81344cf6d12c25cb2b7d038d7b166b6cf30534811c15d0e8ab880a2ac06786ae2dd\ +de61329a78d526f65245380ce877e979c5b50de66c9c30d66382c8f254653d25a1eb1d3a4897d7\ +623399b473ce712a2184cf2da1861706c41466806aefe41b497db82aca6c31c8f4aa68c17d1d9e\ +380b57998917655783ec96e5234a131f7299398d36f1f5f84297a55ff292f1f060958c358fed34\ +6db2de45127ca728a9417b2c54203e33e53b9a061d924395b09afab8daf3e8dd7eedcec3ac + """).splitlines() + + expected = [ + {'g': int('06b7861abbd35cc89e79c52f68d20875389b127361ca66822138ce499' + '1d2b862259d6b4548a6495b195aa0e0b6137ca37eb23b94074d3c3d3000' + '42bdf15762812b6333ef7b07ceba78607610fcc9ee68491dbc1e34cd12' + '615474e52b18bc934fb00c61d39e7da8902291c4434a4e2224c3f' + '4fd9f93cd6f4f17fc076341a7e7d9', 16), + 'p': int('d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d4b725e' + 'f341eabb47cf8a7a8a41e792a156b7ce97206c4f9c5ce6fc5ae791210' + '2b6b502e59050b5b21ce263dddb2044b652236f4d42ab4b5d6aa73189c' + 'ef1ace778d7845a5c1c1c7147123188f8dc551054ee162b634d60f097f7' + '19076640e20980a0093113a8bd73', 16), + 'q': int('96c5390a8b612c0e422bb2b0ea194a3ec935a281', 16), + 'x': int('8185fee9cc7c0e91fd85503274f1cd5a3fd15a49', 16), + 'y': int('6f26d98d41de7d871b6381851c9d91fa03942092ab6097e76422' + '070edb71db44ff568280fdb1709f8fc3feab39f1f824adaeb2a29808815' + '6ac31af1aa04bf54f475bdcfdcf2f8a2dd973e922d83e76f01655861760' + '3129b21c70bf7d0e5dc9e68fe332e295b65876eb9a12fe6fca9f1a1ce80' + '204646bf99b5771d249a6fea627', 16)}, + {'g': int('06b7861abbd35cc89e79c52f68d20875389b127361ca66822138ce4991d' + '2b862259d6b4548a6495b195aa0e0b6137ca37eb23b94074d3c3d30004' + '2bdf15762812b6333ef7b07ceba78607610fcc9ee68491dbc1e34cd126' + '15474e52b18bc934fb00c61d39e7da8902291c4434a4e2224c3f4fd9' + 'f93cd6f4f17fc076341a7e7d9', 16), + 'p': int('d38311e2cd388c3ed698e82fdf88eb92b5a9a483dc88005d4b725ef341e' + 'abb47cf8a7a8a41e792a156b7ce97206c4f9c5ce6fc5ae7912102b6b50' + '2e59050b5b21ce263dddb2044b652236f4d42ab4b5d6aa73189cef1a' + 'ce778d7845a5c1c1c7147123188f8dc551054ee162b634d6' + '0f097f719076640e20980a0093113a8bd73', 16), + 'q': int('96c5390a8b612c0e422bb2b0ea194a3ec935a281', 16), + 'x': int('85322d6ea73083064376099ca2f65f56e8522d9b', 16), + 'y': int('21f8690f717c9f4dcb8f4b6971de2f15b9231fcf41b7eeb997d781f240' + 'bfdddfd2090d22083c26cca39bf37c9caf1ec89518ea64845a50d747b49' + '131ffff6a2fd11ea7bacbb93c7d05137383a06365af82225dd3713c' + 'a5a45006316f53bd12b0e260d5f79795e5a4c9f353f12867a1d3' + '202394673ada8563b71555e53f415254', 16)}, + + {'g': int('e4c4eca88415b23ecf811c96e48cd24200fe916631a68a684e6ccb6b191' + '3413d344d1d8d84a333839d88eee431521f6e357c16e6a93be111a9807' + '6739cd401bab3b9d565bf4fb99e9d185b1e14d61c93700133f908bae0' + '3e28764d107dcd2ea7674217622074bb19efff482f5f5c1a86d5551b2' + 'fc68d1c6e9d8011958ef4b9c2a3a55d0d3c882e6ad7f9f0f3c61568f78' + 'd0706b10a26f23b4f197c322b825002284a0aca91807bba98ece912' + 'b80e10cdf180cf99a35f210c1655fbfdd74f13b1b5046591f8403873d' + '12239834dd6c4eceb42bf7482e1794a1601357b629ddfa971f2ed273b1' + '46ec1ca06d0adf55dd91d65c37297bda78c6d210c0bc26e558302', 16), + 'p': int('ea1fb1af22881558ef93be8a5f8653c5a559434c49c8c2c12ace' + '5e9c41434c9cf0a8e9498acb0f4663c08b4484eace845f6fb17d' + 'ac62c98e706af0fc74e4da1c6c2b3fbf5a1d58ff82fc1a66f3e8b122' + '52c40278fff9dd7f102eed2cb5b7323ebf1908c234d935414dded7f8d2' + '44e54561b0dca39b301de8c49da9fb23df33c6182e3f983208c560fb5' + '119fbf78ebe3e6564ee235c6a15cbb9ac247baba5a423bc6582a1a9d8a' + '2b4f0e9e3d9dbac122f750dd754325135257488b1f6ecabf21bff2947' + 'fe0d3b2cb7ffe67f4e7fcdf1214f6053e72a5bb0dd20a0e9fe6db2df0a' + '908c36e95e60bf49ca4368b8b892b9c79f61ef91c47567c40e1f80ac' + '5aa66ef7', 16), + 'q': int('8ec73f3761caf5fdfe6e4e82098bf10f898740dcb808204bf6b1' + '8f507192c19d', 16), + 'x': int('405772da6e90d809e77d5de796562a2dd4dfd10ef00a83a3aba6' + 'bd818a0348a1', 16), + 'y': int('6b32e31ab9031dc4dd0b5039a78d07826687ab087ae6de4736f5' + 'b0434e1253092e8a0b231f9c87f3fc8a4cb5634eb194bf1b638' + 'b7a7889620ce6711567e36aa36cda4604cfaa601a45918371d' + '4ccf68d8b10a50a0460eb1dc0fff62ef5e6ee4d473e18ea4a6' + '6c196fb7e677a49b48241a0b4a97128eff30fa437050501a584' + 'f8771e7280d26d5af30784039159c11ebfea10b692fd0a58215ee' + 'b18bff117e13f08db792ed4151a218e4bed8dddfb0793225bd1e97' + '73505166f4bd8cedbb286ea28232972da7bae836ba97329ba6b0a36508' + 'e50a52a7675e476d4d4137eae13f22a9d2fefde708ba8f34bf336c6e7' + '6331761e4b0617633fe7ec3f23672fb19d27', 16)}, + {'g': int('e4c4eca88415b23ecf811c96e48cd24200fe916631a68a684e6ccb6b191' + '3413d344d1d8d84a333839d88eee431521f6e357c16e6a93be111a9807' + '6739cd401bab3b9d565bf4fb99e9d185b1e14d61c93700133f908bae0' + '3e28764d107dcd2ea7674217622074bb19efff482f5f5c1a86d5551b2' + 'fc68d1c6e9d8011958ef4b9c2a3a55d0d3c882e6ad7f9f0f3c61568f78' + 'd0706b10a26f23b4f197c322b825002284a0aca91807bba98ece912' + 'b80e10cdf180cf99a35f210c1655fbfdd74f13b1b5046591f8403873d' + '12239834dd6c4eceb42bf7482e1794a1601357b629ddfa971f2ed273b1' + '46ec1ca06d0adf55dd91d65c37297bda78c6d210c0bc26e558302', 16), + 'p': int('ea1fb1af22881558ef93be8a5f8653c5a559434c49c8c2c12ace' + '5e9c41434c9cf0a8e9498acb0f4663c08b4484eace845f6fb17d' + 'ac62c98e706af0fc74e4da1c6c2b3fbf5a1d58ff82fc1a66f3e8b122' + '52c40278fff9dd7f102eed2cb5b7323ebf1908c234d935414dded7f8d2' + '44e54561b0dca39b301de8c49da9fb23df33c6182e3f983208c560fb5' + '119fbf78ebe3e6564ee235c6a15cbb9ac247baba5a423bc6582a1a9d8a' + '2b4f0e9e3d9dbac122f750dd754325135257488b1f6ecabf21bff2947' + 'fe0d3b2cb7ffe67f4e7fcdf1214f6053e72a5bb0dd20a0e9fe6db2df0a' + '908c36e95e60bf49ca4368b8b892b9c79f61ef91c47567c40e1f80ac' + '5aa66ef7', 16), + 'q': int('8ec73f3761caf5fdfe6e4e82098bf10f898740dcb808204bf6b1' + '8f507192c19d', 16), + 'x': int('0e0b95e31fda3f888059c46c3002ef8f2d6be112d0209aeb9e95' + '45da67aeea80', 16), + 'y': int('778082b77ddba6f56597cc74c3a612abf2ddbd85cc81430c99ab' + '843c1f630b9db0139965f563978164f9bf3a8397256be714625' + 'cd41cd7fa0067d94ea66d7e073f7125af692ad01371d4a17f45' + '50590378f2b074030c20e36911598a1018772f61be3b24de4be' + '5a388ccc09e15a92819c31dec50de9fde105b49eaa097b9d13d' + '9219eeb33b628facfd1c78a7159c8430d0647c506e7e3de74763c' + 'b351eada72c00bef3c9641881e6254870c1e6599f8ca2f1bbb74f' + '39a905e3a34e4544168e6e50c9e3305fd09cab6ed4aff6fda6e0d' + '5bf375c81ac9054406d9193b003c89272f1bd83d48250134b65c77' + 'c2b6332d38d34d9016f0e8975536ad6c348a1faedb0', 16)}, + + {'g': int('ce84b30ddf290a9f787a7c2f1ce92c1cbf4ef400e3cd7ce4978d' + 'b2104d7394b493c18332c64cec906a71c3778bd93341165dee8' + 'e6cd4ca6f13afff531191194ada55ecf01ff94d6cf7c4768b82' + 'dd29cd131aaf202aefd40e564375285c01f3220af4d70b96f1' + '395420d778228f1461f5d0b8e47357e87b1fe3286223b553e3' + 'fc9928f16ae3067ded6721bedf1d1a01bfd22b9ae85fce77820d88cdf' + '50a6bde20668ad77a707d1c60fcc5d51c9de488610d0285eb8ff721f' + 'f141f93a9fb23c1d1f7654c07c46e58836d1652828f71057b8aff0b077' + '8ef2ca934ea9d0f37daddade2d823a4d8e362721082e279d003b575ee' + '59fd050d105dfd71cd63154efe431a0869178d9811f4f231dc5dcf3b' + '0ec0f2b0f9896c32ec6c7ee7d60aa97109e09224907328d4e6acd1011' + '7e45774406c4c947da8020649c3168f690e0bd6e91ac67074d1d436b' + '58ae374523deaf6c93c1e6920db4a080b744804bb073cecfe83fa939' + '8cf150afa286dc7eb7949750cf5001ce104e9187f7e16859afa8fd0d' + '775ae', 16), + 'p': int('f335666dd1339165af8b9a5e3835adfe15c158e4c3c7bd53132e7d5828' + 'c352f593a9a787760ce34b789879941f2f01f02319f6ae0b756f1a842' + 'ba54c85612ed632ee2d79ef17f06b77c641b7b080aff52a03fc2462e8' + '0abc64d223723c236deeb7d201078ec01ca1fbc1763139e25099a84ec' + '389159c409792080736bd7caa816b92edf23f2c351f90074aa5ea2651' + 'b372f8b58a0a65554db2561d706a63685000ac576b7e4562e262a1428' + '5a9c6370b290e4eb7757527d80b6c0fd5df831d36f3d1d35f12ab0605' + '48de1605fd15f7c7aafed688b146a02c945156e284f5b71282045aba9' + '844d48b5df2e9e7a5887121eae7d7b01db7cdf6ff917cd8eb50c6bf1d' + '54f90cce1a491a9c74fea88f7e7230b047d16b5a6027881d6f154818f' + '06e513faf40c8814630e4e254f17a47bfe9cb519b98289935bf17673a' + 'e4c8033504a20a898d0032ee402b72d5986322f3bdfb27400561f7476' + 'cd715eaabb7338b854e51fc2fa026a5a579b6dcea1b1c0559c13d3c11' + '36f303f4b4d25ad5b692229957', 16), + 'q': int('d3eba6521240694015ef94412e08bf3cf8d635a455a398d6f210' + 'f6169041653b', 16), + 'x': int('b2764c46113983777d3e7e97589f1303806d14ad9f2f1ef03309' + '7de954b17706', 16), + 'y': int('814824e435e1e6f38daa239aad6dad21033afce6a3ebd35c1359348a0f2' + '418871968c2babfc2baf47742148828f8612183178f126504da73566b6' + 'bab33ba1f124c15aa461555c2451d86c94ee21c3e3fc24c55527e' + '01b1f03adcdd8ec5cb08082803a7b6a829c3e99eeb332a2cf5c035b0c' + 'e0078d3d414d31fa47e9726be2989b8d06da2e6cd363f5a7d1515e3f4' + '925e0b32adeae3025cc5a996f6fd27494ea408763de48f3bb39f6a06' + '514b019899b312ec570851637b8865cff3a52bf5d54ad5a19e6e400' + 'a2d33251055d0a440b50d53f4791391dc754ad02b9eab74c46b4903' + 'f9d76f824339914db108057af7cde657d41766a99991ac8787694f' + '4185d6f91d7627048f827b405ec67bf2fe56141c4c581d8c317333' + '624e073e5879a82437cb0c7b435c0ce434e15965db1315d648959' + '91e6bbe7dac040c42052408bbc53423fd31098248a58f8a67da3a' + '39895cd0cc927515d044c1e3cb6a3259c3d0da354cce89ea3552c' + '59609db10ee989986527436af21d9485ddf25f90f7dff6d2bae', 16)}, + {'g': int('ce84b30ddf290a9f787a7c2f1ce92c1cbf4ef400e3cd7ce4978d' + 'b2104d7394b493c18332c64cec906a71c3778bd93341165dee8' + 'e6cd4ca6f13afff531191194ada55ecf01ff94d6cf7c4768b82' + 'dd29cd131aaf202aefd40e564375285c01f3220af4d70b96f1' + '395420d778228f1461f5d0b8e47357e87b1fe3286223b553e3' + 'fc9928f16ae3067ded6721bedf1d1a01bfd22b9ae85fce77820d88cdf' + '50a6bde20668ad77a707d1c60fcc5d51c9de488610d0285eb8ff721f' + 'f141f93a9fb23c1d1f7654c07c46e58836d1652828f71057b8aff0b077' + '8ef2ca934ea9d0f37daddade2d823a4d8e362721082e279d003b575ee' + '59fd050d105dfd71cd63154efe431a0869178d9811f4f231dc5dcf3b' + '0ec0f2b0f9896c32ec6c7ee7d60aa97109e09224907328d4e6acd1011' + '7e45774406c4c947da8020649c3168f690e0bd6e91ac67074d1d436b' + '58ae374523deaf6c93c1e6920db4a080b744804bb073cecfe83fa939' + '8cf150afa286dc7eb7949750cf5001ce104e9187f7e16859afa8fd0d' + '775ae', 16), + 'p': int('f335666dd1339165af8b9a5e3835adfe15c158e4c3c7bd53132e7d5828' + 'c352f593a9a787760ce34b789879941f2f01f02319f6ae0b756f1a842' + 'ba54c85612ed632ee2d79ef17f06b77c641b7b080aff52a03fc2462e8' + '0abc64d223723c236deeb7d201078ec01ca1fbc1763139e25099a84ec' + '389159c409792080736bd7caa816b92edf23f2c351f90074aa5ea2651' + 'b372f8b58a0a65554db2561d706a63685000ac576b7e4562e262a1428' + '5a9c6370b290e4eb7757527d80b6c0fd5df831d36f3d1d35f12ab0605' + '48de1605fd15f7c7aafed688b146a02c945156e284f5b71282045aba9' + '844d48b5df2e9e7a5887121eae7d7b01db7cdf6ff917cd8eb50c6bf1d' + '54f90cce1a491a9c74fea88f7e7230b047d16b5a6027881d6f154818f' + '06e513faf40c8814630e4e254f17a47bfe9cb519b98289935bf17673a' + 'e4c8033504a20a898d0032ee402b72d5986322f3bdfb27400561f7476' + 'cd715eaabb7338b854e51fc2fa026a5a579b6dcea1b1c0559c13d3c11' + '36f303f4b4d25ad5b692229957', 16), + 'q': int('d3eba6521240694015ef94412e08bf3cf8d635a455a398d6f210' + 'f6169041653b', 16), + 'x': int('52e3e040efb30e1befd909a0bdbcfd140d005b1bff094af97186' + '080262f1904d', 16), + 'y': int('a5ae6e8f9b7a68ab0516dad4d7b7d002126f811d5a52e3d35c6d' + '387fcb43fd19bf7792362f9c98f8348aa058bb62376685f3d0c3' + '66c520d697fcd8416947151d4bbb6f32b53528a016479e99d2cd' + '48d1fc679027c15f0042f207984efe05c1796bca8eba678dfdd0' + '0b80418e3ea840557e73b09e003882f9a68edba3431d351d1ca0' + '7a8150b018fdbdf6c2f1ab475792a3ccaa6594472a45f8dc777b' + '60bf67de3e0f65c20d11b7d59faedf83fbce52617f500d9e5149' + '47c455274c6e900464767fb56599b81344cf6d12c25cb2b7d038' + 'd7b166b6cf30534811c15d0e8ab880a2ac06786ae2ddde61329a' + '78d526f65245380ce877e979c5b50de66c9c30d66382c8f25465' + '3d25a1eb1d3a4897d7623399b473ce712a2184cf2da1861706c4' + '1466806aefe41b497db82aca6c31c8f4aa68c17d1d9e380b5799' + '8917655783ec96e5234a131f7299398d36f1f5f84297a55ff292' + 'f1f060958c358fed346db2de45127ca728a9417b2c54203e33e5' + '3b9a061d924395b09afab8daf3e8dd7eedcec3ac', 16)} + ] + + assert expected == load_fips_dsa_key_pair_vectors(vector_data) diff --git a/tests/utils.py b/tests/utils.py index b97c7f7b..720a9054 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -339,3 +339,52 @@ def load_rsa_nist_vectors(vector_data): test_data[name.lower()] = value.encode("ascii") return data + + +def load_fips_dsa_key_pair_vectors(vector_data): + """ + Loads data out of the FIPS DSA KeyPair vector files. + """ + vectors = [] + # When reading_key_data is set to True it tells the loader to continue + # constructing dictionaries. We set reading_key_data to False during the + # blocks of the vectors of N=224 because we don't support it. + reading_key_data = True + for line in vector_data: + line = line.strip() + + if not line or line.startswith("#"): + continue + elif line.startswith("[mod = L=1024"): + continue + elif line.startswith("[mod = L=2048, N=224"): + reading_key_data = False + continue + elif line.startswith("[mod = L=2048, N=256"): + reading_key_data = True + continue + elif line.startswith("[mod = L=3072"): + continue + + if not reading_key_data: + continue + + elif reading_key_data: + if line.startswith("P"): + vectors.append({'p': int(line.split("=")[1], 16)}) + elif line.startswith("Q"): + vectors[-1]['q'] = int(line.split("=")[1], 16) + elif line.startswith("G"): + vectors[-1]['g'] = int(line.split("=")[1], 16) + elif line.startswith("X") and 'x' not in vectors[-1]: + vectors[-1]['x'] = int(line.split("=")[1], 16) + elif line.startswith("X") and 'x' in vectors[-1]: + vectors.append({'p': vectors[-1]['p'], + 'q': vectors[-1]['q'], + 'g': vectors[-1]['g'], + 'x': int(line.split("=")[1], 16) + }) + elif line.startswith("Y"): + vectors[-1]['y'] = int(line.split("=")[1], 16) + + return vectors |