Skip to content

Refactor mlk_polymat_permute_bitrev_to_custom - #1336

Open
mkannwischer wants to merge 1 commit into
mainfrom
refactor-polymat-permute
Open

Refactor mlk_polymat_permute_bitrev_to_custom#1336
mkannwischer wants to merge 1 commit into
mainfrom
refactor-polymat-permute

Conversation

@mkannwischer

@mkannwischer mkannwischer commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

This commit refactors mlk_polymat_permute_bitrev_to_custom to not require the helper function mlk_polyvec_permute_bitrev_to_custom. The function was only needed due CBMC limitations.

@mkannwischer
mkannwischer force-pushed the refactor-polymat-permute branch from 18ed177 to 28046a2 Compare December 3, 2025 09:18
@mkannwischer

mkannwischer commented Dec 3, 2025

Copy link
Copy Markdown
Contributor Author

This proves fine in a couple of seconds for MLKEM_K=3, but spins forever for MLKEM_K=2 and MLKEM_K=4:

$ tests cbmc -p polymat_permute_bitrev_to_custom_native --k 3

For your convenience, the output of this run will be symbolically linked to  /Users/matthiaskannwischer/git/native/mlkem-native/proofs/cbmc/output/latest/html/index.html 

Configuring CBMC proofs: 1 / 1
[16/16] mlk_polymat_permute_bitrev_to_custom_native: generating report                                                                                                                                                                                                                                                                                                  
Report was rendered at file:///Users/matthiaskannwischer/git/native/mlkem-native/proofs/cbmc/output/latest/html/index.html
## Summary of CBMC proof results

| Status  | Count |
|---------|-------|
| Success | 1     |

| Proof                                       | Status  | Duration (in s) |
|---------------------------------------------|---------|-----------------|
| mlk_polymat_permute_bitrev_to_custom_native | Success | 6               |


WARNING:root:$GITHUB_STEP_SUMMARY not set, not writing summary file
All good!
Matthiass-MacBook-Pro:mlkem-native matthiaskannwischer$ tests cbmc -p polymat_permute_bitrev_to_custom_native --k 2

For your convenience, the output of this run will be symbolically linked to  /Users/matthiaskannwischer/git/native/mlkem-native/proofs/cbmc/output/latest/html/index.html 

Configuring CBMC proofs: 1 / 1
[14/16] mlk_polymat_permute_bitrev_to_custom_native: printing safety properties  

Makes no sense to me.
@rod-chapman, any ideas?

@rod-chapman

Copy link
Copy Markdown
Contributor

Since we introduced struct wrappers around mlk_polyvec and mlk_polymat, the latter is now a struct that contains a K-element array of structs, each of which contains a single K-element array of mlk_poly.

This new code is trying to treat that as a single-dimensional array of K*K mlk_poly's by the look of it. That's bound to cause serious complications for CBMC.

Try a nested loop, so the code structure matches the data structure.

@rod-chapman
rod-chapman force-pushed the refactor-polymat-permute branch from cc0d751 to 782e470 Compare December 18, 2025 11:04
@hanno-becker

Copy link
Copy Markdown
Contributor

@mkannwischer Can you comment on state/plans for this?

@mkannwischer

Copy link
Copy Markdown
Contributor Author

@mkannwischer Can you comment on state/plans for this?

See pq-code-package/mldsa-native#770 - we are waiting for diffblue/cbmc#8705 to be merged.

@willieyz, could you rebase this PR and also include the experimental branch of CBMC so we can confirm that the proofs pass with that version.

@willieyz

willieyz commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

@mkannwischer Can you comment on state/plans for this?

See pq-code-package/mldsa-native#770 - we are waiting for diffblue/cbmc#8705 to be merged.

@willieyz, could you rebase this PR and also include the experimental branch of CBMC so we can confirm that the proofs pass with that version.

Yes, I can do it.

@willieyz
willieyz force-pushed the refactor-polymat-permute branch 5 times, most recently from 1745ecc to d5b04b1 Compare January 7, 2026 01:56
@hanno-becker

Copy link
Copy Markdown
Contributor

This seems no longer relevant; closing. @mkannwischer reopen if you disagree and foresee time to work on this.

@mkannwischer

mkannwischer commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

This seems no longer relevant; closing. @mkannwischer reopen if you disagree and foresee time to work on this.

Why is this no longer relevant? I still want to do this refactoring as soon as the CBMC fix has been merged.

@mkannwischer mkannwischer reopened this Mar 19, 2026
@rod-chapman

Copy link
Copy Markdown
Contributor

Agree. We will return to this when we get a new release of CBMC. The helper function could be removed if and when CBMC can handle a nested loop efficiently.

@rod-chapman
rod-chapman force-pushed the refactor-polymat-permute branch 3 times, most recently from 4afccb7 to 9f86f86 Compare April 20, 2026 14:27
@rod-chapman rod-chapman self-assigned this Apr 20, 2026
@oqs-bot

oqs-bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

CBMC Results (ML-KEM-1024)

