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

Use full Montgomery mul for BoxedResidue::{mul, square} #442

Merged
merged 1 commit into from
Dec 16, 2023

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Dec 16, 2023

Previously "almost Montgomery multiplications" were used which return a result which is only reduced modulo the bit size of the modulus, but may still equal or exceed the modulus.

This commit goes back to using a multiply followed by a full Montgomery reduction, and adds more asserts that the result is fully reduced. This incurs a performance hit, but AMM is likely "unsafe" to use outside of this crate unless we decide to fully encapsulate the inner representation of *Residue types.

Note that this does not ensure the output of modpow is fully reduced, which is left to be fixed in a followup.

This commit includes a regression test from the issue where this was reported (#441) and additionally adds some general proptests for BoxedResidue::square.

Closes #441.

Previously "almost Montgomery multiplications" were used which return a
result which is only reduced modulo the bit size of the modulus, but may
still equal or exceed the modulus.

This commit goes back to using a multiply followed by a full Montgomery
reduction, and adds more asserts that the result is fully reduced.
This incurs a performance hit, but AMM is likely "unsafe" to use outside
of this crate unless we decide to fully encapsulate the inner
representation of `*Residue` types.

Note that this does not ensure the output of modpow is fully reduced,
which is left to be fixed in a followup.

This commit includes a regression test from the issue where this was
reported (#441) and additionally adds some general proptests for
`BoxedResidue::square`.
@tarcieri tarcieri merged commit 5b00a57 into master Dec 16, 2023
16 checks passed
@tarcieri tarcieri deleted the boxed-residue/use-full-montgomery-multiplications branch December 16, 2023 17:22
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.

BoxedResidue square error
1 participant