34#define XOF_BLOCKBYTES 168U
35#define REJ_UNIFORM_NBLOCKS 5U
36#define REJ_UNIFORM_BUFLEN (REJ_UNIFORM_NBLOCKS * XOF_BLOCKBYTES)
41 return (uint32_t) x[0] | ((uint32_t) x[1] << 8U) | ((uint32_t) x[2] << 16U)
42 | ((uint32_t) x[3] << 24U);
47 return (uint32_t) x[0] | ((uint32_t) x[1] << 8U) | ((uint32_t) x[2] << 16U);
52 for (uint32_t i = 0U; i < (
MLKEM_N / 8U); i++) {
54 uint32_t d = t & 0x55555555U;
55 d += (t >> 1U) & 0x55555555U;
57 for (uint32_t j = 0U; j < 8U; j++) {
58 int16_t a_val = (int16_t) ((d >> ((4U * j) + 0U)) & 0x3U);
59 int16_t b_val = (int16_t) ((d >> ((4U * j) + 2U)) & 0x3U);
60 r->
coeffs[(8U * i) + j] = (int16_t) (a_val - b_val);
67 for (uint32_t i = 0U; i < (
MLKEM_N / 4U); i++) {
69 uint32_t d = t & 0x00249249U;
70 d += (t >> 1U) & 0x00249249U;
71 d += (t >> 2U) & 0x00249249U;
73 for (uint32_t j = 0U; j < 4U; j++) {
74 int16_t a_val = (int16_t) ((d >> ((6U * j) + 0U)) & 0x7U);
75 int16_t b_val = (int16_t) ((d >> ((6U * j) + 3U)) & 0x7U);
76 r->
coeffs[(4U * i) + j] = (int16_t) (a_val - b_val);
83 uint8_t buf[3 *
MLKEM_N / 4] = {0};
84 size_t buflen = (size_t) eta *
MLKEM_N / 4;
95 explicit_bzero(buf,
sizeof(buf));
98#define REJ_UNIFORM_BUFLEN_EXT (REJ_UNIFORM_BUFLEN + (XOF_BLOCKBYTES * 3U))
109 int16_t val0 = (int16_t) (((buf[
pos] >> 0U) | ((uint16_t) buf[
pos + 1U] << 8U)) & 0xFFFU);
111 = (int16_t) (((buf[
pos + 1U] >> 4U) | ((uint16_t) buf[
pos + 2U] << 4U)) & 0xFFFU);
124 int16_t val0 = (int16_t) (((buf[
pos] >> 0U) | ((uint16_t) buf[
pos + 1U] << 8U)) & 0xFFFU);
126 = (int16_t) (((buf[
pos + 1U] >> 4U) | ((uint16_t) buf[
pos + 2U] << 4U)) & 0xFFFU);
136 explicit_bzero(buf,
sizeof(buf));
void MLKEM_SAMPLE_cbd2(poly *r, const uint8_t *buf)
Samples a polynomial using the centered binomial distribution with eta=2.
void MLKEM_SAMPLE_getnoise(poly *r, const uint8_t *seed, uint8_t nonce, uint8_t eta)
Samples a noise polynomial using PRF and CBD.
static uint32_t load24_le(const uint8_t *x)
void MLKEM_SAMPLE_cbd3(poly *r, const uint8_t *buf)
Samples a polynomial using the centered binomial distribution with eta=3.
#define REJ_UNIFORM_BUFLEN
#define REJ_UNIFORM_BUFLEN_EXT
void MLKEM_SAMPLE_rej_uniform(poly *r, const uint8_t *seed, uint8_t x, uint8_t y)
Samples a polynomial using rejection sampling from a uniform distribution.
static uint32_t load32_le(const uint8_t *x)
void MLKEM_UTIL_prf(uint8_t *out, size_t outlen, const uint8_t *key, uint8_t nonce)
Computes the PRF function (SHAKE256) as defined in FIPS 203.
void MLKEM_UTIL_xof_squeeze(uint8_t *out, size_t outlen, const uint8_t *seed, uint8_t x, uint8_t y)
Computes the XOF function (SHAKE128) as defined in FIPS 203.
Polynomial with MLKEM_N coefficients.
static nbgl_touchStatePosition_t pos