Skip to content

Commit

Permalink
KeyGen: Remove size annotation from gen_matrix_entry_x4()
Browse files Browse the repository at this point in the history
gen_matrix_entry_x4() expects a slice of 4 polynomials to be filled.
In the caller gen_matrix(), this slice is constructed as a pointer
into an array of MLKEM_K polyvecs. Importantly, however, the slice of
4 poly's passed to gen_matrix_entry_x4() can cross the boundary
between two polyvec instances. Some compilers notice that from
the signature of gen_matrix_entry_x4(), and fail.

The behaviour of the code is intentional and safe here. To suppress
the compiler warning, this commit changes the signature of
gen_matrix_entry_x4() to use a generic poly* pointer, rather than
a pointer to a poly[4].

Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker committed Nov 8, 2024
1 parent cbb0565 commit c5b619d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mlkem/indcpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static void unpack_ciphertext(polyvec *b, poly *v,
// sampling on the output of a XOF.
// clang-format off
STATIC_TESTABLE
void gen_matrix_entry_x4(poly vec[4], uint8_t *seed[4])
void gen_matrix_entry_x4(poly *vec, uint8_t *seed[4])
REQUIRES(IS_FRESH(vec, sizeof(poly) * 4))
REQUIRES(IS_FRESH(seed, sizeof(uint8_t*) * 4))
REQUIRES(IS_FRESH(seed[0], MLKEM_SYMBYTES + 2))
Expand Down Expand Up @@ -299,6 +299,8 @@ void gen_matrix(polyvec *a, const uint8_t seed[MLKEM_SYMBYTES],
}
}

// This call writes across polyvec boundaries for K=2 and K=3.
// This is intentional and safe.
gen_matrix_entry_x4(&a[0].vec[0] + i, seedxy);
}

Expand Down

0 comments on commit c5b619d

Please sign in to comment.