From 85cfc7d81bc902f35460804bb59de2870217c511 Mon Sep 17 00:00:00 2001 From: Zarmack Tanen Date: Thu, 10 Sep 2015 11:49:44 +0200 Subject: [PATCH] Optimizing code --- lib/srp.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/srp.js b/lib/srp.js index 1c4b6b7..a77de86 100644 --- a/lib/srp.js +++ b/lib/srp.js @@ -231,8 +231,7 @@ function getu(params, A, B) { var u_buf = crypto.createHash(params.hash) .update(A).update(B) .digest(); -//! return bignum.fromBuffer(u_buf); - return(new BigInteger(u_buf)); + return(new BigInteger(u_buf)); }; /* @@ -255,8 +254,6 @@ function client_getS(params, k_num, x_num, a_num, B_num, u_num) { assertIsBigInteger(a_num); assertIsBigInteger(B_num); assertIsBigInteger(u_num); -// var g = params.g; -// var N = params.N; if((zero.compareTo(B_num) > 0) && (N.compareTo(B_num) < 0)) throw new Error("invalid server-supplied 'B', must be 1..N-1"); var S_num = B_num.subtract(k_num.multiply(params.g.modPow(x_num, params.N))).modPow(a_num.add(u_num.multiply(x_num)), params.N).mod(params.N); @@ -281,12 +278,10 @@ function server_getS(params, v_num, A_num, b_num, u_num) { assertIsBigInteger(A_num); assertIsBigInteger(b_num); assertIsBigInteger(u_num); - var N = params.N; //! if (zero.greater(A_num) || N.lesser(A_num)) if((zero.compareTo(A_num) > 0) && (N.compareTo(A_num) < 0)) throw new Error("invalid client-supplied 'A', must be 1..N-1"); -//* var S_num = A_num.mul(v_num.powm(u_num, N)).powm(b_num, N).mod(N); - var S_num = A_num.multiply(v_num.modPow(u_num, N)).modPow(b_num, N).mod(N); + var S_num = A_num.multiply(v_num.modPow(u_num, params.N)).modPow(b_num, params.N).mod(params.N); return padToN(S_num, params); };