aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/hazmat/primitives
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2018-11-23 10:44:37 +0800
committerAlex Gaynor <alex.gaynor@gmail.com>2018-11-22 20:44:37 -0600
commit6f88e01af8f5d6db7082d155f3faf88dfb48e864 (patch)
tree42fb14caa9d24a6eca1ae9d07b69a4a502e5c200 /src/cryptography/hazmat/primitives
parent579dfcf48f013dddfd3447e6dc38cfdc0b17145c (diff)
downloadcryptography-6f88e01af8f5d6db7082d155f3faf88dfb48e864.tar.gz
cryptography-6f88e01af8f5d6db7082d155f3faf88dfb48e864.tar.bz2
cryptography-6f88e01af8f5d6db7082d155f3faf88dfb48e864.zip
X448 support (#4580)
* x448 support This work was originally authored by derwolfe * update docs to have a more useful derived key length * error if key is not a valid length in from_public_bytes * one more * switch to using evp_pkey_keygen_gc for x448 keygen * review feedback * switch to using evp_pkey_derive * nit fix
Diffstat (limited to 'src/cryptography/hazmat/primitives')
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/x448.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/x448.py b/src/cryptography/hazmat/primitives/asymmetric/x448.py
new file mode 100644
index 00000000..69bfa408
--- /dev/null
+++ b/src/cryptography/hazmat/primitives/asymmetric/x448.py
@@ -0,0 +1,61 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import abc
+
+import six
+
+from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
+
+
+@six.add_metaclass(abc.ABCMeta)
+class X448PublicKey(object):
+ @classmethod
+ def from_public_bytes(cls, data):
+ from cryptography.hazmat.backends.openssl.backend import backend
+ if not backend.x448_supported():
+ raise UnsupportedAlgorithm(
+ "X448 is not supported by this version of OpenSSL.",
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
+ )
+
+ return backend.x448_load_public_bytes(data)
+
+ @abc.abstractmethod
+ def public_bytes(self):
+ """
+ The serialized bytes of the public key.
+ """
+
+
+@six.add_metaclass(abc.ABCMeta)
+class X448PrivateKey(object):
+ @classmethod
+ def generate(cls):
+ from cryptography.hazmat.backends.openssl.backend import backend
+ if not backend.x448_supported():
+ raise UnsupportedAlgorithm(
+ "X448 is not supported by this version of OpenSSL.",
+ _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM
+ )
+ return backend.x448_generate_key()
+
+ @classmethod
+ def _from_private_bytes(cls, data):
+ from cryptography.hazmat.backends.openssl.backend import backend
+ return backend.x448_load_private_bytes(data)
+
+ @abc.abstractmethod
+ def public_key(self):
+ """
+ The serialized bytes of the public key.
+ """
+
+ @abc.abstractmethod
+ def exchange(self, peer_public_key):
+ """
+ Performs a key exchange operation using the provided peer's public key.
+ """