diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 14 | ||||
-rw-r--r-- | tests/conftest.py | 15 | ||||
-rw-r--r-- | tests/hazmat/__init__.py | 14 | ||||
-rw-r--r-- | tests/hazmat/backends/__init__.py | 14 | ||||
-rw-r--r-- | tests/hazmat/backends/test_commoncrypto.py | 2 | ||||
-rw-r--r-- | tests/hazmat/backends/test_multibackend.py | 2 | ||||
-rw-r--r-- | tests/hazmat/backends/test_openssl.py | 2 | ||||
-rw-r--r-- | tests/hazmat/bindings/test_commoncrypto.py | 2 | ||||
-rw-r--r-- | tests/hazmat/bindings/test_openssl.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/__init__.py | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_padding.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/__init__.py | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_hotp.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/twofactor/test_totp.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/utils.py | 15 | ||||
-rw-r--r-- | tests/test_fernet.py | 2 | ||||
-rw-r--r-- | tests/test_utils.py | 68 | ||||
-rw-r--r-- | tests/utils.py | 43 |
18 files changed, 228 insertions, 1 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..2f420574 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,14 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function diff --git a/tests/conftest.py b/tests/conftest.py index 64982efd..0069f2c0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,18 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function + import pytest from cryptography.hazmat.backends import _ALL_BACKENDS diff --git a/tests/hazmat/__init__.py b/tests/hazmat/__init__.py index e69de29b..2f420574 100644 --- a/tests/hazmat/__init__.py +++ b/tests/hazmat/__init__.py @@ -0,0 +1,14 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function diff --git a/tests/hazmat/backends/__init__.py b/tests/hazmat/backends/__init__.py index e69de29b..2f420574 100644 --- a/tests/hazmat/backends/__init__.py +++ b/tests/hazmat/backends/__init__.py @@ -0,0 +1,14 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py index 7feb0c72..1062b2ba 100644 --- a/tests/hazmat/backends/test_commoncrypto.py +++ b/tests/hazmat/backends/test_commoncrypto.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest from cryptography import utils diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index 87ef0446..31fb0a26 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest from cryptography import utils diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index c6792185..599d1531 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest from cryptography import utils diff --git a/tests/hazmat/bindings/test_commoncrypto.py b/tests/hazmat/bindings/test_commoncrypto.py index db3d1b74..0332674b 100644 --- a/tests/hazmat/bindings/test_commoncrypto.py +++ b/tests/hazmat/bindings/test_commoncrypto.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest from cryptography.hazmat.bindings.commoncrypto.binding import Binding diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py index c476390b..acab22b1 100644 --- a/tests/hazmat/bindings/test_openssl.py +++ b/tests/hazmat/bindings/test_openssl.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest from cryptography.hazmat.bindings.openssl.binding import Binding diff --git a/tests/hazmat/primitives/__init__.py b/tests/hazmat/primitives/__init__.py index e69de29b..2f420574 100644 --- a/tests/hazmat/primitives/__init__.py +++ b/tests/hazmat/primitives/__init__.py @@ -0,0 +1,14 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function diff --git a/tests/hazmat/primitives/test_padding.py b/tests/hazmat/primitives/test_padding.py index 6a2b6243..932cef1e 100644 --- a/tests/hazmat/primitives/test_padding.py +++ b/tests/hazmat/primitives/test_padding.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest import six diff --git a/tests/hazmat/primitives/twofactor/__init__.py b/tests/hazmat/primitives/twofactor/__init__.py index e69de29b..2f420574 100644 --- a/tests/hazmat/primitives/twofactor/__init__.py +++ b/tests/hazmat/primitives/twofactor/__init__.py @@ -0,0 +1,14 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py index 0f8c4a53..bc907c9f 100644 --- a/tests/hazmat/primitives/twofactor/test_hotp.py +++ b/tests/hazmat/primitives/twofactor/test_hotp.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import os import pytest diff --git a/tests/hazmat/primitives/twofactor/test_totp.py b/tests/hazmat/primitives/twofactor/test_totp.py index a4a108bc..f3bddb88 100644 --- a/tests/hazmat/primitives/twofactor/test_totp.py +++ b/tests/hazmat/primitives/twofactor/test_totp.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import pytest from cryptography.exceptions import InvalidToken diff --git a/tests/hazmat/primitives/utils.py b/tests/hazmat/primitives/utils.py index 5a8dc3ab..f0a00319 100644 --- a/tests/hazmat/primitives/utils.py +++ b/tests/hazmat/primitives/utils.py @@ -1,3 +1,18 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import absolute_import, division, print_function + import binascii import os diff --git a/tests/test_fernet.py b/tests/test_fernet.py index bd4d90a5..36e87297 100644 --- a/tests/test_fernet.py +++ b/tests/test_fernet.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import base64 import calendar import json diff --git a/tests/test_utils.py b/tests/test_utils.py index 622a6656..cc57665b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import os import textwrap @@ -21,7 +23,7 @@ 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 + select_backends, load_pkcs1_vectors, load_rsa_nist_vectors ) @@ -1035,3 +1037,67 @@ def test_load_totp_vectors(): "secret": b"12345678901234567890", }, ] + + +def test_load_rsa_nist_vectors(): + vector_data = textwrap.dedent(""" + # SHA Algorithm selected:SHA1 SHA224 SHA256 SHA384 SHA512 + # Salt len: 20 + + [mod = 1024] + + n = bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda707a146b3b4e29989d + + e = 00000000000000000000000000000000000000000000000000000000000000000010001 + SHAAlg = SHA1 + Msg = 1248f62a4389f42f7b4bb131053d6c88a994db2075b912ccbe3ea7dc611714f14e + S = 682cf53c1145d22a50caa9eb1a9ba70670c5915e0fdfde6457a765de2a8fe12de97 + + SHAAlg = SHA384 + Msg = e511903c2f1bfba245467295ac95413ac4746c984c3750a728c388aa628b0ebf + S = 9c748702bbcc1f9468864cd360c8c39d007b2d8aaee833606c70f7593cf0d1519 + + [mod = 1024] + + n = 1234567890 + + e = 0010001 + + SHAAlg = SHA512 + Msg = 3456781293fab829 + S = deadbeef0000 + """).splitlines() + + vectors = load_rsa_nist_vectors(vector_data) + assert vectors == [ + { + "modulus": int("bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda" + "707a146b3b4e29989d", 16), + "public_exponent": 65537, + "algorithm": b"SHA1", + "salt_length": 20, + "msg": b"1248f62a4389f42f7b4bb131053d6c88a994db2075b912ccbe3ea7dc6" + b"11714f14e", + "s": b"682cf53c1145d22a50caa9eb1a9ba70670c5915e0fdfde6457a765de2a8" + b"fe12de97" + }, + { + "modulus": int("bcb47b2e0dafcba81ff2a2b5cb115ca7e757184c9d72bcdcda" + "707a146b3b4e29989d", 16), + "public_exponent": 65537, + "algorithm": b"SHA384", + "salt_length": 20, + "msg": b"e511903c2f1bfba245467295ac95413ac4746c984c3750a728c388aa6" + b"28b0ebf", + "s": b"9c748702bbcc1f9468864cd360c8c39d007b2d8aaee833606c70f7593cf" + b"0d1519" + }, + { + "modulus": 78187493520, + "public_exponent": 65537, + "algorithm": b"SHA512", + "salt_length": 20, + "msg": b"3456781293fab829", + "s": b"deadbeef0000" + }, + ] diff --git a/tests/utils.py b/tests/utils.py index 0d9567f9..b97c7f7b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -11,6 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import absolute_import, division, print_function + import collections import os @@ -296,3 +298,44 @@ def load_pkcs1_vectors(vector_data): if key is not None and attr is not None: key[attr].append(line.strip()) return vectors + + +def load_rsa_nist_vectors(vector_data): + test_data = None + data = [] + + for line in vector_data: + line = line.strip() + + # Blank lines and section headers are ignored + if not line or line.startswith("["): + continue + + if line.startswith("# Salt len:"): + salt_length = int(line.split(":")[1].strip()) + continue + elif line.startswith("#"): + continue + + # Build our data using a simple Key = Value format + name, value = [c.strip() for c in line.split("=")] + + if name == "n": + n = int(value, 16) + elif name == "e": + e = int(value, 16) + elif name == "SHAAlg": + test_data = { + "modulus": n, + "public_exponent": e, + "salt_length": salt_length, + "algorithm": value.encode("ascii") + } + data.append(test_data) + continue + # For all other tokens we simply want the name, value stored in + # the dictionary + else: + test_data[name.lower()] = value.encode("ascii") + + return data |