@@ -40,6 +40,9 @@ pub(crate) enum KeyType {
4040 Ec ,
4141 Ed25519 ,
4242 Ed448 ,
43+ MlDsa44 ,
44+ MlDsa65 ,
45+ MlDsa87 ,
4346}
4447
4548enum HashType {
@@ -68,9 +71,16 @@ pub(crate) fn identify_key_type(
6871 Ok ( KeyType :: Ed25519 )
6972 } else if private_key. is_instance ( & types:: ED448_PRIVATE_KEY . get ( py) ?) ? {
7073 Ok ( KeyType :: Ed448 )
74+ } else if private_key. is_instance ( & types:: MLDSA44_PRIVATE_KEY . get ( py) ?) ? {
75+ Ok ( KeyType :: MlDsa44 )
76+ } else if private_key. is_instance ( & types:: MLDSA65_PRIVATE_KEY . get ( py) ?) ? {
77+ Ok ( KeyType :: MlDsa65 )
78+ } else if private_key. is_instance ( & types:: MLDSA87_PRIVATE_KEY . get ( py) ?) ? {
79+ Ok ( KeyType :: MlDsa87 )
7180 } else {
7281 Err ( pyo3:: exceptions:: PyTypeError :: new_err (
73- "Key must be an rsa, dsa, ec, ed25519, or ed448 private key." ,
82+ "Key must be an rsa, dsa, ec, ed25519, ed448, ml-dsa-44, \
83+ ml-dsa-65, or ml-dsa-87 private key.",
7484 ) )
7585 }
7686}
@@ -190,6 +200,24 @@ pub(crate) fn compute_signature_algorithm<'p>(
190200 "Algorithm must be None when signing via ed25519 or ed448" ,
191201 ) ) ,
192202
203+ ( KeyType :: MlDsa44 , HashType :: None ) => Ok ( common:: AlgorithmIdentifier {
204+ oid : asn1:: DefinedByMarker :: marker ( ) ,
205+ params : common:: AlgorithmParameters :: MlDsa44 ,
206+ } ) ,
207+ ( KeyType :: MlDsa65 , HashType :: None ) => Ok ( common:: AlgorithmIdentifier {
208+ oid : asn1:: DefinedByMarker :: marker ( ) ,
209+ params : common:: AlgorithmParameters :: MlDsa65 ,
210+ } ) ,
211+ ( KeyType :: MlDsa87 , HashType :: None ) => Ok ( common:: AlgorithmIdentifier {
212+ oid : asn1:: DefinedByMarker :: marker ( ) ,
213+ params : common:: AlgorithmParameters :: MlDsa87 ,
214+ } ) ,
215+ ( KeyType :: MlDsa44 | KeyType :: MlDsa65 | KeyType :: MlDsa87 , _) => {
216+ Err ( pyo3:: exceptions:: PyValueError :: new_err (
217+ "Algorithm must be None when signing via ml-dsa-44, ml-dsa-65, or ml-dsa-87" ,
218+ ) )
219+ }
220+
193221 ( KeyType :: Ec , HashType :: Sha224 ) => Ok ( common:: AlgorithmIdentifier {
194222 oid : asn1:: DefinedByMarker :: marker ( ) ,
195223 params : common:: AlgorithmParameters :: EcDsaWithSha224 ( None ) ,
@@ -295,9 +323,11 @@ pub(crate) fn sign_data<'p>(
295323 let key_type = identify_key_type ( py, private_key. clone ( ) ) ?;
296324
297325 let signature = match key_type {
298- KeyType :: Ed25519 | KeyType :: Ed448 => {
299- private_key. call_method1 ( pyo3:: intern!( py, "sign" ) , ( data, ) ) ?
300- }
326+ KeyType :: Ed25519
327+ | KeyType :: Ed448
328+ | KeyType :: MlDsa44
329+ | KeyType :: MlDsa65
330+ | KeyType :: MlDsa87 => private_key. call_method1 ( pyo3:: intern!( py, "sign" ) , ( data, ) ) ?,
301331 KeyType :: Ec => {
302332 let ecdsa = types:: ECDSA
303333 . get ( py) ?
@@ -338,7 +368,11 @@ pub(crate) fn verify_signature_with_signature_algorithm<'p>(
338368 identify_signature_algorithm_parameters ( py, signature_algorithm) ?;
339369 let py_signature_hash_algorithm = identify_signature_hash_algorithm ( py, signature_algorithm) ?;
340370 match key_type {
341- KeyType :: Ed25519 | KeyType :: Ed448 => {
371+ KeyType :: Ed25519
372+ | KeyType :: Ed448
373+ | KeyType :: MlDsa44
374+ | KeyType :: MlDsa65
375+ | KeyType :: MlDsa87 => {
342376 issuer_public_key. call_method1 ( pyo3:: intern!( py, "verify" ) , ( signature, data) ) ?
343377 }
344378 KeyType :: Ec => issuer_public_key. call_method1 (
@@ -376,9 +410,16 @@ pub(crate) fn identify_public_key_type(
376410 Ok ( KeyType :: Ed25519 )
377411 } else if public_key. is_instance ( & types:: ED448_PUBLIC_KEY . get ( py) ?) ? {
378412 Ok ( KeyType :: Ed448 )
413+ } else if public_key. is_instance ( & types:: MLDSA44_PUBLIC_KEY . get ( py) ?) ? {
414+ Ok ( KeyType :: MlDsa44 )
415+ } else if public_key. is_instance ( & types:: MLDSA65_PUBLIC_KEY . get ( py) ?) ? {
416+ Ok ( KeyType :: MlDsa65 )
417+ } else if public_key. is_instance ( & types:: MLDSA87_PUBLIC_KEY . get ( py) ?) ? {
418+ Ok ( KeyType :: MlDsa87 )
379419 } else {
380420 Err ( pyo3:: exceptions:: PyTypeError :: new_err (
381- "Key must be an rsa, dsa, ec, ed25519, or ed448 public key." ,
421+ "Key must be an rsa, dsa, ec, ed25519, ed448, ml-dsa-44, \
422+ ml-dsa-65, or ml-dsa-87 public key.",
382423 ) )
383424 }
384425}
@@ -406,6 +447,9 @@ fn identify_key_type_for_algorithm_params(
406447 | common:: AlgorithmParameters :: EcDsaWithSha3_512 => Ok ( KeyType :: Ec ) ,
407448 common:: AlgorithmParameters :: Ed25519 => Ok ( KeyType :: Ed25519 ) ,
408449 common:: AlgorithmParameters :: Ed448 => Ok ( KeyType :: Ed448 ) ,
450+ common:: AlgorithmParameters :: MlDsa44 => Ok ( KeyType :: MlDsa44 ) ,
451+ common:: AlgorithmParameters :: MlDsa65 => Ok ( KeyType :: MlDsa65 ) ,
452+ common:: AlgorithmParameters :: MlDsa87 => Ok ( KeyType :: MlDsa87 ) ,
409453 common:: AlgorithmParameters :: DsaWithSha224 ( ..)
410454 | common:: AlgorithmParameters :: DsaWithSha256 ( ..)
411455 | common:: AlgorithmParameters :: DsaWithSha384 ( ..)
@@ -594,6 +638,9 @@ mod tests {
594638 ( & common:: AlgorithmParameters :: EcDsaWithSha3_512 , KeyType :: Ec ) ,
595639 ( & common:: AlgorithmParameters :: Ed25519 , KeyType :: Ed25519 ) ,
596640 ( & common:: AlgorithmParameters :: Ed448 , KeyType :: Ed448 ) ,
641+ ( & common:: AlgorithmParameters :: MlDsa44 , KeyType :: MlDsa44 ) ,
642+ ( & common:: AlgorithmParameters :: MlDsa65 , KeyType :: MlDsa65 ) ,
643+ ( & common:: AlgorithmParameters :: MlDsa87 , KeyType :: MlDsa87 ) ,
597644 (
598645 & common:: AlgorithmParameters :: DsaWithSha224 ( None ) ,
599646 KeyType :: Dsa ,
0 commit comments