Skip to content

Commit 818292a

Browse files
committed
Resolve a composite key's algorithm name through the composite KEM index as well as the composite signature one, so that getAlgorithm() no longer returns null for the twelve Composite ML-KEM parameter sets and the SubjectPublicKeyInfo / PrivateKeyInfo constructors accept them, normalise an EC component to an uncompressed point wherever a composite key or the KEM combiner input is serialised as section 4 of the drafts requires, while still decoding a compressed one, default the SecureRandom the RSA-OAEP composites draw their traditional secret from and clear the ML-KEM component's secret as section 3.5 requires, and register the brainpool sets under the draft's spelling with the abbreviated names and OID constants kept as deprecated aliases, relates to github #2404.
1 parent 7decad0 commit 818292a

16 files changed

Lines changed: 454 additions & 63 deletions

File tree

‎core/src/main/java/org/bouncycastle/asn1/iana/IANAObjectIdentifiers.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,19 @@ public interface IANAObjectIdentifiers
131131
/** 1.3.6.1.5.5.7.6.60 id-MLKEM768-ECDH-P384-SHA3-256 */
132132
ASN1ObjectIdentifier id_MLKEM768_ECDH_P384_SHA3_256 = id_alg.branch("60");
133133
/** 1.3.6.1.5.5.7.6.61 id-MLKEM768-ECDH-brainpoolP256r1-SHA3-256 */
134-
ASN1ObjectIdentifier id_MLKEM768_ECDH_BP256_SHA3_256 = id_alg.branch("61");
134+
ASN1ObjectIdentifier id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256 = id_alg.branch("61");
135+
/** @deprecated use id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256 instead */
136+
@Deprecated
137+
ASN1ObjectIdentifier id_MLKEM768_ECDH_BP256_SHA3_256 = id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256;
135138
/** 1.3.6.1.5.5.7.6.62 id-MLKEM1024-RSA3072-SHA3-256 */
136139
ASN1ObjectIdentifier id_MLKEM1024_RSA3072_SHA3_256 = id_alg.branch("62");
137140
/** 1.3.6.1.5.5.7.6.63 id-MLKEM1024-ECDH-P384-SHA3-256 */
138141
ASN1ObjectIdentifier id_MLKEM1024_ECDH_P384_SHA3_256 = id_alg.branch("63");
139142
/** 1.3.6.1.5.5.7.6.64 id-MLKEM1024-ECDH-brainpoolP384r1-SHA3-256 */
140-
ASN1ObjectIdentifier id_MLKEM1024_ECDH_BP384_SHA3_256 = id_alg.branch("64");
143+
ASN1ObjectIdentifier id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256 = id_alg.branch("64");
144+
/** @deprecated use id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256 instead */
145+
@Deprecated
146+
ASN1ObjectIdentifier id_MLKEM1024_ECDH_BP384_SHA3_256 = id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256;
141147
/** 1.3.6.1.5.5.7.6.65 id-MLKEM1024-X448-SHA3-256 */
142148
ASN1ObjectIdentifier id_MLKEM1024_X448_SHA3_256 = id_alg.branch("65");
143149
/** 1.3.6.1.5.5.7.6.66 id-MLKEM1024-ECDH-P521-SHA3-256 */

‎docs/releasenotes.html‎

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

‎pkix/src/main/java/org/bouncycastle/operator/DefaultKemEncapsulationLengthProvider.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ public class DefaultKemEncapsulationLengthProvider
7272
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM768_X25519_SHA3_256, Integers.valueOf(1120));
7373
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_P256_SHA3_256, Integers.valueOf(1153));
7474
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_P384_SHA3_256, Integers.valueOf(1185));
75-
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_BP256_SHA3_256, Integers.valueOf(1153));
75+
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256, Integers.valueOf(1153));
7676
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM1024_RSA3072_SHA3_256, Integers.valueOf(1952));
7777
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_P384_SHA3_256, Integers.valueOf(1665));
78-
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_BP384_SHA3_256, Integers.valueOf(1665));
78+
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256, Integers.valueOf(1665));
7979
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM1024_X448_SHA3_256, Integers.valueOf(1624));
8080
kemEncapsulationLengths.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_P521_SHA3_256, Integers.valueOf(1701));
8181
}

