sjcl icon indicating copy to clipboard operation
sjcl copied to clipboard

bn.inverseMod does not support negative numbers

Open armfazh opened this issue 5 years ago • 0 comments

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.

armfazh avatar Dec 05 '18 19:12 armfazh