-
Notifications
You must be signed in to change notification settings - Fork 1.7k
MLDSA65 support for AWS-LC #14404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
MLDSA65 support for AWS-LC #14404
Changes from all commits
176e34b
65ab941
4fab32f
2450b41
ef4345f
2f6b313
4fe06c7
ed6d9de
b60d88b
39c9db3
db6d98d
c78a527
7bde7d5
a8083a4
f849147
7284fec
16bd0d3
b66fdca
67c5374
e457a27
8cb4c7e
a532164
c56210c
b2cd7dd
f492ca3
d517b35
530aa92
4b8430c
1f1303a
7a6f3a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # 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 cryptography.hazmat.primitives.asymmetric import mldsa | ||
| from cryptography.utils import Buffer | ||
|
|
||
| class MlDsa65PrivateKey: ... | ||
| class MlDsa65PublicKey: ... | ||
|
|
||
| def generate_key() -> mldsa.MlDsa65PrivateKey: ... | ||
| def from_public_bytes(data: bytes) -> mldsa.MlDsa65PublicKey: ... | ||
| def from_seed_bytes(data: Buffer) -> mldsa.MlDsa65PrivateKey: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| # 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 annotations | ||
|
|
||
| import abc | ||
|
|
||
| from cryptography.exceptions import UnsupportedAlgorithm, _Reasons | ||
| from cryptography.hazmat.bindings._rust import openssl as rust_openssl | ||
| from cryptography.hazmat.primitives import _serialization | ||
| from cryptography.utils import Buffer | ||
|
|
||
|
|
||
| class MlDsa65PublicKey(metaclass=abc.ABCMeta): | ||
| @classmethod | ||
| def from_public_bytes(cls, data: bytes) -> MlDsa65PublicKey: | ||
| from cryptography.hazmat.backends.openssl.backend import backend | ||
|
|
||
| if not backend.mldsa_supported(): | ||
| raise UnsupportedAlgorithm( | ||
| "ML-DSA-65 is not supported by this backend.", | ||
| _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, | ||
| ) | ||
|
|
||
| return rust_openssl.mldsa.from_public_bytes(data) | ||
|
|
||
| @abc.abstractmethod | ||
| def public_bytes( | ||
| self, | ||
| encoding: _serialization.Encoding, | ||
| format: _serialization.PublicFormat, | ||
| ) -> bytes: | ||
| """ | ||
| The serialized bytes of the public key. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def public_bytes_raw(self) -> bytes: | ||
| """ | ||
| The raw bytes of the public key. | ||
| Equivalent to public_bytes(Raw, Raw). | ||
|
|
||
| The public key is 1,952 bytes for MLDSA-65. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def verify( | ||
| self, | ||
| signature: Buffer, | ||
| data: Buffer, | ||
| context: Buffer | None = None, | ||
| ) -> None: | ||
| """ | ||
alex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Verify the signature. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def __eq__(self, other: object) -> bool: | ||
| """ | ||
| Checks equality. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def __copy__(self) -> MlDsa65PublicKey: | ||
| """ | ||
| Returns a copy. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def __deepcopy__(self, memo: dict) -> MlDsa65PublicKey: | ||
| """ | ||
| Returns a deep copy. | ||
| """ | ||
|
|
||
|
|
||
| if hasattr(rust_openssl, "mldsa"): | ||
| MlDsa65PublicKey.register(rust_openssl.mldsa.MlDsa65PublicKey) | ||
|
|
||
|
|
||
| class MlDsa65PrivateKey(metaclass=abc.ABCMeta): | ||
| @classmethod | ||
| def generate(cls) -> MlDsa65PrivateKey: | ||
| from cryptography.hazmat.backends.openssl.backend import backend | ||
|
|
||
| if not backend.mldsa_supported(): | ||
| raise UnsupportedAlgorithm( | ||
| "ML-DSA-65 is not supported by this backend.", | ||
| _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, | ||
| ) | ||
|
|
||
| return rust_openssl.mldsa.generate_key() | ||
|
|
||
| @classmethod | ||
| def from_seed_bytes(cls, data: Buffer) -> MlDsa65PrivateKey: | ||
| from cryptography.hazmat.backends.openssl.backend import backend | ||
|
|
||
| if not backend.mldsa_supported(): | ||
| raise UnsupportedAlgorithm( | ||
| "ML-DSA-65 is not supported by this backend.", | ||
| _Reasons.UNSUPPORTED_PUBLIC_KEY_ALGORITHM, | ||
| ) | ||
|
|
||
| return rust_openssl.mldsa.from_seed_bytes(data) | ||
|
|
||
| @abc.abstractmethod | ||
| def public_key(self) -> MlDsa65PublicKey: | ||
| """ | ||
| The MlDsa65PublicKey derived from the private key. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def private_bytes( | ||
DarkaMaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self, | ||
| encoding: _serialization.Encoding, | ||
| format: _serialization.PrivateFormat, | ||
| encryption_algorithm: _serialization.KeySerializationEncryption, | ||
| ) -> bytes: | ||
| """ | ||
| The serialized bytes of the private key. | ||
|
|
||
| This method only returns the serialization of the seed form of the | ||
| private key, never the expanded one. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def private_bytes_raw(self) -> bytes: | ||
| """ | ||
| The raw bytes of the private key. | ||
| Equivalent to private_bytes(Raw, Raw, NoEncryption()). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same Q here about seed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (replied about this one in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should be using the noun seed here, rather than raw -- wdyt @reaperhulk ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reaperhulk still pending :-)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, well a seed only key can have two forms. The raw/bare seed or one wrapped in a PKCS8 structure. This parses the raw seed so I think I'm fine with it being called raw? |
||
|
|
||
| This method only returns the seed form of the private key (32 bytes). | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def sign(self, data: Buffer, context: Buffer | None = None) -> bytes: | ||
| """ | ||
| Signs the data. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def __copy__(self) -> MlDsa65PrivateKey: | ||
| """ | ||
| Returns a copy. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def __deepcopy__(self, memo: dict) -> MlDsa65PrivateKey: | ||
| """ | ||
| Returns a deep copy. | ||
| """ | ||
|
|
||
|
|
||
| if hasattr(rust_openssl, "mldsa"): | ||
| MlDsa65PrivateKey.register(rust_openssl.mldsa.MlDsa65PrivateKey) | ||
Uh oh!
There was an error while loading. Please reload this page.