diff --git a/src/crypto/crypto_ec.cc b/src/crypto/crypto_ec.cc index ea4c70ad5d8c84..cdf8dd47d6e2a5 100644 --- a/src/crypto/crypto_ec.cc +++ b/src/crypto/crypto_ec.cc @@ -314,7 +314,7 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo& args) { return THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Failed to set generated public key"); - EC_KEY_copy(ecdh->key_.get(), new_key.get()); + ecdh->key_.reset(EC_KEY_dup(new_key.get())); ecdh->group_ = EC_KEY_get0_group(ecdh->key_.get()); } diff --git a/test/parallel/test-crypto-ecdh-convert-key.js b/test/parallel/test-crypto-ecdh-convert-key.js index f4d5a651ed6b88..c0046099df9ec0 100644 --- a/test/parallel/test-crypto-ecdh-convert-key.js +++ b/test/parallel/test-crypto-ecdh-convert-key.js @@ -117,7 +117,7 @@ if (getCurves().includes('secp256k1')) { // rather than Node's generic error message. const badKey = 'f'.repeat(128); assert.throws( - () => ECDH.convertKey(badKey, 'secp256k1', 'hex', 'hex', 'compressed'), + () => ECDH.convertKey(badKey, 'secp521r1', 'hex', 'hex', 'compressed'), /Failed to convert Buffer to EC_POINT/); // Next statement should not throw an exception.