Skip to content
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

ML-DSA: Add rejection sampling functions #195

Merged
merged 8 commits into from
Dec 2, 2024
Merged

Conversation

marsella
Copy link
Contributor

@marsella marsella commented Nov 21, 2024

Closes #182.

Adds a few functions for rejection sampling.

I compared some of these to the versions in the IPD. The hash functions are the same. The CoeffFrom... functions are the same. RejBoundedPoly matches. The seed for RejNTTPoly is a different size and I tried to compare them, but it didn't work. I feel pretty confident about my implementation, though, so I'm willing to wait to see if we get an error at a higher level.

Base automatically changed from 180-start-final-mldsa to master November 21, 2024 18:44
@marsella marsella marked this pull request as ready for review November 21, 2024 19:08
@marsella marsella force-pushed the 182-rejection-sampling branch from b659790 to 247fe0d Compare November 21, 2024 19:08
type Byte = [8]

/**
* Ring defined as the product of 255 elements in `Z q` used for NTT.
Copy link
Contributor

Choose a reason for hiding this comment

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

The array is still 256 for this correct since it is storing X^^0 as well? I get that this only goes up to X^^255 is that what you are implying by this being 255?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh you're right, that was just a mistake on my part. The definition on page 6 is $$\prod_{j=0}^{255} \mathbb Z_q$$ and I misparsed it.

// Step 7 - 9. The recursive call here replaces the `while` loop.
a_hat' = case a_hat_j of
Some aj -> [aj] # (sample ctx)
None -> sample ctx
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if it is worth mentioning that the spec just overwrites this part of the "stream" on this case hence why it is safe to just skip writing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, this was confusing when I came back to it. Added some docs.

Copy link
Contributor

@mccleeary-galois mccleeary-galois left a comment

Choose a reason for hiding this comment

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

LGTM

@marsella marsella force-pushed the 182-rejection-sampling branch from 247fe0d to 3c3d2e6 Compare December 2, 2024 16:16
@marsella marsella merged commit d765520 into master Dec 2, 2024
2 checks passed
@marsella marsella deleted the 182-rejection-sampling branch December 2, 2024 16:19
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.

ML-DSA: Add NTT rejection sampling functions
2 participants