29#define MLDSA_XOF_BLOCKBYTES 168U
35#define MLDSA_REJ_UNIFORM_NBLOCKS 5U
36#define MLDSA_REJ_UNIFORM_BUFLEN (MLDSA_REJ_UNIFORM_NBLOCKS * MLDSA_XOF_BLOCKBYTES)
46 while ((ctr <
MLDSA_N) && ((
pos + 3U) <=
sizeof(buf))) {
48 t = (uint32_t) buf[
pos++];
49 t |= (uint32_t) buf[
pos++] << 8U;
50 t |= (uint32_t) buf[
pos++] << 16U;
54 a->
coeffs[ctr] = (int32_t) t;
64 explicit_bzero(buf,
sizeof(buf));
77 uint8_t buf[136U * 4U];
94 uint8_t t0 = buf[
pos] & 0x0FU;
95 uint8_t t1 = buf[
pos] >> 4U;
100 a->
coeffs[ctr] = (int32_t) (2U - (t0 % 5U));
103 if ((t1 < 15U) && (ctr <
MLDSA_N)) {
104 a->
coeffs[ctr] = (int32_t) (2U - (t1 % 5U));
112 uint8_t t0 = buf[
pos] & 0x0FU;
113 uint8_t t1 = buf[
pos] >> 4U;
117 a->
coeffs[ctr] = (int32_t) (4 - t0);
120 if ((t1 < 9U) && (ctr <
MLDSA_N)) {
121 a->
coeffs[ctr] = (int32_t) (4 - t1);
127 explicit_bzero(buf,
sizeof(buf));
140 if (gamma1 == (1 << 17)) {
149 if (gamma1 == (1 << 17)) {
151 for (uint32_t i = 0U; i <
MLDSA_N / 4U; i++) {
152 uint32_t t0, t1, t2, t3;
153 t0 = (uint32_t) buf[9U * i + 0U];
154 t0 |= (uint32_t) buf[9U * i + 1U] << 8U;
155 t0 |= (uint32_t) buf[9U * i + 2U] << 16U;
158 t1 = (uint32_t) buf[9U * i + 2U] >> 2U;
159 t1 |= (uint32_t) buf[9U * i + 3U] << 6U;
160 t1 |= (uint32_t) buf[9U * i + 4U] << 14U;
163 t2 = (uint32_t) buf[9U * i + 4U] >> 4U;
164 t2 |= (uint32_t) buf[9U * i + 5U] << 4U;
165 t2 |= (uint32_t) buf[9U * i + 6U] << 12U;
168 t3 = (uint32_t) buf[9U * i + 6U] >> 6U;
169 t3 |= (uint32_t) buf[9U * i + 7U] << 2U;
170 t3 |= (uint32_t) buf[9U * i + 8U] << 10U;
173 a->
coeffs[4U * i + 0U] = gamma1 - (int32_t) t0;
174 a->
coeffs[4U * i + 1U] = gamma1 - (int32_t) t1;
175 a->
coeffs[4U * i + 2U] = gamma1 - (int32_t) t2;
176 a->
coeffs[4U * i + 3U] = gamma1 - (int32_t) t3;
181 for (uint32_t i = 0U; i <
MLDSA_N / 2U; i++) {
183 t0 = (uint32_t) buf[5U * i + 0U];
184 t0 |= (uint32_t) buf[5U * i + 1U] << 8U;
185 t0 |= (uint32_t) buf[5U * i + 2U] << 16U;
188 t1 = (uint32_t) buf[5U * i + 2U] >> 4U;
189 t1 |= (uint32_t) buf[5U * i + 3U] << 4U;
190 t1 |= (uint32_t) buf[5U * i + 4U] << 12U;
193 a->
coeffs[2U * i + 0U] = gamma1 - (int32_t) t0;
194 a->
coeffs[2U * i + 1U] = gamma1 - (int32_t) t1;
198 explicit_bzero(buf,
sizeof(buf));
205 uint8_t buf[136U * 2U];
212 for (uint32_t i = 0U; i < 8U; i++) {
213 signs |= (uint64_t) buf[i] << (8U * i);
217 for (uint32_t i = 0U; i <
MLDSA_N; i++) {
226 if (
pos >=
sizeof(buf)) {
231 j = (uint32_t) buf[
pos++];
235 c->
coeffs[j] = 1 - 2 * (int32_t) (signs & 1U);
239 explicit_bzero(buf,
sizeof(buf));
void MLDSA_SAMPLE_eta(mldsa_poly *a, const uint8_t seed[MLDSA_CRHBYTES], uint16_t nonce, uint8_t eta)
Sample polynomial with coefficients in [-eta, eta] from SHAKE256(seed||nonce).
void MLDSA_SAMPLE_uniform(mldsa_poly *a, const uint8_t seed[MLDSA_SEEDBYTES], uint16_t nonce)
Sample polynomial with uniformly random coefficients in [0, q-1] by performing rejection sampling on ...
void MLDSA_SAMPLE_challenge(mldsa_poly *c, const uint8_t *seed, size_t seedlen, uint8_t tau)
Sample challenge polynomial with TAU coefficients in {-1, +1}.
void MLDSA_SAMPLE_gamma1(mldsa_poly *a, const uint8_t seed[MLDSA_CRHBYTES], uint16_t nonce, int32_t gamma1)
Sample polynomial with coefficients in [-(gamma1-1), gamma1] from SHAKE256(seed||nonce).
#define MLDSA_REJ_UNIFORM_BUFLEN
void MLDSA_UTIL_shake256(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen)
SHAKE256 hash wrapper.
void MLDSA_UTIL_shake256_seed_nonce(uint8_t *out, size_t outlen, const uint8_t *seed, size_t seedlen, uint16_t nonce)
SHAKE256 with seed || uint16_t nonce.
void MLDSA_UTIL_shake128_seed_nonce(uint8_t *out, size_t outlen, const uint8_t *seed, size_t seedlen, uint16_t nonce)
SHAKE128 with seed || uint16_t nonce.
Polynomial with MLDSA_N int32_t coefficients.
static nbgl_touchStatePosition_t pos