-
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
Merged
Merged
MLDSA65 support for AWS-LC #14404
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
176e34b
MLDSA65 support for AWS-LC
DarkaMaul 65ab941
Improve coverage
DarkaMaul 4fab32f
Initial review
DarkaMaul 2450b41
First round of review
DarkaMaul ef4345f
Clean tests
DarkaMaul 2f6b313
Revert spurious formatting
DarkaMaul 4fe06c7
Incorporate review
DarkaMaul ed6d9de
Rename from mldsa65 to mldsa
DarkaMaul b60d88b
Improve serialization/deserialization
DarkaMaul 39c9db3
Fix coverage
DarkaMaul db6d98d
Use ASN1 struct to parse the private key
DarkaMaul c78a527
Merge branch 'pyca:main' into dm/mldsa65-aws-lc
DarkaMaul 7bde7d5
Use Enum instead of Struct
DarkaMaul a8083a4
Inline function
DarkaMaul f849147
Change match arm
DarkaMaul 7284fec
Remove duplicate comment
DarkaMaul 16bd0d3
Change unimplemented by assert
DarkaMaul b66fdca
More review fix
DarkaMaul 67c5374
Merge branch 'pyca:main' into dm/mldsa65-aws-lc
DarkaMaul e457a27
Fix Wycheproof vectors handling
DarkaMaul 8cb4c7e
Add NO-COVERAGE marker
DarkaMaul a532164
Merge remote-tracking branch 'origin/main' into dm/mldsa65-aws-lc
DarkaMaul c56210c
Remove vectors
DarkaMaul b2cd7dd
Merge remote-tracking branch 'origin/main' into dm/mldsa65-aws-lc
DarkaMaul f492ca3
Review comments
DarkaMaul d517b35
Remove markers
DarkaMaul 530aa92
Merge branch 'pyca:main' into dm/mldsa65-aws-lc
DarkaMaul 4b8430c
Merge branch 'pyca:main' into dm/mldsa65-aws-lc
DarkaMaul 1f1303a
Additional round of review
DarkaMaul 7a6f3a2
Merge branch 'pyca:main' into dm/mldsa65-aws-lc
DarkaMaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/cryptography/hazmat/bindings/_rust/openssl/mldsa65.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 mldsa65 | ||
| from cryptography.utils import Buffer | ||
|
|
||
| class MlDsa65PrivateKey: ... | ||
| class MlDsa65PublicKey: ... | ||
|
|
||
| def generate_key() -> mldsa65.MlDsa65PrivateKey: ... | ||
| def from_public_bytes(data: bytes) -> mldsa65.MlDsa65PublicKey: ... | ||
| def from_seed_bytes(data: Buffer) -> mldsa65.MlDsa65PrivateKey: ... |
157 changes: 157 additions & 0 deletions
157
src/cryptography/hazmat/primitives/asymmetric/mldsa65.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # 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.mldsa65.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). | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def verify(self, signature: Buffer, data: Buffer) -> None: | ||
| """ | ||
| Verify the signature. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def verify_with_context( | ||
| self, signature: Buffer, data: Buffer, context: Buffer | ||
| ) -> None: | ||
| """ | ||
| Verify the signature with a context string. | ||
| """ | ||
|
|
||
| @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, "mldsa65"): | ||
| MlDsa65PublicKey.register(rust_openssl.mldsa65.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.mldsa65.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.mldsa65.from_seed_bytes(data) | ||
|
|
||
| @abc.abstractmethod | ||
| def public_key(self) -> MlDsa65PublicKey: | ||
| """ | ||
| The MlDsa65PublicKey derived from the private key. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def private_bytes( | ||
| self, | ||
| encoding: _serialization.Encoding, | ||
| format: _serialization.PrivateFormat, | ||
| encryption_algorithm: (_serialization.KeySerializationEncryption), | ||
| ) -> bytes: | ||
| """ | ||
| The serialized bytes of the private key. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def private_bytes_raw(self) -> bytes: | ||
| """ | ||
| The raw bytes of the private key (32-byte seed). | ||
| Equivalent to private_bytes(Raw, Raw, NoEncryption()). | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def sign(self, data: Buffer) -> bytes: | ||
| """ | ||
| Signs the data. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def sign_with_context(self, data: Buffer, context: Buffer) -> bytes: | ||
| """ | ||
| Signs the data with a context string. | ||
| """ | ||
|
|
||
| @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, "mldsa65"): | ||
| MlDsa65PrivateKey.register(rust_openssl.mldsa65.MlDsa65PrivateKey) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.