indutny / bn.js

BigNum in pure javascript
MIT License
1.19k stars 150 forks source link

Incorrect mod result with mont reduction #256

Open SurienDG opened 3 years ago

SurienDG commented 3 years ago

I did

let red10 = BN.mont(new BN(10, 10));
let red_1 = new BN(104, 10).toRed(red10);
red_1 = red_1.fromRed();
console.log("red_1: " + red_1.toString());

This outputs

red_1: 2

Which is incorrect. It should output red_1: 4 (since 104 mod 10 = 4). I do get the correct if I use BN.red instead if BN.mont

SurienDG commented 3 years ago

Nevermind I read #193 but perhaps we could get some better documentation about this?