@@ -14,8 +14,8 @@ Signing & Verification
1414.. doctest ::
1515 :skipif: not _backend.mldsa_supported()
1616
17- >>> from cryptography.hazmat.primitives.asymmetric.mldsa import MlDsa65PrivateKey
18- >>> private_key = MlDsa65PrivateKey .generate()
17+ >>> from cryptography.hazmat.primitives.asymmetric.mldsa import MlDsa44PrivateKey
18+ >>> private_key = MlDsa44PrivateKey .generate()
1919 >>> signature = private_key.sign(b " my authenticated message" )
2020 >>> public_key = private_key.public_key()
2121 >>> public_key.verify(signature, b " my authenticated message" )
@@ -30,8 +30,8 @@ different contexts or protocols.
3030.. doctest ::
3131 :skipif: not _backend.mldsa_supported()
3232
33- >>> from cryptography.hazmat.primitives.asymmetric.mldsa import MlDsa65PrivateKey
34- >>> private_key = MlDsa65PrivateKey .generate()
33+ >>> from cryptography.hazmat.primitives.asymmetric.mldsa import MlDsa44PrivateKey
34+ >>> private_key = MlDsa44PrivateKey .generate()
3535 >>> context = b " email-signature-v1"
3636 >>> signature = private_key.sign(b " my authenticated message" , context)
3737 >>> public_key = private_key.public_key()
@@ -41,6 +41,192 @@ different contexts or protocols.
4141Key interfaces
4242~~~~~~~~~~~~~~
4343
44+ .. class :: MlDsa44PrivateKey
45+
46+ .. versionadded :: 47.0
47+
48+ .. classmethod :: generate()
49+
50+ Generate an ML-DSA-44 private key.
51+
52+ :returns: :class: `MlDsa44PrivateKey `
53+
54+ :raises cryptography.exceptions.UnsupportedAlgorithm: If ML-DSA-44 is
55+ not supported by the backend ``cryptography `` is using.
56+
57+ .. classmethod :: from_seed_bytes(data)
58+
59+ Load an ML-DSA-44 private key from seed bytes.
60+
61+ :param data: 32 byte seed.
62+ :type data: :term: `bytes-like `
63+
64+ :returns: :class: `MlDsa44PrivateKey `
65+
66+ :raises ValueError: If the seed is not 32 bytes.
67+
68+ :raises cryptography.exceptions.UnsupportedAlgorithm: If ML-DSA-44 is
69+ not supported by the backend ``cryptography `` is using.
70+
71+ .. doctest ::
72+ :skipif: not _backend.mldsa_supported()
73+
74+ >>> from cryptography.hazmat.primitives.asymmetric import mldsa
75+ >>> private_key = mldsa.MlDsa44PrivateKey.generate()
76+ >>> seed = private_key.private_bytes_raw()
77+ >>> same_key = mldsa.MlDsa44PrivateKey.from_seed_bytes(seed)
78+
79+ .. method :: public_key()
80+
81+ :returns: :class: `MlDsa44PublicKey `
82+
83+ .. method :: sign(data, context=None)
84+
85+ Sign the data using ML-DSA-44. An optional context string can be
86+ provided.
87+
88+ :param data: The data to sign.
89+ :type data: :term: `bytes-like `
90+
91+ :param context: An optional context string (up to 255 bytes).
92+ :type context: :term: `bytes-like ` or ``None ``
93+
94+ :returns bytes: The signature (2420 bytes).
95+
96+ :raises ValueError: If the context is longer than 255 bytes.
97+
98+ .. method :: private_bytes(encoding, format, encryption_algorithm)
99+
100+ Allows serialization of the key to bytes. Encoding (
101+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.PEM `,
102+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.DER `, or
103+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.Raw `) and
104+ format (
105+ :attr: `~cryptography.hazmat.primitives.serialization.PrivateFormat.PKCS8 `
106+ or
107+ :attr: `~cryptography.hazmat.primitives.serialization.PrivateFormat.Raw `
108+ ) are chosen to define the exact serialization.
109+
110+ This method only returns the serialization of the seed form of the
111+ private key, never the expanded one.
112+
113+ :param encoding: A value from the
114+ :class: `~cryptography.hazmat.primitives.serialization.Encoding ` enum.
115+
116+ :param format: A value from the
117+ :class: `~cryptography.hazmat.primitives.serialization.PrivateFormat `
118+ enum. If the ``encoding `` is
119+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.Raw `
120+ then ``format `` must be
121+ :attr: `~cryptography.hazmat.primitives.serialization.PrivateFormat.Raw `
122+ , otherwise it must be
123+ :attr: `~cryptography.hazmat.primitives.serialization.PrivateFormat.PKCS8 `.
124+
125+ :param encryption_algorithm: An instance of an object conforming to the
126+ :class: `~cryptography.hazmat.primitives.serialization.KeySerializationEncryption `
127+ interface.
128+
129+ :return bytes: Serialized key.
130+
131+ .. method :: private_bytes_raw()
132+
133+ Allows serialization of the key to raw bytes. This method is a
134+ convenience shortcut for calling :meth: `private_bytes ` with
135+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.Raw `
136+ encoding,
137+ :attr: `~cryptography.hazmat.primitives.serialization.PrivateFormat.Raw `
138+ format, and
139+ :class: `~cryptography.hazmat.primitives.serialization.NoEncryption `.
140+
141+ This method only returns the seed form of the private key (32 bytes).
142+
143+ :return bytes: Raw key (32-byte seed).
144+
145+ .. class :: MlDsa44PublicKey
146+
147+ .. versionadded :: 47.0
148+
149+ .. classmethod :: from_public_bytes(data)
150+
151+ :param bytes data: 1312 byte public key.
152+
153+ :returns: :class: `MlDsa44PublicKey `
154+
155+ :raises ValueError: If the public key is not 1312 bytes.
156+
157+ :raises cryptography.exceptions.UnsupportedAlgorithm: If ML-DSA-44 is
158+ not supported by the backend ``cryptography `` is using.
159+
160+ .. doctest ::
161+ :skipif: not _backend.mldsa_supported()
162+
163+ >>> from cryptography.hazmat.primitives import serialization
164+ >>> from cryptography.hazmat.primitives.asymmetric import mldsa
165+ >>> private_key = mldsa.MlDsa44PrivateKey.generate()
166+ >>> public_key = private_key.public_key()
167+ >>> public_bytes = public_key.public_bytes(
168+ ... encoding= serialization.Encoding.Raw,
169+ ... format = serialization.PublicFormat.Raw
170+ ... )
171+ >>> loaded_public_key = mldsa.MlDsa44PublicKey.from_public_bytes(public_bytes)
172+
173+ .. method :: public_bytes(encoding, format)
174+
175+ Allows serialization of the key to bytes. Encoding (
176+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.PEM `,
177+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.DER `, or
178+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.Raw `) and
179+ format (
180+ :attr: `~cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo `
181+ or
182+ :attr: `~cryptography.hazmat.primitives.serialization.PublicFormat.Raw `
183+ ) are chosen to define the exact serialization.
184+
185+ :param encoding: A value from the
186+ :class: `~cryptography.hazmat.primitives.serialization.Encoding ` enum.
187+
188+ :param format: A value from the
189+ :class: `~cryptography.hazmat.primitives.serialization.PublicFormat `
190+ enum. If the ``encoding `` is
191+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.Raw `
192+ then ``format `` must be
193+ :attr: `~cryptography.hazmat.primitives.serialization.PublicFormat.Raw `
194+ , otherwise it must be
195+ :attr: `~cryptography.hazmat.primitives.serialization.PublicFormat.SubjectPublicKeyInfo `.
196+
197+ :returns bytes: The public key bytes.
198+
199+ .. method :: public_bytes_raw()
200+
201+ Allows serialization of the key to raw bytes. This method is a
202+ convenience shortcut for calling :meth: `public_bytes ` with
203+ :attr: `~cryptography.hazmat.primitives.serialization.Encoding.Raw `
204+ encoding and
205+ :attr: `~cryptography.hazmat.primitives.serialization.PublicFormat.Raw `
206+ format.
207+
208+ :return bytes: 1312-byte raw public key.
209+
210+ .. method :: verify(signature, data, context=None)
211+
212+ Verify a signature using ML-DSA-44. If a context string was used during
213+ signing, the same context must be provided for verification to succeed.
214+
215+ :param signature: The signature to verify.
216+ :type signature: :term: `bytes-like `
217+
218+ :param data: The data to verify.
219+ :type data: :term: `bytes-like `
220+
221+ :param context: An optional context string (up to 255 bytes) that was
222+ used during signing.
223+ :type context: :term: `bytes-like ` or ``None ``
224+
225+ :returns: None
226+ :raises cryptography.exceptions.InvalidSignature: Raised when the
227+ signature cannot be verified.
228+ :raises ValueError: If the context is longer than 255 bytes.
229+
44230.. class :: MlDsa65PrivateKey
45231
46232 .. versionadded :: 47.0
0 commit comments