Skip to content

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

@mahrud

Description

@mahrud

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions