Skip to content

Implement polyvecl_uniform_gamma1 using 4-way Keccak #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2025

Conversation

mkannwischer
Copy link
Contributor

This commit adds poly_uniform_gamma1_4x which implements uniform
sampling in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] using 4-way batched
Keccak. It then implements polyvecl_uniform_gamma1 using
the new batched function.

L = 4 is implemented using one call to poly_uniform_gamma1_4x.
L = 5 is implemented using one call to poly_uniform_gamma1_4x and one call to
poly_uniform_gamma1
L = 7 is implemented using two call to poly_uniform_gamma1_4x (with one
polynomial being wasted).

@mkannwischer mkannwischer force-pushed the poly_uniform_gamma1_4x branch from 67a1c6f to 52e8f98 Compare May 17, 2025 16:41
@mkannwischer mkannwischer marked this pull request as ready for review May 17, 2025 16:56
@mkannwischer mkannwischer requested a review from a team as a code owner May 17, 2025 16:56
@hanno-becker hanno-becker force-pushed the poly_uniform_gamma1_4x branch from 52e8f98 to 142be6c Compare May 17, 2025 18:27
Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A call to xxx_release() is missing at the end of the refactored poly_uniform_gamma1()

This commit adds poly_uniform_gamma1_4x which implements uniform
sampling in [-(MLDSA_GAMMA1 - 1), MLDSA_GAMMA1] using 4-way batched
Keccak. It then implements polyvecl_uniform_gamma1 using
the new batched function.

L = 4 is implemented using one call to poly_uniform_gamma1_4x.
L = 5 is implemented using one call to poly_uniform_gamma1_4x and one call to
poly_uniform_gamma1
L = 7 is implemented using two call to poly_uniform_gamma1_4x (with one
polynomial being wasted).

Signed-off-by: Matthias J. Kannwischer <[email protected]>
The poly_uniform_gamma1 function is the last one using the stream256
instead of the standard keccak APIs.
This commit refactors it to be in-line with the batched implementation as
well as the xof128 function.

The initialization function is removed and inlined into poly_uniform_gamma1.

The CBMC proof is adjusted accordingly.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
Some Keccak implementations (e.g., liboqs) may dynamically allocate the Keccak
state in the _init() function. We, hence, need an explicit _release() function
to potentially free this memory.
In mldsa-native this is a no-op (or it zeros out the state once we have
secure stack zeroziation).

This commit adds the _release functions for both shake128 and shake256.
According mld_xof{128,256}_release macros are added to symmetric.h.
Function calls to the _release functions are added in all places that use the
mld_xof APIs.

CBMC proofs are amended for those functions to in-line the empty release
functions.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
@mkannwischer mkannwischer force-pushed the poly_uniform_gamma1_4x branch from 142be6c to 1f90e23 Compare May 18, 2025 05:09
@mkannwischer mkannwischer requested a review from hanno-becker May 18, 2025 05:10
@hanno-becker hanno-becker merged commit de0522a into main May 18, 2025
77 checks passed
@hanno-becker hanno-becker deleted the poly_uniform_gamma1_4x branch May 18, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add poly_uniform_gamma1_4x
2 participants