Full Results (190 proofs)
Proof Status Current Previous Change
**TOTAL** 1740s 1885s -7.7%
mlk_indcpa_enc 440s 402s +9%
mlk_poly_rej_uniform 144s 161s -11%
mlk_rej_uniform_c 121s 144s -16%
mlk_indcpa_keypair_derand 79s 176s -55%
mlk_polyvec_basemul_acc_montgomery_cached_c 67s 79s -15%
mlk_polymat_permute_bitrev_to_custom_native 62s - new
rej_uniform_native_x86_64 57s 67s -15%
rej_uniform_native_aarch64 48s 53s -9%
poly_ntt_native 39s 43s -9%
mlk_poly_reduce_native 34s 40s -15%
mlk_ntt_layer 32s 38s -16%
polyvec_basemul_acc_montgomery_cached_native 28s 31s -10%
mlk_keccak_squeezeblocks_x4 26s 26s +0%
keccakf1600x4_permute_native_x4 17s 15s +13%
mlk_polyvec_add 17s 18s -6%
mlk_fqmul 16s 20s -20%
mlk_poly_decompress_d11_native 15s 16s -6%
mlk_poly_decompress_d5_native 14s 18s -22%
mlk_indcpa_dec 13s 11s +18%
mlk_poly_frommsg 9s 10s -10%
mlk_polyvec_ntt 9s 12s -25%
mlk_keccak_squeezeblocks 8s 9s -11%
mlk_ntt_butterfly_block 7s 9s -22%
mlk_poly_frombytes_native 7s 10s -30%
mlk_poly_sub 7s 8s -12%
mlk_gen_matrix 6s 2s +200%
mlk_gen_matrix_serial 6s 4s +50%
mlk_invntt_layer 6s 6s +0%
mlk_keccak_squeeze_once 6s 10s -40%
mlk_poly_add 6s 5s +20%
mlk_poly_ntt 6s 8s -25%
mlk_poly_rej_uniform_x4 6s 7s -14%
mlk_keccak_absorb_once 5s 4s +25%
mlk_keccak_absorb_once_x4 5s 5s +0%
mlk_keccakf1600_permute_c 5s 6s -17%
mlk_poly_frombytes_c 5s 3s +67%
mlk_poly_getnoise_eta1_4x 5s 2s +150%
mlk_poly_tomont_c 5s 3s +67%
mlk_shake256x4 5s 4s +25%
poly_decompress_d5_native_x86_64 5s 5s +0%
poly_frombytes_native_x86_64 5s 5s +0%
kem_check_pk 4s 4s +0%
kem_dec 4s 5s -20%
kem_enc 4s 2s +100%
kem_enc_derand 4s 3s +33%
kem_keypair_derand 4s 1s +300%
mlk_check_pct 4s 1s +300%
mlk_ct_cmask_nonzero_u8 4s 1s +300%
mlk_ct_get_optblocker_i32 4s 3s +33%
mlk_keccakf1600_extract_bytes (big endian) 4s 2s +100%
mlk_keccakf1600x4_xor_bytes 4s 2s +100%
mlk_poly_decompress_d11_c 4s 2s +100%
mlk_poly_getnoise_eta1_4x_native 4s 3s +33%
mlk_poly_invntt_tomont_c 4s 2s +100%
mlk_poly_mulcache_compute 4s 2s +100%
mlk_poly_reduce_c 4s 1s +300%
mlk_scalar_decompress_d4 4s 3s +33%
nttunpack_native_x86_64 4s 2s +100%
poly_compress_d5_native_x86_64 4s 4s +0%
poly_decompress_d11_native_x86_64 4s 5s -20%
poly_getnoise_eta1122_4x_native 4s 3s +33%
intt_native_x86_64 3s 2s +50%
keccak_f1600_x1_native_aarch64_v84a 3s 2s +50%
keccak_f1600_x4_native_aarch64_v84a 3s 3s +0%
keccak_f1600_x4_native_aarch64_v8a_v84a_scalar_hybrid 3s 3s +0%
kem_check_sk 3s 3s +0%
kem_keypair 3s 2s +50%
mlk_ct_get_optblocker_u32 3s 3s +0%
mlk_keccakf1600_extract_bytes 3s 2s +50%
mlk_matvec_mul 3s 5s -40%
mlk_poly_cbd_eta2 3s 3s +0%
mlk_poly_compress_d10_native 3s 3s +0%
mlk_poly_compress_d11_c 3s 4s -25%
mlk_poly_compress_d11_native 3s 3s +0%
mlk_poly_compress_d5_native 3s 4s -25%
mlk_poly_decompress_d4 3s 3s +0%
mlk_poly_decompress_d4_native 3s 3s +0%
mlk_poly_frombytes 3s 2s +50%
mlk_poly_invntt_tomont 3s 3s +0%
mlk_poly_mulcache_compute_c 3s 3s +0%
mlk_poly_tomont_native 3s 4s -25%
mlk_polyvec_compress_du 3s 3s +0%
mlk_polyvec_reduce 3s 2s +50%
mlk_polyvec_tobytes 3s 1s +200%
mlk_polyvec_tomont 3s 2s +50%
mlk_sha3_512 3s 1s +200%
mlk_shake128_absorb_once 3s 2s +50%
mlk_shake128_squeezeblocks 3s 1s +200%
mlk_value_barrier_u32 3s 3s +0%
ntt_native_aarch64 3s 3s +0%
poly_compress_d10_native_x86_64 3s 2s +50%
poly_compress_d4_native_x86_64 3s 2s +50%
poly_mulcache_compute_native_aarch64 3s 3s +0%
poly_mulcache_compute_native_x86_64 3s 5s -40%
poly_reduce_native_x86_64 3s 3s +0%
polyvec_basemul_acc_montgomery_cached_k2_native_x86_64 3s 2s +50%
polyvec_basemul_acc_montgomery_cached_k3_native_x86_64 3s 2s +50%
intt_native_aarch64 2s 3s -33%
keccak_f1600_x4_native_aarch64_v8a_scalar_hybrid 2s 3s -33%
keccakf1600x4_extract_bytes_native 2s 2s +0%
keccakf1600x4_xor_bytes_native 2s 2s +0%
mlk_barrett_reduce 2s 2s +0%
mlk_ct_cmask_nonzero_u16 2s 2s +0%
mlk_ct_cmov_zero 2s 3s -33%
mlk_ct_get_optblocker_u8 2s 2s +0%
mlk_ct_sel_int16 2s 4s -50%
mlk_ct_sel_uint8 2s 2s +0%
mlk_enc_getnoise_eta1_eta2 2s 4s -50%
mlk_keccakf1600_xor_bytes 2s 1s +100%
mlk_keccakf1600_xor_bytes (big endian) 2s 2s +0%
mlk_keccakf1600x4_extract_bytes 2s 2s +0%
mlk_keccakf1600x4_permute 2s 2s +0%
mlk_poly_compress_d11 2s 3s -33%
mlk_poly_compress_d4_c 2s 4s -50%
mlk_poly_compress_d4_native 2s 2s +0%
mlk_poly_compress_d5 2s 5s -60%
mlk_poly_decompress_d10 2s 2s +0%
mlk_poly_decompress_d10_c 2s 2s +0%
mlk_poly_decompress_d11 2s 3s -33%
mlk_poly_decompress_d5 2s 3s -33%
mlk_poly_decompress_d5_c 2s 2s +0%
mlk_poly_decompress_dv 2s 2s +0%
mlk_poly_getnoise_eta1122_4x 2s 3s -33%
mlk_poly_getnoise_eta2 2s 1s +100%
mlk_poly_ntt_c 2s 1s +100%
mlk_poly_reduce 2s 2s +0%
mlk_poly_tobytes 2s 3s -33%
mlk_poly_tobytes_c 2s 4s -50%
mlk_poly_tobytes_native 2s 1s +100%
mlk_poly_tomont 2s 2s +0%
mlk_poly_tomsg 2s 3s -33%
mlk_polymat_permute_bitrev_to_custom 2s 5s -60%
mlk_polyvec_decompress_du 2s 2s +0%
mlk_polyvec_frombytes 2s 5s -60%
mlk_polyvec_invntt_tomont 2s 1s +100%
mlk_polyvec_mulcache_compute 2s 4s -50%
mlk_rej_uniform 2s 2s +0%
mlk_scalar_compress_d10 2s 2s +0%
mlk_scalar_compress_d5 2s 4s -50%
mlk_scalar_decompress_d10 2s 2s +0%
mlk_scalar_decompress_d11 2s 2s +0%
mlk_scalar_decompress_d5 2s 2s +0%
mlk_sha3_256 2s 2s +0%
mlk_shake128x4_squeezeblocks 2s 2s +0%
mlk_shake256 2s 1s +100%
poly_invntt_tomont_native 2s 3s -33%
poly_tobytes_native_aarch64 2s 3s -33%
poly_tobytes_native_x86_64 2s 3s -33%
poly_tomont_native_aarch64 2s 3s -33%
poly_tomont_native_x86_64 2s 2s +0%
polyvec_basemul_acc_montgomery_cached_k3_native_aarch64 2s 2s +0%
polyvec_basemul_acc_montgomery_cached_k4_native_x86_64 2s 2s +0%
sys_check_capability 2s 2s +0%
keccak_f1600_x1_native_aarch64 1s 1s +0%
keccak_f1600_x4_native_avx2 1s 2s -50%
keccakf1600_permute_native 1s 2s -50%
mlk_ct_cmask_neg_i16 1s 3s -67%
mlk_ct_memcmp 1s 3s -67%
mlk_keccakf1600_permute 1s 2s -50%
mlk_keccakf1600x4_extract_bytes_c 1s 3s -67%
mlk_keccakf1600x4_xor_bytes_c 1s 5s -80%
mlk_keypair_getnoise_eta1 1s 5s -80%
mlk_montgomery_reduce 1s 2s -50%
mlk_poly_cbd_eta1 1s 3s -67%
mlk_poly_compress_d10 1s 2s -50%
mlk_poly_compress_d10_c 1s 3s -67%
mlk_poly_compress_d4 1s 3s -67%
mlk_poly_compress_d5_c 1s 4s -75%
mlk_poly_compress_du 1s 2s -50%
mlk_poly_compress_dv 1s 1s +0%
mlk_poly_decompress_d10_native 1s 2s -50%
mlk_poly_decompress_d4_c 1s 4s -75%
mlk_poly_decompress_du 1s 1s +0%
mlk_poly_mulcache_compute_native 1s 3s -67%
mlk_polyvec_basemul_acc_montgomery_cached 1s 2s -50%
mlk_scalar_compress_d1 1s 3s -67%
mlk_scalar_compress_d11 1s 4s -75%
mlk_scalar_compress_d4 1s 1s +0%
mlk_scalar_signed_to_unsigned_q 1s 3s -67%
mlk_shake128x4_absorb_once 1s 2s -50%
mlk_value_barrier_i32 1s 3s -67%
mlk_value_barrier_u8 1s 1s +0%
ntt_native_x86_64 1s 2s -50%
poly_compress_d11_native_x86_64 1s 3s -67%
poly_decompress_d10_native_x86_64 1s 4s -75%
poly_decompress_d4_native_x86_64 1s 2s -50%
poly_reduce_native_aarch64 1s 2s -50%
polyvec_basemul_acc_montgomery_cached_k2_native_aarch64 1s 1s +0%
polyvec_basemul_acc_montgomery_cached_k4_native_aarch64 1s 2s -50%
rej_uniform_native 1s 1s +0%

