1
0
mirror of https://github.com/danog/fast-srp.git synced 2024-11-26 20:04:49 +01:00

Fix input validation for server_getS and client_getS

This commit is contained in:
Supereg 2020-04-12 07:22:55 +02:00
parent 98e7ed7233
commit aeb6c1e42b
No known key found for this signature in database
GPG Key ID: 2F08948C5653D720

View File

@ -233,7 +233,7 @@ function client_getS(params, k_num, x_num, a_num, B_num, u_num) {
assertIsBigInteger(a_num); assertIsBigInteger(a_num);
assertIsBigInteger(B_num); assertIsBigInteger(B_num);
assertIsBigInteger(u_num); assertIsBigInteger(u_num);
if((zero.compareTo(B_num) > 0) && (N.compareTo(B_num) < 0)) if((zero.compareTo(B_num) < 0) && (N.compareTo(B_num) > 0))
throw new Error("invalid server-supplied 'B', must be 1..N-1"); 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); 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);
return S_num.toBuffer(true); return S_num.toBuffer(true);
@ -256,7 +256,7 @@ function server_getS(params, v_num, A_num, b_num, u_num) {
assertIsBigInteger(A_num); assertIsBigInteger(A_num);
assertIsBigInteger(b_num); assertIsBigInteger(b_num);
assertIsBigInteger(u_num); assertIsBigInteger(u_num);
if((zero.compareTo(A_num) > 0) && (N.compareTo(A_num) < 0)) if((zero.compareTo(A_num) < 0) && (N.compareTo(A_num) > 0))
throw new Error("invalid client-supplied 'A', must be 1..N-1"); throw new Error("invalid client-supplied 'A', must be 1..N-1");
var S_num = A_num.multiply(v_num.modPow(u_num, params.N)).modPow(b_num, params.N).mod(params.N); var S_num = A_num.multiply(v_num.modPow(u_num, params.N)).modPow(b_num, params.N).mod(params.N);
return S_num.toBuffer(true); return S_num.toBuffer(true);