Skip to content

[RFC] ML-KEM: Add AArch64 arithmetic backend (from s2n-bignum) #2500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hanno-becker
Copy link
Contributor

@hanno-becker hanno-becker commented Jun 23, 2025

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.


The purpose of this PR is to demonstrate and gather feedback on one option for integrating an AArch64 arithmetic backend for mlkem-native into AWS-LC.

Alternative option: #2498


Context: The ML-KEM implementation in AWS-LC is imported from mlkem-native. mlkem-native comes in a "C-only" version, but also offers AArch64 and x86_64 backends for (a) arithmetic, and (b) FIPS-202. Currently, only the "C-only" version is imported into AWS-LC.

This commit adds a custom AArch64 backend to AWS-LC. The backend is essentially the same as in mlkem-native, but its assembly sources are taken from s2n-bignum and its headers are written from scratch. The constant tables used in the backend are copied from mlkem-native.

Compared to extending the mlkem-native->AWS-LC importer (see #2498) to include mlkem-native's AArch64 backend, this approach sticks to s2n-bignum as the sole source of verified assembly. It also provides greater flexibility in maintaining and adjusting the backend, both the assembly and the headers. For example, the assembly may be optimized for Graviton cores in the future, or the dispatch in the metadata files adjusted; the latter will mostly be relevant as we integrate x86_64 assembly, for which we aim to use the same methodology.

s2n-bignum is partially re-imported from @jargh's development branch https://github.com/jargh/s2n-bignum-dev/tree/mlkem/, restricting to the ML-KEM related files. Keeping this PR as Draft until John's work is merged into main of s2n-bignum, and the updated s2n-bignum has been re-imported in a separate PR.

To avoid a symbol clash with s2n-bignum, the mlkem-native namespace is changed from mlkem to mlkem_native.

@hanno-becker hanno-becker force-pushed the mlkem_arith_backend_s2n_bignum branch 2 times, most recently from 752841e to b8f2779 Compare June 23, 2025 14:44
@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.85%. Comparing base (587cf97) to head (c16676e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2500      +/-   ##
==========================================
- Coverage   78.86%   78.85%   -0.01%     
==========================================
  Files         640      640              
  Lines      109560   109560              
  Branches    15522    15521       -1     
==========================================
- Hits        86402    86394       -8     
- Misses      22461    22468       +7     
- Partials      697      698       +1     

☔ View full report in Codecov by Sentry.
📢 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.

Context: The ML-KEM implementation in AWS-LC is imported from
mlkem-native. mlkem-native comes in a "C-only" version, but also
offers AArch64 and x86_64 backends for (a) arithmetic,
and (b) FIPS-202. Currently, only the "C-only" version is
imported into AWS-LC.

This commit adds a custom AArch64 backend to AWS-LC.
The backend is essentially the same as in mlkem-native, but its
assembly sources are taken from s2n-bignum and its headers are
written from scratch. The constant tables used in the backend
are copied from mlkem-native.

Compared to extending the mlkem-native->AWS-LC importer to include
mlkem-native's AArch64 backend, this approach sticks to s2n-bignum
as the sole source of verified assembly. It also provides greater
flexibility in maintaining and adjusting the backend, both the
assembly and the headers. For example, the assembly may be optimized
for Graviton cores in the future, or the dispatch in the metadata
files adjusted; the latter will mostly be relevant as we integrate
x86_64 assembly, for which we aim to use the same methodology.

To avoid a symbol clash with s2n-bignum, the mlkem-native namespace
is changed from `mlkem` to `mlkem_native`.

s2n-bignum is partially re-imported from the development branch
https://github.com/jargh/s2n-bignum-dev/tree/mlkem/, restricting to
the ML-KEM related files.

Signed-off-by: Hanno Becker <[email protected]>
@hanno-becker hanno-becker force-pushed the mlkem_arith_backend_s2n_bignum branch from b8f2779 to c16676e Compare June 23, 2025 15:13
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