Closed dkostic closed 2 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 78.32%. Comparing base (
79d5d16
) to head (9c591df
). Report is 18 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Issues:
CryptoAlg-2614
Description of changes:
Previous to this change, ML-KEM was implemented such that the code for a parameter set was selected by defining the correct C pre-processor flag (for example, if you want to compile the code for ML-KEM 512 parameter set you would
#define KYBER_K 2
). The consequence of this was that we had to compile the code three times for three ML-KEM parameter sets. We do this by adding a C file for each parameter set where we first define the correspondingKYBER_K
value and then include all the ML-KEM C files. Besides being an awkward way to handle multiple parameter sets, this will not work for the FIPS module where we bundle all C files insidebcm.c
and compile it as a single compilation unit.In this change we refactor ML-KEM by parametrizing all functions that depend on values that are specific to a parameter set, i.e., that directly or indirectly depend on the value of
KYBER_K
. To do this, inparams.h
we define a structure that holds those ML-KEM parameters and functions that initialize a given structure with values corresponding to a parameter set. This structure can then be passed to every function that requires it. For example,polyvec_ntt
function was previously implemented like this:We now change that to:
Of course, now we have to change all callers of
polyvec_ntt
to also haveml_kem_params
as an input argument, and then callers of the caller, etc. These changes bubble up to the highest level API defined inkem.h
where we now have:Then we can easily implement these functions for specific parameter sets, which can be seen in
ml_kem.c
file. For example:Call-outs:
Point out areas that need special attention or support during the review process. Discuss architecture or design changes.
Testing:
How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.