mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-11 04:48:39 -04:00
add bn powermod and mulmod
This commit is contained in:
parent
89905acb59
commit
2bbda850b1
3 changed files with 93 additions and 0 deletions
15
core/bn.js
15
core/bn.js
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue