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

In-place operation in a reduction context is not reduced. #177

Closed
mahrud opened this issue Feb 15, 2018 · 2 comments
Closed

In-place operation in a reduction context is not reduced. #177

mahrud opened this issue Feb 15, 2018 · 2 comments
Labels

Comments

@mahrud
Copy link

mahrud commented Feb 15, 2018

Seems like in-place operations are not reducing the result before changing the host object. Example:

var BN=require('bn.js')
red = new BN.red(new BN(13))
a = new BN(2).toRed(red)
b = new BN(7).toRed(red)
x = a.redIMul(b)

red.m // <BN: d>
x // <BN-R: 1>
x.cmp(red.m) // correct
a // <BN-R: e>
a.cmp(red.m) // incorrect

Note that a is still in a reduction context, but its value is larger than the modulus!

@fanatid
Copy link
Collaborator

fanatid commented Feb 16, 2018

This happens because Red#imod is not actually imod... :(

bn.js/lib/bn.js

Line 3172 in 98ac84e

return a.umod(this.m)._forceRed(this);

@dcousens
Copy link
Contributor

dcousens commented Jun 6, 2018

See #178

@dcousens dcousens closed this as completed Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants