Skip to content

Commit 6152118

Browse files
Update tests for new algorithms and message digests. (#1458)
Another change to get the repos in sync.
1 parent da0a4a8 commit 6152118

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

common/src/test/java/org/conscrypt/java/security/KeyPairGeneratorTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

common/src/test/java/org/conscrypt/java/security/MessageDigestTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ private static Map<String, byte[]> getExpectations(String algorithm) throws Exce
169169
TestUtils.decodeHex(
170170
"a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a6"
171171
+ "15b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"));
172+
putExpectation("SHAKE128-256", INPUT_EMPTY,
173+
TestUtils.decodeHex(
174+
"7f9c2ba4e88f827d616045507605853ed73b8093f6efbc88eb1a6eacfa66ef26"));
175+
putExpectation("SHAKE256-512", INPUT_EMPTY,
176+
TestUtils.decodeHex(
177+
"46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f"
178+
+ "d75dc4ddd8c0f200cb05019d67b592f6fc821c49479ab48640292eacb3b7c4be"));
172179

173180
// Regression test for a SHA-1 problem with inputs larger than 256 MiB. http://b/4501620
174181
// In mid-2013 this takes 3 minutes even on the host, so let's not run it on devices.

0 commit comments

Comments
 (0)