summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/crypto
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-08-08 11:35:29 +0200
committerGitHub <noreply@github.com>2024-08-08 15:05:29 +0530
commit93d479252b5a18e6e782c74b808240bd3ef036bd (patch)
tree4c8b83797fb0e30d1ce3fcebad3fbde6cf33ef1d /ext/node/polyfills/internal/crypto
parent507e5b74ff21161ba8bd947d7d9cee317c0af379 (diff)
fix(ext/node): add crypto.diffieHellman (#24938)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com> Closes #21806
Diffstat (limited to 'ext/node/polyfills/internal/crypto')
-rw-r--r--ext/node/polyfills/internal/crypto/diffiehellman.ts15
-rw-r--r--ext/node/polyfills/internal/crypto/keys.ts2
2 files changed, 13 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts
index 16a1f2498..a439306a9 100644
--- a/ext/node/polyfills/internal/crypto/diffiehellman.ts
+++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts
@@ -7,6 +7,7 @@
import {
op_node_dh_compute_secret,
op_node_dh_keys_generate_and_export,
+ op_node_diffie_hellman,
op_node_ecdh_compute_public_key,
op_node_ecdh_compute_secret,
op_node_ecdh_encode_pubkey,
@@ -40,7 +41,12 @@ import type {
BinaryToTextEncoding,
ECDHKeyFormat,
} from "ext:deno_node/internal/crypto/types.ts";
-import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts";
+import {
+ getKeyObjectHandle,
+ kConsumePrivate,
+ kConsumePublic,
+ KeyObject,
+} from "ext:deno_node/internal/crypto/keys.ts";
import type { BufferEncoding } from "ext:deno_node/_global.d.ts";
const DH_GENERATOR = 2;
@@ -1305,11 +1311,14 @@ export class ECDH {
}
}
-export function diffieHellman(_options: {
+export function diffieHellman(options: {
privateKey: KeyObject;
publicKey: KeyObject;
}): Buffer {
- notImplemented("crypto.diffieHellman");
+ const privateKey = getKeyObjectHandle(options.privateKey, kConsumePrivate);
+ const publicKey = getKeyObjectHandle(options.publicKey, kConsumePublic);
+ const bytes = op_node_diffie_hellman(privateKey, publicKey);
+ return Buffer.from(bytes);
}
export default {
diff --git a/ext/node/polyfills/internal/crypto/keys.ts b/ext/node/polyfills/internal/crypto/keys.ts
index 31d674e67..62cec47d6 100644
--- a/ext/node/polyfills/internal/crypto/keys.ts
+++ b/ext/node/polyfills/internal/crypto/keys.ts
@@ -232,7 +232,7 @@ export interface JsonWebKeyInput {
format: "jwk";
}
-function getKeyObjectHandle(key: KeyObject, ctx: KeyHandleContext) {
+export function getKeyObjectHandle(key: KeyObject, ctx: KeyHandleContext) {
if (ctx === kCreatePrivate) {
throw new ERR_INVALID_ARG_TYPE(
"key",