-
Notifications
You must be signed in to change notification settings - Fork 26
Open
0 / 30 of 3 issues completedLabels
enhancementNew feature or requestNew feature or request
Description
Goal: The goal of this task is to reduce RAM usage by ad-hoc generating the matrix rather than storing it in memory.
Proposed steps (these should be critiqued):
- Introduce a struct wrapper for the matrix: Instead of
mld_polyvecl mat[MLDSA_K], usemld_polymat. This should follow Reintroduce struct definitions for mlk_poly{mat,vec} mlkem-native#1263. Check thattests allstill pass. Adjust all CBMC annotations and check the relevant proofs viatests cbmc -p {FUNCTION_NAME}, to be run in thenix developshell. Seetests cbmc --list-functionsfor the full list of functions. - Introduce a helper function
mld_polymat_get_rowwhich retrieves amld_polyveclpointer from amld_polymatpointer pointing to the required row of the matrix. Initially, this would simply return the address of thei-th entry in themld_polyvecl mat[MLDSA_K]array thatmld_polymatwraps. Rewritemld_polyvec_matrix_pointwise_montgomery()to use this function rather than directly accessing the matrix. Check that./scripts/tests allstill passes. Adjust all CBMC annotations and check the relevant proofs viatests cbmc -p {FUNCTION_NAME}, to be run in thenix developshell. Seetests cbmc --list-functionsfor the full list of functions. - Check that at this point, the only operations dealing with the matrix are (a)
mld_polymat_get_row(), (b)mld_polyvec_matrix_expand(), (c)mld_polyvec_matrix_pointwise_montgomery(), and (d)mld_polymat_permute_bitrev_to_custom(). - Introduce a compile-time option
MLD_CONFIG_REDUCE_RAM. It should be unset by default. Initially, it should be unused. - Implement
MLD_CONFIG_REDUCE_RAM, ignoring CBMC initially:- Modify the definition of
mld_polymatso it contains a singlemld_polyvecland a copy of the seed-bufferconst uint8_t rho[MLDSA_SEEDBYTES]. -
mld_polyvec_matrix_expand()should merely copy the seed buffer. Note that this changes the signature ofmld_polyvec_matrix_pointwise_montgomeryas it can no longer take the matrix asconst. -
mld_polymat_get_row()should ad-hoc generate the required row by callingmld_poly_uniformin a loop, just as inmld_polyvec_matrix_expand(), and callmld_poly_permute_bitrev_to_customon the generated entries to make sure they have the right ordering. Initially, this should ignore batched matrix generation, at the cost of performance. -
mld_polyvec_matrix_pointwise_montgomery()does not need changing since it already callsmld_polymat_get_row(). - Make sure
./scripts/tests allstill passes, but ignore CBMC annotations and proofs in this step.
- Modify the definition of
- Verify the reduction in stack usage when
MLD_CONFIG_REDUCE_RAMis used and document it. - TBD: Develop and implement a test plan for
MLD_CONFIG_REDUCE_RAM. - TBD: Find a way to make CBMC happy
Sub-issues
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request