‎pkix/src/test/java/org/bouncycastle/cms/test/CompositeKEMEnvelopedDataTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public class CompositeKEMEnvelopedDataTest
4343
private static final String[] NAMES = {
4444
"MLKEM768-RSA2048-SHA3-256", "MLKEM768-RSA3072-SHA3-256", "MLKEM768-RSA4096-SHA3-256",
4545
"MLKEM768-X25519-SHA3-256", "MLKEM768-ECDH-P256-SHA3-256", "MLKEM768-ECDH-P384-SHA3-256",
46-
"MLKEM768-ECDH-BP256-SHA3-256", "MLKEM1024-RSA3072-SHA3-256", "MLKEM1024-ECDH-P384-SHA3-256",
47-
"MLKEM1024-ECDH-BP384-SHA3-256", "MLKEM1024-X448-SHA3-256", "MLKEM1024-ECDH-P521-SHA3-256"
46+
"MLKEM768-ECDH-brainpoolP256r1-SHA3-256", "MLKEM1024-RSA3072-SHA3-256", "MLKEM1024-ECDH-P384-SHA3-256",
47+
"MLKEM1024-ECDH-brainpoolP384r1-SHA3-256", "MLKEM1024-X448-SHA3-256", "MLKEM1024-ECDH-P521-SHA3-256"
4848
};
4949

5050
private static final ASN1ObjectIdentifier[] OIDS = {
5151
IANAObjectIdentifiers.id_MLKEM768_RSA2048_SHA3_256, IANAObjectIdentifiers.id_MLKEM768_RSA3072_SHA3_256,
5252
IANAObjectIdentifiers.id_MLKEM768_RSA4096_SHA3_256, IANAObjectIdentifiers.id_MLKEM768_X25519_SHA3_256,
5353
IANAObjectIdentifiers.id_MLKEM768_ECDH_P256_SHA3_256, IANAObjectIdentifiers.id_MLKEM768_ECDH_P384_SHA3_256,
54-
IANAObjectIdentifiers.id_MLKEM768_ECDH_BP256_SHA3_256, IANAObjectIdentifiers.id_MLKEM1024_RSA3072_SHA3_256,
55-
IANAObjectIdentifiers.id_MLKEM1024_ECDH_P384_SHA3_256, IANAObjectIdentifiers.id_MLKEM1024_ECDH_BP384_SHA3_256,
54+
IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256, IANAObjectIdentifiers.id_MLKEM1024_RSA3072_SHA3_256,
55+
IANAObjectIdentifiers.id_MLKEM1024_ECDH_P384_SHA3_256, IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256,
5656
IANAObjectIdentifiers.id_MLKEM1024_X448_SHA3_256, IANAObjectIdentifiers.id_MLKEM1024_ECDH_P521_SHA3_256
5757
};
5858

‎prov/src/main/java/org/bouncycastle/jcajce/CompositePrivateKey.java‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,19 @@ public CompositePrivateKey(PrivateKeyInfo keyInfo)
199199
ASN1ObjectIdentifier keyInfoIdentifier = keyInfo.getPrivateKeyAlgorithm().getAlgorithm();
200200
try
201201
{
202-
if (!CompositeIndex.isAlgorithmSupported(keyInfoIdentifier))
202+
AsymmetricKeyInfoConverter keyInfoConverter;
203+
if (CompositeIndex.isAlgorithmSupported(keyInfoIdentifier))
204+
{
205+
keyInfoConverter = new KeyFactorySpi();
206+
}
207+
else if (org.bouncycastle.jcajce.provider.asymmetric.compositekem.CompositeIndex.isCompositeKEMOID(keyInfoIdentifier))
208+
{
209+
keyInfoConverter = new org.bouncycastle.jcajce.provider.asymmetric.compositekem.KeyFactorySpi();
210+
}
211+
else
203212
{
204213
throw new IllegalStateException("Unable to create CompositePrivateKey from PrivateKeyInfo");
205214
}
206-
AsymmetricKeyInfoConverter keyInfoConverter = new KeyFactorySpi();
207215
privateKeyFromFactory = (CompositePrivateKey)keyInfoConverter.generatePrivate(keyInfo);
208216

209217
if (privateKeyFromFactory == null)
@@ -241,9 +249,25 @@ public List<Provider> getProviders()
241249
return providers;
242250
}
243251

