From a472c1beeedb15a28aa40c1ad6e19570fb81a350 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Fri, 9 Mar 2018 17:06:37 +0300 Subject: [PATCH] bn: add method move --- lib/bn.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; };