Skip to content

8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java should pass on Aarch64#28722

Closed
ferakocz wants to merge 2 commits intoopenjdk:masterfrom
ferakocz:MLDSA-test
Closed

8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java should pass on Aarch64#28722
ferakocz wants to merge 2 commits intoopenjdk:masterfrom
ferakocz:MLDSA-test

Conversation

@ferakocz
Copy link
Contributor

@ferakocz ferakocz commented Dec 9, 2025

…hould pass on Aarch64

The test used to fail because it had checked a stronger equivalence of the results of the Java method and its intrinsified version.
Other then fixing that, I did some formatting and corrected a comment.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java should pass on Aarch64 (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28722/head:pull/28722
$ git checkout pull/28722

Update a local copy of the PR:
$ git checkout pull/28722
$ git pull https://git.openjdk.org/jdk.git pull/28722/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28722

View PR using the GUI difftool:
$ git pr show -t 28722

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28722.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 9, 2025

👋 Welcome back ferakocz! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 9, 2025

@ferakocz This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java should pass on Aarch64

Reviewed-by: weijun, vpaprotski

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 71 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vpaprotsk, @wangweij) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot changed the title 8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java s… 8373059: Test sun/security/provider/acvp/ML_DSA_Intrinsic_Test.java should pass on Aarch64 Dec 9, 2025
@openjdk openjdk bot added the security security-dev@openjdk.org label Dec 9, 2025
@openjdk
Copy link

openjdk bot commented Dec 9, 2025

@ferakocz The following label will be automatically applied to this pull request:

  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 9, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 9, 2025

Webrevs

Copy link
Contributor

@vpaprotsk vpaprotsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claims:

  • "while the java version of implDilithiumNttMult can accept full signed INT32 on both coeffs1 and coeffs2, in the actual implementation of ML_DSA, calls never exceed -Q-to-+Q on either inputs"
    • (I believe, it allows aarch64 to rearrange some multiplications, perhaps to relieve some register-alloc pressure? Multiplications are commutative, so this is valid, except range would be exceeded)
  • "congruence is sufficient in modular arithmetic for test to pass"

The second claim is self-evident (which allows to relax the Arrays.equals test).
The first.. I was able to convince myself by going through the code:

  • All calls to implDilithiumNttMult originate from nttConstMultiply and matrixVectorPointwiseMultiply.
  • All inputs to nttConstMultiply and matrixVectorPointwiseMultiply are 'cleansed' by mlDsaVectorNtt, mlDsaNtt and generateA
    • mlDsaVectorNtt itself is 'cleansed' by mlDsaNtt
    • generateA masks its outputs to 23-bits (fits within the 2Q in this PR)
    • mlDsaNtt 'cleansed' by montMul
    • montMul returns range (-Q,Q) per paper in the comments.
image


if (!Arrays.equals(prod1, prod2)) {
throw new RuntimeException("[Seed "+seed+"@"+i+"] Result mult mismatch: " + formatOf(prod1) + " != " + formatOf(prod2));
boolean modQequal = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably had moved this to its own helper arraysCongruent and replaces the if (!Arrays.equals(prod1, prod2)) with !arraysCongruent(prod1, prod2). But not a deal-breaker..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your thorough review and comments!

// -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent one space to align with lines below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've modified the test path above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I have changed it.


if (!Arrays.equals(prod1, prod2)) {
throw new RuntimeException("[Seed "+seed+"@"+i+"] Result mult mismatch: " + formatOf(prod1) + " != " + formatOf(prod2));
boolean modQequal = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can copy the "the result is greater than -MONT_Q and less than MONT_Q" comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments.

coeffs2[j] = rnd.nextInt();
for (int j = 0; j < ML_DSA_N; j++) {
coeffs1[j] = rnd.nextInt(2 * ML_DSA_Q) - ML_DSA_Q;
coeffs2[j] = rnd.nextInt(2 * ML_DSA_Q) - ML_DSA_Q;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are both so small? Maybe only one is enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purely for performance reasons. The test works for any case that satisfies the montMul() preconditions, but since this particular method that is under test here, these stricter conditions are always satisfied. If we allow a bigger range, the probability that the whole vector fails the equality test is higher, so the for loop will be executed more frequently and that takes time. I added a comment to the code.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 12, 2025
@ferakocz
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 12, 2025
@openjdk
Copy link

openjdk bot commented Dec 12, 2025

@ferakocz
Your change (at version 917a505) is now ready to be sponsored by a Committer.

@wangweij
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 12, 2025

Going to push as commit 6ec36d3.
Since your change was applied there have been 71 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 12, 2025
@openjdk openjdk bot closed this Dec 12, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Dec 12, 2025
@openjdk
Copy link

openjdk bot commented Dec 12, 2025

@wangweij @ferakocz Pushed as commit 6ec36d3.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated security security-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants