aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.coveragerc3
-rw-r--r--CHANGELOG.rst13
-rw-r--r--MANIFEST.in1
-rw-r--r--cryptography/hazmat/backends/__init__.py24
-rw-r--r--cryptography/hazmat/backends/openssl/rsa.py3
-rw-r--r--cryptography/hazmat/bindings/commoncrypto/binding.py12
-rw-r--r--cryptography/hazmat/bindings/openssl/binding.py12
-rw-r--r--cryptography/hazmat/bindings/openssl/pem.py1
-rw-r--r--cryptography/hazmat/bindings/openssl/x509_vfy.py39
-rw-r--r--cryptography/hazmat/primitives/constant_time.py29
-rw-r--r--cryptography/hazmat/primitives/src/constant_time.c31
-rw-r--r--cryptography/hazmat/primitives/src/constant_time.h16
-rw-r--r--docs/hazmat/primitives/mac/index.rst2
-rw-r--r--docs/installation.rst1
-rw-r--r--docs/spelling_wordlist.txt2
-rw-r--r--setup.py27
-rw-r--r--tests/hazmat/backends/test_commoncrypto.py5
-rw-r--r--tests/hazmat/bindings/test_commoncrypto.py4
-rw-r--r--tests/hazmat/bindings/test_openssl.py3
-rw-r--r--tests/hazmat/primitives/test_rsa.py2
-rw-r--r--tests/test_utils.py459
-rw-r--r--tests/utils.py59
-rw-r--r--tox.ini5
23 files changed, 665 insertions, 88 deletions
diff --git a/.coveragerc b/.coveragerc
index 03fc621e..58a1992d 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,5 +1,8 @@
[run]
branch = True
+source =
+ cryptography/
+ tests/
[report]
exclude_lines =
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 3969cb9e..dfc6d8b0 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -10,6 +10,19 @@ Changelog
the :class:`~cryptography.hazmat.primitives.asymmetric.padding.MGF1`
constructor. The ``salt_length`` should be passed to
:class:`~cryptography.hazmat.primitives.asymmetric.padding.PSS` instead.
+* Fix compilation on OS X Yosemite.
+
+0.5.4 - 2014-08-20
+~~~~~~~~~~~~~~~~~~
+
+* Added several functions to the OpenSSL bindings to support new
+ functionality in pyOpenSSL.
+* Fixed a redefined constant causing compilation failure with Solaris 11.2.
+
+0.5.3 - 2014-08-06
+~~~~~~~~~~~~~~~~~~
+
+* Updated Windows wheels to be compiled against OpenSSL 1.0.1i.
0.5.2 - 2014-07-09
~~~~~~~~~~~~~~~~~~
diff --git a/MANIFEST.in b/MANIFEST.in
index e12e430a..07e3f97a 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -5,6 +5,7 @@ include LICENSE
include README.rst
recursive-include docs *
+recursive-include cryptography/hazmat/primitives/src *.c *.h
prune docs/_build
recursive-include tests *.py
recursive-exclude vectors *
diff --git a/cryptography/hazmat/backends/__init__.py b/cryptography/hazmat/backends/__init__.py
index ae78822c..b0f663fe 100644
--- a/cryptography/hazmat/backends/__init__.py
+++ b/cryptography/hazmat/backends/__init__.py
@@ -13,13 +13,9 @@
from __future__ import absolute_import, division, print_function
+import pkg_resources
+
from cryptography.hazmat.backends.multibackend import MultiBackend
-from cryptography.hazmat.bindings.commoncrypto.binding import (
- Binding as CommonCryptoBinding
-)
-from cryptography.hazmat.bindings.openssl.binding import (
- Binding as OpenSSLBinding
-)
_available_backends_list = None
@@ -29,19 +25,15 @@ def _available_backends():
global _available_backends_list
if _available_backends_list is None:
- _available_backends_list = []
-
- if CommonCryptoBinding.is_available():
- from cryptography.hazmat.backends import commoncrypto
- _available_backends_list.append(commoncrypto.backend)
-
- if OpenSSLBinding.is_available():
- from cryptography.hazmat.backends import openssl
- _available_backends_list.append(openssl.backend)
+ _available_backends_list = [
+ backend.load(require=False)
+ for backend in pkg_resources.iter_entry_points(
+ "cryptography.backends"
+ )
+ ]
return _available_backends_list
-
_default_backend = None
diff --git a/cryptography/hazmat/backends/openssl/rsa.py b/cryptography/hazmat/backends/openssl/rsa.py
index 21ac1573..d24bea57 100644
--- a/cryptography/hazmat/backends/openssl/rsa.py
+++ b/cryptography/hazmat/backends/openssl/rsa.py
@@ -43,6 +43,9 @@ def _get_rsa_pss_salt_length(pss, key_size, digest_size):
def _enc_dec_rsa(backend, key, data, padding):
+ if not isinstance(padding, interfaces.AsymmetricPadding):
+ raise TypeError("Padding must be an instance of AsymmetricPadding.")
+
if isinstance(padding, PKCS1v15):
padding_enum = backend._lib.RSA_PKCS1_PADDING
elif isinstance(padding, OAEP):
diff --git a/cryptography/hazmat/bindings/commoncrypto/binding.py b/cryptography/hazmat/bindings/commoncrypto/binding.py
index ee7378ad..e23a2fd9 100644
--- a/cryptography/hazmat/bindings/commoncrypto/binding.py
+++ b/cryptography/hazmat/bindings/commoncrypto/binding.py
@@ -13,9 +13,6 @@
from __future__ import absolute_import, division, print_function
-import platform
-import sys
-
from cryptography.hazmat.bindings.utils import build_ffi
@@ -51,10 +48,7 @@ class Binding(object):
cls.ffi, cls.lib = build_ffi(
module_prefix=cls._module_prefix,
modules=cls._modules,
- extra_link_args=["-framework", "Security"]
+ extra_link_args=[
+ "-framework", "Security", "-framework", "CoreFoundation"
+ ]
)
-
- @classmethod
- def is_available(cls):
- return sys.platform == "darwin" and list(map(
- int, platform.mac_ver()[0].split("."))) >= [10, 8, 0]
diff --git a/cryptography/hazmat/bindings/openssl/binding.py b/cryptography/hazmat/bindings/openssl/binding.py
index 4cd1b89b..37891f6b 100644
--- a/cryptography/hazmat/bindings/openssl/binding.py
+++ b/cryptography/hazmat/bindings/openssl/binding.py
@@ -96,7 +96,11 @@ class Binding(object):
# OpenSSL goes by a different library name on different operating
# systems.
if sys.platform != "win32":
- libraries = ["crypto", "ssl"]
+ # In some circumstances, the order in which these libs are
+ # specified on the linker command-line is significant;
+ # libssl must come before libcrypto
+ # (http://marc.info/?l=openssl-users&m=135361825921871)
+ libraries = ["ssl", "crypto"]
else: # pragma: no cover
link_type = os.environ.get("PYCA_WINDOWS_LINK_TYPE", "static")
libraries = _get_windows_libraries(link_type)
@@ -112,12 +116,6 @@ class Binding(object):
assert res != 0
@classmethod
- def is_available(cls):
- # For now, OpenSSL is considered our "default" binding, so we treat it
- # as always available.
- return True
-
- @classmethod
def init_static_locks(cls):
with cls._lock_init_lock:
cls._ensure_ffi_initialized()
diff --git a/cryptography/hazmat/bindings/openssl/pem.py b/cryptography/hazmat/bindings/openssl/pem.py
index e42fc6fe..752f1987 100644
--- a/cryptography/hazmat/bindings/openssl/pem.py
+++ b/cryptography/hazmat/bindings/openssl/pem.py
@@ -41,6 +41,7 @@ int i2d_PKCS8PrivateKey_bio(BIO *, EVP_PKEY *, const EVP_CIPHER *,
int i2d_PKCS8PrivateKey_nid_bio(BIO *, EVP_PKEY *, int,
char *, int, pem_password_cb *, void *);
+PKCS7 *d2i_PKCS7_bio(BIO *, PKCS7 **);
EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *, EVP_PKEY **, pem_password_cb *,
void *);
diff --git a/cryptography/hazmat/bindings/openssl/x509_vfy.py b/cryptography/hazmat/bindings/openssl/x509_vfy.py
index a53716b0..601926c9 100644
--- a/cryptography/hazmat/bindings/openssl/x509_vfy.py
+++ b/cryptography/hazmat/bindings/openssl/x509_vfy.py
@@ -27,10 +27,10 @@ typedef STACK_OF(ASN1_OBJECT) Cryptography_STACK_OF_ASN1_OBJECT;
"""
TYPES = """
-static const long Cryptography_HAS_X509_VERIFY_PARAM_SET_HOSTFLAGS;
static const long Cryptography_HAS_102_VERIFICATION_ERROR_CODES;
static const long Cryptography_HAS_102_VERIFICATION_PARAMS;
static const long Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST;
+static const long Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN;
static const long Cryptography_HAS_100_VERIFICATION_ERROR_CODES;
static const long Cryptography_HAS_100_VERIFICATION_PARAMS;
static const long Cryptography_HAS_X509_V_FLAG_CHECK_SS_SIGNATURE;
@@ -186,10 +186,10 @@ void X509_STORE_CTX_set0_crls(X509_STORE_CTX *,
Cryptography_STACK_OF_X509_CRL *);
/* X509_VERIFY_PARAM */
-int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *, const unsigned char *,
+int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *, const char *,
size_t);
void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *, unsigned int);
-int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *, const unsigned char *,
+int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *, const char *,
size_t);
int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *, const unsigned char *,
size_t);
@@ -197,15 +197,6 @@ int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *, const char *);
"""
CUSTOMIZATIONS = """
-/* OpenSSL 1.0.2+, but only some very new releases */
-#ifdef X509_VERIFY_PARAM_set_hostflags
-static const long Cryptography_HAS_X509_VERIFY_PARAM_SET_HOSTFLAGS = 1;
-#else
-static const long Cryptography_HAS_X509_VERIFY_PARAM_SET_HOSTFLAGS = 0;
-void (*X509_VERIFY_PARAM_set_hostflags)(X509_VERIFY_PARAM *,
- unsigned int) = NULL;
-#endif
-
/* OpenSSL 1.0.2+ verification error codes */
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
static const long Cryptography_HAS_102_VERIFICATION_ERROR_CODES = 1;
@@ -232,15 +223,24 @@ static const long Cryptography_HAS_102_VERIFICATION_PARAMS = 0;
static const long X509_V_FLAG_SUITEB_128_LOS_ONLY = 0;
static const long X509_V_FLAG_SUITEB_192_LOS = 0;
static const long X509_V_FLAG_SUITEB_128_LOS = 0;
-static const long X509_V_FLAG_PARTIAL_CHAIN = 0;
-int (*X509_VERIFY_PARAM_set1_host)(X509_VERIFY_PARAM *, const unsigned char *,
+int (*X509_VERIFY_PARAM_set1_host)(X509_VERIFY_PARAM *, const char *,
size_t) = NULL;
-int (*X509_VERIFY_PARAM_set1_email)(X509_VERIFY_PARAM *, const unsigned char *,
+int (*X509_VERIFY_PARAM_set1_email)(X509_VERIFY_PARAM *, const char *,
size_t) = NULL;
int (*X509_VERIFY_PARAM_set1_ip)(X509_VERIFY_PARAM *, const unsigned char *,
size_t) = NULL;
int (*X509_VERIFY_PARAM_set1_ip_asc)(X509_VERIFY_PARAM *, const char *) = NULL;
+void (*X509_VERIFY_PARAM_set_hostflags)(X509_VERIFY_PARAM *,
+ unsigned int) = NULL;
+#endif
+
+/* OpenSSL 1.0.2+ or Solaris's backport */
+#ifdef X509_V_FLAG_PARTIAL_CHAIN
+static const long Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN = 1;
+#else
+static const long Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN = 0;
+static const long X509_V_FLAG_PARTIAL_CHAIN = 0;
#endif
/* OpenSSL 1.0.2+, *or* Fedora 20's flavor of OpenSSL 1.0.1e... */
@@ -286,9 +286,6 @@ static const long X509_V_FLAG_CHECK_SS_SIGNATURE = 0;
"""
CONDITIONAL_NAMES = {
- "Cryptography_HAS_X509_VERIFY_PARAM_SET_HOSTFLAGS": [
- "X509_VERIFY_PARAM_set_hostflags",
- ],
"Cryptography_HAS_102_VERIFICATION_ERROR_CODES": [
'X509_V_ERR_SUITE_B_INVALID_VERSION',
'X509_V_ERR_SUITE_B_INVALID_ALGORITHM',
@@ -304,16 +301,18 @@ CONDITIONAL_NAMES = {
"X509_V_FLAG_SUITEB_128_LOS_ONLY",
"X509_V_FLAG_SUITEB_192_LOS",
"X509_V_FLAG_SUITEB_128_LOS",
- "X509_V_FLAG_PARTIAL_CHAIN",
-
"X509_VERIFY_PARAM_set1_host",
"X509_VERIFY_PARAM_set1_email",
"X509_VERIFY_PARAM_set1_ip",
"X509_VERIFY_PARAM_set1_ip_asc",
+ "X509_VERIFY_PARAM_set_hostflags",
],
"Cryptography_HAS_X509_V_FLAG_TRUSTED_FIRST": [
"X509_V_FLAG_TRUSTED_FIRST",
],
+ "Cryptography_HAS_X509_V_FLAG_PARTIAL_CHAIN": [
+ "X509_V_FLAG_PARTIAL_CHAIN",
+ ],
"Cryptography_HAS_100_VERIFICATION_ERROR_CODES": [
'X509_V_ERR_DIFFERENT_CRL_SCOPE',
'X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE',
diff --git a/cryptography/hazmat/primitives/constant_time.py b/cryptography/hazmat/primitives/constant_time.py
index 9789851a..d75528a8 100644
--- a/cryptography/hazmat/primitives/constant_time.py
+++ b/cryptography/hazmat/primitives/constant_time.py
@@ -14,37 +14,20 @@
from __future__ import absolute_import, division, print_function
import hmac
+import os
import sys
import cffi
from cryptography.hazmat.bindings.utils import _create_modulename
-TYPES = """
-uint8_t Cryptography_constant_time_bytes_eq(uint8_t *, size_t, uint8_t *,
- size_t);
-"""
-FUNCTIONS = """
-uint8_t Cryptography_constant_time_bytes_eq(uint8_t *a, size_t len_a,
- uint8_t *b, size_t len_b) {
- size_t i = 0;
- uint8_t mismatch = 0;
- if (len_a != len_b) {
- return 0;
- }
- for (i = 0; i < len_a; i++) {
- mismatch |= a[i] ^ b[i];
- }
+with open(os.path.join(os.path.dirname(__file__), "src/constant_time.h")) as f:
+ TYPES = f.read()
+
+with open(os.path.join(os.path.dirname(__file__), "src/constant_time.c")) as f:
+ FUNCTIONS = f.read()
- /* Make sure any bits set are copied to the lowest bit */
- mismatch |= mismatch >> 4;
- mismatch |= mismatch >> 2;
- mismatch |= mismatch >> 1;
- /* Now check the low bit to see if it's set */
- return (mismatch & 1) == 0;
-}
-"""
_ffi = cffi.FFI()
_ffi.cdef(TYPES)
diff --git a/cryptography/hazmat/primitives/src/constant_time.c b/cryptography/hazmat/primitives/src/constant_time.c
new file mode 100644
index 00000000..13ac4ab9
--- /dev/null
+++ b/cryptography/hazmat/primitives/src/constant_time.c
@@ -0,0 +1,31 @@
+// 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.
+
+uint8_t Cryptography_constant_time_bytes_eq(uint8_t *a, size_t len_a,
+ uint8_t *b, size_t len_b) {
+ size_t i = 0;
+ uint8_t mismatch = 0;
+ if (len_a != len_b) {
+ return 0;
+ }
+ for (i = 0; i < len_a; i++) {
+ mismatch |= a[i] ^ b[i];
+ }
+
+ /* Make sure any bits set are copied to the lowest bit */
+ mismatch |= mismatch >> 4;
+ mismatch |= mismatch >> 2;
+ mismatch |= mismatch >> 1;
+ /* Now check the low bit to see if it's set */
+ return (mismatch & 1) == 0;
+}
diff --git a/cryptography/hazmat/primitives/src/constant_time.h b/cryptography/hazmat/primitives/src/constant_time.h
new file mode 100644
index 00000000..4f41034e
--- /dev/null
+++ b/cryptography/hazmat/primitives/src/constant_time.h
@@ -0,0 +1,16 @@
+// 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.
+
+
+uint8_t Cryptography_constant_time_bytes_eq(uint8_t *, size_t, uint8_t *,
+ size_t);
diff --git a/docs/hazmat/primitives/mac/index.rst b/docs/hazmat/primitives/mac/index.rst
index acfe9bed..bc54bae4 100644
--- a/docs/hazmat/primitives/mac/index.rst
+++ b/docs/hazmat/primitives/mac/index.rst
@@ -1,6 +1,6 @@
.. hazmat::
-Message Authentication Codes
+Message authentication codes
============================
While cryptography supports both the CMAC and HMAC algorithms, we strongly
diff --git a/docs/installation.rst b/docs/installation.rst
index 6b8bb219..76f0439a 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -28,6 +28,7 @@ OpenSSL releases:
* ``OpenSSL 0.9.8y``
* ``OpenSSL 1.0.0-fips`` (``RHEL/CentOS 6.4``)
* ``OpenSSL 1.0.1``
+* ``OpenSSL 1.0.1e-fips`` (``RHEL/CentOS 7``)
* ``OpenSSL 1.0.1e-freebsd``
* ``OpenSSL 1.0.1h``
* ``OpenSSL 1.0.2 beta``
diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
index d90547a8..b16026f6 100644
--- a/docs/spelling_wordlist.txt
+++ b/docs/spelling_wordlist.txt
@@ -38,8 +38,10 @@ plaintext
preprocessor
preprocessors
pseudorandom
+pyOpenSSL
Schneier
scrypt
+Solaris
Tanja
testability
Ubuntu
diff --git a/setup.py b/setup.py
index f73394ee..347dbe82 100644
--- a/setup.py
+++ b/setup.py
@@ -14,6 +14,7 @@
from __future__ import absolute_import, division, print_function
import os
+import platform
import subprocess
import sys
from distutils.command.build import build
@@ -32,13 +33,15 @@ with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f:
exec(f.read(), about)
+SETUPTOOLS_DEPENDENCY = "setuptools"
CFFI_DEPENDENCY = "cffi>=0.8"
SIX_DEPENDENCY = "six>=1.4.1"
VECTORS_DEPENDENCY = "cryptography_vectors=={0}".format(about['__version__'])
requirements = [
CFFI_DEPENDENCY,
- SIX_DEPENDENCY
+ SIX_DEPENDENCY,
+ SETUPTOOLS_DEPENDENCY
]
# If you add a new dep here you probably need to add it in the tox.ini as well
@@ -55,6 +58,21 @@ if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")):
test_requirements.append(VECTORS_DEPENDENCY)
+def cc_is_available():
+ return sys.platform == "darwin" and list(map(
+ int, platform.mac_ver()[0].split("."))) >= [10, 8, 0]
+
+
+backends = [
+ "openssl = cryptography.hazmat.backends.openssl:backend"
+]
+
+if cc_is_available():
+ backends.append(
+ "commoncrypto = cryptography.hazmat.backends.commoncrypto:backend",
+ )
+
+
def get_ext_modules():
from cryptography.hazmat.bindings.commoncrypto.binding import (
Binding as CommonCryptoBinding
@@ -69,7 +87,7 @@ def get_ext_modules():
constant_time._ffi.verifier.get_extension(),
padding._ffi.verifier.get_extension()
]
- if CommonCryptoBinding.is_available():
+ if cc_is_available():
ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension())
return ext_modules
@@ -161,6 +179,7 @@ setup(
],
packages=find_packages(exclude=["tests", "tests.*"]),
+ include_package_data=True,
install_requires=requirements,
setup_requires=requirements,
@@ -173,5 +192,9 @@ setup(
"build": CFFIBuild,
"install": CFFIInstall,
"test": PyTest,
+ },
+
+ entry_points={
+ "cryptography.backends": backends,
}
)
diff --git a/tests/hazmat/backends/test_commoncrypto.py b/tests/hazmat/backends/test_commoncrypto.py
index e2c6f4a0..28d1a6ca 100644
--- a/tests/hazmat/backends/test_commoncrypto.py
+++ b/tests/hazmat/backends/test_commoncrypto.py
@@ -17,7 +17,7 @@ import pytest
from cryptography import utils
from cryptography.exceptions import InternalError, _Reasons
-from cryptography.hazmat.bindings.commoncrypto.binding import Binding
+from cryptography.hazmat.backends import _available_backends
from cryptography.hazmat.primitives import interfaces
from cryptography.hazmat.primitives.ciphers.algorithms import AES
from cryptography.hazmat.primitives.ciphers.base import Cipher
@@ -32,7 +32,8 @@ class DummyCipher(object):
block_size = 128
-@pytest.mark.skipif(not Binding.is_available(),
+@pytest.mark.skipif("commoncrypto" not in
+ [i.name for i in _available_backends()],
reason="CommonCrypto not available")
class TestCommonCrypto(object):
def test_supports_cipher(self):
diff --git a/tests/hazmat/bindings/test_commoncrypto.py b/tests/hazmat/bindings/test_commoncrypto.py
index 0332674b..71c832ef 100644
--- a/tests/hazmat/bindings/test_commoncrypto.py
+++ b/tests/hazmat/bindings/test_commoncrypto.py
@@ -15,10 +15,12 @@ from __future__ import absolute_import, division, print_function
import pytest
+from cryptography.hazmat.backends import _available_backends
from cryptography.hazmat.bindings.commoncrypto.binding import Binding
-@pytest.mark.skipif(not Binding.is_available(),
+@pytest.mark.skipif("commoncrypto" not in
+ [i.name for i in _available_backends()],
reason="CommonCrypto not available")
class TestCommonCrypto(object):
def test_binding_loads(self):
diff --git a/tests/hazmat/bindings/test_openssl.py b/tests/hazmat/bindings/test_openssl.py
index d22c4fd2..ca6e9ab0 100644
--- a/tests/hazmat/bindings/test_openssl.py
+++ b/tests/hazmat/bindings/test_openssl.py
@@ -27,9 +27,6 @@ class TestOpenSSL(object):
assert binding.lib
assert binding.ffi
- def test_is_available(self):
- assert Binding.is_available() is True
-
def test_crypto_lock_init(self):
b = Binding()
b.init_static_locks()
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py
index e53ff06b..88b30d61 100644
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -1616,6 +1616,8 @@ class TestRSAEncryption(object):
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING):
public_key.encrypt(b"somedata", DummyPadding())
+ with pytest.raises(TypeError):
+ public_key.encrypt(b"somedata", padding=object())
def test_unsupported_oaep_mgf(self, backend):
private_key = RSA_KEY_512.private_key(backend)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 4673b49e..da3b1a2a 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -30,9 +30,9 @@ from .utils import (
check_backend_support, check_for_iface, der_encode_dsa_signature,
load_cryptrec_vectors, load_fips_dsa_key_pair_vectors,
load_fips_dsa_sig_vectors, load_fips_ecdsa_key_pair_vectors,
- load_fips_ecdsa_signing_vectors, load_hash_vectors, load_nist_vectors,
- load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file,
- raises_unsupported_algorithm, select_backends
+ load_fips_ecdsa_signing_vectors, load_hash_vectors, load_kasvs_dh_vectors,
+ load_nist_vectors, load_pkcs1_vectors, load_rsa_nist_vectors,
+ load_vectors_from_file, raises_unsupported_algorithm, select_backends
)
@@ -2626,6 +2626,459 @@ bdcf3035f6829ede041b745955d219dc5d30ddd8b37f6ba0f6d2857504cdc68a1ed812a10
assert expected == load_fips_ecdsa_signing_vectors(vector_data)
+def test_load_kasvs_dh_vectors():
+ vector_data = textwrap.dedent("""
+ [SHA(s) supported (Used for hashing Z): SHA256 ]
+ # Generated on Thu Mar 17 20:44:26 2011
+
+
+
+ [FA - SHA1]
+ P = da3a8085d372437805de95b88b675122f575df976610c6a844de99f1df82a06848bf7a\
+42f18895c97402e81118e01a00d0855d51922f434c022350861d58ddf60d65bc6941fc6064b147\
+071a4c30426d82fc90d888f94990267c64beef8c304a4b2b26fb93724d6a9472fa16bc50c5b9b8\
+b59afb62cfe9ea3ba042c73a6ade35
+ Q = f2ca7621eb250aa5f22cef1907011295defc50a7
+ G = a51883e9ac0539859df3d25c716437008bb4bd8ec4786eb4bc643299daef5e3e5af586\
+3a6ac40a597b83a27583f6a658d408825105b16d31b6ed088fc623f648fd6d95e9cefcb0745763\
+cddf564c87bcf4ba7928e74fd6a3080481f588d535e4c026b58a21e1e5ec412ff241b436043e29\
+173f1dc6cb943c09742de989547288
+
+
+
+ COUNT = 0
+ XstatCAVS = 42c6ee70beb7465928a1efe692d2281b8f7b53d6
+ YstatCAVS = 5a7890f6d20ee9c7162cd84222cb0c7cb5b4f29244a58fc95327fc41045f47\
+6fb3da42fca76a1dd59222a7a7c3872d5af7d8dc254e003eccdb38f291619c51911df2b6ed67d0\
+b459f4bc25819c0078777b9a1a24c72e7c037a3720a1edad5863ef5ac75ce816869c820859558d\
+5721089ddbe331f55bef741396a3bbf85c6c1a
+ XstatIUT = 54081a8fef2127a1f22ed90440b1b09c331d0614
+ YstatIUT = 0b92af0468b841ea5de4ca91d895b5e922245421de57ed7a88d2de41610b208\
+e8e233705f17b2e9eb91914bad2fa87f0a58519a7da2980bc06e7411c925a6050526bd86e62150\
+5e6f610b63fdcd9afcfaa96bd087afca44d9197cc35b559f731357a5b979250c0f3a254bb8165f\
+5072156e3fd6f9a6e69bcf4b4578f78b3bde7
+ Z = 8d8f4175e16e15a42eb9099b11528af88741cc206a088971d3064bb291eda608d1600b\
+ff829624db258fd15e95d96d3e74c6be3232afe5c855b9c59681ce13b7aea9ff2b16707e4c02f0\
+e82bf6dadf2149ac62630f6c62dea0e505e3279404da5ffd5a088e8474ae0c8726b8189cb3d2f0\
+4baffe700be849df9f91567fc2ebb8
+ CAVSHashZZ = eb99e77ac2272c7a2ee70c59375ac4d167312c20
+ Result = P (0 - Correct)
+
+
+
+ COUNT = 2
+ XstatCAVS = 32e642683d745a23dccf4f12f989d8dfd1fd9894c422930950cb4c71
+ YstatCAVS = 8cd371363b32fcc2e936e345f2278b77001f2efdf78512c3ee75c12f88507e\
+2d5c0e5cdded3bb78435506c8028a3f4d6f028c0f49a0d61f1285795197e56deac80279e723f2b\
+3746e213ac8ec60f1cefc2308ff17a7e9e2efab537e17406d2829fd85e0c54dda2d9f0b4fcda3d\
+2776110e096a817588e19588b77be8b41bafdd41ad91b0edf629333bd6ac1e461208ead124c31b\
+8a7935c723e1c450c5798dc05f8265ad9e35095ff112af9e889f00315fa337a76a450670866eca\
+12cc6ad0778576962eb9cdc12721d3c15e4d87b67488a145d400240670eb26695a42879cd3940a\
+55087f6527667277e1212a202dbe455c45c64b9be4a38153557bbb8fd755
+ XstatIUT = 7d8ae93df3bc09d399a4157ec562126acf51092c3269ab27f60a3a2b
+ YstatIUT = 22127e9728e906ea4b1512c8b1e80474b58446210c23ccfc800f83c2c15da81\
+59940e494b235266f6a9d5f80529067794f1a9edd566755d23d0a3060fe074c5a10122df3e4729\
+73bba39ea3a988e8387f5f0491e590b6b5edc299b4598ab1e79b72681a0be8cd8735a5adb85fa3\
+1310f29ec407c9654f1bb83bcdf7f771b68d176817f662e8d798b53ebb4e5dd407b7b1d8fdb62e\
+a9e1b60d6c3d75d9bcf83f4b8d1ed39408bd8d973b4ea81e8e832eac361dcd530713388a60971e\
+a9f8b1e69c1e99df1cca12bdaf293dacfa1419c5692ceffa91988aef3321ac8cbc2efae6c4337c\
+8808310fb5a240395a98e6004fe613c39e84f4177341746d9e388dcb2e8
+ Z = 0efeaa399a182e0a603baf0dd95aa0fae5289ebd47d5f0f60c86bc936839c31c9f7f37\
+bf04f76ab02f4094a8ab10ed907ec7291585cc085c3e8981df2bd46a01c19ec9a2f66709df1d4f\
+efbeb48c8263554e46890f59eb642bf95ff7f0de70138621c22c4cc32be6c3d5c82c0c9a76a9f5\
+a65bffe0c096a350f96a9da945d7e5095b15b566ce3cb8b0377cd9375b6c046afa9ea0bc084677\
+3445f16566b2c84cae4f6d212e89ee539a1ce7ea325273fd228053efce2a585eb9e8f308b48cf4\
+e29593b6f7a02e8625e1e8bff1ea1405f8c8c34b8339a9a99c7c9de4eb9895df7719ccda9394f5\
+3080eff1226f6b9c7ae0a38941e18b1a137aabbb62308eb35ba2
+ CAVSHashZZ = 76dedc997d5113573bbeeaf991f62b257511b7d9aa83270dfc4fec40
+ Result = P (10 - Z value should have leading 0 nibble )
+
+
+
+ COUNT = 3
+ XstatCAVS = 66502429aba271e2f2ee2197a2b336e5f0467f192aa28b60dcbf1194
+ YstatCAVS = dfb001294215423d7146a2453cdb8598ccef01e1d931a913c3e4ed4a3cf38a\
+912066c28e4eaf77dd80ff07183a6160bd95932f513402f864dcf7a70cbedc9b60bbfbc67f72a8\
+3d5f6463a2b5a4fc906d3e921f5e1069126113265b440e15ccf2d7164bad7131f1613fec35df7f\
+470d45888e0c91be091f3f9552d670b8b7f479853193cb3c39f35fc7bd547ccb1bc579a67302b4\
+ba948e6db51043d351bb74a952e6a694e6e7456f714c47d7c8eeeb4fd83ad93c86b78445f9393f\
+dfd65c7dbd7fd6eba9794ddf183901b1d213321fd0ab3f7588ab0f6b3692f365a87131eda0e062\
+505861988f6ce63150207545ecf9678e0971330253dfb7cfd546c5346fec
+ XstatIUT = 106b358be4f068348ac240ecbb454e5c39ca80b078cb0fafd856e9c5
+ YstatIUT = 715d0781975b7b03162f4401c1eda343fd9bf1140006034573b31828a618c35\
+6163554cd27da956f7179a69e860fb6efeaa2e2aa9f1261506a8344c4929953621381b13d6426e\
+152c0f2f94bfcd2b758eca24923596d427ed8f957e8bc9b1c7d21a87ef02222a1477cf3bfaadc6\
+8106456ab9706026006eccd290b21543de6bb97d5b8cf4ccee1c081a6d1dd27aaef060fa93888a\
+47a4a416ad5c5bd490ea600e04379232fb1077fbf394f4579accdbe352714e25b88916dca8d8f7\
+e0c4ed9594f7693f656a235a2e88ebda48b0d557e32da9f12d2a4c3180f05b16b4fba9bec79278\
+a3971b77f9223b5ab78b857e0376c5008211592c8c72d521373ee3b22b8
+ Z = cf879ebd107bb877457809c3fc410218b7acba3c5967495a8f1c3370d57f038a48dd69\
+f9f69b9f4dd855e7c58a1e4ec32646a978266eb314db468ea1dfcee8a85a1644a5732498c4fbcd\
+f85098c6ed0ce12e431e99142fd2335369b3f56620ada21aa69d883e82a0b5e35484dde32d17c2\
+dc873f2cc5518eb7fc19695dff9fc94c9d9432bb4b09d8180323cfc561ebc2d6eff8dd5f8496f2\
+b22377700a22bbfe61a6969c198129397454843e4fc3540026986039665095490056287e4fc49e\
+6cb3181cb2bf06444fd0040150271c9ce1f61c13ecd5dd022194a2dbf3e1c7fbc6bd19497c7b88\
+8b4da613d28fa6f378a43369cb8795a1c823f7d6cf4d84bba578
+ CAVSHashZZ = ebac4fb70699224f85d9e3c799b1f3a56dab268b882aba49525df02d
+ Result = F (5 - Z changed )
+
+
+
+ [FB - SHA224]
+ P = f3722b9b911c6aede9eaeeaa406283de66a097f39a7225df6c3c916e57920d356e5047\
+8d307dbfd146bfb91b6f68ecbbcf54b3d19c33a4b17293fea3e3d6bff8ac4cca93a805386f062a\
+8a27ae906ef5da94d279fd7b3d7289e00956f76bae9c0d2b8d11742ca5809630632aae58f9c6dc\
+e00c7380581deffde2187b022f83c6ceaeaadb0844a17fcbb04039ca6843c91f0c9058b22434b2\
+63c3dfda8de8429e087c5be97fc5c9db9526031ad3a218bd9916fb4a3c27966d208b1e360014c0\
+1e95530c148fb3cd27e6a7250d3c3b81dcd220ca14548dbccf99ebb9e334db6bcd14e632c98dd3\
+f9860af7ae450f1b7809b45f0ec10e6f27672beebc9963befc73
+ Q = a9a17de95a29091bf8e07dab53ea1aba9403be3c61027c6c8f48bac5
+ G = 035513ec441402b78353ab1bba550b21c76c89973885a627170262ef52497d5d137b89\
+27a212aaab2f051198c90bb81dffd9eb10b36b7ca3b63565b4c1025aea3b5e9c4a348c9cfa17f3\
+907a1e4469701c0dedb8a4b9e96c5965b1fb8c229b0c34baac774bf9dda4fc5ee8764358b3c848\
+12878aab7464bc09e97aecab7d7e3fbb4870e2a3b89667a4158bf1ed1a90dfaf47019fbb52b1b9\
+6365bb4e1e9474993fe382fd23480dc875861be152997a621fdb7aef977ea5b4d3d74486b162dc\
+28f95a64cf65587a919a57eef92934fc9410df7f09fa82f975328ed82ff29cc3e15a971f56f4ac\
+2dcb289252575e02a6cdb7fcc6cddd7b0dca9c422e63eb2b8f05
+
+
+
+ COUNT = 0
+ XstatCAVS = 1610eaa4e0ccc8857e2b53149e008492b1fbd9025a6e8d95aaee9c0f
+ YstatCAVS = 51ee21cd9f97015180f258fad5c94ff5a458806b1412087236bf77fe87aae1\
+a36735816ed6e2160a731159814b6ae1f3f52c478dd9207094adfb62f7667d5c366327e66d2309\
+6395e938504db330953a708015f861fe9d9487611093b9fe7327518a7cc15994ab573313e15411\
+7c1a3ae88b8bdd1e316748249e4a9cbd1947f159836d13613d1f9449fc3442171d1970bc28958c\
+1cafa2776a6f14ccdb29db02f64911bd83bfdcdfc843dd14a4cab9acb0bda8b293d2f5f7050768\
+e57533cbc415a29e6f31cc365e107f91ae3722484e2c7329a85af69055a5a104da37e810878896\
+d1b247b02b75234ecff82b1958f42d7b031622e9394c98b5229112f7f620
+ XstatIUT = 0c4c83d75b27864b052cadc556e500e25aabf0c9d1bc01f0e1fe3862
+ YstatIUT = 467a857337a82472a1307a64dccc8e9994c5c63ec4312936885d17be419051a\
+5f037fbb052d7010ebe01634d9e8b8b522d9ab4749fdc274f465369b89e360df8f70b7865a3c71\
+d2dbcd2df19e9293dab1153d3d63fcb7deb559b684dde6c6eed63214444807041c9a0ce3f52ca4\
+39ec16dd231995b5dc6f18e6801b6bd6454babccf9abbfacffb49c71e6494a4779cbfa550c5d71\
+44114e6fc193f460dcd0be7e6e06e546da7653770dc5859df87029e722dbe81361030569148d16\
+36988926bf0dcfe47c9d8a54698c08b3b5c70afe86b5c6f643463f8f34889d27d6cfd2d478c2d7\
+b3d008a985c7380f0b43f10024b59c3543880883c42d0e7e0a07326ba3a
+ Z = 10a30bacab82e652415376baffdbc008c7eb2e5a3aa68bc10ce486ca84983fd89b1b02\
+7bb40e75333406361005f5e756526a95fe01202df9217d81b1713d5187c368fdd4c9c2433d9e6c\
+18844769479b725c4140c92a304ee1bc5726d8f5321b5b1c54a1a6b67c527e6817c0ed613a0d4e\
+60db55de898788b7e8d4aa9a81ab5ed7f6282962c433d246ed640555bdd76d29c2874551264d74\
+c76373f8a88871b41b041c98041b16f94f983ddf00f5bc7d2416d19168c90178974a0602436cd1\
+86748bcc63a629edc3a0db59415cccd37a65130ea477c89da92d41371f5972891cf41f9c7f0e75\
+ccbff9893225384db30daa5e310f08e3e0fad98bcdf8ecf35fe5
+ CAVSHashZZ = 014f5daea733d0e9e100f852e74d64a319f741cfbdb47975ab9dd3d0
+ Result = F (3 - IUT's Static public key fails PKV 5.6.2.4)
+
+
+ COUNT = 1
+ XstatCAVS = 9ee22ac51664e40e0a24dbb94142dba40605e2b6eeaaa0268a0f6847
+ YstatCAVS = c2630c9d38ed5c825d1c6a3eba7143f3fc8a049c8bcd1efc212d2af64eca99\
+4308208691d330aa8f27fc4a1e55de4e512113996d21375a667f8c26d76dee2f6809b15432a33f\
+b735aca5c2263940f58712bded08f55443dee300b9489589e0462bd6bce19deaec4adc12fa61a6\
+94c8c5c999b28211d7835bac0ffd2b316850823e2dc1d1f58e05cbf75c673036d116b3f03b9687\
+c89f9c2a0d43c4ffc9a605addbdcce0cb3790c6db846156bb857a7b3df40dc6ed04d19cc9eaebb\
+6bbc034e77c3d882a1a62317cce25b6130f0803e3bc49b5e36768260073a617034872be0b50bed\
+32740224beaf582d67fbcfef3b3ecc18f9c71c782e9a68495ef31dc7986e
+ XstatIUT = 438093a468236658821bf64eb08456139963d4fb27121c3ed6c55876
+ YstatIUT = e192da8e1244e27221c1765344a5bb379dce741d427a734b4bdb6c4d16b2490\
+bd37564d745008e63ae46ef332331d79887ac63298ce143e125f8b320c0f859b7f5f2c1e0053e4\
+a7a16997e6143ff702300c9863ae7caef5c1dfca0ecf5197c557745b793f0790a4fe678aeb93fd\
+b52490d4f273a5553944dda3ac8b9b792c9b67f8d7b9496398e432a423ae87ebeba688be3ed67e\
+ddd7575fa56431cd48579bf53c903bbe066dd78b23c0996ef3a880f0d91315104366a82f01abde\
+cce96fd371f94e8420f8bc5b896c801df573554f749b03d0d28b1e1a990bc61c7e9659342ac7e2\
+68e9c0b7c40fdaab394f29cf0a54f780022f9a03b0bd28eb7db8b0b1b47
+ Z = 56f8f40fa4b8f3580f9014b30d60a42933a53a62182a690142f458dc275c3b2f0e721b\
+c5ee6e890b14516419110f5252ff1cceea8e274b2987aa78e3bae90c1935b276b7a1f1c944f79d\
+4774b7a85b3355bdf25cb02bddfbda4ee7918bc93a5c9ca6d7e8fdedbda8e6c8a6ca794bad055a\
+52b19c148958227344cbddd70271d4610316cfea1e559b0bc3a12d15023b30d9f2db602053a056\
+9c3bd2ce1faf59280ecd339f845dbcaaf2e883c5cc6263996f866b18b75d049d4c82097af8a5ce\
+353e14416b3eeb31ba9bc4f6f3dbd846c5299fb5c0043a1b95b9149b39d14df9e6a69547abf8a4\
+d518475576730ed528779366568e46b7dd4ed787cb72d0733c93
+ CAVSHashZZ = 17dbbaa7a20c1390cd8cb3d31ee947bf9dde87739e067b9861ffeea9
+ Result = P (0 - Correct)
+ """).splitlines()
+
+ expected = [
+ {
+ 'fail_agree': False,
+ 'fail_z': False,
+ 'g': int(
+ "a51883e9ac0539859df3d25c716437008bb4bd8ec4786eb4bc643299daef5"
+ "e3e5af5863a6ac40a597b83a27583f6a658d408825105b16d31b6ed088fc6"
+ "23f648fd6d95e9cefcb0745763cddf564c87bcf4ba7928e74fd6a3080481f"
+ "588d535e4c026b58a21e1e5ec412ff241b436043e29173f1dc6cb943c0974"
+ "2de989547288", 16),
+ 'p': int(
+ "da3a8085d372437805de95b88b675122f575df976610c6a844de99f1df82a"
+ "06848bf7a42f18895c97402e81118e01a00d0855d51922f434c022350861d"
+ "58ddf60d65bc6941fc6064b147071a4c30426d82fc90d888f94990267c64b"
+ "eef8c304a4b2b26fb93724d6a9472fa16bc50c5b9b8b59afb62cfe9ea3ba0"
+ "42c73a6ade35", 16),
+ 'q': 1386090807861091316803998193774751098153687863463,
+ 'x1': 381229709512864262422021151581620734547375903702,
+ 'x2': 479735944608461101114916716909067001453470352916,
+ 'y1': int(
+ "5a7890f6d20ee9c7162cd84222cb0c7cb5b4f29244a58fc95327fc41045f4"
+ "76fb3da42fca76a1dd59222a7a7c3872d5af7d8dc254e003eccdb38f29161"
+ "9c51911df2b6ed67d0b459f4bc25819c0078777b9a1a24c72e7c037a3720a"
+ "1edad5863ef5ac75ce816869c820859558d5721089ddbe331f55bef741396"
+ "a3bbf85c6c1a", 16),
+ 'y2': int(
+ "b92af0468b841ea5de4ca91d895b5e922245421de57ed7a88d2de41610b20"
+ "8e8e233705f17b2e9eb91914bad2fa87f0a58519a7da2980bc06e7411c925"
+ "a6050526bd86e621505e6f610b63fdcd9afcfaa96bd087afca44d9197cc35"
+ "b559f731357a5b979250c0f3a254bb8165f5072156e3fd6f9a6e69bcf4b45"
+ "78f78b3bde7", 16),
+ 'z': binascii.unhexlify(
+ b"8d8f4175e16e15a42eb9099b11528af88741cc206a088971d3064bb291ed"
+ b"a608d1600bff829624db258fd15e95d96d3e74c6be3232afe5c855b9c596"
+ b"81ce13b7aea9ff2b16707e4c02f0e82bf6dadf2149ac62630f6c62dea0e5"
+ b"05e3279404da5ffd5a088e8474ae0c8726b8189cb3d2f04baffe700be849"
+ b"df9f91567fc2ebb8"
+ )
+ },
+ {
+ 'fail_agree': False,
+ 'fail_z': False,
+ 'g': int(
+ "a51883e9ac0539859df3d25c716437008bb4bd8ec4786eb4bc643299daef5"
+ "e3e5af5863a6ac40a597b83a27583f6a658d408825105b16d31b6ed088fc6"
+ "23f648fd6d95e9cefcb0745763cddf564c87bcf4ba7928e74fd6a3080481f"
+ "588d535e4c026b58a21e1e5ec412ff241b436043e29173f1dc6cb943c0974"
+ "2de989547288", 16),
+ 'p': int(
+ "da3a8085d372437805de95b88b675122f575df976610c6a844de99f1df82a"
+ "06848bf7a42f18895c97402e81118e01a00d0855d51922f434c022350861d"
+ "58ddf60d65bc6941fc6064b147071a4c30426d82fc90d888f94990267c64b"
+ "eef8c304a4b2b26fb93724d6a9472fa16bc50c5b9b8b59afb62cfe9ea3ba0"
+ "42c73a6ade35", 16),
+ 'q': 1386090807861091316803998193774751098153687863463,
+ 'x1': int(
+ "32e642683d745a23dccf4f12f989d8dfd1fd9894c422930950cb4c71",
+ 16),
+ 'x2': int(
+ "7d8ae93df3bc09d399a4157ec562126acf51092c3269ab27f60a3a2b",
+ 16),
+ 'y1': int(
+ "8cd371363b32fcc2e936e345f2278b77001f2efdf78512c3ee75c12f88507"
+ "e2d5c0e5cdded3bb78435506c8028a3f4d6f028c0f49a0d61f1285795197e"
+ "56deac80279e723f2b3746e213ac8ec60f1cefc2308ff17a7e9e2efab537e"
+ "17406d2829fd85e0c54dda2d9f0b4fcda3d2776110e096a817588e19588b7"
+ "7be8b41bafdd41ad91b0edf629333bd6ac1e461208ead124c31b8a7935c72"
+ "3e1c450c5798dc05f8265ad9e35095ff112af9e889f00315fa337a76a4506"
+ "70866eca12cc6ad0778576962eb9cdc12721d3c15e4d87b67488a145d4002"
+ "40670eb26695a42879cd3940a55087f6527667277e1212a202dbe455c45c6"
+ "4b9be4a38153557bbb8fd755", 16),
+ 'y2': int(
+ "22127e9728e906ea4b1512c8b1e80474b58446210c23ccfc800f83c2c15da"
+ "8159940e494b235266f6a9d5f80529067794f1a9edd566755d23d0a3060fe"
+ "074c5a10122df3e472973bba39ea3a988e8387f5f0491e590b6b5edc299b4"
+ "598ab1e79b72681a0be8cd8735a5adb85fa31310f29ec407c9654f1bb83bc"
+ "df7f771b68d176817f662e8d798b53ebb4e5dd407b7b1d8fdb62ea9e1b60d"
+ "6c3d75d9bcf83f4b8d1ed39408bd8d973b4ea81e8e832eac361dcd5307133"
+ "88a60971ea9f8b1e69c1e99df1cca12bdaf293dacfa1419c5692ceffa9198"
+ "8aef3321ac8cbc2efae6c4337c8808310fb5a240395a98e6004fe613c39e8"
+ "4f4177341746d9e388dcb2e8", 16),
+ 'z': binascii.unhexlify(
+ b"0efeaa399a182e0a603baf0dd95aa0fae5289ebd47d5f0f60c86bc936839"
+ b"c31c9f7f37bf04f76ab02f4094a8ab10ed907ec7291585cc085c3e8981df"
+ b"2bd46a01c19ec9a2f66709df1d4fefbeb48c8263554e46890f59eb642bf9"
+ b"5ff7f0de70138621c22c4cc32be6c3d5c82c0c9a76a9f5a65bffe0c096a3"
+ b"50f96a9da945d7e5095b15b566ce3cb8b0377cd9375b6c046afa9ea0bc08"
+ b"46773445f16566b2c84cae4f6d212e89ee539a1ce7ea325273fd228053ef"
+ b"ce2a585eb9e8f308b48cf4e29593b6f7a02e8625e1e8bff1ea1405f8c8c3"
+ b"4b8339a9a99c7c9de4eb9895df7719ccda9394f53080eff1226f6b9c7ae0"
+ b"a38941e18b1a137aabbb62308eb35ba2"
+ )
+ },
+ {
+ 'fail_agree': False,
+ 'fail_z': True,
+ 'g': int(
+ "a51883e9ac0539859df3d25c716437008bb4bd8ec4786eb4bc643299daef5"
+ "e3e5af5863a6ac40a597b83a27583f6a658d408825105b16d31b6ed088fc6"
+ "23f648fd6d95e9cefcb0745763cddf564c87bcf4ba7928e74fd6a3080481f"
+ "588d535e4c026b58a21e1e5ec412ff241b436043e29173f1dc6cb943c0974"
+ "2de989547288", 16),
+ 'p': int(
+ "da3a8085d372437805de95b88b675122f575df976610c6a844de99f1df82a"
+ "06848bf7a42f18895c97402e81118e01a00d0855d51922f434c022350861d"
+ "58ddf60d65bc6941fc6064b147071a4c30426d82fc90d888f94990267c64b"
+ "eef8c304a4b2b26fb93724d6a9472fa16bc50c5b9b8b59afb62cfe9ea3ba0"
+ "42c73a6ade35", 16),
+ 'q': 1386090807861091316803998193774751098153687863463,
+ 'x1': int(
+ "66502429aba271e2f2ee2197a2b336e5f0467f192aa28b60dcbf1194",
+ 16),
+ 'x2': int(
+ "106b358be4f068348ac240ecbb454e5c39ca80b078cb0fafd856e9c5",
+ 16),
+ 'y1': int(
+ "dfb001294215423d7146a2453cdb8598ccef01e1d931a913c3e4ed4a3cf38"
+ "a912066c28e4eaf77dd80ff07183a6160bd95932f513402f864dcf7a70cbe"
+ "dc9b60bbfbc67f72a83d5f6463a2b5a4fc906d3e921f5e1069126113265b4"
+ "40e15ccf2d7164bad7131f1613fec35df7f470d45888e0c91be091f3f9552"
+ "d670b8b7f479853193cb3c39f35fc7bd547ccb1bc579a67302b4ba948e6db"
+ "51043d351bb74a952e6a694e6e7456f714c47d7c8eeeb4fd83ad93c86b784"
+ "45f9393fdfd65c7dbd7fd6eba9794ddf183901b1d213321fd0ab3f7588ab0"
+ "f6b3692f365a87131eda0e062505861988f6ce63150207545ecf9678e0971"
+ "330253dfb7cfd546c5346fec", 16),
+ 'y2': int(
+ "715d0781975b7b03162f4401c1eda343fd9bf1140006034573b31828a618c"
+ "356163554cd27da956f7179a69e860fb6efeaa2e2aa9f1261506a8344c492"
+ "9953621381b13d6426e152c0f2f94bfcd2b758eca24923596d427ed8f957e"
+ "8bc9b1c7d21a87ef02222a1477cf3bfaadc68106456ab9706026006eccd29"
+ "0b21543de6bb97d5b8cf4ccee1c081a6d1dd27aaef060fa93888a47a4a416"
+ "ad5c5bd490ea600e04379232fb1077fbf394f4579accdbe352714e25b8891"
+ "6dca8d8f7e0c4ed9594f7693f656a235a2e88ebda48b0d557e32da9f12d2a"
+ "4c3180f05b16b4fba9bec79278a3971b77f9223b5ab78b857e0376c500821"
+ "1592c8c72d521373ee3b22b8", 16),
+ 'z': binascii.unhexlify(
+ b"cf879ebd107bb877457809c3fc410218b7acba3c5967495a8f1c3370d57f"
+ b"038a48dd69f9f69b9f4dd855e7c58a1e4ec32646a978266eb314db468ea1"
+ b"dfcee8a85a1644a5732498c4fbcdf85098c6ed0ce12e431e99142fd23353"
+ b"69b3f56620ada21aa69d883e82a0b5e35484dde32d17c2dc873f2cc5518e"
+ b"b7fc19695dff9fc94c9d9432bb4b09d8180323cfc561ebc2d6eff8dd5f84"
+ b"96f2b22377700a22bbfe61a6969c198129397454843e4fc3540026986039"
+ b"665095490056287e4fc49e6cb3181cb2bf06444fd0040150271c9ce1f61c"
+ b"13ecd5dd022194a2dbf3e1c7fbc6bd19497c7b888b4da613d28fa6f378a4"
+ b"3369cb8795a1c823f7d6cf4d84bba578"
+ )
+ },
+ {
+ 'fail_agree': True,
+ 'fail_z': False,
+ 'g': int(
+ "35513ec441402b78353ab1bba550b21c76c89973885a627170262ef52497d"
+ "5d137b8927a212aaab2f051198c90bb81dffd9eb10b36b7ca3b63565b4c10"
+ "25aea3b5e9c4a348c9cfa17f3907a1e4469701c0dedb8a4b9e96c5965b1fb"
+ "8c229b0c34baac774bf9dda4fc5ee8764358b3c84812878aab7464bc09e97"
+ "aecab7d7e3fbb4870e2a3b89667a4158bf1ed1a90dfaf47019fbb52b1b963"
+ "65bb4e1e9474993fe382fd23480dc875861be152997a621fdb7aef977ea5b"
+ "4d3d74486b162dc28f95a64cf65587a919a57eef92934fc9410df7f09fa82"
+ "f975328ed82ff29cc3e15a971f56f4ac2dcb289252575e02a6cdb7fcc6cdd"
+ "d7b0dca9c422e63eb2b8f05", 16),
+ 'p': int(
+ "f3722b9b911c6aede9eaeeaa406283de66a097f39a7225df6c3c916e57920"
+ "d356e50478d307dbfd146bfb91b6f68ecbbcf54b3d19c33a4b17293fea3e3"
+ "d6bff8ac4cca93a805386f062a8a27ae906ef5da94d279fd7b3d7289e0095"
+ "6f76bae9c0d2b8d11742ca5809630632aae58f9c6dce00c7380581deffde2"
+ "187b022f83c6ceaeaadb0844a17fcbb04039ca6843c91f0c9058b22434b26"
+ "3c3dfda8de8429e087c5be97fc5c9db9526031ad3a218bd9916fb4a3c2796"
+ "6d208b1e360014c01e95530c148fb3cd27e6a7250d3c3b81dcd220ca14548"
+ "dbccf99ebb9e334db6bcd14e632c98dd3f9860af7ae450f1b7809b45f0ec1"
+ "0e6f27672beebc9963befc73", 16),
+ 'q': int(
+ "a9a17de95a29091bf8e07dab53ea1aba9403be3c61027c6c8f48bac5",
+ 16),
+ 'x1': int(
+ "1610eaa4e0ccc8857e2b53149e008492b1fbd9025a6e8d95aaee9c0f",
+ 16),
+ 'x2': int(
+ "c4c83d75b27864b052cadc556e500e25aabf0c9d1bc01f0e1fe3862",
+ 16),
+ 'y1': int(
+ "51ee21cd9f97015180f258fad5c94ff5a458806b1412087236bf77fe87aae"
+ "1a36735816ed6e2160a731159814b6ae1f3f52c478dd9207094adfb62f766"
+ "7d5c366327e66d23096395e938504db330953a708015f861fe9d948761109"
+ "3b9fe7327518a7cc15994ab573313e154117c1a3ae88b8bdd1e316748249e"
+ "4a9cbd1947f159836d13613d1f9449fc3442171d1970bc28958c1cafa2776"
+ "a6f14ccdb29db02f64911bd83bfdcdfc843dd14a4cab9acb0bda8b293d2f5"
+ "f7050768e57533cbc415a29e6f31cc365e107f91ae3722484e2c7329a85af"
+ "69055a5a104da37e810878896d1b247b02b75234ecff82b1958f42d7b0316"
+ "22e9394c98b5229112f7f620", 16),
+ 'y2': int(
+ "467a857337a82472a1307a64dccc8e9994c5c63ec4312936885d17be41905"
+ "1a5f037fbb052d7010ebe01634d9e8b8b522d9ab4749fdc274f465369b89e"
+ "360df8f70b7865a3c71d2dbcd2df19e9293dab1153d3d63fcb7deb559b684"
+ "dde6c6eed63214444807041c9a0ce3f52ca439ec16dd231995b5dc6f18e68"
+ "01b6bd6454babccf9abbfacffb49c71e6494a4779cbfa550c5d7144114e6f"
+ "c193f460dcd0be7e6e06e546da7653770dc5859df87029e722dbe81361030"
+ "569148d1636988926bf0dcfe47c9d8a54698c08b3b5c70afe86b5c6f64346"
+ "3f8f34889d27d6cfd2d478c2d7b3d008a985c7380f0b43f10024b59c35438"
+ "80883c42d0e7e0a07326ba3a", 16),
+ 'z': binascii.unhexlify(
+ b"10a30bacab82e652415376baffdbc008c7eb2e5a3aa68bc10ce486ca8498"
+ b"3fd89b1b027bb40e75333406361005f5e756526a95fe01202df9217d81b1"
+ b"713d5187c368fdd4c9c2433d9e6c18844769479b725c4140c92a304ee1bc"
+ b"5726d8f5321b5b1c54a1a6b67c527e6817c0ed613a0d4e60db55de898788"
+ b"b7e8d4aa9a81ab5ed7f6282962c433d246ed640555bdd76d29c287455126"
+ b"4d74c76373f8a88871b41b041c98041b16f94f983ddf00f5bc7d2416d191"
+ b"68c90178974a0602436cd186748bcc63a629edc3a0db59415cccd37a6513"
+ b"0ea477c89da92d41371f5972891cf41f9c7f0e75ccbff9893225384db30d"
+ b"aa5e310f08e3e0fad98bcdf8ecf35fe5"
+ )
+ },
+ {
+ 'fail_agree': False,
+ 'fail_z': False,
+ 'g': int("35513ec441402b78353ab1bba550b21c76c89973885a627170262ef5"
+ "2497d5d137b8927a212aaab2f051198c90bb81dffd9eb10b36b7ca3b"
+ "63565b4c1025aea3b5e9c4a348c9cfa17f3907a1e4469701c0dedb8a"
+ "4b9e96c5965b1fb8c229b0c34baac774bf9dda4fc5ee8764358b3c84"
+ "812878aab7464bc09e97aecab7d7e3fbb4870e2a3b89667a4158bf1e"
+ "d1a90dfaf47019fbb52b1b96365bb4e1e9474993fe382fd23480dc87"
+ "5861be152997a621fdb7aef977ea5b4d3d74486b162dc28f95a64cf6"
+ "5587a919a57eef92934fc9410df7f09fa82f975328ed82ff29cc3e15"
+ "a971f56f4ac2dcb289252575e02a6cdb7fcc6cddd7b0dca9c422e63e"
+ "b2b8f05", 16),
+ 'p': int("f3722b9b911c6aede9eaeeaa406283de66a097f39a7225df6c3c916e"
+ "57920d356e50478d307dbfd146bfb91b6f68ecbbcf54b3d19c33a4b1"
+ "7293fea3e3d6bff8ac4cca93a805386f062a8a27ae906ef5da94d279"
+ "fd7b3d7289e00956f76bae9c0d2b8d11742ca5809630632aae58f9c6"
+ "dce00c7380581deffde2187b022f83c6ceaeaadb0844a17fcbb04039"
+ "ca6843c91f0c9058b22434b263c3dfda8de8429e087c5be97fc5c9db"
+ "9526031ad3a218bd9916fb4a3c27966d208b1e360014c01e95530c14"
+ "8fb3cd27e6a7250d3c3b81dcd220ca14548dbccf99ebb9e334db6bcd"
+ "14e632c98dd3f9860af7ae450f1b7809b45f0ec10e6f27672beebc99"
+ "63befc73", 16),
+ 'q': int(
+ "a9a17de95a29091bf8e07dab53ea1aba9403be3c61027c6c8f48bac5",
+ 16),
+ 'x1': int(
+ "9ee22ac51664e40e0a24dbb94142dba40605e2b6eeaaa0268a0f6847",
+ 16),
+ 'x2': int(
+ "438093a468236658821bf64eb08456139963d4fb27121c3ed6c55876",
+ 16),
+ 'y1': int(
+ "c2630c9d38ed5c825d1c6a3eba7143f3fc8a049c8bcd1efc212d2af64eca9"
+ "94308208691d330aa8f27fc4a1e55de4e512113996d21375a667f8c26d76d"
+ "ee2f6809b15432a33fb735aca5c2263940f58712bded08f55443dee300b94"
+ "89589e0462bd6bce19deaec4adc12fa61a694c8c5c999b28211d7835bac0f"
+ "fd2b316850823e2dc1d1f58e05cbf75c673036d116b3f03b9687c89f9c2a0"
+ "d43c4ffc9a605addbdcce0cb3790c6db846156bb857a7b3df40dc6ed04d19"
+ "cc9eaebb6bbc034e77c3d882a1a62317cce25b6130f0803e3bc49b5e36768"
+ "260073a617034872be0b50bed32740224beaf582d67fbcfef3b3ecc18f9c7"
+ "1c782e9a68495ef31dc7986e", 16),
+ 'y2': int(
+ "e192da8e1244e27221c1765344a5bb379dce741d427a734b4bdb6c4d16b24"
+ "90bd37564d745008e63ae46ef332331d79887ac63298ce143e125f8b320c0"
+ "f859b7f5f2c1e0053e4a7a16997e6143ff702300c9863ae7caef5c1dfca0e"
+ "cf5197c557745b793f0790a4fe678aeb93fdb52490d4f273a5553944dda3a"
+ "c8b9b792c9b67f8d7b9496398e432a423ae87ebeba688be3ed67eddd7575f"
+ "a56431cd48579bf53c903bbe066dd78b23c0996ef3a880f0d91315104366a"
+ "82f01abdecce96fd371f94e8420f8bc5b896c801df573554f749b03d0d28b"
+ "1e1a990bc61c7e9659342ac7e268e9c0b7c40fdaab394f29cf0a54f780022"
+ "f9a03b0bd28eb7db8b0b1b47", 16),
+ 'z': binascii.unhexlify(
+ b"56f8f40fa4b8f3580f9014b30d60a42933a53a62182a690142f458dc275c"
+ b"3b2f0e721bc5ee6e890b14516419110f5252ff1cceea8e274b2987aa78e3"
+ b"bae90c1935b276b7a1f1c944f79d4774b7a85b3355bdf25cb02bddfbda4e"
+ b"e7918bc93a5c9ca6d7e8fdedbda8e6c8a6ca794bad055a52b19c14895822"
+ b"7344cbddd70271d4610316cfea1e559b0bc3a12d15023b30d9f2db602053"
+ b"a0569c3bd2ce1faf59280ecd339f845dbcaaf2e883c5cc6263996f866b18"
+ b"b75d049d4c82097af8a5ce353e14416b3eeb31ba9bc4f6f3dbd846c5299f"
+ b"b5c0043a1b95b9149b39d14df9e6a69547abf8a4d518475576730ed52877"
+ b"9366568e46b7dd4ed787cb72d0733c93"
+ )
+ }
+ ]
+
+ assert expected == load_kasvs_dh_vectors(vector_data)
+
+
def test_vector_version():
assert cryptography.__version__ == cryptography_vectors.__version__
diff --git a/tests/utils.py b/tests/utils.py
index 5c0e2343..5557ea85 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -624,3 +624,62 @@ def load_fips_ecdsa_signing_vectors(vector_data):
if data is not None:
vectors.append(data)
return vectors
+
+
+def load_kasvs_dh_vectors(vector_data):
+ """
+ Loads data out of the KASVS key exchange vector data
+ """
+
+ result_rx = re.compile(r"([FP]) \(([0-9]+) -")
+
+ vectors = []
+ data = {
+ "fail_z": False,
+ "fail_agree": False
+ }
+
+ for line in vector_data:
+ line = line.strip()
+
+ if not line or line.startswith("#"):
+ continue
+
+ if line.startswith("P = "):
+ data["p"] = int(line.split("=")[1], 16)
+ elif line.startswith("Q = "):
+ data["q"] = int(line.split("=")[1], 16)
+ elif line.startswith("G = "):
+ data["g"] = int(line.split("=")[1], 16)
+ elif line.startswith("Z = "):
+ z_hex = line.split("=")[1].strip().encode("ascii")
+ data["z"] = binascii.unhexlify(z_hex)
+ elif line.startswith("XstatCAVS = "):
+ data["x1"] = int(line.split("=")[1], 16)
+ elif line.startswith("YstatCAVS = "):
+ data["y1"] = int(line.split("=")[1], 16)
+ elif line.startswith("XstatIUT = "):
+ data["x2"] = int(line.split("=")[1], 16)
+ elif line.startswith("YstatIUT = "):
+ data["y2"] = int(line.split("=")[1], 16)
+ elif line.startswith("Result = "):
+ result_str = line.split("=")[1].strip()
+ match = result_rx.match(result_str)
+
+ if match.group(1) == "F":
+ if int(match.group(2)) in (5, 10):
+ data["fail_z"] = True
+ else:
+ data["fail_agree"] = True
+
+ vectors.append(data)
+
+ data = {
+ "p": data["p"],
+ "q": data["q"],
+ "g": data["g"],
+ "fail_z": False,
+ "fail_agree": False
+ }
+
+ return vectors
diff --git a/tox.ini b/tox.ini
index ef5e46d7..7d64be80 100644
--- a/tox.ini
+++ b/tox.ini
@@ -11,7 +11,7 @@ deps =
pytest
./vectors
commands =
- coverage run --source=cryptography/,tests/ -m pytest --capture=no --strict {posargs}
+ coverage run -m pytest --capture=no --strict {posargs}
coverage report -m
[testenv:docs]
@@ -63,3 +63,6 @@ commands =
exclude = .tox,*.egg
select = E,W,F,N,I
application-import-names = cryptography,cryptography_vectors,tests
+
+[doc8]
+extensions = rst