@@ -11,7 +11,7 @@ var crypto = require('crypto');
11
11
12
12
// Test Diffie-Hellman with two parties sharing a secret,
13
13
// using various encodings as we go along
14
- var dh1 = crypto . createDiffieHellman ( 256 ) ;
14
+ var dh1 = crypto . createDiffieHellman ( 1024 ) ;
15
15
var p1 = dh1 . getPrime ( 'buffer' ) ;
16
16
var dh2 = crypto . createDiffieHellman ( p1 , 'buffer' ) ;
17
17
var key1 = dh1 . generateKeys ( ) ;
@@ -82,9 +82,11 @@ assert.equal(aSecret, bSecret);
82
82
assert . equal ( alice . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
83
83
assert . equal ( bob . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
84
84
85
- // Ensure specific generator (buffer) works as expected.
86
- var modp1 = crypto . createDiffieHellmanGroup ( 'modp1' ) ;
87
- var modp1buf = new Buffer ( [
85
+ /* Ensure specific generator (buffer) works as expected.
86
+ * The values below (modp2/modp2buf) are for a 1024 bits long prime from
87
+ * RFC 2412 E.2, see https://tools.ietf.org/html/rfc2412. */
88
+ var modp2 = crypto . createDiffieHellmanGroup ( 'modp2' ) ;
89
+ var modp2buf = new Buffer ( [
88
90
0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xc9 , 0x0f ,
89
91
0xda , 0xa2 , 0x21 , 0x68 , 0xc2 , 0x34 , 0xc4 , 0xc6 , 0x62 , 0x8b ,
90
92
0x80 , 0xdc , 0x1c , 0xd1 , 0x29 , 0x02 , 0x4e , 0x08 , 0x8a , 0x67 ,
@@ -93,47 +95,50 @@ var modp1buf = new Buffer([
93
95
0x19 , 0xb3 , 0xcd , 0x3a , 0x43 , 0x1b , 0x30 , 0x2b , 0x0a , 0x6d ,
94
96
0xf2 , 0x5f , 0x14 , 0x37 , 0x4f , 0xe1 , 0x35 , 0x6d , 0x6d , 0x51 ,
95
97
0xc2 , 0x45 , 0xe4 , 0x85 , 0xb5 , 0x76 , 0x62 , 0x5e , 0x7e , 0xc6 ,
96
- 0xf4 , 0x4c , 0x42 , 0xe9 , 0xa6 , 0x3a , 0x36 , 0x20 , 0xff , 0xff ,
97
- 0xff , 0xff , 0xff , 0xff , 0xff , 0xff
98
+ 0xf4 , 0x4c , 0x42 , 0xe9 , 0xa6 , 0x37 , 0xed , 0x6b , 0x0b , 0xff ,
99
+ 0x5c , 0xb6 , 0xf4 , 0x06 , 0xb7 , 0xed , 0xee , 0x38 , 0x6b , 0xfb ,
100
+ 0x5a , 0x89 , 0x9f , 0xa5 , 0xae , 0x9f , 0x24 , 0x11 , 0x7c , 0x4b ,
101
+ 0x1f , 0xe6 , 0x49 , 0x28 , 0x66 , 0x51 , 0xec , 0xe6 , 0x53 , 0x81 ,
102
+ 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff , 0xff
98
103
] ) ;
99
- var exmodp1 = crypto . createDiffieHellman ( modp1buf , new Buffer ( [ 2 ] ) ) ;
100
- modp1 . generateKeys ( ) ;
101
- exmodp1 . generateKeys ( ) ;
102
- var modp1Secret = modp1 . computeSecret ( exmodp1 . getPublicKey ( ) ) . toString ( 'hex' ) ;
103
- var exmodp1Secret = exmodp1 . computeSecret ( modp1 . getPublicKey ( ) ) . toString ( 'hex' ) ;
104
- assert . equal ( modp1Secret , exmodp1Secret ) ;
105
- assert . equal ( modp1 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
106
- assert . equal ( exmodp1 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
104
+ var exmodp2 = crypto . createDiffieHellman ( modp2buf , new Buffer ( [ 2 ] ) ) ;
105
+ modp2 . generateKeys ( ) ;
106
+ exmodp2 . generateKeys ( ) ;
107
+ var modp2Secret = modp2 . computeSecret ( exmodp2 . getPublicKey ( ) ) . toString ( 'hex' ) ;
108
+ var exmodp2Secret = exmodp2 . computeSecret ( modp2 . getPublicKey ( ) ) . toString ( 'hex' ) ;
109
+ assert . equal ( modp2Secret , exmodp2Secret ) ;
110
+ assert . equal ( modp2 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
111
+ assert . equal ( exmodp2 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
107
112
108
113
109
114
// Ensure specific generator (string with encoding) works as expected.
110
- var exmodp1_2 = crypto . createDiffieHellman ( modp1buf , '02' , 'hex' ) ;
111
- exmodp1_2 . generateKeys ( ) ;
112
- modp1Secret = modp1 . computeSecret ( exmodp1_2 . getPublicKey ( ) ) . toString ( 'hex' ) ;
113
- var exmodp1_2Secret = exmodp1_2 . computeSecret ( modp1 . getPublicKey ( ) )
115
+ var exmodp2_2 = crypto . createDiffieHellman ( modp2buf , '02' , 'hex' ) ;
116
+ exmodp2_2 . generateKeys ( ) ;
117
+ modp2Secret = modp2 . computeSecret ( exmodp2_2 . getPublicKey ( ) ) . toString ( 'hex' ) ;
118
+ var exmodp2_2Secret = exmodp2_2 . computeSecret ( modp2 . getPublicKey ( ) )
114
119
. toString ( 'hex' ) ;
115
- assert . equal ( modp1Secret , exmodp1_2Secret ) ;
116
- assert . equal ( exmodp1_2 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
120
+ assert . equal ( modp2Secret , exmodp2_2Secret ) ;
121
+ assert . equal ( exmodp2_2 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
117
122
118
123
119
124
// Ensure specific generator (string without encoding) works as expected.
120
- var exmodp1_3 = crypto . createDiffieHellman ( modp1buf , '\x02' ) ;
121
- exmodp1_3 . generateKeys ( ) ;
122
- modp1Secret = modp1 . computeSecret ( exmodp1_3 . getPublicKey ( ) ) . toString ( 'hex' ) ;
123
- var exmodp1_3Secret = exmodp1_3 . computeSecret ( modp1 . getPublicKey ( ) )
125
+ var exmodp2_3 = crypto . createDiffieHellman ( modp2buf , '\x02' ) ;
126
+ exmodp2_3 . generateKeys ( ) ;
127
+ modp2Secret = modp2 . computeSecret ( exmodp2_3 . getPublicKey ( ) ) . toString ( 'hex' ) ;
128
+ var exmodp2_3Secret = exmodp2_3 . computeSecret ( modp2 . getPublicKey ( ) )
124
129
. toString ( 'hex' ) ;
125
- assert . equal ( modp1Secret , exmodp1_3Secret ) ;
126
- assert . equal ( exmodp1_3 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
130
+ assert . equal ( modp2Secret , exmodp2_3Secret ) ;
131
+ assert . equal ( exmodp2_3 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
127
132
128
133
129
134
// Ensure specific generator (numeric) works as expected.
130
- var exmodp1_4 = crypto . createDiffieHellman ( modp1buf , 2 ) ;
131
- exmodp1_4 . generateKeys ( ) ;
132
- modp1Secret = modp1 . computeSecret ( exmodp1_4 . getPublicKey ( ) ) . toString ( 'hex' ) ;
133
- var exmodp1_4Secret = exmodp1_4 . computeSecret ( modp1 . getPublicKey ( ) )
135
+ var exmodp2_4 = crypto . createDiffieHellman ( modp2buf , 2 ) ;
136
+ exmodp2_4 . generateKeys ( ) ;
137
+ modp2Secret = modp2 . computeSecret ( exmodp2_4 . getPublicKey ( ) ) . toString ( 'hex' ) ;
138
+ var exmodp2_4Secret = exmodp2_4 . computeSecret ( modp2 . getPublicKey ( ) )
134
139
. toString ( 'hex' ) ;
135
- assert . equal ( modp1Secret , exmodp1_4Secret ) ;
136
- assert . equal ( exmodp1_4 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
140
+ assert . equal ( modp2Secret , exmodp2_4Secret ) ;
141
+ assert . equal ( exmodp2_4 . verifyError , constants . DH_NOT_SUITABLE_GENERATOR ) ;
137
142
138
143
139
144
var p = 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74' +
0 commit comments