-
Notifications
You must be signed in to change notification settings - Fork 507
Open
Description
In short weierstrass curves, the member curve.n is missing _move from its prototype:
var BN = require('bn.js')
var EC = require('elliptic')
var curve = new EC.ec('secp256k1'); // e.g.---same problem for other curves
curve.n._move // undefined
new BN(curve.n.toString(16), 16)._move // definedIf n is then used to initialize a reduction context, calling redNeg causes _move to drop, which leads to crashes:
var q = BN.red(curve.n) // bad
var temp = new BN(1234).toRed(q)
temp.redNeg()._move // undefined
temp.redNeg().redMul(temp) // crashesand yet,
var q = BN.red(new BN(curve.n.toString(16), 16))
var temp = new BN(1234).toRed(q)
temp.redNeg()._move // now defined
temp.redNeg().redMul(temp) // this worksHere is the stacktrace:
TypeError: a.umod(...)._forceRed(...)._move is not a function
at Red.imod (/Users/benediamond/node_modules/bn.js/lib/bn.js:3190:36)
at Red.mul (/Users/benediamond/node_modules/bn.js/lib/bn.js:3254:17)
at BN.redMul (/Users/benediamond/node_modules/elliptic/node_modules/bn.js/lib/bn.js:2883:21)This issue only happens when bn.js version v5.0.0 is used! elliptic version is 6.5.0. @fanatid
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels