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)
@@ -230,9 +231,10 @@ void mld_poly_use_hint(mld_poly *b, const mld_poly *a, const mld_poly *h)
230231#else /* MLDSA_ETA == 4 */
231232#error "Invalid value of MLDSA_ETA"
232233#endif /* MLDSA_ETA != 2 && MLDSA_ETA != 4 */
233- static unsigned int mld_rej_eta (int32_t * a , unsigned int target ,
234- unsigned int offset , const uint8_t * buf ,
235- unsigned int buflen )
234+
235+ static unsigned int mld_rej_eta_c (int32_t * a , unsigned int target ,
236+ unsigned int offset , const uint8_t * buf ,
237+ unsigned int buflen )
236238__contract__ (
237239 requires (offset <= target && target <= MLDSA_N )
238240 requires (buflen <= (POLY_UNIFORM_ETA_NBLOCKS * STREAM256_BLOCKBYTES ))
@@ -248,36 +250,6 @@ __contract__(
248250 int t_valid ;
249251 uint32_t t0 , t1 ;
250252 mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
251-
252- /* TODO: CBMC proof based on mld_rej_uniform_eta2_native */
253- #if MLDSA_ETA == 2 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2 )
254- if (offset == 0 )
255- {
256- int ret ;
257- ret = mld_rej_uniform_eta2_native (a , target , buf , buflen );
258- if (ret != MLD_NATIVE_FUNC_FALLBACK )
259- {
260- unsigned res = (unsigned )ret ;
261- mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
262- return res ;
263- }
264- }
265- /* TODO: CBMC proof based on mld_rej_uniform_eta4_native */
266- #elif MLDSA_ETA == 4 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4 )
267- if (offset == 0 )
268- {
269- int ret ;
270- ret = mld_rej_uniform_eta4_native (a , target , buf , buflen );
271- if (ret != MLD_NATIVE_FUNC_FALLBACK )
272- {
273- unsigned res = (unsigned )ret ;
274- mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
275- return res ;
276- }
277- }
278- #endif /* !(MLDSA_ETA == 2 && MLD_USE_NATIVE_REJ_UNIFORM_ETA2) && MLDSA_ETA == \
279- 4 && MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
280-
281253 ctr = offset ;
282254 pos = 0 ;
283255 while (ctr < target && pos < buflen )
@@ -332,6 +304,53 @@ __contract__(
332304 return ctr ;
333305}
334306
307+ static unsigned int mld_rej_eta (int32_t * a , unsigned int target ,
308+ unsigned int offset , const uint8_t * buf ,
309+ unsigned int buflen )
310+ __contract__ (
311+ requires (offset <= target && target <= MLDSA_N )
312+ requires (buflen <= (POLY_UNIFORM_ETA_NBLOCKS * STREAM256_BLOCKBYTES ))
313+ requires (memory_no_alias (a , sizeof (int32_t ) * target ))
314+ requires (memory_no_alias (buf , buflen ))
315+ requires (array_abs_bound (a , 0 , offset , MLDSA_ETA + 1 ))
316+ assigns (memory_slice (a , sizeof (int32_t ) * target ))
317+ ensures (offset <= return_value && return_value <= target )
318+ ensures (array_abs_bound (a , 0 , return_value , MLDSA_ETA + 1 ))
319+ )
320+ {
321+ mld_assert_abs_bound (a , offset , MLDSA_ETA + 1 );
322+ /* TODO: CBMC proof based on mld_rej_uniform_eta2_native */
323+ #if MLDSA_ETA == 2 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA2 )
324+ if (offset == 0 )
325+ {
326+ int ret ;
327+ ret = mld_rej_uniform_eta2_native (a , target , buf , buflen );
328+ if (ret != MLD_NATIVE_FUNC_FALLBACK )
329+ {
330+ unsigned res = (unsigned )ret ;
331+ mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
332+ return res ;
333+ }
334+ }
335+ /* TODO: CBMC proof based on mld_rej_uniform_eta4_native */
336+ #elif MLDSA_ETA == 4 && defined(MLD_USE_NATIVE_REJ_UNIFORM_ETA4 )
337+ if (offset == 0 )
338+ {
339+ int ret ;
340+ ret = mld_rej_uniform_eta4_native (a , target , buf , buflen );
341+ if (ret != MLD_NATIVE_FUNC_FALLBACK )
342+ {
343+ unsigned res = (unsigned )ret ;
344+ mld_assert_abs_bound (a , res , MLDSA_ETA + 1 );
345+ return res ;
346+ }
347+ }
348+ #endif /* !(MLDSA_ETA == 2 && MLD_USE_NATIVE_REJ_UNIFORM_ETA2) && MLDSA_ETA == \
349+ 4 && MLD_USE_NATIVE_REJ_UNIFORM_ETA4 */
350+
351+ return mld_rej_eta_c (a , target , offset , buf , buflen );
352+ }
353+
335354#if !defined(MLD_CONFIG_SERIAL_FIPS202_ONLY )
336355MLD_INTERNAL_API
337356void mld_poly_uniform_eta_4x (mld_poly * r0 , mld_poly * r1 , mld_poly * r2 ,
@@ -912,6 +931,7 @@ void mld_polyw1_pack(uint8_t r[MLDSA_POLYW1_PACKEDBYTES], const mld_poly *a)
912931/* To facilitate single-compilation-unit (SCU) builds, undefine all macros.
913932 * Don't modify by hand -- this is auto-generated by scripts/autogen. */
914933#undef mld_rej_eta
934+ #undef mld_rej_eta_c
915935#undef mld_poly_decompose_c
916936#undef mld_poly_use_hint_c
917937#undef mld_polyz_unpack_c
0 commit comments