@oqs-bot

oqs-bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

CBMC Results (ML-KEM-512)

Full Results (190 proofs)
Proof Status Current Previous Change
**TOTAL** 1710s 1614s +5.9%
mlk_indcpa_enc 288s 255s +13%
mlk_poly_rej_uniform 173s 150s +15%
mlk_rej_uniform_c 136s 135s +1%
mlk_polymat_permute_bitrev_to_custom_native 101s - new
mlk_indcpa_keypair_derand 85s 213s -60%
rej_uniform_native_x86_64 65s 57s +14%
mlk_polyvec_basemul_acc_montgomery_cached_c 61s 55s +11%
rej_uniform_native_aarch64 52s 43s +21%
poly_ntt_native 45s 45s +0%
mlk_poly_reduce_native 41s 35s +17%
mlk_ntt_layer 40s 32s +25%
mlk_keccak_squeezeblocks_x4 25s 26s -4%
keccakf1600x4_permute_native_x4 18s 16s +12%
mlk_fqmul 18s 17s +6%
mlk_poly_decompress_d10_native 18s 15s +20%
mlk_indcpa_dec 16s 14s +14%
mlk_poly_decompress_d4_native 14s 14s +0%
mlk_poly_frommsg 12s 10s +20%
mlk_polyvec_add 12s 11s +9%
mlk_keccak_squeezeblocks 10s 9s +11%
mlk_ntt_butterfly_block 9s 9s +0%
mlk_poly_frombytes_native 9s 8s +12%
polyvec_basemul_acc_montgomery_cached_native 9s 8s +12%
mlk_keccak_squeeze_once 8s 8s +0%
mlk_poly_ntt 8s 5s +60%
mlk_poly_sub 7s 6s +17%
poly_decompress_d10_native_x86_64 7s 9s -22%
kem_dec 6s 5s +20%
mlk_keccak_absorb_once_x4 6s 5s +20%
mlk_keccakf1600_permute_c 6s 5s +20%
mlk_poly_add 6s 4s +50%
keccak_f1600_x4_native_aarch64_v8a_scalar_hybrid 5s 3s +67%
mlk_enc_getnoise_eta1_eta2 5s 2s +150%
mlk_gen_matrix 5s 2s +150%
mlk_invntt_layer 5s 4s +25%
mlk_keccak_absorb_once 5s 3s +67%
mlk_poly_decompress_d4_c 5s 7s -29%
mlk_poly_rej_uniform_x4 5s 8s -38%
nttunpack_native_x86_64 5s 2s +150%
mlk_ct_sel_uint8 4s 2s +100%
mlk_keccakf1600_extract_bytes 4s 2s +100%
mlk_poly_cbd_eta1 4s 2s +100%
mlk_poly_decompress_dv 4s 2s +100%
mlk_poly_frombytes 4s 1s +300%
mlk_poly_getnoise_eta1_4x 4s 5s -20%
mlk_poly_getnoise_eta1_4x_native 4s 2s +100%
mlk_poly_invntt_tomont_c 4s 3s +33%
mlk_poly_mulcache_compute_native 4s 2s +100%
mlk_polyvec_reduce 4s 2s +100%
mlk_shake256x4 4s 5s -20%
poly_decompress_d4_native_x86_64 4s 4s +0%
poly_frombytes_native_x86_64 4s 5s -20%
poly_invntt_tomont_native 4s 2s +100%
poly_tomont_native_x86_64 4s 2s +100%
polyvec_basemul_acc_montgomery_cached_k2_native_x86_64 4s 3s +33%
rej_uniform_native 4s 1s +300%
sys_check_capability 4s 1s +300%
kem_check_pk 3s 4s -25%
kem_enc 3s 2s +50%
kem_keypair_derand 3s 3s +0%
mlk_check_pct 3s 5s -40%
mlk_ct_cmask_nonzero_u16 3s 2s +50%
mlk_ct_cmask_nonzero_u8 3s 1s +200%
mlk_ct_get_optblocker_i32 3s 2s +50%
mlk_ct_memcmp 3s 3s +0%
mlk_keccakf1600_permute 3s 1s +200%
mlk_keccakf1600_xor_bytes (big endian) 3s 2s +50%
mlk_keccakf1600x4_xor_bytes_c 3s 2s +50%
mlk_poly_cbd_eta2 3s 3s +0%
mlk_poly_compress_d10_native 3s 1s +200%
mlk_poly_compress_d11_native 3s 3s +0%
mlk_poly_compress_d4_native 3s 2s +50%
mlk_poly_decompress_d10 3s 2s +50%
mlk_poly_decompress_d10_c 3s 4s -25%
mlk_poly_decompress_d11_c 3s 2s +50%
mlk_poly_decompress_d11_native 3s 3s +0%
mlk_poly_decompress_d4 3s 3s +0%
mlk_poly_decompress_d5_c 3s 1s +200%
mlk_poly_decompress_d5_native 3s 2s +50%
mlk_poly_frombytes_c 3s 4s -25%
mlk_poly_getnoise_eta1122_4x 3s 3s +0%
mlk_poly_getnoise_eta2 3s 3s +0%
mlk_poly_mulcache_compute_c 3s 4s -25%
mlk_poly_tobytes_native 3s 2s +50%
mlk_poly_tomont 3s 1s +200%
mlk_poly_tomont_native 3s 2s +50%
mlk_poly_tomsg 3s 3s +0%
mlk_polymat_permute_bitrev_to_custom 3s 2s +50%
mlk_polyvec_decompress_du 3s 2s +50%
mlk_polyvec_invntt_tomont 3s 3s +0%
mlk_polyvec_mulcache_compute 3s 5s -40%
mlk_polyvec_ntt 3s 1s +200%
mlk_polyvec_tomont 3s 1s +200%
mlk_scalar_decompress_d4 3s 3s +0%
ntt_native_aarch64 3s 2s +50%
ntt_native_x86_64 3s 2s +50%
poly_compress_d10_native_x86_64 3s 3s +0%
poly_decompress_d11_native_x86_64 3s 1s +200%
poly_decompress_d5_native_x86_64 3s 2s +50%
poly_tobytes_native_x86_64 3s 1s +200%
polyvec_basemul_acc_montgomery_cached_k2_native_aarch64 3s 3s +0%
polyvec_basemul_acc_montgomery_cached_k3_native_aarch64 3s 3s +0%
polyvec_basemul_acc_montgomery_cached_k4_native_aarch64 3s 3s +0%
intt_native_aarch64 2s 2s +0%
intt_native_x86_64 2s 2s +0%
keccak_f1600_x1_native_aarch64 2s 2s +0%
keccak_f1600_x1_native_aarch64_v84a 2s 2s +0%
keccak_f1600_x4_native_aarch64_v84a 2s 3s -33%
keccak_f1600_x4_native_aarch64_v8a_v84a_scalar_hybrid 2s 3s -33%
kem_keypair 2s 4s -50%
mlk_barrett_reduce 2s 2s +0%
mlk_ct_cmov_zero 2s 3s -33%
mlk_ct_get_optblocker_u32 2s 3s -33%
mlk_ct_get_optblocker_u8 2s 2s +0%
mlk_ct_sel_int16 2s 1s +100%
mlk_gen_matrix_serial 2s 3s -33%
mlk_keccakf1600_extract_bytes (big endian) 2s 5s -60%
mlk_keccakf1600_xor_bytes 2s 1s +100%
mlk_keccakf1600x4_extract_bytes 2s 2s +0%
mlk_keccakf1600x4_permute 2s 4s -50%
mlk_keypair_getnoise_eta1 2s 1s +100%
mlk_matvec_mul 2s 3s -33%
mlk_montgomery_reduce 2s 2s +0%
mlk_poly_compress_d10 2s 4s -50%
mlk_poly_compress_d10_c 2s 2s +0%
mlk_poly_compress_d11 2s 3s -33%
mlk_poly_compress_d4 2s 3s -33%
mlk_poly_compress_d4_c 2s 3s -33%
mlk_poly_compress_d5_c 2s 3s -33%
mlk_poly_compress_du 2s 3s -33%
mlk_poly_decompress_d11 2s 2s +0%
mlk_poly_decompress_du 2s 2s +0%
mlk_poly_reduce_c 2s 3s -33%
mlk_poly_tobytes 2s 3s -33%
mlk_poly_tobytes_c 2s 3s -33%
mlk_polyvec_basemul_acc_montgomery_cached 2s 1s +100%
mlk_polyvec_compress_du 2s 2s +0%
mlk_polyvec_frombytes 2s 2s +0%
mlk_polyvec_tobytes 2s 3s -33%
mlk_rej_uniform 2s 5s -60%
mlk_scalar_compress_d1 2s 2s +0%
mlk_scalar_compress_d10 2s 2s +0%
mlk_scalar_compress_d4 2s 1s +100%
mlk_scalar_compress_d5 2s 2s +0%
mlk_scalar_decompress_d10 2s 2s +0%
mlk_scalar_decompress_d11 2s 2s +0%
mlk_scalar_decompress_d5 2s 3s -33%
mlk_scalar_signed_to_unsigned_q 2s 1s +100%
mlk_sha3_256 2s 2s +0%
mlk_sha3_512 2s 2s +0%
mlk_shake128_absorb_once 2s 3s -33%
mlk_shake128_squeezeblocks 2s 3s -33%
mlk_shake128x4_squeezeblocks 2s 1s +100%
mlk_value_barrier_i32 2s 2s +0%
mlk_value_barrier_u8 2s 4s -50%
poly_compress_d11_native_x86_64 2s 2s +0%
poly_compress_d4_native_x86_64 2s 1s +100%
poly_compress_d5_native_x86_64 2s 2s +0%
poly_getnoise_eta1122_4x_native 2s 1s +100%
poly_mulcache_compute_native_aarch64 2s 3s -33%
poly_reduce_native_x86_64 2s 2s +0%
poly_tobytes_native_aarch64 2s 2s +0%
poly_tomont_native_aarch64 2s 2s +0%
polyvec_basemul_acc_montgomery_cached_k3_native_x86_64 2s 2s +0%
polyvec_basemul_acc_montgomery_cached_k4_native_x86_64 2s 2s +0%
keccak_f1600_x4_native_avx2 1s 2s -50%
keccakf1600_permute_native 1s 1s +0%
keccakf1600x4_extract_bytes_native 1s 1s +0%
keccakf1600x4_xor_bytes_native 1s 1s +0%
kem_check_sk 1s 2s -50%
kem_enc_derand 1s 3s -67%
mlk_ct_cmask_neg_i16 1s 3s -67%
mlk_keccakf1600x4_extract_bytes_c 1s 3s -67%
mlk_keccakf1600x4_xor_bytes 1s 2s -50%
mlk_poly_compress_d11_c 1s 2s -50%
mlk_poly_compress_d5 1s 2s -50%
mlk_poly_compress_d5_native 1s 3s -67%
mlk_poly_compress_dv 1s 3s -67%
mlk_poly_decompress_d5 1s 1s +0%
mlk_poly_invntt_tomont 1s 2s -50%
mlk_poly_mulcache_compute 1s 2s -50%
mlk_poly_ntt_c 1s 2s -50%
mlk_poly_reduce 1s 1s +0%
mlk_poly_tomont_c 1s 2s -50%
mlk_scalar_compress_d11 1s 2s -50%
mlk_shake128x4_absorb_once 1s 2s -50%
mlk_shake256 1s 2s -50%
mlk_value_barrier_u32 1s 3s -67%
poly_mulcache_compute_native_x86_64 1s 1s +0%
poly_reduce_native_aarch64 1s 1s +0%

