sjcl
sjcl copied to clipboard
bn.inverseMod does not support negative numbers
This is a minimal example showing that inverseMod
cannot handle negative numbers.
const sjcl = require('./sjcl.js');
function main()
{
const p = new sjcl.bn(7);
let x = new sjcl.bn(-2);
// Fix:
// x = x.mod(p)
let y = x.inverseMod(p)
console.log("x : ",x.toString())
console.log("y : ",y.toString())
}
main()
An immediate fix is to reduce modulo p before calling this function.