3232 * of mldsa-native (e.g. with varying parameter sets)
3333 * within a single compilation unit. */
3434#define mld_rej_eta MLD_ADD_PARAM_SET(mld_rej_eta)
35+ #define mld_rej_eta_c MLD_ADD_PARAM_SET(mld_rej_eta_c)
3536#define mld_poly_decompose_c MLD_ADD_PARAM_SET(mld_poly_decompose_c)
3637#define mld_poly_use_hint_c MLD_ADD_PARAM_SET(mld_poly_use_hint_c)
3738#define mld_polyz_unpack_c MLD_ADD_PARAM_SET(mld_polyz_unpack_c)
@@ -231,9 +232,11 @@ void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
231232#else /* MLDSA_ETA == 4 */
232233#error "Invalid value of MLDSA_ETA"
233234#endif /* MLDSA_ETA != 2 && MLDSA_ETA != 4 */
234- static unsigned int mld_rej_eta (int32_t * a , unsigned int target ,
235- unsigned int offset , const uint8_t * buf ,
236- unsigned int buflen )
235+
236+ MLD_STATIC_TESTABLE unsigned int mld_rej_eta_c (int32_t * a , unsigned int target ,
237+ unsigned int offset ,
238+ const uint8_t * buf ,
239+ unsigned int buflen )
237240__contract__ (
238241 requires (offset <= target && target <= MLDSA_N )
239242 requires (buflen <= (POLY_UNIFORM_ETA_NBLOCKS * STREAM256_BLOCKBYTES ))
@@ -249,36 +252,6 @@ __contract__(
249252 int t_valid ;
250253 uint32_t t0 , t1 ;
251254 mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
252-
253- /* TODO: CBMC proof based on mld_rej_uniform_eta2_native */
254- #if MLDSA_ETA == 2 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2 )
255- if (offset == 0 )
256- {
257- int ret ;
258- ret = mld_rej_uniform_eta2_native (a , target , buf , buflen );
259- if (ret != MLD_NATIVE_FUNC_FALLBACK )
260- {
261- unsigned res = (unsigned )ret ;
262- mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
263- return res ;
264- }
265- }
266- /* TODO: CBMC proof based on mld_rej_uniform_eta4_native */
267- #elif MLDSA_ETA == 4 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4 )
268- if (offset == 0 )
269- {
270- int ret ;
271- ret = mld_rej_uniform_eta4_native (a , target , buf , buflen );
272- if (ret != MLD_NATIVE_FUNC_FALLBACK )
273- {
274- unsigned res = (unsigned )ret ;
275- mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
276- return res ;
277- }
278- }
279- #endif /* !(MLDSA_ETA == 2 && MLD_USE_NATIVE_REJ_UNIFORM_ETA2) && MLDSA_ETA == \
280- 4 && MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
281-
282255 ctr = offset ;
283256 pos = 0 ;
284257 while (ctr < target && pos < buflen )
@@ -333,6 +306,53 @@ __contract__(
333306 return ctr ;
334307}
335308
309+ static unsigned int mld_rej_eta (int32_t * a , unsigned int target ,
310+ unsigned int offset , const uint8_t * buf ,
311+ unsigned int buflen )
312+ __contract__ (
313+ requires (offset <= target && target <= MLDSA_N )
314+ requires (buflen <= (POLY_UNIFORM_ETA_NBLOCKS * STREAM256_BLOCKBYTES ))
315+ requires (memory_no_alias (a , sizeof (int32_t ) * target ))
316+ requires (memory_no_alias (buf , buflen ))
317+ requires (array_abs_bound (a , 0 , offset , MLDSA_ETA + 1 ))
318+ assigns (memory_slice (a , sizeof (int32_t ) * target ))
319+ ensures (offset <= return_value && return_value <= target )
320+ ensures (array_abs_bound (a , 0 , return_value , MLDSA_ETA + 1 ))
321+ )
322+ {
323+ mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
324+ /* TODO: CBMC proof based on mld_rej_uniform_eta2_native */
325+ #if MLDSA_ETA == 2 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2 )
326+ if (offset == 0 )
327+ {
328+ int ret ;
329+ ret = mld_rej_uniform_eta2_native (a , target , buf , buflen );
330+ if (ret != MLD_NATIVE_FUNC_FALLBACK )
331+ {
332+ unsigned res = (unsigned )ret ;
333+ mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
334+ return res ;
335+ }
336+ }
337+ /* TODO: CBMC proof based on mld_rej_uniform_eta4_native */
338+ #elif MLDSA_ETA == 4 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4 )
339+ if (offset == 0 )
340+ {
341+ int ret ;
342+ ret = mld_rej_uniform_eta4_native (a , target , buf , buflen );
343+ if (ret != MLD_NATIVE_FUNC_FALLBACK )
344+ {
345+ unsigned res = (unsigned )ret ;
346+ mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
347+ return res ;
348+ }
349+ }
350+ #endif /* !(MLDSA_ETA == 2 && MLD_USE_NATIVE_REJ_UNIFORM_ETA2) && MLDSA_ETA == \
351+ 4 && MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
352+
353+ return mld_rej_eta_c (a , target , offset , buf , buflen );
354+ }
355+
336356#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY )
337357MLD_INTERNAL_API
338358void mld_poly_uniform_eta_4x (mld_poly * r0 , mld_poly * r1 , mld_poly * r2 ,
@@ -914,6 +934,7 @@ void mld_polyw1_pack(uint8_t r[MLDSA_POLYW1_PACKEDBYTES], const mld_poly *a)
914934/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
915935 * Don't modify by hand -- this is auto-generated by scripts/autogen. */
916936#undef mld_rej_eta
937+ #undef mld_rej_eta_c
917938#undef mld_poly_decompose_c
918939#undef mld_poly_use_hint_c
919940#undef mld_polyz_unpack_c
0 commit comments