@@ -3,13 +3,16 @@ import { getParams } from './params'
33import { SRPError } from './SRPError'
44import { SRPInt } from './SRPInt'
55import type { Ephemeral , HashAlgorithm , PrimeGroup , Session } from './types'
6- import { bufferToHex , hexToBuffer } from './utils'
6+ import { bufferToHex , constantTimeEqualHex , hexToBuffer } from './utils'
77
88export const createSRPClient = (
99 hashAlgorithm : HashAlgorithm ,
1010 primeGroup : PrimeGroup ,
1111) => {
12- const { N, g, k, H, PAD , hashBytes } = getParams ( hashAlgorithm , primeGroup )
12+ const { N, g, k, H, PAD , hashBytes, ephemeralSecretBytes } = getParams (
13+ hashAlgorithm ,
14+ primeGroup ,
15+ )
1316
1417 return {
1518 generateSalt : ( ) : string => {
@@ -53,7 +56,7 @@ export const createSRPClient = (
5356 } ,
5457
5558 generateEphemeral : ( ) : Ephemeral => {
56- const a = SRPInt . getRandom ( hashBytes )
59+ const a = SRPInt . getRandom ( ephemeralSecretBytes )
5760
5861 // A = g^a (a = random number)
5962 const A = g . modPow ( a , N )
@@ -115,10 +118,9 @@ export const createSRPClient = (
115118 const K = SRPInt . fromHex ( clientSession . key ) // Shared, strong session key
116119
117120 // H(A, M, K)
118- const expected = await H ( A , M , K )
119- const actual = SRPInt . fromHex ( serverSessionProof )
121+ const expected = ( await H ( A , M , K ) ) . toHex ( )
120122
121- if ( ! actual . equals ( expected ) ) {
123+ if ( ! constantTimeEqualHex ( serverSessionProof , expected ) ) {
122124 throw new SRPError ( 'server' , 'InvalidSessionProof' )
123125 }
124126 } ,
0 commit comments