Skip to content

Commit ab8f4bf

Browse files
Add ML-KEM Braid API
Split K-PKE.Encrypt and ML-KEM.Encaps into two phases (u and v) to support protocols like MLKEMBraid that transmit large KEM components in parallel over bandwidth-constrained channels. CPA level (indcpa): - mlk_indcpa_enc_u: computes ct_u from ek_seed, outputs intermediate state (sp, epp, sp_cache) - mlk_indcpa_enc_v: computes ct_v from ek_vector using intermediate state from enc_u CCA KEM level (kem): - mlk_kem_enc_derand_u: FO transform + enc_u, outputs shared secret and intermediate state; only needs ek_seed and H(pk) - mlk_kem_enc_v: modulus check on ek_vector + enc_v; only needs ek_vector epp is serialized as 4-bit nibbles (ETA2 - x) to provide a natural coefficient bound on deserialization; sp is serialized as 16-bit LE. The shared sp mulcache is computed once and threaded through enc_u/enc_v. Includes CBMC contracts and proofs for the new functions, the MLK_CONFIG_ENABLE_MLKEM_BRAID configuration option exposing the API, recomputed peak stack consumption values, and OpenTitan work buffer size updates. The test verifies that the incremental API produces identical ciphertexts and shared secrets as the standard API across all three parameter sets. Co-authored-by: Hanno Becker <beckphan@amazon.co.uk> Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
1 parent d9613cf commit ab8f4bf

53 files changed

Lines changed: 1966 additions & 316 deletions

File tree

Some content is hidden

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

.github/actions/config-variations/action.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ inputs:
1111
description: 'List of tests to run (space-separated IDs) or "all" for all tests. Available IDs: pct-enabled,
1212
pct-enabled-broken, custom-alloc-heap, custom-zeroize, native-cap-ON, native-cap-OFF, native-cap-ID_AA64PFR1_EL1,
1313
native-cap-CPUID_AVX2, no-asm, serial-fips202, custom-randombytes, custom-memcpy, custom-memset, custom-stdlib,
14-
nblocks-1, nblocks-2, nblocks-4'
14+
mlkem-braid, nblocks-1, nblocks-2, nblocks-4'
1515
required: false
1616
default: 'all'
1717
opt:
@@ -231,6 +231,21 @@ runs:
231231
examples: false # Some examples use a custom config themselves
232232
alloc: false # Requires custom config
233233
rng_fail: true
234+
- name: "ML-KEM Braid (incremental encapsulation API)"
235+
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'mlkem-braid') }}
236+
uses: ./.github/actions/multi-functest
237+
with:
238+
gh_token: ${{ inputs.gh_token }}
239+
compile_mode: native
240+
cflags: "-std=c11 -D_GNU_SOURCE -Itest -DMLK_CONFIG_FILE=\\\\\\\"configs/test_mlkem_braid_config.h\\\\\\\" -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
241+
ldflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all"
242+
func: true
243+
kat: true
244+
acvp: true
245+
opt: ${{ inputs.opt }}
246+
examples: false
247+
alloc: false
248+
rng_fail: true
234249
- name: "MLKEM_GEN_MATRIX_NBLOCKS=1"
235250
if: ${{ inputs.tests == 'all' || contains(inputs.tests, 'nblocks-1') }}
236251
uses: ./.github/actions/multi-functest

.github/workflows/integration-pavona.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ jobs:
7979
echo "=== Patched extensions.bzl ==="
8080
cat third_party/mlkem_native/extensions.bzl
8181
82+
- name: Update work buffer sizes
83+
run: |
84+
cd "$PAVONA_DIR"
85+
git apply "$GITHUB_WORKSPACE/integration/pavona/update-alloc-sizes.patch"
86+
8287
- name: Patch functest to only test deterministic API
8388
run: |
8489
cd "$PAVONA_DIR"

BIBLIOGRAPHY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ source code and documentation.
9191
- [test/configs/no_asm_config.h](test/configs/no_asm_config.h)
9292
- [test/configs/serial_fips202_config.h](test/configs/serial_fips202_config.h)
9393
- [test/configs/test_alloc_config.h](test/configs/test_alloc_config.h)
94+
- [test/configs/test_mlkem_braid_config.h](test/configs/test_mlkem_braid_config.h)
9495

9596
### `FIPS202`
9697

@@ -154,6 +155,7 @@ source code and documentation.
154155
- [test/configs/no_asm_config.h](test/configs/no_asm_config.h)
155156
- [test/configs/serial_fips202_config.h](test/configs/serial_fips202_config.h)
156157
- [test/configs/test_alloc_config.h](test/configs/test_alloc_config.h)
158+
- [test/configs/test_mlkem_braid_config.h](test/configs/test_mlkem_braid_config.h)
157159

158160
### `HOL-Light`
159161

