Skip to content

Commit

Permalink
Rename GEN_NMATRIX_BLOCKS -> MLKEM_GEN_MATRIX_NBLOCKS
Browse files Browse the repository at this point in the history
Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker committed Nov 19, 2024
1 parent 1d36073 commit a75a08b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,32 +222,32 @@ jobs:
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: "GEN_MATRIX_NBLOCKS=1"
- name: "MLKEM_GEN_MATRIX_NBLOCKS=1"
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
compile_mode: native
cflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -DGEN_MATRIX_NBLOCKS=1"
cflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -DMLKEM_GEN_MATRIX_NBLOCKS=1"
func: true
nistkat: true
kat: false
acvp: false
- name: "GEN_MATRIX_NBLOCKS=2"
- name: "MLKEM_GEN_MATRIX_NBLOCKS=2"
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
compile_mode: native
cflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -DGEN_MATRIX_NBLOCKS=2"
cflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -DMLKEM_GEN_MATRIX_NBLOCKS=2"
func: true
nistkat: true
kat: false
acvp: false
- name: "GEN_MATRIX_NBLOCKS=4"
- name: "MLKEM_GEN_MATRIX_NBLOCKS=4"
uses: ./.github/actions/multi-functest
with:
gh_token: ${{ secrets.GITHUB_TOKEN }}
compile_mode: native
cflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -DGEN_MATRIX_NBLOCKS=4"
cflags: "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -DMLKEM_GEN_MATRIX_NBLOCKS=4"
func: true
nistkat: true
kat: false
Expand Down
26 changes: 13 additions & 13 deletions mlkem/indcpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ static void unpack_ciphertext(polyvec *b, poly *v,
poly_decompress(v, c + MLKEM_POLYVECCOMPRESSEDBYTES);
}

#ifndef GEN_MATRIX_NBLOCKS
#define GEN_MATRIX_NBLOCKS \
#ifndef MLKEM_GEN_MATRIX_NBLOCKS
#define MLKEM_GEN_MATRIX_NBLOCKS \
((12 * MLKEM_N / 8 * (1 << 12) / MLKEM_Q + SHAKE128_RATE) / SHAKE128_RATE)
#endif

Expand All @@ -147,10 +147,10 @@ void gen_matrix_entry_x4(poly *vec, uint8_t *seed[4]) // clang-format off
// clang-format on
{
// Temporary buffers for XOF output before rejection sampling
uint8_t buf0[GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf1[GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf2[GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf3[GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf0[MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf1[MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf2[MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf3[MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE];

// Tracks the number of coefficients we have already sampled
unsigned int ctr[KECCAK_WAY];
Expand All @@ -161,10 +161,10 @@ void gen_matrix_entry_x4(poly *vec, uint8_t *seed[4]) // clang-format off
shake128x4_absorb(&statex, seed[0], seed[1], seed[2], seed[3],
MLKEM_SYMBYTES + 2);

// Initially, squeeze heuristic number of GEN_MATRIX_NBLOCKS.
// Initially, squeeze heuristic number of MLKEM_GEN_MATRIX_NBLOCKS.
// This should generate the matrix entries with high probability.
shake128x4_squeezeblocks(buf0, buf1, buf2, buf3, GEN_MATRIX_NBLOCKS, &statex);
buflen = GEN_MATRIX_NBLOCKS * SHAKE128_RATE;
shake128x4_squeezeblocks(buf0, buf1, buf2, buf3, MLKEM_GEN_MATRIX_NBLOCKS, &statex);

Check failure on line 166 in mlkem/indcpa.c

View workflow job for this annotation

GitHub Actions / Linting (ubuntu-latest)

Format error

mlkem/indcpa.c require to be formatted
buflen = MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE;
ctr[0] = rej_uniform(vec[0].coeffs, MLKEM_N, 0, buf0, buflen);
ctr[1] = rej_uniform(vec[1].coeffs, MLKEM_N, 0, buf1, buflen);
ctr[2] = rej_uniform(vec[2].coeffs, MLKEM_N, 0, buf2, buflen);
Expand Down Expand Up @@ -206,15 +206,15 @@ void gen_matrix_entry(poly *entry,
ENSURES(ARRAY_BOUND(entry->coeffs, 0, MLKEM_N - 1, 0, (MLKEM_Q - 1)))
{ // clang-format on
shake128ctx state;
uint8_t buf[GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
uint8_t buf[MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE];
unsigned int ctr, buflen;

shake128_absorb(&state, seed, MLKEM_SYMBYTES + 2);

// Initially, squeeze + sample heuristic number of GEN_MATRIX_NBLOCKS.
// Initially, squeeze + sample heuristic number of MLKEM_GEN_MATRIX_NBLOCKS.
// This should generate the matrix entry with high probability.
shake128_squeezeblocks(buf, GEN_MATRIX_NBLOCKS, &state);
buflen = GEN_MATRIX_NBLOCKS * SHAKE128_RATE;
shake128_squeezeblocks(buf, MLKEM_GEN_MATRIX_NBLOCKS, &state);
buflen = MLKEM_GEN_MATRIX_NBLOCKS * SHAKE128_RATE;
ctr = rej_uniform(entry->coeffs, MLKEM_N, 0, buf, buflen);

// Squeeze + sample one more block a time until we're done
Expand Down

0 comments on commit a75a08b

Please sign in to comment.