From 6ec36d348b1eaeedb993a905e42650242fac0918 Mon Sep 17 00:00:00 2001 From: Ferenc Rakoczi Date: Fri, 12 Dec 2025 16:04:56 +0000 Subject: [PATCH] 8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java should pass on Aarch64 Reviewed-by: weijun, vpaprotski --- .../classes/sun/security/provider/ML_DSA.java | 2 +- .../{acvp => pqc}/ML_DSA_Intrinsic_Test.java | 90 +++++++++++++------ 2 files changed, 63 insertions(+), 29 deletions(-) rename test/jdk/sun/security/provider/{acvp => pqc}/ML_DSA_Intrinsic_Test.java (90%) diff --git a/src/java.base/share/classes/sun/security/provider/ML_DSA.java b/src/java.base/share/classes/sun/security/provider/ML_DSA.java index af64ef399a8..6a578427e51 100644 --- a/src/java.base/share/classes/sun/security/provider/ML_DSA.java +++ b/src/java.base/share/classes/sun/security/provider/ML_DSA.java @@ -1555,7 +1555,7 @@ public class ML_DSA { return res; } - // precondition: -2^31 * MONT_Q <= a, b < 2^31, -2^31 < a * b < 2^31 * MONT_Q + // precondition: -2^31 <= a, b < 2^31, -2^31 * MONT_Q <= a * b < 2^31 * MONT_Q // computes a * b * 2^-32 mod MONT_Q // the result is greater than -MONT_Q and less than MONT_Q // See e.g. Algorithm 3 in https://eprint.iacr.org/2018/039.pdf diff --git a/test/jdk/sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java b/test/jdk/sun/security/provider/pqc/ML_DSA_Intrinsic_Test.java similarity index 90% rename from test/jdk/sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java rename to test/jdk/sun/security/provider/pqc/ML_DSA_Intrinsic_Test.java index 1e9faf7fb74..d6d9fea789f 100644 --- a/test/jdk/sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java +++ b/test/jdk/sun/security/provider/pqc/ML_DSA_Intrinsic_Test.java @@ -38,16 +38,17 @@ import java.util.HexFormat; */ /* * @test - * @comment This test should be reenabled on aarch64 - * @requires os.simpleArch == "x64" * @library /test/lib * @key randomness * @modules java.base/sun.security.provider:+open * @run main ML_DSA_Intrinsic_Test */ -// To run manually: java --add-opens java.base/sun.security.provider=ALL-UNNAMED --add-exports java.base/sun.security.provider=ALL-UNNAMED -// -XX:+UnlockDiagnosticVMOptions -XX:+UseDilithiumIntrinsics test/jdk/sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java +// To run manually: +// java --add-opens java.base/sun.security.provider=ALL-UNNAMED +// --add-exports java.base/sun.security.provider=ALL-UNNAMED +// -XX:+UnlockDiagnosticVMOptions -XX:+UseDilithiumIntrinsics +// test/jdk/sun/security/provider/pqc/ML_DSA_Intrinsic_Test.java public class ML_DSA_Intrinsic_Test { public static void main(String[] args) throws Throwable { @@ -104,9 +105,10 @@ public class ML_DSA_Intrinsic_Test { m.setAccessible(true); MethodHandle inverseNttJava = lookup.unreflect(m); - // Hint: if test fails, you can hardcode the seed to make the test more reproducible Random rnd = new Random(); long seed = rnd.nextLong(); + // Hint: if a test fails, it prints the seed, so you can hardcode + // it here to reproduce the failure rnd.setSeed(seed); //Note: it might be useful to increase this number during development of new intrinsics final int repeat = 10000; @@ -117,32 +119,49 @@ public class ML_DSA_Intrinsic_Test { int[] prod3 = new int[ML_DSA_N]; int[] prod4 = new int[ML_DSA_N]; for (int i = 0; i < repeat; i++) { - // Hint: if test fails, you can hardcode the seed to make the test more reproducible: - // rnd.setSeed(seed); - testMult(prod1, prod2, coeffs1, coeffs2, mult, multJava, rnd, seed, i); + testMult(prod1, prod2, coeffs1, coeffs2, + mult, multJava, rnd, seed, i); testMultConst(prod1, prod2, multConst, multConstJava, rnd, seed, i); - testDecompose(prod1, prod2, prod3, prod4, coeffs1, coeffs2, decompose, decomposeJava, rnd, seed, i); + testDecompose(prod1, prod2, prod3, prod4, coeffs1, coeffs2, + decompose, decomposeJava, rnd, seed, i); testAlmostNtt(coeffs1, coeffs2, almostNtt, almostNttJava, rnd, seed, i); testInverseNtt(coeffs1, coeffs2, inverseNtt, inverseNttJava, rnd, seed, i); } System.out.println("Fuzz Success"); } - private static final int ML_DSA_N = 256; - public static void testMult(int[] prod1, int[] prod2, int[] coeffs1, int[] coeffs2, + public static void testMult(int[] prod1, int[] prod2, + int[] coeffs1, int[] coeffs2, MethodHandle mult, MethodHandle multJava, Random rnd, long seed, int i) throws Throwable { - for (int j = 0; j