1# This file is dual licensed under the terms of the Apache License, Version 2# 2.0, and the BSD License. See the LICENSE file in the root of this repository 3# for complete details. 4 5from __future__ import absolute_import, division, print_function 6 7import abc 8 9import six 10 11from cryptography.exceptions import UnsupportedAlgorithm, _Reasons 12 13 14@six.add_metaclass(abc.ABCMeta) 15class X448PublicKey(object): 16 @classmethod 17 def from_public_bytes(cls, data): 18 from cryptography.hazmat.backends.openssl.backend import backend 19 20 if not backend.x448_supported(): 21 raise UnsupportedAlgorithm( 22 "X448 is not supported by this version of OpenSSL.", 23 _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, 24 ) 25 26 return backend.x448_load_public_bytes(data) 27 28 @abc.abstractmethod 29 def public_bytes(self, encoding, format): 30 """ 31 The serialized bytes of the public key. 32 """ 33 34 35@six.add_metaclass(abc.ABCMeta) 36class X448PrivateKey(object): 37 @classmethod 38 def generate(cls): 39 from cryptography.hazmat.backends.openssl.backend import backend 40 41 if not backend.x448_supported(): 42 raise UnsupportedAlgorithm( 43 "X448 is not supported by this version of OpenSSL.", 44 _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, 45 ) 46 return backend.x448_generate_key() 47 48 @classmethod 49 def from_private_bytes(cls, data): 50 from cryptography.hazmat.backends.openssl.backend import backend 51 52 if not backend.x448_supported(): 53 raise UnsupportedAlgorithm( 54 "X448 is not supported by this version of OpenSSL.", 55 _Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM, 56 ) 57 58 return backend.x448_load_private_bytes(data) 59 60 @abc.abstractmethod 61 def public_key(self): 62 """ 63 The serialized bytes of the public key. 64 """ 65 66 @abc.abstractmethod 67 def private_bytes(self, encoding, format, encryption_algorithm): 68 """ 69 The serialized bytes of the private key. 70 """ 71 72 @abc.abstractmethod 73 def exchange(self, peer_public_key): 74 """ 75 Performs a key exchange operation using the provided peer's public key. 76 """ 77