1
1
const crypto = require ( 'crypto' ) ,
2
- bigint = require ( 'bigint ' ) ,
2
+ bignum = require ( 'bignum ' ) ,
3
3
assert = require ( 'assert' ) ,
4
4
ALG = 'sha256' ;
5
5
6
- const zero = bigint ( 0 ) ;
6
+ const zero = bignum ( 0 ) ;
7
7
8
8
/*
9
9
* If a conversion is explicitly specified with the operator PAD(),
@@ -12,8 +12,8 @@ const zero = bigint(0);
12
12
* length equals the implicitly-converted length of N.
13
13
*
14
14
* params:
15
- * n (bigint ) Number to pad
16
- * N (bigint ) N
15
+ * n (bignum ) Number to pad
16
+ * N (bignum ) N
17
17
*
18
18
* returns: buffer
19
19
*/
@@ -55,7 +55,7 @@ var getx = exports.getx = function getx(s, I, P, alg) {
55
55
. update ( s )
56
56
. update ( hashIP )
57
57
. digest ( 'hex' ) ;
58
- return bigint ( hashX , 16 ) ;
58
+ return bignum ( hashX , 16 ) ;
59
59
} ;
60
60
61
61
/*
@@ -72,11 +72,11 @@ var getx = exports.getx = function getx(s, I, P, alg) {
72
72
* s (buffer) salt
73
73
* I (buffer) user identity
74
74
* P (buffer) user password
75
- * N (bigint ) group parameter N
76
- * g (bigint ) generator
75
+ * N (bignum ) group parameter N
76
+ * g (bignum ) generator
77
77
* alg (string) default = ALG
78
78
*
79
- * returns: bigint
79
+ * returns: bignum
80
80
*/
81
81
var getv = exports . getv = function getv ( s , I , P , N , g , alg ) {
82
82
alg = alg || ALG ;
@@ -87,15 +87,15 @@ var getv = exports.getv = function getv(s, I, P, N, g, alg) {
87
87
* calculate the SRP-6 multiplier
88
88
*
89
89
* params:
90
- * N (bigint ) group parameter N
91
- * g (bigint ) generator
90
+ * N (bignum ) group parameter N
91
+ * g (bignum ) generator
92
92
* alg (string) default = ALG
93
93
*
94
- * returns: bigint
94
+ * returns: bignum
95
95
*/
96
96
var getk = exports . getk = function getk ( N , g , alg ) {
97
97
alg = alg || ALG ;
98
- return bigint (
98
+ return bignum (
99
99
crypto
100
100
. createHash ( alg )
101
101
. update ( N . toBuffer ( ) )
@@ -110,7 +110,7 @@ var getk = exports.getk = function getk(N, g, alg) {
110
110
* bytes (int) length of key (default=32)
111
111
* callback (func) function to call with err,key
112
112
*
113
- * returns: bigint
113
+ * returns: bignum
114
114
*/
115
115
var genKey = exports . genKey = function genKey ( bytes , callback ) {
116
116
// bytes is optional
@@ -123,7 +123,7 @@ var genKey = exports.genKey = function genKey(bytes, callback) {
123
123
}
124
124
crypto . randomBytes ( bytes , function ( err , buf ) {
125
125
if ( err ) return callback ( err ) ;
126
- return callback ( null , bigint . fromBuffer ( buf ) ) ;
126
+ return callback ( null , bignum . fromBuffer ( buf ) ) ;
127
127
} ) ;
128
128
} ;
129
129
@@ -136,8 +136,8 @@ var genKey = exports.genKey = function genKey(bytes, callback) {
136
136
* Note: as the tests imply, the entire expression is mod N.
137
137
*
138
138
* params:
139
- * v (bigint ) verifier
140
- * g (bigint ) generator
139
+ * v (bignum ) verifier
140
+ * g (bignum ) generator
141
141
*/
142
142
var getB = exports . getB = function getB ( v , g , b , N , alg ) {
143
143
alg = alg || ALG ;
@@ -164,13 +164,13 @@ var getA = exports.getA = function getA(g, a, N) {
164
164
* Random scrambling parameter u
165
165
*
166
166
* params:
167
- * A (bigint ) client ephemeral public key
168
- * B (bigint ) server ephemeral public key
169
- * N (bigint ) group parameter N
167
+ * A (bignum ) client ephemeral public key
168
+ * B (bignum ) server ephemeral public key
169
+ * N (bignum ) group parameter N
170
170
*/
171
171
var getu = exports . getu = function getu ( A , B , N , alg ) {
172
172
alg = alg || ALG ;
173
- return bigint (
173
+ return bignum (
174
174
crypto
175
175
. createHash ( alg )
176
176
. update ( pad ( A , N ) )
@@ -185,12 +185,12 @@ var getu = exports.getu = function getu(A, B, N, alg) {
185
185
* s (buffer) salt (read from server)
186
186
* I (buffer) user identity (read from user)
187
187
* P (buffer) user password (read from user)
188
- * N (bigint ) group parameter N (known in advance)
189
- * g (bigint ) generator for N (known in advance)
190
- * a (bigint ) ephemeral private key (generated for session)
191
- * B (bigint ) server ephemeral public key (read from server)
188
+ * N (bignum ) group parameter N (known in advance)
189
+ * g (bignum ) generator for N (known in advance)
190
+ * a (bignum ) ephemeral private key (generated for session)
191
+ * B (bignum ) server ephemeral public key (read from server)
192
192
*
193
- * returns: bigint
193
+ * returns: bignum
194
194
*/
195
195
var client_getS = exports . client_getS = function client_getS ( s , I , P , N , g , a , B , alg ) {
196
196
if ( zero . ge ( B ) || N . le ( B ) )
@@ -206,14 +206,14 @@ var client_getS = exports.client_getS = function client_getS(s, I, P, N, g, a, B
206
206
* The TLS premastersecret as calculated by the server
207
207
*
208
208
* params:
209
- * s (bigint ) salt (stored on server)
210
- * v (bigint ) verifier (stored on server)
211
- * N (bigint ) group parameter N (known in advance)
212
- * g (bigint ) generator for N (known in advance)
213
- * A (bigint ) ephemeral client public key (read from client)
214
- * b (bigint ) server ephemeral private key (generated for session)
215
- *
216
- * returns: bigint
209
+ * s (bignum ) salt (stored on server)
210
+ * v (bignum ) verifier (stored on server)
211
+ * N (bignum ) group parameter N (known in advance)
212
+ * g (bignum ) generator for N (known in advance)
213
+ * A (bignum ) ephemeral client public key (read from client)
214
+ * b (bignum ) server ephemeral private key (generated for session)
215
+ *
216
+ * returns: bignum
217
217
*/
218
218
var server_getS = exports . server_getS = function server_getS ( s , v , N , g , A , b , alg ) {
219
219
if ( zero . ge ( A ) || N . le ( A ) )
@@ -228,14 +228,14 @@ var server_getS = exports.server_getS = function server_getS(s, v, N, g, A, b, a
228
228
* Compute the shared session key K from S
229
229
*
230
230
* params:
231
- * S (bigint ) Session key
231
+ * S (bignum ) Session key
232
232
*
233
- * returns: bigint
233
+ * returns: bignum
234
234
*/
235
235
var getK = exports . getK = function getK ( S , N , alg ) {
236
236
alg = alg || ALG ;
237
237
var S_pad = new Buffer ( pad ( S , N ) ) ;
238
- return bigint (
238
+ return bignum (
239
239
crypto
240
240
. createHash ( alg )
241
241
. update ( S_pad )
0 commit comments