From c5b619ddc9633258e2ca8d489ffe76abdbe8f982 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 8 Nov 2024 06:13:29 +0000 Subject: [PATCH] KeyGen: Remove size annotation from gen_matrix_entry_x4() 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 --- mlkem/indcpa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mlkem/indcpa.c b/mlkem/indcpa.c index ddff6726b..db066d684 100644 --- a/mlkem/indcpa.c +++ b/mlkem/indcpa.c @@ -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)) @@ -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); }