Skip to content

Commit be81d6c

Browse files
author
royb
committed
added MLKEM and MLDSA provider structs
1 parent 86b26f0 commit be81d6c

30 files changed

+2928
-13
lines changed

pkix/src/main/java/org/bouncycastle/operator/DefaultSignatureAlgorithmIdentifierFinder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ public class DefaultSignatureAlgorithmIdentifierFinder
226226
algorithms.put("DILITHIUM3-AES", BCObjectIdentifiers.dilithium3_aes);
227227
algorithms.put("DILITHIUM5-AES", BCObjectIdentifiers.dilithium5_aes);
228228

229+
algorithms.put("ML-DSA-44", NISTObjectIdentifiers.id_ml_dsa_44);
230+
algorithms.put("ML-DSA-65", NISTObjectIdentifiers.id_ml_dsa_65);
231+
algorithms.put("ML-DSA-87", NISTObjectIdentifiers.id_ml_dsa_87);
232+
229233
algorithms.put("SLH-DSA-SHA2-128S", NISTObjectIdentifiers.id_slh_dsa_sha2_128s);
230234
algorithms.put("SLH-DSA-SHA2-128F", NISTObjectIdentifiers.id_slh_dsa_sha2_128f);
231235
algorithms.put("SLH-DSA-SHA2-192S", NISTObjectIdentifiers.id_slh_dsa_sha2_192s);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.bouncycastle.jcajce.interfaces;
2+
3+
import org.bouncycastle.jcajce.spec.MLDSAParameterSpec;
4+
5+
import java.security.Key;
6+
7+
public interface MLDSAKey
8+
extends Key
9+
{
10+
/**
11+
* Return the parameters for this key.
12+
*
13+
* @return a MLDSAParameterSpec
14+
*/
15+
MLDSAParameterSpec getParameterSpec();
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.bouncycastle.jcajce.interfaces;
2+
3+
import java.security.PrivateKey;
4+
5+
public interface MLDSAPrivateKey
6+
extends PrivateKey, MLDSAKey
7+
{
8+
/**
9+
* Return the public key corresponding to this private key.
10+
*
11+
* @return a ML-DSA Public Key
12+
*/
13+
MLDSAPublicKey getPublicKey();
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.bouncycastle.jcajce.interfaces;
2+
3+
import java.security.PublicKey;
4+
5+
public interface MLDSAPublicKey
6+
extends PublicKey, MLDSAKey
7+
{
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.bouncycastle.jcajce.interfaces;
2+
3+
import org.bouncycastle.jcajce.spec.MLKEMParameterSpec;
4+
5+
import java.security.Key;
6+
7+
public interface MLKEMKey
8+
extends Key
9+
{
10+
/**
11+
* Return the parameters for this key.
12+
*
13+
* @return a MLKEMParameterSpec
14+
*/
15+
MLKEMParameterSpec getParameterSpec();
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.bouncycastle.jcajce.interfaces;
2+
3+
import java.security.PrivateKey;
4+
5+
public interface MLKEMPrivateKey
6+
extends PrivateKey, MLKEMKey
7+
{
8+
/**
9+
* Return the public key corresponding to this private key.
10+
*
11+
* @return a ML-KEM Public Key
12+
*/
13+
MLKEMPublicKey getPublicKey();
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.bouncycastle.jcajce.interfaces;
2+
3+
import java.security.PublicKey;
4+
5+
public interface MLKEMPublicKey
6+
extends PublicKey, MLKEMKey
7+
{
8+
}

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/Dilithium.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.bouncycastle.jcajce.provider.asymmetric;
22

33
import org.bouncycastle.asn1.bc.BCObjectIdentifiers;
4-
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
54
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
65
import org.bouncycastle.jcajce.provider.util.AsymmetricAlgorithmProvider;
76
import org.bouncycastle.pqc.jcajce.provider.dilithium.DilithiumKeyFactorySpi;
@@ -21,21 +20,21 @@ public void configure(ConfigurableProvider provider)
2120
{
2221
provider.addAlgorithm("KeyFactory.DILITHIUM", PREFIX + "DilithiumKeyFactorySpi");
2322

24-
addKeyFactoryAlgorithm(provider, "DILITHIUM2", PREFIX + "DilithiumKeyFactorySpi$Base2", NISTObjectIdentifiers.id_ml_dsa_44, new DilithiumKeyFactorySpi.Base2());
25-
addKeyFactoryAlgorithm(provider, "DILITHIUM3", PREFIX + "DilithiumKeyFactorySpi$Base3", NISTObjectIdentifiers.id_ml_dsa_65, new DilithiumKeyFactorySpi.Base3());
26-
addKeyFactoryAlgorithm(provider, "DILITHIUM5", PREFIX + "DilithiumKeyFactorySpi$Base5", NISTObjectIdentifiers.id_ml_dsa_87, new DilithiumKeyFactorySpi.Base5());
23+
addKeyFactoryAlgorithm(provider, "DILITHIUM2", PREFIX + "DilithiumKeyFactorySpi$Base2", BCObjectIdentifiers.dilithium2, new DilithiumKeyFactorySpi.Base2());
24+
addKeyFactoryAlgorithm(provider, "DILITHIUM3", PREFIX + "DilithiumKeyFactorySpi$Base3", BCObjectIdentifiers.dilithium3, new DilithiumKeyFactorySpi.Base3());
25+
addKeyFactoryAlgorithm(provider, "DILITHIUM5", PREFIX + "DilithiumKeyFactorySpi$Base5", BCObjectIdentifiers.dilithium5, new DilithiumKeyFactorySpi.Base5());
2726

2827
provider.addAlgorithm("KeyPairGenerator.DILITHIUM", PREFIX + "DilithiumKeyPairGeneratorSpi");
2928

30-
addKeyPairGeneratorAlgorithm(provider, "DILITHIUM2", PREFIX + "DilithiumKeyPairGeneratorSpi$Base2", NISTObjectIdentifiers.id_ml_dsa_44);
31-
addKeyPairGeneratorAlgorithm(provider, "DILITHIUM3", PREFIX + "DilithiumKeyPairGeneratorSpi$Base3", NISTObjectIdentifiers.id_ml_dsa_65);
32-
addKeyPairGeneratorAlgorithm(provider, "DILITHIUM5", PREFIX + "DilithiumKeyPairGeneratorSpi$Base5", NISTObjectIdentifiers.id_ml_dsa_87);
29+
addKeyPairGeneratorAlgorithm(provider, "DILITHIUM2", PREFIX + "DilithiumKeyPairGeneratorSpi$Base2", BCObjectIdentifiers.dilithium2);
30+
addKeyPairGeneratorAlgorithm(provider, "DILITHIUM3", PREFIX + "DilithiumKeyPairGeneratorSpi$Base3", BCObjectIdentifiers.dilithium3);
31+
addKeyPairGeneratorAlgorithm(provider, "DILITHIUM5", PREFIX + "DilithiumKeyPairGeneratorSpi$Base5", BCObjectIdentifiers.dilithium5);
3332

3433
addSignatureAlgorithm(provider, "DILITHIUM", PREFIX + "SignatureSpi$Base", BCObjectIdentifiers.dilithium);
3534

36-
addSignatureAlgorithm(provider, "DILITHIUM2", PREFIX + "SignatureSpi$Base2", NISTObjectIdentifiers.id_ml_dsa_44);
37-
addSignatureAlgorithm(provider, "DILITHIUM3", PREFIX + "SignatureSpi$Base3", NISTObjectIdentifiers.id_ml_dsa_65);
38-
addSignatureAlgorithm(provider, "DILITHIUM5", PREFIX + "SignatureSpi$Base5", NISTObjectIdentifiers.id_ml_dsa_87);
35+
addSignatureAlgorithm(provider, "DILITHIUM2", PREFIX + "SignatureSpi$Base2", BCObjectIdentifiers.dilithium2);
36+
addSignatureAlgorithm(provider, "DILITHIUM3", PREFIX + "SignatureSpi$Base3", BCObjectIdentifiers.dilithium3);
37+
addSignatureAlgorithm(provider, "DILITHIUM5", PREFIX + "SignatureSpi$Base5", BCObjectIdentifiers.dilithium5);
3938
}
4039
}
4140
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.bouncycastle.jcajce.provider.asymmetric;
2+
3+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4+
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
5+
import org.bouncycastle.jcajce.provider.asymmetric.mldsa.MLDSAKeyFactorySpi;
6+
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
7+
import org.bouncycastle.jcajce.provider.util.AsymmetricAlgorithmProvider;
8+
import org.bouncycastle.jcajce.provider.util.AsymmetricKeyInfoConverter;
9+
10+
public class MLDSA
11+
{
12+
private static final String PREFIX = "org.bouncycastle.jcajce.provider.asymmetric" + ".mldsa.";
13+
14+
public static class Mappings
15+
extends AsymmetricAlgorithmProvider
16+
{
17+
public Mappings()
18+
{
19+
}
20+
21+
public void configure(ConfigurableProvider provider)
22+
{
23+
provider.addAlgorithm("KeyFactory.ML-DSA", PREFIX + "MLDSAKeyFactorySpi");
24+
provider.addAlgorithm("KeyPairGenerator.ML-DSA", PREFIX + "MLDSAKeyPairGeneratorSpi");
25+
26+
// addKeyFactoryAlgorithm(provider, "ML-DSA-44", PREFIX + "MLDSAKeyFactorySpi$MLDSA44", NISTObjectIdentifiers.id_ml_dsa_44, new MLDSAKeyFactorySpi.MLDSA44());
27+
// addKeyFactoryAlgorithm(provider, "ML-DSA-65", PREFIX + "MLDSAKeyFactorySpi$MLDSA65", NISTObjectIdentifiers.id_ml_dsa_65, new MLDSAKeyFactorySpi.MLDSA65());
28+
// addKeyFactoryAlgorithm(provider, "ML-DSA-87", PREFIX + "MLDSAKeyFactorySpi$MLDSA87", NISTObjectIdentifiers.id_ml_dsa_87, new MLDSAKeyFactorySpi.MLDSA87());
29+
30+
31+
addKeyPairGeneratorAlgorithm(provider, "ML-DSA-44", PREFIX + "MLDSAKeyPairGeneratorSpi$MLDSA44", NISTObjectIdentifiers.id_ml_dsa_44);
32+
addKeyPairGeneratorAlgorithm(provider, "ML-DSA-65", PREFIX + "MLDSAKeyPairGeneratorSpi$MLDSA65", NISTObjectIdentifiers.id_ml_dsa_65);
33+
addKeyPairGeneratorAlgorithm(provider, "ML-DSA-87", PREFIX + "MLDSAKeyPairGeneratorSpi$MLDSA87", NISTObjectIdentifiers.id_ml_dsa_87);
34+
35+
addSignatureAlgorithm(provider, "ML-DSA", PREFIX + "SignatureSpi$MLDSA", (ASN1ObjectIdentifier) null);
36+
37+
addSignatureAlgorithm(provider, "ML-DSA-44", PREFIX + "SignatureSpi$MLDSA44", NISTObjectIdentifiers.id_ml_dsa_44);
38+
addSignatureAlgorithm(provider, "ML-DSA-65", PREFIX + "SignatureSpi$MLDSA65", NISTObjectIdentifiers.id_ml_dsa_65);
39+
addSignatureAlgorithm(provider, "ML-DSA-87", PREFIX + "SignatureSpi$MLDSA87", NISTObjectIdentifiers.id_ml_dsa_87);
40+
41+
42+
// provider.addAlgorithm("Alg.Alias.Signature." + NISTObjectIdentifiers.id_ml_dsa_44, "ML-DSA");
43+
// provider.addAlgorithm("Alg.Alias.Signature.OID." + NISTObjectIdentifiers.id_ml_dsa_44, "ML-DSA");
44+
//
45+
// provider.addAlgorithm("Alg.Alias.Signature." + NISTObjectIdentifiers.id_ml_dsa_65, "ML-DSA");
46+
// provider.addAlgorithm("Alg.Alias.Signature.OID." + NISTObjectIdentifiers.id_ml_dsa_65, "ML-DSA");
47+
//
48+
// provider.addAlgorithm("Alg.Alias.Signature." + NISTObjectIdentifiers.id_ml_dsa_87, "ML-DSA");
49+
// provider.addAlgorithm("Alg.Alias.Signature.OID." + NISTObjectIdentifiers.id_ml_dsa_87, "ML-DSA");
50+
51+
AsymmetricKeyInfoConverter keyFact = new MLDSAKeyFactorySpi();
52+
53+
registerKeyFactoryOid(provider, NISTObjectIdentifiers.id_ml_dsa_44, "ML-DSA", keyFact);
54+
registerKeyFactoryOid(provider, NISTObjectIdentifiers.id_ml_dsa_65, "ML-DSA", keyFact);
55+
registerKeyFactoryOid(provider, NISTObjectIdentifiers.id_ml_dsa_87, "ML-DSA", keyFact);
56+
57+
}
58+
59+
60+
}
61+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.bouncycastle.jcajce.provider.asymmetric;
2+
3+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
4+
import org.bouncycastle.asn1.bc.BCObjectIdentifiers;
5+
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
6+
import org.bouncycastle.jcajce.provider.asymmetric.mlkem.MLKEMKeyFactorySpi;
7+
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
8+
import org.bouncycastle.jcajce.provider.util.AsymmetricAlgorithmProvider;
9+
import org.bouncycastle.jcajce.provider.util.AsymmetricKeyInfoConverter;
10+
import org.bouncycastle.pqc.jcajce.provider.kyber.KyberKeyFactorySpi;
11+
12+
public class MLKEM
13+
{
14+
private static final String PREFIX = "org.bouncycastle.jcajce.provider.asymmetric" + ".mlkem.";
15+
16+
public static class Mappings
17+
extends AsymmetricAlgorithmProvider
18+
{
19+
public Mappings()
20+
{
21+
}
22+
23+
public void configure(ConfigurableProvider provider)
24+
{
25+
provider.addAlgorithm("KeyFactory.ML-KEM", PREFIX + "MLKEMKeyFactorySpi");
26+
27+
addKeyFactoryAlgorithm(provider, "ML-KEM-512", PREFIX + "MLKEMKeyFactorySpi$MLKEM512", NISTObjectIdentifiers.id_alg_ml_kem_512, new MLKEMKeyFactorySpi.MLKEM512());
28+
addKeyFactoryAlgorithm(provider, "ML-KEM-768", PREFIX + "MLKEMKeyFactorySpi$MLKEM768", NISTObjectIdentifiers.id_alg_ml_kem_768, new MLKEMKeyFactorySpi.MLKEM768());
29+
addKeyFactoryAlgorithm(provider, "ML-KEM-1024", PREFIX + "MLKEMKeyFactorySpi$MLKEM1024", NISTObjectIdentifiers.id_alg_ml_kem_1024, new MLKEMKeyFactorySpi.MLKEM1024());
30+
31+
32+
provider.addAlgorithm("KeyPairGenerator.ML-KEM", PREFIX + "MLKEMKeyPairGeneratorSpi");
33+
34+
addKeyPairGeneratorAlgorithm(provider, "ML-KEM-512", PREFIX + "MLKEMKeyPairGeneratorSpi$MLKEM512", NISTObjectIdentifiers.id_alg_ml_kem_512);
35+
addKeyPairGeneratorAlgorithm(provider, "ML-KEM-768", PREFIX + "MLKEMKeyPairGeneratorSpi$MLKEM768", NISTObjectIdentifiers.id_alg_ml_kem_768);
36+
addKeyPairGeneratorAlgorithm(provider, "ML-KEM-1024", PREFIX + "MLKEMKeyPairGeneratorSpi$MLKEM1024", NISTObjectIdentifiers.id_alg_ml_kem_1024);
37+
38+
provider.addAlgorithm("KeyGenerator.ML-KEM", PREFIX + "MLKEMKeyGeneratorSpi");
39+
40+
addKeyGeneratorAlgorithm(provider, "ML-KEM-512", PREFIX + "MLKEMKeyGeneratorSpi$MLKEM512", NISTObjectIdentifiers.id_alg_ml_kem_512);
41+
addKeyGeneratorAlgorithm(provider, "ML-KEM-768", PREFIX + "MLKEMKeyGeneratorSpi$MLKEM768", NISTObjectIdentifiers.id_alg_ml_kem_768);
42+
addKeyGeneratorAlgorithm(provider, "ML-KEM-1024", PREFIX + "MLKEMKeyGeneratorSpi$MLKEM1024", NISTObjectIdentifiers.id_alg_ml_kem_1024);
43+
44+
AsymmetricKeyInfoConverter keyFact = new MLKEMKeyFactorySpi();
45+
46+
provider.addAlgorithm("Cipher.ML-KEM", PREFIX + "MLKEMCipherSpi$Base");
47+
provider.addAlgorithm("Alg.Alias.Cipher." + (ASN1ObjectIdentifier) null, "ML-KEM");
48+
49+
addCipherAlgorithm(provider, "ML-KEM-512", PREFIX + "MLKEMCipherSpi$MLKEM512", NISTObjectIdentifiers.id_alg_ml_kem_512);
50+
addCipherAlgorithm(provider, "ML-KEM-768", PREFIX + "MLKEMCipherSpi$MLKEM768", NISTObjectIdentifiers.id_alg_ml_kem_768);
51+
addCipherAlgorithm(provider, "ML-KEM-1024", PREFIX + "MLKEMCipherSpi$MLKEM1024", NISTObjectIdentifiers.id_alg_ml_kem_1024);
52+
53+
registerOid(provider, (ASN1ObjectIdentifier) null, "ML-KEM", keyFact);
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)