252+
/**
253+
* Return the name the composite algorithm this key belongs to is registered under, or null if
254+
* the key's algorithm is not one of the composite signature or composite KEM parameter sets
255+
* (the legacy generic composite key OIDs have no registered name of their own).
256+
*
257+
* @return the composite algorithm name, e.g. "MLDSA44-Ed25519-SHA512" or "MLKEM768-X25519-SHA3-256".
258+
*/
244259
public String getAlgorithm()
245260
{
246-
return CompositeIndex.getAlgorithmName(this.algorithmIdentifier.getAlgorithm()); // UPDATED
261+
ASN1ObjectIdentifier algOid = this.algorithmIdentifier.getAlgorithm();
262+
String algorithmName = CompositeIndex.getAlgorithmName(algOid);
263+
264+
if (algorithmName == null)
265+
{
266+
// the composite KEM parameter sets are held in their own index
267+
algorithmName = org.bouncycastle.jcajce.provider.asymmetric.compositekem.CompositeIndex.getAlgorithmName(algOid);
268+
}
269+
270+
return algorithmName;
247271
}
248272

249273
public AlgorithmIdentifier getAlgorithmIdentifier()

‎prov/src/main/java/org/bouncycastle/jcajce/CompositePublicKey.java‎

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
import org.bouncycastle.asn1.ASN1EncodableVector;
1212
import org.bouncycastle.asn1.ASN1Encoding;
1313
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
14+
import org.bouncycastle.asn1.DERBitString;
1415
import org.bouncycastle.asn1.DERSequence;
1516
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
1617
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
1718
import org.bouncycastle.asn1.iana.IANAObjectIdentifiers;
1819
import org.bouncycastle.internal.asn1.misc.MiscObjectIdentifiers;
1920
import org.bouncycastle.jcajce.provider.asymmetric.compositesignatures.CompositeIndex;
2021
import org.bouncycastle.jcajce.provider.asymmetric.compositesignatures.KeyFactorySpi;
22+
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
2123
import org.bouncycastle.jcajce.provider.util.AsymmetricKeyInfoConverter;
24+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
2225
import org.bouncycastle.util.Arrays;
2326
import org.bouncycastle.util.Exceptions;
2427

@@ -143,12 +146,21 @@ public CompositePublicKey(SubjectPublicKeyInfo keyInfo)
143146
CompositePublicKey publicKeyFromFactory = null;
144147
try
145148
{
146-
//Check if the public key algorithm specified in SubjectPublicKeyInfo is one of the supported composite signatures.
147-
if (!CompositeIndex.isAlgorithmSupported(keyInfoIdentifier))
149+
//Check if the public key algorithm specified in SubjectPublicKeyInfo is one of the
150+
//supported composite signatures or one of the supported composite KEMs.
151+
AsymmetricKeyInfoConverter keyInfoConverter;
152+
if (CompositeIndex.isAlgorithmSupported(keyInfoIdentifier))
153+
{
154+
keyInfoConverter = new KeyFactorySpi();
155+
}
156+
else if (org.bouncycastle.jcajce.provider.asymmetric.compositekem.CompositeIndex.isCompositeKEMOID(keyInfoIdentifier))
157+
{
158+
keyInfoConverter = new org.bouncycastle.jcajce.provider.asymmetric.compositekem.KeyFactorySpi();
159+
}
160+
else
148161
{
149162
throw new IllegalStateException("unable to create CompositePublicKey from SubjectPublicKeyInfo");
150163
}
151-
AsymmetricKeyInfoConverter keyInfoConverter = new KeyFactorySpi();
152164
publicKeyFromFactory = (CompositePublicKey)keyInfoConverter.generatePublic(keyInfo);
153165

154166
if (publicKeyFromFactory == null)
@@ -217,9 +229,25 @@ public List<Provider> getProviders()
217229
return providers;
218230
}
219231

232+
/**
233+
* Return the name the composite algorithm this key belongs to is registered under, or null if
234+
* the key's algorithm is not one of the composite signature or composite KEM parameter sets
235+
* (the legacy generic composite key OIDs have no registered name of their own).
236+
*
237+
* @return the composite algorithm name, e.g. "MLDSA44-Ed25519-SHA512" or "MLKEM768-X25519-SHA3-256".
238+
*/
220239
public String getAlgorithm()
221240
{
222-
return CompositeIndex.getAlgorithmName(this.algorithmIdentifier.getAlgorithm());
241+
ASN1ObjectIdentifier algOid = this.algorithmIdentifier.getAlgorithm();
242+
String algorithmName = CompositeIndex.getAlgorithmName(algOid);
243+
244+
if (algorithmName == null)
245+
{
246+
// the composite KEM parameter sets are held in their own index
247+
algorithmName = org.bouncycastle.jcajce.provider.asymmetric.compositekem.CompositeIndex.getAlgorithmName(algOid);
248+
}
249+
250+
return algorithmName;
223251
}
224252

225253
public AlgorithmIdentifier getAlgorithmIdentifier()
@@ -253,9 +281,9 @@ public byte[] getEncoded()
253281
{
254282
try
255283
{
256-
byte[] mldsaPK = SubjectPublicKeyInfo.getInstance(keys.get(0).getEncoded()).getPublicKeyData().getOctets();
257-
byte[] tradPK = SubjectPublicKeyInfo.getInstance(keys.get(1).getEncoded()).getPublicKeyData().getOctets();
258-
return new SubjectPublicKeyInfo(algorithmIdentifier, Arrays.concatenate(mldsaPK, tradPK)).getEncoded(ASN1Encoding.DER);
284+
byte[] pqcPK = getComponentKeyBytes(keys.get(0));
285+
byte[] tradPK = getComponentKeyBytes(keys.get(1));
286+
return new SubjectPublicKeyInfo(algorithmIdentifier, Arrays.concatenate(pqcPK, tradPK)).getEncoded(ASN1Encoding.DER);
259287
}
260288
catch (IOException e)
261289
{
@@ -277,7 +305,7 @@ public byte[] getEncoded()
277305
else
278306
{
279307
//component is the value of subjectPublicKey from SubjectPublicKeyInfo
280-
v.add(spki.getPublicKeyData());
308+
v.add(new DERBitString(getComponentKeyBytes(keys.get(i))));
281309
}
282310
}
283311

@@ -291,6 +319,21 @@ public byte[] getEncoded()
291319
}
292320
}
293321

