-
Notifications
You must be signed in to change notification settings - Fork 136
ML-KEM: Import AArch64 backend from mlkem-native #2498
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
Conversation
9f583c4
to
2749386
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2498 +/- ##
=======================================
Coverage 78.72% 78.73%
=======================================
Files 645 645
Lines 110641 110641
Branches 15648 15648
=======================================
+ Hits 87099 87109 +10
+ Misses 22843 22832 -11
- Partials 699 700 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a81eb55
to
417e91c
Compare
417e91c
to
65eda0d
Compare
65eda0d
to
9c42220
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does mlkem-native do the assembly dispatching? This raises an interesting gap we might have in our CI: building the arm implementation once and testing on all CPUs like we do for x86 with the Intel SDE.
echo "Fixup include paths" | ||
sed "${SED_I[@]}" 's/#include "src\/\([^"]*\)"/#include "\1"/' $SRC/mlkem_native_bcm.c | ||
|
||
echo "Fixup AArch64 assembly backend to use s2n-bignum macros" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update aws-lc's code to not need to modify the mlkem-native code? I would like to keep this as simple as git clone and copying some directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The delocator seems to have issues with nested relative #include's, so trying to have it process the ASM as it is in mlkem-native seems to be a challenge, at best. I'm not convinced that patching the delocator and build is better than patching the assembly headers to be compatible with the existing tooling.
What we're currently doing is replacing
#include "../../../common.h"
#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED)
.text
.balign 4
.global MLK_ASM_NAMESPACE(ntt_asm)
MLK_ASM_FN_SYMBOL(ntt_asm)
by
#include "_internal_s2n_bignum.h"
.text
.balign 4
S2N_BN_SYM_VISIBILITY_DIRECTIVE(mlkem_ntt_asm)
S2N_BN_SYM_PRIVACY_DIRECTIVE(mlkem_ntt_asm)
S2N_BN_SYMBOL(mlkem_ntt_asm):
This doesn't look too bad to me. Also, there is still room for simplification, since in mlkem-native we could use a different macro structure (e.g. wrapping .global MLK_ASM_NAMESPACE(...)
as MLK_ASM_GLOBAL(...)
which would further simplify the search-and-replace transformation to the s2n-bignum directives.
9ffcf39
to
f53824c
Compare
f53824c
to
a811024
Compare
a811024
to
ed9a708
Compare
Is the new backend code supposed to work on all aarch64 processors? Or are there specific versions/capabilities we need to be present for the code to work? |
@dkostic The backend is supposed to work with all AArch64 processors. Since Neon is mandatory with AArch64 and we do not use any extensions, no runtime checks are required (at least, as far as I know). |
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. Summary: This commit extends the mlkem-native->AWS-LC import to include the AArch64 arithmetic backend. Details: - `crypto/fipsmodule/ml_kem/importer.sh` now imports the arithmetic backend API header `native/api.h` as well as the native backend `native/aarch64/*`. - The backend is imported as-is, with one exception: `importer.sh` converts the preprocessor directives used by mlkem-native into the ones used by s2n-bignum. This is to piggy-back on the adjustments made to the delocator to work with s2n-bignum assembly; otherwise, similar adjustments would likely be needed for mlkem-native assembly files. - All imported functions are formally verified for functional correctness using HOL-Light. The proofs run as part of mlkem-native's CI. The HOL-Light specs are manually translated into CBMC specs in the header accompanying the ASM, and all higher level CBMC proofs conducted against those specs. Again, those are part of the mlkem-native CI. - A backend header crypto/fipsmodule/ml_kem/mlkem_native_backend.h is added, activating the AArch64 arithmetic backend on Linux and MacOS AArch64 system, except if the NO_ASM directive is set (same as for s2n-bignum). Once the x86_64 arithmetic backend is ready for integration, it will be added to `mlkem_native_backend.h` as well. - The backend header is registered in the configuration file `crypto/fipsmodule/ml_kem/mlkem_native_config.h`. - The importer.sh is re-run. Signed-off-by: Hanno Becker <[email protected]>
dbcadca
to
7d888dc
Compare
# Set the source directory for s2n-bignum assembly files | ||
set(MLKEM_NATIVE_DIR "${AWSLC_SOURCE_DIR}/crypto/fipsmodule/ml_kem") | ||
|
||
set(MLKEM_NATIVE_AARCH64_ASM_SOURCES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be simplified to
list(APPEND BCM_ASM_SOURCES
Not important.
@dkostic @torben-hansen Do you want me to rebase or will you take care of that during merge? |
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.
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.
Summary: This commit extends the mlkem-native->AWS-LC import to include the AArch64 arithmetic backend.
Details:
crypto/fipsmodule/ml_kem/importer.sh
now importsthe arithmetic backend API header
native/api.h
as wellas the native backend
native/aarch64/*
.The backend is imported as-is, with one exception:
importer.sh
converts the preprocessor directives used bymlkem-native into the ones used by s2n-bignum. This is to
piggy-back on the adjustments made to the delocator to work
with s2n-bignum assembly; otherwise, similar adjustments would
likely be needed for mlkem-native assembly files.
All imported functions are formally verified for functional
correctness using HOL-Light. The proofs run as part of
mlkem-native's CI. The HOL-Light specs are manually translated
into CBMC specs in the header accompanying the ASM, and
all higher level CBMC proofs conducted against those specs.
Again, those are part of the mlkem-native CI.
A backend header crypto/fipsmodule/ml_kem/mlkem_native_backend.h
is added, activating the AArch64 arithmetic backend on Linux and
MacOS AArch64 system, except if the NO_ASM directive is set
(same as for s2n-bignum).
Once the x86_64 arithmetic backend is ready for integration,
it will be added to
mlkem_native_backend.h
as well.The backend header is registered in the configuration file
crypto/fipsmodule/ml_kem/mlkem_native_config.h
.The importer.sh is re-run.
Performance
Example for header patching during import:
Before (mlkem-native):
After (imported):