@@ -152,6 +152,10 @@ private static List<Integer> getKeySizes(String algorithm) throws Exception {
152152 putKeySize ("EC" , 521 );
153153 putKeySize ("XDH" , 255 );
154154 putKeySize ("EdDSA" , 255 );
155+ putKeySize ("ML-KEM" , -1 );
156+ putKeySize ("ML-KEM-512" , -1 );
157+ putKeySize ("ML-KEM-768" , -1 );
158+ putKeySize ("ML-KEM-1024" , -1 );
155159 putKeySize ("ML-DSA" , -1 );
156160 putKeySize ("ML-DSA-44" , -1 );
157161 putKeySize ("ML-DSA-65" , -1 );
@@ -184,6 +188,11 @@ private void test_KeyPairGenerator(KeyPairGenerator kpg) throws Exception {
184188
185189 List <Integer > keySizes = getKeySizes (algorithm );
186190 for (int keySize : keySizes ) {
191+ if (algorithm .equals ("ML-KEM" )) {
192+ // The generic ML-KEM generator in SunJCE doesn't support initialize(keySize).
193+ // The specific named variants like "ML-KEM-512" are tested separately.
194+ continue ;
195+ }
187196 // TODO(flooey): Remove when we don't support Java 6 anymore
188197 if ("DSA" .equals (algorithm )
189198 && ("SUN" .equalsIgnoreCase (kpg .getProvider ().getName ())
@@ -252,6 +261,11 @@ private void test_Key(KeyPairGenerator kpg, Key k) throws Exception {
252261 // which supported generation of Ed25519 keys before Conscrypt did.
253262 expectedAlgorithm = "1.3.101.112" ;
254263 }
264+ if (expectedAlgorithm .startsWith ("ML-KEM" )) {
265+ // The KeyPairGenerator might be "ML-KEM-512", but the key it generates
266+ // has the algorithm "ML-KEM".
267+ expectedAlgorithm = "ML-KEM" ;
268+ }
255269 assertEquals (expectedAlgorithm , k .getAlgorithm ().toUpperCase (Locale .ROOT ));
256270 if (expectedAlgorithm .equals ("DH" )) {
257271 if (k instanceof DHPublicKey ) {
@@ -274,6 +288,10 @@ private void test_Key(KeyPairGenerator kpg, Key k) throws Exception {
274288 // ML-DSA keys are not yet serializable, so just skip them.
275289 return ;
276290 }
291+ if (expectedAlgorithm .equals ("ML-KEM" )) {
292+ // ML-KEM keys are not yet serializable, so just skip them.
293+ return ;
294+ }
277295 if (expectedAlgorithm .equals ("SLH-DSA-SHA2-128S" )) {
278296 // SLH-DSA keys are not yet serializable, so just skip them.
279297 return ;
0 commit comments