Skip to content

ML-DSA x86_64: import full assembly backend from mldsa-native#3357

Draft
jakemas wants to merge 2 commits into
aws:mainfrom
jakemas:mldsa-x86-full-import
Draft

ML-DSA x86_64: import full assembly backend from mldsa-native#3357
jakemas wants to merge 2 commits into
aws:mainfrom
jakemas:mldsa-x86-full-import

Conversation

@jakemas

@jakemas jakemas commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

import mldsa-native v1, including x86 backend additions

Description of changes

Imports the complete mldsa-native x86_64 assembly backend, bringing in the six ML-DSA operations that were previously AVX2 C intrinsics and excluded from the import (#3195): rej_uniform, rej_uniform_eta2/eta4, poly_decompose_32/88, poly_use_hint_32/88, poly_chknorm, and polyz_unpack_17/19. Each of these assembly routines has a verified functional-correctness and memory-safety proof in s2n-bignum, which is the bar for importing assembly here.

The upstream x86_64 backend is now 100% assembly (no AVX2 C intrinsics remain), so this brings x86_64 in line with the aarch64 backend (#3219): the importer copies the whole backend tree verbatim and uses the upstream meta.h directly, and the hand-maintained mldsa_x86_64_meta.h is removed.

This is a full mldsa-native re-import (pin bumped to 1dbd70f7), so the diff also includes the corresponding C-source refresh. One upstream API change is worth calling out for review:

  • The mld_sign_signature/mld_sign_verify family dropped the sig_len parameter (signatures are fixed size). AWS-LC's ml_dsa.c glue is migrated accordingly: the inner calls drop the argument, and the signature wrappers set *sig_len = MLDSA{44,65,87}_SIGNATURE_BYTES themselves. The public AWS-LC wrapper prototypes are unchanged.

Commit 1 is the hand-authored change (importer script + glue); commit 2 is the mechanical output of running importer.sh.

Testing

All 79 ML-DSA tests pass (crypto_test --gtest_filter='*MLDSA*') on x86_64 with AVX2. nm confirms the native dispatchers call the new assembly (the symbols are undefined references from the BCM object, not fallbacks).

Benchmarked with bssl speed -filter MLDSA on x86_64 (AVX2), before (6 ops still C vs. after (full assembly), ops/sec:

Operation Before After Speedup
MLDSA44 keygen 18,167 23,217 1.28x
MLDSA44 signing 4,789 6,868 1.43x
MLDSA44 verify 17,491 26,296 1.50x
MLDSA65 keygen 8,660 13,468 1.56x
MLDSA65 signing 3,414 4,085 1.20x
MLDSA65 verify 10,879 15,275 1.40x
MLDSA87 keygen 6,943 9,146 1.32x
MLDSA87 signing 2,645 3,694 1.40x
MLDSA87 verify 7,224 10,220 1.41x

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

github-actions[bot]

This comment was marked as spam.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 Security ReviewView Report

Please review before merging.

@codecov-commenter

codecov-commenter commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.81395% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.21%. Comparing base (b06d89b) to head (f2a71bd).

Files with missing lines Patch % Lines
crypto/fipsmodule/ml_dsa/ml_dsa.c 75.00% 18 Missing ⚠️
...rypto/fipsmodule/ml_dsa/mldsa/native/x86_64/meta.h 80.23% 17 Missing ⚠️
crypto/fipsmodule/ml_dsa/mldsa/sign.c 56.41% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3357      +/-   ##
==========================================
+ Coverage   78.20%   78.21%   +0.01%     
==========================================
  Files         695      696       +1     
  Lines      124172   124290     +118     
  Branches    17238    17277      +39     
==========================================
+ Hits        97104    97218     +114     
- Misses      26147    26149       +2     
- Partials      921      923       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jakemas added 2 commits July 21, 2026 22:49
Prepares AWS-LC to import the complete mldsa-native x86_64 assembly
backend, matching the aarch64 backend. The upstream x86_64 backend is now
100% assembly (no AVX2 C intrinsics), so:

- importer.sh: copy the whole native/x86_64 tree verbatim (as for
  aarch64) and drop the obsolete BCM C-intrinsic include stripping.
- mldsa_native_backend.h: include the imported upstream
  mldsa/native/x86_64/meta.h and remove the hand-maintained
  mldsa_x86_64_meta.h.
- mldsa_native_config.h: track the MLD_SYS_CAP_AVX2 ->
  MLD_SYS_CAP_X86_64_AVX2 rename.
- ml_dsa.c: adapt to the mldsa-native API change that dropped siglen from
  the sign/verify functions (pq-code-package/mldsa-native#1240). Signing
  now writes a fixed-size signature, so the wrappers set *sig_len
  themselves. Verification no longer forwards siglen to the callee, so the
  wrappers check it up front (sig_len == MLDSA{44,65,87}_SIGNATURE_BYTES)
  before verifying, keeping the length guard the old forwarded siglen used
  to provide for direct-API callers. Matches the ML-KEM length checks.
Result of running importer.sh against mldsa-native
1dbd70f78583fab6fbfc46287702d6a09d5ec5e6. Imports the complete x86_64
assembly backend: adds verified .S implementations for poly_chknorm,
poly_decompose_{32,88}, poly_use_hint_{32,88}, polyz_unpack_{17,19},
rej_uniform, and rej_uniform_eta{2,4} (previously AVX2 C intrinsics,
excluded from import), plus the upstream meta.h and rej_uniform_table.c.
The remainder is the corresponding mldsa-native C-source refresh.

Generated by importer.sh; do not edit by hand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants