Skip to content

Commit

Permalink
fix: regenerate if the random value is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
caru-ini committed Jul 2, 2024
1 parent dd81155 commit a939e17
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/domain/user/service/srp/calcSrpB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ export const calculateSrpB = (
b: string;
B: string;
} => {
const b = crypto.randomBytes(32);
const bInt = fromBuffer(b);
let BInt = BigInteger.ZERO;
let b = Buffer.from([0]);
const vInt = new BigInteger(v, 16);

while (BInt === BigInteger.ZERO) {
b = crypto.randomBytes(32);
const bInt = fromBuffer(b);
BInt = multiplierParam.multiply(vInt).add(g.modPow(bInt, N)).mod(N);
}

// kv + g^b
const B = toBuffer(multiplierParam.multiply(vInt).add(g.modPow(bInt, N)).mod(N));
const B = toBuffer(BInt);
return { b: b.toString('hex'), B: B.toString('hex') };
};

0 comments on commit a939e17

Please sign in to comment.