2017-01-03 21:16:48 +00:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2016-04-02 04:40:21 +00:00
|
|
|
const common = require('../common');
|
2021-04-25 04:13:48 +00:00
|
|
|
|
2021-04-04 13:31:13 +00:00
|
|
|
if (!common.hasCrypto) {
|
2017-06-30 23:29:09 +00:00
|
|
|
common.skip('node compiled without OpenSSL.');
|
2021-04-04 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 15:40:27 +00:00
|
|
|
if (process.config.variables.arm_version === '7') {
|
|
|
|
common.skip('Too slow for armv7 bots');
|
2021-04-04 13:31:13 +00:00
|
|
|
}
|
2017-06-30 23:29:09 +00:00
|
|
|
|
2016-04-02 04:40:21 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const crypto = require('crypto');
|
2012-01-22 18:24:37 +00:00
|
|
|
|
2019-06-22 21:38:22 +00:00
|
|
|
[ 'modp1', 'modp2', 'modp5', 'modp14', 'modp15', 'modp16', 'modp17' ]
|
|
|
|
.forEach((name) => {
|
2015-11-10 19:56:52 +00:00
|
|
|
// modp1 is 768 bits, FIPS requires >= 1024
|
2016-08-18 23:15:39 +00:00
|
|
|
if (name === 'modp1' && common.hasFipsCrypto)
|
2019-06-22 21:38:22 +00:00
|
|
|
return;
|
2017-01-08 13:19:00 +00:00
|
|
|
const group1 = crypto.getDiffieHellman(name);
|
|
|
|
const group2 = crypto.getDiffieHellman(name);
|
2012-01-22 18:24:37 +00:00
|
|
|
group1.generateKeys();
|
|
|
|
group2.generateKeys();
|
2017-01-08 13:19:00 +00:00
|
|
|
const key1 = group1.computeSecret(group2.getPublicKey());
|
|
|
|
const key2 = group2.computeSecret(group1.getPublicKey());
|
2016-04-19 22:37:45 +00:00
|
|
|
assert.deepStrictEqual(key1, key2);
|
2019-06-22 21:38:22 +00:00
|
|
|
});
|