examples/basic_deterministic/mlkem_native/mlkem_native_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@
152152
*/
153153
/* #define MLK_CONFIG_CONSTANTS_ONLY */
154154

155+
/******************************************************************************
156+
* Name: MLK_CONFIG_ENABLE_MLKEM_BRAID
157+
*
158+
* Description: If this option is set, mlkem-native exposes the incremental
159+
* encapsulation API (mlk_kem_enc_derand_u, mlk_kem_enc_v)
160+
* needed for the ML-KEM Braid protocol.
161+
*
162+
*****************************************************************************/
163+
/* #define MLK_CONFIG_ENABLE_MLKEM_BRAID */
164+
155165
/******************************************************************************
156166
*
157167
* Build-only configuration options

examples/bring_your_own_fips202/mlkem_native/mlkem_native_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@
152152
*/
153153
/* #define MLK_CONFIG_CONSTANTS_ONLY */
154154

155+
/******************************************************************************
156+
* Name: MLK_CONFIG_ENABLE_MLKEM_BRAID
157+
*
158+
* Description: If this option is set, mlkem-native exposes the incremental
159+
* encapsulation API (mlk_kem_enc_derand_u, mlk_kem_enc_v)
160+
* needed for the ML-KEM Braid protocol.
161+
*
162+
*****************************************************************************/
163+
/* #define MLK_CONFIG_ENABLE_MLKEM_BRAID */
164+
155165
/******************************************************************************
156166
*
157167
* Build-only configuration options

examples/bring_your_own_fips202_static/mlkem_native/mlkem_native_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@
153153
*/
154154
/* #define MLK_CONFIG_CONSTANTS_ONLY */
155155

156+
/******************************************************************************
157+
* Name: MLK_CONFIG_ENABLE_MLKEM_BRAID
158+
*
159+
* Description: If this option is set, mlkem-native exposes the incremental
160+
* encapsulation API (mlk_kem_enc_derand_u, mlk_kem_enc_v)
161+
* needed for the ML-KEM Braid protocol.
162+
*
163+
*****************************************************************************/
164+
/* #define MLK_CONFIG_ENABLE_MLKEM_BRAID */
165+
156166
/******************************************************************************
157167
*
158168
* Build-only configuration options

examples/custom_backend/mlkem_native/mlkem_native_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@
154154
*/
155155
/* #define MLK_CONFIG_CONSTANTS_ONLY */
156156

157+
/******************************************************************************
158+
* Name: MLK_CONFIG_ENABLE_MLKEM_BRAID
159+
*
160+
* Description: If this option is set, mlkem-native exposes the incremental
161+
* encapsulation API (mlk_kem_enc_derand_u, mlk_kem_enc_v)
162+
* needed for the ML-KEM Braid protocol.
163+
*
164+
*****************************************************************************/
165+
/* #define MLK_CONFIG_ENABLE_MLKEM_BRAID */
166+
157167
/******************************************************************************
158168
*
159169
* Build-only configuration options

examples/monolithic_build/mlkem_native/mlkem_native_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@
151151
*/
152152
/* #define MLK_CONFIG_CONSTANTS_ONLY */
153153

154+
/******************************************************************************
155+
* Name: MLK_CONFIG_ENABLE_MLKEM_BRAID
156+
*
157+
* Description: If this option is set, mlkem-native exposes the incremental
158+
* encapsulation API (mlk_kem_enc_derand_u, mlk_kem_enc_v)
159+
* needed for the ML-KEM Braid protocol.
160+
*
161+
*****************************************************************************/
162+
/* #define MLK_CONFIG_ENABLE_MLKEM_BRAID */
163+
154164
/******************************************************************************
155165
*
156166
* Build-only configuration options

examples/monolithic_build_multilevel/mlkem_native/mlkem_native_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@
153153
*/
154154
/* #define MLK_CONFIG_CONSTANTS_ONLY */
155155

156+
/******************************************************************************
157+
* Name: MLK_CONFIG_ENABLE_MLKEM_BRAID
158+
*
159+
* Description: If this option is set, mlkem-native exposes the incremental
160+
* encapsulation API (mlk_kem_enc_derand_u, mlk_kem_enc_v)
161+
* needed for the ML-KEM Braid protocol.
162+
*
163+
*****************************************************************************/
164+
/* #define MLK_CONFIG_ENABLE_MLKEM_BRAID */
165+
156166
/******************************************************************************
157167
*
158168
* Build-only configuration options

examples/monolithic_build_multilevel_native/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ CFLAGS := \
2323
-Wno-long-long \
2424
-Wno-unknown-pragmas \
2525
-Wno-unused-command-line-argument \
26+
-Wno-unused-function \
2627
-O3 \
2728
-fomit-frame-pointer \
2829
-std=c99 \

0 commit comments

Comments
 (0)