@@ -119,7 +119,7 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
119
119
120
120
//console.log("js hash:"+hash)
121
121
//console.log("js x before modN "+this.fromHex(hash));
122
- this . x = this . fromHex ( hash ) . mod ( this . N ( ) ) ;
122
+ this . x = this . fromHex ( hash ) . mod ( this . N ) ;
123
123
return this . x ;
124
124
} ;
125
125
@@ -149,32 +149,34 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
149
149
this . check ( B , "B" ) ;
150
150
151
151
var exp = u . multiply ( x ) . add ( a ) ;
152
- var tmp = this . g ( ) . modPow ( x , this . N ( ) ) . multiply ( k ) ;
153
- return B . subtract ( tmp ) . modPow ( exp , this . N ( ) ) ;
152
+ var tmp = this . g . modPow ( x , this . N ) . multiply ( k ) ;
153
+ return B . subtract ( tmp ) . modPow ( exp , this . N ) ;
154
154
} ;
155
155
}
156
156
157
157
// public helper
158
158
SRP6JavascriptClientSession . prototype . toHex = function ( n ) {
159
159
"use strict" ;
160
+ if ( n === null || n === undefined || typeof n . toString !== 'function' ) {
161
+ throw new Error ( "Invalid parameter for hex conversion: " + typeof n ) ;
162
+ }
160
163
return n . toString ( 16 ) ;
161
164
} ;
162
165
163
166
// public helper
164
- /* jshint ignore:start */
165
167
SRP6JavascriptClientSession . prototype . fromHex = function ( s ) {
166
168
"use strict" ;
169
+ if ( s === null || s === undefined || typeof s !== 'string' ) {
170
+ throw new Error ( "Invalid hex string for BigInteger conversion: " + typeof s ) ;
171
+ }
167
172
return new BigInteger ( "" + s , 16 ) ; // jdk1.7 rhino requires string concat
168
173
} ;
169
- /* jshint ignore:end */
170
174
171
175
// public helper to hide BigInteger from the linter
172
- /* jshint ignore:start */
173
176
SRP6JavascriptClientSession . prototype . BigInteger = function ( string , radix ) {
174
177
"use strict" ;
175
178
return new BigInteger ( "" + string , radix ) ; // jdk1.7 rhino requires string concat
176
179
} ;
177
- /* jshint ignore:end */
178
180
179
181
180
182
// public getter of the current workflow state.
@@ -224,9 +226,7 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
224
226
"use strict" ;
225
227
var s = null ;
226
228
227
- /* jshint ignore:start */
228
229
s = randomStrings . hex ( 32 ) ; // 16 bytes
229
- /* jshint ignore:end */
230
230
231
231
// if you invoke without passing the string parameter the '+' operator uses 'undefined' so no nullpointer risk here
232
232
var ss = this . H ( ( new Date ( ) ) + ':' + opionalServerSalt + ':' + s ) ;
@@ -249,7 +249,7 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
249
249
// no need to check the parameters as generateX will do this
250
250
var x = this . generateX ( salt , identity , password ) ;
251
251
//console.log("js x: "+this.toHex(x));
252
- this . v = this . g ( ) . modPow ( x , this . N ( ) ) ;
252
+ this . v = this . g . modPow ( x , this . N ) ;
253
253
//console.log("js v: "+this.toHex(this.v));
254
254
return this . toHex ( this . v ) ;
255
255
} ;
@@ -299,7 +299,6 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
299
299
//console.log("SRP6JavascriptClientSession.prototype.computeU");
300
300
this . check ( Astr , "Astr" ) ;
301
301
this . check ( Bstr , "Bstr" ) ;
302
- /* jshint ignore:start */
303
302
var output = this . H ( Astr + Bstr ) ;
304
303
//console.log("js raw u:"+output);
305
304
var u = new BigInteger ( "" + output , 16 ) ;
@@ -308,16 +307,13 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
308
307
throw new Error ( "SRP6Exception bad shared public value 'u' as u==0" ) ;
309
308
}
310
309
return u ;
311
- /* jshint ignore:end */
312
310
} ;
313
311
314
312
SRP6JavascriptClientSession . prototype . random16byteHex = function ( ) {
315
313
"use strict" ;
316
314
317
315
var r1 = null ;
318
- /* jshint ignore:start */
319
316
r1 = random16byteHex . random ( ) ;
320
- /* jshint ignore:end */
321
317
return r1 ;
322
318
} ;
323
319
@@ -330,13 +326,14 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
330
326
* to the generated random number.
331
327
* @param N The safe prime.
332
328
*/
333
- SRP6JavascriptClientSession . prototype . randomA = function ( N ) {
329
+ SRP6JavascriptClientSession . prototype . randomA = function ( ) {
334
330
"use strict" ;
335
331
336
- //console.log("N:"+N);
332
+ //console.log("N:"+this.N);
333
+
337
334
338
335
// our ideal number of random bits to use for `a` as long as its bigger than 256 bits
339
- var hexLength = this . toHex ( N ) . length ;
336
+ var hexLength = this . toHex ( this . N ) . length ;
340
337
341
338
var ZERO = this . BigInteger ( "0" , 10 ) ;
342
339
var ONE = this . BigInteger ( "1" , 10 ) ;
@@ -366,7 +363,7 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
366
363
// this protected against a buggy browser random number generated generating a constant value
367
364
// we mod(N) to wrap to the range [0,N) then loop if we get 0 to give [1,N)
368
365
// mod(N) is broken due to buggy library code so we workaround with modPow(1,N)
369
- r = ( oneTimeBi . add ( rBi ) ) . modPow ( ONE , N ) ;
366
+ r = ( oneTimeBi . add ( rBi ) ) . modPow ( ONE , this . N ) ;
370
367
}
371
368
372
369
//console.log("r:"+r);
@@ -413,11 +410,9 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
413
410
414
411
var ZERO = null ;
415
412
416
- /* jshint ignore:start */
417
413
ZERO = BigInteger . ZERO ;
418
- /* jshint ignore:end */
419
414
420
- if ( this . B . mod ( this . N ( ) ) . equals ( ZERO ) ) {
415
+ if ( this . B . mod ( this . N ) . equals ( ZERO ) ) {
421
416
throw new Error ( "SRP6Exception bad server public value 'B' as B == 0 (mod N)" ) ;
422
417
}
423
418
@@ -432,11 +427,11 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
432
427
433
428
//console.log("N:"+this.toHex(this.N).toString(16));
434
429
435
- this . a = this . randomA ( this . N ) ;
430
+ this . a = this . randomA ( ) ;
436
431
437
432
//console.log("a:" + this.toHex(this.a));
438
433
439
- this . A = this . g ( ) . modPow ( this . a , this . N ( ) ) ;
434
+ this . A = this . g . modPow ( this . a , this . N ) ;
440
435
//console.log("A:" + this.toHex(this.A));
441
436
this . check ( this . A , "A" ) ;
442
437
@@ -531,13 +526,9 @@ function srpClientFactory (N_base10, g_base10, k_base16) {
531
526
532
527
SRP6JavascriptClientSessionSHA256 . prototype = new SRP6JavascriptClientSession ( ) ;
533
528
534
- SRP6JavascriptClientSessionSHA256 . prototype . N = function ( ) {
535
- return new BigInteger ( N_base10 , 10 ) ;
536
- }
529
+ SRP6JavascriptClientSessionSHA256 . prototype . N = new BigInteger ( N_base10 , 10 ) ;
537
530
538
- SRP6JavascriptClientSessionSHA256 . prototype . g = function ( ) {
539
- return new BigInteger ( g_base10 , 10 ) ;
540
- }
531
+ SRP6JavascriptClientSessionSHA256 . prototype . g = new BigInteger ( g_base10 , 10 ) ;
541
532
542
533
SRP6JavascriptClientSessionSHA256 . prototype . H = function ( x ) {
543
534
return SHA256 ( x ) . toString ( ) . toLowerCase ( ) ;
0 commit comments