@oqs-bot

oqs-bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

CBMC Results (ML-KEM-768)

Full Results (190 proofs)
Proof Status Current Previous Change
**TOTAL** 1686s 1645s +2.5%
mlk_indcpa_enc 321s 252s +27%
mlk_indcpa_keypair_derand 177s 318s -44%
mlk_poly_rej_uniform 145s 129s +12%
mlk_rej_uniform_c 123s 114s +8%
rej_uniform_native_x86_64 63s 55s +15%
mlk_polymat_permute_bitrev_to_custom_native 47s - new
mlk_polyvec_basemul_acc_montgomery_cached_c 45s 46s -2%
rej_uniform_native_aarch64 45s 45s +0%
poly_ntt_native 42s 39s +8%
mlk_ntt_layer 37s 29s +28%
mlk_poly_reduce_native 34s 34s +0%
mlk_keccak_squeezeblocks_x4 26s 24s +8%
keccakf1600x4_permute_native_x4 16s 21s -24%
mlk_fqmul 16s 16s +0%
mlk_poly_decompress_d10_native 13s 15s -13%
polyvec_basemul_acc_montgomery_cached_native 13s 14s -7%
mlk_poly_decompress_d4_native 12s 12s +0%
mlk_indcpa_dec 11s 10s +10%
mlk_poly_frommsg 11s 9s +22%
mlk_polyvec_add 10s 12s -17%
mlk_poly_frombytes_native 9s 8s +12%
mlk_ntt_butterfly_block 8s 7s +14%
mlk_poly_ntt 8s 5s +60%
mlk_poly_sub 8s 10s -20%
mlk_keccak_squeeze_once 7s 7s +0%
mlk_keccak_squeezeblocks 7s 8s -12%
mlk_invntt_layer 6s 4s +50%
mlk_keccak_absorb_once_x4 6s 5s +20%
mlk_poly_getnoise_eta2 6s 2s +200%
mlk_poly_rej_uniform_x4 6s 5s +20%
poly_decompress_d4_native_x86_64 6s 6s +0%
kem_dec 5s 5s +0%
mlk_keccakf1600_permute_c 5s 6s -17%
mlk_poly_add 5s 7s -29%
mlk_poly_frombytes_c 5s 4s +25%
mlk_poly_reduce 5s 2s +150%
mlk_scalar_compress_d4 5s 2s +150%
kem_check_sk 4s 2s +100%
kem_keypair 4s 2s +100%
mlk_barrett_reduce 4s 2s +100%
mlk_check_pct 4s 3s +33%
mlk_enc_getnoise_eta1_eta2 4s 3s +33%
mlk_gen_matrix_serial 4s 2s +100%
mlk_keccakf1600x4_permute 4s 4s +0%
mlk_matvec_mul 4s 4s +0%
mlk_poly_decompress_d4_c 4s 4s +0%
mlk_poly_mulcache_compute_native 4s 1s +300%
mlk_polyvec_invntt_tomont 4s 1s +300%
mlk_scalar_decompress_d5 4s 2s +100%
mlk_scalar_signed_to_unsigned_q 4s 5s -20%
poly_compress_d5_native_x86_64 4s 2s +100%
poly_decompress_d10_native_x86_64 4s 5s -20%
poly_frombytes_native_x86_64 4s 5s -20%
poly_invntt_tomont_native 4s 2s +100%
poly_mulcache_compute_native_aarch64 4s 6s -33%
poly_reduce_native_x86_64 4s 2s +100%
polyvec_basemul_acc_montgomery_cached_k3_native_aarch64 4s 2s +100%
sys_check_capability 4s 3s +33%
keccak_f1600_x4_native_aarch64_v8a_scalar_hybrid 3s 3s +0%
keccak_f1600_x4_native_avx2 3s 2s +50%
keccakf1600_permute_native 3s 3s +0%
mlk_ct_cmask_nonzero_u16 3s 4s -25%
mlk_ct_cmask_nonzero_u8 3s 4s -25%
mlk_ct_cmov_zero 3s 3s +0%
mlk_ct_get_optblocker_u32 3s 1s +200%
mlk_gen_matrix 3s 2s +50%
mlk_keccak_absorb_once 3s 3s +0%
mlk_keccakf1600_extract_bytes 3s 4s -25%
mlk_keccakf1600_permute 3s 1s +200%
mlk_keccakf1600_xor_bytes 3s 3s +0%
mlk_keccakf1600_xor_bytes (big endian) 3s 1s +200%
mlk_poly_compress_d10_native 3s 2s +50%
mlk_poly_compress_d11_c 3s 1s +200%
mlk_poly_compress_d4 3s 3s +0%
mlk_poly_compress_d5_native 3s 2s +50%
mlk_poly_compress_dv 3s 1s +200%
mlk_poly_decompress_d10 3s 2s +50%
mlk_poly_decompress_d11_c 3s 3s +0%
mlk_poly_decompress_d11_native 3s 1s +200%
mlk_poly_decompress_d4 3s 3s +0%
mlk_poly_decompress_d5_native 3s 3s +0%
mlk_poly_frombytes 3s 2s +50%
mlk_poly_getnoise_eta1122_4x 3s 1s +200%
mlk_poly_getnoise_eta1_4x 3s 2s +50%
mlk_poly_invntt_tomont_c 3s 2s +50%
mlk_poly_mulcache_compute_c 3s 2s +50%
mlk_poly_tobytes 3s 3s +0%
mlk_poly_tomont_native 3s 3s +0%
mlk_polyvec_compress_du 3s 1s +200%
mlk_polyvec_mulcache_compute 3s 2s +50%
mlk_scalar_compress_d10 3s 2s +50%
mlk_shake128_squeezeblocks 3s 3s +0%
mlk_shake128x4_absorb_once 3s 3s +0%
mlk_shake256x4 3s 3s +0%
mlk_value_barrier_u8 3s 2s +50%
ntt_native_aarch64 3s 3s +0%
nttunpack_native_x86_64 3s 3s +0%
poly_compress_d11_native_x86_64 3s 3s +0%
poly_decompress_d11_native_x86_64 3s 1s +200%
poly_decompress_d5_native_x86_64 3s 4s -25%
poly_mulcache_compute_native_x86_64 3s 3s +0%
poly_tomont_native_aarch64 3s 1s +200%
poly_tomont_native_x86_64 3s 1s +200%
polyvec_basemul_acc_montgomery_cached_k2_native_aarch64 3s 3s +0%
polyvec_basemul_acc_montgomery_cached_k4_native_aarch64 3s 1s +200%
intt_native_aarch64 2s 5s -60%
keccak_f1600_x1_native_aarch64 2s 1s +100%
keccak_f1600_x4_native_aarch64_v84a 2s 2s +0%
keccakf1600x4_extract_bytes_native 2s 3s -33%
keccakf1600x4_xor_bytes_native 2s 2s +0%
kem_check_pk 2s 2s +0%
kem_enc 2s 2s +0%
kem_enc_derand 2s 3s -33%
kem_keypair_derand 2s 2s +0%
mlk_ct_cmask_neg_i16 2s 3s -33%
mlk_ct_get_optblocker_u8 2s 2s +0%
mlk_ct_memcmp 2s 4s -50%
mlk_ct_sel_int16 2s 3s -33%
mlk_keccakf1600x4_extract_bytes 2s 4s -50%
mlk_keypair_getnoise_eta1 2s 2s +0%
mlk_montgomery_reduce 2s 1s +100%
mlk_poly_cbd_eta1 2s 1s +100%
mlk_poly_compress_d10_c 2s 2s +0%
mlk_poly_compress_d11 2s 1s +100%
mlk_poly_compress_d11_native 2s 4s -50%
mlk_poly_compress_d4_native 2s 3s -33%
mlk_poly_compress_d5 2s 2s +0%
mlk_poly_compress_du 2s 1s +100%
mlk_poly_decompress_d10_c 2s 1s +100%
mlk_poly_decompress_d11 2s 2s +0%
mlk_poly_decompress_du 2s 1s +100%
mlk_poly_decompress_dv 2s 2s +0%
mlk_poly_getnoise_eta1_4x_native 2s 3s -33%
mlk_poly_invntt_tomont 2s 4s -50%
mlk_poly_mulcache_compute 2s 2s +0%
mlk_poly_reduce_c 2s 3s -33%
mlk_poly_tobytes_c 2s 1s +100%
mlk_poly_tobytes_native 2s 1s +100%
mlk_poly_tomont 2s 1s +100%
mlk_poly_tomsg 2s 3s -33%
mlk_polymat_permute_bitrev_to_custom 2s 3s -33%
mlk_polyvec_basemul_acc_montgomery_cached 2s 4s -50%
mlk_polyvec_decompress_du 2s 4s -50%
mlk_polyvec_frombytes 2s 3s -33%
mlk_polyvec_ntt 2s 4s -50%
mlk_polyvec_reduce 2s 1s +100%
mlk_polyvec_tobytes 2s 1s +100%
mlk_polyvec_tomont 2s 1s +100%
mlk_scalar_compress_d1 2s 2s +0%
mlk_scalar_compress_d11 2s 1s +100%
mlk_scalar_compress_d5 2s 1s +100%
mlk_scalar_decompress_d10 2s 2s +0%
mlk_scalar_decompress_d11 2s 3s -33%
mlk_scalar_decompress_d4 2s 2s +0%
mlk_sha3_256 2s 2s +0%
mlk_shake128_absorb_once 2s 1s +100%
mlk_shake256 2s 2s +0%
ntt_native_x86_64 2s 3s -33%
poly_compress_d10_native_x86_64 2s 5s -60%
poly_compress_d4_native_x86_64 2s 3s -33%
poly_getnoise_eta1122_4x_native 2s 1s +100%
poly_reduce_native_aarch64 2s 2s +0%
poly_tobytes_native_aarch64 2s 1s +100%
poly_tobytes_native_x86_64 2s 3s -33%
polyvec_basemul_acc_montgomery_cached_k2_native_x86_64 2s 4s -50%
polyvec_basemul_acc_montgomery_cached_k3_native_x86_64 2s 2s +0%
polyvec_basemul_acc_montgomery_cached_k4_native_x86_64 2s 2s +0%
intt_native_x86_64 1s 3s -67%
keccak_f1600_x1_native_aarch64_v84a 1s 3s -67%
keccak_f1600_x4_native_aarch64_v8a_v84a_scalar_hybrid 1s 1s +0%
mlk_ct_get_optblocker_i32 1s 1s +0%
mlk_ct_sel_uint8 1s 1s +0%
mlk_keccakf1600_extract_bytes (big endian) 1s 2s -50%
mlk_keccakf1600x4_extract_bytes_c 1s 2s -50%
mlk_keccakf1600x4_xor_bytes 1s 2s -50%
mlk_keccakf1600x4_xor_bytes_c 1s 1s +0%
mlk_poly_cbd_eta2 1s 2s -50%
mlk_poly_compress_d10 1s 2s -50%
mlk_poly_compress_d4_c 1s 1s +0%
mlk_poly_compress_d5_c 1s 1s +0%
mlk_poly_decompress_d5 1s 2s -50%
mlk_poly_decompress_d5_c 1s 3s -67%
mlk_poly_ntt_c 1s 1s +0%
mlk_poly_tomont_c 1s 3s -67%
mlk_rej_uniform 1s 1s +0%
mlk_sha3_512 1s 3s -67%
mlk_shake128x4_squeezeblocks 1s 1s +0%
mlk_value_barrier_i32 1s 2s -50%
mlk_value_barrier_u32 1s 2s -50%
rej_uniform_native 1s 2s -50%

@rod-chapman
rod-chapman marked this pull request as ready for review April 20, 2026 17:47
@rod-chapman
rod-chapman requested a review from a team as a code owner April 20, 2026 17:47
This commit refactors mlk_polymat_permute_bitrev_to_custom to not require the
helper function mlk_polyvec_permute_bitrev_to_custom.
The function was only needed due CBMC limitations.

The code structure now mimics the data structure to make proof tractable.
Also updates Makefile for this proof in line with the similar function
in mldsa-native.

Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
Signed-off-by: Rod Chapman <rodchap@amazon.com>
Signed-off-by: willieyz <willie.zhao@chelpis.com>

Re-format with clang-format and add decreases contract

Signed-off-by: Rod Chapman <rodchap@amazon.com>
@hanno-becker
hanno-becker force-pushed the refactor-polymat-permute branch from 9f86f86 to f9406ce Compare August 5, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CBMC: Refactor mlk_polymat_permute_bitrev_to_custom and prove monolithically

5 participants