diff --git a/lib/bn.js b/lib/bn.js index fe5c726..33f7c24 100644 --- a/lib/bn.js +++ b/lib/bn.js @@ -327,6 +327,13 @@ dest.red = this.red; }; + BN.prototype.move = function move (dest) { + dest.words = this.words; + dest.length = this.length; + dest.negative = this.negative; + dest.red = this.red; + }; + BN.prototype.clone = function clone () { var r = new BN(null); this.copy(r); @@ -3170,8 +3177,7 @@ Red.prototype.imod = function imod (a) { if (this.prime) return this.prime.ireduce(a)._forceRed(this); - var mod = a.umod(this.m)._forceRed(this); - if (mod !== a) mod.copy(a); + a.umod(this.m)._forceRed(this).move(a); return a; };