Skip to content

Commit 8472767

Browse files
committed
Re-import mlkem-native and mldsa-native; drop custom meta headers
This commit re-imports mlkem-native (v1.3.0, 398050c87) and mldsa-native (c800f268c) and removes the three "shadow" backend meta headers owned by AWS-LC (ml_kem/mlkem_aarch64_meta.h, ml_dsa/mldsa_aarch64_meta.h, and ml_dsa/mldsa_x86_64_meta.h). The AArch64 shadows existed to add a runtime NEON gate with a C fallback; upstream now gates NEON in the vendored meta.h itself. The x86_64 mldsa shadow trimmed the backend to the assembly-backed subset. Upstream has since converted the remaining AVX2 C-intrinsic operations to proven assembly, so the full backend is imported and its meta.h is used as-is. The commit also removes a previous label-renaming at import time that was in place to avoid a name clash between mlkem and mldsa labels: Upstream has since made the labels globally unique (mlkem-native PR#1813 and mldsa-native PR#1310). Finally, the commit removes a previous file-renaming at import time that was in place to avoid a name clash between the mlkem and mldsa assembly files, which are compiled into the same FIPS module. Upstream has since prefixed the backend assembly filenames per project (mlkem_*_asm.S and mldsa_*_asm.S), so the basenames are globally unique and the individual .S files can again be built directly. The mlkem importer gains -UMLK_CONFIG_NO_{KEYPAIR,ENCAPS,DECAPS}_API in the assembly unifdef invocation, mirroring what the mldsa importer already does: v1.3.0 added these terms to the backend guards, and without resolving them the guards would not collapse, leaving the imported assembly gated on macros that are no longer in scope once common.h is replaced by the s2n-bignum header. This commit also reverts the custom configs to the vendored capability enum (mldsa: `MLD_SYS_CAP_X86_64_AVX2`), adjusts ml_dsa.c for the `sig_len`-less upstream sign/verify API, and makes `GITHUB_SERVER_URL` overridable in both importers. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent fe08b9c commit 8472767

141 files changed

Lines changed: 9934 additions & 5492 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crypto/fipsmodule/CMakeLists.txt

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -461,55 +461,31 @@ endif()
461461
# mlkem-native assembly files can be compiled on Unix platforms for x86_64 and arm64 only.
462462
if((ARCH STREQUAL "aarch64") AND UNIX)
463463

464-
# Set the source directory for s2n-bignum assembly files
464+
# Set the source directory for mlkem-native assembly files.
465465
set(MLKEM_NATIVE_DIR "${AWSLC_SOURCE_DIR}/crypto/fipsmodule/ml_kem")
466466

467-
set(MLKEM_NATIVE_AARCH64_ASM_SOURCES
468-
469-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/intt.S
470-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/ntt.S
471-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/poly_mulcache_compute_asm.S
472-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/poly_reduce_asm.S
473-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/poly_tobytes_asm.S
474-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/poly_tomont_asm.S
475-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S
476-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S
477-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S
478-
${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/rej_uniform_asm.S
479-
)
467+
# Every .S file in this directory is imported by importer.sh and must be
468+
# compiled; glob so that refreshes which add/remove/rename files don't need a
469+
# matching edit here. CONFIGURE_DEPENDS makes CMake re-run when the set of
470+
# matching files changes.
471+
file(GLOB MLKEM_NATIVE_AARCH64_ASM_SOURCES CONFIGURE_DEPENDS
472+
"${MLKEM_NATIVE_DIR}/mlkem/native/aarch64/src/*.S")
480473

481474
list(APPEND BCM_ASM_SOURCES ${MLKEM_NATIVE_AARCH64_ASM_SOURCES})
482475

483476
endif()
484477

485478
if((ARCH STREQUAL "x86_64") AND UNIX AND NOT MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
486479

487-
# Set the source directory for s2n-bignum assembly files
480+
# Set the source directory for mlkem-native assembly files.
488481
set(MLKEM_NATIVE_DIR "${AWSLC_SOURCE_DIR}/crypto/fipsmodule/ml_kem")
489482

490-
set(MLKEM_NATIVE_X86_64_ASM_SOURCES
491-
492-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/intt.S
493-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/ntt.S
494-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/mulcache_compute.S
495-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/nttfrombytes.S
496-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/ntttobytes.S
497-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/nttunpack.S
498-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/reduce.S
499-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/tomont.S
500-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k2.S
501-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k3.S
502-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/polyvec_basemul_acc_montgomery_cached_asm_k4.S
503-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/rej_uniform_asm.S
504-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_compress_d10.S
505-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_compress_d11.S
506-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_compress_d4.S
507-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_compress_d5.S
508-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_decompress_d10.S
509-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_decompress_d11.S
510-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_decompress_d4.S
511-
${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/poly_decompress_d5.S
512-
)
483+
# Every .S file in this directory is imported by importer.sh and must be
484+
# compiled; glob so that refreshes which add/remove/rename files don't need a
485+
# matching edit here. CONFIGURE_DEPENDS makes CMake re-run when the set of
486+
# matching files changes.
487+
file(GLOB MLKEM_NATIVE_X86_64_ASM_SOURCES CONFIGURE_DEPENDS
488+
"${MLKEM_NATIVE_DIR}/mlkem/native/x86_64/src/*.S")
513489

514490
list(APPEND BCM_ASM_SOURCES ${MLKEM_NATIVE_X86_64_ASM_SOURCES})
515491

@@ -524,7 +500,7 @@ if(UNIX AND ((ARCH STREQUAL "x86_64" AND NOT MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX) OR
524500
set(MLDSA_NATIVE_DIR "${AWSLC_SOURCE_DIR}/crypto/fipsmodule/ml_dsa")
525501

526502
# Every .S file in this directory is imported by importer.sh and must be
527-
# compiled; glob so that refreshes which add/remove files don't need a
503+
# compiled; glob so that refreshes which add/remove/rename files don't need a
528504
# matching edit here. CONFIGURE_DEPENDS makes CMake re-run when the set of
529505
# matching files changes.
530506
if(ARCH STREQUAL "x86_64")
@@ -541,7 +517,6 @@ if(UNIX AND ((ARCH STREQUAL "x86_64" AND NOT MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX) OR
541517

542518
endif()
543519

544-
545520
if(FIPS_DELOCATE)
546521
if(FIPS_SHARED)
547522
message(FATAL_ERROR "Can't set both delocate and shared mode for FIPS build")

crypto/fipsmodule/ml_dsa/META.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: mldsa-native
22
source: pq-code-package/mldsa-native.git
3-
branch: 08d40f9403a9ca80f160118bc63e96bf36627866
4-
commit: 08d40f9403a9ca80f160118bc63e96bf36627866
5-
imported-at: 2026-06-12T17:04:44+0000
3+
branch: c800f268c55dc35e2b928b60630a2f66d97083f8
4+
commit: c800f268c55dc35e2b928b60630a2f66d97083f8
5+
imported-at: 2026-08-03T15:28:02+0100

crypto/fipsmodule/ml_dsa/importer.sh

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# Dependencies:
3232
# - unifdef
3333

34-
GITHUB_SERVER_URL=https://github.com/
34+
GITHUB_SERVER_URL=${GITHUB_SERVER_URL:=https://github.com/}
3535
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:=pq-code-package/mldsa-native.git}
3636
GITHUB_SHA=${GITHUB_SHA:=main}
3737

@@ -78,27 +78,22 @@ mkdir $SRC
7878
find $TMP/mldsa/src -maxdepth 1 -type f -exec cp {} $SRC \;
7979

8080
# Copy x86_64 backend
81-
# We import all assembly (.S) files and shared headers/constants from the
82-
# upstream x86_64 backend. The AVX2 C-intrinsic .c files (rej_uniform,
83-
# decompose, use_hint, chknorm, polyz_unpack) are excluded — their includes
84-
# are stripped from the BCM below.
85-
#
86-
# The upstream meta.h advertises both assembly and C-intrinsic operations.
87-
# Rather than modify it, we keep a hand-maintained replacement in
88-
# ../mldsa_x86_64_meta.h (referenced via MLD_CONFIG_ARITH_BACKEND_FILE) that
89-
# declares only the assembly-backed subset. Upstream meta.h is not copied.
81+
# The x86_64 backend is fully assembly-backed: every native operation is
82+
# implemented by a proven .S kernel (proofs live in the upstream mldsa-native
83+
# repo). We import the upstream meta.h verbatim along with all assembly (.S)
84+
# files and shared headers/constants, so no hand-maintained meta.h shadow is
85+
# needed.
9086
mkdir -p $SRC/native/x86_64/src
9187
cp $TMP/mldsa/src/native/api.h $SRC/native
92-
cp $TMP/mldsa/src/native/x86_64/src/arith_native_x86_64.h $SRC/native/x86_64/src
93-
cp $TMP/mldsa/src/native/x86_64/src/consts.h $SRC/native/x86_64/src
94-
cp $TMP/mldsa/src/native/x86_64/src/consts.c $SRC/native/x86_64/src
95-
# NOTE: all imported .S files must have verified proofs in s2n-bignum.
88+
cp $TMP/mldsa/src/native/x86_64/meta.h $SRC/native/x86_64
89+
cp $TMP/mldsa/src/native/x86_64/src/*.h $SRC/native/x86_64/src
90+
cp $TMP/mldsa/src/native/x86_64/src/*.c $SRC/native/x86_64/src
9691
cp $TMP/mldsa/src/native/x86_64/src/*.S $SRC/native/x86_64/src
9792

9893
# Copy aarch64 backend
99-
# Unlike x86_64, the aarch64 backend is 100% assembly — no C-intrinsic .c
100-
# files. The upstream meta.h is suitable as-is, so we copy it verbatim.
101-
# All assembly (.S) files have verified proofs in s2n-bignum.
94+
# Like x86_64, the aarch64 backend is fully assembly-backed (proofs live in the
95+
# upstream mldsa-native repo). The upstream meta.h is suitable as-is, so we copy
96+
# it verbatim.
10297
mkdir -p $SRC/native/aarch64/src
10398
cp $TMP/mldsa/src/native/aarch64/*.h $SRC/native/aarch64
10499
cp $TMP/mldsa/src/native/aarch64/src/* $SRC/native/aarch64/src
@@ -141,12 +136,6 @@ cp $TMP/mldsa/mldsa_native.h $SRC
141136
echo "Fixup include paths"
142137
sed "${SED_I[@]}" 's/#include "src\/\([^"]*\)"/#include "\1"/' $SRC/mldsa_native_bcm.c
143138

144-
# Drop #include directives for the C-intrinsic .c files we did not import.
145-
# Only consts.c (shared with the assembly backend) is kept.
146-
echo "Strip C-intrinsic includes from mldsa_native_bcm.c"
147-
BCM=$SRC/mldsa_native_bcm.c
148-
sed "${SED_I[@]}" '/^#include "native\/x86_64\/src\/[^"]*\.c"/{/consts\.c/!d;}' "$BCM"
149-
150139
# ================================================================
151140
# Fixup assembly backends to use s2n-bignum macros
152141
# ================================================================
@@ -188,16 +177,6 @@ for file in $SRC/native/aarch64/src/*.S $SRC/native/x86_64/src/*.S; do
188177
sed "${SED_I[@]}" "s/MLD_ASM_FN_SYMBOL($func_name)/S2N_BN_SYMBOL(mldsa_$func_name):/" "$file"
189178
sed "${SED_I[@]}" "s/MLD_ASM_FN_SIZE($func_name)/S2N_BN_SIZE_DIRECTIVE(mldsa_$func_name)/" "$file"
190179
fi
191-
192-
# Prefix local labels with `Lmldsa_` to avoid collisions with other
193-
# backends linked into the same FIPS BCM module (e.g. mlkem-native's
194-
# ntt.S also defines `Lntt_layer123_start`). The delocator rejects
195-
# duplicate symbol names across the unified BCM input.
196-
# Build the rename list from the local label definitions (`^Lfoo:`) in
197-
# this file, then s/Lfoo/Lmldsa_foo/g across all occurrences.
198-
for label in $(grep -oE '^L[a-z][a-zA-Z0-9_]*:' "$file" | sed 's/:$//' | sort -u); do
199-
sed "${SED_I[@]}" "s/\b${label}\b/Lmldsa_${label#L}/g" "$file"
200-
done
201180
done
202181

203182
echo "Remove temporary artifacts ..."

0 commit comments

Comments
 (0)