add bn powermod and mulmod

This commit is contained in:
Quinn Slack 2011-04-19 05:13:45 -07:00
parent 89905acb59
commit 2bbda850b1
3 changed files with 93 additions and 0 deletions

View file

@ -275,6 +275,21 @@ sjcl.bn.prototype = {
return out;
},
mulmod: function(x, N) {
return this.mod(N).mul(x.mod(N)).mod(N);
},
powermod: function(x, N) {
var result = new sjcl.bn(1), a = new sjcl.bn(this), k = new sjcl.bn(x);
while (true) {
if (k.limbs[0] & 1) { result = result.mulmod(a, N); }
k.halveM();
if (k.equals(0)) { break; }
a = a.mulmod(a, N);
}
return result.normalize().reduce();
},
trim: function() {
var l = this.limbs, p;
do {