From 4fcb490558ebecfe50034113faa1ba06d0fda83e Mon Sep 17 00:00:00 2001 From: willieyz Date: Tue, 2 Dec 2025 16:33:34 +0800 Subject: [PATCH 1/2] refactor: move pre-bound_assertion into native branch Signed-off-by: willieyz --- mlkem/src/poly.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mlkem/src/poly.c b/mlkem/src/poly.c index 858b744820..99ee4f3d6a 100644 --- a/mlkem/src/poly.c +++ b/mlkem/src/poly.c @@ -456,17 +456,14 @@ __contract__( MLK_INTERNAL_API void mlk_poly_ntt(mlk_poly *p) { - mlk_assert_abs_bound(p, MLKEM_N, MLKEM_Q); - #if defined(MLK_USE_NATIVE_NTT) + int ret; + mlk_assert_abs_bound(p, MLKEM_N, MLKEM_Q); + ret = mlk_ntt_native(p->coeffs); + if (ret == MLK_NATIVE_FUNC_SUCCESS) { - int ret; - ret = mlk_ntt_native(p->coeffs); - if (ret == MLK_NATIVE_FUNC_SUCCESS) - { - mlk_assert_abs_bound(p, MLKEM_N, MLK_NTT_BOUND); - return; - } + mlk_assert_abs_bound(p, MLKEM_N, MLK_NTT_BOUND); + return; } #endif /* MLK_USE_NATIVE_NTT */ From 03b54c99e920844f80a1a0e821fe7fae6557ea3c Mon Sep 17 00:00:00 2001 From: willieyz Date: Tue, 2 Dec 2025 17:44:18 +0800 Subject: [PATCH 2/2] Remove outdate comment and add assertion for mlk_polyvec_basemul_acc_montgomery_cached_native Signed-off-by: willieyz --- mlkem/src/poly_k.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mlkem/src/poly_k.c b/mlkem/src/poly_k.c index f83fa35962..f07a9b256f 100644 --- a/mlkem/src/poly_k.c +++ b/mlkem/src/poly_k.c @@ -194,9 +194,7 @@ void mlk_polyvec_basemul_acc_montgomery_cached( #if defined(MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED) { int ret; - /* Omitting bounds assertion for cache since native implementations may - * decide not to use a mulcache. Note that the C backend implementation - * of poly_basemul_montgomery_cached() does still include the check. */ + mlk_assert_bound_2d(a->vec, MLKEM_K, MLKEM_N, 0, MLKEM_UINT12_LIMIT); #if MLKEM_K == 2 ret = mlk_polyvec_basemul_acc_montgomery_cached_k2_native( r->coeffs, (const int16_t *)a, (const int16_t *)b,