|
39 | 39 |
|
40 | 40 | /* Bound on absolute value of coefficients after NTT. |
41 | 41 | * |
42 | | - * NOTE: This is the same bound as in ntt.h and has to be kept |
| 42 | + * NOTE: This is the same bound as in poly.h and has to be kept |
43 | 43 | * in sync. */ |
44 | 44 | #define MLD_NTT_BOUND (9 * MLDSA_Q) |
45 | 45 |
|
46 | 46 | /* Absolute exclusive upper bound for the output of the inverse NTT |
47 | 47 | * |
48 | | - * NOTE: This is the same bound as in ntt.h and has to be kept |
| 48 | + * NOTE: This is the same bound as in poly.h and has to be kept |
49 | 49 | * in sync. */ |
50 | 50 | #define MLD_INTT_BOUND MLDSA_Q |
51 | 51 |
|
|
54 | 54 | * NOTE: This is the same bound as in reduce.h and has to be kept |
55 | 55 | * in sync. */ |
56 | 56 | /* check-magic: 6283009 == (MLD_REDUCE32_DOMAIN_MAX - 255 * MLDSA_Q + 1) */ |
57 | | -#define REDUCE32_RANGE_MAX 6283009 |
| 57 | +#define MLD_REDUCE32_RANGE_MAX 6283009 |
58 | 58 | /* |
59 | 59 | * This is the C<->native interface allowing for the drop-in of |
60 | 60 | * native code for performance critical arithmetic components of ML-DSA. |
@@ -429,19 +429,28 @@ __contract__( |
429 | 429 | * Assumes input coefficients were reduced by mld_reduce32(). |
430 | 430 | * |
431 | 431 | * Arguments: - const int32_t *a: pointer to polynomial |
432 | | - * - int32_t B: norm bound |
| 432 | + * - int32_t B: norm bound, which must be in the range |
| 433 | + * 0 .. MLDSA_Q - MLD_REDUCE32_RANGE_MAX inclusive. |
433 | 434 | * |
434 | | - * Returns 0 if the infinity norm is strictly smaller than B, and 1 |
435 | | - * otherwise. B must not be larger than MLDSA_Q - MLD_REDUCE32_RANGE_MAX. |
| 435 | + * Returns MLD_NATIVE_FUNC_FALLBACK (-1) if the target CPU cannot |
| 436 | + * support a native implementation of this function. |
| 437 | + * |
| 438 | + * If the target CPU can support this function, then |
| 439 | + * Returns MLD_NATIVE_FUNC_SUCCESS (0) if the infinity norm is strictly |
| 440 | + * smaller than B |
| 441 | + * Returns 1 otherwise |
436 | 442 | **************************************************/ |
437 | 443 | MLD_MUST_CHECK_RETURN_VALUE |
438 | 444 | static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B) |
439 | 445 | __contract__( |
440 | 446 | requires(memory_no_alias(a, sizeof(int32_t) * MLDSA_N)) |
441 | | - requires(0 <= B && B <= MLDSA_Q - REDUCE32_RANGE_MAX) |
442 | | - requires(array_bound(a, 0, MLDSA_N, -REDUCE32_RANGE_MAX, REDUCE32_RANGE_MAX)) |
443 | | - ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == MLD_NATIVE_FUNC_SUCCESS) |
444 | | - ensures((return_value == 0) == array_abs_bound(a, 0, MLDSA_N, B)) |
| 447 | + requires(0 <= B && B <= MLDSA_Q - MLD_REDUCE32_RANGE_MAX) |
| 448 | + requires(array_bound(a, 0, MLDSA_N, -MLD_REDUCE32_RANGE_MAX, MLD_REDUCE32_RANGE_MAX)) |
| 449 | + ensures(return_value == MLD_NATIVE_FUNC_FALLBACK || return_value == 0 || |
| 450 | + return_value == 1) |
| 451 | + ensures((return_value != MLD_NATIVE_FUNC_FALLBACK) ==> |
| 452 | + ((return_value == 0) == array_abs_bound(a, 0, MLDSA_N, B))) |
| 453 | + |
445 | 454 | ); |
446 | 455 | #endif /* MLD_USE_NATIVE_POLY_CHKNORM */ |
447 | 456 |
|
|
0 commit comments