-
Notifications
You must be signed in to change notification settings - Fork 56
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
BoxedResidue square error #441
Comments
Looks like I looked through the paper, and it claims that (in Section 4):
I ran some tests and it seems that it is true for any modulus. @tarcieri, any comments? Also, should we use the same algorithm for |
Yeah, I've been worried about this. https://github.com/rust-num/num-bigint/blob/2cea7f4/src/biguint/monty.rs#L207-L221 It also mentions golang/go#13907 which notes AMM reduces to the bit length but not the modulus. For the general purpose (Also for squarings in particular I need to revisit #383)
Possibly for modpow, though we'll need to investigate whether AMM actually makes sense for multiply/square in the public API performance-wise. It's something I haven't prioritized for a few reasons, namely we'd like to investigate ASM optimizations for it which would clash with the |
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`.
#442 fixes this by using full Montgomery reductions for Additionally modpow needs to add a final modular reduction similar to |
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`.
#443 is the fix for modpow |
BoxedResidue::square()
sometimes producesBoxedResidue
whosemontgomery_form
is greater than itsmodulus
, which will breakBoxedResidue::add
andBoxedResidue::sub
.Here is some code to reproduce the error:
The text was updated successfully, but these errors were encountered: