11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst crypto = require('crypto'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciassert.throws(() => crypto.diffieHellman(), { 101cb0ef41Sopenharmony_ci name: 'TypeError', 111cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 121cb0ef41Sopenharmony_ci message: 'The "options" argument must be of type object. Received undefined' 131cb0ef41Sopenharmony_ci}); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciassert.throws(() => crypto.diffieHellman(null), { 161cb0ef41Sopenharmony_ci name: 'TypeError', 171cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 181cb0ef41Sopenharmony_ci message: 'The "options" argument must be of type object. Received null' 191cb0ef41Sopenharmony_ci}); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciassert.throws(() => crypto.diffieHellman([]), { 221cb0ef41Sopenharmony_ci name: 'TypeError', 231cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 241cb0ef41Sopenharmony_ci message: 251cb0ef41Sopenharmony_ci 'The "options" argument must be of type object. ' + 261cb0ef41Sopenharmony_ci 'Received an instance of Array', 271cb0ef41Sopenharmony_ci}); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_cifunction test({ publicKey: alicePublicKey, privateKey: alicePrivateKey }, 301cb0ef41Sopenharmony_ci { publicKey: bobPublicKey, privateKey: bobPrivateKey }, 311cb0ef41Sopenharmony_ci expectedValue) { 321cb0ef41Sopenharmony_ci const buf1 = crypto.diffieHellman({ 331cb0ef41Sopenharmony_ci privateKey: alicePrivateKey, 341cb0ef41Sopenharmony_ci publicKey: bobPublicKey 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci const buf2 = crypto.diffieHellman({ 371cb0ef41Sopenharmony_ci privateKey: bobPrivateKey, 381cb0ef41Sopenharmony_ci publicKey: alicePublicKey 391cb0ef41Sopenharmony_ci }); 401cb0ef41Sopenharmony_ci assert.deepStrictEqual(buf1, buf2); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci if (expectedValue !== undefined) 431cb0ef41Sopenharmony_ci assert.deepStrictEqual(buf1, expectedValue); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciconst alicePrivateKey = crypto.createPrivateKey({ 471cb0ef41Sopenharmony_ci key: '-----BEGIN PRIVATE KEY-----\n' + 481cb0ef41Sopenharmony_ci 'MIIBoQIBADCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKL\n' + 491cb0ef41Sopenharmony_ci 'gNwc0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVt\n' + 501cb0ef41Sopenharmony_ci 'bVHCReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR\n' + 511cb0ef41Sopenharmony_ci '7ORbPcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkH\n' + 521cb0ef41Sopenharmony_ci 'cJaWbWcMNU5KvJgE8XRsCMojcyf//////////wIBAgSBwwKBwEh82IAVnYNf0Kjb\n' + 531cb0ef41Sopenharmony_ci 'qYSImDFyg9sH6CJ0GzRK05e6hM3dOSClFYi4kbA7Pr7zyfdn2SH6wSlNS14Jyrtt\n' + 541cb0ef41Sopenharmony_ci 'HePrRSeYl1T+tk0AfrvaLmyM56F+9B3jwt/nzqr5YxmfVdXb2aQV53VS/mm3pB2H\n' + 551cb0ef41Sopenharmony_ci 'iIt9FmvFaaOVe2DupqSr6xzbf/zyON+WF5B5HNVOWXswgpgdUsCyygs98hKy/Xje\n' + 561cb0ef41Sopenharmony_ci 'TGzJUoWInW39t0YgMXenJrkS0m6wol8Rhxx81AGgELNV7EHZqg==\n' + 571cb0ef41Sopenharmony_ci '-----END PRIVATE KEY-----', 581cb0ef41Sopenharmony_ci format: 'pem' 591cb0ef41Sopenharmony_ci}); 601cb0ef41Sopenharmony_ciconst alicePublicKey = crypto.createPublicKey({ 611cb0ef41Sopenharmony_ci key: '-----BEGIN PUBLIC KEY-----\n' + 621cb0ef41Sopenharmony_ci 'MIIBnzCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKLgNwc\n' + 631cb0ef41Sopenharmony_ci '0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHC\n' + 641cb0ef41Sopenharmony_ci 'ReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7ORb\n' + 651cb0ef41Sopenharmony_ci 'PcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkHcJaW\n' + 661cb0ef41Sopenharmony_ci 'bWcMNU5KvJgE8XRsCMojcyf//////////wIBAgOBxAACgcBR7+iL5qx7aOb9K+aZ\n' + 671cb0ef41Sopenharmony_ci 'y2oLt7ST33sDKT+nxpag6cWDDWzPBKFDCJ8fr0v7yW453px8N4qi4R7SYYxFBaYN\n' + 681cb0ef41Sopenharmony_ci 'Y3JvgDg1ct2JC9sxSuUOLqSFn3hpmAjW7cS0kExIVGfdLlYtIqbhhuo45cTEbVIM\n' + 691cb0ef41Sopenharmony_ci 'rDEz8mjIlnvbWpKB9+uYmbjfVoc3leFvUBqfG2In2m23Md1swsPxr3n7g68H66JX\n' + 701cb0ef41Sopenharmony_ci 'iBJKZLQMqNdbY14G9rdKmhhTJrQjC+i7Q/wI8JPhOFzHIGA=\n' + 711cb0ef41Sopenharmony_ci '-----END PUBLIC KEY-----', 721cb0ef41Sopenharmony_ci format: 'pem' 731cb0ef41Sopenharmony_ci}); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ciconst bobPrivateKey = crypto.createPrivateKey({ 761cb0ef41Sopenharmony_ci key: '-----BEGIN PRIVATE KEY-----\n' + 771cb0ef41Sopenharmony_ci 'MIIBoQIBADCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKL\n' + 781cb0ef41Sopenharmony_ci 'gNwc0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVt\n' + 791cb0ef41Sopenharmony_ci 'bVHCReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR\n' + 801cb0ef41Sopenharmony_ci '7ORbPcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkH\n' + 811cb0ef41Sopenharmony_ci 'cJaWbWcMNU5KvJgE8XRsCMojcyf//////////wIBAgSBwwKBwHxnT7Zw2Ehh1vyw\n' + 821cb0ef41Sopenharmony_ci 'eolzQFHQzyuT0y+3BF+FxK2Ox7VPguTp57wQfGHbORJ2cwCdLx2mFM7gk4tZ6COS\n' + 831cb0ef41Sopenharmony_ci 'E3Vta85a/PuhKXNLRdP79JgLnNtVtKXB+ePDS5C2GgXH1RHvqEdJh7JYnMy7Zj4P\n' + 841cb0ef41Sopenharmony_ci 'GagGtIy3dV5f4FA0B/2C97jQ1pO16ah8gSLQRKsNpTCw2rqsZusE0rK6RaYAef7H\n' + 851cb0ef41Sopenharmony_ci 'y/0tmLIsHxLIn+WK9CANqMbCWoP4I178BQaqhiOBkNyNZ0ndqA==\n' + 861cb0ef41Sopenharmony_ci '-----END PRIVATE KEY-----', 871cb0ef41Sopenharmony_ci format: 'pem' 881cb0ef41Sopenharmony_ci}); 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ciconst bobPublicKey = crypto.createPublicKey({ 911cb0ef41Sopenharmony_ci key: '-----BEGIN PUBLIC KEY-----\n' + 921cb0ef41Sopenharmony_ci 'MIIBoDCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKLgNwc\n' + 931cb0ef41Sopenharmony_ci '0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHC\n' + 941cb0ef41Sopenharmony_ci 'ReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7ORb\n' + 951cb0ef41Sopenharmony_ci 'PcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkHcJaW\n' + 961cb0ef41Sopenharmony_ci 'bWcMNU5KvJgE8XRsCMojcyf//////////wIBAgOBxQACgcEAi26oq8z/GNSBm3zi\n' + 971cb0ef41Sopenharmony_ci 'gNt7SA7cArUBbTxINa9iLYWp6bxrvCKwDQwISN36/QUw8nUAe8aRyMt0oYn+y6vW\n' + 981cb0ef41Sopenharmony_ci 'Pw5OlO+TLrUelMVFaADEzoYomH0zVGb0sW4aBN8haC0mbrPt9QshgCvjr1hEPEna\n' + 991cb0ef41Sopenharmony_ci 'QFKfjzNaJRNMFFd4f2Dn8MSB4yu1xpA1T2i0JSk24vS2H55jx24xhUYtfhT2LJgK\n' + 1001cb0ef41Sopenharmony_ci 'JvnaODey/xtY4Kql10ZKf43Lw6gdQC3G8opC9OxVxt9oNR7Z\n' + 1011cb0ef41Sopenharmony_ci '-----END PUBLIC KEY-----', 1021cb0ef41Sopenharmony_ci format: 'pem' 1031cb0ef41Sopenharmony_ci}); 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ciassert.throws(() => crypto.diffieHellman({ privateKey: alicePrivateKey }), { 1061cb0ef41Sopenharmony_ci name: 'TypeError', 1071cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE', 1081cb0ef41Sopenharmony_ci message: "The property 'options.publicKey' is invalid. Received undefined" 1091cb0ef41Sopenharmony_ci}); 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ciassert.throws(() => crypto.diffieHellman({ publicKey: alicePublicKey }), { 1121cb0ef41Sopenharmony_ci name: 'TypeError', 1131cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE', 1141cb0ef41Sopenharmony_ci message: "The property 'options.privateKey' is invalid. Received undefined" 1151cb0ef41Sopenharmony_ci}); 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ciconst privateKey = Buffer.from( 1181cb0ef41Sopenharmony_ci '487CD880159D835FD0A8DBA9848898317283DB07E822741B344AD397BA84CDDD3920A51588' + 1191cb0ef41Sopenharmony_ci 'B891B03B3EBEF3C9F767D921FAC1294D4B5E09CABB6D1DE3EB4527989754FEB64D007EBBDA' + 1201cb0ef41Sopenharmony_ci '2E6C8CE7A17EF41DE3C2DFE7CEAAF963199F55D5DBD9A415E77552FE69B7A41D87888B7D16' + 1211cb0ef41Sopenharmony_ci '6BC569A3957B60EEA6A4ABEB1CDB7FFCF238DF961790791CD54E597B3082981D52C0B2CA0B' + 1221cb0ef41Sopenharmony_ci '3DF212B2FD78DE4C6CC95285889D6DFDB746203177A726B912D26EB0A25F11871C7CD401A0' + 1231cb0ef41Sopenharmony_ci '10B355EC41D9AA', 'hex'); 1241cb0ef41Sopenharmony_ciconst publicKey = Buffer.from( 1251cb0ef41Sopenharmony_ci '8b6ea8abccff18d4819b7ce280db7b480edc02b5016d3c4835af622d85a9e9bc6bbc22b00d' + 1261cb0ef41Sopenharmony_ci '0c0848ddfafd0530f275007bc691c8cb74a189fecbabd63f0e4e94ef932eb51e94c5456800' + 1271cb0ef41Sopenharmony_ci 'c4ce8628987d335466f4b16e1a04df21682d266eb3edf50b21802be3af58443c49da40529f' + 1281cb0ef41Sopenharmony_ci '8f335a25134c1457787f60e7f0c481e32bb5c690354f68b4252936e2f4b61f9e63c76e3185' + 1291cb0ef41Sopenharmony_ci '462d7e14f62c980a26f9da3837b2ff1b58e0aaa5d7464a7f8dcbc3a81d402dc6f28a42f4ec' + 1301cb0ef41Sopenharmony_ci '55c6df68351ed9', 'hex'); 1311cb0ef41Sopenharmony_ci 1321cb0ef41Sopenharmony_ciconst group = crypto.getDiffieHellman('modp5'); 1331cb0ef41Sopenharmony_ciconst dh = crypto.createDiffieHellman(group.getPrime(), group.getGenerator()); 1341cb0ef41Sopenharmony_cidh.setPrivateKey(privateKey); 1351cb0ef41Sopenharmony_ci 1361cb0ef41Sopenharmony_ci// Test simple Diffie-Hellman, no curves involved. 1371cb0ef41Sopenharmony_citest({ publicKey: alicePublicKey, privateKey: alicePrivateKey }, 1381cb0ef41Sopenharmony_ci { publicKey: bobPublicKey, privateKey: bobPrivateKey }, 1391cb0ef41Sopenharmony_ci dh.computeSecret(publicKey)); 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_citest(crypto.generateKeyPairSync('dh', { group: 'modp5' }), 1421cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('dh', { group: 'modp5' })); 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_citest(crypto.generateKeyPairSync('dh', { group: 'modp5' }), 1451cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('dh', { prime: group.getPrime() })); 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_ciconst list = [ 1481cb0ef41Sopenharmony_ci // Same generator, but different primes. 1491cb0ef41Sopenharmony_ci [{ group: 'modp5' }, { group: 'modp18' }]]; 1501cb0ef41Sopenharmony_ci 1511cb0ef41Sopenharmony_ci// TODO(danbev): Take a closer look if there should be a check in OpenSSL3 1521cb0ef41Sopenharmony_ci// when the dh parameters differ. 1531cb0ef41Sopenharmony_ciif (!common.hasOpenSSL3) { 1541cb0ef41Sopenharmony_ci // Same primes, but different generator. 1551cb0ef41Sopenharmony_ci list.push([{ group: 'modp5' }, { prime: group.getPrime(), generator: 5 }]); 1561cb0ef41Sopenharmony_ci // Same generator, but different primes. 1571cb0ef41Sopenharmony_ci list.push([{ primeLength: 1024 }, { primeLength: 1024 }]); 1581cb0ef41Sopenharmony_ci} 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_cifor (const [params1, params2] of list) { 1611cb0ef41Sopenharmony_ci assert.throws(() => { 1621cb0ef41Sopenharmony_ci test(crypto.generateKeyPairSync('dh', params1), 1631cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('dh', params2)); 1641cb0ef41Sopenharmony_ci }, common.hasOpenSSL3 ? { 1651cb0ef41Sopenharmony_ci name: 'Error', 1661cb0ef41Sopenharmony_ci code: 'ERR_OSSL_MISMATCHING_DOMAIN_PARAMETERS' 1671cb0ef41Sopenharmony_ci } : { 1681cb0ef41Sopenharmony_ci name: 'Error', 1691cb0ef41Sopenharmony_ci code: 'ERR_OSSL_EVP_DIFFERENT_PARAMETERS' 1701cb0ef41Sopenharmony_ci }); 1711cb0ef41Sopenharmony_ci} 1721cb0ef41Sopenharmony_ci{ 1731cb0ef41Sopenharmony_ci const privateKey = crypto.createPrivateKey({ 1741cb0ef41Sopenharmony_ci key: '-----BEGIN PRIVATE KEY-----\n' + 1751cb0ef41Sopenharmony_ci 'MIIBoQIBADCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKL\n' + 1761cb0ef41Sopenharmony_ci 'gNwc0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVt\n' + 1771cb0ef41Sopenharmony_ci 'bVHCReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR\n' + 1781cb0ef41Sopenharmony_ci '7ORbPcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkH\n' + 1791cb0ef41Sopenharmony_ci 'cJaWbWcMNU5KvJgE8XRsCMojcyf//////////wIBAgSBwwKBwHu9fpiqrfJJ+tl9\n' + 1801cb0ef41Sopenharmony_ci 'ujFtEWv4afub6A/1/7sgishOYN3YQ+nmWQlmPpveIY34an5dG82CTrixHwUzQTMF\n' + 1811cb0ef41Sopenharmony_ci 'JaiCW3ax9+qk31f2jTNKrQznmKgopVKXF0FEJC6H79W/8Y0U14gsI9sHpovKhfou\n' + 1821cb0ef41Sopenharmony_ci 'RQD0QogW7ejSwMG8hCYibfrvMm0b5PHlwimISyEKh7VtDQ1frYN/Wr9ZbiV+FePJ\n' + 1831cb0ef41Sopenharmony_ci '2j6RUKYNj1Pv+B4zdMgiLLjILAs8WUfbHciU21KSJh1izVQaUQ==\n' + 1841cb0ef41Sopenharmony_ci '-----END PRIVATE KEY-----' 1851cb0ef41Sopenharmony_ci }); 1861cb0ef41Sopenharmony_ci const publicKey = crypto.createPublicKey({ 1871cb0ef41Sopenharmony_ci key: '-----BEGIN PUBLIC KEY-----\n' + 1881cb0ef41Sopenharmony_ci 'MIIBoDCB1QYJKoZIhvcNAQMBMIHHAoHBAP//////////yQ/aoiFowjTExmKLgNwc\n' + 1891cb0ef41Sopenharmony_ci '0SkCTgiKZ8x0Agu+pjsTmyJRSgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHC\n' + 1901cb0ef41Sopenharmony_ci 'ReSFtXZiXn7G9ExC6aY37WsL/1y29Aa37e44a/taiZ+lrp8kEXxLH+ZJKGZR7ORb\n' + 1911cb0ef41Sopenharmony_ci 'PcIAfLihY78FmNpINhxV05ppFj+o/STPX4NlXSPco62WHGLzViCFUrue1SkHcJaW\n' + 1921cb0ef41Sopenharmony_ci 'bWcMNU5KvJgE8XRsCMojcyf//////////wIBAgOBxQACgcEAmG9LpD8SAA6/W7oK\n' + 1931cb0ef41Sopenharmony_ci 'E4MCuuQtf5E8bqtcEAfYTOOvKyCS+eiX3TtZRsvHJjUBEyeO99PR/KrGVlkSuW52\n' + 1941cb0ef41Sopenharmony_ci 'ZOSXUOFu1L/0tqHrvRVHo+QEq3OvZ3EAyJkdtSEUTztxuUrMOyJXHDc1OUdNSnk0\n' + 1951cb0ef41Sopenharmony_ci 'taGX4mP3247golVx2DS4viDYs7UtaMdx03dWaP6y5StNUZQlgCIUzL7MYpC16V5y\n' + 1961cb0ef41Sopenharmony_ci 'KkFrE+Kp/Z77gEjivaG6YuxVj4GPLxJYbNFVTel42oSVeKuq\n' + 1971cb0ef41Sopenharmony_ci '-----END PUBLIC KEY-----', 1981cb0ef41Sopenharmony_ci format: 'pem' 1991cb0ef41Sopenharmony_ci }); 2001cb0ef41Sopenharmony_ci 2011cb0ef41Sopenharmony_ci // This key combination will result in an unusually short secret, and should 2021cb0ef41Sopenharmony_ci // not cause an assertion failure. 2031cb0ef41Sopenharmony_ci const secret = crypto.diffieHellman({ publicKey, privateKey }); 2041cb0ef41Sopenharmony_ci assert.strictEqual(secret.toString('hex'), 2051cb0ef41Sopenharmony_ci '0099d0fa242af5db9ea7330e23937a27db041f79c581500fc7f9976' + 2061cb0ef41Sopenharmony_ci '554d59d5b9ced934778d72e19a1fefc81e9d981013198748c0b5c6c' + 2071cb0ef41Sopenharmony_ci '762985eec687dc5bec5c9367b05837daee9d0bcc29024ed7f3abba1' + 2081cb0ef41Sopenharmony_ci '2794b65a745117fb0d87bc5b1b2b68c296c3f686cc29e450e4e1239' + 2091cb0ef41Sopenharmony_ci '21f56a5733fe58aabf71f14582954059c2185d342b9b0fa10c2598a' + 2101cb0ef41Sopenharmony_ci '5426c2baee7f9a686fc1e16cd4757c852bf7225a2732250548efe28' + 2111cb0ef41Sopenharmony_ci 'debc26f1acdec51efe23d20786a6f8a14d360803bbc71972e87fd3'); 2121cb0ef41Sopenharmony_ci} 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci// Test ECDH. 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_citest(crypto.generateKeyPairSync('ec', { namedCurve: 'secp256k1' }), 2171cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('ec', { namedCurve: 'secp256k1' })); 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ciconst not256k1 = crypto.getCurves().find((c) => /^sec.*(224|384|512)/.test(c)); 2201cb0ef41Sopenharmony_ciassert.throws(() => { 2211cb0ef41Sopenharmony_ci test(crypto.generateKeyPairSync('ec', { namedCurve: 'secp256k1' }), 2221cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('ec', { namedCurve: not256k1 })); 2231cb0ef41Sopenharmony_ci}, common.hasOpenSSL3 ? { 2241cb0ef41Sopenharmony_ci name: 'Error', 2251cb0ef41Sopenharmony_ci code: 'ERR_OSSL_MISMATCHING_DOMAIN_PARAMETERS' 2261cb0ef41Sopenharmony_ci} : { 2271cb0ef41Sopenharmony_ci name: 'Error', 2281cb0ef41Sopenharmony_ci code: 'ERR_OSSL_EVP_DIFFERENT_PARAMETERS' 2291cb0ef41Sopenharmony_ci}); 2301cb0ef41Sopenharmony_ci 2311cb0ef41Sopenharmony_ci// Test ECDH-ES. 2321cb0ef41Sopenharmony_ci 2331cb0ef41Sopenharmony_citest(crypto.generateKeyPairSync('x448'), 2341cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('x448')); 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_citest(crypto.generateKeyPairSync('x25519'), 2371cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('x25519')); 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ciassert.throws(() => { 2401cb0ef41Sopenharmony_ci test(crypto.generateKeyPairSync('x448'), 2411cb0ef41Sopenharmony_ci crypto.generateKeyPairSync('x25519')); 2421cb0ef41Sopenharmony_ci}, { 2431cb0ef41Sopenharmony_ci name: 'Error', 2441cb0ef41Sopenharmony_ci code: 'ERR_CRYPTO_INCOMPATIBLE_KEY', 2451cb0ef41Sopenharmony_ci message: 'Incompatible key types for Diffie-Hellman: x448 and x25519' 2461cb0ef41Sopenharmony_ci}); 247