pq-crystals/kyber

Kyber Ref dead code ?

yogappu opened this issue · 4 comments

Hello all,

I was analyzing Kyber768 ref code and found a possible deadcode.

Can this line be reached : https://github.com/pq-crystals/kyber/blob/main/ref/indcpa.c#L185 ?

GEN_MATRIX_NBLOCKS is 3 & XOF_BLOCKBYTES is168 (also multiple of 3) that makes off ( @ https://github.com/pq-crystals/kyber/blob/main/ref/indcpa.c#L183) always 0.

---EDIT---
The same is applicable for Dilithium as well : https://github.com/pq-crystals/dilithium/blob/master/ref/poly.c#L360

Thanks.

I think you are right that this is dead code in the 'standard' branch. Tagging @cryptojedi @gregorseiler.

In the Kyber 'main' branch there is the "90s" version where XOF_BLOCKBYTES is 64 and GEN_MATRIX_NBLOCKS is 8.

I agree that it's dead code, because the block size of SHAKE-128 is a multiple of 3.

I'm not sure how I feel about removing it, though. If we do, we should have a #if around that function
to ensure that it's only ever used with symmetric primitives that have a block sizes that are a multiple of 3
and have that checked at compile time. Also, add a comment then stating where this is used.

@cryptojedi is there a fix planned for this ?

This is now changed in the "standard" branch.