From c5280f872c185ebb54a4409de5330806248a6e88 Mon Sep 17 00:00:00 2001 From: "Matthias J. Kannwischer" Date: Tue, 13 Oct 2026 15:14:30 +0800 Subject: [PATCH] sys.h: Do not depend on configuration options sys.h evaluated MLK_CONFIG_NO_ASM, MLK_CONFIG_CT_TESTING_ENABLED and MLK_CONFIG_CUSTOM_CAPABILITY_FUNC when it was first included. Configuration hooks such as MLK_CONFIG_CUSTOM_ZEROIZE include sys.h, and its include guard prevents re-evaluation, so an option defined after such a hook was silently ignored or, for the capability function, caused a redefinition error. This affects the order of the config template and test/configs/no_asm_config.h: the "No ASM" configuration kept the inline-assembly value barrier and never built the volatile opt-blocker, and a late CT_TESTING_ENABLED made constant-time tests vacuous. Move the inline-assembly decision and the CT-testing macros to common.h, after the whole configuration has been read. Move the default mlk_sys_check_capability() to a new shared header capability.h, included from common.h, so that multilevel builds still define it only once. Document in sys.h that it must not depend on configuration options. Signed-off-by: Matthias J. Kannwischer --- .../mlkem_native/src/capability.h | 1 + .../mlkem_native/src/capability.h | 1 + .../mlkem_native/src/capability.h | 1 + .../mlkem_native/src/capability.h | 1 + integration/liboqs/ML-KEM-1024_META.yml | 40 ++++++++--------- integration/liboqs/ML-KEM-512_META.yml | 40 ++++++++--------- integration/liboqs/ML-KEM-768_META.yml | 40 ++++++++--------- integration/pavona/capability-header.patch | 12 ++++++ mlkem/mlkem_native.c | 8 ++-- mlkem/mlkem_native_asm.S | 8 ++-- mlkem/src/capability.h | 30 +++++++++++++ mlkem/src/common.h | 22 ++++++++++ mlkem/src/sys.h | 43 ++----------------- .../sys_check_capability_harness.c | 2 +- test/abicheck/abicheck_common.h | 7 +-- 15 files changed, 146 insertions(+), 110 deletions(-) create mode 120000 examples/bring_your_own_fips202/mlkem_native/src/capability.h create mode 120000 examples/bring_your_own_fips202_static/mlkem_native/src/capability.h create mode 120000 examples/custom_backend/mlkem_native/src/capability.h create mode 120000 examples/monolithic_build/mlkem_native/src/capability.h create mode 100644 integration/pavona/capability-header.patch create mode 100644 mlkem/src/capability.h diff --git a/examples/bring_your_own_fips202/mlkem_native/src/capability.h b/examples/bring_your_own_fips202/mlkem_native/src/capability.h new file mode 120000 index 0000000000..ba30bab52a --- /dev/null +++ b/examples/bring_your_own_fips202/mlkem_native/src/capability.h @@ -0,0 +1 @@ +../../../../mlkem/src/capability.h \ No newline at end of file diff --git a/examples/bring_your_own_fips202_static/mlkem_native/src/capability.h b/examples/bring_your_own_fips202_static/mlkem_native/src/capability.h new file mode 120000 index 0000000000..ba30bab52a --- /dev/null +++ b/examples/bring_your_own_fips202_static/mlkem_native/src/capability.h @@ -0,0 +1 @@ +../../../../mlkem/src/capability.h \ No newline at end of file diff --git a/examples/custom_backend/mlkem_native/src/capability.h b/examples/custom_backend/mlkem_native/src/capability.h new file mode 120000 index 0000000000..ba30bab52a --- /dev/null +++ b/examples/custom_backend/mlkem_native/src/capability.h @@ -0,0 +1 @@ +../../../../mlkem/src/capability.h \ No newline at end of file diff --git a/examples/monolithic_build/mlkem_native/src/capability.h b/examples/monolithic_build/mlkem_native/src/capability.h new file mode 120000 index 0000000000..ba30bab52a --- /dev/null +++ b/examples/monolithic_build/mlkem_native/src/capability.h @@ -0,0 +1 @@ +../../../../mlkem/src/capability.h \ No newline at end of file diff --git a/integration/liboqs/ML-KEM-1024_META.yml b/integration/liboqs/ML-KEM-1024_META.yml index 3b2f43fe57..3400cfc791 100644 --- a/integration/liboqs/ML-KEM-1024_META.yml +++ b/integration/liboqs/ML-KEM-1024_META.yml @@ -35,11 +35,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM1024_C_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM1024_C_dec_oqs sources: integration/liboqs/config_c.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc - name: x86_64 @@ -52,11 +52,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM1024_X86_64_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM1024_X86_64_dec_oqs sources: integration/liboqs/config_x86_64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/x86_64 supported_platforms: @@ -78,11 +78,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM1024_AARCH64_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM1024_AARCH64_dec_oqs sources: integration/liboqs/config_aarch64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/aarch64 supported_platforms: @@ -102,11 +102,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM1024_PPC64LE_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM1024_PPC64LE_dec_oqs sources: integration/liboqs/config_ppc64le.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/ppc64le supported_platforms: diff --git a/integration/liboqs/ML-KEM-512_META.yml b/integration/liboqs/ML-KEM-512_META.yml index 23104ab66c..c3082b954a 100644 --- a/integration/liboqs/ML-KEM-512_META.yml +++ b/integration/liboqs/ML-KEM-512_META.yml @@ -35,11 +35,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM512_C_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM512_C_dec_oqs sources: integration/liboqs/config_c.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc - name: x86_64 @@ -52,11 +52,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM512_X86_64_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM512_X86_64_dec_oqs sources: integration/liboqs/config_x86_64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/x86_64 supported_platforms: @@ -78,11 +78,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM512_AARCH64_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM512_AARCH64_dec_oqs sources: integration/liboqs/config_aarch64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/aarch64 supported_platforms: @@ -102,11 +102,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM512_PPC64LE_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM512_PPC64LE_dec_oqs sources: integration/liboqs/config_ppc64le.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/ppc64le supported_platforms: diff --git a/integration/liboqs/ML-KEM-768_META.yml b/integration/liboqs/ML-KEM-768_META.yml index 08d3686304..686e335916 100644 --- a/integration/liboqs/ML-KEM-768_META.yml +++ b/integration/liboqs/ML-KEM-768_META.yml @@ -35,11 +35,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM768_C_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM768_C_dec_oqs sources: integration/liboqs/config_c.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc - name: x86_64 @@ -52,11 +52,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM768_X86_64_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM768_X86_64_dec_oqs sources: integration/liboqs/config_x86_64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/x86_64 supported_platforms: @@ -78,11 +78,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM768_AARCH64_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM768_AARCH64_dec_oqs sources: integration/liboqs/config_aarch64.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/aarch64 supported_platforms: @@ -102,11 +102,11 @@ implementations: signature_enc_derand: PQCP_MLKEM_NATIVE_MLKEM768_PPC64LE_enc_derand_oqs signature_dec: PQCP_MLKEM_NATIVE_MLKEM768_PPC64LE_dec_oqs sources: integration/liboqs/config_ppc64le.h integration/liboqs/fips202_glue.h integration/liboqs/fips202x4_glue.h - integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/cbmc.h mlkem/src/common.h - mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h mlkem/src/debug.c - mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c mlkem/src/kem.h - mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h mlkem/src/poly.c - mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h + integration/liboqs/kem_glue.c mlkem/mlkem_native.h mlkem/src/capability.h mlkem/src/cbmc.h + mlkem/src/common.h mlkem/src/compress.c mlkem/src/compress.h mlkem/src/context.h + mlkem/src/debug.c mlkem/src/debug.h mlkem/src/indcpa.c mlkem/src/indcpa.h mlkem/src/kem.c + mlkem/src/kem.h mlkem/src/native/api.h mlkem/src/native/meta.h mlkem/src/params.h + mlkem/src/poly.c mlkem/src/poly.h mlkem/src/poly_k.c mlkem/src/poly_k.h mlkem/src/randombytes.h mlkem/src/sampling.c mlkem/src/sampling.h mlkem/src/symmetric.h mlkem/src/sys.h mlkem/src/verify.c mlkem/src/verify.h mlkem/src/zetas.inc mlkem/src/native/ppc64le supported_platforms: diff --git a/integration/pavona/capability-header.patch b/integration/pavona/capability-header.patch new file mode 100644 index 0000000000..7c23ee4f52 --- /dev/null +++ b/integration/pavona/capability-header.patch @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT +diff --git a/third_party/mlkem_native/BUILD.mlkem_native.bazel b/third_party/mlkem_native/BUILD.mlkem_native.bazel +--- a/third_party/mlkem_native/BUILD.mlkem_native.bazel ++++ b/third_party/mlkem_native/BUILD.mlkem_native.bazel +@@ -10,6 +10,7 @@ cc_library( + hdrs = [ + "mlkem/mlkem_native.c", + "mlkem/mlkem_native.h", ++ "mlkem/src/capability.h", + "mlkem/src/cbmc.h", + "mlkem/src/common.h", + "mlkem/src/context.h", diff --git a/mlkem/mlkem_native.c b/mlkem/mlkem_native.c index 12059df95d..84adf0806c 100644 --- a/mlkem/mlkem_native.c +++ b/mlkem/mlkem_native.c @@ -188,6 +188,8 @@ #undef MLK_COMMON_H #undef MLK_CONCAT #undef MLK_CONCAT_ +#undef MLK_CT_TESTING_DECLASSIFY +#undef MLK_CT_TESTING_SECRET #undef MLK_EMPTY_CU #undef MLK_ERR_FAIL #undef MLK_ERR_INVALID_PK @@ -199,6 +201,7 @@ #undef MLK_FIPS202X4_HEADER_FILE #undef MLK_FIPS202_HEADER_FILE #undef MLK_FREE +#undef MLK_HAVE_INLINE_ASM #undef MLK_INTERNAL_API #undef MLK_INTERNAL_DATA_DECLARATION #undef MLK_INTERNAL_DATA_DEFINITION @@ -281,6 +284,8 @@ /* * Undefine macros from MLK_CONFIG_PARAMETER_SET-generic files */ +/* mlkem/src/capability.h */ +#undef MLK_CAPABILITY_H /* mlkem/src/compress.h */ #undef MLK_COMPRESS_H #undef mlk_poly_compress_d10 @@ -661,10 +666,7 @@ #undef MLK_ALIGN_UP #undef MLK_ALWAYS_INLINE #undef MLK_CET_ENDBR -#undef MLK_CT_TESTING_DECLASSIFY -#undef MLK_CT_TESTING_SECRET #undef MLK_DEFAULT_ALIGN -#undef MLK_HAVE_INLINE_ASM #undef MLK_INLINE #undef MLK_MUST_CHECK_RETURN_VALUE #undef MLK_NOINLINE diff --git a/mlkem/mlkem_native_asm.S b/mlkem/mlkem_native_asm.S index 79be78ed0d..e0a0213c57 100644 --- a/mlkem/mlkem_native_asm.S +++ b/mlkem/mlkem_native_asm.S @@ -219,6 +219,8 @@ #undef MLK_COMMON_H #undef MLK_CONCAT #undef MLK_CONCAT_ +#undef MLK_CT_TESTING_DECLASSIFY +#undef MLK_CT_TESTING_SECRET #undef MLK_EMPTY_CU #undef MLK_ERR_FAIL #undef MLK_ERR_INVALID_PK @@ -230,6 +232,7 @@ #undef MLK_FIPS202X4_HEADER_FILE #undef MLK_FIPS202_HEADER_FILE #undef MLK_FREE +#undef MLK_HAVE_INLINE_ASM #undef MLK_INTERNAL_API #undef MLK_INTERNAL_DATA_DECLARATION #undef MLK_INTERNAL_DATA_DEFINITION @@ -312,6 +315,8 @@ /* * Undefine macros from MLK_CONFIG_PARAMETER_SET-generic files */ +/* mlkem/src/capability.h */ +#undef MLK_CAPABILITY_H /* mlkem/src/compress.h */ #undef MLK_COMPRESS_H #undef mlk_poly_compress_d10 @@ -692,10 +697,7 @@ #undef MLK_ALIGN_UP #undef MLK_ALWAYS_INLINE #undef MLK_CET_ENDBR -#undef MLK_CT_TESTING_DECLASSIFY -#undef MLK_CT_TESTING_SECRET #undef MLK_DEFAULT_ALIGN -#undef MLK_HAVE_INLINE_ASM #undef MLK_INLINE #undef MLK_MUST_CHECK_RETURN_VALUE #undef MLK_NOINLINE diff --git a/mlkem/src/capability.h b/mlkem/src/capability.h new file mode 100644 index 0000000000..86dd9e745d --- /dev/null +++ b/mlkem/src/capability.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) The mlkem-native project authors + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT + */ +#ifndef MLK_CAPABILITY_H +#define MLK_CAPABILITY_H + +#include "sys.h" + +#if !defined(MLK_CONFIG_CUSTOM_CAPABILITY_FUNC) && !defined(__ASSEMBLER__) +#include "cbmc.h" + +MLK_MUST_CHECK_RETURN_VALUE +static MLK_INLINE int mlk_sys_check_capability(mlk_sys_cap cap) +__contract__( + ensures(return_value == 0 || return_value == 1) +) +{ + /* By default, we rely on compile-time feature detection/specification: + * If a feature is enabled at compile-time, we assume it is supported by + * the host that the resulting library/binary will be built on. + * If this assumption is not true, you MUST overwrite this function. + * See the documentation of MLK_CONFIG_CUSTOM_CAPABILITY_FUNC in + * mlkem_native_config.h for more information. */ + (void)cap; + return 1; +} +#endif /* !MLK_CONFIG_CUSTOM_CAPABILITY_FUNC && !__ASSEMBLER__ */ + +#endif /* !MLK_CAPABILITY_H */ diff --git a/mlkem/src/common.h b/mlkem/src/common.h index d7201984a2..17d60bc3a0 100644 --- a/mlkem/src/common.h +++ b/mlkem/src/common.h @@ -34,9 +34,31 @@ #include "mlkem_native_config.h" #endif +#include "capability.h" #include "params.h" #include "sys.h" +#if !defined(MLK_CONFIG_NO_ASM) && (defined(__GNUC__) || defined(__clang__)) +#define MLK_HAVE_INLINE_ASM +#endif + +#if defined(MLK_CONFIG_CT_TESTING_ENABLED) && !defined(__ASSEMBLER__) +#include +#define MLK_CT_TESTING_SECRET(ptr, len) \ + VALGRIND_MAKE_MEM_UNDEFINED((ptr), (len)) +#define MLK_CT_TESTING_DECLASSIFY(ptr, len) \ + VALGRIND_MAKE_MEM_DEFINED((ptr), (len)) +#else /* MLK_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__ */ +#define MLK_CT_TESTING_SECRET(ptr, len) \ + do \ + { \ + } while (0) +#define MLK_CT_TESTING_DECLASSIFY(ptr, len) \ + do \ + { \ + } while (0) +#endif /* !(MLK_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__) */ + /* Internal and public API have external linkage by default, but * this can be overwritten by the user, e.g. for single-CU builds. */ #if !defined(MLK_CONFIG_INTERNAL_API_QUALIFIER) diff --git a/mlkem/src/sys.h b/mlkem/src/sys.h index c430f77b0d..e39c43449b 100644 --- a/mlkem/src/sys.h +++ b/mlkem/src/sys.h @@ -5,9 +5,9 @@ #ifndef MLK_SYS_H #define MLK_SYS_H -#if !defined(MLK_CONFIG_NO_ASM) && (defined(__GNUC__) || defined(__clang__)) -#define MLK_HAVE_INLINE_ASM -#endif +/* This header must not depend on configuration options: configuration + * hooks may include it before all options are defined, and its include + * guard prevents re-evaluation. Evaluate options in common.h instead. */ /* Try to find endianness, if not forced through CFLAGS already */ #if !defined(MLK_SYS_LITTLE_ENDIAN) && !defined(MLK_SYS_BIG_ENDIAN) @@ -235,23 +235,6 @@ #endif #endif /* MLK_SYS_X86_64 */ -#if defined(MLK_CONFIG_CT_TESTING_ENABLED) && !defined(__ASSEMBLER__) -#include -#define MLK_CT_TESTING_SECRET(ptr, len) \ - VALGRIND_MAKE_MEM_UNDEFINED((ptr), (len)) -#define MLK_CT_TESTING_DECLASSIFY(ptr, len) \ - VALGRIND_MAKE_MEM_DEFINED((ptr), (len)) -#else /* MLK_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__ */ -#define MLK_CT_TESTING_SECRET(ptr, len) \ - do \ - { \ - } while (0) -#define MLK_CT_TESTING_DECLASSIFY(ptr, len) \ - do \ - { \ - } while (0) -#endif /* !(MLK_CONFIG_CT_TESTING_ENABLED && !__ASSEMBLER__) */ - #if defined(__GNUC__) || defined(__clang__) #define MLK_MUST_CHECK_RETURN_VALUE __attribute__((warn_unused_result)) #else @@ -295,26 +278,6 @@ typedef enum /* Armv8.1-M */ MLK_SYS_CAP_ARMV81M_MVE } mlk_sys_cap; - -#if !defined(MLK_CONFIG_CUSTOM_CAPABILITY_FUNC) -#include "cbmc.h" - -MLK_MUST_CHECK_RETURN_VALUE -static MLK_INLINE int mlk_sys_check_capability(mlk_sys_cap cap) -__contract__( - ensures(return_value == 0 || return_value == 1) -) -{ - /* By default, we rely on compile-time feature detection/specification: - * If a feature is enabled at compile-time, we assume it is supported by - * the host that the resulting library/binary will be built on. - * If this assumption is not true, you MUST overwrite this function. - * See the documentation of MLK_CONFIG_CUSTOM_CAPABILITY_FUNC in - * mlkem_native_config.h for more information. */ - (void)cap; - return 1; -} -#endif /* !MLK_CONFIG_CUSTOM_CAPABILITY_FUNC */ #endif /* !__ASSEMBLER__ */ #endif /* !MLK_SYS_H */ diff --git a/proofs/cbmc/sys_check_capability/sys_check_capability_harness.c b/proofs/cbmc/sys_check_capability/sys_check_capability_harness.c index dcdcbb464b..a15117adff 100644 --- a/proofs/cbmc/sys_check_capability/sys_check_capability_harness.c +++ b/proofs/cbmc/sys_check_capability/sys_check_capability_harness.c @@ -2,7 +2,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 -#include "sys.h" +#include "capability.h" void harness(void) { diff --git a/test/abicheck/abicheck_common.h b/test/abicheck/abicheck_common.h index d64264aeed..a995a84414 100644 --- a/test/abicheck/abicheck_common.h +++ b/test/abicheck/abicheck_common.h @@ -9,9 +9,9 @@ #include /* - * Resolve the build config and sys.h. We don't include common.h: it would - * drag in backend constant tables that older compilers do not drop, forcing - * them into the abicheck link. + * Resolve the build config, sys.h and capability.h. We don't include + * common.h: it would drag in backend constant tables that older compilers do + * not drop, forcing them into the abicheck link. * * Paths use the project's -Imlkem search path (set in test/mk/components.mk) * so this header is includable from any depth under test/abicheck/. @@ -22,6 +22,7 @@ #else #include "mlkem_native_config.h" #endif +#include "src/capability.h" #include "src/sys.h" /* Return codes for check_(), shared with abicheck.c. */