ed448.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. from __future__ import absolute_import, division, print_function
  5. import abc
  6. import six
  7. from cryptography.exceptions import UnsupportedAlgorithm, _Reasons
  8. @six.add_metaclass(abc.ABCMeta)
  9. class Ed448PublicKey(object):
  10. @classmethod
  11. def from_public_bytes(cls, data):
  12. from cryptography.hazmat.backends.openssl.backend import backend
  13. if not backend.ed448_supported():
  14. raise UnsupportedAlgorithm(
  15. "ed448 is not supported by this version of OpenSSL.",
  16. _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
  17. )
  18. return backend.ed448_load_public_bytes(data)
  19. @abc.abstractmethod
  20. def public_bytes(self, encoding, format):
  21. """
  22. The serialized bytes of the public key.
  23. """
  24. @abc.abstractmethod
  25. def verify(self, signature, data):
  26. """
  27. Verify the signature.
  28. """
  29. @six.add_metaclass(abc.ABCMeta)
  30. class Ed448PrivateKey(object):
  31. @classmethod
  32. def generate(cls):
  33. from cryptography.hazmat.backends.openssl.backend import backend
  34. if not backend.ed448_supported():
  35. raise UnsupportedAlgorithm(
  36. "ed448 is not supported by this version of OpenSSL.",
  37. _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
  38. )
  39. return backend.ed448_generate_key()
  40. @classmethod
  41. def from_private_bytes(cls, data):
  42. from cryptography.hazmat.backends.openssl.backend import backend
  43. if not backend.ed448_supported():
  44. raise UnsupportedAlgorithm(
  45. "ed448 is not supported by this version of OpenSSL.",
  46. _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM,
  47. )
  48. return backend.ed448_load_private_bytes(data)
  49. @abc.abstractmethod
  50. def public_key(self):
  51. """
  52. The Ed448PublicKey derived from the private key.
  53. """
  54. @abc.abstractmethod
  55. def sign(self, data):
  56. """
  57. Signs the data.
  58. """
  59. @abc.abstractmethod
  60. def private_bytes(self, encoding, format, encryption_algorithm):
  61. """
  62. The serialized bytes of the private key.
  63. """