From 2424b23d1ee763c766eea6d886c90d1a7b827792 Mon Sep 17 00:00:00 2001 From: "Matthias J. Kannwischer" Date: Wed, 1 Jul 2026 13:58:32 +0800 Subject: [PATCH] FIPS202: Consolidate backend MLK_USE_NATIVE_* flags Rename the FIPS202 backend function-support flags to the MLK_USE_NATIVE_ convention already used by the arithmetic backend: MLK_USE_FIPS202_X1_NATIVE -> MLK_USE_NATIVE_FIPS202_X1 MLK_USE_FIPS202_X4_NATIVE -> MLK_USE_NATIVE_FIPS202_X4 MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE -> MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE -> MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES Custom backends that set these flags must rename them accordingly. - Ports https://github.com/pq-code-package/mldsa-native/pull/1207 Signed-off-by: Matthias J. Kannwischer --- dev/fips202/aarch64/x1_scalar.h | 2 +- dev/fips202/aarch64/x1_v84a.h | 2 +- dev/fips202/aarch64/x2_v84a.h | 2 +- dev/fips202/aarch64/x4_v8a_scalar.h | 2 +- dev/fips202/aarch64/x4_v8a_v84a_scalar.h | 2 +- dev/fips202/armv81m/mve.h | 6 ++--- dev/fips202/x86_64/keccak_f1600_x4_avx2.h | 2 +- examples/custom_backend/README.md | 4 ++-- .../src/fips202/native/custom/custom.h | 2 +- mlkem/mlkem_native.c | 18 +++++++------- mlkem/mlkem_native_asm.S | 18 +++++++------- mlkem/src/fips202/fips202.h | 4 ++-- mlkem/src/fips202/keccakf1600.c | 16 ++++++------- mlkem/src/fips202/native/aarch64/x1_scalar.h | 2 +- mlkem/src/fips202/native/aarch64/x1_v84a.h | 2 +- mlkem/src/fips202/native/aarch64/x2_v84a.h | 2 +- .../fips202/native/aarch64/x4_v8a_scalar.h | 2 +- .../native/aarch64/x4_v8a_v84a_scalar.h | 2 +- mlkem/src/fips202/native/api.h | 22 ++++++++--------- mlkem/src/fips202/native/armv81m/mve.h | 6 ++--- .../native/x86_64/keccak_f1600_x4_avx2.h | 2 +- proofs/cbmc/dummy_backend_fips202_x1.h | 2 +- proofs/cbmc/dummy_backend_fips202_x4.h | 6 ++--- test/bench/bench_components_mlkem.c | 12 +++++----- test/src/test_unit.c | 24 +++++++++---------- 25 files changed, 82 insertions(+), 82 deletions(-) diff --git a/dev/fips202/aarch64/x1_scalar.h b/dev/fips202/aarch64/x1_scalar.h index 10d43cafed..6bc7d245a0 100644 --- a/dev/fips202/aarch64/x1_scalar.h +++ b/dev/fips202/aarch64/x1_scalar.h @@ -7,7 +7,7 @@ #define MLK_DEV_FIPS202_AARCH64_X1_SCALAR_H /* Part of backend API */ -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X1_SCALAR diff --git a/dev/fips202/aarch64/x1_v84a.h b/dev/fips202/aarch64/x1_v84a.h index 87c0a81155..f3d35525c6 100644 --- a/dev/fips202/aarch64/x1_v84a.h +++ b/dev/fips202/aarch64/x1_v84a.h @@ -11,7 +11,7 @@ #endif /* Part of backend API */ -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X1_V84A diff --git a/dev/fips202/aarch64/x2_v84a.h b/dev/fips202/aarch64/x2_v84a.h index f0adab5180..596cf414e7 100644 --- a/dev/fips202/aarch64/x2_v84a.h +++ b/dev/fips202/aarch64/x2_v84a.h @@ -11,7 +11,7 @@ #endif /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X2_V84A diff --git a/dev/fips202/aarch64/x4_v8a_scalar.h b/dev/fips202/aarch64/x4_v8a_scalar.h index e6e453caf8..55662c9bf5 100644 --- a/dev/fips202/aarch64/x4_v8a_scalar.h +++ b/dev/fips202/aarch64/x4_v8a_scalar.h @@ -7,7 +7,7 @@ #define MLK_DEV_FIPS202_AARCH64_X4_V8A_SCALAR_H /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID diff --git a/dev/fips202/aarch64/x4_v8a_v84a_scalar.h b/dev/fips202/aarch64/x4_v8a_v84a_scalar.h index 47a68379d7..10dd000c1a 100644 --- a/dev/fips202/aarch64/x4_v8a_v84a_scalar.h +++ b/dev/fips202/aarch64/x4_v8a_v84a_scalar.h @@ -11,7 +11,7 @@ #endif /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID diff --git a/dev/fips202/armv81m/mve.h b/dev/fips202/armv81m/mve.h index a86dc156d1..17b2541013 100644 --- a/dev/fips202/armv81m/mve.h +++ b/dev/fips202/armv81m/mve.h @@ -9,9 +9,9 @@ #define MLK_FIPS202_NATIVE_ARMV81M /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE -#define MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE -#define MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 +#define MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES +#define MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES /* Guard for assembly file */ #define MLK_FIPS202_ARMV81M_NEED_X4 diff --git a/dev/fips202/x86_64/keccak_f1600_x4_avx2.h b/dev/fips202/x86_64/keccak_f1600_x4_avx2.h index 30a63e31cb..fa6a6dfec7 100644 --- a/dev/fips202/x86_64/keccak_f1600_x4_avx2.h +++ b/dev/fips202/x86_64/keccak_f1600_x4_avx2.h @@ -11,7 +11,7 @@ #define MLK_FIPS202_X86_64_NEED_X4_AVX2 /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 #if !defined(__ASSEMBLER__) #include "../api.h" diff --git a/examples/custom_backend/README.md b/examples/custom_backend/README.md index 4e1018b2ec..6f252d46f8 100644 --- a/examples/custom_backend/README.md +++ b/examples/custom_backend/README.md @@ -31,7 +31,7 @@ The configuration file [mlkem_native_config.h](mlkem_native/mlkem_native_config. A custom backend consists of: 1. A metadata header (e.g., [custom.h](mlkem_native/src/fips202/native/custom/custom.h)) that: - - Sets `MLK_USE_FIPS202_X1_NATIVE` (and/or `X4`) to indicate which functions are replaced + - Sets `MLK_USE_NATIVE_FIPS202_X1` (and/or `X4`) to indicate which functions are replaced - Includes the implementation header 2. An implementation providing `mlk_keccakf1600_native()` (and/or batched variants) @@ -41,7 +41,7 @@ Example backend metadata file: #define CUSTOM_FIPS202_BACKEND_H /* Indicate we're replacing 1-fold Keccak-f1600 */ -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 /* Include the implementation */ #include "custom/src/keccak_impl.h" diff --git a/examples/custom_backend/mlkem_native/src/fips202/native/custom/custom.h b/examples/custom_backend/mlkem_native/src/fips202/native/custom/custom.h index 1e99f0b2a4..9a1c6935f4 100644 --- a/examples/custom_backend/mlkem_native/src/fips202/native/custom/custom.h +++ b/examples/custom_backend/mlkem_native/src/fips202/native/custom/custom.h @@ -10,7 +10,7 @@ #include "../api.h" #include "src/sha3.h" /* Replace (single) Keccak-F1600 by tiny-SHA3's */ -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 static MLK_INLINE int mlk_keccak_f1600_x1_native(uint64_t *state) { tiny_sha3_keccakf(state); diff --git a/mlkem/mlkem_native.c b/mlkem/mlkem_native.c index d8b0fd5398..c9305cc25d 100644 --- a/mlkem/mlkem_native.c +++ b/mlkem/mlkem_native.c @@ -463,23 +463,23 @@ /* mlkem/src/fips202/native/aarch64/x1_scalar.h */ #undef MLK_FIPS202_AARCH64_NEED_X1_SCALAR #undef MLK_FIPS202_NATIVE_AARCH64_X1_SCALAR_H -#undef MLK_USE_FIPS202_X1_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X1 /* mlkem/src/fips202/native/aarch64/x1_v84a.h */ #undef MLK_FIPS202_AARCH64_NEED_X1_V84A #undef MLK_FIPS202_NATIVE_AARCH64_X1_V84A_H -#undef MLK_USE_FIPS202_X1_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X1 /* mlkem/src/fips202/native/aarch64/x2_v84a.h */ #undef MLK_FIPS202_AARCH64_NEED_X2_V84A #undef MLK_FIPS202_NATIVE_AARCH64_X2_V84A_H -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 /* mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h */ #undef MLK_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID #undef MLK_FIPS202_NATIVE_AARCH64_X4_V8A_SCALAR_H -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 /* mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h */ #undef MLK_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID #undef MLK_FIPS202_NATIVE_AARCH64_X4_V8A_V84A_SCALAR_H -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 #endif /* MLK_SYS_AARCH64 */ #if defined(MLK_SYS_X86_64) /* @@ -488,7 +488,7 @@ /* mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h */ #undef MLK_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX2_H #undef MLK_FIPS202_X86_64_NEED_X4_AVX2 -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 /* mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h */ #undef MLK_FIPS202_NATIVE_X86_64_SRC_FIPS202_NATIVE_X86_64_H #undef mlk_keccak_f1600_x4_avx2_asm @@ -504,9 +504,9 @@ #undef MLK_FIPS202_ARMV81M_NEED_X4 #undef MLK_FIPS202_NATIVE_ARMV81M #undef MLK_FIPS202_NATIVE_ARMV81M_MVE_H -#undef MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE -#undef MLK_USE_FIPS202_X4_NATIVE -#undef MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 +#undef MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES +#undef MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES #undef mlk_keccak_f1600_x4_native_impl #undef mlk_keccak_f1600_x4_state_extract_bytes #undef mlk_keccak_f1600_x4_state_xor_bytes diff --git a/mlkem/mlkem_native_asm.S b/mlkem/mlkem_native_asm.S index c2edd2b161..fdc6db5187 100644 --- a/mlkem/mlkem_native_asm.S +++ b/mlkem/mlkem_native_asm.S @@ -487,23 +487,23 @@ /* mlkem/src/fips202/native/aarch64/x1_scalar.h */ #undef MLK_FIPS202_AARCH64_NEED_X1_SCALAR #undef MLK_FIPS202_NATIVE_AARCH64_X1_SCALAR_H -#undef MLK_USE_FIPS202_X1_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X1 /* mlkem/src/fips202/native/aarch64/x1_v84a.h */ #undef MLK_FIPS202_AARCH64_NEED_X1_V84A #undef MLK_FIPS202_NATIVE_AARCH64_X1_V84A_H -#undef MLK_USE_FIPS202_X1_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X1 /* mlkem/src/fips202/native/aarch64/x2_v84a.h */ #undef MLK_FIPS202_AARCH64_NEED_X2_V84A #undef MLK_FIPS202_NATIVE_AARCH64_X2_V84A_H -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 /* mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h */ #undef MLK_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID #undef MLK_FIPS202_NATIVE_AARCH64_X4_V8A_SCALAR_H -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 /* mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h */ #undef MLK_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID #undef MLK_FIPS202_NATIVE_AARCH64_X4_V8A_V84A_SCALAR_H -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 #endif /* MLK_SYS_AARCH64 */ #if defined(MLK_SYS_X86_64) /* @@ -512,7 +512,7 @@ /* mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h */ #undef MLK_FIPS202_NATIVE_X86_64_KECCAK_F1600_X4_AVX2_H #undef MLK_FIPS202_X86_64_NEED_X4_AVX2 -#undef MLK_USE_FIPS202_X4_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 /* mlkem/src/fips202/native/x86_64/src/fips202_native_x86_64.h */ #undef MLK_FIPS202_NATIVE_X86_64_SRC_FIPS202_NATIVE_X86_64_H #undef mlk_keccak_f1600_x4_avx2_asm @@ -528,9 +528,9 @@ #undef MLK_FIPS202_ARMV81M_NEED_X4 #undef MLK_FIPS202_NATIVE_ARMV81M #undef MLK_FIPS202_NATIVE_ARMV81M_MVE_H -#undef MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE -#undef MLK_USE_FIPS202_X4_NATIVE -#undef MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE +#undef MLK_USE_NATIVE_FIPS202_X4 +#undef MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES +#undef MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES #undef mlk_keccak_f1600_x4_native_impl #undef mlk_keccak_f1600_x4_state_extract_bytes #undef mlk_keccak_f1600_x4_state_xor_bytes diff --git a/mlkem/src/fips202/fips202.h b/mlkem/src/fips202/fips202.h index 6349ae1ff3..99eaccc0fe 100644 --- a/mlkem/src/fips202/fips202.h +++ b/mlkem/src/fips202/fips202.h @@ -132,12 +132,12 @@ __contract__( ); #if !defined(MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202) || \ - !defined(MLK_USE_FIPS202_X4_NATIVE) + !defined(MLK_USE_NATIVE_FIPS202_X4) /* If you provide your own FIPS-202 implementation where the x4- * Keccak-f1600-x4 implementation falls back to 4-fold Keccak-f1600, * set this to gain a small speedup. */ #define FIPS202_X4_DEFAULT_IMPLEMENTATION -#endif /* !MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 || !MLK_USE_FIPS202_X4_NATIVE \ +#endif /* !MLK_CONFIG_USE_NATIVE_BACKEND_FIPS202 || !MLK_USE_NATIVE_FIPS202_X4 \ */ diff --git a/mlkem/src/fips202/keccakf1600.c b/mlkem/src/fips202/keccakf1600.c index 586b283f9d..b3cec2eaba 100644 --- a/mlkem/src/fips202/keccakf1600.c +++ b/mlkem/src/fips202/keccakf1600.c @@ -115,14 +115,14 @@ void mlk_keccakf1600x4_extract_bytes(uint64_t *state, unsigned char *data0, unsigned char *data3, unsigned offset, unsigned length) { -#if defined(MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES) if (mlk_keccakf1600_extract_bytes_x4_native(state, data0, data1, data2, data3, offset, length) == MLK_NATIVE_FUNC_SUCCESS) { return; } -#endif /* MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES */ mlk_keccakf1600x4_extract_bytes_c(state, data0, data1, data2, data3, offset, length); } @@ -164,26 +164,26 @@ void mlk_keccakf1600x4_xor_bytes(uint64_t *state, const unsigned char *data0, const unsigned char *data3, unsigned offset, unsigned length) { -#if defined(MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES) if (mlk_keccakf1600_xor_bytes_x4_native(state, data0, data1, data2, data3, offset, length) == MLK_NATIVE_FUNC_SUCCESS) { return; } -#endif /* MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES */ mlk_keccakf1600x4_xor_bytes_c(state, data0, data1, data2, data3, offset, length); } void mlk_keccakf1600x4_permute(uint64_t *state) { -#if defined(MLK_USE_FIPS202_X4_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4) if (mlk_keccak_f1600_x4_native(state) == MLK_NATIVE_FUNC_SUCCESS) { return; } -#endif /* MLK_USE_FIPS202_X4_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4 */ mlk_keccakf1600_permute(state + MLK_KECCAK_LANES * 0); mlk_keccakf1600_permute(state + MLK_KECCAK_LANES * 1); mlk_keccakf1600_permute(state + MLK_KECCAK_LANES * 2); @@ -478,12 +478,12 @@ __contract__( void mlk_keccakf1600_permute(uint64_t *state) { -#if defined(MLK_USE_FIPS202_X1_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X1) if (mlk_keccak_f1600_x1_native(state) == MLK_NATIVE_FUNC_SUCCESS) { return; } -#endif /* MLK_USE_FIPS202_X1_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X1 */ mlk_keccakf1600_permute_c(state); } diff --git a/mlkem/src/fips202/native/aarch64/x1_scalar.h b/mlkem/src/fips202/native/aarch64/x1_scalar.h index bd6b3768a5..ccf805b002 100644 --- a/mlkem/src/fips202/native/aarch64/x1_scalar.h +++ b/mlkem/src/fips202/native/aarch64/x1_scalar.h @@ -7,7 +7,7 @@ #define MLK_FIPS202_NATIVE_AARCH64_X1_SCALAR_H /* Part of backend API */ -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X1_SCALAR diff --git a/mlkem/src/fips202/native/aarch64/x1_v84a.h b/mlkem/src/fips202/native/aarch64/x1_v84a.h index c7d374a9a0..6887d8d530 100644 --- a/mlkem/src/fips202/native/aarch64/x1_v84a.h +++ b/mlkem/src/fips202/native/aarch64/x1_v84a.h @@ -11,7 +11,7 @@ #endif /* Part of backend API */ -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X1_V84A diff --git a/mlkem/src/fips202/native/aarch64/x2_v84a.h b/mlkem/src/fips202/native/aarch64/x2_v84a.h index 3dabec4834..b642454fef 100644 --- a/mlkem/src/fips202/native/aarch64/x2_v84a.h +++ b/mlkem/src/fips202/native/aarch64/x2_v84a.h @@ -11,7 +11,7 @@ #endif /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X2_V84A diff --git a/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h b/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h index fb8b99cd64..b7d8e7b373 100644 --- a/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h +++ b/mlkem/src/fips202/native/aarch64/x4_v8a_scalar.h @@ -7,7 +7,7 @@ #define MLK_FIPS202_NATIVE_AARCH64_X4_V8A_SCALAR_H /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X4_V8A_SCALAR_HYBRID diff --git a/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h b/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h index c215198c11..61d9a66150 100644 --- a/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h +++ b/mlkem/src/fips202/native/aarch64/x4_v8a_v84a_scalar.h @@ -11,7 +11,7 @@ #endif /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 /* Guard for assembly file */ #define MLK_FIPS202_AARCH64_NEED_X4_V8A_V84A_SCALAR_HYBRID diff --git a/mlkem/src/fips202/native/api.h b/mlkem/src/fips202/native/api.h index 041480861c..8ef7383e25 100644 --- a/mlkem/src/fips202/native/api.h +++ b/mlkem/src/fips202/native/api.h @@ -29,13 +29,13 @@ * A _backend_ is a specific implementation of parts of this interface. * * You can replace 1-fold or 4-fold batched Keccak-F1600. - * To enable, set MLK_USE_FIPS202_X1_NATIVE or MLK_USE_FIPS202_X4_NATIVE + * To enable, set MLK_USE_NATIVE_FIPS202_X1 or MLK_USE_NATIVE_FIPS202_X4 * in your backend, and define the inline wrappers mlk_keccak_f1600_x1_native() * and/or mlk_keccak_f1600_x4_native(), respectively, to forward to your * implementation. */ -#if defined(MLK_USE_FIPS202_X1_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X1) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_keccak_f1600_x1_native(uint64_t *state) __contract__( @@ -43,8 +43,8 @@ __contract__( assigns(memory_slice(state, sizeof(uint64_t) * 25 * 1)) ensures(return_value == MLK_NATIVE_FUNC_FALLBACK || return_value == MLK_NATIVE_FUNC_SUCCESS) ensures((return_value == MLK_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 1))); -#endif /* MLK_USE_FIPS202_X1_NATIVE */ -#if defined(MLK_USE_FIPS202_X4_NATIVE) +#endif /* MLK_USE_NATIVE_FIPS202_X1 */ +#if defined(MLK_USE_NATIVE_FIPS202_X4) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_keccak_f1600_x4_native(uint64_t *state) __contract__( @@ -52,7 +52,7 @@ __contract__( assigns(memory_slice(state, sizeof(uint64_t) * 25 * 4)) ensures(return_value == MLK_NATIVE_FUNC_FALLBACK || return_value == MLK_NATIVE_FUNC_SUCCESS) ensures((return_value == MLK_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 4))); -#endif /* MLK_USE_FIPS202_X4_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4 */ /* * Native x4 XOR bytes and extract bytes interface. @@ -66,12 +66,12 @@ __contract__( * NOTE: We assume that the custom representation of the zero state is the * all-zero state. * - * MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE: Backend provides native XOR bytes - * MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE: Backend provides native extract + * MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES: Backend provides native XOR bytes + * MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES: Backend provides native extract * bytes */ -#if defined(MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_keccakf1600_xor_bytes_x4_native( uint64_t *state, const unsigned char *data0, const unsigned char *data1, @@ -91,9 +91,9 @@ __contract__( assigns(memory_slice(state, sizeof(uint64_t) * 25 * 4)) ensures(return_value == MLK_NATIVE_FUNC_FALLBACK || return_value == MLK_NATIVE_FUNC_SUCCESS) ensures((return_value == MLK_NATIVE_FUNC_FALLBACK) ==> array_unchanged_u64(state, 25 * 4))); -#endif /* MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES */ -#if defined(MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_keccakf1600_extract_bytes_x4_native( uint64_t *state, unsigned char *data0, unsigned char *data1, @@ -112,6 +112,6 @@ __contract__( assigns(memory_slice(data2, length)) assigns(memory_slice(data3, length)) ensures(return_value == MLK_NATIVE_FUNC_FALLBACK || return_value == MLK_NATIVE_FUNC_SUCCESS)); -#endif /* MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES */ #endif /* !MLK_FIPS202_NATIVE_API_H */ diff --git a/mlkem/src/fips202/native/armv81m/mve.h b/mlkem/src/fips202/native/armv81m/mve.h index e2f19ec24c..685b990392 100644 --- a/mlkem/src/fips202/native/armv81m/mve.h +++ b/mlkem/src/fips202/native/armv81m/mve.h @@ -9,9 +9,9 @@ #define MLK_FIPS202_NATIVE_ARMV81M /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE -#define MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE -#define MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 +#define MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES +#define MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES /* Guard for assembly file */ #define MLK_FIPS202_ARMV81M_NEED_X4 diff --git a/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h b/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h index 1c37f31ac3..cb59a5fbbb 100644 --- a/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h +++ b/mlkem/src/fips202/native/x86_64/keccak_f1600_x4_avx2.h @@ -11,7 +11,7 @@ #define MLK_FIPS202_X86_64_NEED_X4_AVX2 /* Part of backend API */ -#define MLK_USE_FIPS202_X4_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 #if !defined(__ASSEMBLER__) #include "../api.h" diff --git a/proofs/cbmc/dummy_backend_fips202_x1.h b/proofs/cbmc/dummy_backend_fips202_x1.h index c3080909b6..6655021c9a 100644 --- a/proofs/cbmc/dummy_backend_fips202_x1.h +++ b/proofs/cbmc/dummy_backend_fips202_x1.h @@ -6,7 +6,7 @@ #ifndef MLK_DUMMY_FIPS202X1_BACKEND_H #define MLK_DUMMY_FIPS202X1_BACKEND_H -#define MLK_USE_FIPS202_X1_NATIVE +#define MLK_USE_NATIVE_FIPS202_X1 #include "../../mlkem/src/fips202/native/api.h" diff --git a/proofs/cbmc/dummy_backend_fips202_x4.h b/proofs/cbmc/dummy_backend_fips202_x4.h index e9d00a9c12..d31958aa27 100644 --- a/proofs/cbmc/dummy_backend_fips202_x4.h +++ b/proofs/cbmc/dummy_backend_fips202_x4.h @@ -6,9 +6,9 @@ #ifndef MLK_DUMMY_FIPS202X4_BACKEND_H #define MLK_DUMMY_FIPS202X4_BACKEND_H -#define MLK_USE_FIPS202_X4_NATIVE -#define MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE -#define MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE +#define MLK_USE_NATIVE_FIPS202_X4 +#define MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES +#define MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES #include "../../mlkem/src/fips202/native/api.h" diff --git a/test/bench/bench_components_mlkem.c b/test/bench/bench_components_mlkem.c index 8accc27b41..037d7e6eed 100644 --- a/test/bench/bench_components_mlkem.c +++ b/test/bench/bench_components_mlkem.c @@ -333,31 +333,31 @@ static int bench(void) #endif #endif /* MLKEM_K == 4 */ -#if defined(MLK_USE_FIPS202_X1_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X1) BENCH_NATIVE_OK("mlk_keccak_f1600_x1_native", mlk_keccak_f1600_x1_native(data0)); #endif -#if defined(MLK_USE_FIPS202_X4_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4) BENCH_NATIVE_OK("mlk_keccak_f1600_x4_native", mlk_keccak_f1600_x4_native(data0)); #endif -#if defined(MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES) BENCH_NATIVE_OK( "mlk_keccakf1600_xor_bytes_x4_native", mlk_keccakf1600_xor_bytes_x4_native( data0, (uint8_t *)data1, (uint8_t *)data2, (uint8_t *)data3, (uint8_t *)data4, 0, 25 * sizeof(uint64_t))); -#endif /* MLK_USE_FIPS202_X4_XOR_BYTES_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4_XOR_BYTES */ -#if defined(MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES) BENCH_NATIVE_OK( "mlk_keccakf1600_extract_bytes_x4_native", mlk_keccakf1600_extract_bytes_x4_native( data0, (uint8_t *)data1, (uint8_t *)data2, (uint8_t *)data3, (uint8_t *)data4, 0, 25 * sizeof(uint64_t))); -#endif /* MLK_USE_FIPS202_X4_EXTRACT_BYTES_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4_EXTRACT_BYTES */ return 0; } diff --git a/test/src/test_unit.c b/test/src/test_unit.c index 55430a5466..8a872133d1 100644 --- a/test/src/test_unit.c +++ b/test/src/test_unit.c @@ -74,7 +74,7 @@ void mlk_poly_decompress_d11_c(mlk_poly *r, } \ } while (0) -#if defined(MLK_USE_FIPS202_X1_NATIVE) +#if defined(MLK_USE_NATIVE_FIPS202_X1) static void print_u64_array(const char *label, const uint64_t *array, size_t len) { @@ -122,14 +122,14 @@ static int compare_u64_arrays(const uint64_t *a, const uint64_t *b, } return 1; } -#endif /* MLK_USE_FIPS202_X1_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X1 */ #if defined(MLK_USE_NATIVE_POLY_REDUCE) || \ defined(MLK_USE_NATIVE_POLY_TOMONT) || defined(MLK_USE_NATIVE_NTT) || \ defined(MLK_USE_NATIVE_INTT) || defined(MLK_USE_NATIVE_POLY_TOBYTES) || \ defined(MLK_USE_NATIVE_POLY_FROMBYTES) || \ defined(MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED) || \ - defined(MLK_USE_FIPS202_X1_NATIVE) || defined(MLK_USE_FIPS202_X4_NATIVE) + defined(MLK_USE_NATIVE_FIPS202_X1) || defined(MLK_USE_NATIVE_FIPS202_X4) /* Backend unit test helper functions for arithmetic native backends */ #if defined(MLK_USE_NATIVE_POLY_REDUCE) || \ @@ -776,7 +776,7 @@ static int test_native_polyvec_basemul(void) } #endif /* MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED */ -#ifdef MLK_USE_FIPS202_X1_NATIVE +#ifdef MLK_USE_NATIVE_FIPS202_X1 static int test_keccakf1600_permute(void) { int ret = 1; @@ -808,13 +808,13 @@ static int test_keccakf1600_permute(void) MLK_FREE(state, uint64_t, MLK_KECCAK_LANES, NULL); return ret; } -#endif /* MLK_USE_FIPS202_X1_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X1 */ /* * Test that x4 Keccak (xor_bytes, permute, extract_bytes) produces * the same results as the x1 C reference. */ -#ifdef MLK_USE_FIPS202_X4_NATIVE +#ifdef MLK_USE_NATIVE_FIPS202_X4 #define MAX_RATE 136 static int test_keccakf1600x4_xor_permute_extract(void) @@ -913,7 +913,7 @@ static int test_keccakf1600x4_xor_permute_extract(void) } #undef MAX_RATE -#endif /* MLK_USE_FIPS202_X4_NATIVE */ +#endif /* MLK_USE_NATIVE_FIPS202_X4 */ #ifdef MLK_USE_NATIVE_REJ_UNIFORM #define REJ_UNIFORM_BUFLEN 504 /* 3 * 168, divisible by 3 */ @@ -1107,11 +1107,11 @@ static int test_backend_units(void) CHECK(test_native_polyvec_basemul() == 0); #endif -#ifdef MLK_USE_FIPS202_X1_NATIVE +#ifdef MLK_USE_NATIVE_FIPS202_X1 CHECK(test_keccakf1600_permute() == 0); #endif -#ifdef MLK_USE_FIPS202_X4_NATIVE +#ifdef MLK_USE_NATIVE_FIPS202_X4 CHECK(test_keccakf1600x4_xor_permute_extract() == 0); #endif @@ -1156,7 +1156,7 @@ static int test_backend_units(void) MLK_USE_NATIVE_NTT || MLK_USE_NATIVE_INTT || \ MLK_USE_NATIVE_POLY_TOBYTES || MLK_USE_NATIVE_POLY_FROMBYTES || \ MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED || \ - MLK_USE_FIPS202_X1_NATIVE || MLK_USE_FIPS202_X4_NATIVE */ + MLK_USE_NATIVE_FIPS202_X1 || MLK_USE_NATIVE_FIPS202_X4 */ /* poly_rej_uniform and poly_rej_uniform_4x implement the same * functionality with different degrees of batching. This unit @@ -1228,13 +1228,13 @@ int main(void) defined(MLK_USE_NATIVE_INTT) || defined(MLK_USE_NATIVE_POLY_TOBYTES) || \ defined(MLK_USE_NATIVE_POLY_FROMBYTES) || \ defined(MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED) || \ - defined(MLK_USE_FIPS202_X1_NATIVE) || defined(MLK_USE_FIPS202_X4_NATIVE) + defined(MLK_USE_NATIVE_FIPS202_X1) || defined(MLK_USE_NATIVE_FIPS202_X4) CHECK(test_backend_units() == 0); #endif /* MLK_USE_NATIVE_POLY_REDUCE || MLK_USE_NATIVE_POLY_TOMONT || \ MLK_USE_NATIVE_NTT || MLK_USE_NATIVE_INTT || \ MLK_USE_NATIVE_POLY_TOBYTES || MLK_USE_NATIVE_POLY_FROMBYTES || \ MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED || \ - MLK_USE_FIPS202_X1_NATIVE || MLK_USE_FIPS202_X4_NATIVE */ + MLK_USE_NATIVE_FIPS202_X1 || MLK_USE_NATIVE_FIPS202_X4 */ #if !defined(MLK_CONFIG_SERIAL_FIPS202_ONLY) CHECK(test_poly_rej_uniform_consistency() == 0);