diff --git a/.github/actions/config-variations/action.yml b/.github/actions/config-variations/action.yml index b776d605f9..6b7ad80afc 100644 --- a/.github/actions/config-variations/action.yml +++ b/.github/actions/config-variations/action.yml @@ -11,7 +11,8 @@ inputs: description: 'List of tests to run (space-separated IDs) or "all" for all tests. Available IDs: pct-enabled, pct-enabled-broken, custom-alloc-heap, custom-zeroize, native-cap-ON, native-cap-OFF, native-cap-ID_AA64PFR1_EL1, native-cap-CPUID_AVX2, no-asm, serial-fips202, custom-randombytes, custom-memcpy, custom-memset, custom-stdlib, - nblocks-1, nblocks-2, nblocks-4' + nblocks-1, nblocks-2, nblocks-4, keygen-only, encaps-only, decaps-only, keygen-encaps, keygen-decaps, encaps-decaps, + no-randomized' required: false default: 'all' opt: @@ -276,3 +277,116 @@ runs: examples: false # Some examples use a custom config themselves alloc: false # Requires custom config rng_fail: true + - name: "Keygen-only API" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'keygen-only') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_ENCAPS_API -DMLK_CONFIG_NO_DECAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + - name: "Encaps-only API" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'encaps-only') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_KEYPAIR_API -DMLK_CONFIG_NO_DECAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + - name: "Decaps-only API" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'decaps-only') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_KEYPAIR_API -DMLK_CONFIG_NO_ENCAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + - name: "Keygen+Encaps API (no decaps)" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'keygen-encaps') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_DECAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + - name: "Keygen+Decaps API (no encaps)" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'keygen-decaps') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_ENCAPS_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + - name: "Encaps+Decaps API (no keygen)" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'encaps-decaps') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_KEYPAIR_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + - name: "No randomized API (deterministic only)" + if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'no-randomized') }} + uses: ./.github/actions/multi-functest + with: + gh_token: ${{ inputs.gh_token }} + compile_mode: native + cflags: "-DMLK_CONFIG_NO_RANDOMIZED_API -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" + func: true + kat: true + acvp: true + wycheproof: true + stack: true + rng_fail: true + opt: ${{ inputs.opt }} + examples: true + # basic_deterministic sets MLK_CONFIG_NO_RANDOMIZED_API in its own config, + # so passing it again on the command line is a macro redefinition. + extra_args: "--exclude-example basic_deterministic" + # The alloc test's exact high-watermark check assumes the randomized + # wrappers (which allocate the coins buffer), so it doesn't match the + # deterministic-only allocation profile. + alloc: false diff --git a/.github/workflows/baremetal.yml b/.github/workflows/baremetal.yml index 7269f44dc9..c3016cfea6 100644 --- a/.github/workflows/baremetal.yml +++ b/.github/workflows/baremetal.yml @@ -17,7 +17,7 @@ jobs: matrix: target: - runner: ubuntu-latest - name: 'AVR ATmega128RFR2 (modified for 32K RAM)' + name: 'AVR ATmega128RFR2 (modified for 63.5K RAM)' makefile: test/baremetal/platform/avr/platform.mk nix-shell: cross-avr func: true diff --git a/META.py b/META.py index efa172432b..4ff55e817b 100644 --- a/META.py +++ b/META.py @@ -5,7 +5,9 @@ # Checks the KAT output of a gen_KAT binary against META.yml. # # Reads the KAT bytes from stdin, hashes them with SHA-256, and compares -# against the kat-sha256 field for the given scheme in META.yml. +# against the kat-sha256 field for the given scheme in META.yml. If stdin is +# "SKIPPED" (emitted by gen_KAT for reduced-API builds), the check is reported +# as skipped. # # To run manually, pipe a gen_KAT binary into it, e.g.: # @@ -53,9 +55,16 @@ def main(): err(f"META.yml: no kat-sha256 entry for {scheme_name}") sys.exit(1) - # Hash the raw bytes piped in from gen_KAT on stdin. Read in binary mode so + # Read the raw bytes piped in from gen_KAT on stdin. Read in binary mode so # that no newline translation occurs on Windows. - computed = hashlib.sha256(sys.stdin.buffer.read()).hexdigest() + data = sys.stdin.buffer.read() + + # Reduced-API builds emit "SKIPPED" instead of KAT bytes; report as skipped. + if data.startswith(b"SKIPPED"): + info(f"META.yml {scheme_name} kat-sha256: SKIPPED") + sys.exit(0) + + computed = hashlib.sha256(data).hexdigest() if computed == ref: info(f"META.yml {scheme_name} kat-sha256: OK") diff --git a/dev/aarch64_clean/meta.h b/dev/aarch64_clean/meta.h index 89f3e27787..0734373ad8 100644 --- a/dev/aarch64_clean/meta.h +++ b/dev/aarch64_clean/meta.h @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) mlk_aarch64_invntt_zetas_layer67); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -60,6 +62,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -70,6 +73,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) mlk_poly_tomont_aarch64_asm(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2], @@ -130,6 +134,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native( } #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], const int16_t a[MLKEM_N]) @@ -141,6 +146,7 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], mlk_poly_tobytes_aarch64_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len, diff --git a/dev/aarch64_clean/src/aarch64_zetas.c b/dev/aarch64_clean/src/aarch64_zetas.c index cc3a48dddf..c743d92f18 100644 --- a/dev/aarch64_clean/src/aarch64_zetas.c +++ b/dev/aarch64_clean/src/aarch64_zetas.c @@ -79,6 +79,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t 10129, 10129, -3878, -3878, -11566, -11566, }; +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t mlk_aarch64_invntt_zetas_layer12345[80] = { 1583, 15582, -821, -8081, 1355, 13338, 0, 0, -569, @@ -138,6 +139,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t 1041, -1637, -1637, -583, -583, -17, -17, 10247, 10247, -16113, -16113, -5739, -5739, -167, -167, }; +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t mlk_aarch64_zetas_mulcache_native[128] = { diff --git a/dev/aarch64_clean/src/intt_aarch64_asm.S b/dev/aarch64_clean/src/intt_aarch64_asm.S index a1efae1d89..2f74cf4cae 100644 --- a/dev/aarch64_clean/src/intt_aarch64_asm.S +++ b/dev/aarch64_clean/src/intt_aarch64_asm.S @@ -52,7 +52,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_AARCH64) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /* simpasm: header-end */ // Bounds: @@ -400,4 +402,5 @@ mlk_intt_layer123_start: .unreq ninv_tw /* simpasm: footer-start */ -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ diff --git a/dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S b/dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S index 79122a676d..ac28c822de 100644 --- a/dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S +++ b/dev/aarch64_clean/src/poly_tobytes_aarch64_asm.S @@ -29,7 +29,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_AARCH64) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) /* simpasm: header-end */ .macro ld2_wrap a, ptr @@ -94,4 +96,5 @@ mlk_poly_tobytes_loop_start: .unreq count /* simpasm: footer-start */ -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + (!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */ diff --git a/dev/aarch64_clean/src/poly_tomont_aarch64_asm.S b/dev/aarch64_clean/src/poly_tomont_aarch64_asm.S index b8b212ab52..cf050fff90 100644 --- a/dev/aarch64_clean/src/poly_tomont_aarch64_asm.S +++ b/dev/aarch64_clean/src/poly_tomont_aarch64_asm.S @@ -23,7 +23,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_AARCH64) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /* simpasm: header-end */ /* Montgomery multiplication, with precomputed Montgomery twist @@ -103,4 +104,5 @@ mlk_poly_tomont_loop: .unreq tmp0 /* simpasm: footer-start */ -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + !MLK_CONFIG_NO_KEYPAIR_API */ diff --git a/dev/aarch64_opt/meta.h b/dev/aarch64_opt/meta.h index 6bd1653e28..6964067a32 100644 --- a/dev/aarch64_opt/meta.h +++ b/dev/aarch64_opt/meta.h @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) mlk_aarch64_invntt_zetas_layer67); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -60,6 +62,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -70,6 +73,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) mlk_poly_tomont_aarch64_asm(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2], @@ -130,6 +134,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native( } #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], const int16_t a[MLKEM_N]) @@ -141,6 +146,7 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], mlk_poly_tobytes_aarch64_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len, diff --git a/dev/aarch64_opt/src/aarch64_zetas.c b/dev/aarch64_opt/src/aarch64_zetas.c index cc3a48dddf..c743d92f18 100644 --- a/dev/aarch64_opt/src/aarch64_zetas.c +++ b/dev/aarch64_opt/src/aarch64_zetas.c @@ -79,6 +79,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t 10129, 10129, -3878, -3878, -11566, -11566, }; +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t mlk_aarch64_invntt_zetas_layer12345[80] = { 1583, 15582, -821, -8081, 1355, 13338, 0, 0, -569, @@ -138,6 +139,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t 1041, -1637, -1637, -583, -583, -17, -17, 10247, 10247, -16113, -16113, -5739, -5739, -167, -167, }; +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t mlk_aarch64_zetas_mulcache_native[128] = { diff --git a/dev/aarch64_opt/src/intt_aarch64_asm.S b/dev/aarch64_opt/src/intt_aarch64_asm.S index b36ea2b90a..e24c0165e3 100644 --- a/dev/aarch64_opt/src/intt_aarch64_asm.S +++ b/dev/aarch64_opt/src/intt_aarch64_asm.S @@ -51,7 +51,10 @@ */ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) +#if defined(MLK_ARITH_BACKEND_AARCH64) && \ + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /* simpasm: header-end */ // Bounds: @@ -1420,4 +1423,5 @@ mlk_intt_layer123_start: .unreq ninv_tw /* simpasm: footer-start */ -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ diff --git a/dev/aarch64_opt/src/poly_tobytes_aarch64_asm.S b/dev/aarch64_opt/src/poly_tobytes_aarch64_asm.S index 3893db026a..ce4da552bf 100644 --- a/dev/aarch64_opt/src/poly_tobytes_aarch64_asm.S +++ b/dev/aarch64_opt/src/poly_tobytes_aarch64_asm.S @@ -28,7 +28,10 @@ */ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) +#if defined(MLK_ARITH_BACKEND_AARCH64) && \ + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) /* simpasm: header-end */ .macro ld2_wrap a, ptr @@ -253,4 +256,5 @@ mlk_poly_tobytes_loop_start: .unreq count /* simpasm: footer-start */ -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + (!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */ diff --git a/dev/aarch64_opt/src/poly_tomont_aarch64_asm.S b/dev/aarch64_opt/src/poly_tomont_aarch64_asm.S index f0caa420ae..1dd22fb7af 100644 --- a/dev/aarch64_opt/src/poly_tomont_aarch64_asm.S +++ b/dev/aarch64_opt/src/poly_tomont_aarch64_asm.S @@ -22,7 +22,9 @@ */ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) +#if defined(MLK_ARITH_BACKEND_AARCH64) && \ + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /* simpasm: header-end */ /* Montgomery multiplication, with precomputed Montgomery twist @@ -220,4 +222,5 @@ mlk_poly_tomont_loop: .unreq tmp0 /* simpasm: footer-start */ -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + !MLK_CONFIG_NO_KEYPAIR_API */ diff --git a/dev/ppc64le/meta.h b/dev/ppc64le/meta.h index baa95db2d4..e10ecd6907 100644 --- a/dev/ppc64le/meta.h +++ b/dev/ppc64le/meta.h @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) #endif } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_FALLBACK; #endif } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -61,6 +63,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) #endif } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -72,6 +75,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_FALLBACK; #endif } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ #endif /* !__ASSEMBLER__ */ #endif /* !MLK_DEV_PPC64LE_META_H */ diff --git a/dev/ppc64le/src/intt_ppc_asm.S b/dev/ppc64le/src/intt_ppc_asm.S index 61777d1a26..3ec1777174 100644 --- a/dev/ppc64le/src/intt_ppc_asm.S +++ b/dev/ppc64le/src/intt_ppc_asm.S @@ -8,7 +8,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_PPC64LE_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /*yaml Name: intt_ppc_asm Description: PowerPC64 VSX inverse NTT @@ -1002,4 +1004,5 @@ mlk_intt_ppc_asm_Loopf: /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_PPC64LE_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && __POWER8_VECTOR__ */ + && __POWER8_VECTOR__ && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ diff --git a/dev/ppc64le/src/poly_tomont_ppc_asm.S b/dev/ppc64le/src/poly_tomont_ppc_asm.S index b103e76b28..d680dc361f 100644 --- a/dev/ppc64le/src/poly_tomont_ppc_asm.S +++ b/dev/ppc64le/src/poly_tomont_ppc_asm.S @@ -15,7 +15,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_PPC64LE_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /*yaml Name: poly_tomont_ppc_asm Description: PowerPC64 VSX conversion to Montgomery form @@ -241,4 +242,4 @@ MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm) /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_PPC64LE_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && __POWER8_VECTOR__ */ + && __POWER8_VECTOR__ && !MLK_CONFIG_NO_KEYPAIR_API */ diff --git a/dev/x86_64/meta.h b/dev/x86_64/meta.h index fdbbfcea28..59529eb5be 100644 --- a/dev/x86_64/meta.h +++ b/dev/x86_64/meta.h @@ -68,6 +68,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -79,6 +80,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) mlk_invntt_avx2_asm(data, mlk_qdata); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -92,6 +94,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -103,6 +106,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) mlk_tomont_avx2_asm(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2], @@ -165,6 +169,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native( } #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], const int16_t a[MLKEM_N]) @@ -177,7 +182,9 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], mlk_ntttobytes_avx2_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_frombytes_native( int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYBYTES]) @@ -190,8 +197,12 @@ static MLK_INLINE int mlk_poly_frombytes_native( mlk_nttfrombytes_avx2_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ -#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) +#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ + (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || \ + MLKEM_K == 3) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_compress_d4_native( uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4], const int16_t a[MLKEM_N]) @@ -218,6 +229,7 @@ static MLK_INLINE int mlk_poly_compress_d10_native( return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_decompress_d4_native( int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4]) @@ -243,9 +255,14 @@ static MLK_INLINE int mlk_poly_decompress_d10_native( mlk_poly_decompress_d10_avx2_asm(r, a, mlk_decompress_d10_data); return MLK_NATIVE_FUNC_SUCCESS; } -#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ - -#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ + +#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ + (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_compress_d5_native( uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5], const int16_t a[MLKEM_N]) @@ -272,6 +289,7 @@ static MLK_INLINE int mlk_poly_compress_d11_native( return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_decompress_d5_native( int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5]) @@ -297,7 +315,9 @@ static MLK_INLINE int mlk_poly_decompress_d11_native( mlk_poly_decompress_d11_avx2_asm(r, a, mlk_decompress_d11_data); return MLK_NATIVE_FUNC_SUCCESS; } -#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ #endif /* !__ASSEMBLER__ */ diff --git a/dev/x86_64/src/compress_consts.c b/dev/x86_64/src/compress_consts.c index 91fd4d1920..1645fca573 100644 --- a/dev/x86_64/src/compress_consts.c +++ b/dev/x86_64/src/compress_consts.c @@ -11,7 +11,8 @@ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) +#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) #include "compress_consts.h" @@ -25,11 +26,13 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0, /* permdidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d4_data[32] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, /* shufbidx */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_compress_d10_data[32] = { @@ -38,11 +41,13 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 255, 255, 255, 255, 0, 1, 2, 3, 4, 8, /* shufbidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d10_data[32] = { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, /* shufbidx */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ @@ -58,6 +63,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 1, 2, 3, 4, 255, 255, 255, 255, 255, 8, /* shufbidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* shufbidx[0:32], mask[32:64], shift[64:96] */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d5_data[96] = { @@ -68,6 +74,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 0, 4, 32, 0, 0, 1, 8, 0, 64, 0, 0, 2, 16, 0, 128, 0, 0, 4, 32, 0, 0, 1, 8, 0, 64, 0, 0, 2, 16, 0, 128, 0, /* shift */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* srlvqidx[0:32], shufbidx[32:64] */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t @@ -81,6 +88,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 255, 255, 255, 255, 0, 0, 1, 2, 3, 4, /* shufbidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* shufbidx[0:32], srlvdidx[32:64], srlvqidx[64:96], shift[96:128] */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d11_data[128] = { @@ -93,12 +101,15 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 32, 0, 4, 0, 1, 0, 32, 0, 8, 0, 1, 0, 32, 0, 4, 0, 32, 0, 4, 0, 1, 0, 32, 0, 8, 0, 1, 0, 32, 0, 4, 0, /* shift */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ -#else /* MLK_ARITH_BACKEND_X86_64_DEFAULT */ +#else /* MLK_ARITH_BACKEND_X86_64_DEFAULT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ MLK_EMPTY_CU(avx2_compress_consts) -#endif /* !MLK_ARITH_BACKEND_X86_64_DEFAULT */ +#endif /* !(MLK_ARITH_BACKEND_X86_64_DEFAULT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API)) */ diff --git a/dev/x86_64/src/compress_consts.h b/dev/x86_64/src/compress_consts.h index 5646c44cae..d47ffd877d 100644 --- a/dev/x86_64/src/compress_consts.h +++ b/dev/x86_64/src/compress_consts.h @@ -19,26 +19,34 @@ #define mlk_compress_d4_data MLK_NAMESPACE(compress_d4_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d4_data[32]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d4_data MLK_NAMESPACE(decompress_d4_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d4_data[32]; +#endif #define mlk_compress_d10_data MLK_NAMESPACE(compress_d10_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d10_data[32]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d10_data MLK_NAMESPACE(decompress_d10_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d10_data[32]; +#endif #define mlk_compress_d5_data MLK_NAMESPACE(compress_d5_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d5_data[32]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d5_data MLK_NAMESPACE(decompress_d5_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d5_data[96]; +#endif #define mlk_compress_d11_data MLK_NAMESPACE(compress_d11_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d11_data[64]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d11_data MLK_NAMESPACE(decompress_d11_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d11_data[128]; +#endif #endif /* !__ASSEMBLER__ */ diff --git a/dev/x86_64/src/intt_avx2_asm.S b/dev/x86_64/src/intt_avx2_asm.S index 9fa6591bcd..72e59c67f0 100644 --- a/dev/x86_64/src/intt_avx2_asm.S +++ b/dev/x86_64/src/intt_avx2_asm.S @@ -30,7 +30,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /*yaml Name: invntt_avx2_asm Description: x86_64 AVX2 inverse NTT @@ -311,4 +313,4 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ diff --git a/dev/x86_64/src/nttfrombytes_avx2_asm.S b/dev/x86_64/src/nttfrombytes_avx2_asm.S index 096a59abc3..bf559bdad6 100644 --- a/dev/x86_64/src/nttfrombytes_avx2_asm.S +++ b/dev/x86_64/src/nttfrombytes_avx2_asm.S @@ -20,7 +20,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /*yaml Name: nttfrombytes_avx2_asm Description: x86_64 AVX2 polynomial deserialization in NTT domain @@ -131,4 +133,4 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ diff --git a/dev/x86_64/src/ntttobytes_avx2_asm.S b/dev/x86_64/src/ntttobytes_avx2_asm.S index 61bddf1e7c..6849961e12 100644 --- a/dev/x86_64/src/ntttobytes_avx2_asm.S +++ b/dev/x86_64/src/ntttobytes_avx2_asm.S @@ -20,7 +20,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) /*yaml Name: ntttobytes_avx2_asm Description: x86_64 AVX2 polynomial serialization in NTT domain @@ -126,4 +128,4 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && (!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */ diff --git a/dev/x86_64/src/poly_compress_d10_avx2_asm.S b/dev/x86_64/src/poly_compress_d10_avx2_asm.S index 1e0b52d5bb..823e7c9fca 100644 --- a/dev/x86_64/src/poly_compress_d10_avx2_asm.S +++ b/dev/x86_64/src/poly_compress_d10_avx2_asm.S @@ -31,6 +31,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_compress_d10_avx2_asm @@ -185,5 +187,6 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ diff --git a/dev/x86_64/src/poly_compress_d11_avx2_asm.S b/dev/x86_64/src/poly_compress_d11_avx2_asm.S index 420cd61b87..74a689a62b 100644 --- a/dev/x86_64/src/poly_compress_d11_avx2_asm.S +++ b/dev/x86_64/src/poly_compress_d11_avx2_asm.S @@ -33,6 +33,8 @@ #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_compress_d11_avx2_asm @@ -157,4 +159,5 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ diff --git a/dev/x86_64/src/poly_compress_d4_avx2_asm.S b/dev/x86_64/src/poly_compress_d4_avx2_asm.S index 7481a1fda9..d202571b2d 100644 --- a/dev/x86_64/src/poly_compress_d4_avx2_asm.S +++ b/dev/x86_64/src/poly_compress_d4_avx2_asm.S @@ -31,6 +31,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_compress_d4_avx2_asm @@ -144,5 +146,6 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ diff --git a/dev/x86_64/src/poly_compress_d5_avx2_asm.S b/dev/x86_64/src/poly_compress_d5_avx2_asm.S index e3166f7107..f49e0e5d4c 100644 --- a/dev/x86_64/src/poly_compress_d5_avx2_asm.S +++ b/dev/x86_64/src/poly_compress_d5_avx2_asm.S @@ -31,6 +31,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_compress_d5_avx2_asm @@ -163,4 +165,5 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ diff --git a/dev/x86_64/src/poly_decompress_d10_avx2_asm.S b/dev/x86_64/src/poly_decompress_d10_avx2_asm.S index dbf25dde17..a3ed37e784 100644 --- a/dev/x86_64/src/poly_decompress_d10_avx2_asm.S +++ b/dev/x86_64/src/poly_decompress_d10_avx2_asm.S @@ -31,6 +31,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_decompress_d10_avx2_asm @@ -121,5 +122,5 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 2 || MLKEM_K == 3) */ diff --git a/dev/x86_64/src/poly_decompress_d11_avx2_asm.S b/dev/x86_64/src/poly_decompress_d11_avx2_asm.S index 3f9e40226b..67ec88f1b0 100644 --- a/dev/x86_64/src/poly_decompress_d11_avx2_asm.S +++ b/dev/x86_64/src/poly_decompress_d11_avx2_asm.S @@ -33,6 +33,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_decompress_d11_avx2_asm @@ -126,4 +127,5 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 4) */ diff --git a/dev/x86_64/src/poly_decompress_d4_avx2_asm.S b/dev/x86_64/src/poly_decompress_d4_avx2_asm.S index 968f8342cb..8834955367 100644 --- a/dev/x86_64/src/poly_decompress_d4_avx2_asm.S +++ b/dev/x86_64/src/poly_decompress_d4_avx2_asm.S @@ -31,6 +31,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_decompress_d4_avx2_asm @@ -118,5 +119,5 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 2 || MLKEM_K == 3) */ diff --git a/dev/x86_64/src/poly_decompress_d5_avx2_asm.S b/dev/x86_64/src/poly_decompress_d5_avx2_asm.S index 8452db1c9b..cc0a3b0f16 100644 --- a/dev/x86_64/src/poly_decompress_d5_avx2_asm.S +++ b/dev/x86_64/src/poly_decompress_d5_avx2_asm.S @@ -32,6 +32,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_decompress_d5_avx2_asm @@ -113,4 +114,5 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 4) */ diff --git a/dev/x86_64/src/tomont_avx2_asm.S b/dev/x86_64/src/tomont_avx2_asm.S index 0a43b14795..c5a4cb4cdd 100644 --- a/dev/x86_64/src/tomont_avx2_asm.S +++ b/dev/x86_64/src/tomont_avx2_asm.S @@ -24,7 +24,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /*yaml Name: tomont_avx2_asm Description: x86_64 AVX2 Montgomery conversion @@ -104,4 +105,4 @@ ret /* simpasm: footer-start */ #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && !MLK_CONFIG_NO_KEYPAIR_API */ diff --git a/examples/basic/expected_test_vectors.h b/examples/basic/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/basic/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/basic/main.c b/examples/basic/main.c index b41761de75..92daf1731b 100644 --- a/examples/basic/main.c +++ b/examples/basic/main.c @@ -6,13 +6,9 @@ #include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - */ +/* Import public mlkem-native API */ +#include "expected_test_vectors.h" #include "mlkem_native/mlkem_native.h" - #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -27,80 +23,81 @@ } \ } while (0) -int main(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_keygen(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key_a[CRYPTO_BYTES]; - uint8_t key_b[CRYPTO_BYTES]; - - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - printf("Generating keypair ... "); - - /* Alice generates a public key */ + printf("Generating keypair... "); CHECK(crypto_kem_keypair(pk, sk) == 0); - + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); printf("DONE\n"); - printf("Encaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_keygen(void) +{ + printf("Generating keypair... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Bob derives a secret key and creates a response */ - CHECK(crypto_kem_enc(ct, key_b, pk) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; + printf("Encaps... "); + CHECK(crypto_kem_enc(ct, ss, test_vector_pk) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Decaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_encaps(void) +{ + printf("Encaps... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Alice uses Bobs response to get her shared key */ - CHECK(crypto_kem_dec(key_a, ct, sk) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Compare... "); - - CHECK(memcmp(key_a, key_b, CRYPTO_BYTES) == 0); + return 0; +} +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_DECAPS_API */ - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); +int main(void) +{ + int r = 0; -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, CRYPTO_BYTES) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif + /* WARNING: Test-only + * Normally, you would seed a PRNG _once_ with trustworthy entropy and not + * reseed it afterwards. Here, we reseed before each API call to make each + * test independent and reproducible even when some API is disabled. */ + randombytes_reset(); + r |= example_keygen(); + randombytes_reset(); + r |= example_encaps(); + r |= example_decaps(); - printf("OK\n"); - return 0; + return r; } diff --git a/examples/basic_deterministic/expected_test_vectors.h b/examples/basic_deterministic/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/basic_deterministic/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/basic_deterministic/main.c b/examples/basic_deterministic/main.c index a7573c92c1..03aaa72012 100644 --- a/examples/basic_deterministic/main.c +++ b/examples/basic_deterministic/main.c @@ -6,11 +6,8 @@ #include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - */ +/* Import public mlkem-native API */ +#include "expected_test_vectors.h" #include "mlkem_native/mlkem_native.h" /* No randombytes needed for deterministic API */ @@ -27,81 +24,77 @@ } \ } while (0) -int main(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) +static int example_keygen(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key_a[CRYPTO_BYTES]; - uint8_t key_b[CRYPTO_BYTES]; - uint8_t alice_en[2 * MLKEM_SYMBYTES] = {0}; - uint8_t bob_en[MLKEM_SYMBYTES] = {1}; - - - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. - * Expected keys are generated using deterministic entropy: - * keypair uses all-zero entropy {0}, enc uses all-one entropy {1} */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x5f, 0x5f, 0x8c, 0xf5, 0x7c, 0x34, 0xd4, 0x68, 0x06, 0xa2, 0xe9, - 0xc9, 0x28, 0xba, 0x10, 0x5a, 0x46, 0xf2, 0x67, 0x1a, 0xc7, 0x81, - 0xdf, 0xf1, 0x4a, 0xbb, 0x27, 0xea, 0x46, 0x06, 0x46, 0x3c}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0x85, 0x21, 0xab, 0xc8, 0x14, 0xc7, 0x67, 0x70, 0x4f, 0xa6, 0x25, - 0xd9, 0x35, 0x95, 0xd0, 0x03, 0x79, 0xa8, 0xb3, 0x70, 0x35, 0x2c, - 0xa4, 0xba, 0xb3, 0xa6, 0x82, 0x46, 0x63, 0x0d, 0xb0, 0x8b}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x30, 0x4d, 0xbe, 0x54, 0xd6, 0x6f, 0x80, 0x66, 0xc6, 0xa8, 0x1c, - 0x6b, 0x36, 0xc4, 0x48, 0x9b, 0xf9, 0xe6, 0x05, 0x79, 0x83, 0x3c, - 0x4e, 0xdc, 0x8a, 0xc7, 0x92, 0xe5, 0x73, 0x0d, 0xdd, 0x85}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ + uint8_t coins[2 * MLKEM_SYMBYTES]; - /* No randombytes_reset() needed for deterministic API */ - - printf("Generating keypair ... "); - - /* Alice generates a public key using deterministic API with all-zero entropy - */ - CHECK(crypto_kem_keypair_derand(pk, sk, alice_en) == 0); + memcpy(coins, test_vector_d, MLKEM_SYMBYTES); + memcpy(coins + MLKEM_SYMBYTES, test_vector_z, MLKEM_SYMBYTES); + printf("Generating keypair (deterministic)... "); + CHECK(crypto_kem_keypair_derand(pk, sk, coins) == 0); + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); printf("DONE\n"); - printf("Encaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API */ +static int example_keygen(void) +{ + printf( + "Generating keypair (deterministic)... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_KEYPAIR_API */ - /* Bob derives a secret key and creates a response using deterministic API - * with all-one entropy */ - CHECK(crypto_kem_enc_derand(ct, key_b, pk, bob_en) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; + printf("Encaps (deterministic)... "); + CHECK(crypto_kem_enc_derand(ct, ss, test_vector_pk, test_vector_m) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Decaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API */ +static int example_encaps(void) +{ + printf("Encaps (deterministic)... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_ENCAPS_API */ - /* Alice uses Bobs response to get her shared key */ - CHECK(crypto_kem_dec(key_a, ct, sk) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Compare... "); - - CHECK(memcmp(key_a, key_b, CRYPTO_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); - - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, CRYPTO_BYTES) == 0); - - - printf("OK\n"); return 0; } +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_DECAPS_API */ + +int main(void) +{ + int r = 0; + r |= example_keygen(); + r |= example_encaps(); + r |= example_decaps(); + return r; +} diff --git a/examples/basic_deterministic/mlkem_native/mlkem_native_config.h b/examples/basic_deterministic/mlkem_native/mlkem_native_config.h index 8c072921ff..42923ca84e 100644 --- a/examples/basic_deterministic/mlkem_native/mlkem_native_config.h +++ b/examples/basic_deterministic/mlkem_native/mlkem_native_config.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/bring_your_own_fips202/expected_test_vectors.h b/examples/bring_your_own_fips202/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/bring_your_own_fips202/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/bring_your_own_fips202/main.c b/examples/bring_your_own_fips202/main.c index 9788aa6e53..e0173dd385 100644 --- a/examples/bring_your_own_fips202/main.c +++ b/examples/bring_your_own_fips202/main.c @@ -6,13 +6,10 @@ #include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - */ +/* Import public mlkem-native API */ #include +#include "expected_test_vectors.h" #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -27,85 +24,81 @@ } \ } while (0) -int main(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_keygen(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key_a[CRYPTO_BYTES]; - uint8_t key_b[CRYPTO_BYTES]; - - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - printf("Generating keypair ... "); - /* Alice generates a public key */ + printf("Generating keypair... "); CHECK(crypto_kem_keypair(pk, sk) == 0); - + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); printf("DONE\n"); - printf("Encaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_keygen(void) +{ + printf("Generating keypair... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Bob derives a secret key and creates a response */ - CHECK(crypto_kem_enc(ct, key_b, pk) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; + printf("Encaps... "); + CHECK(crypto_kem_enc(ct, ss, test_vector_pk) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Decaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_encaps(void) +{ + printf("Encaps... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Alice uses Bobs response to get her shared key */ - CHECK(crypto_kem_dec(key_a, ct, sk) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Compare... "); - - if (memcmp(key_a, key_b, CRYPTO_BYTES)) - { - printf("ERROR: Mismatching keys\n"); - return 1; - } - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_DECAPS_API */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif +int main(void) +{ + int r = 0; - printf("OK\n"); + /* WARNING: Test-only + * Normally, you would seed a PRNG _once_ with trustworthy entropy and not + * reseed it afterwards. Here, we reseed before each API call to make each + * test independent and reproducible even when some API is disabled. */ + randombytes_reset(); + r |= example_keygen(); + randombytes_reset(); + r |= example_encaps(); + r |= example_decaps(); - return 0; + return r; } diff --git a/examples/bring_your_own_fips202/mlkem_native/mlkem_native_config.h b/examples/bring_your_own_fips202/mlkem_native/mlkem_native_config.h index 31333aa667..7dc511cfa1 100644 --- a/examples/bring_your_own_fips202/mlkem_native/mlkem_native_config.h +++ b/examples/bring_your_own_fips202/mlkem_native/mlkem_native_config.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/bring_your_own_fips202_static/expected_test_vectors.h b/examples/bring_your_own_fips202_static/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/bring_your_own_fips202_static/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/bring_your_own_fips202_static/main.c b/examples/bring_your_own_fips202_static/main.c index 9788aa6e53..e0173dd385 100644 --- a/examples/bring_your_own_fips202_static/main.c +++ b/examples/bring_your_own_fips202_static/main.c @@ -6,13 +6,10 @@ #include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - */ +/* Import public mlkem-native API */ #include +#include "expected_test_vectors.h" #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -27,85 +24,81 @@ } \ } while (0) -int main(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_keygen(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key_a[CRYPTO_BYTES]; - uint8_t key_b[CRYPTO_BYTES]; - - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - printf("Generating keypair ... "); - /* Alice generates a public key */ + printf("Generating keypair... "); CHECK(crypto_kem_keypair(pk, sk) == 0); - + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); printf("DONE\n"); - printf("Encaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_keygen(void) +{ + printf("Generating keypair... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Bob derives a secret key and creates a response */ - CHECK(crypto_kem_enc(ct, key_b, pk) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; + printf("Encaps... "); + CHECK(crypto_kem_enc(ct, ss, test_vector_pk) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Decaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_encaps(void) +{ + printf("Encaps... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Alice uses Bobs response to get her shared key */ - CHECK(crypto_kem_dec(key_a, ct, sk) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Compare... "); - - if (memcmp(key_a, key_b, CRYPTO_BYTES)) - { - printf("ERROR: Mismatching keys\n"); - return 1; - } - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_DECAPS_API */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif +int main(void) +{ + int r = 0; - printf("OK\n"); + /* WARNING: Test-only + * Normally, you would seed a PRNG _once_ with trustworthy entropy and not + * reseed it afterwards. Here, we reseed before each API call to make each + * test independent and reproducible even when some API is disabled. */ + randombytes_reset(); + r |= example_keygen(); + randombytes_reset(); + r |= example_encaps(); + r |= example_decaps(); - return 0; + return r; } diff --git a/examples/bring_your_own_fips202_static/mlkem_native/mlkem_native_config.h b/examples/bring_your_own_fips202_static/mlkem_native/mlkem_native_config.h index 85adffa9b8..3d06042518 100644 --- a/examples/bring_your_own_fips202_static/mlkem_native/mlkem_native_config.h +++ b/examples/bring_your_own_fips202_static/mlkem_native/mlkem_native_config.h @@ -116,6 +116,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/custom_backend/expected_test_vectors.h b/examples/custom_backend/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/custom_backend/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/custom_backend/main.c b/examples/custom_backend/main.c index b8c1a5635d..9301ba482f 100644 --- a/examples/custom_backend/main.c +++ b/examples/custom_backend/main.c @@ -6,14 +6,11 @@ #include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - */ +/* Import public mlkem-native API */ #define MLK_CONFIG_NAMESPACE_PREFIX CUSTOM_TINY_SHA3 #include +#include "expected_test_vectors.h" #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -28,85 +25,81 @@ } \ } while (0) -int main(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_keygen(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key_a[CRYPTO_BYTES]; - uint8_t key_b[CRYPTO_BYTES]; - - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - printf("Generating keypair ... "); - /* Alice generates a public key */ + printf("Generating keypair... "); CHECK(crypto_kem_keypair(pk, sk) == 0); - + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); printf("DONE\n"); - printf("Encaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_keygen(void) +{ + printf("Generating keypair... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Bob derives a secret key and creates a response */ - CHECK(crypto_kem_enc(ct, key_b, pk) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; + printf("Encaps... "); + CHECK(crypto_kem_enc(ct, ss, test_vector_pk) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Decaps... "); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_encaps(void) +{ + printf("Encaps... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - /* Alice uses Bobs response to get her shared key */ - CHECK(crypto_kem_dec(key_a, ct, sk) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); printf("DONE\n"); - printf("Compare... "); - - if (memcmp(key_a, key_b, CRYPTO_BYTES)) - { - printf("ERROR: Mismatching keys\n"); - return 1; - } - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); + return 0; +} +#endif /* MLK_CONFIG_NO_DECAPS_API */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, CRYPTO_BYTES) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif +int main(void) +{ + int r = 0; - printf("OK\n"); + /* WARNING: Test-only + * Normally, you would seed a PRNG _once_ with trustworthy entropy and not + * reseed it afterwards. Here, we reseed before each API call to make each + * test independent and reproducible even when some API is disabled. */ + randombytes_reset(); + r |= example_keygen(); + randombytes_reset(); + r |= example_encaps(); + r |= example_decaps(); - return 0; + return r; } diff --git a/examples/custom_backend/mlkem_native/mlkem_native_config.h b/examples/custom_backend/mlkem_native/mlkem_native_config.h index 9598cdc3e0..1718b72929 100644 --- a/examples/custom_backend/mlkem_native/mlkem_native_config.h +++ b/examples/custom_backend/mlkem_native/mlkem_native_config.h @@ -117,6 +117,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/monolithic_build/expected_test_vectors.h b/examples/monolithic_build/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/monolithic_build/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/monolithic_build/main.c b/examples/monolithic_build/main.c index 845eec55f2..e0173dd385 100644 --- a/examples/monolithic_build/main.c +++ b/examples/monolithic_build/main.c @@ -4,17 +4,12 @@ */ #include -#include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - * - * The parameter set is configured on the command line - */ +/* Import public mlkem-native API */ #include + +#include "expected_test_vectors.h" #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -29,79 +24,81 @@ } \ } while (0) -static int test_keys_mlkem(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_keygen(void) { - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM_PUBLICKEYBYTES(MLK_CONFIG_PARAMETER_SET)]; - uint8_t sk[MLKEM_SECRETKEYBYTES(MLK_CONFIG_PARAMETER_SET)]; - uint8_t ct[MLKEM_CIPHERTEXTBYTES(MLK_CONFIG_PARAMETER_SET)]; - uint8_t key_a[MLKEM_BYTES]; - uint8_t key_b[MLKEM_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem_keypair(pk, sk) == 0); + uint8_t pk[CRYPTO_PUBLICKEYBYTES]; + uint8_t sk[CRYPTO_SECRETKEYBYTES]; - /* Bob derives a secret key and creates a response */ - CHECK(mlkem_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem_dec(key_a, ct, sk) == 0); + printf("Generating keypair... "); + CHECK(crypto_kem_keypair(pk, sk) == 0); + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); + printf("DONE\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_keygen(void) +{ + printf("Generating keypair... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - CHECK(memcmp(key_a, key_b, MLKEM_BYTES) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); + printf("Encaps... "); + CHECK(crypto_kem_enc(ct, ss, test_vector_pk) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); + printf("DONE\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_encaps(void) +{ + printf("Encaps... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; - printf("[MLKEM-%d] OK\n", MLK_CONFIG_PARAMETER_SET); + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); + printf("DONE\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); return 0; } +#endif /* MLK_CONFIG_NO_DECAPS_API */ int main(void) { - if (test_keys_mlkem() != 0) - { - return 1; - } + int r = 0; - return 0; + /* WARNING: Test-only + * Normally, you would seed a PRNG _once_ with trustworthy entropy and not + * reseed it afterwards. Here, we reseed before each API call to make each + * test independent and reproducible even when some API is disabled. */ + randombytes_reset(); + r |= example_keygen(); + randombytes_reset(); + r |= example_encaps(); + r |= example_decaps(); + + return r; } diff --git a/examples/monolithic_build/mlkem_native/mlkem_native_config.h b/examples/monolithic_build/mlkem_native/mlkem_native_config.h index 619c176b76..b75ece19e4 100644 --- a/examples/monolithic_build/mlkem_native/mlkem_native_config.h +++ b/examples/monolithic_build/mlkem_native/mlkem_native_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/monolithic_build_multilevel/expected_test_vectors_multilevel.h b/examples/monolithic_build_multilevel/expected_test_vectors_multilevel.h new file mode 120000 index 0000000000..66fc295283 --- /dev/null +++ b/examples/monolithic_build_multilevel/expected_test_vectors_multilevel.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors_multilevel.h \ No newline at end of file diff --git a/examples/monolithic_build_multilevel/main.c b/examples/monolithic_build_multilevel/main.c index ebcc9c0f2f..18ea3881dd 100644 --- a/examples/monolithic_build_multilevel/main.c +++ b/examples/monolithic_build_multilevel/main.c @@ -7,6 +7,7 @@ #include #include +#include "expected_test_vectors_multilevel.h" #include "mlkem_native_all.h" #include "test_only_rng/notrandombytes.h" @@ -22,188 +23,103 @@ } \ } while (0) -static int test_keys_mlkem512(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM512_PUBLICKEYBYTES]; - uint8_t sk[MLKEM512_SECRETKEYBYTES]; - uint8_t ct[MLKEM512_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM512_BYTES]; - uint8_t key_b[MLKEM512_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem512_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem512_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem512_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM512_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +/* Per-level test functions. Each block is guarded by the matching + * reduced-API config so the multilevel example works with any subset + * of enabled APIs. */ + +#define TEST_LEVEL_KEYGEN(LVL) \ + static int example_keygen_##LVL(void) \ + { \ + uint8_t pk[MLKEM##LVL##_PUBLICKEYBYTES]; \ + uint8_t sk[MLKEM##LVL##_SECRETKEYBYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Generating keypair... "); \ + CHECK(mlkem##LVL##_keypair(pk, sk) == 0); \ + CHECK(memcmp(pk, test_vector_pk_##LVL, MLKEM##LVL##_PUBLICKEYBYTES) == 0); \ + CHECK(memcmp(sk, test_vector_sk_##LVL, MLKEM##LVL##_SECRETKEYBYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif - printf("[MLKEM-512] OK\n"); - return 0; -} - -static int test_keys_mlkem768(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM768_PUBLICKEYBYTES]; - uint8_t sk[MLKEM768_SECRETKEYBYTES]; - uint8_t ct[MLKEM768_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM768_BYTES]; - uint8_t key_b[MLKEM768_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem768_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem768_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem768_dec(key_a, ct, sk) == 0); +#define TEST_LEVEL_ENCAPS(LVL) \ + static int example_encaps_##LVL(void) \ + { \ + uint8_t ct[MLKEM##LVL##_CIPHERTEXTBYTES]; \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Encaps... "); \ + CHECK(mlkem##LVL##_enc(ct, ss, test_vector_pk_##LVL) == 0); \ + CHECK(memcmp(ct, test_vector_ct_##LVL, MLKEM##LVL##_CIPHERTEXTBYTES) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - CHECK(memcmp(key_a, key_b, MLKEM768_BYTES) == 0); +#define TEST_LEVEL_DECAPS(LVL) \ + static int example_decaps_##LVL(void) \ + { \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + printf("[MLKEM-" #LVL "] Decaps... "); \ + CHECK(mlkem##LVL##_dec(ss, test_vector_ct_##LVL, test_vector_sk_##LVL) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +#define TEST_LEVEL_SKIP(NAME, LVL, MSG) \ + static int example_##NAME##_##LVL(void) \ + { \ + printf("[MLKEM-" #LVL "] " MSG " SKIPPED\n"); \ + return 0; \ } - printf("\n"); -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_KEYGEN(512) +TEST_LEVEL_KEYGEN(768) +TEST_LEVEL_KEYGEN(1024) +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +TEST_LEVEL_SKIP(keygen, 512, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 768, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 1024, "Generating keypair...") +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ + +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_ENCAPS(512) +TEST_LEVEL_ENCAPS(768) +TEST_LEVEL_ENCAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(encaps, 512, "Encaps...") +TEST_LEVEL_SKIP(encaps, 768, "Encaps...") +TEST_LEVEL_SKIP(encaps, 1024, "Encaps...") #endif - printf("[MLKEM-768] OK\n"); - return 0; -} - - -static int test_keys_mlkem1024(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM1024_PUBLICKEYBYTES]; - uint8_t sk[MLKEM1024_SECRETKEYBYTES]; - uint8_t ct[MLKEM1024_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM1024_BYTES]; - uint8_t key_b[MLKEM1024_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem1024_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem1024_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem1024_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM1024_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +TEST_LEVEL_DECAPS(512) +TEST_LEVEL_DECAPS(768) +TEST_LEVEL_DECAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(decaps, 512, "Decaps...") +TEST_LEVEL_SKIP(decaps, 768, "Decaps...") +TEST_LEVEL_SKIP(decaps, 1024, "Decaps...") #endif - printf("[MLKEM-1024] OK\n"); - return 0; -} - int main(void) { - if (test_keys_mlkem512() != 0) - { - return 1; - } - - if (test_keys_mlkem768() != 0) - { - return 1; - } - - if (test_keys_mlkem1024() != 0) - { - return 1; - } - - return 0; + int r = 0; + r |= example_keygen_512(); + r |= example_encaps_512(); + r |= example_decaps_512(); + r |= example_keygen_768(); + r |= example_encaps_768(); + r |= example_decaps_768(); + r |= example_keygen_1024(); + r |= example_encaps_1024(); + r |= example_decaps_1024(); + return r; } diff --git a/examples/monolithic_build_multilevel/mlkem_native/mlkem_native_config.h b/examples/monolithic_build_multilevel/mlkem_native/mlkem_native_config.h index 6be461e4d6..136a8c134d 100644 --- a/examples/monolithic_build_multilevel/mlkem_native/mlkem_native_config.h +++ b/examples/monolithic_build_multilevel/mlkem_native/mlkem_native_config.h @@ -116,6 +116,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/monolithic_build_multilevel_native/expected_test_vectors_multilevel.h b/examples/monolithic_build_multilevel_native/expected_test_vectors_multilevel.h new file mode 120000 index 0000000000..66fc295283 --- /dev/null +++ b/examples/monolithic_build_multilevel_native/expected_test_vectors_multilevel.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors_multilevel.h \ No newline at end of file diff --git a/examples/monolithic_build_multilevel_native/main.c b/examples/monolithic_build_multilevel_native/main.c index d71a3fa32e..7bce56d8cc 100644 --- a/examples/monolithic_build_multilevel_native/main.c +++ b/examples/monolithic_build_multilevel_native/main.c @@ -11,7 +11,7 @@ #define MLK_CONFIG_CONSTANTS_ONLY #include - +#include "expected_test_vectors_multilevel.h" #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -26,188 +26,103 @@ } \ } while (0) -static int test_keys_mlkem512(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM512_PUBLICKEYBYTES]; - uint8_t sk[MLKEM512_SECRETKEYBYTES]; - uint8_t ct[MLKEM512_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM512_BYTES]; - uint8_t key_b[MLKEM512_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem512_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem512_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem512_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM512_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +/* Per-level test functions. Each block is guarded by the matching + * reduced-API config so the multilevel example works with any subset + * of enabled APIs. */ + +#define TEST_LEVEL_KEYGEN(LVL) \ + static int example_keygen_##LVL(void) \ + { \ + uint8_t pk[MLKEM##LVL##_PUBLICKEYBYTES]; \ + uint8_t sk[MLKEM##LVL##_SECRETKEYBYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Generating keypair... "); \ + CHECK(mlkem##LVL##_keypair(pk, sk) == 0); \ + CHECK(memcmp(pk, test_vector_pk_##LVL, MLKEM##LVL##_PUBLICKEYBYTES) == 0); \ + CHECK(memcmp(sk, test_vector_sk_##LVL, MLKEM##LVL##_SECRETKEYBYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif - - printf("[MLKEM-512] OK\n"); - return 0; -} - -static int test_keys_mlkem768(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM768_PUBLICKEYBYTES]; - uint8_t sk[MLKEM768_SECRETKEYBYTES]; - uint8_t ct[MLKEM768_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM768_BYTES]; - uint8_t key_b[MLKEM768_BYTES]; - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem768_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem768_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem768_dec(key_a, ct, sk) == 0); +#define TEST_LEVEL_ENCAPS(LVL) \ + static int example_encaps_##LVL(void) \ + { \ + uint8_t ct[MLKEM##LVL##_CIPHERTEXTBYTES]; \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Encaps... "); \ + CHECK(mlkem##LVL##_enc(ct, ss, test_vector_pk_##LVL) == 0); \ + CHECK(memcmp(ct, test_vector_ct_##LVL, MLKEM##LVL##_CIPHERTEXTBYTES) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - CHECK(memcmp(key_a, key_b, MLKEM768_BYTES) == 0); +#define TEST_LEVEL_DECAPS(LVL) \ + static int example_decaps_##LVL(void) \ + { \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + printf("[MLKEM-" #LVL "] Decaps... "); \ + CHECK(mlkem##LVL##_dec(ss, test_vector_ct_##LVL, test_vector_sk_##LVL) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +#define TEST_LEVEL_SKIP(NAME, LVL, MSG) \ + static int example_##NAME##_##LVL(void) \ + { \ + printf("[MLKEM-" #LVL "] " MSG " SKIPPED\n"); \ + return 0; \ } - printf("\n"); -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_KEYGEN(512) +TEST_LEVEL_KEYGEN(768) +TEST_LEVEL_KEYGEN(1024) +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +TEST_LEVEL_SKIP(keygen, 512, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 768, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 1024, "Generating keypair...") +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ + +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_ENCAPS(512) +TEST_LEVEL_ENCAPS(768) +TEST_LEVEL_ENCAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(encaps, 512, "Encaps...") +TEST_LEVEL_SKIP(encaps, 768, "Encaps...") +TEST_LEVEL_SKIP(encaps, 1024, "Encaps...") #endif - printf("[MLKEM-768] OK\n"); - return 0; -} - - -static int test_keys_mlkem1024(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM1024_PUBLICKEYBYTES]; - uint8_t sk[MLKEM1024_SECRETKEYBYTES]; - uint8_t ct[MLKEM1024_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM1024_BYTES]; - uint8_t key_b[MLKEM1024_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem1024_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem1024_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem1024_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM1024_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +TEST_LEVEL_DECAPS(512) +TEST_LEVEL_DECAPS(768) +TEST_LEVEL_DECAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(decaps, 512, "Decaps...") +TEST_LEVEL_SKIP(decaps, 768, "Decaps...") +TEST_LEVEL_SKIP(decaps, 1024, "Decaps...") #endif - printf("[MLKEM-1024] OK\n"); - return 0; -} - int main(void) { - if (test_keys_mlkem512() != 0) - { - return 1; - } - - if (test_keys_mlkem768() != 0) - { - return 1; - } - - if (test_keys_mlkem1024() != 0) - { - return 1; - } - - return 0; + int r = 0; + r |= example_keygen_512(); + r |= example_encaps_512(); + r |= example_decaps_512(); + r |= example_keygen_768(); + r |= example_encaps_768(); + r |= example_decaps_768(); + r |= example_keygen_1024(); + r |= example_encaps_1024(); + r |= example_decaps_1024(); + return r; } diff --git a/examples/monolithic_build_multilevel_native/mlkem_native/mlkem_native_config.h b/examples/monolithic_build_multilevel_native/mlkem_native/mlkem_native_config.h index ac478b2bab..bb1396e7c3 100644 --- a/examples/monolithic_build_multilevel_native/mlkem_native/mlkem_native_config.h +++ b/examples/monolithic_build_multilevel_native/mlkem_native/mlkem_native_config.h @@ -120,6 +120,42 @@ */ #define MLK_CONFIG_EXTERNAL_API_QUALIFIER static +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/monolithic_build_native/expected_test_vectors.h b/examples/monolithic_build_native/expected_test_vectors.h new file mode 120000 index 0000000000..5c5d41ccb3 --- /dev/null +++ b/examples/monolithic_build_native/expected_test_vectors.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors.h \ No newline at end of file diff --git a/examples/monolithic_build_native/main.c b/examples/monolithic_build_native/main.c index 527aa4ccab..e0173dd385 100644 --- a/examples/monolithic_build_native/main.c +++ b/examples/monolithic_build_native/main.c @@ -4,18 +4,12 @@ */ #include -#include #include -/* Import public mlkem-native API - * - * This requires specifying the parameter set and namespace prefix - * used for the build. - * - * The parameter set is configured on the command line - */ -#define MLK_CONFIG_NAMESPACE_PREFIX mlkem +/* Import public mlkem-native API */ #include + +#include "expected_test_vectors.h" #include "test_only_rng/notrandombytes.h" #define CHECK(x) \ @@ -30,79 +24,81 @@ } \ } while (0) -static int test_keys_mlkem(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_keygen(void) { - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) -#if MLK_CONFIG_PARAMETER_SET == 512 - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#elif MLK_CONFIG_PARAMETER_SET == 768 - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#elif MLK_CONFIG_PARAMETER_SET == 1024 - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM_PUBLICKEYBYTES(MLK_CONFIG_PARAMETER_SET)]; - uint8_t sk[MLKEM_SECRETKEYBYTES(MLK_CONFIG_PARAMETER_SET)]; - uint8_t ct[MLKEM_CIPHERTEXTBYTES(MLK_CONFIG_PARAMETER_SET)]; - uint8_t key_a[MLKEM_BYTES]; - uint8_t key_b[MLKEM_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem_keypair(pk, sk) == 0); + uint8_t pk[CRYPTO_PUBLICKEYBYTES]; + uint8_t sk[CRYPTO_SECRETKEYBYTES]; - /* Bob derives a secret key and creates a response */ - CHECK(mlkem_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem_dec(key_a, ct, sk) == 0); + printf("Generating keypair... "); + CHECK(crypto_kem_keypair(pk, sk) == 0); + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk, CRYPTO_SECRETKEYBYTES) == 0); + printf("DONE\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_keygen(void) +{ + printf("Generating keypair... SKIPPED (keygen API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ - CHECK(memcmp(key_a, key_b, MLKEM_BYTES) == 0); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int example_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); + printf("Encaps... "); + CHECK(crypto_kem_enc(ct, ss, test_vector_pk) == 0); + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); + printf("DONE\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +static int example_encaps(void) +{ + printf("Encaps... SKIPPED (encaps API disabled)\n"); + return 0; +} +#endif /* !(!MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int example_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; - printf("[MLKEM-%d] OK\n", MLK_CONFIG_PARAMETER_SET); + printf("Decaps... "); + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); + printf("DONE\n"); + return 0; +} +#else /* !MLK_CONFIG_NO_DECAPS_API */ +static int example_decaps(void) +{ + printf("Decaps... SKIPPED (decaps API disabled)\n"); return 0; } +#endif /* MLK_CONFIG_NO_DECAPS_API */ int main(void) { - if (test_keys_mlkem() != 0) - { - return 1; - } + int r = 0; - return 0; + /* WARNING: Test-only + * Normally, you would seed a PRNG _once_ with trustworthy entropy and not + * reseed it afterwards. Here, we reseed before each API call to make each + * test independent and reproducible even when some API is disabled. */ + randombytes_reset(); + r |= example_keygen(); + randombytes_reset(); + r |= example_encaps(); + r |= example_decaps(); + + return r; } diff --git a/examples/monolithic_build_native/mlkem_native/mlkem_native_config.h b/examples/monolithic_build_native/mlkem_native/mlkem_native_config.h index 7b731cd6a1..a702e41ebe 100644 --- a/examples/monolithic_build_native/mlkem_native/mlkem_native_config.h +++ b/examples/monolithic_build_native/mlkem_native/mlkem_native_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/multilevel_build/expected_test_vectors_multilevel.h b/examples/multilevel_build/expected_test_vectors_multilevel.h new file mode 120000 index 0000000000..66fc295283 --- /dev/null +++ b/examples/multilevel_build/expected_test_vectors_multilevel.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors_multilevel.h \ No newline at end of file diff --git a/examples/multilevel_build/main.c b/examples/multilevel_build/main.c index 37e3d2d586..18ea3881dd 100644 --- a/examples/multilevel_build/main.c +++ b/examples/multilevel_build/main.c @@ -7,6 +7,7 @@ #include #include +#include "expected_test_vectors_multilevel.h" #include "mlkem_native_all.h" #include "test_only_rng/notrandombytes.h" @@ -22,187 +23,103 @@ } \ } while (0) -static int test_keys_mlkem512(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM512_PUBLICKEYBYTES]; - uint8_t sk[MLKEM512_SECRETKEYBYTES]; - uint8_t ct[MLKEM512_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM512_BYTES]; - uint8_t key_b[MLKEM512_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem512_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem512_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem512_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM512_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +/* Per-level test functions. Each block is guarded by the matching + * reduced-API config so the multilevel example works with any subset + * of enabled APIs. */ + +#define TEST_LEVEL_KEYGEN(LVL) \ + static int example_keygen_##LVL(void) \ + { \ + uint8_t pk[MLKEM##LVL##_PUBLICKEYBYTES]; \ + uint8_t sk[MLKEM##LVL##_SECRETKEYBYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Generating keypair... "); \ + CHECK(mlkem##LVL##_keypair(pk, sk) == 0); \ + CHECK(memcmp(pk, test_vector_pk_##LVL, MLKEM##LVL##_PUBLICKEYBYTES) == 0); \ + CHECK(memcmp(sk, test_vector_sk_##LVL, MLKEM##LVL##_SECRETKEYBYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif - printf("[MLKEM-512] OK\n"); - return 0; -} - -static int test_keys_mlkem768(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM768_PUBLICKEYBYTES]; - uint8_t sk[MLKEM768_SECRETKEYBYTES]; - uint8_t ct[MLKEM768_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM768_BYTES]; - uint8_t key_b[MLKEM768_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem768_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem768_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem768_dec(key_a, ct, sk) == 0); +#define TEST_LEVEL_ENCAPS(LVL) \ + static int example_encaps_##LVL(void) \ + { \ + uint8_t ct[MLKEM##LVL##_CIPHERTEXTBYTES]; \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Encaps... "); \ + CHECK(mlkem##LVL##_enc(ct, ss, test_vector_pk_##LVL) == 0); \ + CHECK(memcmp(ct, test_vector_ct_##LVL, MLKEM##LVL##_CIPHERTEXTBYTES) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - CHECK(memcmp(key_a, key_b, MLKEM768_BYTES) == 0); +#define TEST_LEVEL_DECAPS(LVL) \ + static int example_decaps_##LVL(void) \ + { \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + printf("[MLKEM-" #LVL "] Decaps... "); \ + CHECK(mlkem##LVL##_dec(ss, test_vector_ct_##LVL, test_vector_sk_##LVL) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +#define TEST_LEVEL_SKIP(NAME, LVL, MSG) \ + static int example_##NAME##_##LVL(void) \ + { \ + printf("[MLKEM-" #LVL "] " MSG " SKIPPED\n"); \ + return 0; \ } - printf("\n"); -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_KEYGEN(512) +TEST_LEVEL_KEYGEN(768) +TEST_LEVEL_KEYGEN(1024) +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +TEST_LEVEL_SKIP(keygen, 512, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 768, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 1024, "Generating keypair...") +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ + +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_ENCAPS(512) +TEST_LEVEL_ENCAPS(768) +TEST_LEVEL_ENCAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(encaps, 512, "Encaps...") +TEST_LEVEL_SKIP(encaps, 768, "Encaps...") +TEST_LEVEL_SKIP(encaps, 1024, "Encaps...") #endif - printf("[MLKEM-768] OK\n"); - return 0; -} - - -static int test_keys_mlkem1024(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - uint8_t pk[MLKEM1024_PUBLICKEYBYTES]; - uint8_t sk[MLKEM1024_SECRETKEYBYTES]; - uint8_t ct[MLKEM1024_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM1024_BYTES]; - uint8_t key_b[MLKEM1024_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem1024_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem1024_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem1024_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM1024_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +TEST_LEVEL_DECAPS(512) +TEST_LEVEL_DECAPS(768) +TEST_LEVEL_DECAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(decaps, 512, "Decaps...") +TEST_LEVEL_SKIP(decaps, 768, "Decaps...") +TEST_LEVEL_SKIP(decaps, 1024, "Decaps...") #endif - printf("[MLKEM-1024] OK\n"); - return 0; -} - int main(void) { - if (test_keys_mlkem512() != 0) - { - return 1; - } - - if (test_keys_mlkem768() != 0) - { - return 1; - } - - if (test_keys_mlkem1024() != 0) - { - return 1; - } - - return 0; + int r = 0; + r |= example_keygen_512(); + r |= example_encaps_512(); + r |= example_decaps_512(); + r |= example_keygen_768(); + r |= example_encaps_768(); + r |= example_decaps_768(); + r |= example_keygen_1024(); + r |= example_encaps_1024(); + r |= example_decaps_1024(); + return r; } diff --git a/examples/multilevel_build/mlkem_native/mlkem_native_config.h b/examples/multilevel_build/mlkem_native/mlkem_native_config.h index d5474ad777..069cf6e6ec 100644 --- a/examples/multilevel_build/mlkem_native/mlkem_native_config.h +++ b/examples/multilevel_build/mlkem_native/mlkem_native_config.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/examples/multilevel_build_native/expected_test_vectors_multilevel.h b/examples/multilevel_build_native/expected_test_vectors_multilevel.h new file mode 120000 index 0000000000..66fc295283 --- /dev/null +++ b/examples/multilevel_build_native/expected_test_vectors_multilevel.h @@ -0,0 +1 @@ +../../test/test_vectors/expected_test_vectors_multilevel.h \ No newline at end of file diff --git a/examples/multilevel_build_native/main.c b/examples/multilevel_build_native/main.c index ebcc9c0f2f..18ea3881dd 100644 --- a/examples/multilevel_build_native/main.c +++ b/examples/multilevel_build_native/main.c @@ -7,6 +7,7 @@ #include #include +#include "expected_test_vectors_multilevel.h" #include "mlkem_native_all.h" #include "test_only_rng/notrandombytes.h" @@ -22,188 +23,103 @@ } \ } while (0) -static int test_keys_mlkem512(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x77, 0x6c, 0x74, 0xdf, 0x30, 0x1f, 0x8d, 0x82, 0x52, 0x5e, 0x8e, - 0xbb, 0xb4, 0x00, 0x95, 0xcd, 0x2e, 0x92, 0xdf, 0x6d, 0xc9, 0x33, - 0xe7, 0x86, 0x62, 0x59, 0xf5, 0x31, 0xc7, 0x35, 0x0a, 0xd5}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM512_PUBLICKEYBYTES]; - uint8_t sk[MLKEM512_SECRETKEYBYTES]; - uint8_t ct[MLKEM512_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM512_BYTES]; - uint8_t key_b[MLKEM512_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem512_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem512_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem512_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM512_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +/* Per-level test functions. Each block is guarded by the matching + * reduced-API config so the multilevel example works with any subset + * of enabled APIs. */ + +#define TEST_LEVEL_KEYGEN(LVL) \ + static int example_keygen_##LVL(void) \ + { \ + uint8_t pk[MLKEM##LVL##_PUBLICKEYBYTES]; \ + uint8_t sk[MLKEM##LVL##_SECRETKEYBYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Generating keypair... "); \ + CHECK(mlkem##LVL##_keypair(pk, sk) == 0); \ + CHECK(memcmp(pk, test_vector_pk_##LVL, MLKEM##LVL##_PUBLICKEYBYTES) == 0); \ + CHECK(memcmp(sk, test_vector_sk_##LVL, MLKEM##LVL##_SECRETKEYBYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); -#else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); -#endif - printf("[MLKEM-512] OK\n"); - return 0; -} - -static int test_keys_mlkem768(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0xe9, 0x13, 0x77, 0x84, 0x0e, 0x6b, 0x66, 0x94, 0xea, 0xa9, 0xf0, - 0x1c, 0x97, 0xff, 0x68, 0x87, 0x4e, 0x8b, 0x0c, 0x52, 0x0b, 0x00, - 0xc2, 0xcd, 0xe3, 0x7c, 0x4f, 0xc2, 0x39, 0x62, 0x6e, 0x70}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM768_PUBLICKEYBYTES]; - uint8_t sk[MLKEM768_SECRETKEYBYTES]; - uint8_t ct[MLKEM768_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM768_BYTES]; - uint8_t key_b[MLKEM768_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem768_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem768_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem768_dec(key_a, ct, sk) == 0); +#define TEST_LEVEL_ENCAPS(LVL) \ + static int example_encaps_##LVL(void) \ + { \ + uint8_t ct[MLKEM##LVL##_CIPHERTEXTBYTES]; \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + randombytes_reset(); \ + printf("[MLKEM-" #LVL "] Encaps... "); \ + CHECK(mlkem##LVL##_enc(ct, ss, test_vector_pk_##LVL) == 0); \ + CHECK(memcmp(ct, test_vector_ct_##LVL, MLKEM##LVL##_CIPHERTEXTBYTES) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - CHECK(memcmp(key_a, key_b, MLKEM768_BYTES) == 0); +#define TEST_LEVEL_DECAPS(LVL) \ + static int example_decaps_##LVL(void) \ + { \ + uint8_t ss[MLKEM##LVL##_BYTES]; \ + \ + printf("[MLKEM-" #LVL "] Decaps... "); \ + CHECK(mlkem##LVL##_dec(ss, test_vector_ct_##LVL, test_vector_sk_##LVL) == \ + 0); \ + CHECK(memcmp(ss, test_vector_ss_##LVL, MLKEM##LVL##_BYTES) == 0); \ + printf("DONE\n"); \ + return 0; \ + } - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } +#define TEST_LEVEL_SKIP(NAME, LVL, MSG) \ + static int example_##NAME##_##LVL(void) \ + { \ + printf("[MLKEM-" #LVL "] " MSG " SKIPPED\n"); \ + return 0; \ } - printf("\n"); -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_KEYGEN(512) +TEST_LEVEL_KEYGEN(768) +TEST_LEVEL_KEYGEN(1024) +#else /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +TEST_LEVEL_SKIP(keygen, 512, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 768, "Generating keypair...") +TEST_LEVEL_SKIP(keygen, 1024, "Generating keypair...") +#endif /* !(!MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API) */ + +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) +TEST_LEVEL_ENCAPS(512) +TEST_LEVEL_ENCAPS(768) +TEST_LEVEL_ENCAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(encaps, 512, "Encaps...") +TEST_LEVEL_SKIP(encaps, 768, "Encaps...") +TEST_LEVEL_SKIP(encaps, 1024, "Encaps...") #endif - printf("[MLKEM-768] OK\n"); - return 0; -} - - -static int test_keys_mlkem1024(void) -{ - /* The PCT modifies the PRNG state, so the KAT tests don't work. - * We run KAT tests only for disabled PCT. */ -#if !defined(MLK_CONFIG_KEYGEN_PCT) - const uint8_t expected_key[] = { - 0x5d, 0x9e, 0x23, 0x5f, 0xcc, 0xb2, 0xb3, 0x49, 0x9a, 0x5f, 0x49, - 0x0a, 0x56, 0xe3, 0xf0, 0xd3, 0xfd, 0x9b, 0x58, 0xbd, 0xa2, 0x8b, - 0x69, 0x0f, 0x91, 0xb5, 0x7b, 0x88, 0xa5, 0xa8, 0x0b, 0x90}; -#endif /* !MLK_CONFIG_KEYGEN_PCT */ - - uint8_t pk[MLKEM1024_PUBLICKEYBYTES]; - uint8_t sk[MLKEM1024_SECRETKEYBYTES]; - uint8_t ct[MLKEM1024_CIPHERTEXTBYTES]; - uint8_t key_a[MLKEM1024_BYTES]; - uint8_t key_b[MLKEM1024_BYTES]; - - /* WARNING: Test-only - * Normally, you would want to seed a PRNG with trustworthy entropy here. */ - randombytes_reset(); - - /* Alice generates a public key */ - CHECK(mlkem1024_keypair(pk, sk) == 0); - - /* Bob derives a secret key and creates a response */ - CHECK(mlkem1024_enc(ct, key_b, pk) == 0); - - /* Alice uses Bobs response to get her shared key */ - CHECK(mlkem1024_dec(key_a, ct, sk) == 0); - - CHECK(memcmp(key_a, key_b, MLKEM1024_BYTES) == 0); - - printf("Shared secret: "); - { - size_t i; - for (i = 0; i < sizeof(key_a); i++) - { - printf("%02x", key_a[i]); - } - } - printf("\n"); - -#if !defined(MLK_CONFIG_KEYGEN_PCT) - /* Check against hardcoded result to make sure that - * we integrated custom FIPS202 correctly */ - CHECK(memcmp(key_a, expected_key, sizeof(key_a)) == 0); +#if !defined(MLK_CONFIG_NO_DECAPS_API) +TEST_LEVEL_DECAPS(512) +TEST_LEVEL_DECAPS(768) +TEST_LEVEL_DECAPS(1024) #else - printf( - "[WARNING] Skipping KAT test since PCT is enabled and modifies PRNG\n"); +TEST_LEVEL_SKIP(decaps, 512, "Decaps...") +TEST_LEVEL_SKIP(decaps, 768, "Decaps...") +TEST_LEVEL_SKIP(decaps, 1024, "Decaps...") #endif - printf("[MLKEM-1024] OK\n"); - return 0; -} - int main(void) { - if (test_keys_mlkem512() != 0) - { - return 1; - } - - if (test_keys_mlkem768() != 0) - { - return 1; - } - - if (test_keys_mlkem1024() != 0) - { - return 1; - } - - return 0; + int r = 0; + r |= example_keygen_512(); + r |= example_encaps_512(); + r |= example_decaps_512(); + r |= example_keygen_768(); + r |= example_encaps_768(); + r |= example_decaps_768(); + r |= example_keygen_1024(); + r |= example_encaps_1024(); + r |= example_decaps_1024(); + return r; } diff --git a/examples/multilevel_build_native/mlkem_native/mlkem_native_config.h b/examples/multilevel_build_native/mlkem_native/mlkem_native_config.h index 2a0467f096..d0bdfb72d1 100644 --- a/examples/multilevel_build_native/mlkem_native/mlkem_native_config.h +++ b/examples/multilevel_build_native/mlkem_native/mlkem_native_config.h @@ -117,6 +117,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/integration/aws-lc/pre_import.patch b/integration/aws-lc/pre_import.patch index c65cec57d5..702f89d405 100644 --- a/integration/aws-lc/pre_import.patch +++ b/integration/aws-lc/pre_import.patch @@ -1,7 +1,26 @@ diff --git a/crypto/fipsmodule/ml_kem/importer.sh b/crypto/fipsmodule/ml_kem/importer.sh --- a/crypto/fipsmodule/ml_kem/importer.sh +++ b/crypto/fipsmodule/ml_kem/importer.sh -@@ -151,6 +151,48 @@ +@@ -134,9 +134,16 @@ + + backend_define=$(if [[ "$file" == *"aarch64"* ]]; then echo "MLK_ARITH_BACKEND_AARCH64"; else echo "MLK_ARITH_BACKEND_X86_64_DEFAULT"; fi) + +- # Flatten multiline preprocessor directives, then process with unifdef ++ # Flatten multiline preprocessor directives, then process with unifdef. ++ # The reduced-API macros (MLK_CONFIG_NO_KEYPAIR_API, MLK_CONFIG_NO_ENCAPS_API ++ # and MLK_CONFIG_NO_DECAPS_API) are never set in the AWS-LC import, so mark ++ # them undefined; otherwise unifdef leaves the enclosing ++ # MLK_ARITH_BACKEND_AARCH64 guard in place, which then evaluates to false (the ++ # include is rewritten to s2n-bignum, so the backend macro is undefined at ++ # build time) and drops the assembly symbol. + sed -e ':a' -e 'N' -e '$!ba' -e 's/\\\n/ /g' "$file" | \ +- unifdef -D$backend_define -UMLK_CONFIG_MULTILEVEL_NO_SHARED -DMLK_CONFIG_MULTILEVEL_WITH_SHARED > "$tmp_file" ++ unifdef -D$backend_define -UMLK_CONFIG_MULTILEVEL_NO_SHARED -DMLK_CONFIG_MULTILEVEL_WITH_SHARED \ ++ -UMLK_CONFIG_NO_KEYPAIR_API -UMLK_CONFIG_NO_ENCAPS_API -UMLK_CONFIG_NO_DECAPS_API > "$tmp_file" + mv "$tmp_file" "$file" + + # Replace common.h include and assembly macros +@@ -151,6 +158,48 @@ fi done diff --git a/mlkem/mlkem_native.h b/mlkem/mlkem_native.h index 9bbb3e2d52..135526deda 100644 --- a/mlkem/mlkem_native.h +++ b/mlkem/mlkem_native.h @@ -191,6 +191,7 @@ extern "C" { #endif +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) /** * Generate a public/private keypair for the ML-KEM key encapsulation mechanism. * @@ -255,7 +256,9 @@ int MLK_API_NAMESPACE(keypair)( #endif ); #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) /** * Generate ciphertext and shared secret for a given public key. * @@ -324,7 +327,9 @@ int MLK_API_NAMESPACE(enc)( #endif ); #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) /** * Generate shared secret for a given ciphertext and private key. * @@ -356,6 +361,7 @@ int MLK_API_NAMESPACE(dec)( MLK_CONFIG_CONTEXT_PARAMETER_TYPE context #endif ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /** @@ -375,6 +381,7 @@ int MLK_API_NAMESPACE(dec)( * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and * MLK_CUSTOM_ALLOC returned NULL. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_API_QUALIFIER MLK_API_MUST_CHECK_RETURN_VALUE int MLK_API_NAMESPACE(check_pk)( @@ -384,6 +391,7 @@ int MLK_API_NAMESPACE(check_pk)( MLK_CONFIG_CONTEXT_PARAMETER_TYPE context #endif ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ /** * Implements public key hash check mandated by FIPS 203, i.e., ensures that @@ -402,6 +410,7 @@ int MLK_API_NAMESPACE(check_pk)( * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and * MLK_CUSTOM_ALLOC returned NULL. */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_API_QUALIFIER MLK_API_MUST_CHECK_RETURN_VALUE int MLK_API_NAMESPACE(check_sk)( @@ -411,6 +420,7 @@ int MLK_API_NAMESPACE(check_sk)( MLK_CONFIG_CONTEXT_PARAMETER_TYPE context #endif ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #ifdef __cplusplus } @@ -427,13 +437,23 @@ int MLK_API_NAMESPACE(check_sk)( #define CRYPTO_SYMBYTES MLKEM_SYMBYTES #define CRYPTO_BYTES MLKEM_BYTES +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) #define crypto_kem_keypair_derand MLK_API_NAMESPACE(keypair_derand) +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) #define crypto_kem_keypair MLK_API_NAMESPACE(keypair) +#endif +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) #define crypto_kem_enc_derand MLK_API_NAMESPACE(enc_derand) +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) #define crypto_kem_enc MLK_API_NAMESPACE(enc) -#define crypto_kem_dec MLK_API_NAMESPACE(dec) +#endif #define crypto_kem_check_pk MLK_API_NAMESPACE(check_pk) +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) +#define crypto_kem_dec MLK_API_NAMESPACE(dec) #define crypto_kem_check_sk MLK_API_NAMESPACE(check_sk) +#endif #else /* !MLK_CONFIG_API_NO_SUPERCOP */ diff --git a/mlkem/mlkem_native_config.h b/mlkem/mlkem_native_config.h index e9e5b12df9..13e401da22 100644 --- a/mlkem/mlkem_native_config.h +++ b/mlkem/mlkem_native_config.h @@ -99,6 +99,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/mlkem/src/common.h b/mlkem/src/common.h index 05d67bc84f..5667ac0cc2 100644 --- a/mlkem/src/common.h +++ b/mlkem/src/common.h @@ -125,6 +125,14 @@ #error Bad configuration: MLK_CONFIG_NO_RANDOMIZED_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_enc() #endif +#if defined(MLK_CONFIG_NO_ENCAPS_API) && defined(MLK_CONFIG_KEYGEN_PCT) +#error Bad configuration: MLK_CONFIG_NO_ENCAPS_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_enc() +#endif + +#if defined(MLK_CONFIG_NO_DECAPS_API) && defined(MLK_CONFIG_KEYGEN_PCT) +#error Bad configuration: MLK_CONFIG_NO_DECAPS_API is incompatible with MLK_CONFIG_KEYGEN_PCT as the current PCT implementation requires crypto_kem_dec() +#endif + #if defined(MLK_CONFIG_USE_NATIVE_BACKEND_ARITH) #include MLK_CONFIG_ARITH_BACKEND_FILE /* Include to enforce consistency of API and implementation, diff --git a/mlkem/src/compress.c b/mlkem/src/compress.c index 874ea1efda..b42c2584fa 100644 --- a/mlkem/src/compress.c +++ b/mlkem/src/compress.c @@ -26,7 +26,10 @@ #include "debug.h" #include "verify.h" -#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) +#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ + (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || \ + MLKEM_K == 3) /* Reference: `poly_compress()` in the reference implementation @[REF], * for ML-KEM-{512,768}. * - In contrast to the reference implementation, we assume @@ -158,6 +161,7 @@ __contract__( mlk_poly_compress_d10_c(r, a); } +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `poly_decompress()` in the reference implementation @[REF], * for ML-KEM-{512,768}. */ MLK_STATIC_TESTABLE void mlk_poly_decompress_d4_c( @@ -268,9 +272,14 @@ __contract__( mlk_poly_decompress_d10_c(r, a); } -#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ - -#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ + +#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ + (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /* Reference: `poly_compress()` in the reference implementation @[REF], * for ML-KEM-1024. * - In contrast to the reference implementation, we assume @@ -409,6 +418,7 @@ __contract__( mlk_poly_compress_d11_c(r, a); } +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `poly_decompress()` in the reference implementation @[REF], * for ML-KEM-1024. */ MLK_STATIC_TESTABLE void mlk_poly_decompress_d5_c( @@ -554,8 +564,11 @@ __contract__( mlk_poly_decompress_d11_c(r, a); } -#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) /* Reference: `poly_tobytes()` in the reference implementation @[REF]. * - In contrast to the reference implementation, we assume * unsigned canonical coefficients here. @@ -620,7 +633,9 @@ void mlk_poly_tobytes(uint8_t r[MLKEM_POLYBYTES], const mlk_poly *a) mlk_poly_tobytes_c(r, a); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `poly_frombytes()` in the reference implementation @[REF]. */ MLK_STATIC_TESTABLE void mlk_poly_frombytes_c(mlk_poly *r, const uint8_t a[MLKEM_POLYBYTES]) @@ -668,7 +683,9 @@ void mlk_poly_frombytes(mlk_poly *r, const uint8_t a[MLKEM_POLYBYTES]) mlk_poly_frombytes_c(r, a); } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `poly_frommsg()` in the reference implementation @[REF]. * - We use a value barrier around the bit-selection mask to * reduce the risk of compiler-introduced branches. @@ -706,7 +723,9 @@ void mlk_poly_frommsg(mlk_poly *r, const uint8_t msg[MLKEM_INDCPA_MSGBYTES]) } mlk_assert_abs_bound(r, MLKEM_N, MLKEM_Q); } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `poly_tomsg()` in the reference implementation @[REF]. * - In contrast to the reference implementation, we assume * unsigned canonical coefficients here. @@ -735,6 +754,7 @@ void mlk_poly_tomsg(uint8_t msg[MLKEM_INDCPA_MSGBYTES], const mlk_poly *r) } } } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */ diff --git a/mlkem/src/compress.h b/mlkem/src/compress.h index f9df8e8d1e..19e1d402b2 100644 --- a/mlkem/src/compress.h +++ b/mlkem/src/compress.h @@ -333,6 +333,7 @@ __contract__( return (int16_t)((((uint32_t)u * MLKEM_Q) + 1024) >> 11); } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) #define mlk_poly_compress_d4 MLK_NAMESPACE(poly_compress_d4) /** @@ -374,6 +375,7 @@ MLK_INTERNAL_API void mlk_poly_compress_d10(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10], const mlk_poly *a); +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_decompress_d4 MLK_NAMESPACE(poly_decompress_d4) /** * De-serialization and subsequent decompression (4 bits) of a polynomial; @@ -419,6 +421,7 @@ void mlk_poly_decompress_d4(mlk_poly *r, MLK_INTERNAL_API void mlk_poly_decompress_d10(mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10]); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 @@ -462,6 +465,7 @@ MLK_INTERNAL_API void mlk_poly_compress_d11(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11], const mlk_poly *a); +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_decompress_d5 MLK_NAMESPACE(poly_decompress_d5) /** * De-serialization and subsequent decompression (5 bits) of a polynomial; @@ -507,8 +511,11 @@ void mlk_poly_decompress_d5(mlk_poly *r, MLK_INTERNAL_API void mlk_poly_decompress_d11(mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11]); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) #define mlk_poly_tobytes MLK_NAMESPACE(poly_tobytes) /** * Serialization of a polynomial. Signed coefficients are converted to @@ -529,8 +536,10 @@ __contract__( requires(array_bound(a->coeffs, 0, MLKEM_N, 0, MLKEM_Q)) assigns(memory_slice(r, MLKEM_POLYBYTES)) ); +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_frombytes MLK_NAMESPACE(poly_frombytes) /** * De-serialization of a polynomial. @@ -550,8 +559,10 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_poly))) ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT)) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_frommsg MLK_NAMESPACE(poly_frommsg) /** * Convert a 32-byte message to a polynomial. @@ -573,7 +584,9 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_poly))) ensures(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q)) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_tomsg MLK_NAMESPACE(poly_tomsg) /** * Convert a polynomial to a 32-byte message. @@ -595,5 +608,6 @@ __contract__( requires(array_bound(r->coeffs, 0, MLKEM_N, 0, MLKEM_Q)) assigns(memory_slice(msg, MLKEM_INDCPA_MSGBYTES)) ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_COMPRESS_H */ diff --git a/mlkem/src/indcpa.c b/mlkem/src/indcpa.c index 50d2b92c0f..98060e3742 100644 --- a/mlkem/src/indcpa.c +++ b/mlkem/src/indcpa.c @@ -55,6 +55,7 @@ * [0,..,MLKEM_Q-1]. * @param[in] seed Input public seed. */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES], const mlk_polyvec *pk, const uint8_t seed[MLKEM_SYMBYTES]) @@ -63,6 +64,7 @@ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES], mlk_polyvec_tobytes(r, pk); mlk_memcpy(r + MLKEM_POLYVECBYTES, seed, MLKEM_SYMBYTES); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** * De-serialize public key from a byte array; approximate inverse of @@ -75,6 +77,7 @@ static void mlk_pack_pk(uint8_t r[MLKEM_INDCPA_PUBLICKEYBYTES], * @param[out] seed Output seed to generate matrix A. * @param[in] packedpk Input serialized public key. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES], const uint8_t packedpk[MLKEM_INDCPA_PUBLICKEYBYTES]) { @@ -86,6 +89,7 @@ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES], * specifications and proofs, however, do _not_ assume this, and instead * work with the easily provable bound by MLKEM_UINT12_LIMIT. */ } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /** * Serialize the secret key. @@ -95,12 +99,14 @@ static void mlk_unpack_pk(mlk_polyvec *pk, uint8_t seed[MLKEM_SYMBYTES], * @param[out] r Output serialized secret key. * @param[in] sk Input vector of polynomials (secret key). */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES], const mlk_polyvec *sk) { mlk_assert_bound_2d(sk->vec, MLKEM_K, MLKEM_N, 0, MLKEM_Q); mlk_polyvec_tobytes(r, sk); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** * De-serialize the secret key; inverse of mlk_pack_sk. @@ -110,11 +116,13 @@ static void mlk_pack_sk(uint8_t r[MLKEM_INDCPA_SECRETKEYBYTES], * @param[out] sk Output vector of polynomials (secret key). * @param[in] packedsk Input serialized secret key. */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) static void mlk_unpack_sk(mlk_polyvec *sk, const uint8_t packedsk[MLKEM_INDCPA_SECRETKEYBYTES]) { mlk_polyvec_frombytes(sk, packedsk); } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /** * Serialize the ciphertext as the concatenation of the compressed and @@ -127,12 +135,14 @@ static void mlk_unpack_sk(mlk_polyvec *sk, * @param[in] b Input vector of polynomials b. * @param[in] v Input polynomial v. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES], const mlk_polyvec *b, mlk_poly *v) { mlk_polyvec_compress_du(r, b); mlk_poly_compress_dv(r + MLKEM_POLYVECCOMPRESSEDBYTES_DU, v); } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /** * De-serialize and decompress ciphertext from a byte array; approximate @@ -144,12 +154,14 @@ static void mlk_pack_ciphertext(uint8_t r[MLKEM_INDCPA_BYTES], * @param[out] v Output polynomial v. * @param[in] c Input serialized ciphertext. */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) static void mlk_unpack_ciphertext(mlk_polyvec *b, mlk_poly *v, const uint8_t c[MLKEM_INDCPA_BYTES]) { mlk_polyvec_decompress_du(b, c); mlk_poly_decompress_dv(v, c + MLKEM_POLYVECCOMPRESSEDBYTES_DU); } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* Helper function to ensure that the polynomial entries in the output * of gen_matrix use the standard (bitreversed) ordering of coefficients. @@ -345,6 +357,7 @@ __contract__( * @param[out] e Output polynomial vector. * @param[in] seed Seed bytes for sampling. */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) static void mlk_keypair_getnoise_eta1(mlk_polyvec *pv, mlk_polyvec *e, const uint8_t seed[MLKEM_SYMBYTES]) __contract__( @@ -378,6 +391,7 @@ __contract__( seed, 4, 5, 6, 7); #endif /* MLKEM_K == 4 */ } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** * Compute and fill the sp, ep, and epp polynomial structures needed by @@ -391,6 +405,7 @@ __contract__( * @param[out] epp Output polynomial. * @param[in] coins Seed bytes for sampling. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) static void mlk_enc_getnoise_eta1_eta2(mlk_polyvec *sp, mlk_polyvec *ep, mlk_poly *epp, const uint8_t coins[MLKEM_SYMBYTES]) @@ -429,6 +444,7 @@ __contract__( mlk_poly_getnoise_eta2(epp, coins, 8); #endif /* MLKEM_K == 4 */ } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /* Reference: `indcpa_keypair_derand()` in the reference implementation @[REF]. @@ -437,6 +453,7 @@ __contract__( * - We use a mulcache to speed up matrix-vector multiplication. * - We include buffer zeroization. */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_INTERNAL_API int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES], uint8_t sk[MLKEM_INDCPA_SECRETKEYBYTES], @@ -508,6 +525,7 @@ int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES], MLK_FREE(buf, uint8_t, 2 * MLKEM_SYMBYTES, context); return ret; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /* Reference: `indcpa_enc()` in the reference implementation @[REF]. * - We use x4-batched versions of `poly_getnoise` to leverage @@ -517,6 +535,7 @@ int mlk_indcpa_keypair_derand(uint8_t pk[MLKEM_INDCPA_PUBLICKEYBYTES], * - We use a mulcache to speed up matrix-vector multiplication. * - We include buffer zeroization. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_INTERNAL_API int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES], const uint8_t m[MLKEM_INDCPA_MSGBYTES], @@ -591,10 +610,12 @@ int mlk_indcpa_enc(uint8_t c[MLKEM_INDCPA_BYTES], MLK_FREE(seed, uint8_t, MLKEM_SYMBYTES, context); return ret; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /* Reference: `indcpa_dec()` in the reference implementation @[REF]. * - We use a mulcache for the scalar product. * - We include buffer zeroization. */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_INTERNAL_API int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES], const uint8_t c[MLKEM_INDCPA_BYTES], @@ -637,6 +658,7 @@ int mlk_indcpa_dec(uint8_t m[MLKEM_INDCPA_MSGBYTES], MLK_FREE(b, mlk_polyvec, 1, context); return ret; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* To facilitate single-compilation-unit (SCU) builds, undefine all macros. * Don't modify by hand -- this is auto-generated by scripts/autogen. */ diff --git a/mlkem/src/indcpa.h b/mlkem/src/indcpa.h index 5fe5e22e90..e50308be35 100644 --- a/mlkem/src/indcpa.h +++ b/mlkem/src/indcpa.h @@ -45,6 +45,7 @@ __contract__( array_bound(a->vec[x].vec[y].coeffs, 0, MLKEM_N, 0, MLKEM_Q)))) ); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) #define mlk_indcpa_keypair_derand \ MLK_NAMESPACE_K(indcpa_keypair_derand) MLK_CONTEXT_PARAMETERS_3 /** @@ -84,7 +85,9 @@ __contract__( return_value == MLK_ERR_OUT_OF_MEMORY || return_value == MLK_ERR_RNG_FAIL) ); +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_indcpa_enc MLK_NAMESPACE_K(indcpa_enc) MLK_CONTEXT_PARAMETERS_4 /** * Encryption function of the CPA-secure public-key encryption scheme @@ -123,7 +126,9 @@ __contract__( ensures(return_value == 0 || return_value == MLK_ERR_FAIL || return_value == MLK_ERR_OUT_OF_MEMORY) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_indcpa_dec MLK_NAMESPACE_K(indcpa_dec) MLK_CONTEXT_PARAMETERS_3 /** * Decryption function of the CPA-secure public-key encryption scheme @@ -159,5 +164,6 @@ __contract__( ensures(return_value == 0 || return_value == MLK_ERR_FAIL || return_value == MLK_ERR_OUT_OF_MEMORY) ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_INDCPA_H */ diff --git a/mlkem/src/kem.c b/mlkem/src/kem.c index 3c82d6df70..1f449c13c1 100644 --- a/mlkem/src/kem.c +++ b/mlkem/src/kem.c @@ -37,6 +37,7 @@ #define mlk_check_pct MLK_ADD_PARAM_SET(mlk_check_pct) MLK_CONTEXT_PARAMETERS_2 /* End of parameter set namespacing */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) /* Reference: Not implemented in the reference implementation @[REF]. */ MLK_EXTERNAL_API MLK_MUST_CHECK_RETURN_VALUE @@ -68,8 +69,10 @@ int mlk_kem_check_pk(const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES], MLK_FREE(p, mlk_polyvec, 1, context); return ret; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: Not implemented in the reference implementation @[REF]. */ MLK_EXTERNAL_API MLK_MUST_CHECK_RETURN_VALUE @@ -113,7 +116,9 @@ int mlk_kem_check_sk(const uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES], MLK_FREE(test, uint8_t, MLKEM_SYMBYTES, context); return ret; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES], uint8_t const sk[MLKEM_INDCCA_SECRETKEYBYTES], @@ -207,6 +212,7 @@ static int mlk_check_pct(uint8_t const pk[MLKEM_INDCCA_PUBLICKEYBYTES], * - We optionally include PCT which is not present in * the reference code. */ MLK_EXTERNAL_API +MLK_MUST_CHECK_RETURN_VALUE int mlk_kem_keypair_derand(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES], uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES], const uint8_t coins[2 * MLKEM_SYMBYTES], @@ -282,7 +288,9 @@ int mlk_kem_keypair(uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES], return ret; } #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) /* Reference: `crypto_kem_enc_derand()` in the reference implementation @[REF] * - We include public key check * - We include stack buffer zeroization */ @@ -368,7 +376,9 @@ int mlk_kem_enc(uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES], return ret; } #endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `crypto_kem_dec()` in the reference implementation @[REF] * - We include secret key check * - We include stack buffer zeroization */ @@ -440,6 +450,7 @@ int mlk_kem_dec(uint8_t ss[MLKEM_SSBYTES], return ret; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* To facilitate single-compilation-unit (SCU) builds, undefine all macros. * Don't modify by hand -- this is auto-generated by scripts/autogen. */ diff --git a/mlkem/src/kem.h b/mlkem/src/kem.h index 5310dc8b4d..f892937d6f 100644 --- a/mlkem/src/kem.h +++ b/mlkem/src/kem.h @@ -46,14 +46,24 @@ #endif /* MLK_CHECK_APIS */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) #define mlk_kem_keypair_derand \ MLK_NAMESPACE_K(keypair_derand) MLK_CONTEXT_PARAMETERS_3 +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) #define mlk_kem_keypair MLK_NAMESPACE_K(keypair) MLK_CONTEXT_PARAMETERS_2 +#endif +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) #define mlk_kem_enc_derand MLK_NAMESPACE_K(enc_derand) MLK_CONTEXT_PARAMETERS_4 +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) #define mlk_kem_enc MLK_NAMESPACE_K(enc) MLK_CONTEXT_PARAMETERS_3 -#define mlk_kem_dec MLK_NAMESPACE_K(dec) MLK_CONTEXT_PARAMETERS_3 +#endif #define mlk_kem_check_pk MLK_NAMESPACE_K(check_pk) MLK_CONTEXT_PARAMETERS_1 +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) +#define mlk_kem_dec MLK_NAMESPACE_K(dec) MLK_CONTEXT_PARAMETERS_3 #define mlk_kem_check_sk MLK_NAMESPACE_K(check_sk) MLK_CONTEXT_PARAMETERS_1 +#endif /** * Implements modulus check mandated by FIPS 203, i.e., ensures that @@ -74,6 +84,7 @@ * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and * MLK_CUSTOM_ALLOC returned NULL. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_EXTERNAL_API MLK_MUST_CHECK_RETURN_VALUE int mlk_kem_check_pk(const uint8_t pk[MLKEM_INDCCA_PUBLICKEYBYTES], @@ -83,6 +94,7 @@ __contract__( ensures(return_value == 0 || return_value == MLK_ERR_FAIL || return_value == MLK_ERR_OUT_OF_MEMORY) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ /** @@ -104,6 +116,7 @@ __contract__( * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and * MLK_CUSTOM_ALLOC returned NULL. */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_EXTERNAL_API MLK_MUST_CHECK_RETURN_VALUE int mlk_kem_check_sk(const uint8_t sk[MLKEM_INDCCA_SECRETKEYBYTES], @@ -113,7 +126,9 @@ __contract__( ensures(return_value == 0 || return_value == MLK_ERR_FAIL || return_value == MLK_ERR_OUT_OF_MEMORY) ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) /** * Generate a public/private keypair for the ML-KEM key encapsulation mechanism. * @@ -151,6 +166,7 @@ __contract__( return_value == MLK_ERR_RNG_FAIL) ); +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) /** * Generate a public/private keypair for the ML-KEM key encapsulation mechanism. * @@ -184,6 +200,8 @@ __contract__( return_value == MLK_ERR_OUT_OF_MEMORY || return_value == MLK_ERR_RNG_FAIL) ); +#endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** * Generate ciphertext and shared secret for a given public key. @@ -208,6 +226,7 @@ __contract__( * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and * MLK_CUSTOM_ALLOC returned NULL. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_EXTERNAL_API MLK_MUST_CHECK_RETURN_VALUE int mlk_kem_enc_derand(uint8_t ct[MLKEM_INDCCA_CIPHERTEXTBYTES], @@ -226,6 +245,7 @@ __contract__( return_value == MLK_ERR_OUT_OF_MEMORY) ); +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) /** * Generate ciphertext and shared secret for a given public key. * @@ -264,6 +284,8 @@ __contract__( return_value == MLK_ERR_OUT_OF_MEMORY || return_value == MLK_ERR_RNG_FAIL) ); +#endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ /** * Generate shared secret for a given ciphertext and private key. @@ -286,6 +308,7 @@ __contract__( * @retval MLK_ERR_OUT_OF_MEMORY MLK_CONFIG_CUSTOM_ALLOC_FREE was used and * MLK_CUSTOM_ALLOC returned NULL. */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_EXTERNAL_API MLK_MUST_CHECK_RETURN_VALUE int mlk_kem_dec(uint8_t ss[MLKEM_SSBYTES], @@ -300,5 +323,6 @@ __contract__( ensures(return_value == 0 || return_value == MLK_ERR_FAIL || return_value == MLK_ERR_OUT_OF_MEMORY) ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_KEM_H */ diff --git a/mlkem/src/native/aarch64/meta.h b/mlkem/src/native/aarch64/meta.h index fb4a7c164b..4729a1d50d 100644 --- a/mlkem/src/native/aarch64/meta.h +++ b/mlkem/src/native/aarch64/meta.h @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) mlk_aarch64_invntt_zetas_layer67); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -60,6 +62,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -70,6 +73,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) mlk_poly_tomont_aarch64_asm(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2], @@ -130,6 +134,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native( } #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], const int16_t a[MLKEM_N]) @@ -141,6 +146,7 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], mlk_poly_tobytes_aarch64_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len, diff --git a/mlkem/src/native/aarch64/src/aarch64_zetas.c b/mlkem/src/native/aarch64/src/aarch64_zetas.c index cc3a48dddf..c743d92f18 100644 --- a/mlkem/src/native/aarch64/src/aarch64_zetas.c +++ b/mlkem/src/native/aarch64/src/aarch64_zetas.c @@ -79,6 +79,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t 10129, 10129, -3878, -3878, -11566, -11566, }; +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t mlk_aarch64_invntt_zetas_layer12345[80] = { 1583, 15582, -821, -8081, 1355, 13338, 0, 0, -569, @@ -138,6 +139,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t 1041, -1637, -1637, -583, -583, -17, -17, 10247, 10247, -16113, -16113, -5739, -5739, -167, -167, }; +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const int16_t mlk_aarch64_zetas_mulcache_native[128] = { diff --git a/mlkem/src/native/aarch64/src/intt_aarch64_asm.S b/mlkem/src/native/aarch64/src/intt_aarch64_asm.S index 2cfc2ee02e..d88cc5f103 100644 --- a/mlkem/src/native/aarch64/src/intt_aarch64_asm.S +++ b/mlkem/src/native/aarch64/src/intt_aarch64_asm.S @@ -51,7 +51,10 @@ */ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) +#if defined(MLK_ARITH_BACKEND_AARCH64) && \ + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /* * WARNING: This file is auto-derived from the mlkem-native source file @@ -624,7 +627,8 @@ Lmlk_intt_layer123_start: MLK_ASM_FN_SIZE(intt_aarch64_asm) -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/aarch64/src/poly_tobytes_aarch64_asm.S b/mlkem/src/native/aarch64/src/poly_tobytes_aarch64_asm.S index 0f5e7a143c..41f720adcb 100644 --- a/mlkem/src/native/aarch64/src/poly_tobytes_aarch64_asm.S +++ b/mlkem/src/native/aarch64/src/poly_tobytes_aarch64_asm.S @@ -28,7 +28,10 @@ */ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) +#if defined(MLK_ARITH_BACKEND_AARCH64) && \ + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) /* * WARNING: This file is auto-derived from the mlkem-native source file @@ -113,7 +116,8 @@ Lmlk_poly_tobytes_loop_start: MLK_ASM_FN_SIZE(poly_tobytes_aarch64_asm) -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + (!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/aarch64/src/poly_tomont_aarch64_asm.S b/mlkem/src/native/aarch64/src/poly_tomont_aarch64_asm.S index 9f37410691..c7b0c21393 100644 --- a/mlkem/src/native/aarch64/src/poly_tomont_aarch64_asm.S +++ b/mlkem/src/native/aarch64/src/poly_tomont_aarch64_asm.S @@ -22,7 +22,9 @@ */ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_AARCH64) && !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) +#if defined(MLK_ARITH_BACKEND_AARCH64) && \ + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /* * WARNING: This file is auto-derived from the mlkem-native source file @@ -92,7 +94,8 @@ Lmlk_poly_tomont_loop: MLK_ASM_FN_SIZE(poly_tomont_aarch64_asm) -#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* MLK_ARITH_BACKEND_AARCH64 && !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ + !MLK_CONFIG_NO_KEYPAIR_API */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/api.h b/mlkem/src/native/api.h index 45f267ea7c..f8578763b6 100644 --- a/mlkem/src/native/api.h +++ b/mlkem/src/native/api.h @@ -144,7 +144,8 @@ __contract__( ensures(array_bound(p, 0, MLKEM_N, 0, MLKEM_Q))); #endif /* MLK_USE_NATIVE_NTT_CUSTOM_ORDER */ -#if defined(MLK_USE_NATIVE_INTT) +#if defined(MLK_USE_NATIVE_INTT) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) /** * Compute the inverse negacyclic number-theoretic transform (NTT) of a * polynomial in place. @@ -168,7 +169,8 @@ __contract__( ensures((return_value == MLK_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(p, 0, MLKEM_N, MLK_INVNTT_BOUND)) ensures((return_value == MLK_NATIVE_FUNC_FALLBACK) ==> array_unchanged(p, MLKEM_N)) ); -#endif /* MLK_USE_NATIVE_INTT */ +#endif /* MLK_USE_NATIVE_INTT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ #if defined(MLK_USE_NATIVE_POLY_REDUCE) /** @@ -191,7 +193,7 @@ __contract__( ); #endif /* MLK_USE_NATIVE_POLY_REDUCE */ -#if defined(MLK_USE_NATIVE_POLY_TOMONT) +#if defined(MLK_USE_NATIVE_POLY_TOMONT) && !defined(MLK_CONFIG_NO_KEYPAIR_API) /** * In-place conversion of all coefficients of a polynomial from the normal * domain to the Montgomery domain. @@ -210,7 +212,7 @@ __contract__( ensures((return_value == MLK_NATIVE_FUNC_SUCCESS) ==> array_abs_bound(p, 0, MLKEM_N, MLKEM_Q)) ensures((return_value == MLK_NATIVE_FUNC_FALLBACK) ==> array_unchanged(p, MLKEM_N)) ); -#endif /* MLK_USE_NATIVE_POLY_TOMONT */ +#endif /* MLK_USE_NATIVE_POLY_TOMONT && !MLK_CONFIG_NO_KEYPAIR_API */ #if defined(MLK_USE_NATIVE_POLY_MULCACHE_COMPUTE) /** @@ -340,7 +342,9 @@ __contract__( #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ #endif /* MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED */ -#if defined(MLK_USE_NATIVE_POLY_TOBYTES) +#if defined(MLK_USE_NATIVE_POLY_TOBYTES) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) /** * Serialization of a polynomial with unsigned canonical coefficients. * @@ -362,9 +366,11 @@ __contract__( assigns(memory_slice(r, MLKEM_POLYBYTES)) ensures(return_value == MLK_NATIVE_FUNC_SUCCESS || return_value == MLK_NATIVE_FUNC_FALLBACK) ); -#endif /* MLK_USE_NATIVE_POLY_TOBYTES */ +#endif /* MLK_USE_NATIVE_POLY_TOBYTES && (!MLK_CONFIG_NO_KEYPAIR_API || \ + !MLK_CONFIG_NO_ENCAPS_API) */ -#if defined(MLK_USE_NATIVE_POLY_FROMBYTES) +#if defined(MLK_USE_NATIVE_POLY_FROMBYTES) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) /** * Deserialization of a polynomial. * @@ -386,7 +392,8 @@ __contract__( ensures(return_value == MLK_NATIVE_FUNC_SUCCESS || return_value == MLK_NATIVE_FUNC_FALLBACK) ensures((return_value == MLK_NATIVE_FUNC_SUCCESS) ==> array_bound(a, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT)) ); -#endif /* MLK_USE_NATIVE_POLY_FROMBYTES */ +#endif /* MLK_USE_NATIVE_POLY_FROMBYTES && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ #if defined(MLK_USE_NATIVE_REJ_UNIFORM) /** @@ -419,6 +426,7 @@ __contract__( ); #endif /* MLK_USE_NATIVE_REJ_UNIFORM */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) #if defined(MLK_USE_NATIVE_POLY_COMPRESS_D4) /** @@ -470,6 +478,7 @@ __contract__( ensures(return_value == MLK_NATIVE_FUNC_SUCCESS || return_value == MLK_NATIVE_FUNC_FALLBACK)); #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D10 */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D4) /** * De-serialization and subsequent decompression (4 bits) of a polynomial; @@ -525,6 +534,7 @@ __contract__( ensures(return_value == MLK_NATIVE_FUNC_SUCCESS || return_value == MLK_NATIVE_FUNC_FALLBACK) ensures((return_value == MLK_NATIVE_FUNC_SUCCESS) ==> array_bound(r, 0, MLKEM_N, 0, MLKEM_Q))); #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D10 */ +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 @@ -578,6 +588,7 @@ __contract__( ensures(return_value == MLK_NATIVE_FUNC_SUCCESS || return_value == MLK_NATIVE_FUNC_FALLBACK)); #endif /* MLK_USE_NATIVE_POLY_COMPRESS_D11 */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D5) /** * De-serialization and subsequent decompression (5 bits) of a polynomial; @@ -633,6 +644,8 @@ __contract__( ensures(return_value == MLK_NATIVE_FUNC_SUCCESS || return_value == MLK_NATIVE_FUNC_FALLBACK) ensures((return_value == MLK_NATIVE_FUNC_SUCCESS) ==> array_bound(r, 0, MLKEM_N, 0, MLKEM_Q))); #endif /* MLK_USE_NATIVE_POLY_DECOMPRESS_D11 */ +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_NATIVE_API_H */ diff --git a/mlkem/src/native/ppc64le/meta.h b/mlkem/src/native/ppc64le/meta.h index 9cd3b66cdd..2f292432df 100644 --- a/mlkem/src/native/ppc64le/meta.h +++ b/mlkem/src/native/ppc64le/meta.h @@ -37,6 +37,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) #endif } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -48,6 +49,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_FALLBACK; #endif } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -61,6 +63,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) #endif } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -72,6 +75,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_FALLBACK; #endif } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ #endif /* !__ASSEMBLER__ */ #endif /* !MLK_NATIVE_PPC64LE_META_H */ diff --git a/mlkem/src/native/ppc64le/src/intt_ppc_asm.S b/mlkem/src/native/ppc64le/src/intt_ppc_asm.S index 3566b7d8cd..bb66f182d7 100644 --- a/mlkem/src/native/ppc64le/src/intt_ppc_asm.S +++ b/mlkem/src/native/ppc64le/src/intt_ppc_asm.S @@ -8,7 +8,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_PPC64LE_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /*yaml Name: intt_ppc_asm Description: PowerPC64 VSX inverse NTT @@ -3236,7 +3238,8 @@ mlk_intt_ppc_asm_Loopf: MLK_ASM_FN_SIZE(intt_ppc_asm) #endif /* MLK_ARITH_BACKEND_PPC64LE_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && __POWER8_VECTOR__ */ + && __POWER8_VECTOR__ && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S b/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S index 4f569f46c3..2f7deb34b3 100644 --- a/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S +++ b/mlkem/src/native/ppc64le/src/poly_tomont_ppc_asm.S @@ -15,7 +15,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_PPC64LE_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && defined(__POWER8_VECTOR__) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /*yaml Name: poly_tomont_ppc_asm Description: PowerPC64 VSX conversion to Montgomery form @@ -308,7 +309,7 @@ MLK_ASM_FN_SYMBOL(poly_tomont_ppc_asm) MLK_ASM_FN_SIZE(poly_tomont_ppc_asm) #endif /* MLK_ARITH_BACKEND_PPC64LE_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && __POWER8_VECTOR__ */ + && __POWER8_VECTOR__ && !MLK_CONFIG_NO_KEYPAIR_API */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/riscv64/meta.h b/mlkem/src/native/riscv64/meta.h index c1d2be4b54..1dc637615b 100644 --- a/mlkem/src/native/riscv64/meta.h +++ b/mlkem/src/native/riscv64/meta.h @@ -40,6 +40,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -52,13 +53,16 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) mlk_rv64v_poly_invntt_tomont(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { mlk_rv64v_poly_tomont(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len, diff --git a/mlkem/src/native/riscv64/src/arith_native_riscv64.h b/mlkem/src/native/riscv64/src/arith_native_riscv64.h index f21b6da0e9..ab97ca9eb2 100644 --- a/mlkem/src/native/riscv64/src/arith_native_riscv64.h +++ b/mlkem/src/native/riscv64/src/arith_native_riscv64.h @@ -10,8 +10,10 @@ #define mlk_rv64v_poly_ntt MLK_NAMESPACE(ntt_riscv64) void mlk_rv64v_poly_ntt(int16_t *); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_rv64v_poly_invntt_tomont MLK_NAMESPACE(intt_riscv64) void mlk_rv64v_poly_invntt_tomont(int16_t *r); +#endif #define mlk_rv64v_poly_basemul_mont_add_k2 MLK_NAMESPACE(basemul_add_k2_riscv64) void mlk_rv64v_poly_basemul_mont_add_k2(int16_t *r, const int16_t *a, @@ -25,8 +27,10 @@ void mlk_rv64v_poly_basemul_mont_add_k3(int16_t *r, const int16_t *a, void mlk_rv64v_poly_basemul_mont_add_k4(int16_t *r, const int16_t *a, const int16_t *b); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) #define mlk_rv64v_poly_tomont MLK_NAMESPACE(tomont_riscv64) void mlk_rv64v_poly_tomont(int16_t *r); +#endif #define mlk_rv64v_poly_reduce MLK_NAMESPACE(reduce_riscv64) void mlk_rv64v_poly_reduce(int16_t *r); diff --git a/mlkem/src/native/riscv64/src/rv64v_poly.c b/mlkem/src/native/riscv64/src/rv64v_poly.c index af529ee170..5a5de392c8 100644 --- a/mlkem/src/native/riscv64/src/rv64v_poly.c +++ b/mlkem/src/native/riscv64/src/rv64v_poly.c @@ -324,6 +324,7 @@ void mlk_rv64v_poly_ntt(int16_t *r) &r[0xe0], mlk_rv64v_ntt2(__riscv_vcreate_v_i16m1_i16m2(ve, vf), ze), vl2); } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /* Reverse / Gentleman-Sande butterfly operation */ #define MLK_RVV_GS_BFLY_RX(u0, u1, ut, uc, vl) \ @@ -604,6 +605,7 @@ void mlk_rv64v_poly_invntt_tomont(int16_t *r) __riscv_vse16_v_i16m1(&r[0xe0], ve, vl); __riscv_vse16_v_i16m1(&r[0xf0], vf, vl); } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /* ML-KEM's middle field GF(3329)[X]/(X^2) multiplication */ @@ -682,6 +684,7 @@ void mlk_rv64v_poly_basemul_mont_add_k4(int16_t *r, const int16_t *a, } #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) /** * In-place conversion of all coefficients of a polynomial from the normal * domain to the Montgomery domain. @@ -700,6 +703,7 @@ void mlk_rv64v_poly_tomont(int16_t *r) __riscv_vse16_v_i16m1(&r[i], vec, vl); } } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** * Apply Barrett reduction to all coefficients of a polynomial. For details diff --git a/mlkem/src/native/x86_64/meta.h b/mlkem/src/native/x86_64/meta.h index e59849ef76..6ddfb63c36 100644 --- a/mlkem/src/native/x86_64/meta.h +++ b/mlkem/src/native/x86_64/meta.h @@ -68,6 +68,7 @@ static MLK_INLINE int mlk_ntt_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) { @@ -79,6 +80,7 @@ static MLK_INLINE int mlk_intt_native(int16_t data[MLKEM_N]) mlk_invntt_avx2_asm(data, mlk_qdata); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) @@ -92,6 +94,7 @@ static MLK_INLINE int mlk_poly_reduce_native(int16_t data[MLKEM_N]) return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) { @@ -103,6 +106,7 @@ static MLK_INLINE int mlk_poly_tomont_native(int16_t data[MLKEM_N]) mlk_tomont_avx2_asm(data); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_mulcache_compute_native(int16_t x[MLKEM_N / 2], @@ -165,6 +169,7 @@ static MLK_INLINE int mlk_polyvec_basemul_acc_montgomery_cached_k4_native( } #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], const int16_t a[MLKEM_N]) @@ -177,7 +182,9 @@ static MLK_INLINE int mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], mlk_ntttobytes_avx2_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_frombytes_native( int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYBYTES]) @@ -190,8 +197,12 @@ static MLK_INLINE int mlk_poly_frombytes_native( mlk_nttfrombytes_avx2_asm(r, a); return MLK_NATIVE_FUNC_SUCCESS; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ -#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) +#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ + (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || \ + MLKEM_K == 3) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_compress_d4_native( uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4], const int16_t a[MLKEM_N]) @@ -218,6 +229,7 @@ static MLK_INLINE int mlk_poly_compress_d10_native( return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_decompress_d4_native( int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4]) @@ -243,9 +255,14 @@ static MLK_INLINE int mlk_poly_decompress_d10_native( mlk_poly_decompress_d10_avx2_asm(r, a, mlk_decompress_d10_data); return MLK_NATIVE_FUNC_SUCCESS; } -#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ - -#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ + +#if (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ + (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_compress_d5_native( uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5], const int16_t a[MLKEM_N]) @@ -272,6 +289,7 @@ static MLK_INLINE int mlk_poly_compress_d11_native( return MLK_NATIVE_FUNC_SUCCESS; } +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_MUST_CHECK_RETURN_VALUE static MLK_INLINE int mlk_poly_decompress_d5_native( int16_t r[MLKEM_N], const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5]) @@ -297,7 +315,9 @@ static MLK_INLINE int mlk_poly_decompress_d11_native( mlk_poly_decompress_d11_avx2_asm(r, a, mlk_decompress_d11_data); return MLK_NATIVE_FUNC_SUCCESS; } -#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#endif /* (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ #endif /* !__ASSEMBLER__ */ diff --git a/mlkem/src/native/x86_64/src/compress_consts.c b/mlkem/src/native/x86_64/src/compress_consts.c index 91fd4d1920..1645fca573 100644 --- a/mlkem/src/native/x86_64/src/compress_consts.c +++ b/mlkem/src/native/x86_64/src/compress_consts.c @@ -11,7 +11,8 @@ #include "../../../common.h" -#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) +#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) #include "compress_consts.h" @@ -25,11 +26,13 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 2, 0, 0, 0, 6, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0, /* permdidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d4_data[32] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, /* shufbidx */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_compress_d10_data[32] = { @@ -38,11 +41,13 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 255, 255, 255, 255, 0, 1, 2, 3, 4, 8, /* shufbidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d10_data[32] = { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 2, 3, 3, 4, 4, 5, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, /* shufbidx */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ @@ -58,6 +63,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 1, 2, 3, 4, 255, 255, 255, 255, 255, 8, /* shufbidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* shufbidx[0:32], mask[32:64], shift[64:96] */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d5_data[96] = { @@ -68,6 +74,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 0, 4, 32, 0, 0, 1, 8, 0, 64, 0, 0, 2, 16, 0, 128, 0, 0, 4, 32, 0, 0, 1, 8, 0, 64, 0, 0, 2, 16, 0, 128, 0, /* shift */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* srlvqidx[0:32], shufbidx[32:64] */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t @@ -81,6 +88,7 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 255, 255, 255, 255, 0, 0, 1, 2, 3, 4, /* shufbidx */ }; +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* shufbidx[0:32], srlvdidx[32:64], srlvqidx[64:96], shift[96:128] */ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t mlk_decompress_d11_data[128] = { @@ -93,12 +101,15 @@ MLK_ALIGN MLK_INTERNAL_DATA_DEFINITION const uint8_t 32, 0, 4, 0, 1, 0, 32, 0, 8, 0, 1, 0, 32, 0, 4, 0, 32, 0, 4, 0, 1, 0, 32, 0, 8, 0, 1, 0, 32, 0, 4, 0, /* shift */ }; +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_CONFIG_MULTILEVEL_NO_SHARED && \ (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ -#else /* MLK_ARITH_BACKEND_X86_64_DEFAULT */ +#else /* MLK_ARITH_BACKEND_X86_64_DEFAULT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ MLK_EMPTY_CU(avx2_compress_consts) -#endif /* !MLK_ARITH_BACKEND_X86_64_DEFAULT */ +#endif /* !(MLK_ARITH_BACKEND_X86_64_DEFAULT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API)) */ diff --git a/mlkem/src/native/x86_64/src/compress_consts.h b/mlkem/src/native/x86_64/src/compress_consts.h index d8da95fc2b..79182b0052 100644 --- a/mlkem/src/native/x86_64/src/compress_consts.h +++ b/mlkem/src/native/x86_64/src/compress_consts.h @@ -19,26 +19,34 @@ #define mlk_compress_d4_data MLK_NAMESPACE(compress_d4_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d4_data[32]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d4_data MLK_NAMESPACE(decompress_d4_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d4_data[32]; +#endif #define mlk_compress_d10_data MLK_NAMESPACE(compress_d10_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d10_data[32]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d10_data MLK_NAMESPACE(decompress_d10_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d10_data[32]; +#endif #define mlk_compress_d5_data MLK_NAMESPACE(compress_d5_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d5_data[32]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d5_data MLK_NAMESPACE(decompress_d5_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d5_data[96]; +#endif #define mlk_compress_d11_data MLK_NAMESPACE(compress_d11_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_compress_d11_data[64]; +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_decompress_d11_data MLK_NAMESPACE(decompress_d11_data) MLK_INTERNAL_DATA_DECLARATION const uint8_t mlk_decompress_d11_data[128]; +#endif #endif /* !__ASSEMBLER__ */ diff --git a/mlkem/src/native/x86_64/src/intt_avx2_asm.S b/mlkem/src/native/x86_64/src/intt_avx2_asm.S index 9c572f5f1c..d562bd245f 100644 --- a/mlkem/src/native/x86_64/src/intt_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/intt_avx2_asm.S @@ -30,7 +30,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /*yaml Name: invntt_avx2_asm Description: x86_64 AVX2 inverse NTT @@ -734,7 +736,7 @@ MLK_ASM_FN_SYMBOL(invntt_avx2_asm) MLK_ASM_FN_SIZE(invntt_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/nttfrombytes_avx2_asm.S b/mlkem/src/native/x86_64/src/nttfrombytes_avx2_asm.S index 3d833973e7..6b828773a0 100644 --- a/mlkem/src/native/x86_64/src/nttfrombytes_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/nttfrombytes_avx2_asm.S @@ -20,7 +20,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) /*yaml Name: nttfrombytes_avx2_asm Description: x86_64 AVX2 polynomial deserialization in NTT domain @@ -208,7 +210,7 @@ MLK_ASM_FN_SYMBOL(nttfrombytes_avx2_asm) MLK_ASM_FN_SIZE(nttfrombytes_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/ntttobytes_avx2_asm.S b/mlkem/src/native/x86_64/src/ntttobytes_avx2_asm.S index 1415d4439d..6c24096758 100644 --- a/mlkem/src/native/x86_64/src/ntttobytes_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/ntttobytes_avx2_asm.S @@ -20,7 +20,9 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) /*yaml Name: ntttobytes_avx2_asm Description: x86_64 AVX2 polynomial serialization in NTT domain @@ -196,7 +198,7 @@ MLK_ASM_FN_SYMBOL(ntttobytes_avx2_asm) MLK_ASM_FN_SIZE(ntttobytes_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && (!MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_compress_d10_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_compress_d10_avx2_asm.S index 4994ecc5e2..8fbf5dd693 100644 --- a/mlkem/src/native/x86_64/src/poly_compress_d10_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_compress_d10_avx2_asm.S @@ -31,6 +31,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_compress_d10_avx2_asm @@ -402,8 +404,9 @@ MLK_ASM_FN_SYMBOL(poly_compress_d10_avx2_asm) MLK_ASM_FN_SIZE(poly_compress_d10_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_compress_d11_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_compress_d11_avx2_asm.S index adcab50c26..d287fc80bd 100644 --- a/mlkem/src/native/x86_64/src/poly_compress_d11_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_compress_d11_avx2_asm.S @@ -33,6 +33,8 @@ #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_compress_d11_avx2_asm @@ -469,7 +471,8 @@ MLK_ASM_FN_SYMBOL(poly_compress_d11_avx2_asm) MLK_ASM_FN_SIZE(poly_compress_d11_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_compress_d4_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_compress_d4_avx2_asm.S index 3105ad04d6..dbaa5bc23f 100644 --- a/mlkem/src/native/x86_64/src/poly_compress_d4_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_compress_d4_avx2_asm.S @@ -31,6 +31,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_compress_d4_avx2_asm @@ -183,8 +185,9 @@ MLK_ASM_FN_SYMBOL(poly_compress_d4_avx2_asm) MLK_ASM_FN_SIZE(poly_compress_d4_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3) \ + */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_compress_d5_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_compress_d5_avx2_asm.S index 87fdf39ed5..4cf95c553c 100644 --- a/mlkem/src/native/x86_64/src/poly_compress_d5_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_compress_d5_avx2_asm.S @@ -31,6 +31,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API)) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_compress_d5_avx2_asm @@ -241,7 +243,8 @@ MLK_ASM_FN_SYMBOL(poly_compress_d5_avx2_asm) MLK_ASM_FN_SIZE(poly_compress_d5_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API) && \ + (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_decompress_d10_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_decompress_d10_avx2_asm.S index 3974a227b8..d8eb1d232b 100644 --- a/mlkem/src/native/x86_64/src/poly_decompress_d10_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_decompress_d10_avx2_asm.S @@ -31,6 +31,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_decompress_d10_avx2_asm @@ -248,8 +249,8 @@ MLK_ASM_FN_SYMBOL(poly_decompress_d10_avx2_asm) MLK_ASM_FN_SIZE(poly_decompress_d10_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 2 || MLKEM_K == 3) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_decompress_d11_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_decompress_d11_avx2_asm.S index 48cb02e7c8..27f9570e5a 100644 --- a/mlkem/src/native/x86_64/src/poly_decompress_d11_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_decompress_d11_avx2_asm.S @@ -33,6 +33,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_decompress_d11_avx2_asm @@ -298,7 +299,8 @@ MLK_ASM_FN_SYMBOL(poly_decompress_d11_avx2_asm) MLK_ASM_FN_SIZE(poly_decompress_d11_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 4) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_decompress_d4_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_decompress_d4_avx2_asm.S index 0aeec7d10c..973f30b8ce 100644 --- a/mlkem/src/native/x86_64/src/poly_decompress_d4_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_decompress_d4_avx2_asm.S @@ -31,6 +31,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 || MLKEM_K == 3) /*yaml Name: poly_decompress_d4_avx2_asm @@ -200,8 +201,8 @@ MLK_ASM_FN_SYMBOL(poly_decompress_d4_avx2_asm) MLK_ASM_FN_SIZE(poly_decompress_d4_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == \ - 3) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 2 || MLKEM_K == 3) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/poly_decompress_d5_avx2_asm.S b/mlkem/src/native/x86_64/src/poly_decompress_d5_avx2_asm.S index 7f4406e4d5..b545d99b44 100644 --- a/mlkem/src/native/x86_64/src/poly_decompress_d5_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/poly_decompress_d5_avx2_asm.S @@ -32,6 +32,7 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ (defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4) /*yaml Name: poly_decompress_d5_avx2_asm @@ -213,7 +214,8 @@ MLK_ASM_FN_SYMBOL(poly_decompress_d5_avx2_asm) MLK_ASM_FN_SIZE(poly_decompress_d5_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4) */ + && !MLK_CONFIG_NO_DECAPS_API && (MLK_CONFIG_MULTILEVEL_WITH_SHARED || \ + MLKEM_K == 4) */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/native/x86_64/src/tomont_avx2_asm.S b/mlkem/src/native/x86_64/src/tomont_avx2_asm.S index 04d090c9e1..97e139ba7a 100644 --- a/mlkem/src/native/x86_64/src/tomont_avx2_asm.S +++ b/mlkem/src/native/x86_64/src/tomont_avx2_asm.S @@ -24,7 +24,8 @@ #include "../../../common.h" #if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \ - !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) + !defined(MLK_CONFIG_MULTILEVEL_NO_SHARED) && \ + !defined(MLK_CONFIG_NO_KEYPAIR_API) /*yaml Name: tomont_avx2_asm Description: x86_64 AVX2 Montgomery conversion @@ -164,7 +165,7 @@ MLK_ASM_FN_SYMBOL(tomont_avx2_asm) MLK_ASM_FN_SIZE(tomont_avx2_asm) #endif /* MLK_ARITH_BACKEND_X86_64_DEFAULT && !MLK_CONFIG_MULTILEVEL_NO_SHARED \ - */ + && !MLK_CONFIG_NO_KEYPAIR_API */ #if defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/mlkem/src/poly.c b/mlkem/src/poly.c index 3a25fdfe9d..edc17a2b18 100644 --- a/mlkem/src/poly.c +++ b/mlkem/src/poly.c @@ -105,6 +105,7 @@ __contract__( return res; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) /* Reference: `poly_tomont()` in the reference implementation @[REF]. */ MLK_STATIC_TESTABLE void mlk_poly_tomont_c(mlk_poly *r) __contract__( @@ -142,6 +143,7 @@ void mlk_poly_tomont(mlk_poly *r) mlk_poly_tomont_c(r); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** * Constant-time conversion of signed representatives modulo MLKEM_Q within @@ -241,6 +243,7 @@ void mlk_poly_add(mlk_poly *r, const mlk_poly *b) } } +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `poly_sub()` in the reference implementation @[REF]. * - We use destructive version (output=first input) to avoid * reasoning about aliasing in the CBMC specification */ @@ -259,6 +262,7 @@ void mlk_poly_sub(mlk_poly *r, const mlk_poly *b) r->coeffs[i] = (int16_t)(r->coeffs[i] - b->coeffs[i]); } } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #include "zetas.inc" @@ -470,6 +474,7 @@ void mlk_poly_ntt(mlk_poly *r) } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /* Compute one layer of inverse NTT */ /* Reference: Embedded into `invntt()` in the reference implementation @[REF] */ @@ -568,8 +573,8 @@ void mlk_poly_invntt_tomont(mlk_poly *r) mlk_poly_invntt_tomont_c(r); } - -#else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */ +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#else /* !MLK_CONFIG_MULTILEVEL_NO_SHARED */ MLK_EMPTY_CU(mlk_poly) diff --git a/mlkem/src/poly.h b/mlkem/src/poly.h index 4d9e0f8244..3def4394f1 100644 --- a/mlkem/src/poly.h +++ b/mlkem/src/poly.h @@ -99,6 +99,7 @@ __contract__( return (int16_t)r; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) #define mlk_poly_tomont MLK_NAMESPACE(poly_tomont) /** * In-place conversion of all coefficients of a polynomial from the normal @@ -119,6 +120,7 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_poly))) ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLKEM_Q)) ); +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ #define mlk_poly_mulcache_compute MLK_NAMESPACE(poly_mulcache_compute) /** @@ -207,6 +209,7 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_poly))) ); +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_sub MLK_NAMESPACE(poly_sub) /** * Subtract two polynomials; no modular reduction is performed. @@ -231,6 +234,7 @@ __contract__( ensures(forall(k, 0, MLKEM_N, r->coeffs[k] == old(*r).coeffs[k] - b->coeffs[k])) assigns(memory_slice(r, sizeof(mlk_poly))) ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #define mlk_poly_ntt MLK_NAMESPACE(poly_ntt) /** @@ -260,6 +264,7 @@ __contract__( ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLK_NTT_BOUND)) ); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_invntt_tomont MLK_NAMESPACE(poly_invntt_tomont) /** * Compute the inverse negacyclic number-theoretic transform (NTT) of a @@ -286,5 +291,6 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_poly))) ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLK_INVNTT_BOUND)) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ #endif /* !MLK_POLY_H */ diff --git a/mlkem/src/poly_k.c b/mlkem/src/poly_k.c index 99636b846f..60380e34f3 100644 --- a/mlkem/src/poly_k.c +++ b/mlkem/src/poly_k.c @@ -39,6 +39,7 @@ MLK_ADD_PARAM_SET(mlk_polyvec_basemul_acc_montgomery_cached_c) /* End of parameter set namespacing */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `polyvec_compress()` in the reference implementation @[REF] * - In contrast to the reference implementation, we assume * unsigned canonical coefficients here. @@ -56,7 +57,9 @@ void mlk_polyvec_compress_du(uint8_t r[MLKEM_POLYVECCOMPRESSEDBYTES_DU], mlk_poly_compress_du(r + i * MLKEM_POLYCOMPRESSEDBYTES_DU, &a->vec[i]); } } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `polyvec_decompress()` in the reference implementation @[REF]. */ MLK_INTERNAL_API void mlk_polyvec_decompress_du(mlk_polyvec *r, @@ -70,7 +73,9 @@ void mlk_polyvec_decompress_du(mlk_polyvec *r, mlk_assert_bound_2d(r->vec, MLKEM_K, MLKEM_N, 0, MLKEM_Q); } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) /* Reference: `polyvec_tobytes()` in the reference implementation @[REF]. * - In contrast to the reference implementation, we assume * unsigned canonical coefficients here. @@ -92,7 +97,9 @@ void mlk_polyvec_tobytes(uint8_t r[MLKEM_POLYVECBYTES], const mlk_polyvec *a) mlk_poly_tobytes(&r[i * MLKEM_POLYBYTES], &a->vec[i]); } } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /* Reference: `polyvec_frombytes()` in the reference implementation @[REF]. */ MLK_INTERNAL_API void mlk_polyvec_frombytes(mlk_polyvec *r, const uint8_t a[MLKEM_POLYVECBYTES]) @@ -105,6 +112,7 @@ void mlk_polyvec_frombytes(mlk_polyvec *r, const uint8_t a[MLKEM_POLYVECBYTES]) mlk_assert_bound_2d(r->vec, MLKEM_K, MLKEM_N, 0, MLKEM_UINT12_LIMIT); } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /* Reference: `polyvec_ntt()` in the reference implementation @[REF]. */ MLK_INTERNAL_API @@ -124,6 +132,7 @@ void mlk_polyvec_ntt(mlk_polyvec *r) * while the reference implementation normalizes at * the end. This allows us to drop a call to `poly_reduce()` * from the base multiplication. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) MLK_INTERNAL_API void mlk_polyvec_invntt_tomont(mlk_polyvec *r) { @@ -135,6 +144,7 @@ void mlk_polyvec_invntt_tomont(mlk_polyvec *r) mlk_assert_abs_bound_2d(r->vec, MLKEM_K, MLKEM_N, MLK_INVNTT_BOUND); } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ /* Reference: `polyvec_basemul_acc_montgomery()` in the * reference implementation @[REF]. @@ -279,6 +289,7 @@ void mlk_polyvec_add(mlk_polyvec *r, const mlk_polyvec *b) } } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) /* Reference: `polyvec_tomont()` in the reference implementation @[REF]. */ MLK_INTERNAL_API void mlk_polyvec_tomont(mlk_polyvec *r) @@ -291,6 +302,7 @@ void mlk_polyvec_tomont(mlk_polyvec *r) mlk_assert_abs_bound_2d(r->vec, MLKEM_K, MLKEM_N, MLKEM_Q); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ /** @@ -325,6 +337,9 @@ __contract__( #endif } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + (MLKEM_ETA1 == MLKEM_ETA2 && (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API))) /* Reference: Does not exist in the reference implementation @[REF]. * - This implements a x4-batched version of `poly_getnoise_eta1()` * from the reference implementation, to leverage @@ -378,8 +393,11 @@ void mlk_poly_getnoise_eta1_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2, mlk_zeroize(buf, sizeof(buf)); mlk_zeroize(extkey, sizeof(extkey)); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || (MLKEM_ETA1 == MLKEM_ETA2 && \ + (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API)) */ -#if MLKEM_K == 2 || MLKEM_K == 4 +#if (MLKEM_K == 2 || MLKEM_K == 4) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) /** * Given an array of uniformly random bytes, compute a polynomial with * coefficients distributed according to a centered binomial distribution @@ -431,9 +449,11 @@ void mlk_poly_getnoise_eta2(mlk_poly *r, const uint8_t seed[MLKEM_SYMBYTES], mlk_zeroize(buf, sizeof(buf)); mlk_zeroize(extkey, sizeof(extkey)); } -#endif /* MLKEM_K == 2 || MLKEM_K == 4 */ +#endif /* (MLKEM_K == 2 || MLKEM_K == 4) && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ -#if MLKEM_K == 2 +#if MLKEM_K == 2 && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) /* Reference: Does not exist in the reference implementation @[REF]. * - This implements a x4-batched version of `poly_getnoise_eta1()` * and `poly_getnoise_eta2()` from the reference implementation, @@ -492,7 +512,8 @@ void mlk_poly_getnoise_eta1122_4x(mlk_poly *r0, mlk_poly *r1, mlk_poly *r2, mlk_zeroize(buf, sizeof(buf)); mlk_zeroize(extkey, sizeof(extkey)); } -#endif /* MLKEM_K == 2 */ +#endif /* MLKEM_K == 2 && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ /* To facilitate single-compilation-unit (SCU) builds, undefine all macros. * Don't modify by hand -- this is auto-generated by scripts/autogen. */ diff --git a/mlkem/src/poly_k.h b/mlkem/src/poly_k.h index e72432ae7f..1eba9fea67 100644 --- a/mlkem/src/poly_k.h +++ b/mlkem/src/poly_k.h @@ -46,6 +46,7 @@ typedef struct mlk_poly_mulcache vec[MLKEM_K]; /**< Per-component caches. */ } MLK_ALIGN mlk_polyvec_mulcache; +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_compress_du MLK_NAMESPACE_K(poly_compress_du) /** * Compression (du bits) and subsequent serialization of a polynomial. @@ -75,7 +76,9 @@ __contract__( #error "Invalid value of MLKEM_DU" #endif } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_decompress_du MLK_NAMESPACE_K(poly_decompress_du) /** * De-serialization and subsequent decompression (du bits) of a polynomial; @@ -108,7 +111,9 @@ __contract__( #error "Invalid value of MLKEM_DU" #endif } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_compress_dv MLK_NAMESPACE_K(poly_compress_dv) /** * Compression (dv bits) and subsequent serialization of a polynomial. @@ -138,8 +143,10 @@ __contract__( #error "Invalid value of MLKEM_DV" #endif } +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_decompress_dv MLK_NAMESPACE_K(poly_decompress_dv) /** * De-serialization and subsequent decompression (dv bits) of a polynomial; @@ -172,7 +179,9 @@ __contract__( #error "Invalid value of MLKEM_DV" #endif } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_polyvec_compress_du MLK_NAMESPACE_K(polyvec_compress_du) /** * Compress and serialize a vector of polynomials. @@ -196,7 +205,9 @@ __contract__( array_bound(a->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_Q))) assigns(memory_slice(r, MLKEM_POLYVECCOMPRESSEDBYTES_DU)) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_polyvec_decompress_du MLK_NAMESPACE_K(polyvec_decompress_du) /** * De-serialize and decompress a vector of polynomials; approximate inverse @@ -221,7 +232,9 @@ __contract__( ensures(forall(k0, 0, MLKEM_K, array_bound(r->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_Q))) ); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) #define mlk_polyvec_tobytes MLK_NAMESPACE_K(polyvec_tobytes) /** * Serialize a vector of polynomials. @@ -243,7 +256,9 @@ __contract__( array_bound(a->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_Q))) assigns(memory_slice(r, MLKEM_POLYVECBYTES)) ); +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_polyvec_frombytes MLK_NAMESPACE_K(polyvec_frombytes) /** * De-serialize a vector of polynomials; inverse of mlk_polyvec_tobytes. @@ -265,6 +280,7 @@ __contract__( ensures(forall(k0, 0, MLKEM_K, array_bound(r->vec[k0].coeffs, 0, MLKEM_N, 0, MLKEM_UINT12_LIMIT))) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ #define mlk_polyvec_ntt MLK_NAMESPACE_K(polyvec_ntt) /** @@ -292,6 +308,7 @@ __contract__( array_abs_bound(r->vec[j].coeffs, 0, MLKEM_N, MLK_NTT_BOUND))) ); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_polyvec_invntt_tomont MLK_NAMESPACE_K(polyvec_invntt_tomont) /** * Apply inverse NTT to all elements of a vector of polynomials and multiply @@ -316,6 +333,7 @@ __contract__( ensures(forall(j, 0, MLKEM_K, array_abs_bound(r->vec[j].coeffs, 0, MLKEM_N, MLK_INVNTT_BOUND))) ); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ #define mlk_polyvec_basemul_acc_montgomery_cached \ MLK_NAMESPACE_K(polyvec_basemul_acc_montgomery_cached) @@ -442,6 +460,7 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_polyvec))) ); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) #define mlk_polyvec_tomont MLK_NAMESPACE_K(polyvec_tomont) /** * In-place conversion of all coefficients of a polynomial vector from the @@ -463,7 +482,11 @@ __contract__( ensures(forall(j, 0, MLKEM_K, array_abs_bound(r->vec[j].coeffs, 0, MLKEM_N, MLKEM_Q))) ); +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + (MLKEM_ETA1 == MLKEM_ETA2 && (!defined(MLK_CONFIG_NO_ENCAPS_API) || \ + !defined(MLK_CONFIG_NO_DECAPS_API))) #define mlk_poly_getnoise_eta1_4x MLK_NAMESPACE_K(poly_getnoise_eta1_4x) /** * Batch sample four polynomials deterministically from a seed and nonces, @@ -515,8 +538,11 @@ __contract__( */ #define mlk_poly_getnoise_eta2_4x mlk_poly_getnoise_eta1_4x #endif /* MLKEM_ETA1 == MLKEM_ETA2 */ +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || (MLKEM_ETA1 == MLKEM_ETA2 && \ + (!MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API)) */ -#if MLKEM_K == 2 || MLKEM_K == 4 +#if (MLKEM_K == 2 || MLKEM_K == 4) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) #define mlk_poly_getnoise_eta2 MLK_NAMESPACE_K(poly_getnoise_eta2) /** * Sample a polynomial deterministically from a seed and a nonce, with @@ -541,9 +567,11 @@ __contract__( assigns(memory_slice(r, sizeof(mlk_poly))) ensures(array_abs_bound(r->coeffs, 0, MLKEM_N, MLKEM_ETA2 + 1)) ); -#endif /* MLKEM_K == 2 || MLKEM_K == 4 */ +#endif /* (MLKEM_K == 2 || MLKEM_K == 4) && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ -#if MLKEM_K == 2 +#if MLKEM_K == 2 && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) #define mlk_poly_getnoise_eta1122_4x MLK_NAMESPACE_K(poly_getnoise_eta1122_4x) /** * Batch sample four polynomials deterministically from a seed and nonces, @@ -588,6 +616,7 @@ __contract__( && array_abs_bound(r2->coeffs,0, MLKEM_N, MLKEM_ETA2 + 1) && array_abs_bound(r3->coeffs,0, MLKEM_N, MLKEM_ETA2 + 1)) ); -#endif /* MLKEM_K == 2 */ +#endif /* MLKEM_K == 2 && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ #endif /* !MLK_POLY_K_H */ diff --git a/mlkem/src/sampling.c b/mlkem/src/sampling.c index b6b9ff07c3..b01ac5619e 100644 --- a/mlkem/src/sampling.c +++ b/mlkem/src/sampling.c @@ -251,6 +251,8 @@ void mlk_poly_rej_uniform(mlk_poly *entry, uint8_t seed[MLKEM_SYMBYTES + 2]) mlk_zeroize(buf, sizeof(buf)); } +#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 2 || \ + !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) /** * Load 4 bytes into a 32-bit integer in little-endian order. * @@ -300,6 +302,8 @@ void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4]) } } } +#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_ETA1 == 2 || \ + !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 3 /** diff --git a/mlkem/src/sampling.h b/mlkem/src/sampling.h index be3b35142d..24462aeb03 100644 --- a/mlkem/src/sampling.h +++ b/mlkem/src/sampling.h @@ -19,6 +19,8 @@ #include "common.h" #include "poly.h" +#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 2 || \ + !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define mlk_poly_cbd2 MLK_NAMESPACE(poly_cbd2) /** * Given an array of uniformly random bytes, compute a polynomial with @@ -32,6 +34,8 @@ */ MLK_INTERNAL_API void mlk_poly_cbd2(mlk_poly *r, const uint8_t buf[2 * MLKEM_N / 4]); +#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_ETA1 == 2 || \ + !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_ETA1 == 3 #define mlk_poly_cbd3 MLK_NAMESPACE(poly_cbd3) diff --git a/nix/avr/default.nix b/nix/avr/default.nix index 714de72149..66333e12a5 100644 --- a/nix/avr/default.nix +++ b/nix/avr/default.nix @@ -7,9 +7,9 @@ let # Patched simavr with increased RAM and fixed UART output simavr-patched = pkgs.simavr.overrideAttrs (oldAttrs: { patches = (oldAttrs.patches or [ ]) ++ [ - ./simavr-32kb-ram.patch + ./simavr-64kb-ram.patch ./simavr-uart-output-fix.patch - ./simavr-16k-eeprom.patch + ./simavr-32k-eeprom.patch # Exit-code commands (SIMAVR_CMD_EXIT_CODE_*), not yet in a release (pkgs.fetchpatch { url = "https://github.com/buserror/simavr/commit/c9354b32e057e409c2fbc9454e26db3b3103c26a.patch"; diff --git a/nix/avr/simavr-16k-eeprom.patch b/nix/avr/simavr-32k-eeprom.patch similarity index 87% rename from nix/avr/simavr-16k-eeprom.patch rename to nix/avr/simavr-32k-eeprom.patch index a0cbfc1a8c..d0590d79c1 100644 --- a/nix/avr/simavr-16k-eeprom.patch +++ b/nix/avr/simavr-32k-eeprom.patch @@ -6,4 +6,4 @@ index 1234567..abcdefg 100644 +++ b/simavr/cores/avr/iom128rfr2.h @@ -1,1 +1,1 @@ -#define E2END (0xFFF) -+#define E2END (0x3FFF) ++#define E2END (0x7FFF) diff --git a/nix/avr/simavr-32kb-ram.patch b/nix/avr/simavr-64kb-ram.patch similarity index 84% rename from nix/avr/simavr-32kb-ram.patch rename to nix/avr/simavr-64kb-ram.patch index 580dc8a4d2..47c26a32fb 100644 --- a/nix/avr/simavr-32kb-ram.patch +++ b/nix/avr/simavr-64kb-ram.patch @@ -8,8 +8,8 @@ #define RAMSTART (0x200) -#define RAMSIZE (0x4000) -#define RAMEND (0x41FF) -+#define RAMSIZE (0x8000) -+#define RAMEND (0x81FF) ++#define RAMSIZE (0xFE00) ++#define RAMEND (0xFFFF) #define XRAMSTART (0x0000) #define XRAMSIZE (0x0000) #define XRAMEND RAMEND diff --git a/proofs/cbmc/mlkem_native_config_cbmc.h b/proofs/cbmc/mlkem_native_config_cbmc.h index e7272221d1..c923b6538e 100644 --- a/proofs/cbmc/mlkem_native_config_cbmc.h +++ b/proofs/cbmc/mlkem_native_config_cbmc.h @@ -116,6 +116,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/scripts/autogen b/scripts/autogen index b5bdc64cce..2f59695830 100755 --- a/scripts/autogen +++ b/scripts/autogen @@ -1060,6 +1060,8 @@ def gen_aarch64_zeta_file(): gen_aarch64_fwd_ntt_zetas_layer67(), ) yield "" + yield "#if !defined(MLK_CONFIG_NO_ENCAPS_API) || \\" + yield " !defined(MLK_CONFIG_NO_DECAPS_API)" yield from emit_c_array( "const int16_t", "mlk_aarch64_invntt_zetas_layer12345", @@ -1071,6 +1073,7 @@ def gen_aarch64_zeta_file(): "mlk_aarch64_invntt_zetas_layer67", gen_aarch64_inv_ntt_zetas_layer67(), ) + yield "#endif" yield "" yield from emit_c_array( "const int16_t", @@ -1627,7 +1630,9 @@ def gen_avx2_compress_consts_file(): yield from gen_header() yield '#include "../../../common.h"' yield "" - yield "#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT)" + yield "#if defined(MLK_ARITH_BACKEND_X86_64_DEFAULT) && \\" + yield " (!defined(MLK_CONFIG_NO_ENCAPS_API) || \\" + yield " !defined(MLK_CONFIG_NO_DECAPS_API))" yield "" yield '#include "compress_consts.h"' yield "" @@ -1638,7 +1643,11 @@ def gen_avx2_compress_consts_file(): yield "" for name, (sections, dtype, layout, level) in consts.items(): if level == "d4_d10": + if name.startswith("decompress_"): + yield "#if !defined(MLK_CONFIG_NO_DECAPS_API)" yield from gen_const_def(name, sections, dtype, layout) + if name.startswith("decompress_"): + yield "#endif" yield "" yield "#endif /* d4/d10 constants */" yield "" @@ -1649,7 +1658,11 @@ def gen_avx2_compress_consts_file(): yield "" for name, (sections, dtype, layout, level) in consts.items(): if level == "d5_d11": + if name.startswith("decompress_"): + yield "#if !defined(MLK_CONFIG_NO_DECAPS_API)" yield from gen_const_def(name, sections, dtype, layout) + if name.startswith("decompress_"): + yield "#endif" yield "" yield "#endif /* d5/d11 constants */" yield "" @@ -1674,8 +1687,12 @@ def gen_avx2_compress_consts_file(): # Declare all constants for name, (sections, dtype, layout, level) in consts.items(): total_size = sum(len(vals) for _, vals in sections) + if name.startswith("decompress_"): + yield "#if !defined(MLK_CONFIG_NO_DECAPS_API)" yield f"#define mlk_{name} MLK_NAMESPACE({name})" yield emit_c_array_decl(f"const {dtype}", f"mlk_{name}", total_size) + if name.startswith("decompress_"): + yield "#endif" yield "" yield "#endif /* !__ASSEMBLER__ */" @@ -4588,6 +4605,209 @@ def gen_test_config(config_path, config_spec, default_config_content): update_file(config_path, content) +def gen_test_vectors(): + """Generate expected test vectors using ACVP binaries and notrandombytes. + + Randomness for keygen (z, d) and encapsulation (m) is drawn from + notrandombytes (using the default pi-based seed) so that the vectors + are reproducible from a Python-only invocation. + """ + nrb_script = os.path.join(os.path.dirname(__file__), "notrandombytes") + + def notrandombytes(num_bytes): + result = subprocess.run( + [sys.executable, nrb_script, str(num_bytes)], + capture_output=True, + encoding="utf-8", + ) + if result.returncode != 0: + raise RuntimeError(f"notrandombytes failed: {result.stderr}") + return result.stdout.strip().upper() + + def run_acvp(lvl, *args): + acvp_bin = f"./test/build/mlkem{lvl}/bin/acvp_mlkem{lvl}" + if not os.path.isfile(acvp_bin): + console.print( + f"[red]Error:[/] ACVP binary not found: {acvp_bin}\n" + f"Build it first: [bold]make acvp OPT=0[/]" + ) + sys.exit(1) + result = subprocess.run( + [acvp_bin, *args], + capture_output=True, + encoding="utf-8", + ) + if result.returncode != 0: + raise RuntimeError( + f"acvp_mlkem{lvl} {' '.join(args)} failed: {result.stderr}" + ) + out = {} + for line in result.stdout.splitlines(): + k, v = line.split("=", 1) + out[k] = v + return out + + levels = [512, 768, 1024] + + # Each API is exercised independently: the example resets the PRNG + # before invoking each API, so `d, z` are the first 64 bytes of a fresh + # notrandombytes stream (as consumed by crypto_kem_keypair) and `m` is + # the first 32 bytes of a fresh stream (as consumed by crypto_kem_enc). + # + # Order within the keypair pair matters: crypto_kem_keypair reads + # randombytes into `coins[64]` which is then interpreted as `d || z` by + # crypto_kem_keypair_derand, so `d` must be the first 32 bytes. + keygen_rnd = notrandombytes(64) + d = keygen_rnd[:64] + z = keygen_rnd[64:128] + m = notrandombytes(32) + + results = {} + for lvl in levels: + keygen_out = run_acvp(lvl, "keyGen", "AFT", f"z={z}", f"d={d}") + + encap_out = run_acvp( + lvl, + "encapDecap", + "AFT", + "encapsulation", + f"ek={keygen_out['ek']}", + f"m={m}", + ) + + results[lvl] = { + "pk": keygen_out["ek"], + "sk": keygen_out["dk"], + "ct": encap_out["c"], + "ss": encap_out["k"], + } + + def hex_to_c_array(hex_str, indent=" "): + """Convert hex string to C array initializer with 12 bytes per line.""" + raw = bytes.fromhex(hex_str) + lines = [] + for i in range(0, len(raw), 12): + chunk = raw[i : i + 12] + elems = ", ".join(f"0x{b:02x}" for b in chunk) + lines.append(f"{indent}{elems},") + # Remove trailing comma from last line + if lines: + lines[-1] = lines[-1].rstrip(",") + return "\n".join(lines) + + def hex_len(hex_str): + return len(hex_str) // 2 + + def gen_seed_defines(): + yield "/* keygen d (first 32 bytes of a fresh notrandombytes stream) */" + yield f"static const uint8_t test_vector_d[{hex_len(d)}] = {{" + yield hex_to_c_array(d) + yield "};" + yield "/* keygen z (next 32 bytes of the same stream) */" + yield f"static const uint8_t test_vector_z[{hex_len(z)}] = {{" + yield hex_to_c_array(z) + yield "};" + yield "/* encaps m (first 32 bytes of a fresh notrandombytes stream) */" + yield f"static const uint8_t test_vector_m[{hex_len(m)}] = {{" + yield hex_to_c_array(m) + yield "};" + + def gen_description(): + yield "/*" + yield " * Generated with:" + yield " * d, z: consecutive 32-byte draws from a fresh notrandombytes" + yield " * stream (as consumed by crypto_kem_keypair)." + yield " * m: first 32-byte draw from a second, fresh" + yield " * notrandombytes stream (as consumed by crypto_kem_enc" + yield " * after randombytes_reset())." + yield " */" + + # Generate expected_test_vectors.h (single-level, with #if guards) + def gen_single(): + yield from gen_header() + yield from gen_description() + yield "" + yield "#ifndef EXPECTED_TEST_VECTORS_H" + yield "#define EXPECTED_TEST_VECTORS_H" + yield "" + yield "#include " + yield "" + yield from gen_seed_defines() + yield "" + + first = True + for lvl in levels: + r = results[lvl] + directive = "#if" if first else "#elif" + yield f"{directive} MLK_CONFIG_PARAMETER_SET == {lvl}" + yield f"static const uint8_t test_vector_pk[{hex_len(r['pk'])}] = {{" + yield hex_to_c_array(r["pk"]) + yield "};" + yield f"static const uint8_t test_vector_sk[{hex_len(r['sk'])}] = {{" + yield hex_to_c_array(r["sk"]) + yield "};" + yield f"static const uint8_t test_vector_ct[{hex_len(r['ct'])}] = {{" + yield hex_to_c_array(r["ct"]) + yield "};" + yield f"static const uint8_t test_vector_ss[{hex_len(r['ss'])}] = {{" + yield hex_to_c_array(r["ss"]) + yield "};" + first = False + + yield f"#endif /* MLK_CONFIG_PARAMETER_SET == {levels[-1]} */" + yield "" + yield "#endif /* !EXPECTED_TEST_VECTORS_H */" + yield "" + + update_file( + "test/test_vectors/expected_test_vectors.h", + "\n".join(gen_single()), + ) + + # Generate expected_test_vectors_multilevel.h (all levels, suffixed names) + def gen_multi(): + yield from gen_header() + yield "/*" + yield " * Expected test vectors for multilevel builds." + yield " * Generated with per-level array names." + yield " */" + yield "" + yield from gen_description() + yield "" + yield "#ifndef EXPECTED_TEST_VECTORS_MULTILEVEL_H" + yield "#define EXPECTED_TEST_VECTORS_MULTILEVEL_H" + yield "" + yield "#include " + yield "" + yield from gen_seed_defines() + yield "" + + for lvl in levels: + r = results[lvl] + yield f"/* ML-KEM-{lvl} */" + yield f"static const uint8_t test_vector_pk_{lvl}[{hex_len(r['pk'])}] = {{" + yield hex_to_c_array(r["pk"]) + yield "};" + yield f"static const uint8_t test_vector_sk_{lvl}[{hex_len(r['sk'])}] = {{" + yield hex_to_c_array(r["sk"]) + yield "};" + yield f"static const uint8_t test_vector_ct_{lvl}[{hex_len(r['ct'])}] = {{" + yield hex_to_c_array(r["ct"]) + yield "};" + yield f"static const uint8_t test_vector_ss_{lvl}[{hex_len(r['ss'])}] = {{" + yield hex_to_c_array(r["ss"]) + yield "};" + yield "" + + yield "#endif /* !EXPECTED_TEST_VECTORS_MULTILEVEL_H */" + yield "" + + update_file( + "test/test_vectors/expected_test_vectors_multilevel.h", + "\n".join(gen_multi()), + ) + + def gen_test_configs(): """Generate all test configuration files from metadata.""" # Load metadata @@ -5296,6 +5516,15 @@ def _main(): metavar="FLAGS", help="Extra CFLAGS prepended to ppc64le simpasm invocations", ) + parser.add_argument( + "--test-vectors", + default=False, + action="store_true", + help="Regenerate test/test_vectors/expected_test_vectors*.h " + "using ACVP binaries and scripts/notrandombytes. " + "Requires ACVP binaries to be built first " + "(e.g. `make acvp OPT=0`).", + ) args = parser.parse_args() @@ -5390,10 +5619,25 @@ def _main(): ("Check macro typos", check_macro_typos), ("Generate ABI checker tests", gen_abicheck), ("Generate preprocessor comments", gen_preprocessor_comments), + ( + "Generate expected test vectors", + gen_test_vectors, + args.test_vectors, + ), # Formatting should be the last step ("Format files", lambda: format_files(args.dry_run)), ] + # When --test-vectors is set, only run test vector generation + formatting + if args.test_vectors: + steps = [ + ( + "Generate expected test vectors", + gen_test_vectors, + ), + ("Format files", lambda: format_files(args.dry_run)), + ] + global _progress, _main_task with Progress( BarColumn(), diff --git a/scripts/notrandombytes b/scripts/notrandombytes new file mode 100755 index 0000000000..2bcd2b1670 --- /dev/null +++ b/scripts/notrandombytes @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# +# Copyright (c) The mlkem-native project authors +# SPDX-License-Identifier: LicenseRef-PD-hp OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT + +# References +# ========== +# +# - [surf] +# SURF: Simple Unpredictable Random Function +# Daniel J. Bernstein +# https://cr.yp.to/papers.html#surf + +# Based on @[surf]. + +# WARNING +# +# The randombytes() implementation in this file is for TESTING ONLY. +# You MUST NOT use this implementation outside of testing. + +import sys + +MASK32 = 0xFFFFFFFF + +seed = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, + 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5] + +state_in = [0] * 12 +out = [0] * 8 +outleft = 0 + + +def randombytes_reset(): + global state_in, out, outleft + state_in = [0] * 12 + out = [0] * 8 + outleft = 0 + + +def _rotate(x, b): + return ((x << b) | (x >> (32 - b))) & MASK32 + + +def _surf(): + global out + t = [(state_in[i] ^ seed[12 + i]) & MASK32 for i in range(12)] + out = [seed[24 + i] for i in range(8)] + x = t[11] + sum_val = 0 + for _ in range(2): + for _ in range(16): + sum_val = (sum_val + 0x9E3779B9) & MASK32 + for i, b in [(0, 5), (1, 7), (2, 9), (3, 13), + (4, 5), (5, 7), (6, 9), (7, 13), + (8, 5), (9, 7), (10, 9), (11, 13)]: + val = (((x ^ seed[i]) + sum_val) & MASK32) ^ _rotate(x, b) + t[i] = (t[i] + val) & MASK32 + x = t[i] + for i in range(8): + out[i] = (out[i] ^ t[i + 4]) & MASK32 + + +def randombytes(n): + global outleft + buf = [] + for _ in range(n): + if not outleft: + state_in[0] = (state_in[0] + 1) & MASK32 + if state_in[0] == 0: + state_in[1] = (state_in[1] + 1) & MASK32 + if state_in[1] == 0: + state_in[2] = (state_in[2] + 1) & MASK32 + if state_in[2] == 0: + state_in[3] = (state_in[3] + 1) & MASK32 + _surf() + outleft = 8 + outleft -= 1 + buf.append(out[outleft] & 0xFF) + return bytes(buf) + + +if __name__ == "__main__": + num_bytes = int(sys.argv[1]) if len(sys.argv) > 1 else 128 + print(randombytes(num_bytes).hex()) diff --git a/scripts/stack b/scripts/stack index 1af1b1797f..8be1269176 100755 --- a/scripts/stack +++ b/scripts/stack @@ -10,6 +10,8 @@ import subprocess import sys import tempfile +API_NAMES = ["keygen", "encaps", "decaps"] + def parse_su_files(build_dir): """Parse GCC stack usage (.su) files""" @@ -52,7 +54,27 @@ def parse_su_files(build_dir): return stack_usage -def run_valgrind_massif_per_api(stack_test_binary, dump_massif=False): +def detect_supported_apis(stack_test_binary): + """Ask the stack test binary which API modes are compiled in.""" + result = subprocess.run( + [stack_test_binary, "--info"], capture_output=True, text=True, timeout=30 + ) + if result.returncode != 0: + return ( + False, + f"Failed to query supported APIs (return code {result.returncode}): " + f"{result.stderr}", + ) + + reported = {line.strip() for line in result.stdout.splitlines() if line.strip()} + unknown = reported - set(API_NAMES) + if unknown: + return False, f"Stack test binary reported unknown API modes: {sorted(unknown)}" + + return True, [api_name for api_name in API_NAMES if api_name in reported] + + +def run_valgrind_massif_per_api(stack_test_binary, supported_apis, dump_massif=False): """Run valgrind massif with API-level stack analysis using dedicated test binary""" # Determine parameter set from binary path if "test_stack512" in stack_test_binary: @@ -68,17 +90,16 @@ def run_valgrind_massif_per_api(stack_test_binary, dump_massif=False): ) api_results = {} - api_names = ["keygen", "encaps", "decaps"] - api_display_names = [ - f"ML-KEM{param_set}-KeyGen", - f"ML-KEM{param_set}-Encaps", - f"ML-KEM{param_set}-Decaps", - ] + api_display_names = { + "keygen": f"ML-KEM{param_set}-KeyGen", + "encaps": f"ML-KEM{param_set}-Encaps", + "decaps": f"ML-KEM{param_set}-Decaps", + } with tempfile.NamedTemporaryFile(mode="w+", suffix=".massif") as temp_file: massif_output = temp_file.name - for api_name in api_names: + for api_name in supported_apis: cmd = [ "valgrind", "--tool=massif", @@ -123,9 +144,9 @@ def run_valgrind_massif_per_api(stack_test_binary, dump_massif=False): # Format results result_lines = [] - for i, api_name in enumerate(api_names): + for api_name in supported_apis: stack_usage = api_results[api_name] - display_name = api_display_names[i] + display_name = api_display_names[api_name] if stack_usage > 0: result_lines.append(f" {display_name:20}: {stack_usage:,} bytes") else: @@ -145,13 +166,24 @@ def run_valgrind_massif_per_api(stack_test_binary, dump_massif=False): def run_runtime_analysis(binary_path, dump_massif=False): """Run runtime stack analysis""" + success, supported_apis = detect_supported_apis(binary_path) + if not success: + return False, supported_apis + + if not supported_apis: + return True, "No stack-test APIs are enabled in this build" + try: - # Test the stack test binary with keygen argument - test_result = subprocess.run( - [binary_path, "keygen"], capture_output=True, text=True, timeout=30 - ) - if test_result.returncode != 0: - return False, f"Stack test binary execution failed: {test_result.stderr}" + for api_name in supported_apis: + test_result = subprocess.run( + [binary_path, api_name], capture_output=True, text=True, timeout=30 + ) + if test_result.returncode != 0: + return ( + False, + f"Stack test binary execution failed for {api_name}: " + f"{test_result.stderr}", + ) except subprocess.TimeoutExpired: return False, "Binary execution timeout" except Exception as e: @@ -161,16 +193,20 @@ def run_runtime_analysis(binary_path, dump_massif=False): if platform.system() == "Linux": try: subprocess.run(["valgrind", "--version"], capture_output=True, check=True) - return run_valgrind_massif_per_api(binary_path, dump_massif) + return run_valgrind_massif_per_api(binary_path, supported_apis, dump_massif) except (subprocess.CalledProcessError, FileNotFoundError): return ( True, - "Binary executed successfully (valgrind not available for runtime analysis)", + "Enabled APIs executed successfully " + f"({', '.join(supported_apis)}); " + "valgrind not available for runtime analysis", ) else: return ( True, - "Binary executed successfully (detailed runtime stack analysis requires valgrind on Linux)", + "Enabled APIs executed successfully " + f"({', '.join(supported_apis)}); " + "detailed runtime stack analysis requires valgrind on Linux", ) diff --git a/test/acvp/acvp_client.py b/test/acvp/acvp_client.py index 0c31b3a10a..d6ff0f66b0 100755 --- a/test/acvp/acvp_client.py +++ b/test/acvp/acvp_client.py @@ -74,24 +74,127 @@ def loadAcvpData(prompt, expectedResults): return (prompt, promptData, expectedResults, expectedResultsData) -def loadDefaultAcvpData(version): +ALL_ACVP_FUNCTIONS = { + "keyGen", + "encapsulation", + "encapsulationKeyCheck", + "decapsulation", + "decapsulationKeyCheck", +} + + +def detect_supported_functions(): + """Run acvp_mlkem512 --info to detect which ACVP functions are supported.""" + acvp_bin = "./test/build/mlkem512/bin/acvp_mlkem512" + acvp_call = exec_prefix + [acvp_bin, "--info"] + try: + result = subprocess.run(acvp_call, encoding="utf-8", capture_output=True) + if result.returncode != 0: + err( + f"Warning: {acvp_call} failed (rc={result.returncode}), assuming all functions supported" + ) + return set(ALL_ACVP_FUNCTIONS) + functions = set() + for line in result.stdout.splitlines(): + line = line.strip() + if line in ALL_ACVP_FUNCTIONS: + functions.add(line) + return functions + except FileNotFoundError: + err(f"Warning: {acvp_bin} not found, assuming all functions supported") + return set(ALL_ACVP_FUNCTIONS) + + +ENCAP_DECAP_FUNCTIONS = { + "encapsulation", + "encapsulationKeyCheck", + "decapsulation", + "decapsulationKeyCheck", +} + + +def loadDefaultAcvpData(version, supported_functions=None): + if supported_functions is None: + supported_functions = set(ALL_ACVP_FUNCTIONS) + + # Load a prompt whenever any of its sub-functions is compiled in. + # Unsupported sub-functions are filtered out per test case (see + # filter_test_cases) so result comparison stays byte-identical. + keyGen_any = "keyGen" in supported_functions + encapDecap_any = bool(ENCAP_DECAP_FUNCTIONS & supported_functions) + data_dir = f"test/acvp/.acvp-data/{version}/files" acvp_jsons_for_version = [ ( + "keyGen", + keyGen_any, f"{data_dir}/ML-KEM-keyGen-FIPS203/prompt.json", f"{data_dir}/ML-KEM-keyGen-FIPS203/expectedResults.json", ), ( + "encapDecap", + encapDecap_any, f"{data_dir}/ML-KEM-encapDecap-FIPS203/prompt.json", f"{data_dir}/ML-KEM-encapDecap-FIPS203/expectedResults.json", ), ] acvp_data = [] - for prompt, expectedResults in acvp_jsons_for_version: + for mode, is_supported, prompt, expectedResults in acvp_jsons_for_version: + if not is_supported: + warn( + f"WARNING: Skipped {mode} ACVP prompt " + f"(no sub-function supported by this build)." + ) + continue acvp_data.append(loadAcvpData(prompt, expectedResults)) return acvp_data +def unwrap_acvts(data): + # ACVTS files wrap the payload as [{"acvVersion": ...}, {...}]. + return data[1] if isinstance(data, list) else data + + +def filter_test_cases(acvp_data, should_drop): + """Drop cases for which should_drop(tg, tc) returns a reason (None keeps). + Reasons are computed from the prompt but applied consistently to both + prompt and expected data, so downstream byte-identical result comparison + still works. Returns the list of drop reasons for reporting.""" + reasons = [] + for _, promptData, _, expectedData in acvp_data: + drop = {} + for tg in unwrap_acvts(promptData).get("testGroups", []): + for tc in tg["tests"]: + reason = should_drop(tg, tc) + if reason is not None: + drop[tg["tgId"], tc["tcId"]] = reason + for data in (promptData, expectedData): + if data is None: + continue + for tg in unwrap_acvts(data).get("testGroups", []): + tg["tests"] = [ + tc for tc in tg["tests"] if (tg["tgId"], tc["tcId"]) not in drop + ] + reasons += drop.values() + return reasons + + +def unsupported_function(supported_functions): + """Return a should_drop predicate that skips encapDecap test cases whose + tg['function'] is not in supported_functions. keyGen prompts have no + tg['function'] field, so they are never dropped by this predicate. + The predicate returns the bare function name so the caller can format + a compact 'Unsupported functions: A, B, C' summary.""" + + def should_drop(tg, tc): + fn = tg.get("function") + if fn is None or fn in supported_functions: + return None + return fn + + return should_drop + + def err(msg, **kwargs): print(msg, file=sys.stderr, **kwargs) @@ -100,6 +203,23 @@ def info(msg, **kwargs): print(msg, **kwargs) +# Warnings deferred to the end of the run so they stand out after all the +# per-test-case chatter. Collected by warn(), emitted once by flush_warnings(). +_warnings = [] + + +def warn(msg): + _warnings.append(msg) + + +def flush_warnings(): + if not _warnings: + return + err("") + for msg in _warnings: + err(msg) + + def get_acvp_binary(tg): """Convert JSON dict for ACVP test group to suitable ACVP binary.""" parameterSetToLevel = { @@ -303,7 +423,7 @@ def runTest(data, output): info("ALL GOOD!") -def test(prompt, expected, output, version): +def test(prompt, expected, output, version, supported_functions=None): assert prompt is not None or output is None, ( "cannot produce output if there is no input" ) @@ -317,9 +437,26 @@ def test(prompt, expected, output, version): data = [loadAcvpData(prompt, expected)] else: # load data from downloaded files - data = loadDefaultAcvpData(version) + data = loadDefaultAcvpData(version, supported_functions) + + if not data: + warn("WARNING: No ACVP tests supported by this build; no cases were run.") + info("ALL GOOD!") + flush_warnings() + return + + # Filter out test cases whose ACVP function isn't compiled in. + if supported_functions is not None: + reasons = filter_test_cases(data, unsupported_function(supported_functions)) + if reasons: + fns = ", ".join(sorted(set(reasons))) + warn( + f"WARNING: Dropped {len(reasons)} ACVP test case(s). " + f"Unsupported functions: {fns}." + ) runTest(data, output) + flush_warnings() parser = argparse.ArgumentParser() @@ -351,4 +488,7 @@ def test(prompt, expected, output, version): print("Failed to download ACVP test files", file=sys.stderr) sys.exit(1) -test(args.prompt, args.expected, args.output, args.version) +supported_functions = detect_supported_functions() +info(f"Auto-detected supported ACVP functions: {sorted(supported_functions)}") + +test(args.prompt, args.expected, args.output, args.version, supported_functions) diff --git a/test/acvp/acvp_mlkem.c b/test/acvp/acvp_mlkem.c index 277b699f86..4a0a336da5 100644 --- a/test/acvp/acvp_mlkem.c +++ b/test/acvp/acvp_mlkem.c @@ -135,6 +135,7 @@ static void print_hex(const char *name, const unsigned char *raw, size_t len) /* The test-case handlers below are MLK_NOINLINE so their large key buffers * stay in short-lived frames. This can reduce stack usage in some * environments, e.g. AVR. */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) static MLK_NOINLINE void acvp_mlkem_encapDecp_AFT_encapsulation( unsigned char const ek[CRYPTO_PUBLICKEYBYTES], unsigned char const m[MLKEM_SYMBYTES]) @@ -148,6 +149,16 @@ static MLK_NOINLINE void acvp_mlkem_encapDecp_AFT_encapsulation( print_hex("k", ss, sizeof(ss)); } +static MLK_NOINLINE void acvp_mlkem_encapDecp_VAL_encapsulationKeyCheck( + unsigned char const ek[CRYPTO_PUBLICKEYBYTES]) +{ + int rc = 0; + rc = (crypto_kem_check_pk(ek) == 0) ? 1 : 0; + printf("testPassed=%d\n", rc); +} +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ + +#if !defined(MLK_CONFIG_NO_DECAPS_API) static MLK_NOINLINE void acvp_mlkem_encapDecp_VAL_decapsulation( unsigned char const dk[CRYPTO_SECRETKEYBYTES], unsigned char const c[CRYPTO_CIPHERTEXTBYTES]) @@ -159,14 +170,6 @@ static MLK_NOINLINE void acvp_mlkem_encapDecp_VAL_decapsulation( print_hex("k", ss, sizeof(ss)); } -static MLK_NOINLINE void acvp_mlkem_encapDecp_VAL_encapsulationKeyCheck( - unsigned char const ek[CRYPTO_PUBLICKEYBYTES]) -{ - int rc = 0; - rc = (crypto_kem_check_pk(ek) == 0) ? 1 : 0; - printf("testPassed=%d\n", rc); -} - static MLK_NOINLINE void acvp_mlkem_encapDecp_VAL_decapsulationKeyCheck( unsigned char const dk[CRYPTO_SECRETKEYBYTES]) { @@ -174,7 +177,9 @@ static MLK_NOINLINE void acvp_mlkem_encapDecp_VAL_decapsulationKeyCheck( rc = (crypto_kem_check_sk(dk) == 0) ? 1 : 0; printf("testPassed=%d\n", rc); } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) static MLK_NOINLINE void acvp_mlkem_keyGen_AFT( unsigned char const z[MLKEM_SYMBYTES], unsigned char const d[MLKEM_SYMBYTES]) @@ -191,6 +196,27 @@ static MLK_NOINLINE void acvp_mlkem_keyGen_AFT( print_hex("ek", ek, sizeof(ek)); print_hex("dk", dk, sizeof(dk)); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ + +/* Print supported ACVP modes and functions and exit (used by acvp_client.py). + * ML-KEM's ACVP schema bundles encapsulation and decapsulation into the + * "encapDecap" mode; individual test functions (encapsulation vs + * decapsulation, plus the *KeyCheck helpers) may still be disabled + * independently. We advertise each function that is compiled in. */ +static void print_info(void) +{ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) + printf("keyGen\n"); +#endif +#if !defined(MLK_CONFIG_NO_ENCAPS_API) + printf("encapsulation\n"); + printf("encapsulationKeyCheck\n"); +#endif +#if !defined(MLK_CONFIG_NO_DECAPS_API) + printf("decapsulation\n"); + printf("decapsulationKeyCheck\n"); +#endif +} /* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */ #if defined(main) @@ -207,12 +233,18 @@ int main(int argc, char *argv[]) } argc--, argv++; - /* Parse mode: "encapDecap" or "keyGen" */ + /* Parse mode: "encapDecap" or "keyGen" or "--info" */ if (argc == 0) { goto usage; } + if (strcmp(*argv, "--info") == 0) + { + print_info(); + return 0; + } + if (strcmp(*argv, "encapDecap") == 0) { mode = encapDecap; @@ -283,6 +315,7 @@ int main(int argc, char *argv[]) switch (encapDecap_function) { +#if !defined(MLK_CONFIG_NO_ENCAPS_API) case encapsulation: { unsigned char ek[CRYPTO_PUBLICKEYBYTES]; @@ -311,6 +344,8 @@ int main(int argc, char *argv[]) acvp_mlkem_encapDecp_AFT_encapsulation(ek, m); break; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) case decapsulation: { unsigned char dk[CRYPTO_SECRETKEYBYTES]; @@ -339,6 +374,8 @@ int main(int argc, char *argv[]) acvp_mlkem_encapDecp_VAL_decapsulation(dk, c); break; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) case encapsulationKeyCheck: { unsigned char ek[CRYPTO_PUBLICKEYBYTES]; @@ -365,6 +402,8 @@ int main(int argc, char *argv[]) acvp_mlkem_encapDecp_VAL_encapsulationKeyCheck(ek); break; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) case decapsulationKeyCheck: { unsigned char dk[CRYPTO_SECRETKEYBYTES]; @@ -391,9 +430,13 @@ int main(int argc, char *argv[]) acvp_mlkem_encapDecp_VAL_decapsulationKeyCheck(dk); break; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ + default: + goto usage; } break; } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) case keyGen: { unsigned char z[MLKEM_SYMBYTES]; @@ -422,6 +465,9 @@ int main(int argc, char *argv[]) acvp_mlkem_keyGen_AFT(z, d); break; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ + default: + goto usage; } ((void)type); @@ -432,23 +478,29 @@ int main(int argc, char *argv[]) fprintf(stderr, USAGE "\n"); return (1); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) encaps_usage: fprintf(stderr, ENCAPS_USAGE "\n"); return (1); -decaps_usage: - fprintf(stderr, DECAPS_USAGE "\n"); - return (1); - -keygen_usage: - fprintf(stderr, KEYGEN_USAGE "\n"); - return (1); - encapsulationKeyCheck_usage: fprintf(stderr, ENCAPS_KEY_CHECK_USAGE "\n"); return (1); +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ + +#if !defined(MLK_CONFIG_NO_DECAPS_API) +decaps_usage: + fprintf(stderr, DECAPS_USAGE "\n"); + return (1); decapsulationKeyCheck_usage: fprintf(stderr, DECAPS_KEY_CHECK_USAGE "\n"); return (1); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ + +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) +keygen_usage: + fprintf(stderr, KEYGEN_USAGE "\n"); + return (1); +#endif } diff --git a/test/baremetal/platform/avr/README.md b/test/baremetal/platform/avr/README.md index 3ee640160d..3e94e3c44c 100644 --- a/test/baremetal/platform/avr/README.md +++ b/test/baremetal/platform/avr/README.md @@ -6,4 +6,4 @@ This directory provides a baremetal build and test environment for AVR MCUs, usi This is primarily a vehicle to test that mlkem-native builds and is functionally correct in 16-bit C implementations. For actual practical use on 16-bit MCUs, stack usage would need to be reduced. -**Note:** We currently need 32K of RAM, more than any MCU supported by `simavr`; we therefore use a patched version of `simavr` where Atmega128rfr2 is given 32K of RAM. To test this, you must work in the `nix .#avr` shell specified in nix flake. +**Note:** We currently need close to the full 64K data address space of the AVR architecture, more than any MCU supported by `simavr`; we therefore use a patched version of `simavr` where Atmega128rfr2 is given 63.5K of RAM (0x0200-0xFFFF). To test this, you must work in the `nix .#cross-avr` shell specified in nix flake. diff --git a/test/baremetal/platform/avr/avr_wrapper.c b/test/baremetal/platform/avr/avr_wrapper.c index dabb8ab2bc..90ea1b9300 100644 --- a/test/baremetal/platform/avr/avr_wrapper.c +++ b/test/baremetal/platform/avr/avr_wrapper.c @@ -14,7 +14,17 @@ /* Register for sending commands (e.g. exit codes) to simavr */ AVR_MCU_SIMAVR_COMMAND(&GPIOR0); -#define RAM_BASE 0x2000 +/* The argc/argv block is placed at the top of RAM, just below 16 bytes of + * scratch stack used during startup. The exec wrapper chooses the base + * address RAM_TOP - blocksize and stores it in the first two bytes of + * EEPROM, followed by the block itself. The stack grows downwards from + * just below the block, so binaries with little argument data + * automatically get the largest possible stack. */ +#define RAM_TOP 0xFFF0 + +/* Base address of the argc/argv block, read from EEPROM. Used by the + * argc/argv register setup in init7.S. */ +uint16_t mlk_argv_base; static int uart_putchar(char c, FILE *stream) { @@ -27,11 +37,22 @@ static int uart_putchar(char c, FILE *stream) /* Set up stdout stream for avr-libc printf */ static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); -/* Init6 function - copy EEPROM to RAM */ +/* Init6 function - copy argc/argv block from EEPROM to top of RAM and + * point the stack just below it. The scratch stack above RAM_TOP is used + * for the eeprom_read_* calls; the default stack location (RAMEND of the + * unpatched MCU) may lie inside .data/.bss and must not be used. */ void setup_args(void) __attribute__((naked, section(".init6"), used)); void setup_args(void) { - eeprom_read_block((void *)RAM_BASE, (void *)0x0000, 0x4000); + uint16_t base; + SPH = 0xFF; + SPL = 0xFF; + base = eeprom_read_word((const uint16_t *)0); + eeprom_read_block((void *)base, (const void *)2, (size_t)(RAM_TOP - base)); + mlk_argv_base = base; + base--; + SPH = (uint8_t)(base >> 8); + SPL = (uint8_t)(base & 0xFF); } /* This is run as part of the init sequence, after setting up the stack diff --git a/test/baremetal/platform/avr/exec_wrapper.py b/test/baremetal/platform/avr/exec_wrapper.py index 23bde2b32a..897b4c4738 100755 --- a/test/baremetal/platform/avr/exec_wrapper.py +++ b/test/baremetal/platform/avr/exec_wrapper.py @@ -7,6 +7,14 @@ import os import tempfile +# The argc/argv block is placed at the top of RAM, just below 16 bytes of +# scratch stack used during startup (see avr_wrapper.c). The stack grows +# downwards from just below the block. +RAM_TOP = 0xFFF0 + +# Patched EEPROM size (see nix/avr/simavr-32k-eeprom.patch) +EEPROM_SIZE = 0x8000 + def intel_hex_line(addr, data): """Generate Intel HEX format line""" @@ -25,6 +33,10 @@ def intel_hex_line(addr, data): def create_eeprom_hex(args, output_file): """ Create EEPROM hex file from command line arguments. + + EEPROM layout: 2 bytes block base address (little-endian), followed by + the argc/argv block to be copied to that address: + argc (2 bytes) + argv array (len(args) * 2 bytes) + packed strings. """ # First arg should be binary name (strip path) args = [os.path.basename(args[0])] + args[1:] @@ -38,15 +50,23 @@ def create_eeprom_hex(args, output_file): strings_data.extend(arg.encode("utf-8")) strings_data.append(0x00) # Null terminator - # Step 2: Calculate where strings will be in RAM - # Layout: argc (2 bytes) + argv array (len(args) * 2 bytes) + strings + # Step 2: Calculate where the block will be in RAM argc_size = 2 argv_size = len(args) * 2 - strings_ram_base = 0x2000 + argc_size + argv_size + block_size = argc_size + argv_size + len(strings_data) + if block_size + 2 > EEPROM_SIZE: + print( + f"Error: argument block of {block_size} bytes does not fit in EEPROM", + file=sys.stderr, + ) + sys.exit(1) + base = RAM_TOP - block_size + strings_ram_base = base + argc_size + argv_size - # Step 3: Build data starting with argc + # Step 3: Build EEPROM data: block base address, then argc data = bytearray() - data.extend([len(args) & 0xFF, (len(args) >> 8) & 0xFF]) # argc (little-endian) + data.extend([base & 0xFF, (base >> 8) & 0xFF]) + data.extend([len(args) & 0xFF, (len(args) >> 8) & 0xFF]) # Step 4: Build argv array with pointers to RAM addresses for offset in string_offsets: @@ -96,7 +116,7 @@ def main(): # Run with simavr - enable UART output # Note that we use a patched version of simavr where atmega128rfr2 - # has 32K of RAM. This is purely for testing purposes. + # has 63.5K of RAM. This is purely for testing purposes. cmd = [ "simavr", "-m", @@ -126,12 +146,12 @@ def main(): filtered_lines.append(clean_line) output = "\n".join(filtered_lines) - # simavr does not propagate the guest exit code (returncode is always - # 0), so a guest-side failure would otherwise be reported as success. - # As a stopgap until simavr's exit-code mechanism is backported (#1728), - # scan the output for "ERROR" and fail instead. This catches both - # the UBSan-trap abort() in avr_wrapper.c and the CHECK(...) macros in - # the tests, which print "ERROR (file,line)" on failure. + # The guest exit code is propagated via simavr's exit-code commands + # (see avr_wrapper.c). As an additional safety net, scan the output + # for "ERROR" and fail: this catches failures where the firmware + # stops without reaching exit(), and both the UBSan-trap abort() in + # avr_wrapper.c and the CHECK(...) macros in the tests print + # "ERROR (file,line)" on failure. # # On failure, write to stderr, otherwise stdout. if "ERROR" in output: diff --git a/test/baremetal/platform/avr/init7.S b/test/baremetal/platform/avr/init7.S index 56db0aff2f..6ef84c476e 100644 --- a/test/baremetal/platform/avr/init7.S +++ b/test/baremetal/platform/avr/init7.S @@ -7,16 +7,18 @@ /* AVR calling convention for main(int argc, char** argv): * - argc (int, 16-bit) goes in r24:r25 (r24=low, r25=high) * - argv (char**, 16-bit pointer) goes in r22:r23 (r22=low, r23=high) + * + * The argc/argv block was copied to mlk_argv_base by setup_args (init6): + * argc at mlk_argv_base, argv array at mlk_argv_base + 2. */ -/* Load argc from 0x2000 */ -ldi r30, 0x00 -ldi r31, 0x20 +lds r30, mlk_argv_base +lds r31, mlk_argv_base+1 ld r24, Z ldi r25, 0 -/* Set argv = 0x2002 */ -ldi r22, lo8(0x2002) -ldi r23, hi8(0x2002) +movw r22, r30 +subi r22, lo8(-2) +sbci r23, hi8(-2) /* Fall through to init8 - no ret instruction */ diff --git a/test/baremetal/platform/avr/platform.mk b/test/baremetal/platform/avr/platform.mk index 8b702f0740..033584c08b 100644 --- a/test/baremetal/platform/avr/platform.mk +++ b/test/baremetal/platform/avr/platform.mk @@ -7,11 +7,10 @@ CROSS_PREFIX=avr- CC=gcc # AVR target configuration -# We would need ATMega256rfr2 with 32K RAM, but it's not supported by simavr. -# We instead use ATMega128rfr1 with 16K RAM, but modify its specification in -# simavr to bump the RAM to 32K. -# Once simavr supports ATMega256rfr2, or once mlkem-native has [an option for] -# lower stack usage, this should be changed. +# ML-KEM-1024 (together with the RAM-resident test vectors) needs more than +# the 16K RAM of any MCU supported by simavr, so we use ATMega128rfr2 with its +# RAM specification in simavr bumped from 16K to the maximal 63.5K +# (0x0200-0xFFFF). AVR_MCU ?= atmega128rfr2 AVR_FREQ ?= 16000000UL @@ -35,12 +34,16 @@ CFLAGS += \ CFLAGS += $(CFLAGS_EXTRA) -# Non-standard stack end: 0x81FF = 0x200 + 8K instead of default 0x41FF +# Memory layout (data address space 0x0200-0xFFFF): +# - .data/.bss grow upwards from 0x0200 (data region length raised from the +# default 16K to the full RAM size) +# - the argc/argv block sits at the top of RAM, with the stack growing +# downwards from just below it (set up at runtime, see avr_wrapper.c) LDFLAGS += \ -mmcu=$(AVR_MCU) \ -Wl,--gc-sections \ -Wl,--relax \ - -Wl,--defsym=__stack=0x81FF \ + -Wl,--defsym=__DATA_REGION_LENGTH__=0xFC00 \ -Wl,--undefined=_simavr_command_register \ -Wl,--section-start=.mmcu=0x910000 \ -lprintf_min diff --git a/test/configs/break_pct_config.h b/test/configs/break_pct_config.h index b955b63081..4211d277b2 100644 --- a/test/configs/break_pct_config.h +++ b/test/configs/break_pct_config.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_heap_alloc_config.h b/test/configs/custom_heap_alloc_config.h index b4aa854b16..da9f77625c 100644 --- a/test/configs/custom_heap_alloc_config.h +++ b/test/configs/custom_heap_alloc_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_memcpy_config.h b/test/configs/custom_memcpy_config.h index 74fcdbf413..36264ac261 100644 --- a/test/configs/custom_memcpy_config.h +++ b/test/configs/custom_memcpy_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_memset_config.h b/test/configs/custom_memset_config.h index 3d783454b7..810c8436ed 100644 --- a/test/configs/custom_memset_config.h +++ b/test/configs/custom_memset_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_native_capability_config_0.h b/test/configs/custom_native_capability_config_0.h index d0c05a1780..103a652428 100644 --- a/test/configs/custom_native_capability_config_0.h +++ b/test/configs/custom_native_capability_config_0.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_native_capability_config_1.h b/test/configs/custom_native_capability_config_1.h index 5b72911f6b..95e841e747 100644 --- a/test/configs/custom_native_capability_config_1.h +++ b/test/configs/custom_native_capability_config_1.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_native_capability_config_CPUID_AVX2.h b/test/configs/custom_native_capability_config_CPUID_AVX2.h index afde1e7d81..a45ccc15d8 100644 --- a/test/configs/custom_native_capability_config_CPUID_AVX2.h +++ b/test/configs/custom_native_capability_config_CPUID_AVX2.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_native_capability_config_ID_AA64PFR1_EL1.h b/test/configs/custom_native_capability_config_ID_AA64PFR1_EL1.h index dd8eb7f2d6..dd47e5017a 100644 --- a/test/configs/custom_native_capability_config_ID_AA64PFR1_EL1.h +++ b/test/configs/custom_native_capability_config_ID_AA64PFR1_EL1.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_randombytes_config.h b/test/configs/custom_randombytes_config.h index 093503eb8e..b6705d6e93 100644 --- a/test/configs/custom_randombytes_config.h +++ b/test/configs/custom_randombytes_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_stdlib_config.h b/test/configs/custom_stdlib_config.h index 0e06730688..dc5e6514d1 100644 --- a/test/configs/custom_stdlib_config.h +++ b/test/configs/custom_stdlib_config.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/custom_zeroize_config.h b/test/configs/custom_zeroize_config.h index ea7f4194bb..78a20d3be6 100644 --- a/test/configs/custom_zeroize_config.h +++ b/test/configs/custom_zeroize_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/no_asm_config.h b/test/configs/no_asm_config.h index 7c5ca7f50e..af76bb4141 100644 --- a/test/configs/no_asm_config.h +++ b/test/configs/no_asm_config.h @@ -115,6 +115,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/serial_fips202_config.h b/test/configs/serial_fips202_config.h index 4f6a171446..73bd3fc894 100644 --- a/test/configs/serial_fips202_config.h +++ b/test/configs/serial_fips202_config.h @@ -114,6 +114,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/configs/test_alloc_config.h b/test/configs/test_alloc_config.h index 55daffc0ca..4577e18595 100644 --- a/test/configs/test_alloc_config.h +++ b/test/configs/test_alloc_config.h @@ -117,6 +117,42 @@ */ /* #define MLK_CONFIG_EXTERNAL_API_QUALIFIER */ +/** + * MLK_CONFIG_NO_KEYPAIR_API + * + * By default, mlkem-native includes support for generating key pairs. + * If you don't need this, set MLK_CONFIG_NO_KEYPAIR_API to exclude + * crypto_kem_keypair and crypto_kem_keypair_derand, and all internal + * APIs only needed by those functions. + */ +/* #define MLK_CONFIG_NO_KEYPAIR_API */ + +/** + * MLK_CONFIG_NO_ENCAPS_API + * + * By default, mlkem-native includes support for encapsulation. If you + * don't need this, set MLK_CONFIG_NO_ENCAPS_API to exclude + * crypto_kem_enc, crypto_kem_enc_derand, crypto_kem_check_pk, and + * all internal APIs only needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_enc(). + */ +/* #define MLK_CONFIG_NO_ENCAPS_API */ + +/** + * MLK_CONFIG_NO_DECAPS_API + * + * By default, mlkem-native includes support for decapsulation. If you + * don't need this, set MLK_CONFIG_NO_DECAPS_API to exclude + * crypto_kem_dec, crypto_kem_check_sk, and all internal APIs only + * needed by those functions. + * + * @note Setting this option is incompatible with MLK_CONFIG_KEYGEN_PCT + * as the current PCT implementation requires crypto_kem_dec(). + */ +/* #define MLK_CONFIG_NO_DECAPS_API */ + /** * MLK_CONFIG_NO_RANDOMIZED_API * diff --git a/test/mk/components.mk b/test/mk/components.mk index fa381117b9..e464bf4bf5 100644 --- a/test/mk/components.mk +++ b/test/mk/components.mk @@ -243,6 +243,14 @@ ABICHECK_ASM_CFLAGS := \ ABICHECK_ASM_OBJS = $(call MAKE_OBJS,$(ABICHECK_DIR),$(ABICHECK_ASM_SOURCES)) $(ABICHECK_ASM_OBJS): CFLAGS += $(ABICHECK_ASM_CFLAGS) +# Force the full ML-KEM API surface for the ABI check, regardless of any +# reduced-API config the caller passes in. +ABICHECK_FULL_API_CFLAGS := \ + -UMLK_CONFIG_NO_KEYPAIR_API \ + -UMLK_CONFIG_NO_ENCAPS_API \ + -UMLK_CONFIG_NO_DECAPS_API +$(ABICHECK_OBJS): CFLAGS += $(ABICHECK_FULL_API_CFLAGS) + # Platform support objects (e.g. the bare-metal startup providing _start and the # semihosting runtime). EXTRA_SOURCES is set by a platform makefile (see # test/baremetal/platform/*/platform.mk via EXTRA_MAKEFILE); empty for native diff --git a/test/src/gen_KAT.c b/test/src/gen_KAT.c index e5d5440dbd..00574b318c 100644 --- a/test/src/gen_KAT.c +++ b/test/src/gen_KAT.c @@ -9,6 +9,16 @@ #include "../../mlkem/mlkem_native.h" +#if defined(MLK_CONFIG_NO_KEYPAIR_API) || defined(MLK_CONFIG_NO_ENCAPS_API) || \ + defined(MLK_CONFIG_NO_DECAPS_API) +int main(void) +{ + printf("SKIPPED (KAT requires full API)\n"); + return 0; +} +#else /* MLK_CONFIG_NO_KEYPAIR_API || MLK_CONFIG_NO_ENCAPS_API || \ + MLK_CONFIG_NO_DECAPS_API */ + #if defined(_WIN64) || defined(_WIN32) #include #include @@ -90,3 +100,5 @@ int main(void) return 0; } +#endif /* !(MLK_CONFIG_NO_KEYPAIR_API || MLK_CONFIG_NO_ENCAPS_API || \ + MLK_CONFIG_NO_DECAPS_API) */ diff --git a/test/src/test_alloc.c b/test/src/test_alloc.c index a4c6a93b4f..1cca5e7724 100644 --- a/test/src/test_alloc.c +++ b/test/src/test_alloc.c @@ -11,6 +11,7 @@ #include "../../mlkem/mlkem_native.h" #include "../../mlkem/src/common.h" #include "../notrandombytes/notrandombytes.h" +#include "../test_vectors/expected_test_vectors.h" /* * Level-dependent allocation limit macros. @@ -329,98 +330,89 @@ void custom_free(test_ctx_t *ctx, void *p, size_t sz, const char *file, } \ } while (0) -static int test_keygen_alloc_failure(test_ctx_t *ctx) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) +static int test_keypair_derand_alloc_failure(test_ctx_t *ctx) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; + uint8_t coins[2 * MLKEM_SYMBYTES]; - TEST_ALLOC_FAILURE("crypto_kem_keypair", crypto_kem_keypair(pk, sk, ctx), + memcpy(coins, test_vector_d, MLKEM_SYMBYTES); + memcpy(coins + MLKEM_SYMBYTES, test_vector_z, MLKEM_SYMBYTES); + + TEST_ALLOC_FAILURE("crypto_kem_keypair_derand", + crypto_kem_keypair_derand(pk, sk, coins, ctx), MLK_TOTAL_ALLOC_KEYPAIR, &ctx->global_high_mark_keypair); return 0; } -static int test_enc_alloc_failure(test_ctx_t *ctx) +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int test_keypair_alloc_failure(test_ctx_t *ctx) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key[CRYPTO_BYTES]; - /* Generate valid keypair first */ - reset_all(ctx); - if (crypto_kem_keypair(pk, sk, ctx) != 0) - { - fprintf(stderr, "ERROR: crypto_kem_keypair failed in enc test setup\n"); - return 1; - } - - TEST_ALLOC_FAILURE("crypto_kem_enc", crypto_kem_enc(ct, key, pk, ctx), - MLK_TOTAL_ALLOC_ENCAPS, &ctx->global_high_mark_encaps); + TEST_ALLOC_FAILURE("crypto_kem_keypair", crypto_kem_keypair(pk, sk, ctx), + MLK_TOTAL_ALLOC_KEYPAIR, &ctx->global_high_mark_keypair); return 0; } +#endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ -static int test_dec_alloc_failure(test_ctx_t *ctx) +#if !defined(MLK_CONFIG_NO_ENCAPS_API) +static int test_enc_derand_alloc_failure(test_ctx_t *ctx) { - uint8_t pk[CRYPTO_PUBLICKEYBYTES]; - uint8_t sk[CRYPTO_SECRETKEYBYTES]; uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t key_enc[CRYPTO_BYTES]; - uint8_t key_dec[CRYPTO_BYTES]; + uint8_t ss[CRYPTO_BYTES]; - /* Generate valid keypair and ciphertext first */ - reset_all(ctx); - if (crypto_kem_keypair(pk, sk, ctx) != 0) - { - fprintf(stderr, "ERROR: crypto_kem_keypair failed in dec test setup\n"); - return 1; - } + TEST_ALLOC_FAILURE( + "crypto_kem_enc_derand", + crypto_kem_enc_derand(ct, ss, test_vector_pk, test_vector_m, ctx), + MLK_TOTAL_ALLOC_ENCAPS, &ctx->global_high_mark_encaps); + return 0; +} - if (crypto_kem_enc(ct, key_enc, pk, ctx) != 0) - { - fprintf(stderr, "ERROR: crypto_kem_enc failed in dec test setup\n"); - return 1; - } +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int test_enc_alloc_failure(test_ctx_t *ctx) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; - TEST_ALLOC_FAILURE("crypto_kem_dec", crypto_kem_dec(key_dec, ct, sk, ctx), - MLK_TOTAL_ALLOC_DECAPS, &ctx->global_high_mark_decaps); + TEST_ALLOC_FAILURE("crypto_kem_enc", + crypto_kem_enc(ct, ss, test_vector_pk, ctx), + MLK_TOTAL_ALLOC_ENCAPS, &ctx->global_high_mark_encaps); return 0; } +#endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ static int test_check_pk_alloc_failure(test_ctx_t *ctx) { - uint8_t pk[CRYPTO_PUBLICKEYBYTES]; - uint8_t sk[CRYPTO_SECRETKEYBYTES]; - - reset_all(ctx); - if (crypto_kem_keypair(pk, sk, ctx) != 0) - { - fprintf(stderr, - "ERROR: crypto_kem_keypair failed in check_pk test setup\n"); - return 1; - } - - TEST_ALLOC_FAILURE("crypto_kem_check_pk", crypto_kem_check_pk(pk, ctx), + TEST_ALLOC_FAILURE("crypto_kem_check_pk", + crypto_kem_check_pk(test_vector_pk, ctx), MLK_TOTAL_ALLOC_KEYPAIR, &ctx->global_high_mark_keypair); return 0; } +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ -static int test_check_sk_alloc_failure(test_ctx_t *ctx) +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int test_dec_alloc_failure(test_ctx_t *ctx) { - uint8_t pk[CRYPTO_PUBLICKEYBYTES]; - uint8_t sk[CRYPTO_SECRETKEYBYTES]; + uint8_t ss[CRYPTO_BYTES]; - reset_all(ctx); - if (crypto_kem_keypair(pk, sk, ctx) != 0) - { - fprintf(stderr, - "ERROR: crypto_kem_keypair failed in check_sk test setup\n"); - return 1; - } + TEST_ALLOC_FAILURE("crypto_kem_dec", + crypto_kem_dec(ss, test_vector_ct, test_vector_sk, ctx), + MLK_TOTAL_ALLOC_DECAPS, &ctx->global_high_mark_decaps); + return 0; +} - TEST_ALLOC_FAILURE("crypto_kem_check_sk", crypto_kem_check_sk(sk, ctx), +static int test_check_sk_alloc_failure(test_ctx_t *ctx) +{ + TEST_ALLOC_FAILURE("crypto_kem_check_sk", + crypto_kem_check_sk(test_vector_sk, ctx), MLK_TOTAL_ALLOC_KEYPAIR, &ctx->global_high_mark_keypair); return 0; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* * Helper macro to check allocation high watermark matches expected limit. @@ -442,6 +434,7 @@ int main(void); #endif int main(void) { + int r = 0; MLK_ALIGN uint8_t bump_buffer[MLK_BUMP_ALLOC_SIZE]; /* Initialize test context with default settings */ test_ctx_t ctx = { @@ -460,36 +453,46 @@ int main(void) }; ctx.buffer = bump_buffer; - if (test_keygen_alloc_failure(&ctx) != 0) - { - return 1; - } - - if (test_enc_alloc_failure(&ctx) != 0) - { - return 1; - } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) + r |= test_keypair_derand_alloc_failure(&ctx); +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) + r |= test_keypair_alloc_failure(&ctx); +#endif +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ - if (test_dec_alloc_failure(&ctx) != 0) - { - return 1; - } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) + r |= test_enc_derand_alloc_failure(&ctx); +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) + r |= test_enc_alloc_failure(&ctx); +#endif + r |= test_check_pk_alloc_failure(&ctx); +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ - if (test_check_pk_alloc_failure(&ctx) != 0) - { - return 1; - } +#if !defined(MLK_CONFIG_NO_DECAPS_API) + r |= test_dec_alloc_failure(&ctx); + r |= test_check_sk_alloc_failure(&ctx); +#endif - if (test_check_sk_alloc_failure(&ctx) != 0) + if (r != 0) { return 1; } - /* Check per-operation high watermarks match the declared limits */ + /* Check per-operation high watermarks match the declared limits. + * Only enforce for enabled APIs. */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) CHECK_ALLOC_MATCH(ctx.global_high_mark_keypair, MLK_TOTAL_ALLOC_KEYPAIR); +#endif +#if !defined(MLK_CONFIG_NO_ENCAPS_API) CHECK_ALLOC_MATCH(ctx.global_high_mark_encaps, MLK_TOTAL_ALLOC_ENCAPS); +#endif +#if !defined(MLK_CONFIG_NO_DECAPS_API) CHECK_ALLOC_MATCH(ctx.global_high_mark_decaps, MLK_TOTAL_ALLOC_DECAPS); +#endif +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_DECAPS_API) CHECK_ALLOC_MATCH(ctx.global_high_mark, MLK_TOTAL_ALLOC); +#endif return 0; } diff --git a/test/src/test_mlkem.c b/test/src/test_mlkem.c index 429d6656ae..4ab24e4dae 100644 --- a/test/src/test_mlkem.c +++ b/test/src/test_mlkem.c @@ -9,6 +9,7 @@ #include "../../mlkem/mlkem_native.h" #include "../notrandombytes/notrandombytes.h" +#include "../test_vectors/expected_test_vectors.h" #ifndef NTESTS_FUNC #define NTESTS_FUNC 1000 @@ -27,11 +28,18 @@ } while (0) -static int test_keys_core(uint8_t pk[CRYPTO_PUBLICKEYBYTES], - uint8_t sk[CRYPTO_SECRETKEYBYTES], - uint8_t ct[CRYPTO_CIPHERTEXTBYTES], - uint8_t key_a[CRYPTO_BYTES], - uint8_t key_b[CRYPTO_BYTES]) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_ENCAPS_API) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) +/* Forbid inlining so stack buffers below stay in short-lived + * frames and don't stack up in main(). This helps testing on + * memory-constrained targets such as AVR. */ +static MLK_NOINLINE int test_keys_core(uint8_t pk[CRYPTO_PUBLICKEYBYTES], + uint8_t sk[CRYPTO_SECRETKEYBYTES], + uint8_t ct[CRYPTO_CIPHERTEXTBYTES], + uint8_t key_a[CRYPTO_BYTES], + uint8_t key_b[CRYPTO_BYTES]) { /* Alice generates a public key */ CHECK(crypto_kem_keypair(pk, sk) == 0); @@ -48,7 +56,7 @@ static int test_keys_core(uint8_t pk[CRYPTO_PUBLICKEYBYTES], return 0; } -static int test_keys(void) +static MLK_NOINLINE int test_keys(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; @@ -58,7 +66,7 @@ static int test_keys(void) return test_keys_core(pk, sk, ct, key_a, key_b); } -static int test_keys_unaligned(void) +static MLK_NOINLINE int test_keys_unaligned(void) { MLK_ALIGN uint8_t pk[CRYPTO_PUBLICKEYBYTES + 1]; MLK_ALIGN uint8_t sk[CRYPTO_SECRETKEYBYTES + 1]; @@ -68,7 +76,7 @@ static int test_keys_unaligned(void) return test_keys_core(pk + 1, sk + 1, ct + 1, key_a + 1, key_b + 1); } -static int test_invalid_pk(void) +static MLK_NOINLINE int test_invalid_pk(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; @@ -86,7 +94,7 @@ static int test_invalid_pk(void) return 0; } -static int test_invalid_sk_a(void) +static MLK_NOINLINE int test_invalid_sk_a(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; @@ -110,7 +118,7 @@ static int test_invalid_sk_a(void) return 0; } -static int test_invalid_sk_b(void) +static MLK_NOINLINE int test_invalid_sk_b(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; @@ -129,7 +137,7 @@ static int test_invalid_sk_b(void) return 0; } -static int test_invalid_ciphertext(void) +static MLK_NOINLINE int test_invalid_ciphertext(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; @@ -159,6 +167,94 @@ static int test_invalid_ciphertext(void) CHECK(memcmp(key_a, key_b, CRYPTO_BYTES) != 0); return 0; } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_ENCAPS_API && \ + !MLK_CONFIG_NO_DECAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ + +/* + * Test each API operation independently against pre-computed test vectors. + * Compatible with reduced-API configurations. Each API's test is a + * MLK_NOINLINE function so that its large key buffers stay in short-lived + * frames -- this reduces peak stack usage on memory-constrained targets + * such as AVR. + */ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) +static MLK_NOINLINE int test_kem_expected_keygen(void) +{ + uint8_t pk[CRYPTO_PUBLICKEYBYTES]; + uint8_t sk[CRYPTO_SECRETKEYBYTES]; + uint8_t coins[2 * MLKEM_SYMBYTES]; + uint8_t test_vector_sk_copy[CRYPTO_SECRETKEYBYTES]; + + memcpy(coins, test_vector_d, MLKEM_SYMBYTES); + memcpy(coins + MLKEM_SYMBYTES, test_vector_z, MLKEM_SYMBYTES); + + CHECK(crypto_kem_keypair_derand(pk, sk, coins) == 0); + + /* Declassify the generated sk and a copy of test_vector_sk so we can + * memcmp them; the underlying test_vector_sk stays SECRET so it can + * still be used as a CT-sensitive input in the decaps block. */ + MLK_CT_TESTING_DECLASSIFY(sk, CRYPTO_SECRETKEYBYTES); + memcpy(test_vector_sk_copy, test_vector_sk, CRYPTO_SECRETKEYBYTES); + MLK_CT_TESTING_DECLASSIFY(test_vector_sk_copy, CRYPTO_SECRETKEYBYTES); + + CHECK(memcmp(pk, test_vector_pk, CRYPTO_PUBLICKEYBYTES) == 0); + CHECK(memcmp(sk, test_vector_sk_copy, CRYPTO_SECRETKEYBYTES) == 0); + return 0; +} +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ + +#if !defined(MLK_CONFIG_NO_ENCAPS_API) +static MLK_NOINLINE int test_kem_expected_encaps(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; + + CHECK(crypto_kem_enc_derand(ct, ss, test_vector_pk, test_vector_m) == 0); + + MLK_CT_TESTING_DECLASSIFY(ct, CRYPTO_CIPHERTEXTBYTES); + MLK_CT_TESTING_DECLASSIFY(ss, CRYPTO_BYTES); + + CHECK(memcmp(ct, test_vector_ct, CRYPTO_CIPHERTEXTBYTES) == 0); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); + return 0; +} +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ + +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static MLK_NOINLINE int test_kem_expected_decaps(void) +{ + uint8_t ss[CRYPTO_BYTES]; + + CHECK(crypto_kem_dec(ss, test_vector_ct, test_vector_sk) == 0); + + MLK_CT_TESTING_DECLASSIFY(ss, CRYPTO_BYTES); + CHECK(memcmp(ss, test_vector_ss, CRYPTO_BYTES) == 0); + return 0; +} +#endif /* !MLK_CONFIG_NO_DECAPS_API */ + +static int test_kem_expected(void) +{ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) + if (test_kem_expected_keygen() != 0) + { + return 1; + } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) + if (test_kem_expected_encaps() != 0) + { + return 1; + } +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) + if (test_kem_expected_decaps() != 0) + { + return 1; + } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ + return 0; +} /* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */ #if defined(main) @@ -167,6 +263,24 @@ int main(void); int main(void) { unsigned i; + int r; + + /* Fixed test-vector smoke test: exercises whichever of keygen/encaps/decaps + * are enabled against pre-computed vectors. Mark public test vectors + * public and the secret key test vector as well as all randomness + * secret, so valgrind CT testing has the right taint model. */ + MLK_CT_TESTING_DECLASSIFY(test_vector_pk, CRYPTO_PUBLICKEYBYTES); + MLK_CT_TESTING_DECLASSIFY(test_vector_ct, CRYPTO_CIPHERTEXTBYTES); + + MLK_CT_TESTING_SECRET(test_vector_sk, CRYPTO_SECRETKEYBYTES); + MLK_CT_TESTING_SECRET(test_vector_d, sizeof(test_vector_d)); + MLK_CT_TESTING_SECRET(test_vector_z, sizeof(test_vector_z)); + MLK_CT_TESTING_SECRET(test_vector_m, sizeof(test_vector_m)); + + if (test_kem_expected() != 0) + { + return 1; + } /* WARNING: Test-only * Normally, you would want to seed a PRNG with trustworthy entropy here. */ @@ -174,12 +288,23 @@ int main(void) for (i = 0; i < NTESTS_FUNC; i++) { - CHECK(test_keys() == 0); - CHECK(test_keys_unaligned() == 0); - CHECK(test_invalid_pk() == 0); - CHECK(test_invalid_sk_a() == 0); - CHECK(test_invalid_sk_b() == 0); - CHECK(test_invalid_ciphertext() == 0); + r = 0; +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_ENCAPS_API) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) + r |= test_keys(); + r |= test_keys_unaligned(); + r |= test_invalid_pk(); + r |= test_invalid_sk_a(); + r |= test_invalid_sk_b(); + r |= test_invalid_ciphertext(); +#endif /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_ENCAPS_API && \ + !MLK_CONFIG_NO_DECAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ + if (r) + { + return 1; + } } printf("CRYPTO_SECRETKEYBYTES: %d\n", CRYPTO_SECRETKEYBYTES); diff --git a/test/src/test_rng_fail.c b/test/src/test_rng_fail.c index 2773be7ca2..306d80b3d8 100644 --- a/test/src/test_rng_fail.c +++ b/test/src/test_rng_fail.c @@ -7,8 +7,10 @@ /* Expose internal functions */ #define MLK_BUILD_INTERNAL +#include #include "../../mlkem/mlkem_native.h" #include "../../mlkem/src/common.h" +#include "../test_vectors/expected_test_vectors.h" /* * This test checks that we handle randombytes failures correctly by: @@ -109,95 +111,79 @@ int randombytes(uint8_t *buf, size_t len) test_name, num_randombytes_calls); \ } while (0) -static int test_keygen_rng_failure(void) +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) +static int test_keypair_derand_rng_failure(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; + uint8_t coins[2 * MLKEM_SYMBYTES]; - TEST_RNG_FAILURE("crypto_kem_keypair", crypto_kem_keypair(pk, sk)); + memcpy(coins, test_vector_d, MLKEM_SYMBYTES); + memcpy(coins + MLKEM_SYMBYTES, test_vector_z, MLKEM_SYMBYTES); + + TEST_RNG_FAILURE("crypto_kem_keypair_derand", + crypto_kem_keypair_derand(pk, sk, coins)); return 0; } -static int test_enc_rng_failure(void) +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int test_keypair_rng_failure(void) { uint8_t pk[CRYPTO_PUBLICKEYBYTES]; uint8_t sk[CRYPTO_SECRETKEYBYTES]; - uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t ss[CRYPTO_BYTES]; - /* Generate valid keypair first */ - reset_all(); - if (crypto_kem_keypair(pk, sk) != 0) - { - fprintf(stderr, "ERROR: crypto_kem_keypair failed in enc test setup\n"); - return 1; - } - - TEST_RNG_FAILURE("crypto_kem_enc", crypto_kem_enc(ct, ss, pk)); + TEST_RNG_FAILURE("crypto_kem_keypair", crypto_kem_keypair(pk, sk)); return 0; } +#endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ -static int test_dec_rng_failure(void) +#if !defined(MLK_CONFIG_NO_ENCAPS_API) +static int test_enc_derand_rng_failure(void) { - uint8_t pk[CRYPTO_PUBLICKEYBYTES]; - uint8_t sk[CRYPTO_SECRETKEYBYTES]; uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; - uint8_t ss_enc[CRYPTO_BYTES]; - uint8_t ss_dec[CRYPTO_BYTES]; + uint8_t ss[CRYPTO_BYTES]; - /* Generate valid keypair and ciphertext first */ - reset_all(); - if (crypto_kem_keypair(pk, sk) != 0) - { - fprintf(stderr, "ERROR: crypto_kem_keypair failed in dec test setup\n"); - return 1; - } + TEST_RNG_FAILURE( + "crypto_kem_enc_derand", + crypto_kem_enc_derand(ct, ss, test_vector_pk, test_vector_m)); + return 0; +} - if (crypto_kem_enc(ct, ss_enc, pk) != 0) - { - fprintf(stderr, "ERROR: crypto_kem_enc failed in dec test setup\n"); - return 1; - } +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) +static int test_enc_rng_failure(void) +{ + uint8_t ct[CRYPTO_CIPHERTEXTBYTES]; + uint8_t ss[CRYPTO_BYTES]; - TEST_RNG_FAILURE("crypto_kem_dec", crypto_kem_dec(ss_dec, ct, sk)); + TEST_RNG_FAILURE("crypto_kem_enc", crypto_kem_enc(ct, ss, test_vector_pk)); return 0; } +#endif /* !MLK_CONFIG_NO_RANDOMIZED_API */ static int test_check_pk_rng_failure(void) { - uint8_t pk[CRYPTO_PUBLICKEYBYTES]; - uint8_t sk[CRYPTO_SECRETKEYBYTES]; + TEST_RNG_FAILURE("crypto_kem_check_pk", crypto_kem_check_pk(test_vector_pk)); + return 0; +} +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ - /* Generate valid keypair first */ - reset_all(); - if (crypto_kem_keypair(pk, sk) != 0) - { - fprintf(stderr, - "ERROR: crypto_kem_keypair failed in check_pk test setup\n"); - return 1; - } +#if !defined(MLK_CONFIG_NO_DECAPS_API) +static int test_dec_rng_failure(void) +{ + uint8_t ss[CRYPTO_BYTES]; - TEST_RNG_FAILURE("crypto_kem_check_pk", crypto_kem_check_pk(pk)); + TEST_RNG_FAILURE("crypto_kem_dec", + crypto_kem_dec(ss, test_vector_ct, test_vector_sk)); return 0; } static int test_check_sk_rng_failure(void) { - uint8_t pk[CRYPTO_PUBLICKEYBYTES]; - uint8_t sk[CRYPTO_SECRETKEYBYTES]; - - /* Generate valid keypair first */ - reset_all(); - if (crypto_kem_keypair(pk, sk) != 0) - { - fprintf(stderr, - "ERROR: crypto_kem_keypair failed in check_sk test setup\n"); - return 1; - } - - TEST_RNG_FAILURE("crypto_kem_check_sk", crypto_kem_check_sk(sk)); + TEST_RNG_FAILURE("crypto_kem_check_sk", crypto_kem_check_sk(test_vector_sk)); return 0; } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */ #if defined(main) @@ -205,27 +191,29 @@ int main(void); #endif int main(void) { - if (test_keygen_rng_failure() != 0) - { - return 1; - } + int r = 0; - if (test_enc_rng_failure() != 0) - { - return 1; - } +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) + r |= test_keypair_derand_rng_failure(); +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) + r |= test_keypair_rng_failure(); +#endif +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ - if (test_dec_rng_failure() != 0) - { - return 1; - } +#if !defined(MLK_CONFIG_NO_ENCAPS_API) + r |= test_enc_derand_rng_failure(); +#if !defined(MLK_CONFIG_NO_RANDOMIZED_API) + r |= test_enc_rng_failure(); +#endif + r |= test_check_pk_rng_failure(); +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ - if (test_check_pk_rng_failure() != 0) - { - return 1; - } +#if !defined(MLK_CONFIG_NO_DECAPS_API) + r |= test_dec_rng_failure(); + r |= test_check_sk_rng_failure(); +#endif - if (test_check_sk_rng_failure() != 0) + if (r != 0) { return 1; } diff --git a/test/src/test_stack.c b/test/src/test_stack.c index 82b8e3e8b2..998c4914e5 100644 --- a/test/src/test_stack.c +++ b/test/src/test_stack.c @@ -8,6 +8,22 @@ #include "mlkem_native.h" +static void print_info(void) +{ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) + printf("keygen\n"); +#endif +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) + printf("encaps\n"); +#endif +#if !defined(MLK_CONFIG_NO_DECAPS_API) + printf("decaps\n"); +#endif +} + +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) static void test_keygen_only(void) { unsigned char pk[CRYPTO_PUBLICKEYBYTES]; @@ -18,7 +34,9 @@ static void test_keygen_only(void) int ret = crypto_kem_keypair(pk, sk); (void)ret; /* Ignore return value - we only care about stack measurement */ } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) static void test_encaps_only(void) { unsigned char pk[CRYPTO_PUBLICKEYBYTES] = {0}; @@ -30,7 +48,9 @@ static void test_encaps_only(void) int ret = crypto_kem_enc(ct, ss, pk); (void)ret; /* Ignore return value - we only care about stack measurement */ } +#endif /* !MLK_CONFIG_NO_ENCAPS_API && !MLK_CONFIG_NO_RANDOMIZED_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) static void test_decaps_only(void) { unsigned char sk[CRYPTO_SECRETKEYBYTES] = {0}; @@ -42,6 +62,7 @@ static void test_decaps_only(void) int ret = crypto_kem_dec(ss, ct, sk); (void)ret; /* Ignore return value - we only care about stack measurement */ } +#endif /* !MLK_CONFIG_NO_DECAPS_API */ /* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */ #if defined(main) @@ -51,21 +72,38 @@ int main(int argc, char *argv[]) { if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "Usage: %s <--info|keygen|encaps|decaps>\n", argv[0]); return 1; } - if (strcmp(argv[1], "keygen") == 0) + if (strcmp(argv[1], "--info") == 0) { + print_info(); + } + else if (strcmp(argv[1], "keygen") == 0) + { +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) && \ + !defined(MLK_CONFIG_NO_RANDOMIZED_API) test_keygen_only(); +#else + printf("SKIPPED (keygen API disabled)\n"); +#endif } else if (strcmp(argv[1], "encaps") == 0) { +#if !defined(MLK_CONFIG_NO_ENCAPS_API) && !defined(MLK_CONFIG_NO_RANDOMIZED_API) test_encaps_only(); +#else + printf("SKIPPED (encaps API disabled)\n"); +#endif } else if (strcmp(argv[1], "decaps") == 0) { +#if !defined(MLK_CONFIG_NO_DECAPS_API) test_decaps_only(); +#else + printf("SKIPPED (decaps API disabled)\n"); +#endif } else { diff --git a/test/src/test_unit.c b/test/src/test_unit.c index 5a3ccb4f2b..17c25cd9e9 100644 --- a/test/src/test_unit.c +++ b/test/src/test_unit.c @@ -40,11 +40,19 @@ /* Declarations for _c functions exposed by MLK_STATIC_TESTABLE= */ void mlk_poly_reduce_c(mlk_poly *r); +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) void mlk_poly_tomont_c(mlk_poly *r); +#endif void mlk_poly_ntt_c(mlk_poly *r); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) void mlk_poly_invntt_tomont_c(mlk_poly *r); +#endif +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || !defined(MLK_CONFIG_NO_ENCAPS_API) void mlk_poly_tobytes_c(uint8_t r[MLKEM_POLYBYTES], const mlk_poly *a); +#endif +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) void mlk_poly_frombytes_c(mlk_poly *r, const uint8_t a[MLKEM_POLYBYTES]); +#endif void mlk_polyvec_basemul_acc_montgomery_cached_c( mlk_poly *r, const mlk_polyvec *a, const mlk_polyvec *b, const mlk_polyvec_mulcache *b_cache); @@ -52,22 +60,26 @@ void mlk_poly_mulcache_compute_c(mlk_poly_mulcache *x, const mlk_poly *a); void mlk_keccakf1600_permute_c(uint64_t *state); unsigned mlk_rej_uniform_c(int16_t *r, unsigned target, unsigned offset, const uint8_t *buf, unsigned buflen); +#if !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) void mlk_poly_compress_d4_c(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D4], const mlk_poly *a); -void mlk_poly_decompress_d4_c(mlk_poly *r, - const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4]); void mlk_poly_compress_d5_c(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D5], const mlk_poly *a); -void mlk_poly_decompress_d5_c(mlk_poly *r, - const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5]); void mlk_poly_compress_d10_c(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D10], const mlk_poly *a); -void mlk_poly_decompress_d10_c(mlk_poly *r, - const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10]); void mlk_poly_compress_d11_c(uint8_t r[MLKEM_POLYCOMPRESSEDBYTES_D11], const mlk_poly *a); +#endif /* !MLK_CONFIG_NO_ENCAPS_API || !MLK_CONFIG_NO_DECAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) +void mlk_poly_decompress_d4_c(mlk_poly *r, + const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D4]); +void mlk_poly_decompress_d5_c(mlk_poly *r, + const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D5]); +void mlk_poly_decompress_d10_c(mlk_poly *r, + const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D10]); void mlk_poly_decompress_d11_c(mlk_poly *r, const uint8_t a[MLKEM_POLYCOMPRESSEDBYTES_D11]); +#endif /* !MLK_CONFIG_NO_DECAPS_API */ #define CHECK(x) \ do \ @@ -190,6 +202,8 @@ static void generate_i16_array_single(int16_t *data, size_t len, size_t pos, data[pos] = value; } +#if defined(MLK_USE_NATIVE_INTT) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) static void generate_i16_array_constant(int16_t *data, size_t len, int16_t value) { @@ -199,6 +213,8 @@ static void generate_i16_array_constant(int16_t *data, size_t len, data[i] = value; } } +#endif /* MLK_USE_NATIVE_INTT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ /* This does not generate a uniformly random distribution, but it's * good enough for our test. @@ -229,7 +245,9 @@ static void generate_i16_array_ranged(int16_t *data, size_t len, int min_incl, MLK_USE_NATIVE_POLY_DECOMPRESS_D10 || \ MLK_USE_NATIVE_POLY_DECOMPRESS_D11 */ -#if defined(MLK_USE_NATIVE_POLY_TOBYTES) || \ +#if (defined(MLK_USE_NATIVE_POLY_TOBYTES) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API))) || \ defined(MLK_USE_NATIVE_POLY_COMPRESS_D4) || \ defined(MLK_USE_NATIVE_POLY_COMPRESS_D5) || \ defined(MLK_USE_NATIVE_POLY_COMPRESS_D10) || \ @@ -279,7 +297,8 @@ static int compare_u8_arrays(const uint8_t *a, const uint8_t *b, unsigned len, } return 1; } -#endif /* MLK_USE_NATIVE_POLY_TOBYTES || MLK_USE_NATIVE_POLY_COMPRESS_D4 || \ +#endif /* (MLK_USE_NATIVE_POLY_TOBYTES && (!MLK_CONFIG_NO_KEYPAIR_API || \ + !MLK_CONFIG_NO_ENCAPS_API)) || MLK_USE_NATIVE_POLY_COMPRESS_D4 || \ MLK_USE_NATIVE_POLY_COMPRESS_D5 || MLK_USE_NATIVE_POLY_COMPRESS_D10 \ || MLK_USE_NATIVE_POLY_COMPRESS_D11 */ @@ -368,7 +387,7 @@ static int test_native_poly_reduce(void) } #endif /* MLK_USE_NATIVE_POLY_REDUCE */ -#ifdef MLK_USE_NATIVE_POLY_TOMONT +#if defined(MLK_USE_NATIVE_POLY_TOMONT) && !defined(MLK_CONFIG_NO_KEYPAIR_API) static int test_poly_tomont_core(const int16_t *input, const char *test_name) { int ret = 1; @@ -422,7 +441,7 @@ static int test_native_poly_tomont(void) return 0; } -#endif /* MLK_USE_NATIVE_POLY_TOMONT */ +#endif /* MLK_USE_NATIVE_POLY_TOMONT && !MLK_CONFIG_NO_KEYPAIR_API */ #ifdef MLK_USE_NATIVE_NTT static int test_ntt_core(const int16_t *input, const char *test_name) @@ -484,7 +503,8 @@ static int test_native_ntt(void) } #endif /* MLK_USE_NATIVE_NTT */ -#ifdef MLK_USE_NATIVE_INTT +#if defined(MLK_USE_NATIVE_INTT) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) static int test_intt_core(const int16_t *input, const char *test_name) { int ret = 1; @@ -569,9 +589,12 @@ static int test_native_intt(void) return 0; } -#endif /* MLK_USE_NATIVE_INTT */ +#endif /* MLK_USE_NATIVE_INTT && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ -#ifdef MLK_USE_NATIVE_POLY_TOBYTES +#if defined(MLK_USE_NATIVE_POLY_TOBYTES) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) static int test_poly_tobytes_core(const int16_t *input, const char *test_name) { int ret = 1; @@ -629,9 +652,11 @@ static int test_native_poly_tobytes(void) return 0; } -#endif /* MLK_USE_NATIVE_POLY_TOBYTES */ +#endif /* MLK_USE_NATIVE_POLY_TOBYTES && (!MLK_CONFIG_NO_KEYPAIR_API || \ + !MLK_CONFIG_NO_ENCAPS_API) */ -#ifdef MLK_USE_NATIVE_POLY_FROMBYTES +#if defined(MLK_USE_NATIVE_POLY_FROMBYTES) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) static int test_poly_frombytes_core(const uint8_t *input_bytes, const char *test_name) { @@ -690,7 +715,8 @@ static int test_native_poly_frombytes(void) return 0; } -#endif /* MLK_USE_NATIVE_POLY_FROMBYTES */ +#endif /* MLK_USE_NATIVE_POLY_FROMBYTES && (!MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API) */ #ifdef MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED static int test_polyvec_basemul_core(const int16_t *a, const int16_t *b, @@ -1052,31 +1078,39 @@ static int test_native_rej_uniform(void) } #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D4 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D4) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) DEFINE_COMPRESS_TEST(4, MLKEM_POLYCOMPRESSEDBYTES_D4) #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D4 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D4) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) DEFINE_DECOMPRESS_TEST(4, MLKEM_POLYCOMPRESSEDBYTES_D4) #endif -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D10 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D10) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) DEFINE_COMPRESS_TEST(10, MLKEM_POLYCOMPRESSEDBYTES_D10) #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D10 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D10) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) DEFINE_DECOMPRESS_TEST(10, MLKEM_POLYCOMPRESSEDBYTES_D10) #endif #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D5 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D5) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) DEFINE_COMPRESS_TEST(5, MLKEM_POLYCOMPRESSEDBYTES_D5) #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D5 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D5) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) DEFINE_DECOMPRESS_TEST(5, MLKEM_POLYCOMPRESSEDBYTES_D5) #endif -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D11 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D11) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) DEFINE_COMPRESS_TEST(11, MLKEM_POLYCOMPRESSEDBYTES_D11) #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D11 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D11) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) DEFINE_DECOMPRESS_TEST(11, MLKEM_POLYCOMPRESSEDBYTES_D11) #endif #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ @@ -1090,7 +1124,7 @@ static int test_backend_units(void) CHECK(test_native_poly_reduce() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_TOMONT +#if defined(MLK_USE_NATIVE_POLY_TOMONT) && !defined(MLK_CONFIG_NO_KEYPAIR_API) CHECK(test_native_poly_tomont() == 0); #endif @@ -1098,15 +1132,19 @@ static int test_backend_units(void) CHECK(test_native_ntt() == 0); #endif -#ifdef MLK_USE_NATIVE_INTT +#if defined(MLK_USE_NATIVE_INTT) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) CHECK(test_native_intt() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_TOBYTES +#if defined(MLK_USE_NATIVE_POLY_TOBYTES) && \ + (!defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API)) CHECK(test_native_poly_tobytes() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_FROMBYTES +#if defined(MLK_USE_NATIVE_POLY_FROMBYTES) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) CHECK(test_native_poly_frombytes() == 0); #endif @@ -1127,31 +1165,39 @@ static int test_backend_units(void) #endif #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || (MLKEM_K == 2 || MLKEM_K == 3) -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D4 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D4) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) CHECK(test_native_poly_compress_d4() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D4 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D4) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) CHECK(test_native_poly_decompress_d4() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D10 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D10) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) CHECK(test_native_poly_compress_d10() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D10 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D10) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) CHECK(test_native_poly_decompress_d10() == 0); #endif #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 || MLKEM_K == 3 */ #if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D5 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D5) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) CHECK(test_native_poly_compress_d5() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D5 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D5) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) CHECK(test_native_poly_decompress_d5() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_COMPRESS_D11 +#if defined(MLK_USE_NATIVE_POLY_COMPRESS_D11) && \ + (!defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API)) CHECK(test_native_poly_compress_d11() == 0); #endif -#ifdef MLK_USE_NATIVE_POLY_DECOMPRESS_D11 +#if defined(MLK_USE_NATIVE_POLY_DECOMPRESS_D11) && \ + !defined(MLK_CONFIG_NO_DECAPS_API) CHECK(test_native_poly_decompress_d11() == 0); #endif #endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ diff --git a/test/test_vectors/expected_test_vectors.h b/test/test_vectors/expected_test_vectors.h new file mode 100644 index 0000000000..3da5f0cc52 --- /dev/null +++ b/test/test_vectors/expected_test_vectors.h @@ -0,0 +1,1251 @@ +/* + * Copyright (c) The mlkem-native project authors + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT + */ + +/* + * WARNING: This file is auto-generated from scripts/autogen + * in the mlkem-native repository. + * Do not modify it directly. + */ + +/* + * Generated with: + * d, z: consecutive 32-byte draws from a fresh notrandombytes + * stream (as consumed by crypto_kem_keypair). + * m: first 32-byte draw from a second, fresh + * notrandombytes stream (as consumed by crypto_kem_enc + * after randombytes_reset()). + */ + +#ifndef EXPECTED_TEST_VECTORS_H +#define EXPECTED_TEST_VECTORS_H + +#include + +/* keygen d (first 32 bytes of a fresh notrandombytes stream) */ +static const uint8_t test_vector_d[32] = { + 0x93, 0x4d, 0x60, 0xb3, 0x56, 0x24, 0xd7, 0x40, 0xb3, 0x0a, 0x7f, + 0x22, 0x7a, 0xf2, 0xae, 0x7c, 0x67, 0x8e, 0x4e, 0x04, 0xe1, 0x3c, + 0x5f, 0x50, 0x9e, 0xad, 0xe2, 0xb7, 0x9a, 0xea, 0x77, 0xe2}; +/* keygen z (next 32 bytes of the same stream) */ +static const uint8_t test_vector_z[32] = { + 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, 0x49, 0x37, 0xb0, + 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, 0x60, 0x69, + 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +/* encaps m (first 32 bytes of a fresh notrandombytes stream) */ +static const uint8_t test_vector_m[32] = { + 0x93, 0x4d, 0x60, 0xb3, 0x56, 0x24, 0xd7, 0x40, 0xb3, 0x0a, 0x7f, + 0x22, 0x7a, 0xf2, 0xae, 0x7c, 0x67, 0x8e, 0x4e, 0x04, 0xe1, 0x3c, + 0x5f, 0x50, 0x9e, 0xad, 0xe2, 0xb7, 0x9a, 0xea, 0x77, 0xe2}; + +#if MLK_CONFIG_PARAMETER_SET == 512 +static const uint8_t test_vector_pk[800] = { + 0x81, 0x88, 0x22, 0x13, 0x16, 0x88, 0xe3, 0x2b, 0x97, 0x3f, 0x28, 0x56, + 0x7c, 0xd3, 0xb7, 0xdf, 0x5a, 0xc5, 0xef, 0x7b, 0xb9, 0x3a, 0xc6, 0x40, + 0x71, 0x4a, 0x0d, 0x6b, 0x03, 0x59, 0x01, 0x91, 0x86, 0xcf, 0x53, 0xa4, + 0xeb, 0x95, 0x48, 0xdf, 0x2a, 0xaf, 0x63, 0x65, 0x6b, 0x79, 0xeb, 0x70, + 0xbd, 0x33, 0x80, 0x8f, 0x3a, 0x72, 0x2d, 0x85, 0x55, 0xeb, 0x31, 0x5f, + 0xa9, 0xb9, 0x12, 0xff, 0xb5, 0x36, 0xc5, 0x57, 0x83, 0x51, 0x17, 0xae, + 0x2e, 0xd0, 0x8a, 0x9e, 0x13, 0x38, 0xd1, 0xca, 0x59, 0xc5, 0x25, 0x35, + 0x11, 0x84, 0x0d, 0xa6, 0x79, 0x2b, 0x33, 0x41, 0x3d, 0x80, 0x32, 0x0e, + 0x0a, 0x47, 0x7a, 0x75, 0x69, 0x68, 0xf8, 0x07, 0x9d, 0xff, 0x66, 0x67, + 0x04, 0xb0, 0x9a, 0x85, 0xb2, 0xab, 0x7d, 0xbb, 0x22, 0x13, 0x71, 0x91, + 0x8f, 0x18, 0xb6, 0x60, 0xa3, 0xa3, 0x3c, 0x90, 0xb6, 0x01, 0x41, 0x63, + 0x5e, 0x6a, 0x3c, 0xc9, 0x10, 0x90, 0x1f, 0xf7, 0x04, 0x61, 0x31, 0x87, + 0x0b, 0x75, 0x07, 0x6f, 0xf6, 0x0c, 0x9a, 0x98, 0x6a, 0x71, 0x89, 0x42, + 0xb6, 0x14, 0x4b, 0xda, 0xc4, 0x7a, 0xfd, 0xcb, 0xac, 0x6d, 0x44, 0x19, + 0x93, 0xb3, 0xb7, 0x39, 0x02, 0x05, 0x77, 0xd5, 0x3a, 0xb4, 0xec, 0xc2, + 0xc6, 0xc5, 0xca, 0x3e, 0x22, 0xce, 0xc7, 0xac, 0x55, 0x4f, 0x37, 0x85, + 0x33, 0xa8, 0xb4, 0x96, 0x46, 0x35, 0xdc, 0x26, 0xbc, 0x2f, 0xe4, 0xc0, + 0x95, 0x65, 0x0b, 0x9b, 0xc2, 0xb8, 0x6c, 0x45, 0x16, 0x27, 0x6c, 0x31, + 0xc1, 0xa3, 0x7e, 0xf7, 0x0a, 0x03, 0x81, 0x28, 0x6f, 0x2a, 0x19, 0x3d, + 0xfa, 0x77, 0x9f, 0xc3, 0x3b, 0x02, 0x97, 0x8c, 0xae, 0xcb, 0xa4, 0x4e, + 0x82, 0x2b, 0x4c, 0x09, 0xa5, 0x68, 0x7a, 0xf8, 0x79, 0x49, 0xe8, 0x49, + 0xa5, 0xe6, 0x09, 0xea, 0xd3, 0xb2, 0x19, 0x61, 0x32, 0xad, 0x43, 0xb5, + 0x60, 0xd5, 0x99, 0xe4, 0x0a, 0x4b, 0x72, 0x68, 0x6e, 0x1b, 0x42, 0x92, + 0xe4, 0x1b, 0x91, 0xf6, 0x5a, 0x7c, 0x56, 0x79, 0x1b, 0xea, 0xc7, 0xbd, + 0x71, 0x4c, 0x91, 0x50, 0x29, 0x86, 0xa5, 0x78, 0xb8, 0x24, 0xea, 0x2e, + 0x35, 0x14, 0xbf, 0x35, 0x18, 0x02, 0x77, 0xb8, 0x15, 0x1b, 0x22, 0x3e, + 0xa7, 0xba, 0x1b, 0x00, 0x95, 0x6a, 0x4a, 0x44, 0x38, 0xca, 0x6c, 0x04, + 0x34, 0x92, 0x04, 0xaa, 0xb0, 0x19, 0x87, 0x6a, 0x4c, 0x56, 0x36, 0xa5, + 0xf7, 0xf4, 0x53, 0x77, 0xf5, 0x08, 0x43, 0x40, 0xc4, 0x50, 0x9a, 0x07, + 0x0e, 0x94, 0x8b, 0x82, 0x1c, 0x07, 0xcd, 0xa4, 0x2f, 0x87, 0xb2, 0x7a, + 0x81, 0x99, 0x30, 0x9e, 0x80, 0x88, 0xd1, 0x0c, 0xb9, 0x72, 0xa5, 0x99, + 0x50, 0xa8, 0x42, 0x03, 0x19, 0x4b, 0x52, 0x56, 0x16, 0x43, 0xe6, 0x64, + 0xab, 0xe8, 0x4e, 0x6a, 0xcc, 0x84, 0xae, 0x5a, 0x4d, 0x0c, 0x90, 0xaf, + 0x5f, 0x33, 0x44, 0xb5, 0x92, 0xc3, 0x90, 0x00, 0xc2, 0x9d, 0x19, 0x0b, + 0x41, 0x57, 0xbb, 0x30, 0x89, 0x69, 0x22, 0x62, 0xae, 0xa8, 0x41, 0xc5, + 0xbb, 0x83, 0xa5, 0xf5, 0xe3, 0x78, 0x19, 0xab, 0x65, 0xc0, 0xf2, 0x4e, + 0x1b, 0x21, 0x44, 0xa1, 0xe2, 0x35, 0x8f, 0x23, 0x89, 0xa4, 0x98, 0x32, + 0x1d, 0x05, 0x4e, 0xe8, 0x6c, 0x65, 0xc2, 0x97, 0x78, 0x8a, 0x65, 0x79, + 0x11, 0x75, 0x68, 0xe7, 0x34, 0x9e, 0xe0, 0xf2, 0xad, 0x9b, 0xe1, 0x2a, + 0xbc, 0x30, 0x5b, 0x10, 0x98, 0x7d, 0x06, 0xa6, 0xc9, 0xb7, 0x53, 0x7e, + 0x08, 0xb1, 0x7c, 0x75, 0x16, 0x22, 0x9d, 0x20, 0x71, 0xae, 0x41, 0x7c, + 0x51, 0x16, 0xc0, 0xb2, 0x26, 0x56, 0xd8, 0x02, 0x83, 0xaa, 0x4a, 0x93, + 0xe5, 0xc2, 0x66, 0xbe, 0x70, 0x6c, 0x5e, 0x69, 0xa6, 0x20, 0xac, 0x4b, + 0xab, 0x41, 0x4d, 0x2a, 0x54, 0x61, 0x68, 0xa1, 0x6d, 0xc6, 0xd2, 0xce, + 0x0f, 0x3c, 0xad, 0xcf, 0x60, 0x1e, 0x41, 0x70, 0xca, 0xa8, 0xaa, 0xbf, + 0xf3, 0x5a, 0x31, 0x52, 0xe6, 0x36, 0xb5, 0xbc, 0xaa, 0x7d, 0xda, 0xc4, + 0x70, 0xeb, 0xc0, 0xfa, 0xa1, 0x1c, 0x38, 0x48, 0xb3, 0xbb, 0xca, 0x36, + 0xa3, 0xa5, 0x77, 0x07, 0x7a, 0xc1, 0xb9, 0xec, 0xc9, 0x43, 0x77, 0x57, + 0x48, 0x94, 0x08, 0x04, 0x13, 0xc5, 0x1d, 0xec, 0xcb, 0xc1, 0xa8, 0xb0, + 0x9c, 0x40, 0x19, 0x75, 0xfb, 0xba, 0x72, 0x36, 0x9b, 0x0e, 0x37, 0x9b, + 0x98, 0xe6, 0x1e, 0xf9, 0x49, 0x8b, 0x84, 0xcb, 0xa3, 0x43, 0x1a, 0x13, + 0xe0, 0x5a, 0x56, 0x21, 0xfa, 0xb7, 0x58, 0x09, 0x2a, 0x89, 0x6a, 0x80, + 0x1f, 0x96, 0x98, 0x98, 0xb9, 0x92, 0x42, 0x80, 0x22, 0x9d, 0xda, 0x98, + 0xe5, 0x7b, 0x80, 0x0d, 0x23, 0xa7, 0x0d, 0xd2, 0x3d, 0x17, 0xc6, 0x06, + 0xe0, 0x33, 0x06, 0x5a, 0x1a, 0x31, 0x51, 0x62, 0x40, 0xe4, 0x4c, 0x0f, + 0x6b, 0xe2, 0x0f, 0x8e, 0x95, 0x22, 0x86, 0x5a, 0xa9, 0x4a, 0xa1, 0x29, + 0x91, 0x21, 0xb8, 0x34, 0x11, 0x97, 0x57, 0x03, 0x1a, 0xeb, 0x11, 0x35, + 0x66, 0xc6, 0xa8, 0xab, 0xc1, 0x56, 0x54, 0x0a, 0x06, 0x3a, 0x3c, 0x4b, + 0x21, 0xa8, 0x4b, 0x0f, 0x68, 0x14, 0x4d, 0xa2, 0x81, 0xa2, 0xf8, 0x0c, + 0xca, 0x2b, 0x75, 0x51, 0xe0, 0xb8, 0x55, 0x70, 0xbe, 0xfe, 0x95, 0x60, + 0x4f, 0x9b, 0x59, 0xd8, 0x7c, 0x94, 0x98, 0x03, 0x5a, 0xc3, 0x76, 0x3c, + 0x36, 0xe5, 0x75, 0xf3, 0xec, 0x82, 0x76, 0x41, 0x30, 0x87, 0x02, 0x20, + 0xb7, 0x1b, 0x56, 0xc5, 0x6c, 0xc0, 0x7b, 0xb3, 0x64, 0x14, 0xb8, 0x61, + 0x31, 0x42, 0x0a, 0x35, 0xa2, 0x56, 0x55, 0xd5, 0x6e, 0x63, 0x94, 0xad, + 0xf2, 0xd1, 0x42, 0x6c, 0xa6, 0x8a, 0x88, 0xde, 0x54, 0x2f, 0xa4, 0x44, + 0x1a, 0xd5, 0xd3, 0x82, 0x64, 0x48, 0x68, 0x53, 0x59, 0x0e, 0x7f, 0x72, + 0x3f, 0x91, 0xf2, 0x0c, 0x04, 0x0b, 0x49, 0x55}; +static const uint8_t test_vector_sk[1632] = { + 0xc5, 0xa1, 0xcb, 0x12, 0x1a, 0x88, 0x02, 0x36, 0x45, 0x5b, 0x8c, 0x04, + 0xd9, 0x67, 0x06, 0x89, 0x28, 0x32, 0xd1, 0x3a, 0x28, 0x80, 0x9a, 0x16, + 0xaa, 0xdb, 0x6a, 0x95, 0x28, 0x1b, 0x3e, 0xf0, 0x53, 0x38, 0x7a, 0x57, + 0xbe, 0x9a, 0xca, 0x6c, 0x7c, 0x8b, 0xf7, 0xc5, 0xa5, 0xa9, 0x30, 0x61, + 0x43, 0xb7, 0x2f, 0x74, 0x68, 0x0e, 0x10, 0xdc, 0x51, 0xb5, 0xb5, 0xa0, + 0x90, 0xa9, 0x0f, 0xd3, 0xe3, 0x39, 0xe1, 0xf5, 0x6a, 0xa2, 0xb0, 0x52, + 0x0a, 0x77, 0x5d, 0xdd, 0x41, 0x20, 0xbc, 0xf0, 0xa5, 0x41, 0x41, 0xc0, + 0x36, 0x0c, 0x72, 0x77, 0xb9, 0x2a, 0x3e, 0x76, 0x78, 0x13, 0x53, 0x41, + 0x8c, 0x9c, 0x87, 0xc5, 0xac, 0x2d, 0xc6, 0x3a, 0xaf, 0xaf, 0x16, 0xcd, + 0xcf, 0xab, 0xb2, 0x2a, 0x98, 0x6d, 0x54, 0xd4, 0x09, 0x31, 0xd4, 0x55, + 0xb0, 0xe3, 0x58, 0x31, 0xd2, 0x57, 0x0b, 0xe7, 0x07, 0xc7, 0x22, 0x73, + 0xc7, 0x89, 0x5b, 0x40, 0x63, 0x2d, 0x73, 0x5b, 0x23, 0x82, 0x96, 0x41, + 0x33, 0x89, 0x0f, 0xf3, 0x75, 0x85, 0xb1, 0xa0, 0xca, 0x22, 0xf5, 0x6b, + 0xee, 0x98, 0xc3, 0x99, 0xc5, 0x5e, 0xb5, 0x3b, 0x49, 0x00, 0xdc, 0x37, + 0x0e, 0x0c, 0x2f, 0x8a, 0xe4, 0x38, 0x90, 0xf3, 0x80, 0x05, 0x4a, 0x13, + 0xb7, 0xba, 0x37, 0x3e, 0x78, 0x7c, 0x12, 0x98, 0x71, 0x1e, 0xaa, 0x59, + 0x42, 0x00, 0xd0, 0x45, 0x05, 0x8f, 0x63, 0xa9, 0xb9, 0x58, 0x39, 0x38, + 0x27, 0x6c, 0x06, 0x46, 0xf1, 0xc4, 0x6c, 0x24, 0x7f, 0xf9, 0x6b, 0x41, + 0xdb, 0xd8, 0x52, 0x00, 0x76, 0x87, 0x36, 0x00, 0x01, 0x11, 0x7b, 0x9c, + 0x89, 0x97, 0x5a, 0xb6, 0x11, 0x20, 0x30, 0x8a, 0x35, 0x58, 0x16, 0x40, + 0xfc, 0xe2, 0xa4, 0x23, 0x18, 0x47, 0x48, 0x17, 0x69, 0x1f, 0x9a, 0x62, + 0x75, 0x69, 0x73, 0xef, 0x6c, 0x55, 0x11, 0x94, 0x3e, 0xc3, 0x26, 0x1c, + 0xf2, 0x97, 0xbf, 0x62, 0x4c, 0x75, 0xe9, 0xd1, 0xcc, 0xe9, 0xd2, 0x18, + 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 0xed, 0x4c, 0xaf, 0x79, 0x38, 0x5c, 0x3f, 0xc2, 0x3e, + 0x34, 0x16, 0x70, 0xe4, 0xd8, 0x2f, 0x14, 0xe1, 0x50, 0x90, 0x00, 0x9a, + 0xdc, 0xfb, 0xa5, 0x98, 0x7c, 0x14, 0xbc, 0xd2, 0xc1, 0x7a, 0x09, 0x5f, + 0x60, 0x06, 0x14, 0x62, 0xfb, 0x85, 0x81, 0x47, 0x5c, 0xdf, 0xe6, 0x9c, + 0x69, 0x49, 0xb3, 0x77, 0x62, 0x0c, 0x14, 0xd4, 0x9a, 0x7b, 0xca, 0xbb, + 0x2f, 0x64, 0x08, 0x35, 0xe7, 0x6f, 0x16, 0xe4, 0x68, 0x8b, 0x14, 0xa8, + 0x34, 0xd2, 0x2a, 0x10, 0x19, 0x5e, 0x79, 0x62, 0x19, 0x1d, 0x43, 0x27, + 0xe8, 0x3b, 0xcc, 0x99, 0x76, 0x67, 0x50, 0x00, 0xc1, 0x74, 0x48, 0xbf, + 0x84, 0xd5, 0x07, 0x00, 0xf6, 0x50, 0x68, 0x67, 0x85, 0xce, 0x2b, 0x56, + 0xce, 0x6c, 0xa3, 0x56, 0xfb, 0xb2, 0xa5, 0x06, 0xa2, 0x1e, 0x70, 0x90, + 0xb6, 0xb2, 0x97, 0x93, 0x1c, 0x79, 0x4f, 0xc3, 0x21, 0xd8, 0x57, 0xa9, + 0x81, 0x88, 0x22, 0x13, 0x16, 0x88, 0xe3, 0x2b, 0x97, 0x3f, 0x28, 0x56, + 0x7c, 0xd3, 0xb7, 0xdf, 0x5a, 0xc5, 0xef, 0x7b, 0xb9, 0x3a, 0xc6, 0x40, + 0x71, 0x4a, 0x0d, 0x6b, 0x03, 0x59, 0x01, 0x91, 0x86, 0xcf, 0x53, 0xa4, + 0xeb, 0x95, 0x48, 0xdf, 0x2a, 0xaf, 0x63, 0x65, 0x6b, 0x79, 0xeb, 0x70, + 0xbd, 0x33, 0x80, 0x8f, 0x3a, 0x72, 0x2d, 0x85, 0x55, 0xeb, 0x31, 0x5f, + 0xa9, 0xb9, 0x12, 0xff, 0xb5, 0x36, 0xc5, 0x57, 0x83, 0x51, 0x17, 0xae, + 0x2e, 0xd0, 0x8a, 0x9e, 0x13, 0x38, 0xd1, 0xca, 0x59, 0xc5, 0x25, 0x35, + 0x11, 0x84, 0x0d, 0xa6, 0x79, 0x2b, 0x33, 0x41, 0x3d, 0x80, 0x32, 0x0e, + 0x0a, 0x47, 0x7a, 0x75, 0x69, 0x68, 0xf8, 0x07, 0x9d, 0xff, 0x66, 0x67, + 0x04, 0xb0, 0x9a, 0x85, 0xb2, 0xab, 0x7d, 0xbb, 0x22, 0x13, 0x71, 0x91, + 0x8f, 0x18, 0xb6, 0x60, 0xa3, 0xa3, 0x3c, 0x90, 0xb6, 0x01, 0x41, 0x63, + 0x5e, 0x6a, 0x3c, 0xc9, 0x10, 0x90, 0x1f, 0xf7, 0x04, 0x61, 0x31, 0x87, + 0x0b, 0x75, 0x07, 0x6f, 0xf6, 0x0c, 0x9a, 0x98, 0x6a, 0x71, 0x89, 0x42, + 0xb6, 0x14, 0x4b, 0xda, 0xc4, 0x7a, 0xfd, 0xcb, 0xac, 0x6d, 0x44, 0x19, + 0x93, 0xb3, 0xb7, 0x39, 0x02, 0x05, 0x77, 0xd5, 0x3a, 0xb4, 0xec, 0xc2, + 0xc6, 0xc5, 0xca, 0x3e, 0x22, 0xce, 0xc7, 0xac, 0x55, 0x4f, 0x37, 0x85, + 0x33, 0xa8, 0xb4, 0x96, 0x46, 0x35, 0xdc, 0x26, 0xbc, 0x2f, 0xe4, 0xc0, + 0x95, 0x65, 0x0b, 0x9b, 0xc2, 0xb8, 0x6c, 0x45, 0x16, 0x27, 0x6c, 0x31, + 0xc1, 0xa3, 0x7e, 0xf7, 0x0a, 0x03, 0x81, 0x28, 0x6f, 0x2a, 0x19, 0x3d, + 0xfa, 0x77, 0x9f, 0xc3, 0x3b, 0x02, 0x97, 0x8c, 0xae, 0xcb, 0xa4, 0x4e, + 0x82, 0x2b, 0x4c, 0x09, 0xa5, 0x68, 0x7a, 0xf8, 0x79, 0x49, 0xe8, 0x49, + 0xa5, 0xe6, 0x09, 0xea, 0xd3, 0xb2, 0x19, 0x61, 0x32, 0xad, 0x43, 0xb5, + 0x60, 0xd5, 0x99, 0xe4, 0x0a, 0x4b, 0x72, 0x68, 0x6e, 0x1b, 0x42, 0x92, + 0xe4, 0x1b, 0x91, 0xf6, 0x5a, 0x7c, 0x56, 0x79, 0x1b, 0xea, 0xc7, 0xbd, + 0x71, 0x4c, 0x91, 0x50, 0x29, 0x86, 0xa5, 0x78, 0xb8, 0x24, 0xea, 0x2e, + 0x35, 0x14, 0xbf, 0x35, 0x18, 0x02, 0x77, 0xb8, 0x15, 0x1b, 0x22, 0x3e, + 0xa7, 0xba, 0x1b, 0x00, 0x95, 0x6a, 0x4a, 0x44, 0x38, 0xca, 0x6c, 0x04, + 0x34, 0x92, 0x04, 0xaa, 0xb0, 0x19, 0x87, 0x6a, 0x4c, 0x56, 0x36, 0xa5, + 0xf7, 0xf4, 0x53, 0x77, 0xf5, 0x08, 0x43, 0x40, 0xc4, 0x50, 0x9a, 0x07, + 0x0e, 0x94, 0x8b, 0x82, 0x1c, 0x07, 0xcd, 0xa4, 0x2f, 0x87, 0xb2, 0x7a, + 0x81, 0x99, 0x30, 0x9e, 0x80, 0x88, 0xd1, 0x0c, 0xb9, 0x72, 0xa5, 0x99, + 0x50, 0xa8, 0x42, 0x03, 0x19, 0x4b, 0x52, 0x56, 0x16, 0x43, 0xe6, 0x64, + 0xab, 0xe8, 0x4e, 0x6a, 0xcc, 0x84, 0xae, 0x5a, 0x4d, 0x0c, 0x90, 0xaf, + 0x5f, 0x33, 0x44, 0xb5, 0x92, 0xc3, 0x90, 0x00, 0xc2, 0x9d, 0x19, 0x0b, + 0x41, 0x57, 0xbb, 0x30, 0x89, 0x69, 0x22, 0x62, 0xae, 0xa8, 0x41, 0xc5, + 0xbb, 0x83, 0xa5, 0xf5, 0xe3, 0x78, 0x19, 0xab, 0x65, 0xc0, 0xf2, 0x4e, + 0x1b, 0x21, 0x44, 0xa1, 0xe2, 0x35, 0x8f, 0x23, 0x89, 0xa4, 0x98, 0x32, + 0x1d, 0x05, 0x4e, 0xe8, 0x6c, 0x65, 0xc2, 0x97, 0x78, 0x8a, 0x65, 0x79, + 0x11, 0x75, 0x68, 0xe7, 0x34, 0x9e, 0xe0, 0xf2, 0xad, 0x9b, 0xe1, 0x2a, + 0xbc, 0x30, 0x5b, 0x10, 0x98, 0x7d, 0x06, 0xa6, 0xc9, 0xb7, 0x53, 0x7e, + 0x08, 0xb1, 0x7c, 0x75, 0x16, 0x22, 0x9d, 0x20, 0x71, 0xae, 0x41, 0x7c, + 0x51, 0x16, 0xc0, 0xb2, 0x26, 0x56, 0xd8, 0x02, 0x83, 0xaa, 0x4a, 0x93, + 0xe5, 0xc2, 0x66, 0xbe, 0x70, 0x6c, 0x5e, 0x69, 0xa6, 0x20, 0xac, 0x4b, + 0xab, 0x41, 0x4d, 0x2a, 0x54, 0x61, 0x68, 0xa1, 0x6d, 0xc6, 0xd2, 0xce, + 0x0f, 0x3c, 0xad, 0xcf, 0x60, 0x1e, 0x41, 0x70, 0xca, 0xa8, 0xaa, 0xbf, + 0xf3, 0x5a, 0x31, 0x52, 0xe6, 0x36, 0xb5, 0xbc, 0xaa, 0x7d, 0xda, 0xc4, + 0x70, 0xeb, 0xc0, 0xfa, 0xa1, 0x1c, 0x38, 0x48, 0xb3, 0xbb, 0xca, 0x36, + 0xa3, 0xa5, 0x77, 0x07, 0x7a, 0xc1, 0xb9, 0xec, 0xc9, 0x43, 0x77, 0x57, + 0x48, 0x94, 0x08, 0x04, 0x13, 0xc5, 0x1d, 0xec, 0xcb, 0xc1, 0xa8, 0xb0, + 0x9c, 0x40, 0x19, 0x75, 0xfb, 0xba, 0x72, 0x36, 0x9b, 0x0e, 0x37, 0x9b, + 0x98, 0xe6, 0x1e, 0xf9, 0x49, 0x8b, 0x84, 0xcb, 0xa3, 0x43, 0x1a, 0x13, + 0xe0, 0x5a, 0x56, 0x21, 0xfa, 0xb7, 0x58, 0x09, 0x2a, 0x89, 0x6a, 0x80, + 0x1f, 0x96, 0x98, 0x98, 0xb9, 0x92, 0x42, 0x80, 0x22, 0x9d, 0xda, 0x98, + 0xe5, 0x7b, 0x80, 0x0d, 0x23, 0xa7, 0x0d, 0xd2, 0x3d, 0x17, 0xc6, 0x06, + 0xe0, 0x33, 0x06, 0x5a, 0x1a, 0x31, 0x51, 0x62, 0x40, 0xe4, 0x4c, 0x0f, + 0x6b, 0xe2, 0x0f, 0x8e, 0x95, 0x22, 0x86, 0x5a, 0xa9, 0x4a, 0xa1, 0x29, + 0x91, 0x21, 0xb8, 0x34, 0x11, 0x97, 0x57, 0x03, 0x1a, 0xeb, 0x11, 0x35, + 0x66, 0xc6, 0xa8, 0xab, 0xc1, 0x56, 0x54, 0x0a, 0x06, 0x3a, 0x3c, 0x4b, + 0x21, 0xa8, 0x4b, 0x0f, 0x68, 0x14, 0x4d, 0xa2, 0x81, 0xa2, 0xf8, 0x0c, + 0xca, 0x2b, 0x75, 0x51, 0xe0, 0xb8, 0x55, 0x70, 0xbe, 0xfe, 0x95, 0x60, + 0x4f, 0x9b, 0x59, 0xd8, 0x7c, 0x94, 0x98, 0x03, 0x5a, 0xc3, 0x76, 0x3c, + 0x36, 0xe5, 0x75, 0xf3, 0xec, 0x82, 0x76, 0x41, 0x30, 0x87, 0x02, 0x20, + 0xb7, 0x1b, 0x56, 0xc5, 0x6c, 0xc0, 0x7b, 0xb3, 0x64, 0x14, 0xb8, 0x61, + 0x31, 0x42, 0x0a, 0x35, 0xa2, 0x56, 0x55, 0xd5, 0x6e, 0x63, 0x94, 0xad, + 0xf2, 0xd1, 0x42, 0x6c, 0xa6, 0x8a, 0x88, 0xde, 0x54, 0x2f, 0xa4, 0x44, + 0x1a, 0xd5, 0xd3, 0x82, 0x64, 0x48, 0x68, 0x53, 0x59, 0x0e, 0x7f, 0x72, + 0x3f, 0x91, 0xf2, 0x0c, 0x04, 0x0b, 0x49, 0x55, 0xfa, 0x9f, 0x72, 0x93, + 0xa3, 0xf6, 0x5f, 0x79, 0x42, 0x19, 0x01, 0xc0, 0xa4, 0x13, 0x7b, 0xcb, + 0x17, 0x93, 0x28, 0x48, 0xb3, 0x01, 0x7b, 0xe7, 0xd0, 0x10, 0xfe, 0x07, + 0x10, 0xdd, 0x3d, 0x90, 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, + 0x49, 0x37, 0xb0, 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, + 0x60, 0x69, 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +static const uint8_t test_vector_ct[768] = { + 0xb0, 0x7d, 0x00, 0xe5, 0x1a, 0xac, 0x9d, 0x6b, 0xdb, 0xb7, 0x1e, 0xf0, + 0x00, 0xac, 0x9c, 0x70, 0x98, 0x2c, 0x97, 0xe3, 0xb8, 0xbf, 0xc8, 0x60, + 0xba, 0xec, 0x45, 0xbb, 0xc9, 0x83, 0xa2, 0xd3, 0xaa, 0x70, 0x2f, 0xfb, + 0xd0, 0x28, 0x08, 0x34, 0x54, 0x6e, 0x08, 0x36, 0x2c, 0x41, 0x9b, 0x95, + 0x23, 0x52, 0x6a, 0xf0, 0xe0, 0x60, 0x4a, 0x58, 0xf8, 0xcb, 0xf9, 0xa9, + 0xdd, 0xe4, 0xff, 0xae, 0xd4, 0x7e, 0xa1, 0xb3, 0x77, 0x6a, 0x8b, 0x00, + 0xe3, 0x33, 0x78, 0xd2, 0xaa, 0x99, 0xb9, 0x0b, 0xd9, 0xae, 0x41, 0x8c, + 0x59, 0x76, 0x4a, 0x12, 0xb7, 0x1f, 0xff, 0xd5, 0x34, 0xda, 0xc4, 0xd5, + 0xdc, 0xda, 0x4f, 0x57, 0xde, 0xca, 0xa4, 0xae,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, + 0x53, 0xf4, 0x51, 0x82, 0x76, 0x7a, 0x2b, 0xfa, 0x8b, 0x61, 0x21, 0x02, + 0x48, 0x76, 0xa7, 0x50, 0xd9, 0x8d, 0xe1, 0x23, 0x51, 0x34, 0x83, 0x24, + 0x83, 0xdf, 0x1e, 0x74, 0x23, 0xf8, 0xec, 0xb0, 0x34, 0x84, 0x5d, 0xfd, + 0xc0, 0x01, 0xb2, 0x51, 0x24, 0xe7, 0x49, 0xbc, 0x60, 0x36, 0x8a, 0xc4, + 0x6e, 0x55, 0xe4, 0x92, 0xfc, 0xbe, 0x67, 0x55, 0xae, 0x0a, 0x6a, 0x73, + 0xea, 0x8a, 0x96, 0x60, 0x60, 0xe9, 0x50, 0x57, 0x06, 0x7a, 0x54, 0xb7, + 0xcc, 0x5b, 0x9f, 0x96, 0xe3, 0x69, 0xcc, 0xd7, 0x9f, 0x8c, 0xc2, 0xf8, + 0xca, 0x63, 0xc2, 0xc4, 0x2b, 0x98, 0xa3, 0x44, 0xa9, 0xd1, 0x59, 0xb2, + 0xfb, 0x62, 0x2f, 0x0f, 0xcc, 0xf5, 0x89, 0x45, 0xd5, 0x91, 0x89, 0x96, + 0x9f, 0x0c, 0x07, 0x0d, 0x0d, 0xf8, 0xd0, 0xce, 0xef, 0x39, 0xef, 0x2e, + 0x67, 0xa3, 0x61, 0xc5, 0x99, 0x53, 0x0c, 0x7e, 0x49, 0x35, 0xab, 0xc0, + 0x51, 0xee, 0xc1, 0x1d, 0x8c, 0x11, 0xe8, 0xfa, 0xe7, 0x9f, 0x51, 0x95, + 0xc5, 0x30, 0x67, 0x1d, 0x5e, 0x8c, 0xdb, 0x4c, 0x54, 0x5a, 0x6b, 0x80, + 0x09, 0xef, 0xd7, 0xeb, 0x48, 0x8a, 0x93, 0xed, 0x7a, 0xb4, 0x31, 0x7b, + 0x04, 0x0f, 0x89, 0xc4, 0xab, 0xb8, 0x57, 0x86, 0xed, 0xdb, 0xea, 0x9c, + 0x36, 0x11, 0x81, 0xb6, 0xd9, 0x49, 0xf9, 0xae, 0xc7, 0x22, 0x91, 0x21, + 0xf1, 0xda, 0x8e, 0x85, 0xad, 0x50, 0xba, 0x96, 0x38, 0xb6, 0x3f, 0xc2, + 0x17, 0x8e, 0x31, 0x2e, 0xdb, 0x45, 0xc4, 0x4c, 0x10, 0xab, 0xeb, 0x95, + 0xd1, 0x98, 0x5f, 0x2f, 0x6f, 0x86, 0x94, 0x17, 0xe3, 0x5e, 0xd4, 0x62, + 0xc2, 0x72, 0xe3, 0x25, 0xb7, 0xe3, 0x60, 0x4d, 0x58, 0x35, 0xdd, 0x90, + 0x5c, 0x50, 0x95, 0xc8, 0xa5, 0xd1, 0xc6, 0x8f, 0x54, 0x9e, 0x04, 0x7c, + 0x81, 0x0e, 0xcf, 0xd4, 0xb7, 0xdf, 0xa5, 0x11, 0x62, 0x61, 0x46, 0x3e, + 0xb5, 0x98, 0xac, 0x91, 0x25, 0xb2, 0xce, 0x61, 0x59, 0x87, 0x84, 0x69, + 0x50, 0x70, 0xa4, 0xe4, 0x69, 0xb6, 0x20, 0xa1, 0x1a, 0xde, 0x77, 0x02, + 0x43, 0xe1, 0x55, 0x87, 0x46, 0x36, 0xf7, 0x54, 0x37, 0xc5, 0x3d, 0x03}; +static const uint8_t test_vector_ss[32] = { + 0x3f, 0xd5, 0xed, 0xe7, 0x0c, 0xb6, 0x62, 0x37, 0x9d, 0x80, 0x1b, + 0x38, 0x62, 0xb0, 0x38, 0xac, 0x07, 0x89, 0xfd, 0x1c, 0xcd, 0x4c, + 0x9a, 0x77, 0x9f, 0xcb, 0x01, 0x4f, 0x2d, 0x33, 0x19, 0x8a}; +#elif MLK_CONFIG_PARAMETER_SET == 768 +static const uint8_t test_vector_pk[1184] = { + 0x69, 0x3b, 0x4b, 0x7f, 0x22, 0x69, 0x8c, 0xc9, 0x1e, 0x65, 0xa1, 0x11, + 0x98, 0xe9, 0x44, 0x86, 0x97, 0x30, 0x8f, 0x39, 0xa1, 0xf7, 0x7c, 0xbe, + 0x0d, 0xf5, 0x32, 0x45, 0x62, 0x6f, 0x32, 0x35, 0x78, 0x06, 0xc6, 0x8e, + 0x4a, 0xb8, 0xb2, 0x18, 0x29, 0x58, 0xd0, 0xc4, 0x93, 0x39, 0xd0, 0xb8, + 0xc1, 0x53, 0x47, 0x65, 0x5b, 0x75, 0x62, 0x56, 0x93, 0x5b, 0x43, 0xcc, + 0xef, 0x66, 0xba, 0x7a, 0x78, 0x95, 0x3e, 0x5c, 0xa7, 0xac, 0xb3, 0x50, + 0xcc, 0xc8, 0x9a, 0x87, 0xc8, 0x63, 0x66, 0xc7, 0x7b, 0xf0, 0xc0, 0x1f, + 0x8f, 0x47, 0x2f, 0x22, 0xa8, 0x5a, 0x94, 0x70, 0xa8, 0x2e, 0xe0, 0x54, + 0xed, 0x95, 0x63, 0xc4, 0x0b, 0x62, 0xd9, 0xbb, 0xc4, 0xe4, 0x10, 0x76, + 0xbb, 0xe5, 0xb3, 0xf1, 0xb6, 0x0c, 0x2b, 0xa1, 0x65, 0x2f, 0xa7, 0xaa, + 0xc4, 0x4c, 0x6c, 0x26, 0xa0, 0x60, 0x8e, 0x15, 0x9a, 0x6a, 0x10, 0x49, + 0x23, 0xa6, 0x4c, 0xff, 0x90, 0x43, 0x5e, 0x1b, 0x23, 0x83, 0x63, 0x32, + 0x27, 0x67, 0x55, 0x21, 0x42, 0x76, 0x78, 0xc4, 0x63, 0x52, 0xe0, 0x5e, + 0xe8, 0xb7, 0x0a, 0xc5, 0x47, 0x45, 0x97, 0xc7, 0x33, 0x8b, 0x23, 0xa5, + 0x77, 0xf7, 0x51, 0x7c, 0x16, 0xc4, 0x84, 0xfa, 0x23, 0xed, 0x95, 0x48, + 0xb8, 0x1c, 0x35, 0xac, 0xa6, 0xa9, 0x36, 0x00, 0xb7, 0x66, 0x6b, 0x64, + 0x14, 0x36, 0x35, 0x2d, 0x07, 0xb8, 0xd9, 0xc7, 0x3d, 0xac, 0x46, 0x3f, + 0x94, 0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x82, 0x6e, 0xe3, 0x6b, 0xcd, 0x09, 0x2a, 0x6d, 0xe7, 0x7f, + 0x97, 0xb9, 0x25, 0xc2, 0xc2, 0xbd, 0x2e, 0x0b, 0xa9, 0x07, 0xe1, 0x68, + 0xd9, 0x71, 0xb8, 0xe1, 0x96, 0x49, 0x68, 0x64, 0x17, 0xe2, 0x05, 0xbb, + 0x55, 0xa0, 0x7a, 0x35, 0xd6, 0xb7, 0x35, 0x91, 0x57, 0x04, 0x8b, 0x89, + 0xec, 0x85, 0x15, 0x45, 0x37, 0xbf, 0x57, 0x49, 0x63, 0x85, 0x95, 0xcf, + 0xb6, 0x69, 0x0c, 0x04, 0x82, 0x5d, 0x17, 0x76, 0xaf, 0x5a, 0x49, 0x57, + 0xc0, 0x70, 0xb9, 0x7c, 0x39, 0x05, 0xa3, 0xbc, 0x65, 0xcd, 0x7b, 0x19, + 0xeb, 0x61, 0x95, 0x0b, 0x28, 0x52, 0x80, 0x83, 0x54, 0xad, 0x7a, 0xbd, + 0x8d, 0x4b, 0x01, 0xd9, 0xa0, 0xa6, 0x7e, 0x63, 0x89, 0xde, 0x40, 0x58, + 0xb2, 0x13, 0x7c, 0x7b, 0xf0, 0x09, 0x48, 0x2b, 0x1a, 0x25, 0x74, 0x85, + 0x4f, 0x36, 0x79, 0xca, 0xb9, 0x2d, 0x6d, 0x10, 0x06, 0xb8, 0x80, 0x3f, + 0xc2, 0xe6, 0x1e, 0x36, 0x4a, 0x50, 0x57, 0x67, 0x93, 0x2c, 0x7b, 0xba, + 0xd3, 0xc7, 0xb1, 0x68, 0x31, 0x15, 0x8f, 0x22, 0x41, 0xe9, 0xc1, 0x03, + 0xe2, 0xe2, 0xa7, 0x95, 0x74, 0x25, 0x83, 0x97, 0xb8, 0x89, 0x16, 0x14, + 0x97, 0x89, 0xb4, 0xb5, 0xb5, 0x9d, 0x94, 0xc6, 0x03, 0xb2, 0x4a, 0x2a, + 0x11, 0x22, 0x80, 0x14, 0x0a, 0x66, 0x91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, 0xc9, 0x13, + 0x15, 0x32, 0x80, 0x95, 0x21, 0x83, 0x8d, 0x52, 0x1b, 0xe9, 0x68, 0x1b, + 0x81, 0xdc, 0x2c, 0x11, 0x47, 0x5c, 0x60, 0x16, 0x2c, 0xc7, 0xc0, 0x7c, + 0x44, 0x39, 0x82, 0x5d, 0x32, 0x82, 0x04, 0x32, 0x20, 0x57, 0x78, 0x90, + 0x4e, 0xf2, 0x07, 0x95, 0xc5, 0x6e, 0x67, 0x11, 0x40, 0x6a, 0x88, 0x5b, + 0x8c, 0x90, 0x32, 0xe2, 0x72, 0x5b, 0xf6, 0x42, 0x1d, 0xc0, 0xa9, 0x10, + 0x7c, 0x8a, 0x2c, 0x9b, 0x49, 0x0f, 0xfb, 0x0a, 0xb2, 0x85, 0x79, 0xa8, + 0x19, 0x96, 0xc9, 0x2b, 0x64, 0x5c, 0x47, 0x11, 0x1c, 0x57, 0xb2, 0x10, + 0x06, 0x28, 0x76, 0x4c, 0x86, 0x0b, 0x9a, 0x12, 0x58, 0x94, 0xe5, 0x2a, + 0xde, 0x70, 0xc4, 0x64, 0xa4, 0x90, 0x2d, 0xc1, 0x67, 0x5b, 0x64, 0xae, + 0xa0, 0x1a, 0x7b, 0x30, 0x64, 0xb0, 0x99, 0xf4, 0x61, 0x53, 0xfa, 0x20, + 0x6d, 0xa5, 0x84, 0x98, 0xb2, 0x0f, 0x8b, 0x17, 0x17, 0x8b, 0x7a, 0x20, + 0xf0, 0x68, 0x00, 0xb9, 0xf0, 0xcf, 0x3f, 0x59, 0xc9, 0x12, 0xf5, 0x08, + 0x5c, 0xf3, 0x45, 0x05, 0x3b, 0x88, 0x95, 0xf4, 0xb2, 0xdb, 0x89, 0x8a, + 0x42, 0xb0, 0x58, 0xc5, 0xc6, 0x2e, 0xb0, 0xc5, 0x41, 0xad, 0xa4, 0x59, + 0xae, 0xf6, 0xbd, 0x99, 0x48, 0xb8, 0xff, 0x50, 0x95, 0x37, 0xab, 0x15, + 0x50, 0x30, 0x34, 0xd0, 0xa4, 0x10, 0xed, 0xaa, 0x03, 0xf4, 0xd4, 0x90, + 0xf1, 0x42, 0x1c, 0x0b, 0xec, 0x48, 0x38, 0x83, 0x25, 0xe4, 0x02, 0xa5, + 0x96, 0x14, 0x62, 0x68, 0x75, 0xcc, 0x8d, 0x2c, 0x48, 0x1d, 0xd9, 0x04, + 0x8a, 0x17, 0x7e, 0x9b, 0x90, 0x6f, 0xc4, 0x50, 0x38, 0x70, 0x61, 0x08, + 0x5b, 0xa7, 0x3e, 0x2f, 0x1b, 0x49, 0xe5, 0x8b, 0xca, 0x05, 0xbd, 0xa0, + 0x91, 0x73, 0xf8, 0x56, 0xdf, 0x8b, 0xc3, 0x8c}; +static const uint8_t test_vector_sk[2400] = { + 0xaf, 0x54, 0x39, 0xf3, 0xdb, 0x8d, 0x4a, 0x97, 0xc9, 0x75, 0xe4, 0x52, + 0xa5, 0xc3, 0x01, 0xa0, 0x16, 0x15, 0x03, 0x81, 0x2b, 0xb6, 0xa6, 0x99, + 0xf6, 0xaa, 0x40, 0xb7, 0x2c, 0x3f, 0x6c, 0x0a, 0xa5, 0xa0, 0x72, 0x04, + 0x89, 0x24, 0x0d, 0x47, 0x5c, 0x5a, 0x53, 0x02, 0x3b, 0x70, 0x59, 0x8f, + 0xbd, 0xeb, 0x20, 0x79, 0x2c, 0x8c, 0x8e, 0x26, 0x6a, 0xce, 0x08, 0x86, + 0x68, 0x32, 0x77, 0x87, 0x92, 0x31, 0xee, 0x93, 0x4b, 0x81, 0x4c, 0x6f, + 0x78, 0xa2, 0x81, 0x38, 0xba, 0x7c, 0x7c, 0xd9, 0x51, 0xe3, 0x38, 0x8b, + 0x70, 0xb5, 0x44, 0x2e, 0xe2, 0xaa, 0xdd, 0xd7, 0x81, 0xdd, 0xb1, 0xa2, + 0x7f, 0x39, 0xcd, 0x80, 0x82, 0x28, 0xb1, 0x21, 0xa1, 0x30, 0x49, 0x8c, + 0xa7, 0xc3, 0xb3, 0xe4, 0x31, 0xc0, 0x4e, 0xc0, 0xae, 0x3b, 0x6b, 0x0e, + 0xc5, 0xf1, 0x74, 0x21, 0x35, 0xaa, 0x9e, 0x45, 0x73, 0x7a, 0xa3, 0x20, + 0xd3, 0x8c, 0x4c, 0x2d, 0x40, 0x4d, 0x03, 0xe9, 0x04, 0xa1, 0xb6, 0xc9, + 0x92, 0x16, 0x7f, 0xb9, 0x28, 0x00, 0x21, 0xd8, 0xa3, 0x26, 0x59, 0x9a, + 0x1b, 0x7b, 0x72, 0xe4, 0x35, 0x54, 0x68, 0x94, 0x0e, 0x4f, 0x08, 0x61, + 0x26, 0x05, 0x35, 0x29, 0x29, 0x0f, 0xe8, 0xe1, 0xcd, 0x65, 0xf9, 0x46, + 0x7a, 0x05, 0x6d, 0x11, 0x87, 0x79, 0xc1, 0x95, 0x62, 0x39, 0x81, 0x22, + 0xb7, 0xf2, 0x29, 0x68, 0xb3, 0x62, 0x38, 0x28, 0xb7, 0x96, 0x35, 0x94, + 0xd7, 0x44, 0x5a, 0x7f, 0x3a, 0x4b, 0x04, 0x4b, 0xcf, 0x2c, 0xec, 0x0f, + 0xbb, 0x2a, 0x4d, 0xbc, 0x58, 0x1b, 0x41, 0x84, 0xb9, 0x0f, 0x70, 0xb5, + 0x02, 0xa0, 0x26, 0x02, 0xdc, 0x5e, 0x56, 0xc8, 0x7b, 0x98, 0x62, 0x2e, + 0xab, 0x24, 0x56, 0xec, 0xe4, 0x67, 0x4a, 0x0a, 0x1d, 0xee, 0xa1, 0x0d, + 0xf2, 0xd7, 0x1b, 0xdf, 0x36, 0x90, 0x9b, 0x91, 0xaf, 0xa8, 0x52, 0x2a, + 0x2d, 0x65, 0x81, 0xea, 0x72, 0x97, 0xe1, 0xdc, 0x94, 0x49, 0xc1, 0x9d, + 0x01, 0x25, 0x34, 0x96, 0xa7, 0x73, 0x26, 0xb0, 0xad, 0x78, 0xb6, 0xb4, + 0xfe, 0x13, 0x1b, 0xe1, 0xe6, 0x2e, 0xf0, 0x41, 0x71, 0x5f, 0x33, 0x0b, + 0x35, 0x01, 0x21, 0x3e, 0xa8, 0x6f, 0x62, 0x56, 0x02, 0xcb, 0x85, 0x4d, + 0xf9, 0xf8, 0xca, 0x48, 0xf8, 0x3c, 0xae, 0x26, 0x9b, 0x17, 0x8b, 0x09, + 0x96, 0xf8, 0x1e, 0xea, 0xf8, 0x25, 0x79, 0x67, 0x7a, 0xe5, 0x03, 0x99, + 0xbd, 0x51, 0x39, 0xf6, 0xd9, 0x45, 0x2e, 0x8b, 0x56, 0x27, 0x3a, 0x77, + 0x9c, 0x0c, 0x85, 0xd0, 0x10, 0x00, 0xcf, 0x93, 0xb0, 0x6f, 0xb1, 0x47, + 0xa2, 0x87, 0x32, 0xcc, 0x6c, 0x78, 0x94, 0x10, 0xb6, 0x5d, 0xa8, 0x77, + 0xa9, 0xc1, 0x11, 0x54, 0x80, 0x4f, 0xd6, 0xf5, 0x36, 0x21, 0xf2, 0x83, + 0x73, 0x82, 0xa1, 0x98, 0xf9, 0x1a, 0x20, 0x90, 0x04, 0xe8, 0xb1, 0xcf, + 0x0b, 0x0b, 0x31, 0x86, 0x17, 0x08, 0x15, 0x3c, 0x5a, 0x13, 0x47, 0x85, + 0xdb, 0x68, 0x9d, 0x7a, 0xe6, 0x7a, 0xf9, 0xc9, 0xb9, 0x23, 0x44, 0xce, + 0x08, 0x8b, 0x09, 0xf4, 0xdc, 0x11, 0x9d, 0x6a, 0x67, 0xd2, 0x2c, 0x29, + 0xc0, 0x88, 0x3e, 0x7a, 0xe8, 0x9c, 0x9b, 0x95, 0x38, 0x73, 0xea, 0x39, + 0x9b, 0x03, 0x85, 0x67, 0xc0, 0xca, 0x8e, 0x57, 0x66, 0x6d, 0x26, 0x60, + 0x3c, 0xf7, 0xcb, 0xfb, 0xac, 0x0c, 0x5e, 0x36, 0xb8, 0xd3, 0x91, 0x19, + 0xee, 0x5c, 0x01, 0xf2, 0x87, 0xc7, 0x4a, 0xf2, 0xb8, 0xca, 0x37, 0x58, + 0x96, 0x87, 0x0f, 0xfc, 0x39, 0x32, 0xbf, 0x38, 0x96, 0xa0, 0x8c, 0x8a, + 0xd9, 0x4a, 0xa0, 0x8b, 0xd8, 0x1e, 0x28, 0x97, 0xbf, 0x34, 0x98, 0x70, + 0x57, 0xfc, 0x08, 0xe9, 0x36, 0x7c, 0xf3, 0x3c, 0x62, 0x77, 0x2b, 0xad, + 0x79, 0x66, 0xb9, 0xff, 0xb1, 0xc8, 0x43, 0x21, 0x28, 0x33, 0x82, 0x2b, + 0x7c, 0x31, 0xb3, 0x8e, 0x14, 0x1c, 0x00, 0x7b, 0x85, 0x66, 0xf1, 0xad, + 0xa5, 0x34, 0x36, 0x77, 0x40, 0xaa, 0x89, 0x39, 0x50, 0xb7, 0x76, 0xaf, + 0x88, 0x1a, 0x4a, 0x13, 0x41, 0x36, 0x96, 0x51, 0x69, 0xf3, 0x79, 0x99, + 0x70, 0x0a, 0x8d, 0xd2, 0xc5, 0xa1, 0x40, 0x10, 0x52, 0xbe, 0x49, 0x88, + 0x0b, 0xa8, 0x2a, 0xd5, 0x6a, 0x7e, 0xc1, 0xfc, 0xc0, 0x58, 0x84, 0x4f, + 0xd3, 0xeb, 0x14, 0x08, 0x58, 0x07, 0x5c, 0x27, 0xae, 0xea, 0x8b, 0x1e, + 0xfa, 0x28, 0x9d, 0xbf, 0xbc, 0x12, 0x40, 0xf1, 0x14, 0x6d, 0x63, 0x47, + 0x98, 0x13, 0x4d, 0xde, 0x00, 0x74, 0xf0, 0xa4, 0xbc, 0xc5, 0x13, 0xc3, + 0x1a, 0x83, 0x09, 0x53, 0x03, 0x10, 0xc0, 0x62, 0xbf, 0x4c, 0x92, 0x3f, + 0xc1, 0x0c, 0x1c, 0xba, 0x98, 0x4e, 0x24, 0xb8, 0x81, 0xd3, 0x05, 0x92, + 0xcf, 0xb3, 0xb2, 0x89, 0x1b, 0xc3, 0x72, 0x14, 0x21, 0xb7, 0x23, 0x26, + 0x64, 0x63, 0x7e, 0x05, 0x97, 0x26, 0x72, 0xc8, 0x41, 0xcf, 0x73, 0x08, + 0x11, 0x09, 0x2d, 0x06, 0x54, 0x64, 0xb2, 0xe0, 0x4f, 0xc3, 0x11, 0x3f, + 0x2c, 0x36, 0x7d, 0x1f, 0x29, 0xa7, 0xb9, 0xe1, 0x30, 0xeb, 0xb0, 0xb2, + 0x42, 0x80, 0xb5, 0x45, 0xd6, 0x7e, 0x1e, 0x0a, 0x17, 0x09, 0x30, 0x2b, + 0x9e, 0xb9, 0x0c, 0x84, 0x8a, 0x8e, 0xd3, 0x42, 0x0b, 0xb1, 0xcc, 0x83, + 0xa4, 0xa7, 0x9f, 0x9d, 0xea, 0x6c, 0x70, 0x79, 0x76, 0x81, 0x00, 0x63, + 0xe2, 0x71, 0x0b, 0xb8, 0xd3, 0x34, 0x47, 0xc7, 0xba, 0xc9, 0x77, 0x41, + 0x57, 0x55, 0xa9, 0x5e, 0xe4, 0x76, 0xb8, 0x89, 0xc6, 0xb0, 0x0c, 0x7e, + 0x54, 0x98, 0x07, 0x2a, 0x37, 0x15, 0x82, 0x75, 0x3c, 0xf7, 0xf3, 0x88, + 0xc6, 0xf4, 0x32, 0xe8, 0x1b, 0xb6, 0x11, 0xf6, 0x94, 0x76, 0xa2, 0xab, + 0x3e, 0x71, 0x85, 0x38, 0x52, 0x4e, 0xb6, 0xe6, 0x5b, 0x67, 0x62, 0x6b, + 0x20, 0x6c, 0xb5, 0xf9, 0x30, 0x2f, 0x6e, 0x87, 0x9a, 0xe7, 0x6b, 0x64, + 0x6a, 0x48, 0x63, 0x16, 0x46, 0x60, 0x4a, 0xf8, 0xcd, 0x01, 0xb1, 0x36, + 0x82, 0x5b, 0x5a, 0xc7, 0x8a, 0x69, 0xc4, 0x52, 0x1b, 0x27, 0xe6, 0x84, + 0x79, 0x9b, 0x33, 0x62, 0x72, 0x02, 0x96, 0x16, 0x80, 0xf3, 0xdb, 0x18, + 0xbd, 0xc5, 0x52, 0x4b, 0x79, 0x65,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, 0xcc, + 0xef, 0x66, 0xba, 0x7a, 0x78, 0x95, 0x3e, 0x5c, 0xa7, 0xac, 0xb3, 0x50, + 0xcc, 0xc8, 0x9a, 0x87, 0xc8, 0x63, 0x66, 0xc7, 0x7b, 0xf0, 0xc0, 0x1f, + 0x8f, 0x47, 0x2f, 0x22, 0xa8, 0x5a, 0x94, 0x70, 0xa8, 0x2e, 0xe0, 0x54, + 0xed, 0x95, 0x63, 0xc4, 0x0b, 0x62, 0xd9, 0xbb, 0xc4, 0xe4, 0x10, 0x76, + 0xbb, 0xe5, 0xb3, 0xf1, 0xb6, 0x0c, 0x2b, 0xa1, 0x65, 0x2f, 0xa7, 0xaa, + 0xc4, 0x4c, 0x6c, 0x26, 0xa0, 0x60, 0x8e, 0x15, 0x9a, 0x6a, 0x10, 0x49, + 0x23, 0xa6, 0x4c, 0xff, 0x90, 0x43, 0x5e, 0x1b, 0x23, 0x83, 0x63, 0x32, + 0x27, 0x67, 0x55, 0x21, 0x42, 0x76, 0x78, 0xc4, 0x63, 0x52, 0xe0, 0x5e, + 0xe8, 0xb7, 0x0a, 0xc5, 0x47, 0x45, 0x97, 0xc7, 0x33, 0x8b, 0x23, 0xa5, + 0x77, 0xf7, 0x51, 0x7c, 0x16, 0xc4, 0x84, 0xfa, 0x23, 0xed, 0x95, 0x48, + 0xb8, 0x1c, 0x35, 0xac, 0xa6, 0xa9, 0x36, 0x00, 0xb7, 0x66, 0x6b, 0x64, + 0x14, 0x36, 0x35, 0x2d, 0x07, 0xb8, 0xd9, 0xc7, 0x3d, 0xac, 0x46, 0x3f, + 0x94, 0xab, 0xb2, 0xe5, 0x98, 0x96, 0x68, 0x19, 0x2f, 0x01, 0xb8, 0x9a, + 0xa8, 0x56, 0x85, 0x23, 0x65, 0x6b, 0x56, 0x07, 0x34, 0x3a, 0x07, 0x72, + 0xd2, 0x8c, 0x47, 0xeb, 0x43, 0x6a, 0xe0, 0x1b, 0x2b, 0x8d, 0x08, 0xc3, + 0xa1, 0x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, 0x7a, 0x35, 0xd6, 0xb7, 0x35, 0x91, 0x57, 0x04, 0x8b, 0x89, + 0xec, 0x85, 0x15, 0x45, 0x37, 0xbf, 0x57, 0x49, 0x63, 0x85, 0x95, 0xcf, + 0xb6, 0x69, 0x0c, 0x04, 0x82, 0x5d, 0x17, 0x76, 0xaf, 0x5a, 0x49, 0x57, + 0xc0, 0x70, 0xb9, 0x7c, 0x39, 0x05, 0xa3, 0xbc, 0x65, 0xcd, 0x7b, 0x19, + 0xeb, 0x61, 0x95, 0x0b, 0x28, 0x52, 0x80, 0x83, 0x54, 0xad, 0x7a, 0xbd, + 0x8d, 0x4b, 0x01, 0xd9, 0xa0, 0xa6, 0x7e, 0x63, 0x89, 0xde, 0x40, 0x58, + 0xb2, 0x13, 0x7c, 0x7b, 0xf0, 0x09, 0x48, 0x2b, 0x1a, 0x25, 0x74, 0x85, + 0x4f, 0x36, 0x79, 0xca, 0xb9, 0x2d, 0x6d, 0x10, 0x06, 0xb8, 0x80, 0x3f, + 0xc2, 0xe6, 0x1e, 0x36, 0x4a, 0x50, 0x57, 0x67, 0x93, 0x2c, 0x7b, 0xba, + 0xd3, 0xc7, 0xb1, 0x68, 0x31, 0x15, 0x8f, 0x22, 0x41, 0xe9, 0xc1, 0x03, + 0xe2, 0xe2, 0xa7, 0x95, 0x74, 0x25, 0x83, 0x97, 0xb8, 0x89, 0x16, 0x14, + 0x97, 0x89, 0xb4, 0xb5, 0xb5, 0x9d, 0x94, 0xc6, 0x03, 0xb2, 0x4a, 0x2a, + 0x11, 0x22, 0x80, 0x14, 0x0a, 0x66, 0x91, 0xb3, 0xc9, 0x90, 0xf7, 0x40, + 0x55, 0xb9, 0xa4, 0x6a, 0x12, 0xc0, 0xe9, 0xc3, 0xae, 0xdd, 0x4a, 0x3f, + 0x21, 0xa7, 0xa6, 0x47, 0x4b, 0x0a, 0x0e, 0xb7, 0x35, 0xbd, 0x45, 0x5d, + 0x77, 0x6c, 0xaf, 0xc0, 0x72, 0x3f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, 0x8f, 0x26, 0xc9, 0x6a, + 0x45, 0xc9, 0x08, 0xe1, 0x0b, 0xba, 0x27, 0x22, 0x54, 0x14, 0xc2, 0x12, + 0x24, 0x78, 0x13, 0x09, 0xd7, 0xa2, 0x64, 0x29, 0x01, 0x93, 0x81, 0x5d, + 0x64, 0x6a, 0x3d, 0x99, 0xaa, 0x8f, 0xdc, 0xa7, 0x35, 0xc9, 0x4c, 0x9c, + 0x07, 0x41, 0x27, 0x14, 0xd6, 0x50, 0x06, 0x22, 0x32, 0xa2, 0xab, 0x9a, + 0xa7, 0x66, 0xad, 0xa4, 0x7a, 0xaf, 0xba, 0x00, 0x83, 0xf6, 0x13, 0xa3, + 0x83, 0xc6, 0x8a, 0xd7, 0xc6, 0x50, 0x5e, 0x05, 0x2e, 0x9e, 0xd4, 0xc5, + 0xc0, 0x7a, 0x2f, 0x6d, 0x26, 0x7d, 0x35, 0xb7, 0x00, 0x73, 0x5c, 0x4a, + 0x99, 0xb7, 0xbc, 0x48, 0x25, 0x93, 0x8f, 0x55, 0x84, 0xbe, 0x87, 0x40, + 0x40, 0x54, 0x16, 0x4f, 0xab, 0x9f, 0x1e, 0xeb, 0xc8, 0xa3, 0xe0, 0xb5, + 0xa3, 0xa8, 0xcb, 0x34, 0x96, 0x6b, 0xa8, 0x4c, 0x32, 0x06, 0x38, 0xc5, + 0xa5, 0xc0, 0x4f, 0x33, 0xbc, 0x45, 0xfc, 0x3a, 0x62, 0x4b, 0x68, 0xa6, + 0x71, 0x60, 0xcd, 0x8e, 0xf2, 0xa3, 0xd2, 0xb4, 0x1f, 0xc4, 0xc9, 0x13, + 0x15, 0x32, 0x80, 0x95, 0x21, 0x83, 0x8d, 0x52, 0x1b, 0xe9, 0x68, 0x1b, + 0x81, 0xdc, 0x2c, 0x11, 0x47, 0x5c, 0x60, 0x16, 0x2c, 0xc7, 0xc0, 0x7c, + 0x44, 0x39, 0x82, 0x5d, 0x32, 0x82, 0x04, 0x32, 0x20, 0x57, 0x78, 0x90, + 0x4e, 0xf2, 0x07, 0x95, 0xc5, 0x6e, 0x67, 0x11, 0x40, 0x6a, 0x88, 0x5b, + 0x8c, 0x90, 0x32, 0xe2, 0x72, 0x5b, 0xf6, 0x42, 0x1d, 0xc0, 0xa9, 0x10, + 0x7c, 0x8a, 0x2c, 0x9b, 0x49, 0x0f, 0xfb, 0x0a, 0xb2, 0x85, 0x79, 0xa8, + 0x19, 0x96, 0xc9, 0x2b, 0x64, 0x5c, 0x47, 0x11, 0x1c, 0x57, 0xb2, 0x10, + 0x06, 0x28, 0x76, 0x4c, 0x86, 0x0b, 0x9a, 0x12, 0x58, 0x94, 0xe5, 0x2a, + 0xde, 0x70, 0xc4, 0x64, 0xa4, 0x90, 0x2d, 0xc1, 0x67, 0x5b, 0x64, 0xae, + 0xa0, 0x1a, 0x7b, 0x30, 0x64, 0xb0, 0x99, 0xf4, 0x61, 0x53, 0xfa, 0x20, + 0x6d, 0xa5, 0x84, 0x98, 0xb2, 0x0f, 0x8b, 0x17, 0x17, 0x8b, 0x7a, 0x20, + 0xf0, 0x68, 0x00, 0xb9, 0xf0, 0xcf, 0x3f, 0x59, 0xc9, 0x12, 0xf5, 0x08, + 0x5c, 0xf3, 0x45, 0x05, 0x3b, 0x88, 0x95, 0xf4, 0xb2, 0xdb, 0x89, 0x8a, + 0x42, 0xb0, 0x58, 0xc5, 0xc6, 0x2e, 0xb0, 0xc5, 0x41, 0xad, 0xa4, 0x59, + 0xae, 0xf6, 0xbd, 0x99, 0x48, 0xb8, 0xff, 0x50, 0x95, 0x37, 0xab, 0x15, + 0x50, 0x30, 0x34, 0xd0, 0xa4, 0x10, 0xed, 0xaa, 0x03, 0xf4, 0xd4, 0x90, + 0xf1, 0x42, 0x1c, 0x0b, 0xec, 0x48, 0x38, 0x83, 0x25, 0xe4, 0x02, 0xa5, + 0x96, 0x14, 0x62, 0x68, 0x75, 0xcc, 0x8d, 0x2c, 0x48, 0x1d, 0xd9, 0x04, + 0x8a, 0x17, 0x7e, 0x9b, 0x90, 0x6f, 0xc4, 0x50, 0x38, 0x70, 0x61, 0x08, + 0x5b, 0xa7, 0x3e, 0x2f, 0x1b, 0x49, 0xe5, 0x8b, 0xca, 0x05, 0xbd, 0xa0, + 0x91, 0x73, 0xf8, 0x56, 0xdf, 0x8b, 0xc3, 0x8c, 0xa9, 0x77, 0x15, 0xc9, + 0xaf, 0x11, 0xeb, 0xb5, 0x52, 0xf3, 0x04, 0x3e, 0x4c, 0x58, 0xca, 0xba, + 0xa5, 0x43, 0x41, 0xdd, 0x4c, 0x59, 0xf2, 0x9f, 0x1c, 0x5b, 0x0e, 0x12, + 0x5c, 0x19, 0x59, 0xd5, 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, + 0x49, 0x37, 0xb0, 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, + 0x60, 0x69, 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +static const uint8_t test_vector_ct[1088] = { + 0x12, 0xf9, 0x4e, 0xf4, 0xe4, 0xf6, 0xea, 0x11, 0x18, 0x3f, 0x2c, 0x50, + 0x0f, 0x9a, 0x72, 0x9e, 0x06, 0xb0, 0x4d, 0x83, 0x75, 0x3a, 0xa1, 0xb7, + 0xf6, 0xd0, 0x9e, 0x8a, 0xf2, 0x75, 0xbd, 0x0f, 0x4d, 0x06, 0x00, 0x82, + 0xd3, 0x1e, 0xe6, 0x02, 0x75, 0x19, 0xbb, 0xa7, 0x36, 0xb6, 0xbb, 0x66, + 0xa9, 0x8c, 0xcd, 0x71, 0x25, 0x93, 0x16, 0x9e, 0x17, 0x8b, 0x9c, 0xca, + 0x46, 0xa9, 0x1b, 0x85, 0x19, 0xfe, 0x52, 0xf1, 0xa1, 0xd0, 0x54, 0x57, + 0x39, 0x0b, 0x14, 0x7a, 0x72, 0x35, 0xd2, 0xd3, 0x42, 0x14, 0x2f, 0x78,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, 0x38, 0x34, 0x23, 0x31, + 0xa0, 0xbf, 0xea, 0x03, 0xbe, 0xe4, 0xf6, 0xbb, 0xe7, 0x79, 0x40, 0x9e, + 0xcf, 0x3e, 0xa7, 0x21, 0xcb, 0x6d, 0x7d, 0x19, 0x54, 0xc6, 0x14, 0x8b, + 0xe4, 0xec, 0xce, 0xd5, 0x79, 0x4d, 0x9d, 0xec, 0x29, 0x4a, 0xf1, 0x14, + 0x80, 0x5c, 0x93, 0x30, 0xb0, 0x13, 0xb8, 0x06, 0x3b, 0xac, 0x77, 0xde, + 0x7c, 0x8d, 0xd8, 0xc3, 0x05, 0x51, 0x7d, 0x6e, 0xdb, 0x31, 0x7e, 0x8e, + 0x55, 0xa3, 0xdf, 0xfe, 0xdd, 0xd6, 0xaf, 0x14, 0x7f, 0xba, 0xe1, 0x71, + 0x9a, 0x6f, 0x89, 0x48, 0x28, 0xbf, 0x9c, 0xfb, 0x9c, 0x13, 0xf1, 0xe6, + 0x1a, 0xc6, 0x5c, 0x5b, 0x9b, 0x5e, 0xbd, 0x0a}; +static const uint8_t test_vector_ss[32] = { + 0x0b, 0x1b, 0x32, 0xbe, 0x26, 0x24, 0x7c, 0xbc, 0xbe, 0x09, 0x16, + 0xf8, 0xb0, 0xb7, 0x29, 0x69, 0x9c, 0x32, 0xa9, 0x6d, 0x51, 0xef, + 0xa4, 0xa4, 0xcd, 0x5b, 0x28, 0x92, 0x39, 0xc8, 0x20, 0x7e}; +#elif MLK_CONFIG_PARAMETER_SET == 1024 +static const uint8_t test_vector_pk[1568] = { + 0x0a, 0xb5, 0x37, 0xed, 0x94, 0x0a, 0xea, 0x14, 0x1c, 0xef, 0xeb, 0xb9, + 0x82, 0x80, 0x03, 0x8b, 0xe1, 0x3f, 0x7c, 0xdc, 0x8d, 0x1e, 0xd2, 0x09, + 0xd3, 0x34, 0xb6, 0xae, 0xea, 0xa0, 0xed, 0xd2, 0x89, 0x71, 0xa5, 0x91, + 0x15, 0xc8, 0x7f, 0xc6, 0x29, 0x89, 0x98, 0x6c, 0x93, 0x57, 0x91, 0x84, + 0x06, 0x4b, 0x6b, 0xfe, 0x38, 0x2e, 0x29, 0x34, 0x87, 0x25, 0x90, 0x83, + 0x33, 0x17, 0x0b, 0x7e, 0xe4, 0x2e, 0xb2, 0xf8, 0xc2, 0x1f, 0x13, 0x20, + 0x15, 0x5a, 0xa3, 0x95, 0x91, 0x06, 0x38, 0x2a, 0x08, 0xfb, 0x52, 0x73, + 0x27, 0xa5, 0x42, 0x02, 0xe9, 0x1c, 0xeb, 0x39, 0x3e, 0x95, 0x2c, 0x6c, + 0x90, 0xc9, 0xcd, 0x23, 0x92, 0x7d, 0xb1, 0x88, 0xb3, 0x6d, 0x2a, 0x68, + 0x43, 0x9b, 0x59, 0xca, 0x96, 0x92, 0x9e, 0x93, 0x3f, 0x2d, 0x0a, 0xcd, + 0xcd, 0x6a, 0xc1, 0x0b, 0x3a, 0x64, 0x67, 0x2a, 0xa0, 0x31, 0x12, 0x92, + 0xf2, 0x37, 0x06, 0x35, 0x96, 0x88, 0x53, 0x44, 0x29, 0xc6, 0x91, 0x96, + 0x41, 0x8b, 0x6b, 0x5b, 0xa7, 0x69, 0x42, 0xb1, 0xa7, 0x72, 0x08, 0xcc, + 0x11, 0x0c, 0x2e, 0xa7, 0xc2, 0x9b, 0x3a, 0x09, 0x01, 0x27, 0x71, 0x48, + 0x99, 0x4b, 0x1c, 0x32, 0x3a, 0x0f, 0x79, 0xd3, 0x0c, 0xe7, 0xec, 0x76, + 0xdb, 0xbc, 0x76, 0xef, 0x9b, 0x14, 0x5a, 0xd0, 0x42, 0x95, 0xc3, 0x04, + 0xee, 0x42, 0x8d, 0x10, 0x6b, 0xa1, 0x89, 0x39, 0xbf, 0x3d, 0x00, 0xd0, + 0xe7, 0x75, 0xc4, 0x60, 0x69, 0x1b, 0x25, 0xf5, 0x35, 0x2e, 0xbc, 0x19, + 0xd1, 0xa1, 0xad, 0x9d, 0x70, 0x4e, 0xad, 0x8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0x61, 0x56, 0xbc, + 0x37, 0xc2, 0x77, 0x8b, 0x11, 0x16, 0x40, 0x75, 0x70, 0x01, 0xe1, 0x73, + 0x17, 0x97, 0xa3, 0x03, 0xe9, 0x85, 0x91, 0x96, 0x1d, 0x4f, 0x5a, 0x6f, + 0x78, 0x3a, 0x78, 0xbb, 0x31, 0x59, 0xb1, 0xe3, 0xba, 0x84, 0xa3, 0xa8, + 0x1b, 0xf4, 0x2b, 0x96, 0x9c, 0xc8, 0x10, 0x42, 0x19, 0xf8, 0x6a, 0xc8, + 0x40, 0xe2, 0x30, 0xa4, 0xa1, 0x29, 0x08, 0x96, 0x9f, 0xdd, 0xfb, 0xa9, + 0xfa, 0x7a, 0xab, 0xff, 0x38, 0x8b, 0xd6, 0x13, 0x1b, 0xe5, 0x5b, 0x83, + 0x0b, 0x33, 0x27, 0xc0, 0x29, 0xbe, 0x8d, 0xe8, 0x76, 0x68, 0x94, 0x3b, + 0x56, 0xe8, 0x5e, 0xe7, 0x93, 0x32, 0xc5, 0x31, 0x7b, 0xfa, 0x25, 0xa4, + 0x8d, 0xb3, 0x0c, 0xb7, 0xa5, 0xbb, 0xc2, 0x19, 0x15, 0xa4, 0x8c, 0x28, + 0x7e, 0x82, 0x14, 0x9a, 0xaa, 0x91, 0x71, 0x43, 0xa9, 0x8f, 0xb6, 0x30, + 0x9b, 0x07, 0x61, 0x0c, 0x07, 0x69, 0xd2, 0x97, 0x98, 0x9a, 0x5b, 0x35, + 0x4f, 0xb8, 0x2a, 0xb5, 0x09, 0x18, 0x62, 0x34, 0xc0, 0x81, 0xcb, 0xb6, + 0xbb, 0x73, 0x94, 0xe1, 0x9b, 0x3d, 0xd0, 0xf0, 0x99, 0xc3, 0x0a, 0xc7, + 0x0e, 0x3c, 0x49, 0x44, 0x78, 0x24, 0xe0, 0xd8, 0x15, 0x96, 0x72, 0x6f, + 0xfd, 0x37, 0x41, 0x29, 0x11, 0x4e, 0x65, 0x17, 0xce, 0xa6, 0xca, 0x23, + 0xa4, 0x14, 0x7a, 0x68, 0xc0, 0xcf, 0xba, 0x36, 0x10, 0x4f, 0x73, 0x9f, + 0xe5, 0x65, 0x2c, 0xe6, 0x5a, 0xa3, 0x81, 0x13, 0x5b, 0x07, 0x7b, 0x88, + 0x05, 0x53, 0x93, 0xfe, 0x52, 0x23, 0x75, 0x80, 0x26, 0x02, 0xd9, 0xac, + 0x88, 0x31, 0x40, 0xf1, 0x4c, 0x3e, 0x9a, 0xb0, 0xc0, 0x5b, 0xc1, 0xc1, + 0x9e, 0xd1, 0x5a, 0xc3, 0x0c, 0x54, 0x9e, 0x03, 0xac, 0xe4, 0x5a, 0x51, + 0x5d, 0xb7, 0x45, 0xff, 0x47, 0xa5, 0x9b, 0x23, 0x9c, 0x87, 0xb4, 0x62, + 0x9d, 0xb6, 0x6d, 0xdc, 0x86, 0x22, 0x1a, 0x50, 0x2c, 0x65, 0x06, 0x19, + 0xa0, 0x4c, 0xa1, 0xe3, 0x21, 0x8f, 0x8b, 0xe6, 0x31, 0x84, 0xa4, 0xa7, + 0x21, 0xfa, 0x9c, 0x76, 0x74, 0x18, 0xc6, 0x85, 0x0c, 0x6f, 0x43, 0x0d, + 0x91, 0x43, 0x16, 0x0e, 0x7c, 0x72, 0x78, 0x42, 0x1e, 0x16, 0x1c, 0x37, + 0xde, 0xd7, 0x16, 0xf9, 0x82, 0x6d, 0x13, 0xb0, 0xb8, 0xc1, 0xd2, 0x7f, + 0x08, 0xba, 0x19, 0xd3, 0xf1, 0x6d, 0x67, 0x17, 0x1f, 0x9e, 0xea, 0x41, + 0x6a, 0xb3, 0x79, 0x09, 0x3b, 0x8c, 0xb6, 0xf1, 0x82, 0xe4, 0xa3, 0x08, + 0xe0, 0xaa, 0x76, 0x12, 0x30, 0xbd, 0x46, 0x40, 0x10, 0x2d, 0xfb, 0x2c, + 0x89, 0x36, 0x14, 0x8c, 0x69, 0x83, 0x00, 0x41, 0x46, 0x6f, 0x07, 0x87, + 0xe6, 0x43, 0x36, 0x02, 0xe4, 0x5c, 0xb3, 0xa0, 0xb8, 0x1f, 0x66, 0x10, + 0xbd, 0x09, 0xca, 0x5b, 0x86, 0x09, 0x3f, 0x13, 0x43, 0xa3, 0x24, 0x93, + 0xe9, 0x92, 0xcb, 0x00, 0x59, 0x81, 0xc1, 0x06, 0x21, 0xe6, 0x86, 0xbd, + 0xa5, 0xa5, 0x84, 0xe0, 0xa0, 0x43, 0x60, 0xc8, 0x61, 0xf9, 0x97, 0x50, + 0x33, 0xd4, 0x3b, 0x0a, 0x62, 0x9e, 0x58, 0xfc, 0xa8, 0x95, 0xc7, 0x0e, + 0xa1, 0x75, 0x81, 0xf9, 0xb6, 0x3e, 0x81, 0x76, 0x57, 0x3e, 0xec, 0x38, + 0x9f, 0x48, 0x64, 0x3d, 0x63, 0x56, 0xe9, 0x88, 0x86, 0x90, 0xe3, 0x13, + 0xff, 0xd1, 0x1b, 0x6c, 0xea, 0x7d, 0xe4, 0x44, 0x0c, 0x8a, 0xb2, 0x72, + 0x3d, 0x16, 0x67, 0x57, 0x19, 0x6e, 0x9c, 0x2c, 0x88, 0xc3, 0x90, 0x1b, + 0x42, 0xc3, 0x81, 0x6b, 0x78, 0x5d, 0xda, 0x41, 0x85, 0x34, 0xac, 0x16, + 0xa4, 0x98, 0xad, 0x6b, 0xe6, 0x05, 0xcb, 0xa1, 0xab, 0x8f, 0xf8, 0x95, + 0x25, 0xd9, 0x9b, 0x93, 0x38, 0xc4, 0x2f, 0x55, 0x35, 0xea, 0x85, 0xb1, + 0x4e, 0xda, 0x15, 0xe2, 0x94, 0x15, 0x3b, 0x13, 0x7b, 0x79, 0x7b, 0x72, + 0xd7, 0x28, 0x36, 0x41, 0x71, 0x04, 0x2f, 0x29, 0x8a, 0x91, 0x56, 0x1b, + 0xc8, 0xdc, 0x0a, 0xe5, 0x88, 0x7d, 0x0a, 0xac, 0xbd, 0xd3, 0xcc, 0x9d, + 0x5e, 0x6c, 0x37, 0xd4, 0x27, 0x66, 0xa4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0xb4, + 0x52, 0xc3, 0xaf, 0x69, 0x06, 0x0c, 0x53, 0x48, 0xbf, 0x9a, 0xdb, 0x1e, + 0x9d, 0x46, 0x7a, 0x1d, 0xb2, 0x33, 0xbb, 0x20, 0x43, 0x54, 0xea, 0x45, + 0x87, 0xd6, 0x49, 0xfb, 0x7c, 0xb5, 0x6b, 0x63, 0x78, 0x12, 0x9a, 0xcd, + 0xa6, 0x91, 0x4b, 0x5e, 0x20, 0xaa, 0x8a, 0x56, 0x42, 0x84, 0xab, 0x2f, + 0x7f, 0x0a, 0xb2, 0x82, 0x23, 0x3d, 0x6f, 0x11, 0x74, 0xf1, 0x44, 0x81, + 0x22, 0xca, 0x97, 0x42, 0x96, 0x50, 0x47, 0xf6, 0x62, 0xde, 0x37, 0x4b, + 0x86, 0x48, 0x49, 0x68, 0x7c, 0x7a, 0x6c, 0x90, 0x43, 0x19, 0x72, 0xbb, + 0x98, 0xca, 0x69, 0xa8, 0x46, 0x3a, 0x73, 0xe0, 0x3e, 0x1c, 0x53, 0x2c, + 0xb6, 0x92, 0x88, 0x3b, 0x4c, 0x9e, 0x8d, 0xfc, 0xc1, 0x49, 0x65, 0x35, + 0x5e, 0xc7, 0x0b, 0xc0, 0x1c, 0x22, 0x90, 0xb8, 0x79, 0x64, 0x0a, 0x4d, + 0x6e, 0xdc, 0xb0, 0x91, 0xeb, 0x02, 0xb9, 0xb6, 0xa1, 0x07, 0x62, 0x2b, + 0x7f, 0x93, 0x57, 0xce, 0x98, 0xb1, 0x3e, 0xa1, 0xa9, 0x17, 0xda, 0xc4, + 0x7b, 0x67, 0x8a, 0x15, 0x92, 0x58, 0xf7, 0x16, 0x00, 0xb9, 0xfc, 0x9e, + 0xa0, 0xda, 0x1b, 0x1f, 0xda, 0x7d, 0xab, 0xd2, 0xac, 0xec, 0x5a, 0x87, + 0xd0, 0xb2, 0xc7, 0x5b, 0xa4, 0x45, 0xd8, 0x59, 0x65, 0x19, 0xbb, 0x80, + 0x9a, 0xaa, 0x88, 0xf7, 0x31, 0x99, 0x43, 0x01, 0x45, 0x6e, 0x0b, 0x66, + 0x05, 0xf5, 0x7b, 0xaf, 0x80, 0xb3, 0x3a, 0xf4, 0x23, 0xea, 0xd6, 0x60, + 0xf6, 0x73, 0xaa, 0x0e, 0x65, 0x68, 0x57, 0x41, 0x53, 0xfa, 0xb5, 0x62, + 0x28, 0xae, 0xac, 0x1a, 0x1c, 0xa0, 0xa2, 0x87, 0x5f, 0xb7, 0x5c, 0xc3, + 0xf3, 0xb2, 0xf4, 0x2a, 0x1a, 0x3c, 0xbf, 0xfa, 0x1b, 0x90, 0x21, 0x9a, + 0xc7, 0x77, 0xe3, 0x09, 0xd9, 0xcd, 0xcd, 0xcf}; +static const uint8_t test_vector_sk[3168] = { + 0xb7, 0x57, 0x8f, 0x5b, 0xdb, 0xa5, 0x1e, 0x1c, 0x9c, 0xd3, 0x1c, 0xaf, + 0xe3, 0xe1, 0x78, 0x12, 0x85, 0x74, 0xb8, 0xc5, 0x17, 0x11, 0xc6, 0x9e, + 0x5c, 0x29, 0x19, 0x2b, 0xe4, 0x39, 0x22, 0xcb, 0x26, 0xf8, 0x89, 0x9e, + 0x3c, 0xaa, 0x83, 0xc7, 0x09, 0x69, 0xbd, 0x2c, 0x8c, 0x78, 0xf7, 0x11, + 0xfe, 0x2b, 0xb1, 0x8d, 0x08, 0xa2, 0xd7, 0x45, 0x0b, 0xb1, 0xa0, 0x43, + 0xfa, 0x76, 0x4e, 0xe2, 0x4b, 0x54, 0x34, 0xc3, 0xb3, 0xd0, 0x6c, 0xca, + 0xfa, 0x44, 0x92, 0x51, 0xcc, 0xbf, 0x3d, 0x30, 0x0a, 0x92, 0xd5, 0x2f, + 0xcd, 0x55, 0x26, 0xb1, 0x75, 0x4f, 0xec, 0x56, 0x35, 0x79, 0x91, 0xb3, + 0x05, 0x4a, 0x71, 0xee, 0x98, 0x8f, 0x96, 0x44, 0x90, 0x22, 0x44, 0x9d, + 0x80, 0x96, 0x93, 0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xbd, 0xed, 0x1c, 0x77, 0x7d, 0x5b, 0x4b, + 0x3d, 0x8b, 0x05, 0xd9, 0x90, 0x78, 0x74, 0xc1, 0x44, 0xe8, 0x4b, 0xb2, + 0x77, 0x79, 0x20, 0xd4, 0xc5, 0xac, 0xba, 0x64, 0x9e, 0x9c, 0x56, 0xb3, + 0xf0, 0x45, 0x93, 0x05, 0xd5, 0x72, 0x63, 0xdb, 0x99, 0x46, 0x70, 0xb8, + 0x5c, 0x8c, 0x26, 0x70, 0x16, 0x98, 0x7c, 0x9c, 0x27, 0xa1, 0xf8, 0xc2, + 0x69, 0xc2, 0x9b, 0xaa, 0xcb, 0x3b, 0xdf, 0xb6, 0x24, 0x34, 0xc1, 0x6a, + 0x9a, 0xd4, 0x76, 0x7e, 0x63, 0xad, 0x5d, 0xda, 0xb8, 0x8e, 0x69, 0x5c, + 0xc8, 0x8a, 0x94, 0xdd, 0x5a, 0x03, 0x9e, 0x21, 0x2d, 0xb8, 0xfc, 0x87, + 0xbd, 0xe8, 0x0f, 0xd0, 0xa0, 0x86, 0x7d, 0x3a, 0x8a, 0x0a, 0x62, 0xcf, + 0xa1, 0x94, 0x05, 0x62, 0xc1, 0x44, 0xa0, 0x74, 0x53, 0x90, 0x55, 0xb2, + 0x9e, 0x12, 0xc9, 0x64, 0x87, 0x48, 0x39, 0x95, 0x1c, 0xd9, 0x60, 0x98, + 0xb5, 0x98, 0x1b, 0x42, 0x20, 0x9f, 0x87, 0x14, 0x02, 0xfb, 0x47, 0x40, + 0xde, 0x51, 0x12, 0x49, 0x27, 0x5b, 0xd1, 0x6b, 0xc3, 0x68, 0x82, 0xc4, + 0xec, 0x9c, 0xac, 0x90, 0x0c, 0x86, 0x46, 0xd0, 0xce, 0x93, 0x6a, 0x66, + 0x2e, 0xeb, 0x5a, 0xc5, 0xcc, 0x6d, 0x52, 0x55, 0x81, 0x58, 0x7a, 0x1b, + 0xbb, 0x4a, 0x41, 0x44, 0x60, 0x5f, 0x94, 0xc1, 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6a, + 0x4f, 0x5b, 0xa3, 0xc9, 0x85, 0xbe, 0x87, 0x07, 0x04, 0x2a, 0x88, 0xce, + 0x00, 0xe3, 0x3f, 0x19, 0x20, 0x90, 0xaa, 0x08, 0x47, 0x68, 0x79, 0x80, + 0xb9, 0xf6, 0x8c, 0x20, 0x11, 0x69, 0x83, 0x80, 0x50, 0x22, 0xa0, 0x04, + 0xf2, 0xb8, 0x6b, 0x05, 0x4a, 0xaf, 0x62, 0x87, 0x5c, 0xa5, 0x28, 0x76, + 0x3d, 0xb8, 0x70, 0xe5, 0xf1, 0x0d, 0x34, 0x71, 0xa9, 0x60, 0x63, 0xa6, + 0xdd, 0x06, 0x84, 0xbf, 0x5c, 0x7e, 0xe4, 0x63, 0x22, 0x8f, 0x6b, 0x29, + 0x23, 0x07, 0x54, 0xf8, 0x40, 0x5e, 0x70, 0x83, 0x4e, 0x2c, 0x5a, 0x47, + 0xae, 0x64, 0x4a, 0x27, 0xbb, 0x96, 0x6e, 0x57, 0x79, 0x58, 0xb0, 0x7b, + 0xfb, 0xca, 0xad, 0x37, 0x4a, 0x0e, 0xb0, 0x48, 0x00, 0x50, 0x35, 0xbf, + 0x36, 0xf7, 0x2c, 0xc6, 0x17, 0x0a, 0x61, 0x2a, 0xc9, 0xde, 0xa0, 0x8a, + 0x43, 0x08, 0xa5, 0xbf, 0x95, 0x60, 0x1d, 0x99, 0x43, 0x69, 0x9c, 0x63, + 0x31, 0x04, 0x48, 0x69, 0xd2, 0x9a, 0x61, 0xd1, 0x5b, 0xa6, 0xc5, 0x12, + 0x2b, 0xf4, 0x0f, 0x66, 0x54, 0x3f, 0x5d, 0x65, 0x2a, 0x46, 0xe9, 0x2e, + 0x08, 0x64, 0x41, 0x30, 0xb4, 0x05, 0x25, 0x04, 0x92, 0x06, 0x83, 0x55, + 0xa7, 0x03, 0x32, 0x2f, 0x48, 0x48, 0xcd, 0x93, 0xc1, 0x3b, 0xa2, 0x8d, + 0xf5, 0xe1, 0xbb, 0xb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xa3, 0x25, 0x4a, 0x04, 0xa2, 0x9c, + 0x9e, 0x38, 0xc7, 0x9e, 0x42, 0xae, 0x88, 0x4b, 0x2a, 0x2a, 0x6b, 0xce, + 0x30, 0x57, 0x19, 0x21, 0xc5, 0x7e, 0x1a, 0x95, 0xa9, 0x73, 0x85, 0x30, + 0x8c, 0x8c, 0x40, 0x52, 0x95, 0x86, 0xe9, 0x75, 0x78, 0xec, 0xe4, 0xac, + 0x6f, 0x52, 0x9b, 0x7f, 0xb5, 0x1e, 0x9f, 0x7a, 0x09, 0xac, 0xa0, 0x9a, + 0x8a, 0x76, 0xcb, 0x87, 0xc0, 0xc5, 0xd3, 0x61, 0xa7, 0x70, 0xbb, 0xb1, + 0xa8, 0x52, 0x1e, 0xba, 0x78, 0x59, 0xdb, 0x82, 0xc2, 0xd6, 0xe5, 0xbd, + 0x86, 0xa7, 0x7e, 0x08, 0xf2, 0xb4, 0x5a, 0x38, 0x71, 0x45, 0x87, 0x2d, + 0x54, 0x85, 0x06, 0xf8, 0xfa, 0x84, 0xe2, 0xd0, 0x93, 0xc4, 0x43, 0x2a, + 0x18, 0x43, 0x89, 0x82, 0x12, 0x28, 0x86, 0xf5, 0x67, 0x2a, 0x53, 0x23, + 0xe5, 0x51, 0x83, 0x2f, 0xc2, 0x36, 0x89, 0xc8, 0x75, 0x96, 0xdb, 0x33, + 0xad, 0x2c, 0x29, 0x00, 0x68, 0x93, 0xf8, 0xe2, 0x11, 0x53, 0x43, 0x36, + 0xe0, 0x37, 0x52, 0x2e, 0x84, 0x1d, 0xde, 0xa0, 0xba, 0xd2, 0xe2, 0x8e, + 0x7d, 0x63, 0x8c, 0x94, 0xc9, 0x0b, 0x83, 0x39, 0xbd, 0xce, 0x87, 0x7d, + 0xce, 0x8b, 0x6e, 0x14, 0x60, 0xac, 0xd4, 0xf5, 0x1a, 0x29, 0xd6, 0x08, + 0x4a, 0xa8, 0x7d, 0xe4, 0xb3, 0x6a, 0xdd, 0x92, 0xce, 0x41, 0x63, 0x1a, + 0x64, 0xb7, 0x18, 0x5f, 0x9a, 0x8f, 0xc7, 0xa0, 0x2a, 0x5d, 0xa8, 0x91, + 0x11, 0x23, 0x5f, 0x95, 0x84, 0xbd, 0x98, 0x62, 0x5e, 0xa2, 0x03, 0x25, + 0xee, 0x90, 0x22, 0x05, 0xfa, 0x98, 0x6c, 0x18, 0x9b, 0xda, 0xc2, 0x58, + 0x76, 0x23, 0x11, 0xb6, 0xc3, 0x98, 0x37, 0xe7, 0xbc, 0x86, 0x95, 0x4a, + 0xb5, 0x88, 0x63, 0xcb, 0xdb, 0xb5, 0x43, 0x05, 0x8d, 0x04, 0xa5, 0x40, + 0xaf, 0x64, 0xb7, 0x3a, 0x89, 0x10, 0x76, 0x57, 0x4c, 0xbc, 0xcb, 0x82, + 0xda, 0xa0, 0xc7, 0x48, 0x2b, 0x18, 0xab, 0xb5, 0x2e, 0x7f, 0x62, 0x3d, + 0x05, 0x8b, 0xb7, 0x6b, 0xe6, 0x77, 0x54, 0xf6, 0x13, 0x28, 0x87, 0xad, + 0x7f, 0x33, 0x97, 0x64, 0x15, 0x51, 0xe6, 0xb8, 0x0a, 0x9f, 0xcb, 0x83, + 0xa0, 0xf0, 0x36, 0xc4, 0x0b, 0x53, 0xa2, 0xf6, 0xb6, 0xc4, 0x58, 0x6b, + 0xe0, 0x75, 0xb8, 0x99, 0x91, 0x4e, 0x22, 0xfc, 0xc5, 0x79, 0x10, 0x3c, + 0x9c, 0x21, 0x1e, 0x89, 0xd4, 0x1b, 0x54, 0x6c, 0x0b, 0x91, 0x47, 0x05, + 0x0a, 0xb5, 0x37, 0xed, 0x94, 0x0a, 0xea, 0x14, 0x1c, 0xef, 0xeb, 0xb9, + 0x82, 0x80, 0x03, 0x8b, 0xe1, 0x3f, 0x7c, 0xdc, 0x8d, 0x1e, 0xd2, 0x09, + 0xd3, 0x34, 0xb6, 0xae, 0xea, 0xa0, 0xed, 0xd2, 0x89, 0x71, 0xa5, 0x91, + 0x15, 0xc8, 0x7f, 0xc6, 0x29, 0x89, 0x98, 0x6c, 0x93, 0x57, 0x91, 0x84, + 0x06, 0x4b, 0x6b, 0xfe, 0x38, 0x2e, 0x29, 0x34, 0x87, 0x25, 0x90, 0x83, + 0x33, 0x17, 0x0b, 0x7e, 0xe4, 0x2e, 0xb2, 0xf8, 0xc2, 0x1f, 0x13, 0x20, + 0x15, 0x5a, 0xa3, 0x95, 0x91, 0x06, 0x38, 0x2a, 0x08, 0xfb, 0x52, 0x73, + 0x27, 0xa5, 0x42, 0x02, 0xe9, 0x1c, 0xeb, 0x39, 0x3e, 0x95, 0x2c, 0x6c, + 0x90, 0xc9, 0xcd, 0x23, 0x92, 0x7d, 0xb1, 0x88, 0xb3, 0x6d, 0x2a, 0x68, + 0x43, 0x9b, 0x59, 0xca, 0x96, 0x92, 0x9e, 0x93, 0x3f, 0x2d, 0x0a, 0xcd, + 0xcd, 0x6a, 0xc1, 0x0b, 0x3a, 0x64, 0x67, 0x2a, 0xa0, 0x31, 0x12, 0x92, + 0xf2, 0x37, 0x06, 0x35, 0x96, 0x88, 0x53, 0x44, 0x29, 0xc6, 0x91, 0x96, + 0x41, 0x8b, 0x6b, 0x5b, 0xa7, 0x69, 0x42, 0xb1, 0xa7, 0x72, 0x08, 0xcc, + 0x11, 0x0c, 0x2e, 0xa7, 0xc2, 0x9b, 0x3a, 0x09, 0x01, 0x27, 0x71, 0x48, + 0x99, 0x4b, 0x1c, 0x32, 0x3a, 0x0f, 0x79, 0xd3, 0x0c, 0xe7, 0xec, 0x76, + 0xdb, 0xbc, 0x76, 0xef, 0x9b, 0x14, 0x5a, 0xd0, 0x42, 0x95, 0xc3, 0x04, + 0xee, 0x42, 0x8d, 0x10, 0x6b, 0xa1, 0x89, 0x39, 0xbf, 0x3d, 0x00, 0xd0, + 0xe7, 0x75, 0xc4, 0x60, 0x69, 0x1b, 0x25, 0xf5, 0x35, 0x2e, 0xbc, 0x19, + 0xd1, 0xa1, 0xad, 0x9d, 0x70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 0xa6, 0xca, 0x23, + 0xa4, 0x14, 0x7a, 0x68, 0xc0, 0xcf, 0xba, 0x36, 0x10, 0x4f, 0x73, 0x9f, + 0xe5, 0x65, 0x2c, 0xe6, 0x5a, 0xa3, 0x81, 0x13, 0x5b, 0x07, 0x7b, 0x88, + 0x05, 0x53, 0x93, 0xfe, 0x52, 0x23, 0x75, 0x80, 0x26, 0x02, 0xd9, 0xac, + 0x88, 0x31, 0x40, 0xf1, 0x4c, 0x3e, 0x9a, 0xb0, 0xc0, 0x5b, 0xc1, 0xc1, + 0x9e, 0xd1, 0x5a, 0xc3, 0x0c, 0x54, 0x9e, 0x03, 0xac, 0xe4, 0x5a, 0x51, + 0x5d, 0xb7, 0x45, 0xff, 0x47, 0xa5, 0x9b, 0x23, 0x9c, 0x87, 0xb4, 0x62, + 0x9d, 0xb6, 0x6d, 0xdc, 0x86, 0x22, 0x1a, 0x50, 0x2c, 0x65, 0x06, 0x19, + 0xa0, 0x4c, 0xa1, 0xe3, 0x21, 0x8f, 0x8b, 0xe6, 0x31, 0x84, 0xa4, 0xa7, + 0x21, 0xfa, 0x9c, 0x76, 0x74, 0x18, 0xc6, 0x85, 0x0c, 0x6f, 0x43, 0x0d, + 0x91, 0x43, 0x16, 0x0e, 0x7c, 0x72, 0x78, 0x42, 0x1e, 0x16, 0x1c, 0x37, + 0xde, 0xd7, 0x16, 0xf9, 0x82, 0x6d, 0x13, 0xb0, 0xb8, 0xc1, 0xd2, 0x7f, + 0x08, 0xba, 0x19, 0xd3, 0xf1, 0x6d, 0x67, 0x17, 0x1f, 0x9e, 0xea, 0x41, + 0x6a, 0xb3, 0x79, 0x09, 0x3b, 0x8c, 0xb6, 0xf1, 0x82, 0xe4, 0xa3, 0x08, + 0xe0, 0xaa, 0x76, 0x12, 0x30, 0xbd, 0x46, 0x40, 0x10, 0x2d, 0xfb, 0x2c, + 0x89, 0x36, 0x14, 0x8c, 0x69, 0x83, 0x00, 0x41, 0x46, 0x6f, 0x07, 0x87, + 0xe6, 0x43, 0x36, 0x02, 0xe4, 0x5c, 0xb3, 0xa0, 0xb8, 0x1f, 0x66, 0x10, + 0xbd, 0x09, 0xca, 0x5b, 0x86, 0x09, 0x3f, 0x13, 0x43, 0xa3, 0x24, 0x93, + 0xe9, 0x92, 0xcb, 0x00, 0x59, 0x81, 0xc1, 0x06, 0x21, 0xe6, 0x86, 0xbd, + 0xa5, 0xa5, 0x84, 0xe0, 0xa0, 0x43, 0x60, 0xc8, 0x61, 0xf9, 0x97, 0x50, + 0x33, 0xd4, 0x3b, 0x0a, 0x62, 0x9e, 0x58, 0xfc, 0xa8, 0x95, 0xc7, 0x0e, + 0xa1, 0x75, 0x81, 0xf9, 0xb6, 0x3e, 0x81, 0x76, 0x57, 0x3e, 0xec, 0x38, + 0x9f, 0x48, 0x64, 0x3d, 0x63, 0x56, 0xe9, 0x88, 0x86, 0x90, 0xe3, 0x13, + 0xff, 0xd1, 0x1b, 0x6c, 0xea, 0x7d, 0xe4, 0x44, 0x0c, 0x8a, 0xb2, 0x72, + 0x3d, 0x16, 0x67, 0x57, 0x19, 0x6e, 0x9c, 0x2c, 0x88, 0xc3, 0x90, 0x1b, + 0x42, 0xc3, 0x81, 0x6b, 0x78, 0x5d, 0xda, 0x41, 0x85, 0x34, 0xac, 0x16, + 0xa4, 0x98, 0xad, 0x6b, 0xe6, 0x05, 0xcb, 0xa1, 0xab, 0x8f, 0xf8, 0x95, + 0x25, 0xd9, 0x9b, 0x93, 0x38, 0xc4, 0x2f, 0x55, 0x35, 0xea, 0x85, 0xb1, + 0x4e, 0xda, 0x15, 0xe2, 0x94, 0x15, 0x3b, 0x13, 0x7b, 0x79, 0x7b, 0x72, + 0xd7, 0x28, 0x36, 0x41, 0x71, 0x04, 0x2f, 0x29, 0x8a, 0x91, 0x56, 0x1b, + 0xc8, 0xdc, 0x0a, 0xe5, 0x88, 0x7d, 0x0a, 0xac, 0xbd, 0xd3, 0xcc, 0x9d, + 0x5e, 0x6c, 0x37, 0xd4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0x3f, 0x53, 0x52, 0xb4, + 0x52, 0xc3, 0xaf, 0x69, 0x06, 0x0c, 0x53, 0x48, 0xbf, 0x9a, 0xdb, 0x1e, + 0x9d, 0x46, 0x7a, 0x1d, 0xb2, 0x33, 0xbb, 0x20, 0x43, 0x54, 0xea, 0x45, + 0x87, 0xd6, 0x49, 0xfb, 0x7c, 0xb5, 0x6b, 0x63, 0x78, 0x12, 0x9a, 0xcd, + 0xa6, 0x91, 0x4b, 0x5e, 0x20, 0xaa, 0x8a, 0x56, 0x42, 0x84, 0xab, 0x2f, + 0x7f, 0x0a, 0xb2, 0x82, 0x23, 0x3d, 0x6f, 0x11, 0x74, 0xf1, 0x44, 0x81, + 0x22, 0xca, 0x97, 0x42, 0x96, 0x50, 0x47, 0xf6, 0x62, 0xde, 0x37, 0x4b, + 0x86, 0x48, 0x49, 0x68, 0x7c, 0x7a, 0x6c, 0x90, 0x43, 0x19, 0x72, 0xbb, + 0x98, 0xca, 0x69, 0xa8, 0x46, 0x3a, 0x73, 0xe0, 0x3e, 0x1c, 0x53, 0x2c, + 0xb6, 0x92, 0x88, 0x3b, 0x4c, 0x9e, 0x8d, 0xfc, 0xc1, 0x49, 0x65, 0x35, + 0x5e, 0xc7, 0x0b, 0xc0, 0x1c, 0x22, 0x90, 0xb8, 0x79, 0x64, 0x0a, 0x4d, + 0x6e, 0xdc, 0xb0, 0x91, 0xeb, 0x02, 0xb9, 0xb6, 0xa1, 0x07, 0x62, 0x2b, + 0x7f, 0x93, 0x57, 0xce, 0x98, 0xb1, 0x3e, 0xa1, 0xa9, 0x17, 0xda, 0xc4, + 0x7b, 0x67, 0x8a, 0x15, 0x92, 0x58, 0xf7, 0x16, 0x00, 0xb9, 0xfc, 0x9e, + 0xa0, 0xda, 0x1b, 0x1f, 0xda, 0x7d, 0xab, 0xd2, 0xac, 0xec, 0x5a, 0x87, + 0xd0, 0xb2, 0xc7, 0x5b, 0xa4, 0x45, 0xd8, 0x59, 0x65, 0x19, 0xbb, 0x80, + 0x9a, 0xaa, 0x88, 0xf7, 0x31, 0x99, 0x43, 0x01, 0x45, 0x6e, 0x0b, 0x66, + 0x05, 0xf5, 0x7b, 0xaf, 0x80, 0xb3, 0x3a, 0xf4, 0x23, 0xea, 0xd6, 0x60, + 0xf6, 0x73, 0xaa, 0x0e, 0x65, 0x68, 0x57, 0x41, 0x53, 0xfa, 0xb5, 0x62, + 0x28, 0xae, 0xac, 0x1a, 0x1c, 0xa0, 0xa2, 0x87, 0x5f, 0xb7, 0x5c, 0xc3, + 0xf3, 0xb2, 0xf4, 0x2a, 0x1a, 0x3c, 0xbf, 0xfa, 0x1b, 0x90, 0x21, 0x9a, + 0xc7, 0x77, 0xe3, 0x09, 0xd9, 0xcd, 0xcd, 0xcf, 0x02, 0xb9, 0x5a, 0x74, + 0x31, 0x61, 0x66, 0x63, 0xb4, 0x6c, 0x37, 0x0f, 0x7c, 0x33, 0x29, 0xce, + 0x66, 0x41, 0xcb, 0x6f, 0x6d, 0xa7, 0xa8, 0xea, 0x05, 0x17, 0x36, 0xcf, + 0x14, 0xe5, 0x71, 0x95, 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, + 0x49, 0x37, 0xb0, 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, + 0x60, 0x69, 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +static const uint8_t test_vector_ct[1568] = { + 0xcb, 0x90, 0xc5, 0xe7, 0x41, 0x4b, 0x15, 0xf8, 0x32, 0x5b, 0x26, 0x88, + 0xca, 0xfe, 0x21, 0x32, 0x65, 0x59, 0x90, 0x9a, 0x96, 0xa7, 0xa4, 0x85, + 0xe5, 0xa6, 0x1e, 0xea, 0x72, 0x23, 0xea, 0xd2, 0xb2, 0x14, 0x22, 0xfb, + 0x53, 0x5a, 0xd0, 0x45, 0x2e, 0xc1, 0xaf, 0xd1, 0x90, 0xd5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c3, 0xdb, 0x1c, 0x9c, 0xcf, 0x31, 0x1e, 0x4b, + 0xc3, 0x47, 0xf8, 0x12, 0x74, 0xcf, 0xcc, 0xc3, 0xf4, 0xbf, 0x77, 0x43, + 0xea, 0x50, 0x37, 0xbe, 0xba, 0x87, 0x72, 0x80, 0x2e, 0x31, 0x25, 0xc0, + 0xc8, 0xf6, 0xe3, 0xc9, 0x0e, 0x2a, 0xcf, 0x78, 0x29, 0x39, 0x56, 0xea, + 0x48, 0x1e, 0x06, 0xb3, 0x07, 0xf1, 0x08, 0xe7, 0x68, 0xac, 0xe3, 0x2f, + 0xa2, 0x99, 0x20, 0x86, 0x92, 0x24, 0x3b, 0x77, 0x09, 0x57, 0xac, 0x00, + 0xa9, 0xe4, 0x87, 0x85, 0x39, 0x4f, 0x57, 0xb5}; +static const uint8_t test_vector_ss[32] = { + 0xfa, 0x24, 0x82, 0x8f, 0x2b, 0x3d, 0xec, 0xb0, 0x5d, 0x0e, 0x8d, + 0x1e, 0x72, 0x8c, 0x52, 0x93, 0x8b, 0xfb, 0x8c, 0xe7, 0x39, 0xa6, + 0x1c, 0x7d, 0xb9, 0x36, 0xee, 0xe7, 0x7d, 0xd1, 0x98, 0xa6}; +#endif /* MLK_CONFIG_PARAMETER_SET == 1024 */ + +#endif /* !EXPECTED_TEST_VECTORS_H */ diff --git a/test/test_vectors/expected_test_vectors_multilevel.h b/test/test_vectors/expected_test_vectors_multilevel.h new file mode 100644 index 0000000000..8e56a53d11 --- /dev/null +++ b/test/test_vectors/expected_test_vectors_multilevel.h @@ -0,0 +1,1257 @@ +/* + * Copyright (c) The mlkem-native project authors + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT + */ + +/* + * WARNING: This file is auto-generated from scripts/autogen + * in the mlkem-native repository. + * Do not modify it directly. + */ + +/* + * Expected test vectors for multilevel builds. + * Generated with per-level array names. + */ + +/* + * Generated with: + * d, z: consecutive 32-byte draws from a fresh notrandombytes + * stream (as consumed by crypto_kem_keypair). + * m: first 32-byte draw from a second, fresh + * notrandombytes stream (as consumed by crypto_kem_enc + * after randombytes_reset()). + */ + +#ifndef EXPECTED_TEST_VECTORS_MULTILEVEL_H +#define EXPECTED_TEST_VECTORS_MULTILEVEL_H + +#include + +/* keygen d (first 32 bytes of a fresh notrandombytes stream) */ +static const uint8_t test_vector_d[32] = { + 0x93, 0x4d, 0x60, 0xb3, 0x56, 0x24, 0xd7, 0x40, 0xb3, 0x0a, 0x7f, + 0x22, 0x7a, 0xf2, 0xae, 0x7c, 0x67, 0x8e, 0x4e, 0x04, 0xe1, 0x3c, + 0x5f, 0x50, 0x9e, 0xad, 0xe2, 0xb7, 0x9a, 0xea, 0x77, 0xe2}; +/* keygen z (next 32 bytes of the same stream) */ +static const uint8_t test_vector_z[32] = { + 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, 0x49, 0x37, 0xb0, + 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, 0x60, 0x69, + 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +/* encaps m (first 32 bytes of a fresh notrandombytes stream) */ +static const uint8_t test_vector_m[32] = { + 0x93, 0x4d, 0x60, 0xb3, 0x56, 0x24, 0xd7, 0x40, 0xb3, 0x0a, 0x7f, + 0x22, 0x7a, 0xf2, 0xae, 0x7c, 0x67, 0x8e, 0x4e, 0x04, 0xe1, 0x3c, + 0x5f, 0x50, 0x9e, 0xad, 0xe2, 0xb7, 0x9a, 0xea, 0x77, 0xe2}; + +/* ML-KEM-512 */ +static const uint8_t test_vector_pk_512[800] = { + 0x81, 0x88, 0x22, 0x13, 0x16, 0x88, 0xe3, 0x2b, 0x97, 0x3f, 0x28, 0x56, + 0x7c, 0xd3, 0xb7, 0xdf, 0x5a, 0xc5, 0xef, 0x7b, 0xb9, 0x3a, 0xc6, 0x40, + 0x71, 0x4a, 0x0d, 0x6b, 0x03, 0x59, 0x01, 0x91, 0x86, 0xcf, 0x53, 0xa4, + 0xeb, 0x95, 0x48, 0xdf, 0x2a, 0xaf, 0x63, 0x65, 0x6b, 0x79, 0xeb, 0x70, + 0xbd, 0x33, 0x80, 0x8f, 0x3a, 0x72, 0x2d, 0x85, 0x55, 0xeb, 0x31, 0x5f, + 0xa9, 0xb9, 0x12, 0xff, 0xb5, 0x36, 0xc5, 0x57, 0x83, 0x51, 0x17, 0xae, + 0x2e, 0xd0, 0x8a, 0x9e, 0x13, 0x38, 0xd1, 0xca, 0x59, 0xc5, 0x25, 0x35, + 0x11, 0x84, 0x0d, 0xa6, 0x79, 0x2b, 0x33, 0x41, 0x3d, 0x80, 0x32, 0x0e, + 0x0a, 0x47, 0x7a, 0x75, 0x69, 0x68, 0xf8, 0x07, 0x9d, 0xff, 0x66, 0x67, + 0x04, 0xb0, 0x9a, 0x85, 0xb2, 0xab, 0x7d, 0xbb, 0x22, 0x13, 0x71, 0x91, + 0x8f, 0x18, 0xb6, 0x60, 0xa3, 0xa3, 0x3c, 0x90, 0xb6, 0x01, 0x41, 0x63, + 0x5e, 0x6a, 0x3c, 0xc9, 0x10, 0x90, 0x1f, 0xf7, 0x04, 0x61, 0x31, 0x87, + 0x0b, 0x75, 0x07, 0x6f, 0xf6, 0x0c, 0x9a, 0x98, 0x6a, 0x71, 0x89, 0x42, + 0xb6, 0x14, 0x4b, 0xda, 0xc4, 0x7a, 0xfd, 0xcb, 0xac, 0x6d, 0x44, 0x19, + 0x93, 0xb3, 0xb7, 0x39, 0x02, 0x05, 0x77, 0xd5, 0x3a, 0xb4, 0xec, 0xc2, + 0xc6, 0xc5, 0xca, 0x3e, 0x22, 0xce, 0xc7, 0xac, 0x55, 0x4f, 0x37, 0x85, + 0x33, 0xa8, 0xb4, 0x96, 0x46, 0x35, 0xdc, 0x26, 0xbc, 0x2f, 0xe4, 0xc0, + 0x95, 0x65, 0x0b, 0x9b, 0xc2, 0xb8, 0x6c, 0x45, 0x16, 0x27, 0x6c, 0x31, + 0xc1, 0xa3, 0x7e, 0xf7, 0x0a, 0x03, 0x81, 0x28, 0x6f, 0x2a, 0x19, 0x3d, + 0xfa, 0x77, 0x9f, 0xc3, 0x3b, 0x02, 0x97, 0x8c, 0xae, 0xcb, 0xa4, 0x4e, + 0x82, 0x2b, 0x4c, 0x09, 0xa5, 0x68, 0x7a, 0xf8, 0x79, 0x49, 0xe8, 0x49, + 0xa5, 0xe6, 0x09, 0xea, 0xd3, 0xb2, 0x19, 0x61, 0x32, 0xad, 0x43, 0xb5, + 0x60, 0xd5, 0x99, 0xe4, 0x0a, 0x4b, 0x72, 0x68, 0x6e, 0x1b, 0x42, 0x92, + 0xe4, 0x1b, 0x91, 0xf6, 0x5a, 0x7c, 0x56, 0x79, 0x1b, 0xea, 0xc7, 0xbd, + 0x71, 0x4c, 0x91, 0x50, 0x29, 0x86, 0xa5, 0x78, 0xb8, 0x24, 0xea, 0x2e, + 0x35, 0x14, 0xbf, 0x35, 0x18, 0x02, 0x77, 0xb8, 0x15, 0x1b, 0x22, 0x3e, + 0xa7, 0xba, 0x1b, 0x00, 0x95, 0x6a, 0x4a, 0x44, 0x38, 0xca, 0x6c, 0x04, + 0x34, 0x92, 0x04, 0xaa, 0xb0, 0x19, 0x87, 0x6a, 0x4c, 0x56, 0x36, 0xa5, + 0xf7, 0xf4, 0x53, 0x77, 0xf5, 0x08, 0x43, 0x40, 0xc4, 0x50, 0x9a, 0x07, + 0x0e, 0x94, 0x8b, 0x82, 0x1c, 0x07, 0xcd, 0xa4, 0x2f, 0x87, 0xb2, 0x7a, + 0x81, 0x99, 0x30, 0x9e, 0x80, 0x88, 0xd1, 0x0c, 0xb9, 0x72, 0xa5, 0x99, + 0x50, 0xa8, 0x42, 0x03, 0x19, 0x4b, 0x52, 0x56, 0x16, 0x43, 0xe6, 0x64, + 0xab, 0xe8, 0x4e, 0x6a, 0xcc, 0x84, 0xae, 0x5a, 0x4d, 0x0c, 0x90, 0xaf, + 0x5f, 0x33, 0x44, 0xb5, 0x92, 0xc3, 0x90, 0x00, 0xc2, 0x9d, 0x19, 0x0b, + 0x41, 0x57, 0xbb, 0x30, 0x89, 0x69, 0x22, 0x62, 0xae, 0xa8, 0x41, 0xc5, + 0xbb, 0x83, 0xa5, 0xf5, 0xe3, 0x78, 0x19, 0xab, 0x65, 0xc0, 0xf2, 0x4e, + 0x1b, 0x21, 0x44, 0xa1, 0xe2, 0x35, 0x8f, 0x23, 0x89, 0xa4, 0x98, 0x32, + 0x1d, 0x05, 0x4e, 0xe8, 0x6c, 0x65, 0xc2, 0x97, 0x78, 0x8a, 0x65, 0x79, + 0x11, 0x75, 0x68, 0xe7, 0x34, 0x9e, 0xe0, 0xf2, 0xad, 0x9b, 0xe1, 0x2a, + 0xbc, 0x30, 0x5b, 0x10, 0x98, 0x7d, 0x06, 0xa6, 0xc9, 0xb7, 0x53, 0x7e, + 0x08, 0xb1, 0x7c, 0x75, 0x16, 0x22, 0x9d, 0x20, 0x71, 0xae, 0x41, 0x7c, + 0x51, 0x16, 0xc0, 0xb2, 0x26, 0x56, 0xd8, 0x02, 0x83, 0xaa, 0x4a, 0x93, + 0xe5, 0xc2, 0x66, 0xbe, 0x70, 0x6c, 0x5e, 0x69, 0xa6, 0x20, 0xac, 0x4b, + 0xab, 0x41, 0x4d, 0x2a, 0x54, 0x61, 0x68, 0xa1, 0x6d, 0xc6, 0xd2, 0xce, + 0x0f, 0x3c, 0xad, 0xcf, 0x60, 0x1e, 0x41, 0x70, 0xca, 0xa8, 0xaa, 0xbf, + 0xf3, 0x5a, 0x31, 0x52, 0xe6, 0x36, 0xb5, 0xbc, 0xaa, 0x7d, 0xda, 0xc4, + 0x70, 0xeb, 0xc0, 0xfa, 0xa1, 0x1c, 0x38, 0x48, 0xb3, 0xbb, 0xca, 0x36, + 0xa3, 0xa5, 0x77, 0x07, 0x7a, 0xc1, 0xb9, 0xec, 0xc9, 0x43, 0x77, 0x57, + 0x48, 0x94, 0x08, 0x04, 0x13, 0xc5, 0x1d, 0xec, 0xcb, 0xc1, 0xa8, 0xb0, + 0x9c, 0x40, 0x19, 0x75, 0xfb, 0xba, 0x72, 0x36, 0x9b, 0x0e, 0x37, 0x9b, + 0x98, 0xe6, 0x1e, 0xf9, 0x49, 0x8b, 0x84, 0xcb, 0xa3, 0x43, 0x1a, 0x13, + 0xe0, 0x5a, 0x56, 0x21, 0xfa, 0xb7, 0x58, 0x09, 0x2a, 0x89, 0x6a, 0x80, + 0x1f, 0x96, 0x98, 0x98, 0xb9, 0x92, 0x42, 0x80, 0x22, 0x9d, 0xda, 0x98, + 0xe5, 0x7b, 0x80, 0x0d, 0x23, 0xa7, 0x0d, 0xd2, 0x3d, 0x17, 0xc6, 0x06, + 0xe0, 0x33, 0x06, 0x5a, 0x1a, 0x31, 0x51, 0x62, 0x40, 0xe4, 0x4c, 0x0f, + 0x6b, 0xe2, 0x0f, 0x8e, 0x95, 0x22, 0x86, 0x5a, 0xa9, 0x4a, 0xa1, 0x29, + 0x91, 0x21, 0xb8, 0x34, 0x11, 0x97, 0x57, 0x03, 0x1a, 0xeb, 0x11, 0x35, + 0x66, 0xc6, 0xa8, 0xab, 0xc1, 0x56, 0x54, 0x0a, 0x06, 0x3a, 0x3c, 0x4b, + 0x21, 0xa8, 0x4b, 0x0f, 0x68, 0x14, 0x4d, 0xa2, 0x81, 0xa2, 0xf8, 0x0c, + 0xca, 0x2b, 0x75, 0x51, 0xe0, 0xb8, 0x55, 0x70, 0xbe, 0xfe, 0x95, 0x60, + 0x4f, 0x9b, 0x59, 0xd8, 0x7c, 0x94, 0x98, 0x03, 0x5a, 0xc3, 0x76, 0x3c, + 0x36, 0xe5, 0x75, 0xf3, 0xec, 0x82, 0x76, 0x41, 0x30, 0x87, 0x02, 0x20, + 0xb7, 0x1b, 0x56, 0xc5, 0x6c, 0xc0, 0x7b, 0xb3, 0x64, 0x14, 0xb8, 0x61, + 0x31, 0x42, 0x0a, 0x35, 0xa2, 0x56, 0x55, 0xd5, 0x6e, 0x63, 0x94, 0xad, + 0xf2, 0xd1, 0x42, 0x6c, 0xa6, 0x8a, 0x88, 0xde, 0x54, 0x2f, 0xa4, 0x44, + 0x1a, 0xd5, 0xd3, 0x82, 0x64, 0x48, 0x68, 0x53, 0x59, 0x0e, 0x7f, 0x72, + 0x3f, 0x91, 0xf2, 0x0c, 0x04, 0x0b, 0x49, 0x55}; +static const uint8_t test_vector_sk_512[1632] = { + 0xc5, 0xa1, 0xcb, 0x12, 0x1a, 0x88, 0x02, 0x36, 0x45, 0x5b, 0x8c, 0x04, + 0xd9, 0x67, 0x06, 0x89, 0x28, 0x32, 0xd1, 0x3a, 0x28, 0x80, 0x9a, 0x16, + 0xaa, 0xdb, 0x6a, 0x95, 0x28, 0x1b, 0x3e, 0xf0, 0x53, 0x38, 0x7a, 0x57, + 0xbe, 0x9a, 0xca, 0x6c, 0x7c, 0x8b, 0xf7, 0xc5, 0xa5, 0xa9, 0x30, 0x61, + 0x43, 0xb7, 0x2f, 0x74, 0x68, 0x0e, 0x10, 0xdc, 0x51, 0xb5, 0xb5, 0xa0, + 0x90, 0xa9, 0x0f, 0xd3, 0xe3, 0x39, 0xe1, 0xf5, 0x6a, 0xa2, 0xb0, 0x52, + 0x0a, 0x77, 0x5d, 0xdd, 0x41, 0x20, 0xbc, 0xf0, 0xa5, 0x41, 0x41, 0xc0, + 0x36, 0x0c, 0x72, 0x77, 0xb9, 0x2a, 0x3e, 0x76, 0x78, 0x13, 0x53, 0x41, + 0x8c, 0x9c, 0x87, 0xc5, 0xac, 0x2d, 0xc6, 0x3a, 0xaf, 0xaf, 0x16, 0xcd, + 0xcf, 0xab, 0xb2, 0x2a, 0x98, 0x6d, 0x54, 0xd4, 0x09, 0x31, 0xd4, 0x55, + 0xb0, 0xe3, 0x58, 0x31, 0xd2, 0x57, 0x0b, 0xe7, 0x07, 0xc7, 0x22, 0x73, + 0xc7, 0x89, 0x5b, 0x40, 0x63, 0x2d, 0x73, 0x5b, 0x23, 0x82, 0x96, 0x41, + 0x33, 0x89, 0x0f, 0xf3, 0x75, 0x85, 0xb1, 0xa0, 0xca, 0x22, 0xf5, 0x6b, + 0xee, 0x98, 0xc3, 0x99, 0xc5, 0x5e, 0xb5, 0x3b, 0x49, 0x00, 0xdc, 0x37, + 0x0e, 0x0c, 0x2f, 0x8a, 0xe4, 0x38, 0x90, 0xf3, 0x80, 0x05, 0x4a, 0x13, + 0xb7, 0xba, 0x37, 0x3e, 0x78, 0x7c, 0x12, 0x98, 0x71, 0x1e, 0xaa, 0x59, + 0x42, 0x00, 0xd0, 0x45, 0x05, 0x8f, 0x63, 0xa9, 0xb9, 0x58, 0x39, 0x38, + 0x27, 0x6c, 0x06, 0x46, 0xf1, 0xc4, 0x6c, 0x24, 0x7f, 0xf9, 0x6b, 0x41, + 0xdb, 0xd8, 0x52, 0x00, 0x76, 0x87, 0x36, 0x00, 0x01, 0x11, 0x7b, 0x9c, + 0x89, 0x97, 0x5a, 0xb6, 0x11, 0x20, 0x30, 0x8a, 0x35, 0x58, 0x16, 0x40, + 0xfc, 0xe2, 0xa4, 0x23, 0x18, 0x47, 0x48, 0x17, 0x69, 0x1f, 0x9a, 0x62, + 0x75, 0x69, 0x73, 0xef, 0x6c, 0x55, 0x11, 0x94, 0x3e, 0xc3, 0x26, 0x1c, + 0xf2, 0x97, 0xbf, 0x62, 0x4c, 0x75, 0xe9, 0xd1, 0xcc, 0xe9, 0xd2, 0x18, + 0xae, 0x21, 0xc1, 0xa9, 0xa0, 0x61, 0xa7, 0xc8, 0x5a, 0x31, 0x09, 0x24, + 0x76, 0x81, 0xbe, 0x9c, 0x79, 0xb8, 0x23, 0xac, 0xaf, 0xb3, 0xa3, 0xbd, + 0x81, 0xab, 0x5b, 0x36, 0x7c, 0x66, 0x5b, 0xe7, 0x26, 0xbd, 0xbc, 0x1f, + 0xaf, 0x7a, 0x34, 0xa3, 0x90, 0x8f, 0xb9, 0x33, 0x0c, 0x05, 0xf3, 0x5c, + 0x63, 0x58, 0x2d, 0x04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 0xd4, 0x9a, 0x7b, 0xca, 0xbb, + 0x2f, 0x64, 0x08, 0x35, 0xe7, 0x6f, 0x16, 0xe4, 0x68, 0x8b, 0x14, 0xa8, + 0x34, 0xd2, 0x2a, 0x10, 0x19, 0x5e, 0x79, 0x62, 0x19, 0x1d, 0x43, 0x27, + 0xe8, 0x3b, 0xcc, 0x99, 0x76, 0x67, 0x50, 0x00, 0xc1, 0x74, 0x48, 0xbf, + 0x84, 0xd5, 0x07, 0x00, 0xf6, 0x50, 0x68, 0x67, 0x85, 0xce, 0x2b, 0x56, + 0xce, 0x6c, 0xa3, 0x56, 0xfb, 0xb2, 0xa5, 0x06, 0xa2, 0x1e, 0x70, 0x90, + 0xb6, 0xb2, 0x97, 0x93, 0x1c, 0x79, 0x4f, 0xc3, 0x21, 0xd8, 0x57, 0xa9, + 0x81, 0x88, 0x22, 0x13, 0x16, 0x88, 0xe3, 0x2b, 0x97, 0x3f, 0x28, 0x56, + 0x7c, 0xd3, 0xb7, 0xdf, 0x5a, 0xc5, 0xef, 0x7b, 0xb9, 0x3a, 0xc6, 0x40, + 0x71, 0x4a, 0x0d, 0x6b, 0x03, 0x59, 0x01, 0x91, 0x86, 0xcf, 0x53, 0xa4, + 0xeb, 0x95, 0x48, 0xdf, 0x2a, 0xaf, 0x63, 0x65, 0x6b, 0x79, 0xeb, 0x70, + 0xbd, 0x33, 0x80, 0x8f, 0x3a, 0x72, 0x2d, 0x85, 0x55, 0xeb, 0x31, 0x5f, + 0xa9, 0xb9, 0x12, 0xff, 0xb5, 0x36, 0xc5, 0x57, 0x83, 0x51, 0x17, 0xae, + 0x2e, 0xd0, 0x8a, 0x9e, 0x13, 0x38, 0xd1, 0xca, 0x59, 0xc5, 0x25, 0x35, + 0x11, 0x84, 0x0d, 0xa6, 0x79, 0x2b, 0x33, 0x41, 0x3d, 0x80, 0x32, 0x0e, + 0x0a, 0x47, 0x7a, 0x75, 0x69, 0x68, 0xf8, 0x07, 0x9d, 0xff, 0x66, 0x67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0x91, 0x50, 0x29, 0x86, 0xa5, 0x78, 0xb8, 0x24, 0xea, 0x2e, + 0x35, 0x14, 0xbf, 0x35, 0x18, 0x02, 0x77, 0xb8, 0x15, 0x1b, 0x22, 0x3e, + 0xa7, 0xba, 0x1b, 0x00, 0x95, 0x6a, 0x4a, 0x44, 0x38, 0xca, 0x6c, 0x04, + 0x34, 0x92, 0x04, 0xaa, 0xb0, 0x19, 0x87, 0x6a, 0x4c, 0x56, 0x36, 0xa5, + 0xf7, 0xf4, 0x53, 0x77, 0xf5, 0x08, 0x43, 0x40, 0xc4, 0x50, 0x9a, 0x07, + 0x0e, 0x94, 0x8b, 0x82, 0x1c, 0x07, 0xcd, 0xa4, 0x2f, 0x87, 0xb2, 0x7a, + 0x81, 0x99, 0x30, 0x9e, 0x80, 0x88, 0xd1, 0x0c, 0xb9, 0x72, 0xa5, 0x99, + 0x50, 0xa8, 0x42, 0x03, 0x19, 0x4b, 0x52, 0x56, 0x16, 0x43, 0xe6, 0x64, + 0xab, 0xe8, 0x4e, 0x6a, 0xcc, 0x84, 0xae, 0x5a, 0x4d, 0x0c, 0x90, 0xaf, + 0x5f, 0x33, 0x44, 0xb5, 0x92, 0xc3, 0x90, 0x00, 0xc2, 0x9d, 0x19, 0x0b, + 0x41, 0x57, 0xbb, 0x30, 0x89, 0x69, 0x22, 0x62, 0xae, 0xa8, 0x41, 0xc5, + 0xbb, 0x83, 0xa5, 0xf5, 0xe3, 0x78, 0x19, 0xab, 0x65, 0xc0, 0xf2, 0x4e, + 0x1b, 0x21, 0x44, 0xa1, 0xe2, 0x35, 0x8f, 0x23, 0x89, 0xa4, 0x98, 0x32, + 0x1d, 0x05, 0x4e, 0xe8, 0x6c, 0x65, 0xc2, 0x97, 0x78, 0x8a, 0x65, 0x79, + 0x11, 0x75, 0x68, 0xe7, 0x34, 0x9e, 0xe0, 0xf2, 0xad, 0x9b, 0xe1, 0x2a, + 0xbc, 0x30, 0x5b, 0x10, 0x98, 0x7d, 0x06, 0xa6, 0xc9, 0xb7, 0x53, 0x7e, + 0x08, 0xb1, 0x7c, 0x75, 0x16, 0x22, 0x9d, 0x20, 0x71, 0xae, 0x41, 0x7c, + 0x51, 0x16, 0xc0, 0xb2, 0x26, 0x56, 0xd8, 0x02, 0x83, 0xaa, 0x4a, 0x93, + 0xe5, 0xc2, 0x66, 0xbe, 0x70, 0x6c, 0x5e, 0x69, 0xa6, 0x20, 0xac, 0x4b, + 0xab, 0x41, 0x4d, 0x2a, 0x54, 0x61, 0x68, 0xa1, 0x6d, 0xc6, 0xd2, 0xce, + 0x0f, 0x3c, 0xad, 0xcf, 0x60, 0x1e, 0x41, 0x70, 0xca, 0xa8, 0xaa, 0xbf, + 0xf3, 0x5a, 0x31, 0x52, 0xe6, 0x36, 0xb5, 0xbc, 0xaa, 0x7d, 0xda, 0xc4, + 0x70, 0xeb, 0xc0, 0xfa, 0xa1, 0x1c, 0x38, 0x48, 0xb3, 0xbb, 0xca, 0x36, + 0xa3, 0xa5, 0x77, 0x07, 0x7a, 0xc1, 0xb9, 0xec, 0xc9, 0x43, 0x77, 0x57, + 0x48, 0x94, 0x08, 0x04, 0x13, 0xc5, 0x1d, 0xec, 0xcb, 0xc1, 0xa8, 0xb0, + 0x9c, 0x40, 0x19, 0x75, 0xfb, 0xba, 0x72, 0x36, 0x9b, 0x0e, 0x37, 0x9b, + 0x98, 0xe6, 0x1e, 0xf9, 0x49, 0x8b, 0x84, 0xcb, 0xa3, 0x43, 0x1a, 0x13, + 0xe0, 0x5a, 0x56, 0x21, 0xfa, 0xb7, 0x58, 0x09, 0x2a, 0x89, 0x6a, 0x80, + 0x1f, 0x96, 0x98, 0x98, 0xb9, 0x92, 0x42, 0x80, 0x22, 0x9d, 0xda, 0x98, + 0xe5, 0x7b, 0x80, 0x0d, 0x23, 0xa7, 0x0d, 0xd2, 0x3d, 0x17, 0xc6, 0x06, + 0xe0, 0x33, 0x06, 0x5a, 0x1a, 0x31, 0x51, 0x62, 0x40, 0xe4, 0x4c, 0x0f, + 0x6b, 0xe2, 0x0f, 0x8e, 0x95, 0x22, 0x86, 0x5a, 0xa9, 0x4a, 0xa1, 0x29, + 0x91, 0x21, 0xb8, 0x34, 0x11, 0x97, 0x57, 0x03, 0x1a, 0xeb, 0x11, 0x35, + 0x66, 0xc6, 0xa8, 0xab, 0xc1, 0x56, 0x54, 0x0a, 0x06, 0x3a, 0x3c, 0x4b, + 0x21, 0xa8, 0x4b, 0x0f, 0x68, 0x14, 0x4d, 0xa2, 0x81, 0xa2, 0xf8, 0x0c, + 0xca, 0x2b, 0x75, 0x51, 0xe0, 0xb8, 0x55, 0x70, 0xbe, 0xfe, 0x95, 0x60, + 0x4f, 0x9b, 0x59, 0xd8, 0x7c, 0x94, 0x98, 0x03, 0x5a, 0xc3, 0x76, 0x3c, + 0x36, 0xe5, 0x75, 0xf3, 0xec, 0x82, 0x76, 0x41, 0x30, 0x87, 0x02, 0x20, + 0xb7, 0x1b, 0x56, 0xc5, 0x6c, 0xc0, 0x7b, 0xb3, 0x64, 0x14, 0xb8, 0x61, + 0x31, 0x42, 0x0a, 0x35, 0xa2, 0x56, 0x55, 0xd5, 0x6e, 0x63, 0x94, 0xad, + 0xf2, 0xd1, 0x42, 0x6c, 0xa6, 0x8a, 0x88, 0xde, 0x54, 0x2f, 0xa4, 0x44, + 0x1a, 0xd5, 0xd3, 0x82, 0x64, 0x48, 0x68, 0x53, 0x59, 0x0e, 0x7f, 0x72, + 0x3f, 0x91, 0xf2, 0x0c, 0x04, 0x0b, 0x49, 0x55, 0xfa, 0x9f, 0x72, 0x93, + 0xa3, 0xf6, 0x5f, 0x79, 0x42, 0x19, 0x01, 0xc0, 0xa4, 0x13, 0x7b, 0xcb, + 0x17, 0x93, 0x28, 0x48, 0xb3, 0x01, 0x7b, 0xe7, 0xd0, 0x10, 0xfe, 0x07, + 0x10, 0xdd, 0x3d, 0x90, 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, + 0x49, 0x37, 0xb0, 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, + 0x60, 0x69, 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +static const uint8_t test_vector_ct_512[768] = { + 0xb0, 0x7d, 0x00, 0xe5, 0x1a, 0xac, 0x9d, 0x6b, 0xdb, 0xb7, 0x1e, 0xf0, + 0x00, 0xac, 0x9c, 0x70, 0x98, 0x2c, 0x97, 0xe3, 0xb8, 0xbf, 0xc8, 0x60, + 0xba, 0xec, 0x45, 0xbb, 0xc9, 0x83, 0xa2, 0xd3, 0xaa, 0x70, 0x2f, 0xfb, + 0xd0, 0x28, 0x08, 0x34, 0x54, 0x6e, 0x08, 0x36, 0x2c, 0x41, 0x9b, 0x95, + 0x23, 0x52, 0x6a, 0xf0, 0xe0, 0x60, 0x4a, 0x58, 0xf8, 0xcb, 0xf9, 0xa9, + 0xdd, 0xe4, 0xff, 0xae, 0xd4, 0x7e, 0xa1, 0xb3, 0x77, 0x6a, 0x8b, 0x00, + 0xe3, 0x33, 0x78, 0xd2, 0xaa, 0x99, 0xb9, 0x0b, 0xd9, 0xae, 0x41, 0x8c, + 0x59, 0x76, 0x4a, 0x12, 0xb7, 0x1f, 0xff, 0xd5, 0x34, 0xda, 0xc4, 0xd5, + 0xdc, 0xda, 0x4f, 0x57, 0xde, 0xca, 0xa4, 0xae, 0xf3, 0xca, 0x79, 0xbc, + 0x79, 0x9c, 0x2f, 0x58, 0xef, 0x96, 0x09, 0x90, 0x89, 0xd0, 0xc2, 0xda, + 0x6f, 0xb0, 0xeb, 0x61, 0xc5, 0xb6, 0x7f, 0x3b, 0x3f, 0x82, 0x4d, 0x19, + 0x21, 0x66, 0xe2, 0xd8, 0xdd, 0x21, 0x46, 0x04, 0xd5, 0x10, 0xbc, 0x85, + 0x20, 0x13, 0x79, 0x5b, 0x4b, 0x1a, 0x47, 0xcf, 0xdf, 0x12, 0x47, 0x66,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 0xfc, 0xbe, 0x67, 0x55, 0xae, 0x0a, 0x6a, 0x73, + 0xea, 0x8a, 0x96, 0x60, 0x60, 0xe9, 0x50, 0x57, 0x06, 0x7a, 0x54, 0xb7, + 0xcc, 0x5b, 0x9f, 0x96, 0xe3, 0x69, 0xcc, 0xd7, 0x9f, 0x8c, 0xc2, 0xf8, + 0xca, 0x63, 0xc2, 0xc4, 0x2b, 0x98, 0xa3, 0x44, 0xa9, 0xd1, 0x59, 0xb2, + 0xfb, 0x62, 0x2f, 0x0f, 0xcc, 0xf5, 0x89, 0x45, 0xd5, 0x91, 0x89, 0x96, + 0x9f, 0x0c, 0x07, 0x0d, 0x0d, 0xf8, 0xd0, 0xce, 0xef, 0x39, 0xef, 0x2e, + 0x67, 0xa3, 0x61, 0xc5, 0x99, 0x53, 0x0c, 0x7e, 0x49, 0x35, 0xab, 0xc0, + 0x51, 0xee, 0xc1, 0x1d, 0x8c, 0x11, 0xe8, 0xfa, 0xe7, 0x9f, 0x51, 0x95, + 0xc5, 0x30, 0x67, 0x1d, 0x5e, 0x8c, 0xdb, 0x4c, 0x54, 0x5a, 0x6b, 0x80, + 0x09, 0xef, 0xd7, 0xeb, 0x48, 0x8a, 0x93, 0xed, 0x7a, 0xb4, 0x31, 0x7b, + 0x04, 0x0f, 0x89, 0xc4, 0xab, 0xb8, 0x57, 0x86, 0xed, 0xdb, 0xea, 0x9c, + 0x36, 0x11, 0x81, 0xb6, 0xd9, 0x49, 0xf9, 0xae, 0xc7, 0x22, 0x91, 0x21, + 0xf1, 0xda, 0x8e, 0x85, 0xad, 0x50, 0xba, 0x96, 0x38, 0xb6, 0x3f, 0xc2, + 0x17, 0x8e, 0x31, 0x2e, 0xdb, 0x45, 0xc4, 0x4c, 0x10, 0xab, 0xeb, 0x95, + 0xd1, 0x98, 0x5f, 0x2f, 0x6f, 0x86, 0x94, 0x17, 0xe3, 0x5e, 0xd4, 0x62, + 0xc2, 0x72, 0xe3, 0x25, 0xb7, 0xe3, 0x60, 0x4d, 0x58, 0x35, 0xdd, 0x90, + 0x5c, 0x50, 0x95, 0xc8, 0xa5, 0xd1, 0xc6, 0x8f, 0x54, 0x9e, 0x04, 0x7c, + 0x81, 0x0e, 0xcf, 0xd4, 0xb7, 0xdf, 0xa5, 0x11, 0x62, 0x61, 0x46, 0x3e, + 0xb5, 0x98, 0xac, 0x91, 0x25, 0xb2, 0xce, 0x61, 0x59, 0x87, 0x84, 0x69, + 0x50, 0x70, 0xa4, 0xe4, 0x69, 0xb6, 0x20, 0xa1, 0x1a, 0xde, 0x77, 0x02, + 0x43, 0xe1, 0x55, 0x87, 0x46, 0x36, 0xf7, 0x54, 0x37, 0xc5, 0x3d, 0x03}; +static const uint8_t test_vector_ss_512[32] = { + 0x3f, 0xd5, 0xed, 0xe7, 0x0c, 0xb6, 0x62, 0x37, 0x9d, 0x80, 0x1b, + 0x38, 0x62, 0xb0, 0x38, 0xac, 0x07, 0x89, 0xfd, 0x1c, 0xcd, 0x4c, + 0x9a, 0x77, 0x9f, 0xcb, 0x01, 0x4f, 0x2d, 0x33, 0x19, 0x8a}; + +/* ML-KEM-768 */ +static const uint8_t test_vector_pk_768[1184] = { + 0x69, 0x3b, 0x4b, 0x7f, 0x22, 0x69, 0x8c, 0xc9, 0x1e, 0x65, 0xa1, 0x11, + 0x98, 0xe9, 0x44, 0x86, 0x97, 0x30, 0x8f, 0x39, 0xa1, 0xf7, 0x7c, 0xbe, + 0x0d, 0xf5, 0x32, 0x45, 0x62, 0x6f, 0x32, 0x35, 0x78, 0x06, 0xc6, 0x8e, + 0x4a, 0xb8, 0xb2, 0x18, 0x29, 0x58, 0xd0, 0xc4, 0x93, 0x39, 0xd0, 0xb8, + 0xc1, 0x53, 0x47, 0x65, 0x5b, 0x75, 0x62, 0x56, 0x93, 0x5b, 0x43, 0xcc, + 0xef, 0x66, 0xba, 0x7a, 0x78, 0x95, 0x3e, 0x5c, 0xa7, 0xac, 0xb3, 0x50, + 0xcc, 0xc8, 0x9a, 0x87, 0xc8, 0x63, 0x66, 0xc7, 0x7b, 0xf0, 0xc0, 0x1f, + 0x8f, 0x47, 0x2f, 0x22, 0xa8, 0x5a, 0x94, 0x70, 0xa8, 0x2e, 0xe0, 0x54, + 0xed, 0x95, 0x63, 0xc4, 0x0b, 0x62, 0xd9, 0xbb, 0xc4, 0xe4, 0x10, 0x76, + 0xbb, 0xe5, 0xb3, 0xf1, 0xb6, 0x0c, 0x2b, 0xa1, 0x65, 0x2f, 0xa7, 0xaa, + 0xc4, 0x4c, 0x6c, 0x26, 0xa0, 0x60, 0x8e, 0x15, 0x9a, 0x6a, 0x10, 0x49, + 0x23, 0xa6, 0x4c, 0xff, 0x90, 0x43, 0x5e, 0x1b, 0x23, 0x83, 0x63, 0x32, + 0x27, 0x67, 0x55, 0x21, 0x42, 0x76, 0x78, 0xc4, 0x63, 0x52, 0xe0, 0x5e, + 0xe8, 0xb7, 0x0a, 0xc5, 0x47, 0x45, 0x97, 0xc7, 0x33, 0x8b, 0x23, 0xa5, + 0x77, 0xf7, 0x51, 0x7c, 0x16, 0xc4, 0x84, 0xfa, 0x23, 0xed, 0x95, 0x48, + 0xb8, 0x1c, 0x35, 0xac, 0xa6, 0xa9, 0x36, 0x00, 0xb7, 0x66, 0x6b, 0x64, + 0x14, 0x36, 0x35, 0x2d, 0x07, 0xb8, 0xd9, 0xc7, 0x3d, 0xac, 0x46, 0x3f, + 0x94, 0xab, 0xb2, 0xe5, 0x98, 0x96, 0x68, 0x19, 0x2f, 0x01, 0xb8, 0x9a, + 0xa8, 0x56, 0x85, 0x23, 0x65, 0x6b, 0x56, 0x07, 0x34, 0x3a, 0x07, 0x72, + 0xd2, 0x8c, 0x47, 0xeb, 0x43, 0x6a, 0xe0, 0x1b, 0x2b, 0x8d, 0x08, 0xc3, + 0xa1, 0xf0, 0x32, 0x28, 0xa9, 0x66, 0xa0, 0xf0, 0x63, 0x47, 0x33, 0x77, + 0x9d, 0x46, 0xb1, 0x35, 0xfc, 0x75, 0xf5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49, 0x63, 0x85, 0x95, 0xcf, + 0xb6, 0x69, 0x0c, 0x04, 0x82, 0x5d, 0x17, 0x76, 0xaf, 0x5a, 0x49, 0x57, + 0xc0, 0x70, 0xb9, 0x7c, 0x39, 0x05, 0xa3, 0xbc, 0x65, 0xcd, 0x7b, 0x19, + 0xeb, 0x61, 0x95, 0x0b, 0x28, 0x52, 0x80, 0x83, 0x54, 0xad, 0x7a, 0xbd, + 0x8d, 0x4b, 0x01, 0xd9, 0xa0, 0xa6, 0x7e, 0x63, 0x89, 0xde, 0x40, 0x58, + 0xb2, 0x13, 0x7c, 0x7b, 0xf0, 0x09, 0x48, 0x2b, 0x1a, 0x25, 0x74, 0x85, + 0x4f, 0x36, 0x79, 0xca, 0xb9, 0x2d, 0x6d, 0x10, 0x06, 0xb8, 0x80, 0x3f, + 0xc2, 0xe6, 0x1e, 0x36, 0x4a, 0x50, 0x57, 0x67, 0x93, 0x2c, 0x7b, 0xba, + 0xd3, 0xc7, 0xb1, 0x68, 0x31, 0x15, 0x8f, 0x22, 0x41, 0xe9, 0xc1, 0x03, + 0xe2, 0xe2, 0xa7, 0x95, 0x74, 0x25, 0x83, 0x97, 0xb8, 0x89, 0x16, 0x14, + 0x97, 0x89, 0xb4, 0xb5, 0xb5, 0x9d, 0x94, 0xc6, 0x03, 0xb2, 0x4a, 0x2a, + 0x11, 0x22, 0x80, 0x14, 0x0a, 0x66, 0x91, 0xb3, 0xc9, 0x90, 0xf7, 0x40, + 0x55, 0xb9, 0xa4, 0x6a, 0x12, 0xc0, 0xe9, 0xc3, 0xae, 0xdd, 0x4a, 0x3f, + 0x21, 0xa7, 0xa6, 0x47, 0x4b, 0x0a, 0x0e, 0xb7, 0x35, 0xbd, 0x45, 0x5d, + 0x77, 0x6c, 0xaf, 0xc0, 0x72, 0x3f, 0x44, 0xc4, 0x3b, 0xba, 0xc3, 0x94, + 0x88, 0x69, 0x9b, 0x8a, 0x9c, 0x38, 0xfb, 0x65, 0xa8, 0x33, 0x49,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 0x78, 0x13, 0x09, 0xd7, 0xa2, 0x64, 0x29, 0x01, 0x93, 0x81, 0x5d, + 0x64, 0x6a, 0x3d, 0x99, 0xaa, 0x8f, 0xdc, 0xa7, 0x35, 0xc9, 0x4c, 0x9c, + 0x07, 0x41, 0x27, 0x14, 0xd6, 0x50, 0x06, 0x22, 0x32, 0xa2, 0xab, 0x9a, + 0xa7, 0x66, 0xad, 0xa4, 0x7a, 0xaf, 0xba, 0x00, 0x83, 0xf6, 0x13, 0xa3, + 0x83, 0xc6, 0x8a, 0xd7, 0xc6, 0x50, 0x5e, 0x05, 0x2e, 0x9e, 0xd4, 0xc5, + 0xc0, 0x7a, 0x2f, 0x6d, 0x26, 0x7d, 0x35, 0xb7, 0x00, 0x73, 0x5c, 0x4a, + 0x99, 0xb7, 0xbc, 0x48, 0x25, 0x93, 0x8f, 0x55, 0x84, 0xbe, 0x87, 0x40, + 0x40, 0x54, 0x16, 0x4f, 0xab, 0x9f, 0x1e, 0xeb, 0xc8, 0xa3, 0xe0, 0xb5, + 0xa3, 0xa8, 0xcb, 0x34, 0x96, 0x6b, 0xa8, 0x4c, 0x32, 0x06, 0x38, 0xc5, + 0xa5, 0xc0, 0x4f, 0x33, 0xbc, 0x45, 0xfc, 0x3a, 0x62, 0x4b, 0x68, 0xa6, + 0x71, 0x60, 0xcd, 0x8e, 0xf2, 0xa3, 0xd2, 0xb4, 0x1f, 0xc4, 0xc9, 0x13, + 0x15, 0x32, 0x80, 0x95, 0x21, 0x83, 0x8d, 0x52, 0x1b, 0xe9, 0x68, 0x1b, + 0x81, 0xdc, 0x2c, 0x11, 0x47, 0x5c, 0x60, 0x16, 0x2c, 0xc7, 0xc0, 0x7c, + 0x44, 0x39, 0x82, 0x5d, 0x32, 0x82, 0x04, 0x32, 0x20, 0x57, 0x78, 0x90, + 0x4e, 0xf2, 0x07, 0x95, 0xc5, 0x6e, 0x67, 0x11, 0x40, 0x6a, 0x88, 0x5b, + 0x8c, 0x90, 0x32, 0xe2, 0x72, 0x5b, 0xf6, 0x42, 0x1d, 0xc0, 0xa9, 0x10, + 0x7c, 0x8a, 0x2c, 0x9b, 0x49, 0x0f, 0xfb, 0x0a, 0xb2, 0x85, 0x79, 0xa8, + 0x19, 0x96, 0xc9, 0x2b, 0x64, 0x5c, 0x47, 0x11, 0x1c, 0x57, 0xb2, 0x10, + 0x06, 0x28, 0x76, 0x4c, 0x86, 0x0b, 0x9a, 0x12, 0x58, 0x94, 0xe5, 0x2a, + 0xde, 0x70, 0xc4, 0x64, 0xa4, 0x90, 0x2d, 0xc1, 0x67, 0x5b, 0x64, 0xae, + 0xa0, 0x1a, 0x7b, 0x30, 0x64, 0xb0, 0x99, 0xf4, 0x61, 0x53, 0xfa, 0x20, + 0x6d, 0xa5, 0x84, 0x98, 0xb2, 0x0f, 0x8b, 0x17, 0x17, 0x8b, 0x7a, 0x20, + 0xf0, 0x68, 0x00, 0xb9, 0xf0, 0xcf, 0x3f, 0x59, 0xc9, 0x12, 0xf5, 0x08, + 0x5c, 0xf3, 0x45, 0x05, 0x3b, 0x88, 0x95, 0xf4, 0xb2, 0xdb, 0x89, 0x8a, + 0x42, 0xb0, 0x58, 0xc5, 0xc6, 0x2e, 0xb0, 0xc5, 0x41, 0xad, 0xa4, 0x59, + 0xae, 0xf6, 0xbd, 0x99, 0x48, 0xb8, 0xff, 0x50, 0x95, 0x37, 0xab, 0x15, + 0x50, 0x30, 0x34, 0xd0, 0xa4, 0x10, 0xed, 0xaa, 0x03, 0xf4, 0xd4, 0x90, + 0xf1, 0x42, 0x1c, 0x0b, 0xec, 0x48, 0x38, 0x83, 0x25, 0xe4, 0x02, 0xa5, + 0x96, 0x14, 0x62, 0x68, 0x75, 0xcc, 0x8d, 0x2c, 0x48, 0x1d, 0xd9, 0x04, + 0x8a, 0x17, 0x7e, 0x9b, 0x90, 0x6f, 0xc4, 0x50, 0x38, 0x70, 0x61, 0x08, + 0x5b, 0xa7, 0x3e, 0x2f, 0x1b, 0x49, 0xe5, 0x8b, 0xca, 0x05, 0xbd, 0xa0, + 0x91, 0x73, 0xf8, 0x56, 0xdf, 0x8b, 0xc3, 0x8c}; +static const uint8_t test_vector_sk_768[2400] = { + 0xaf, 0x54, 0x39, 0xf3, 0xdb, 0x8d, 0x4a, 0x97, 0xc9, 0x75, 0xe4, 0x52, + 0xa5, 0xc3, 0x01, 0xa0, 0x16, 0x15, 0x03, 0x81, 0x2b, 0xb6, 0xa6, 0x99, + 0xf6, 0xaa, 0x40, 0xb7, 0x2c, 0x3f, 0x6c, 0x0a, 0xa5, 0xa0, 0x72, 0x04, + 0x89, 0x24, 0x0d, 0x47, 0x5c, 0x5a, 0x53, 0x02, 0x3b, 0x70, 0x59, 0x8f, + 0xbd, 0xeb, 0x20, 0x79, 0x2c, 0x8c, 0x8e, 0x26, 0x6a, 0xce, 0x08, 0x86, + 0x68, 0x32, 0x77, 0x87, 0x92, 0x31, 0xee, 0x93, 0x4b, 0x81, 0x4c, 0x6f, + 0x78, 0xa2, 0x81, 0x38, 0xba, 0x7c, 0x7c, 0xd9, 0x51, 0xe3, 0x38, 0x8b, + 0x70, 0xb5, 0x44, 0x2e, 0xe2, 0xaa, 0xdd, 0xd7, 0x81, 0xdd, 0xb1, 0xa2, + 0x7f, 0x39, 0xcd, 0x80, 0x82, 0x28, 0xb1, 0x21, 0xa1, 0x30, 0x49, 0x8c, + 0xa7, 0xc3, 0xb3, 0xe4, 0x31, 0xc0, 0x4e, 0xc0, 0xae, 0x3b, 0x6b, 0x0e, + 0xc5, 0xf1, 0x74, 0x21, 0x35, 0xaa, 0x9e, 0x45, 0x73, 0x7a, 0xa3, 0x20, + 0xd3, 0x8c, 0x4c, 0x2d, 0x40, 0x4d, 0x03, 0xe9, 0x04, 0xa1, 0xb6, 0xc9, + 0x92, 0x16, 0x7f, 0xb9, 0x28, 0x00, 0x21, 0xd8, 0xa3, 0x26, 0x59, 0x9a, + 0x1b, 0x7b, 0x72, 0xe4, 0x35, 0x54, 0x68, 0x94, 0x0e, 0x4f, 0x08, 0x61, + 0x26, 0x05, 0x35, 0x29, 0x29, 0x0f, 0xe8, 0xe1, 0xcd, 0x65, 0xf9, 0x46, + 0x7a, 0x05, 0x6d, 0x11, 0x87, 0x79, 0xc1, 0x95, 0x62, 0x39, 0x81, 0x22, + 0xb7, 0xf2, 0x29, 0x68, 0xb3, 0x62, 0x38, 0x28, 0xb7, 0x96, 0x35, 0x94, + 0xd7, 0x44, 0x5a, 0x7f, 0x3a, 0x4b, 0x04, 0x4b, 0xcf, 0x2c, 0xec, 0x0f, + 0xbb, 0x2a, 0x4d, 0xbc, 0x58, 0x1b, 0x41, 0x84, 0xb9, 0x0f, 0x70, 0xb5, + 0x02, 0xa0, 0x26, 0x02, 0xdc, 0x5e, 0x56, 0xc8, 0x7b, 0x98, 0x62, 0x2e, + 0xab, 0x24, 0x56, 0xec, 0xe4, 0x67, 0x4a, 0x0a, 0x1d, 0xee, 0xa1, 0x0d, + 0xf2, 0xd7, 0x1b, 0xdf, 0x36, 0x90, 0x9b, 0x91, 0xaf, 0xa8, 0x52, 0x2a, + 0x2d, 0x65, 0x81, 0xea, 0x72, 0x97, 0xe1, 0xdc, 0x94, 0x49, 0xc1, 0x9d, + 0x01, 0x25, 0x34, 0x96, 0xa7, 0x73, 0x26, 0xb0, 0xad, 0x78, 0xb6, 0xb4, + 0xfe, 0x13, 0x1b, 0xe1, 0xe6, 0x2e, 0xf0, 0x41, 0x71, 0x5f, 0x33, 0x0b, + 0x35, 0x01, 0x21, 0x3e, 0xa8, 0x6f, 0x62, 0x56, 0x02, 0xcb, 0x85, 0x4d, + 0xf9, 0xf8, 0xca, 0x48, 0xf8, 0x3c, 0xae, 0x26, 0x9b, 0x17, 0x8b, 0x09, + 0x96, 0xf8, 0x1e, 0xea, 0xf8, 0x25, 0x79, 0x67, 0x7a, 0xe5, 0x03, 0x99, + 0xbd, 0x51, 0x39, 0xf6, 0xd9, 0x45, 0x2e, 0x8b, 0x56, 0x27, 0x3a, 0x77, + 0x9c, 0x0c, 0x85, 0xd0, 0x10, 0x00, 0xcf, 0x93, 0xb0, 0x6f, 0xb1, 0x47, + 0xa2, 0x87, 0x32, 0xcc, 0x6c, 0x78, 0x94, 0x10, 0xb6, 0x5d, 0xa8, 0x77, + 0xa9, 0xc1, 0x11, 0x54, 0x80, 0x4f, 0xd6, 0xf5, 0x36, 0x21, 0xf2, 0x83, + 0x73, 0x82, 0xa1, 0x98, 0xf9, 0x1a, 0x20, 0x90, 0x04, 0xe8, 0xb1, 0xcf, + 0x0b, 0x0b, 0x31, 0x86, 0x17, 0x08, 0x15, 0x3c, 0x5a, 0x13, 0x47, 0x85, + 0xdb, 0x68, 0x9d, 0x7a, 0xe6, 0x7a, 0xf9, 0xc9, 0xb9, 0x23, 0x44, 0xce, + 0x08, 0x8b, 0x09, 0xf4, 0xdc, 0x11, 0x9d, 0x6a, 0x67, 0xd2, 0x2c, 0x29, + 0xc0, 0x88, 0x3e, 0x7a, 0xe8, 0x9c, 0x9b, 0x95, 0x38, 0x73, 0xea, 0x39, + 0x9b, 0x03, 0x85, 0x67, 0xc0, 0xca, 0x8e, 0x57, 0x66, 0x6d, 0x26, 0x60, + 0x3c, 0xf7, 0xcb, 0xfb, 0xac, 0x0c, 0x5e, 0x36, 0xb8, 0xd3, 0x91, 0x19, + 0xee, 0x5c, 0x01, 0xf2, 0x87, 0xc7, 0x4a, 0xf2, 0xb8, 0xca, 0x37, 0x58, + 0x96, 0x87, 0x0f, 0xfc, 0x39, 0x32, 0xbf, 0x38, 0x96, 0xa0, 0x8c, 0x8a, + 0xd9, 0x4a, 0xa0, 0x8b, 0xd8, 0x1e, 0x28, 0x97, 0xbf, 0x34, 0x98, 0x70, + 0x57, 0xfc, 0x08, 0xe9, 0x36, 0x7c, 0xf3, 0x3c, 0x62, 0x77, 0x2b, 0xad, + 0x79, 0x66, 0xb9, 0xff, 0xb1, 0xc8, 0x43, 0x21, 0x28, 0x33, 0x82, 0x2b, + 0x7c, 0x31, 0xb3, 0x8e, 0x14, 0x1c, 0x00, 0x7b, 0x85, 0x66, 0xf1, 0xad, + 0xa5, 0x34, 0x36, 0x77, 0x40, 0xaa, 0x89, 0x39, 0x50, 0xb7, 0x76, 0xaf, + 0x88, 0x1a, 0x4a, 0x13, 0x41, 0x36, 0x96, 0x51, 0x69, 0xf3, 0x79, 0x99, + 0x70, 0x0a, 0x8d, 0xd2, 0xc5, 0xa1, 0x40, 0x10, 0x52, 0xbe, 0x49, 0x88, + 0x0b, 0xa8, 0x2a, 0xd5, 0x6a, 0x7e, 0xc1, 0xfc, 0xc0, 0x58, 0x84, 0x4f, + 0xd3, 0xeb, 0x14, 0x08, 0x58, 0x07, 0x5c, 0x27, 0xae, 0xea, 0x8b, 0x1e, + 0xfa, 0x28, 0x9d, 0xbf, 0xbc, 0x12, 0x40, 0xf1, 0x14, 0x6d, 0x63, 0x47, + 0x98, 0x13, 0x4d, 0xde, 0x00, 0x74, 0xf0, 0xa4, 0xbc, 0xc5, 0x13, 0xc3, + 0x1a, 0x83, 0x09, 0x53, 0x03, 0x10, 0xc0, 0x62, 0xbf, 0x4c, 0x92, 0x3f, + 0xc1, 0x0c, 0x1c, 0xba, 0x98, 0x4e, 0x24, 0xb8, 0x81, 0xd3, 0x05, 0x92, + 0xcf, 0xb3, 0xb2, 0x89, 0x1b, 0xc3, 0x72, 0x14, 0x21, 0xb7, 0x23, 0x26, + 0x64, 0x63, 0x7e, 0x05, 0x97, 0x26, 0x72, 0xc8, 0x41, 0xcf, 0x73, 0x08, + 0x11, 0x09, 0x2d, 0x06, 0x54, 0x64, 0xb2, 0xe0, 0x4f, 0xc3, 0x11, 0x3f, + 0x2c, 0x36, 0x7d, 0x1f, 0x29, 0xa7, 0xb9, 0xe1, 0x30, 0xeb, 0xb0, 0xb2, + 0x42, 0x80, 0xb5, 0x45, 0xd6, 0x7e, 0x1e, 0x0a, 0x17, 0x09, 0x30, 0x2b, + 0x9e, 0xb9, 0x0c, 0x84, 0x8a, 0x8e, 0xd3, 0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, 0xc8, 0x78, + 0x78, 0x53, 0x9e, 0xb6, 0xdb, 0x40, 0x6f, 0xc0, 0xc6, 0xad, 0x90, 0x8f, + 0x42, 0x72, 0xc0, 0x20, 0x9a, 0x85, 0x8a, 0xa6, 0xbf, 0xd5, 0xf8, 0x7d, + 0xfe, 0xa6, 0x37, 0xad, 0xb8, 0x74, 0xbe, 0xb5, 0xbc, 0x14, 0x38, 0x92, + 0xb8, 0xa3, 0x78, 0xdf, 0xe9, 0x34, 0x7e, 0x72, 0x73, 0x85, 0xca, 0x24, + 0x43, 0x22, 0xbd, 0xe5, 0x56, 0x6b, 0xcd, 0xd7, 0x46, 0xc5, 0x03, 0xcd, + 0x83, 0x88, 0x21, 0x8f, 0xc3, 0x10, 0x56, 0xb9, 0x2a, 0xc6, 0xe8, 0x09, + 0x31, 0x76, 0x13, 0xf0, 0x31, 0xb2, 0x22, 0xc1, 0x95, 0x41, 0x76, 0x4b, + 0x04, 0x2b, 0x65, 0x07, 0x06, 0xa8, 0x14, 0xe8, 0x7b, 0x96, 0x98, 0x58, + 0xa8, 0xe3, 0x7e, 0xd5, 0xa4, 0x79, 0x89, 0x1c, 0x5a, 0x30, 0xb8, 0x50, + 0x34, 0x67, 0x22, 0xd7, 0x80, 0xb1, 0x7e, 0x0b, 0x55, 0x32, 0x92, 0x3e, + 0x30, 0x17, 0x2b, 0x6c, 0x49, 0x99, 0x7b, 0x5a, 0x4c, 0xf4, 0xc5, 0xcd, + 0x20, 0x65, 0x7a, 0x83, 0x31, 0x41, 0xcd, 0xe8, 0xcd, 0x67, 0x61, 0x91, + 0x95, 0x86, 0x2f, 0xa7, 0xc8, 0x49, 0xc8, 0x17, 0x5b, 0x49, 0xba, 0x58, + 0x56, 0xf9, 0xb3, 0x91, 0x96, 0x08, 0x16, 0x6c, 0x07, 0x25, 0xa5, 0x65, + 0x9c, 0xaa, 0x99, 0x4a, 0xa6, 0x3e, 0xdc, 0x7a, 0x85, 0x37, 0xf4, 0xc0, + 0xe1,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0x03, 0x10, + 0x88, 0x26, 0x6c, 0xb8, 0x69, 0x99, 0x97, 0x8a, 0x05, 0x2c, 0xa0, 0x33, + 0x19, 0xf9, 0x6b, 0x07, 0x62, 0x23, 0x46, 0xa8, 0x29, 0xe6, 0x28, 0x74, + 0x6e, 0xb4, 0xa3, 0x77, 0xfa, 0x5e, 0xd3, 0xa0, 0xa4, 0xf8, 0xd9, 0xb0, + 0xb3, 0x36, 0x43, 0xb0, 0xd7, 0xbf, 0xc9, 0x44, 0x8b, 0x7e, 0x93, 0xb0, + 0x78, 0x62, 0x43, 0xb0, 0x9a, 0xb9, 0x84, 0x45, 0x1d, 0x36, 0xa2, 0x5a, + 0x56, 0x5c, 0x3b, 0xbb, 0x82, 0x56, 0x98, 0xc5, 0x6f, 0xf5, 0x35, 0xb7, + 0xb7, 0x13, 0x0b, 0xe2, 0x67, 0x59, 0x9a, 0x0b, 0x5a, 0x76, 0x2c, 0x18, + 0x57, 0x2b, 0x66, 0x89, 0xca, 0x70, 0x4c, 0xd7, 0x97, 0x94, 0xe5, 0x24, + 0xe9, 0xa2, 0x0b, 0x38, 0xb6, 0x4d, 0x3b, 0xa3, 0xb2, 0x2d, 0xd5, 0x94, + 0xc8, 0x75, 0xab, 0x75, 0x63, 0x09, 0x27, 0x67, 0x44, 0x12, 0xc1, 0x55, + 0xc8, 0x26, 0xbd, 0xe1, 0x2c, 0x73, 0xa0, 0xb4, 0x8f, 0x26, 0xc9, 0x6a, + 0x45, 0xc9, 0x08, 0xe1, 0x0b, 0xba, 0x27, 0x22, 0x54, 0x14, 0xc2, 0x12, + 0x24, 0x78, 0x13, 0x09, 0xd7, 0xa2, 0x64, 0x29, 0x01, 0x93, 0x81, 0x5d, + 0x64, 0x6a, 0x3d, 0x99, 0xaa, 0x8f, 0xdc, 0xa7, 0x35, 0xc9, 0x4c, 0x9c, + 0x07, 0x41, 0x27, 0x14, 0xd6, 0x50, 0x06, 0x22, 0x32, 0xa2, 0xab, 0x9a, + 0xa7, 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4c, 0x86, 0x0b, 0x9a, 0x12, 0x58, 0x94, 0xe5, 0x2a, + 0xde, 0x70, 0xc4, 0x64, 0xa4, 0x90, 0x2d, 0xc1, 0x67, 0x5b, 0x64, 0xae, + 0xa0, 0x1a, 0x7b, 0x30, 0x64, 0xb0, 0x99, 0xf4, 0x61, 0x53, 0xfa, 0x20, + 0x6d, 0xa5, 0x84, 0x98, 0xb2, 0x0f, 0x8b, 0x17, 0x17, 0x8b, 0x7a, 0x20, + 0xf0, 0x68, 0x00, 0xb9, 0xf0, 0xcf, 0x3f, 0x59, 0xc9, 0x12, 0xf5, 0x08, + 0x5c, 0xf3, 0x45, 0x05, 0x3b, 0x88, 0x95, 0xf4, 0xb2, 0xdb, 0x89, 0x8a, + 0x42, 0xb0, 0x58, 0xc5, 0xc6, 0x2e, 0xb0, 0xc5, 0x41, 0xad, 0xa4, 0x59, + 0xae, 0xf6, 0xbd, 0x99, 0x48, 0xb8, 0xff, 0x50, 0x95, 0x37, 0xab, 0x15, + 0x50, 0x30, 0x34, 0xd0, 0xa4, 0x10, 0xed, 0xaa, 0x03, 0xf4, 0xd4, 0x90, + 0xf1, 0x42, 0x1c, 0x0b, 0xec, 0x48, 0x38, 0x83, 0x25, 0xe4, 0x02, 0xa5, + 0x96, 0x14, 0x62, 0x68, 0x75, 0xcc, 0x8d, 0x2c, 0x48, 0x1d, 0xd9, 0x04, + 0x8a, 0x17, 0x7e, 0x9b, 0x90, 0x6f, 0xc4, 0x50, 0x38, 0x70, 0x61, 0x08, + 0x5b, 0xa7, 0x3e, 0x2f, 0x1b, 0x49, 0xe5, 0x8b, 0xca, 0x05, 0xbd, 0xa0, + 0x91, 0x73, 0xf8, 0x56, 0xdf, 0x8b, 0xc3, 0x8c, 0xa9, 0x77, 0x15, 0xc9, + 0xaf, 0x11, 0xeb, 0xb5, 0x52, 0xf3, 0x04, 0x3e, 0x4c, 0x58, 0xca, 0xba, + 0xa5, 0x43, 0x41, 0xdd, 0x4c, 0x59, 0xf2, 0x9f, 0x1c, 0x5b, 0x0e, 0x12, + 0x5c, 0x19, 0x59, 0xd5, 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, + 0x49, 0x37, 0xb0, 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, + 0x60, 0x69, 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +static const uint8_t test_vector_ct_768[1088] = { + 0x12, 0xf9, 0x4e, 0xf4, 0xe4, 0xf6, 0xea, 0x11, 0x18, 0x3f, 0x2c, 0x50, + 0x0f, 0x9a, 0x72, 0x9e, 0x06, 0xb0, 0x4d, 0x83, 0x75, 0x3a, 0xa1, 0xb7, + 0xf6, 0xd0, 0x9e, 0x8a, 0xf2, 0x75, 0xbd, 0x0f, 0x4d, 0x06, 0x00, 0x82, + 0xd3, 0x1e, 0xe6, 0x02, 0x75, 0x19, 0xbb, 0xa7, 0x36, 0xb6, 0xbb, 0x66, + 0xa9, 0x8c, 0xcd, 0x71, 0x25, 0x93, 0x16, 0x9e, 0x17, 0x8b, 0x9c, 0xca, + 0x46, 0xa9, 0x1b, 0x85, 0x19, 0xfe, 0x52, 0xf1, 0xa1, 0xd0, 0x54, 0x57, + 0x39, 0x0b, 0x14, 0x7a, 0x72, 0x35, 0xd2, 0xd3, 0x42, 0x14, 0x2f, 0x78, + 0xb5, 0xd8, 0xd9, 0x17, 0x77, 0x25, 0xa6, 0x1f, 0x08, 0x3e, 0x85, 0x26, + 0xdf, 0xf2, 0xf8, 0xdc, 0x98, 0x8f, 0xe8, 0x38, 0xa4, 0x49, 0x6f, 0x6c, + 0x31, 0xc5, 0x2c, 0xfe, 0xe1, 0x9d, 0x8b, 0x4e, 0xc2, 0x93, 0x98, 0x92, + 0xee, 0x9d, 0x6c, 0xfd, 0x4f, 0xfd, 0xcc, 0xce, 0x96, 0xab, 0x6a, 0x66, + 0x03, 0x53, 0xcd, 0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 0x9b, 0xa5, 0x14, 0xf7, 0x54, 0x27, 0xbd, + 0x59, 0x33, 0xe6, 0xde, 0x58, 0x0a, 0xf1, 0x78, 0xff, 0xf9, 0xc0, 0xb8, + 0xa5, 0x05, 0x7e, 0x54, 0x24, 0x08, 0x97, 0x1d, 0xa7, 0xbf, 0x7e, 0x71, + 0xf4, 0x38, 0x0d, 0x7a, 0x3b, 0x27, 0xbe, 0x79, 0x4a, 0x09, 0x63, 0x61, + 0x7d, 0x84, 0x03, 0xa6, 0x70, 0x3b, 0x44, 0x93, 0x5f, 0x65, 0x4d, 0x6d, + 0x4b, 0x15, 0xe4, 0xcb, 0xdc, 0x14, 0x7b, 0x07, 0xc0, 0xff, 0xda, 0xfa, + 0xe6, 0x2b, 0x14, 0xfa, 0x44, 0x24, 0x29, 0xda, 0x61, 0x4f, 0x46, 0x57, + 0x3d, 0x63, 0xee, 0x80, 0xb5, 0xbf, 0x00, 0x6b, 0xf7, 0xe2, 0x2b, 0x05, + 0xd6, 0xa3, 0xae, 0xf5, 0x4d, 0x84, 0xa3, 0xdc, 0xe1, 0x46, 0x64, 0x83, + 0xdd, 0xc8, 0x28, 0x43, 0x35, 0xa1, 0x9e, 0xda, 0xf0, 0xcb, 0x78, 0x5f, + 0xe3, 0x80, 0x42, 0xf5, 0x65, 0xd3, 0xbb, 0xb4, 0xea, 0x78, 0x11, 0xea, + 0x7f, 0x7f, 0xe3, 0xbb, 0x46, 0x7e, 0x76, 0xc0, 0x78, 0x41, 0x22, 0x3c, + 0xdf, 0x89, 0x46, 0xf2, 0x70, 0xa8, 0x52, 0x2f, 0x99, 0xe4, 0x38, 0xa8, + 0x35, 0x2c, 0x5c, 0x57, 0x71, 0x22, 0x13, 0xc7, 0xf9, 0x8e, 0xe9, 0x1b, + 0x03, 0xb1, 0x4f, 0x2c, 0x05, 0x80, 0xaa, 0x8b, 0xb7, 0xf4, 0x0d, 0x27, + 0x92, 0x89, 0xa1, 0x93, 0xa0, 0xad, 0x66, 0x67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0x7c, 0x8d, 0xd8, 0xc3, 0x05, 0x51, 0x7d, 0x6e, 0xdb, 0x31, 0x7e, 0x8e, + 0x55, 0xa3, 0xdf, 0xfe, 0xdd, 0xd6, 0xaf, 0x14, 0x7f, 0xba, 0xe1, 0x71, + 0x9a, 0x6f, 0x89, 0x48, 0x28, 0xbf, 0x9c, 0xfb, 0x9c, 0x13, 0xf1, 0xe6, + 0x1a, 0xc6, 0x5c, 0x5b, 0x9b, 0x5e, 0xbd, 0x0a}; +static const uint8_t test_vector_ss_768[32] = { + 0x0b, 0x1b, 0x32, 0xbe, 0x26, 0x24, 0x7c, 0xbc, 0xbe, 0x09, 0x16, + 0xf8, 0xb0, 0xb7, 0x29, 0x69, 0x9c, 0x32, 0xa9, 0x6d, 0x51, 0xef, + 0xa4, 0xa4, 0xcd, 0x5b, 0x28, 0x92, 0x39, 0xc8, 0x20, 0x7e}; + +/* ML-KEM-1024 */ +static const uint8_t test_vector_pk_1024[1568] = { + 0x0a, 0xb5, 0x37, 0xed, 0x94, 0x0a, 0xea, 0x14, 0x1c, 0xef, 0xeb, 0xb9, + 0x82, 0x80, 0x03, 0x8b, 0xe1, 0x3f, 0x7c, 0xdc, 0x8d, 0x1e, 0xd2, 0x09, + 0xd3, 0x34, 0xb6, 0xae, 0xea, 0xa0, 0xed, 0xd2, 0x89, 0x71, 0xa5, 0x91, + 0x15, 0xc8, 0x7f, 0xc6, 0x29, 0x89, 0x98, 0x6c, 0x93, 0x57, 0x91, 0x84, + 0x06, 0x4b, 0x6b, 0xfe, 0x38, 0x2e, 0x29, 0x34, 0x87, 0x25, 0x90, 0x83, + 0x33, 0x17, 0x0b, 0x7e, 0xe4, 0x2e, 0xb2, 0xf8, 0xc2, 0x1f, 0x13, 0x20, + 0x15, 0x5a, 0xa3, 0x95, 0x91, 0x06, 0x38, 0x2a, 0x08, 0xfb, 0x52, 0x73, + 0x27, 0xa5, 0x42, 0x02, 0xe9, 0x1c, 0xeb, 0x39, 0x3e, 0x95, 0x2c, 0x6c, + 0x90, 0xc9, 0xcd, 0x23, 0x92, 0x7d, 0xb1, 0x88, 0xb3, 0x6d, 0x2a, 0x68, + 0x43, 0x9b, 0x59, 0xca, 0x96, 0x92, 0x9e, 0x93, 0x3f, 0x2d, 0x0a, 0xcd, + 0xcd, 0x6a, 0xc1, 0x0b, 0x3a, 0x64, 0x67, 0x2a, 0xa0, 0x31, 0x12, 0x92, + 0xf2, 0x37, 0x06, 0x35, 0x96, 0x88, 0x53, 0x44, 0x29, 0xc6, 0x91, 0x96, + 0x41, 0x8b, 0x6b, 0x5b, 0xa7, 0x69, 0x42, 0xb1, 0xa7, 0x72, 0x08, 0xcc, + 0x11, 0x0c, 0x2e, 0xa7, 0xc2, 0x9b, 0x3a, 0x09, 0x01, 0x27, 0x71, 0x48, + 0x99, 0x4b, 0x1c, 0x32, 0x3a, 0x0f, 0x79, 0xd3, 0x0c, 0xe7, 0xec, 0x76, + 0xdb, 0xbc, 0x76, 0xef, 0x9b, 0x14, 0x5a, 0xd0, 0x42, 0x95, 0xc3, 0x04, + 0xee, 0x42, 0x8d, 0x10, 0x6b, 0xa1, 0x89, 0x39, 0xbf, 0x3d, 0x00, 0xd0, + 0xe7, 0x75, 0xc4, 0x60, 0x69, 0x1b, 0x25, 0xf5, 0x35, 0x2e, 0xbc, 0x19, + 0xd1, 0xa1, 0xad, 0x9d, 0x70, 0x4e, 0xad, 0x8a, 0x67, 0xa9, 0xc5, 0x76, + 0x3a, 0xfc, 0x42, 0x32, 0x1a, 0x70, 0x18, 0xd7, 0x6d, 0xc0, 0x2b, 0xb2, + 0x01, 0x10, 0x6a, 0x83, 0xba, 0x34, 0xc4, 0xd4, 0x7a, 0x38, 0xb1, 0x35, + 0x3c, 0xdb, 0x4e, 0x2d, 0x8a, 0xb9, 0x3b, 0x58, 0xce, 0x25, 0x90, 0xc2, + 0xa3, 0x05, 0x89, 0x59, 0xc3, 0x98, 0x61, 0xa8, 0xa8, 0x22, 0x3b, 0x44, + 0xfd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0x54, 0x9e, 0x03, 0xac, 0xe4, 0x5a, 0x51, + 0x5d, 0xb7, 0x45, 0xff, 0x47, 0xa5, 0x9b, 0x23, 0x9c, 0x87, 0xb4, 0x62, + 0x9d, 0xb6, 0x6d, 0xdc, 0x86, 0x22, 0x1a, 0x50, 0x2c, 0x65, 0x06, 0x19, + 0xa0, 0x4c, 0xa1, 0xe3, 0x21, 0x8f, 0x8b, 0xe6, 0x31, 0x84, 0xa4, 0xa7, + 0x21, 0xfa, 0x9c, 0x76, 0x74, 0x18, 0xc6, 0x85, 0x0c, 0x6f, 0x43, 0x0d, + 0x91, 0x43, 0x16, 0x0e, 0x7c, 0x72, 0x78, 0x42, 0x1e, 0x16, 0x1c, 0x37, + 0xde, 0xd7, 0x16, 0xf9, 0x82, 0x6d, 0x13, 0xb0, 0xb8, 0xc1, 0xd2, 0x7f, + 0x08, 0xba, 0x19, 0xd3, 0xf1, 0x6d, 0x67, 0x17, 0x1f, 0x9e, 0xea, 0x41, + 0x6a, 0xb3, 0x79, 0x09, 0x3b, 0x8c, 0xb6, 0xf1, 0x82, 0xe4, 0xa3, 0x08, + 0xe0, 0xaa, 0x76, 0x12, 0x30, 0xbd, 0x46, 0x40, 0x10, 0x2d, 0xfb, 0x2c, + 0x89, 0x36, 0x14, 0x8c, 0x69, 0x83, 0x00, 0x41, 0x46, 0x6f, 0x07, 0x87, + 0xe6, 0x43, 0x36, 0x02, 0xe4, 0x5c, 0xb3, 0xa0, 0xb8, 0x1f, 0x66, 0x10, + 0xbd, 0x09, 0xca, 0x5b, 0x86, 0x09, 0x3f, 0x13, 0x43, 0xa3, 0x24, 0x93, + 0xe9, 0x92, 0xcb, 0x00, 0x59, 0x81, 0xc1, 0x06, 0x21, 0xe6, 0x86, 0xbd, + 0xa5, 0xa5, 0x84, 0xe0, 0xa0, 0x43, 0x60, 0xc8, 0x61, 0xf9, 0x97, 0x50, + 0x33, 0xd4, 0x3b, 0x0a, 0x62, 0x9e, 0x58, 0xfc, 0xa8, 0x95, 0xc7, 0x0e, + 0xa1, 0x75, 0x81, 0xf9, 0xb6, 0x3e, 0x81, 0x76, 0x57, 0x3e, 0xec, 0x38, + 0x9f, 0x48, 0x64, 0x3d, 0x63, 0x56, 0xe9, 0x88, 0x86, 0x90, 0xe3, 0x13, + 0xff, 0xd1, 0x1b, 0x6c, 0xea, 0x7d, 0xe4, 0x44, 0x0c, 0x8a, 0xb2, 0x72, + 0x3d, 0x16, 0x67, 0x57, 0x19, 0x6e, 0x9c, 0x2c, 0x88, 0xc3, 0x90, 0x1b, + 0x42, 0xc3, 0x81, 0x6b, 0x78, 0x5d, 0xda, 0x41, 0x85, 0x34, 0xac, 0x16, + 0xa4, 0x98, 0xad, 0x6b, 0xe6, 0x05, 0xcb, 0xa1, 0xab, 0x8f, 0xf8, 0x95, + 0x25, 0xd9, 0x9b, 0x93, 0x38, 0xc4, 0x2f, 0x55, 0x35, 0xea, 0x85, 0xb1, + 0x4e, 0xda, 0x15, 0xe2, 0x94, 0x15, 0x3b, 0x13, 0x7b, 0x79, 0x7b, 0x72, + 0xd7, 0x28, 0x36, 0x41, 0x71, 0x04, 0x2f, 0x29, 0x8a, 0x91, 0x56, 0x1b, + 0xc8, 0xdc, 0x0a, 0xe5, 0x88, 0x7d, 0x0a, 0xac, 0xbd, 0xd3, 0xcc, 0x9d, + 0x5e, 0x6c, 0x37, 0xd4, 0x27, 0x66, 0xa4, 0xa7, 0x6b, 0x54, 0xab, 0x02, + 0x0e, 0xd1, 0xba, 0x7e, 0xac, 0x5c, 0xf0, 0xe8, 0x4b, 0xf9, 0xc0, 0xb7, + 0x99, 0xd6, 0x27, 0xd1, 0xc8, 0x4b, 0xb6, 0xd1, 0x04, 0x2b, 0x81, 0x23, + 0x1e, 0x52, 0x70, 0x11, 0xc8, 0xb8, 0x3c, 0x8c, 0x5c, 0xb7, 0xc1, 0x0f, + 0x59, 0x51, 0x04, 0x89, 0x29, 0x05, 0x6c, 0xe5, 0x65, 0xfc, 0x83, 0x69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x23, 0x3d, 0x6f, 0x11, 0x74, 0xf1, 0x44, 0x81, + 0x22, 0xca, 0x97, 0x42, 0x96, 0x50, 0x47, 0xf6, 0x62, 0xde, 0x37, 0x4b, + 0x86, 0x48, 0x49, 0x68, 0x7c, 0x7a, 0x6c, 0x90, 0x43, 0x19, 0x72, 0xbb, + 0x98, 0xca, 0x69, 0xa8, 0x46, 0x3a, 0x73, 0xe0, 0x3e, 0x1c, 0x53, 0x2c, + 0xb6, 0x92, 0x88, 0x3b, 0x4c, 0x9e, 0x8d, 0xfc, 0xc1, 0x49, 0x65, 0x35, + 0x5e, 0xc7, 0x0b, 0xc0, 0x1c, 0x22, 0x90, 0xb8, 0x79, 0x64, 0x0a, 0x4d, + 0x6e, 0xdc, 0xb0, 0x91, 0xeb, 0x02, 0xb9, 0xb6, 0xa1, 0x07, 0x62, 0x2b, + 0x7f, 0x93, 0x57, 0xce, 0x98, 0xb1, 0x3e, 0xa1, 0xa9, 0x17, 0xda, 0xc4, + 0x7b, 0x67, 0x8a, 0x15, 0x92, 0x58, 0xf7, 0x16, 0x00, 0xb9, 0xfc, 0x9e, + 0xa0, 0xda, 0x1b, 0x1f, 0xda, 0x7d, 0xab, 0xd2, 0xac, 0xec, 0x5a, 0x87, + 0xd0, 0xb2, 0xc7, 0x5b, 0xa4, 0x45, 0xd8, 0x59, 0x65, 0x19, 0xbb, 0x80, + 0x9a, 0xaa, 0x88, 0xf7, 0x31, 0x99, 0x43, 0x01, 0x45, 0x6e, 0x0b, 0x66, + 0x05, 0xf5, 0x7b, 0xaf, 0x80, 0xb3, 0x3a, 0xf4, 0x23, 0xea, 0xd6, 0x60, + 0xf6, 0x73, 0xaa, 0x0e, 0x65, 0x68, 0x57, 0x41, 0x53, 0xfa, 0xb5, 0x62, + 0x28, 0xae, 0xac, 0x1a, 0x1c, 0xa0, 0xa2, 0x87, 0x5f, 0xb7, 0x5c, 0xc3, + 0xf3, 0xb2, 0xf4, 0x2a, 0x1a, 0x3c, 0xbf, 0xfa, 0x1b, 0x90, 0x21, 0x9a, + 0xc7, 0x77, 0xe3, 0x09, 0xd9, 0xcd, 0xcd, 0xcf}; +static const uint8_t test_vector_sk_1024[3168] = { + 0xb7, 0x57, 0x8f, 0x5b, 0xdb, 0xa5, 0x1e, 0x1c, 0x9c, 0xd3, 0x1c, 0xaf, + 0xe3, 0xe1, 0x78, 0x12, 0x85, 0x74, 0xb8, 0xc5, 0x17, 0x11, 0xc6, 0x9e, + 0x5c, 0x29, 0x19, 0x2b, 0xe4, 0x39, 0x22, 0xcb, 0x26, 0xf8, 0x89, 0x9e, + 0x3c, 0xaa, 0x83, 0xc7, 0x09, 0x69, 0xbd, 0x2c, 0x8c, 0x78, 0xf7, 0x11, + 0xfe, 0x2b, 0xb1, 0x8d, 0x08, 0xa2, 0xd7, 0x45, 0x0b, 0xb1, 0xa0, 0x43, + 0xfa, 0x76, 0x4e, 0xe2, 0x4b, 0x54, 0x34, 0xc3, 0xb3, 0xd0, 0x6c, 0xca, + 0xfa, 0x44, 0x92, 0x51, 0xcc, 0xbf, 0x3d, 0x30, 0x0a, 0x92, 0xd5, 0x2f, + 0xcd, 0x55, 0x26, 0xb1, 0x75, 0x4f, 0xec, 0x56, 0x35, 0x79, 0x91, 0xb3, + 0x05, 0x4a, 0x71, 0xee, 0x98, 0x8f, 0x96, 0x44, 0x90, 0x22, 0x44, 0x9d, + 0x80, 0x96, 0x93, 0xa3, 0xd2, 0x75, 0x00, 0x71, 0x93, 0xd3, 0xc9, 0x23, + 0xf9, 0x3a, 0x08, 0xd4, 0x74, 0xcc, 0x8d, 0x42, 0x0d, 0x2c, 0xe0, 0x04, + 0x36, 0x88, 0x54, 0x35, 0xbc, 0x02, 0x98, 0xc4, 0x45, 0x1f, 0xe8, 0x93, + 0x0a, 0xc1, 0xa9, 0x28, 0x61, 0x71, 0xdc, 0x57, 0xa2, 0x09, 0x82, 0x8a, + 0x64, 0x8a, 0x1b, 0x68, 0x42, 0x15, 0xfe, 0x67, 0xac,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 0x0d, 0x34, 0x71, 0xa9, 0x60, 0x63, 0xa6, + 0xdd, 0x06, 0x84, 0xbf, 0x5c, 0x7e, 0xe4, 0x63, 0x22, 0x8f, 0x6b, 0x29, + 0x23, 0x07, 0x54, 0xf8, 0x40, 0x5e, 0x70, 0x83, 0x4e, 0x2c, 0x5a, 0x47, + 0xae, 0x64, 0x4a, 0x27, 0xbb, 0x96, 0x6e, 0x57, 0x79, 0x58, 0xb0, 0x7b, + 0xfb, 0xca, 0xad, 0x37, 0x4a, 0x0e, 0xb0, 0x48, 0x00, 0x50, 0x35, 0xbf, + 0x36, 0xf7, 0x2c, 0xc6, 0x17, 0x0a, 0x61, 0x2a, 0xc9, 0xde, 0xa0, 0x8a, + 0x43, 0x08, 0xa5, 0xbf, 0x95, 0x60, 0x1d, 0x99, 0x43, 0x69, 0x9c, 0x63, + 0x31, 0x04, 0x48, 0x69, 0xd2, 0x9a, 0x61, 0xd1, 0x5b, 0xa6, 0xc5, 0x12, + 0x2b, 0xf4, 0x0f, 0x66, 0x54, 0x3f, 0x5d, 0x65, 0x2a, 0x46, 0xe9, 0x2e, + 0x08, 0x64, 0x41, 0x30, 0xb4, 0x05, 0x25, 0x04, 0x92, 0x06, 0x83, 0x55, + 0xa7, 0x03, 0x32, 0x2f, 0x48, 0x48, 0xcd, 0x93, 0xc1, 0x3b, 0xa2, 0x8d, + 0xf5, 0xe1, 0xbb, 0xb0, 0x26, 0x7f, 0x22, 0x87, 0x7b, 0xab, 0x64, 0x76, + 0x19, 0xa3, 0x30, 0x9f, 0x23, 0x45, 0xae, 0x57, 0x36, 0x43, 0xe5, 0xa9, + 0xe0, 0x66, 0xc6, 0x8d, 0x4b, 0x29, 0xdc, 0xf6, 0x2c, 0x1b, 0xd6, 0x00, + 0x2e, 0x67, 0xa4, 0x30, 0x32, 0x99, 0x8e, 0x27, 0x5e, 0x53, 0x11, 0x7d, + 0x82, 0xf1, 0x59, 0xd5, 0x46, 0x63, 0x3d, 0xe6, 0xcc, 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9a, + 0x8a, 0x76, 0xcb, 0x87, 0xc0, 0xc5, 0xd3, 0x61, 0xa7, 0x70, 0xbb, 0xb1, + 0xa8, 0x52, 0x1e, 0xba, 0x78, 0x59, 0xdb, 0x82, 0xc2, 0xd6, 0xe5, 0xbd, + 0x86, 0xa7, 0x7e, 0x08, 0xf2, 0xb4, 0x5a, 0x38, 0x71, 0x45, 0x87, 0x2d, + 0x54, 0x85, 0x06, 0xf8, 0xfa, 0x84, 0xe2, 0xd0, 0x93, 0xc4, 0x43, 0x2a, + 0x18, 0x43, 0x89, 0x82, 0x12, 0x28, 0x86, 0xf5, 0x67, 0x2a, 0x53, 0x23, + 0xe5, 0x51, 0x83, 0x2f, 0xc2, 0x36, 0x89, 0xc8, 0x75, 0x96, 0xdb, 0x33, + 0xad, 0x2c, 0x29, 0x00, 0x68, 0x93, 0xf8, 0xe2, 0x11, 0x53, 0x43, 0x36, + 0xe0, 0x37, 0x52, 0x2e, 0x84, 0x1d, 0xde, 0xa0, 0xba, 0xd2, 0xe2, 0x8e, + 0x7d, 0x63, 0x8c, 0x94, 0xc9, 0x0b, 0x83, 0x39, 0xbd, 0xce, 0x87, 0x7d, + 0xce, 0x8b, 0x6e, 0x14, 0x60, 0xac, 0xd4, 0xf5, 0x1a, 0x29, 0xd6, 0x08, + 0x4a, 0xa8, 0x7d, 0xe4, 0xb3, 0x6a, 0xdd, 0x92, 0xce, 0x41, 0x63, 0x1a, + 0x64, 0xb7, 0x18, 0x5f, 0x9a, 0x8f, 0xc7, 0xa0, 0x2a, 0x5d, 0xa8, 0x91, + 0x11, 0x23, 0x5f, 0x95, 0x84, 0xbd, 0x98, 0x62, 0x5e, 0xa2, 0x03, 0x25, + 0xee, 0x90, 0x22, 0x05, 0xfa, 0x98, 0x6c, 0x18, 0x9b, 0xda, 0xc2, 0x58, + 0x76, 0x23, 0x11, 0xb6, 0xc3, 0x98, 0x37, 0xe7, 0xbc, 0x86, 0x95, 0x4a, + 0xb5, 0x88, 0x63, 0xcb, 0xdb, 0xb5, 0x43, 0x05, 0x8d, 0x04, 0xa5, 0x40, + 0xaf, 0x64, 0xb7, 0x3a, 0x89, 0x10, 0x76, 0x57, 0x4c, 0xbc, 0xcb, 0x82, + 0xda, 0xa0, 0xc7, 0x48, 0x2b, 0x18, 0xab, 0xb5, 0x2e, 0x7f, 0x62, 0x3d, + 0x05, 0x8b, 0xb7, 0x6b, 0xe6, 0x77, 0x54, 0xf6, 0x13, 0x28, 0x87, 0xad, + 0x7f, 0x33, 0x97, 0x64, 0x15, 0x51, 0xe6, 0xb8, 0x0a, 0x9f, 0xcb, 0x83, + 0xa0, 0xf0, 0x36, 0xc4, 0x0b, 0x53, 0xa2, 0xf6, 0xb6, 0xc4, 0x58, 0x6b, + 0xe0, 0x75, 0xb8, 0x99, 0x91, 0x4e, 0x22, 0xfc, 0xc5, 0x79, 0x10, 0x3c, + 0x9c, 0x21, 0x1e, 0x89, 0xd4, 0x1b, 0x54, 0x6c, 0x0b, 0x91, 0x47, 0x05, + 0x0a, 0xb5, 0x37, 0xed, 0x94, 0x0a, 0xea, 0x14, 0x1c, 0xef, 0xeb, 0xb9, + 0x82, 0x80, 0x03, 0x8b, 0xe1, 0x3f, 0x7c, 0xdc, 0x8d, 0x1e, 0xd2, 0x09, + 0xd3, 0x34, 0xb6, 0xae, 0xea, 0xa0, 0xed, 0xd2, 0x89, 0x71, 0xa5, 0x91, + 0x15, 0xc8, 0x7f, 0xc6, 0x29, 0x89, 0x98, 0x6c, 0x93, 0x57, 0x91, 0x84, + 0x06, 0x4b, 0x6b, 0xfe, 0x38, 0x2e, 0x29, 0x34, 0x87, 0x25, 0x90, 0x83, + 0x33, 0x17, 0x0b, 0x7e, 0xe4, 0x2e, 0xb2, 0xf8, 0xc2, 0x1f, 0x13, 0x20, + 0x15, 0x5a, 0xa3, 0x95, 0x91, 0x06, 0x38, 0x2a, 0x08, 0xfb, 0x52, 0x73, + 0x27, 0xa5, 0x42, 0x02, 0xe9, 0x1c, 0xeb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 0x5a, 0xc3, 0x0c, 0x54, 0x9e, 0x03, 0xac, 0xe4, 0x5a, 0x51, + 0x5d, 0xb7, 0x45, 0xff, 0x47, 0xa5, 0x9b, 0x23, 0x9c, 0x87, 0xb4, 0x62, + 0x9d, 0xb6, 0x6d, 0xdc, 0x86, 0x22, 0x1a, 0x50, 0x2c, 0x65, 0x06, 0x19, + 0xa0, 0x4c, 0xa1, 0xe3, 0x21, 0x8f, 0x8b, 0xe6, 0x31, 0x84, 0xa4, 0xa7, + 0x21, 0xfa, 0x9c, 0x76, 0x74, 0x18, 0xc6, 0x85, 0x0c, 0x6f, 0x43, 0x0d, + 0x91, 0x43, 0x16, 0x0e, 0x7c, 0x72, 0x78, 0x42, 0x1e, 0x16, 0x1c, 0x37, + 0xde, 0xd7, 0x16, 0xf9, 0x82, 0x6d, 0x13, 0xb0, 0xb8, 0xc1, 0xd2, 0x7f, + 0x08, 0xba, 0x19, 0xd3, 0xf1, 0x6d, 0x67, 0x17, 0x1f, 0x9e, 0xea, 0x41, + 0x6a, 0xb3, 0x79, 0x09, 0x3b, 0x8c, 0xb6, 0xf1, 0x82, 0xe4, 0xa3, 0x08, + 0xe0, 0xaa, 0x76, 0x12, 0x30, 0xbd, 0x46, 0x40, 0x10, 0x2d, 0xfb, 0x2c, + 0x89, 0x36, 0x14, 0x8c, 0x69, 0x83, 0x00, 0x41, 0x46, 0x6f, 0x07, 0x87, + 0xe6, 0x43, 0x36, 0x02, 0xe4, 0x5c, 0xb3, 0xa0, 0xb8, 0x1f, 0x66, 0x10, + 0xbd, 0x09, 0xca, 0x5b, 0x86, 0x09, 0x3f, 0x13, 0x43, 0xa3, 0x24, 0x93, + 0xe9, 0x92, 0xcb, 0x00, 0x59, 0x81, 0xc1, 0x06, 0x21, 0xe6, 0x86, 0xbd, + 0xa5, 0xa5, 0x84, 0xe0, 0xa0, 0x43, 0x60, 0xc8, 0x61, 0xf9, 0x97, 0x50, + 0x33, 0xd4, 0x3b, 0x0a, 0x62, 0x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c0, 0x36, + 0xd9, 0x57, 0x2c, 0xd2, 0xa6, 0x2f, 0x51, 0xfb, 0x3c, 0x30, 0x44, 0x9e, + 0x0a, 0x75, 0x54, 0x90, 0xcc, 0xa9, 0x79, 0xcc, 0x6f, 0x5d, 0x7b, 0x8c, + 0x8e, 0x91, 0x83, 0x65, 0x90, 0x6b, 0x97, 0x95, 0x39, 0x46, 0xec, 0xb3, + 0xc4, 0x38, 0x6f, 0xb0, 0xc7, 0x87, 0xdf, 0x51, 0x0c, 0xf6, 0xa6, 0x9e, + 0xfd, 0x33, 0x63, 0x34, 0x58, 0xc5, 0x8e, 0x48, 0x12, 0xd2, 0x40, 0x25, + 0xc4, 0x66, 0x43, 0x18, 0x0b, 0x71, 0x9c, 0x7b, 0x20, 0x6b, 0xd6, 0x0b, + 0x72, 0x34, 0x0e, 0x27, 0xc7, 0x47, 0x3b, 0x47, 0xa4, 0xf5, 0xa6, 0x23, + 0x67, 0x71, 0x75, 0xd0, 0x87, 0x2d, 0x0c, 0x03, 0x4f, 0x3d, 0x34, 0x37, + 0x0c, 0xb1, 0x5b, 0xd8, 0x7b, 0x12, 0x6f, 0xe3, 0x22, 0xee, 0x76, 0x55, + 0x9c, 0xf4, 0x0a, 0x72, 0x87, 0x7d, 0xf2, 0xc5, 0xca, 0x52, 0x19, 0x44, + 0xf7, 0x5a, 0x73, 0xc2, 0x94, 0x09, 0xf7, 0x34, 0x3f, 0x53, 0x52, 0xb4, + 0x52, 0xc3, 0xaf, 0x69, 0x06, 0x0c, 0x53, 0x48, 0xbf, 0x9a, 0xdb, 0x1e, + 0x9d, 0x46, 0x7a, 0x1d, 0xb2, 0x33, 0xbb, 0x20, 0x43, 0x54, 0xea, 0x45, + 0x87, 0xd6, 0x49, 0xfb, 0x7c, 0xb5, 0x6b, 0x63, 0x78, 0x12, 0x9a, 0xcd, + 0xa6, 0x91, 0x4b, 0x5e, 0x20, 0xaa, 0x8a, 0x56, 0x42, 0x84, 0xab, 0x2f, + 0x7f, 0x0a, 0xb2, 0x82, 0x23, 0x3d, 0x6f, 0x11, 0x74, 0xf1, 0x44, 0x81, + 0x22, 0xca, 0x97, 0x42, 0x96, 0x50, 0x47, 0xf6, 0x62, 0xde, 0x37, 0x4b, + 0x86, 0x48, 0x49, 0x68, 0x7c, 0x7a, 0x6c, 0x90, 0x43, 0x19, 0x72, 0xbb, + 0x98, 0xca, 0x69, 0xa8, 0x46, 0x3a, 0x73, 0xe0, 0x3e, 0x1c, 0x53, 0x2c, + 0xb6, 0x92, 0x88, 0x3b, 0x4c, 0x9e, 0x8d, 0xfc, 0xc1, 0x49, 0x65, 0x35, + 0x5e, 0xc7, 0x0b, 0xc0, 0x1c, 0x22, 0x90, 0xb8, 0x79, 0x64, 0x0a, 0x4d, + 0x6e, 0xdc, 0xb0, 0x91, 0xeb, 0x02, 0xb9, 0xb6, 0xa1, 0x07, 0x62, 0x2b, + 0x7f, 0x93, 0x57, 0xce, 0x98, 0xb1, 0x3e, 0xa1, 0xa9, 0x17, 0xda, 0xc4, + 0x7b, 0x67, 0x8a, 0x15, 0x92, 0x58, 0xf7, 0x16, 0x00, 0xb9, 0xfc, 0x9e, + 0xa0, 0xda, 0x1b, 0x1f, 0xda, 0x7d, 0xab, 0xd2, 0xac, 0xec, 0x5a, 0x87, + 0xd0, 0xb2, 0xc7, 0x5b, 0xa4, 0x45, 0xd8, 0x59, 0x65, 0x19, 0xbb, 0x80, + 0x9a, 0xaa, 0x88, 0xf7, 0x31, 0x99, 0x43, 0x01, 0x45, 0x6e, 0x0b, 0x66, + 0x05, 0xf5, 0x7b, 0xaf, 0x80, 0xb3, 0x3a, 0xf4, 0x23, 0xea, 0xd6, 0x60, + 0xf6, 0x73, 0xaa, 0x0e, 0x65, 0x68, 0x57, 0x41, 0x53, 0xfa, 0xb5, 0x62, + 0x28, 0xae, 0xac, 0x1a, 0x1c, 0xa0, 0xa2, 0x87, 0x5f, 0xb7, 0x5c, 0xc3, + 0xf3, 0xb2, 0xf4, 0x2a, 0x1a, 0x3c, 0xbf, 0xfa, 0x1b, 0x90, 0x21, 0x9a, + 0xc7, 0x77, 0xe3, 0x09, 0xd9, 0xcd, 0xcd, 0xcf, 0x02, 0xb9, 0x5a, 0x74, + 0x31, 0x61, 0x66, 0x63, 0xb4, 0x6c, 0x37, 0x0f, 0x7c, 0x33, 0x29, 0xce, + 0x66, 0x41, 0xcb, 0x6f, 0x6d, 0xa7, 0xa8, 0xea, 0x05, 0x17, 0x36, 0xcf, + 0x14, 0xe5, 0x71, 0x95, 0x3e, 0x2a, 0x2e, 0xa6, 0xc9, 0xc4, 0x76, 0xfc, + 0x49, 0x37, 0xb0, 0x13, 0xc9, 0x93, 0xa7, 0x93, 0xd6, 0xc0, 0xab, 0x99, + 0x60, 0x69, 0x5b, 0xa8, 0x38, 0xf6, 0x49, 0xda, 0x53, 0x9c, 0xa3, 0xd0}; +static const uint8_t test_vector_ct_1024[1568] = { + 0xcb, 0x90, 0xc5, 0xe7, 0x41, 0x4b, 0x15, 0xf8, 0x32, 0x5b, 0x26, 0x88, + 0xca, 0xfe, 0x21, 0x32, 0x65, 0x59, 0x90, 0x9a, 0x96, 0xa7, 0xa4, 0x85, + 0xe5, 0xa6, 0x1e, 0xea, 0x72, 0x23, 0xea, 0xd2, 0xb2, 0x14, 0x22, 0xfb, + 0x53, 0x5a, 0xd0, 0x45, 0x2e, 0xc1, 0xaf, 0xd1, 0x90, 0xd5, 0x08, 0x36, + 0x17, 0x05, 0xbc, 0x24, 0xaf, 0xfe, 0x77, 0xb0, 0xe4, 0x75, 0x81, 0xc4, + 0xcf, 0xcd, 0x71, 0x9b, 0x48, 0x74, 0x5f, 0x62, 0x3f, 0x2e, 0x9c, 0xb3, + 0x69, 0x14, 0x7e, 0x6a, 0x04, 0xba, 0x60, 0xa6, 0x6e, 0x73, 0xf9, 0x9b, + 0x21, 0x2b, 0x0f, 0xab, 0x08, 0x09, 0xe3, 0x5c, 0x11, 0x47, 0xe2, 0x5d, + 0x28, 0x3a, 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 0xac, 0xe3, 0x2f, + 0xa2, 0x99, 0x20, 0x86, 0x92, 0x24, 0x3b, 0x77, 0x09, 0x57, 0xac, 0x00, + 0xa9, 0xe4, 0x87, 0x85, 0x39, 0x4f, 0x57, 0xb5}; +static const uint8_t test_vector_ss_1024[32] = { + 0xfa, 0x24, 0x82, 0x8f, 0x2b, 0x3d, 0xec, 0xb0, 0x5d, 0x0e, 0x8d, + 0x1e, 0x72, 0x8c, 0x52, 0x93, 0x8b, 0xfb, 0x8c, 0xe7, 0x39, 0xa6, + 0x1c, 0x7d, 0xb9, 0x36, 0xee, 0xe7, 0x7d, 0xd1, 0x98, 0xa6}; + +#endif /* !EXPECTED_TEST_VECTORS_MULTILEVEL_H */ diff --git a/test/wycheproof/wycheproof_client.py b/test/wycheproof/wycheproof_client.py index dcbfe2c313..d48e46bbdd 100644 --- a/test/wycheproof/wycheproof_client.py +++ b/test/wycheproof/wycheproof_client.py @@ -111,6 +111,38 @@ def get_binary(level): return f"{basedir}/wycheproof_mlkem{level}" +def detect_supported_modes(): + """Run wycheproof_mlkem512 --info to detect which modes are supported.""" + wycheproof_bin = "./test/build/mlkem512/bin/wycheproof_mlkem512" + wycheproof_call = exec_prefix + [wycheproof_bin, "--info"] + try: + result = subprocess.run(wycheproof_call, encoding="utf-8", capture_output=True) + if result.returncode != 0: + err( + f"Warning: {wycheproof_call} failed (rc={result.returncode}), assuming all modes supported" + ) + return {"keygen_seed", "encaps", "decaps"} + modes = set() + for line in result.stdout.splitlines(): + line = line.strip() + if line in ("keygen_seed", "encaps", "decaps"): + modes.add(line) + return modes + except FileNotFoundError: + err(f"Warning: {wycheproof_bin} not found, assuming all modes supported") + return {"keygen_seed", "encaps", "decaps"} + + +# File-type → set of modes the binary must support to run those tests. +FILE_REQUIRED_MODES = { + "keygen_seed_test": {"keygen_seed"}, + "encaps_test": {"encaps"}, + "semi_expanded_decaps_test": {"decaps"}, + # Combined test drives keygen (to derive dk from seed) then decaps. + "_test": {"keygen_seed", "decaps"}, +} + + def run_binary(args_list): result = subprocess.run( exec_prefix + args_list, encoding="utf-8", capture_output=True @@ -270,11 +302,28 @@ def run_combined_test(data_file): info(f" {count} combined tests passed") -def run_all(data_dir): +def file_required_modes(filename): + """Which API modes must be available to run tests from this file.""" + if "keygen_seed_test" in filename: + return FILE_REQUIRED_MODES["keygen_seed_test"] + if "encaps_test" in filename: + return FILE_REQUIRED_MODES["encaps_test"] + if "semi_expanded_decaps_test" in filename: + return FILE_REQUIRED_MODES["semi_expanded_decaps_test"] + if filename.endswith("_test.json"): + return FILE_REQUIRED_MODES["_test"] + return set() + + +def run_all(data_dir, supported_modes): """Run all Wycheproof test vector files.""" data_dir = Path(data_dir) for filename in WYCHEPROOF_FILES: filepath = data_dir / filename + required = file_required_modes(filename) + if not required.issubset(supported_modes): + info(f"Skipping {filename} (modes not supported in this build)") + continue if "keygen_seed_test" in filename: run_keygen_seed_test(filepath) elif "encaps_test" in filename: @@ -300,9 +349,17 @@ def run_all(data_dir): ) args = parser.parse_args() +supported_modes = detect_supported_modes() +info(f"Auto-detected supported modes: {sorted(supported_modes)}") + if args.file: # Run a single file filename = os.path.basename(args.file) + required = file_required_modes(filename) + if not required.issubset(supported_modes): + info(f"Skipping {filename} (modes not supported in this build)") + info("ALL GOOD!") + sys.exit(0) if "keygen_seed_test" in filename: run_keygen_seed_test(args.file) elif "encaps_test" in filename: @@ -321,4 +378,4 @@ def run_all(data_dir): if not download_wycheproof_files(data_dir): err("Failed to download Wycheproof test files") sys.exit(1) - run_all(data_dir) + run_all(data_dir, supported_modes) diff --git a/test/wycheproof/wycheproof_mlkem.c b/test/wycheproof/wycheproof_mlkem.c index 209710b2da..2e6afe7d78 100644 --- a/test/wycheproof/wycheproof_mlkem.c +++ b/test/wycheproof/wycheproof_mlkem.c @@ -7,6 +7,7 @@ * Wycheproof test driver for ML-KEM. * * Usage: + * wycheproof_mlkem{lvl} --info * wycheproof_mlkem{lvl} keygen_seed seed=HEX * wycheproof_mlkem{lvl} encaps ek=HEX m=HEX * wycheproof_mlkem{lvl} decaps dk=HEX c=HEX @@ -20,7 +21,22 @@ #include "../../mlkem/mlkem_native.h" +/* Print supported API modes and exit (used by wycheproof_client.py) */ +static void print_info(void) +{ +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) + printf("keygen_seed\n"); +#endif +#if !defined(MLK_CONFIG_NO_ENCAPS_API) + printf("encaps\n"); +#endif +#if !defined(MLK_CONFIG_NO_DECAPS_API) + printf("decaps\n"); +#endif +} +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) || \ + !defined(MLK_CONFIG_NO_ENCAPS_API) || !defined(MLK_CONFIG_NO_DECAPS_API) #define CHECK(x) \ do \ { \ @@ -99,6 +115,8 @@ static void print_hex(const char *name, const unsigned char *raw, size_t len) } printf("\n"); } +#endif /* !MLK_CONFIG_NO_KEYPAIR_API || !MLK_CONFIG_NO_ENCAPS_API || \ + !MLK_CONFIG_NO_DECAPS_API */ /* Prototype for a re-#define'd main, to satisfy -Wmissing-prototypes. */ #if defined(main) @@ -111,6 +129,13 @@ int main(int argc, char *argv[]) goto usage; } + if (strcmp(argv[1], "--info") == 0) + { + print_info(); + return 0; + } + +#if !defined(MLK_CONFIG_NO_KEYPAIR_API) if (strcmp(argv[1], "keygen_seed") == 0) { /* keygen_seed seed=HEX (64 bytes = d || z) */ @@ -133,7 +158,10 @@ int main(int argc, char *argv[]) print_hex("ek", ek, sizeof(ek)); print_hex("dk", dk, sizeof(dk)); } - else if (strcmp(argv[1], "encaps") == 0) + else +#endif /* !MLK_CONFIG_NO_KEYPAIR_API */ +#if !defined(MLK_CONFIG_NO_ENCAPS_API) + if (strcmp(argv[1], "encaps") == 0) { /* encaps ek=HEX m=HEX */ unsigned char ek[CRYPTO_PUBLICKEYBYTES]; @@ -157,7 +185,10 @@ int main(int argc, char *argv[]) print_hex("c", ct, sizeof(ct)); print_hex("K", ss, sizeof(ss)); } - else if (strcmp(argv[1], "decaps") == 0) + else +#endif /* !MLK_CONFIG_NO_ENCAPS_API */ +#if !defined(MLK_CONFIG_NO_DECAPS_API) + if (strcmp(argv[1], "decaps") == 0) { /* decaps dk=HEX c=HEX */ unsigned char dk[CRYPTO_SECRETKEYBYTES]; @@ -185,6 +216,7 @@ int main(int argc, char *argv[]) print_hex("K", ss, sizeof(ss)); } else +#endif /* !MLK_CONFIG_NO_DECAPS_API */ { goto usage; } @@ -194,6 +226,7 @@ int main(int argc, char *argv[]) usage: fprintf(stderr, "Usage:\n" + " wycheproof_mlkem{lvl} --info\n" " wycheproof_mlkem{lvl} keygen_seed seed=HEX\n" " wycheproof_mlkem{lvl} encaps ek=HEX m=HEX\n" " wycheproof_mlkem{lvl} decaps dk=HEX c=HEX\n");