322+
/**
323+
* The bytes a component public key contributes to the composite encoding - the contents of its
324+
* SubjectPublicKeyInfo subjectPublicKey BIT STRING - with an EC point normalised to its
325+
* uncompressed encoding as section 4 of both composite drafts requires. A component key that
326+
* would encode itself compressed therefore no longer produces a composite key that other
327+
* implementations reject and whose encoding changed across an encode / decode / encode round
328+
* trip. This is a write-side normalisation: a composite key carrying a compressed component is
329+
* still decoded, since the component key factories accept either form.
330+
*/
331+
private static byte[] getComponentKeyBytes(PublicKey key)
332+
{
333+
return ECUtil.getUncompressedSubjectPublicKeyBytes(
334+
SubjectPublicKeyInfo.getInstance(key.getEncoded()), BouncyCastleProvider.CONFIGURATION);
335+
}
336+
294337
public int hashCode()
295338
{
296339
return algorithmIdentifier.hashCode() ^ keys.hashCode();

‎prov/src/main/java/org/bouncycastle/jcajce/CompositeUtil.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ class CompositeUtil
4040
algorithmOids.put("MLKEM768-X25519-SHA3-256", IANAObjectIdentifiers.id_MLKEM768_X25519_SHA3_256);
4141
algorithmOids.put("MLKEM768-ECDH-P256-SHA3-256", IANAObjectIdentifiers.id_MLKEM768_ECDH_P256_SHA3_256);
4242
algorithmOids.put("MLKEM768-ECDH-P384-SHA3-256", IANAObjectIdentifiers.id_MLKEM768_ECDH_P384_SHA3_256);
43-
algorithmOids.put("MLKEM768-ECDH-BP256-SHA3-256", IANAObjectIdentifiers.id_MLKEM768_ECDH_BP256_SHA3_256);
43+
algorithmOids.put("MLKEM768-ECDH-BRAINPOOLP256R1-SHA3-256", IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256);
44+
algorithmOids.put("MLKEM768-ECDH-BP256-SHA3-256", IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256);
4445
algorithmOids.put("MLKEM1024-RSA3072-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_RSA3072_SHA3_256);
4546
algorithmOids.put("MLKEM1024-ECDH-P384-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_ECDH_P384_SHA3_256);
46-
algorithmOids.put("MLKEM1024-ECDH-BP384-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_ECDH_BP384_SHA3_256);
47+
algorithmOids.put("MLKEM1024-ECDH-BRAINPOOLP384R1-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256);
48+
algorithmOids.put("MLKEM1024-ECDH-BP384-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256);
4749
algorithmOids.put("MLKEM1024-X448-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_X448_SHA3_256);
4850
algorithmOids.put("MLKEM1024-ECDH-P521-SHA3-256", IANAObjectIdentifiers.id_MLKEM1024_ECDH_P521_SHA3_256);
4951
}

‎prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/CompositeKEMs.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public void configure(ConfigurableProvider provider)
5353
provider.addAlgorithm("Alg.Alias.Cipher", oid, algorithmName);
5454

5555
provider.addKeyInfoConverter(oid, new KeyFactorySpi());
56+
57+
String[] aliases = CompositeIndex.getAlgorithmAliases(oid);
58+
for (int i = 0; i != aliases.length; i++)
59+
{
60+
provider.addAlgorithm("Alg.Alias.KeyFactory." + aliases[i], "COMPOSITE");
61+
provider.addAlgorithm("Alg.Alias.KeyPairGenerator." + aliases[i], algorithmName);
62+
provider.addAlgorithm("Alg.Alias.KeyGenerator." + aliases[i], algorithmName);
63+
provider.addAlgorithm("Alg.Alias.Cipher." + aliases[i], algorithmName);
64+
}
5665
}
5766
}
5867
}

‎prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/compositekem/CompositeIndex.java‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CompositeIndex
2525
private static final Map<ASN1ObjectIdentifier, String> algorithmNames = new HashMap<ASN1ObjectIdentifier, String>();
2626
private static final Map<ASN1ObjectIdentifier, byte[]> kemLabels = new HashMap<ASN1ObjectIdentifier, byte[]>();
2727
private static final Map<ASN1ObjectIdentifier, AlgorithmParameterSpec[]> kpgInitSpecs = new HashMap<ASN1ObjectIdentifier, AlgorithmParameterSpec[]>();
28+
private static final Map<ASN1ObjectIdentifier, String[]> algorithmAliases = new HashMap<ASN1ObjectIdentifier, String[]>();
2829

2930
static
3031
{
@@ -75,8 +76,8 @@ public class CompositeIndex
7576
);
7677

7778
registerKEMAlgorithm(
78-
IANAObjectIdentifiers.id_MLKEM768_ECDH_BP256_SHA3_256,
79-
"MLKEM768-ECDH-BP256-SHA3-256",
79+
IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256,
80+
"MLKEM768-ECDH-brainpoolP256r1-SHA3-256",
8081
Strings.toByteArray("MLKEM768-BP256"),
8182
new String[]{"ML-KEM-768", "EC"}
8283
);
@@ -98,8 +99,8 @@ public class CompositeIndex
9899
);
99100

100101
registerKEMAlgorithm(
101-
IANAObjectIdentifiers.id_MLKEM1024_ECDH_BP384_SHA3_256,
102-
"MLKEM1024-ECDH-BP384-SHA3-256",
102+
IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256,
103+
"MLKEM1024-ECDH-brainpoolP384r1-SHA3-256",
103104
Strings.toByteArray("MLKEM1024-BP384"),
104105
new String[]{"ML-KEM-1024", "EC"}
105106
);
@@ -119,6 +120,11 @@ public class CompositeIndex
119120
new String[]{"ML-KEM-1024", "EC"}
120121
);
121122

123+
// The two brainpool sets were originally registered with the curve abbreviated to BP256 /
124+
// BP384; those names are kept as aliases of the draft's spelling.
125+
algorithmAliases.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256, new String[]{"MLKEM768-ECDH-BP256-SHA3-256"});
126+
algorithmAliases.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256, new String[]{"MLKEM1024-ECDH-BP384-SHA3-256"});
127+
122128
// Per-component KeyPairGenerator init specs (in pairing order: ML-KEM first, traditional
123129
// second). The ML-KEM component is generated through its parameter-set-specific
124130
// KeyPairGenerator name ("ML-KEM-768" / "ML-KEM-1024") so it needs no spec.
@@ -128,10 +134,10 @@ public class CompositeIndex
128134
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM768_X25519_SHA3_256, new AlgorithmParameterSpec[]{null, null});
129135
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_P256_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("P-256")});
130136
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_P384_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("P-384")});
131-
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_BP256_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("brainpoolP256r1")});
137+
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM768_ECDH_brainpoolP256r1_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("brainpoolP256r1")});
132138
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM1024_RSA3072_SHA3_256, new AlgorithmParameterSpec[]{null, new RSAKeyGenParameterSpec(3072, RSAKeyGenParameterSpec.F4)});
133139
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_P384_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("P-384")});
134-
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_BP384_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("brainpoolP384r1")});
140+
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_brainpoolP384r1_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("brainpoolP384r1")});
135141
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM1024_X448_SHA3_256, new AlgorithmParameterSpec[]{null, null});
136142
kpgInitSpecs.put(IANAObjectIdentifiers.id_MLKEM1024_ECDH_P521_SHA3_256, new AlgorithmParameterSpec[]{null, new ECNamedCurveGenParameterSpec("P-521")});
137143
}
@@ -161,6 +167,17 @@ public static String[] getPairing(ASN1ObjectIdentifier algorithm)
161167
return pairings.get(algorithm);
162168
}
163169

170+
/**
171+
* Additional names a composite KEM algorithm is registered under, beyond the one
172+
* {@link #getAlgorithmName} returns. Empty for every parameter set that has only one name.
173+
*/
174+
public static String[] getAlgorithmAliases(ASN1ObjectIdentifier algorithm)
175+
{
176+
String[] aliases = algorithmAliases.get(algorithm);
177+
178+
return (aliases != null) ? aliases : new String[0];
179+
}
180+
164181
private static void registerKEMAlgorithm(ASN1ObjectIdentifier oid, String algorithmName,
165182
byte[] label, String[] pairing)
166183
{

0 commit comments

Comments
 (0)