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)
@@ -224,9 +225,11 @@ void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
224225#else /* MLDSA_ETA == 4 */
225226#error "Invalid value of MLDSA_ETA"
226227#endif /* MLDSA_ETA != 2 && MLDSA_ETA != 4 */
227- static unsigned int mld_rej_eta (int32_t * a , unsigned int target ,
228- unsigned int offset , const uint8_t * buf ,
229- unsigned int buflen )
228+
229+ MLD_STATIC_TESTABLE unsigned int mld_rej_eta_c (int32_t * a , unsigned int target ,
230+ unsigned int offset ,
231+ const uint8_t * buf ,
232+ unsigned int buflen )
230233__contract__ (
231234 requires (offset <= target && target <= MLDSA_N )
232235 requires (buflen <= (POLY_UNIFORM_ETA_NBLOCKS * STREAM256_BLOCKBYTES ))
@@ -242,36 +245,6 @@ __contract__(
242245 int t_valid ;
243246 uint32_t t0 , t1 ;
244247 mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
245-
246- /* TODO: CBMC proof based on mld_rej_uniform_eta2_native */
247- #if MLDSA_ETA == 2 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2 )
248- if (offset == 0 )
249- {
250- int ret ;
251- ret = mld_rej_uniform_eta2_native (a , target , buf , buflen );
252- if (ret != MLD_NATIVE_FUNC_FALLBACK )
253- {
254- unsigned res = (unsigned )ret ;
255- mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
256- return res ;
257- }
258- }
259- /* TODO: CBMC proof based on mld_rej_uniform_eta4_native */
260- #elif MLDSA_ETA == 4 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4 )
261- if (offset == 0 )
262- {
263- int ret ;
264- ret = mld_rej_uniform_eta4_native (a , target , buf , buflen );
265- if (ret != MLD_NATIVE_FUNC_FALLBACK )
266- {
267- unsigned res = (unsigned )ret ;
268- mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
269- return res ;
270- }
271- }
272- #endif /* !(MLDSA_ETA == 2 && MLD_USE_NATIVE_REJ_UNIFORM_ETA2) && MLDSA_ETA == \
273- 4 && MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
274-
275248 ctr = offset ;
276249 pos = 0 ;
277250 while (ctr < target && pos < buflen )
@@ -326,6 +299,54 @@ __contract__(
326299 return ctr ;
327300}
328301
302+ static unsigned int mld_rej_eta (int32_t * a , unsigned int target ,
303+ unsigned int offset , const uint8_t * buf ,
304+ unsigned int buflen )
305+ __contract__ (
306+ requires (offset <= target && target <= MLDSA_N )
307+ requires (buflen <= (POLY_UNIFORM_ETA_NBLOCKS * STREAM256_BLOCKBYTES ))
308+ requires (memory_no_alias (a , sizeof (int32_t ) * target ))
309+ requires (memory_no_alias (buf , buflen ))
310+ requires (array_abs_bound (a , 0 , offset , MLDSA_ETA + 1 ))
311+ assigns (memory_slice (a , sizeof (int32_t ) * target ))
312+ ensures (offset <= return_value && return_value <= target )
313+ ensures (array_abs_bound (a , 0 , return_value , MLDSA_ETA + 1 ))
314+ )
315+ {
316+ /* TODO: CBMC proof based on mld_rej_uniform_eta2_native */
317+ #if MLDSA_ETA == 2 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2 )
318+ int ret ;
319+ mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
320+ if (offset == 0 )
321+ {
322+ ret = mld_rej_uniform_eta2_native (a , target , buf , buflen );
323+ if (ret != MLD_NATIVE_FUNC_FALLBACK )
324+ {
325+ unsigned res = (unsigned )ret ;
326+ mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
327+ return res ;
328+ }
329+ }
330+ /* TODO: CBMC proof based on mld_rej_uniform_eta4_native */
331+ #elif MLDSA_ETA == 4 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4 )
332+ int ret ;
333+ mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
334+ if (offset == 0 )
335+ {
336+ ret = mld_rej_uniform_eta4_native (a , target , buf , buflen );
337+ if (ret != MLD_NATIVE_FUNC_FALLBACK )
338+ {
339+ unsigned res = (unsigned )ret ;
340+ mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
341+ return res ;
342+ }
343+ }
344+ #endif /* !(MLDSA_ETA == 2 && MLD_USE_NATIVE_REJ_UNIFORM_ETA2) && MLDSA_ETA == \
345+ 4 && MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
346+
347+ return mld_rej_eta_c (a , target , offset , buf , buflen );
348+ }
349+
329350#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY )
330351MLD_INTERNAL_API
331352void mld_poly_uniform_eta_4x (mld_poly * r0 , mld_poly * r1 , mld_poly * r2 ,
@@ -906,6 +927,7 @@ void mld_polyw1_pack(uint8_t r[MLDSA_POLYW1_PACKEDBYTES], const mld_poly *a)
906927/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
907928 * Don't modify by hand -- this is auto-generated by scripts/autogen. */
908929#undef mld_rej_eta
930+ #undef mld_rej_eta_c
909931#undef mld_poly_decompose_c
910932#undef mld_poly_use_hint_c
911933#undef mld_polyz_unpack_c
0 commit comments