2023-02-14 11:38:45 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
// Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license.
|
|
|
|
|
2023-03-08 06:44:54 -05:00
|
|
|
import { notImplemented } from "ext:deno_node/_utils.ts";
|
2023-02-14 11:38:45 -05:00
|
|
|
import {
|
|
|
|
isAnyArrayBuffer,
|
|
|
|
isArrayBufferView,
|
2023-03-08 06:44:54 -05:00
|
|
|
} from "ext:deno_node/internal/util/types.ts";
|
2023-05-15 13:41:53 -04:00
|
|
|
import {
|
|
|
|
ERR_INVALID_ARG_TYPE,
|
|
|
|
NodeError,
|
|
|
|
} from "ext:deno_node/internal/errors.ts";
|
2023-02-14 11:38:45 -05:00
|
|
|
import {
|
|
|
|
validateInt32,
|
|
|
|
validateString,
|
2023-03-08 06:44:54 -05:00
|
|
|
} from "ext:deno_node/internal/validators.mjs";
|
|
|
|
import { Buffer } from "ext:deno_node/buffer.ts";
|
2023-02-14 11:38:45 -05:00
|
|
|
import {
|
2023-04-27 12:31:35 -04:00
|
|
|
EllipticCurve,
|
|
|
|
ellipticCurves,
|
2023-02-14 11:38:45 -05:00
|
|
|
getDefaultEncoding,
|
|
|
|
toBuf,
|
2023-03-08 06:44:54 -05:00
|
|
|
} from "ext:deno_node/internal/crypto/util.ts";
|
2023-02-14 11:38:45 -05:00
|
|
|
import type {
|
|
|
|
BinaryLike,
|
|
|
|
BinaryToTextEncoding,
|
|
|
|
ECDHKeyFormat,
|
2023-03-08 06:44:54 -05:00
|
|
|
} from "ext:deno_node/internal/crypto/types.ts";
|
|
|
|
import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts";
|
|
|
|
import type { BufferEncoding } from "ext:deno_node/_global.d.ts";
|
2023-02-14 11:38:45 -05:00
|
|
|
|
2023-04-27 12:31:35 -04:00
|
|
|
const { ops } = Deno.core;
|
|
|
|
|
2023-02-14 11:38:45 -05:00
|
|
|
const DH_GENERATOR = 2;
|
|
|
|
|
|
|
|
export class DiffieHellman {
|
|
|
|
verifyError!: number;
|
2023-05-15 13:41:53 -04:00
|
|
|
#prime: Buffer;
|
|
|
|
#primeLength: number;
|
|
|
|
#generator: Buffer;
|
|
|
|
#privateKey: Buffer;
|
|
|
|
#publicKey: Buffer;
|
2023-02-14 11:38:45 -05:00
|
|
|
|
|
|
|
constructor(
|
2023-05-15 13:41:53 -04:00
|
|
|
sizeOrKey: number | string | ArrayBufferView,
|
2023-02-14 11:38:45 -05:00
|
|
|
keyEncoding?: unknown,
|
|
|
|
generator?: unknown,
|
|
|
|
genEncoding?: unknown,
|
|
|
|
) {
|
|
|
|
if (
|
|
|
|
typeof sizeOrKey !== "number" &&
|
|
|
|
typeof sizeOrKey !== "string" &&
|
|
|
|
!isArrayBufferView(sizeOrKey) &&
|
|
|
|
!isAnyArrayBuffer(sizeOrKey)
|
|
|
|
) {
|
|
|
|
throw new ERR_INVALID_ARG_TYPE(
|
|
|
|
"sizeOrKey",
|
|
|
|
["number", "string", "ArrayBuffer", "Buffer", "TypedArray", "DataView"],
|
|
|
|
sizeOrKey,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof sizeOrKey === "number") {
|
|
|
|
validateInt32(sizeOrKey, "sizeOrKey");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
keyEncoding &&
|
|
|
|
!Buffer.isEncoding(keyEncoding as BinaryToTextEncoding) &&
|
|
|
|
keyEncoding !== "buffer"
|
|
|
|
) {
|
|
|
|
genEncoding = generator;
|
|
|
|
generator = keyEncoding;
|
|
|
|
keyEncoding = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const encoding = getDefaultEncoding();
|
|
|
|
keyEncoding = keyEncoding || encoding;
|
|
|
|
genEncoding = genEncoding || encoding;
|
|
|
|
|
|
|
|
if (typeof sizeOrKey !== "number") {
|
2023-05-15 13:41:53 -04:00
|
|
|
this.#prime = toBuf(sizeOrKey as string, keyEncoding as string);
|
|
|
|
} else {
|
|
|
|
// The supplied parameter is our primeLength, generate a suitable prime.
|
|
|
|
this.#primeLength = sizeOrKey as number;
|
|
|
|
if (this.#primeLength < 2) {
|
|
|
|
throw new NodeError("ERR_OSSL_BN_BITS_TOO_SMALL", "bits too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.#prime = Buffer.from(
|
|
|
|
ops.op_node_gen_prime(this.#primeLength).buffer,
|
|
|
|
);
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!generator) {
|
2023-05-15 13:41:53 -04:00
|
|
|
// While the commonly used cyclic group generators for DH are 2 and 5, we
|
|
|
|
// need this a buffer, because, well.. Node.
|
|
|
|
this.#generator = Buffer.alloc(4);
|
|
|
|
this.#generator.writeUint32BE(DH_GENERATOR);
|
2023-02-14 11:38:45 -05:00
|
|
|
} else if (typeof generator === "number") {
|
|
|
|
validateInt32(generator, "generator");
|
2023-05-15 13:41:53 -04:00
|
|
|
this.#generator = Buffer.alloc(4);
|
|
|
|
if (generator <= 0 || generator >= 0x7fffffff) {
|
|
|
|
throw new NodeError("ERR_OSSL_DH_BAD_GENERATOR", "bad generator");
|
|
|
|
}
|
|
|
|
this.#generator.writeUint32BE(generator);
|
2023-02-14 11:38:45 -05:00
|
|
|
} else if (typeof generator === "string") {
|
|
|
|
generator = toBuf(generator, genEncoding as string);
|
2023-05-15 13:41:53 -04:00
|
|
|
this.#generator = generator;
|
2023-02-14 11:38:45 -05:00
|
|
|
} else if (!isArrayBufferView(generator) && !isAnyArrayBuffer(generator)) {
|
|
|
|
throw new ERR_INVALID_ARG_TYPE(
|
|
|
|
"generator",
|
|
|
|
["number", "string", "ArrayBuffer", "Buffer", "TypedArray", "DataView"],
|
|
|
|
generator,
|
|
|
|
);
|
2023-05-15 13:41:53 -04:00
|
|
|
} else {
|
|
|
|
this.#generator = Buffer.from(generator);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.#checkGenerator();
|
|
|
|
|
|
|
|
// TODO(lev): actually implement this value
|
|
|
|
this.verifyError = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#checkGenerator(): number {
|
|
|
|
let generator: number;
|
|
|
|
|
|
|
|
if (this.#generator.length == 0) {
|
|
|
|
throw new NodeError("ERR_OSSL_DH_BAD_GENERATOR", "bad generator");
|
|
|
|
} else if (this.#generator.length == 1) {
|
|
|
|
generator = this.#generator.readUint8();
|
|
|
|
} else if (this.#generator.length == 2) {
|
|
|
|
generator = this.#generator.readUint16BE();
|
|
|
|
} else {
|
|
|
|
generator = this.#generator.readUint32BE();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generator != 2 && generator != 5) {
|
|
|
|
throw new NodeError("ERR_OSSL_DH_BAD_GENERATOR", "bad generator");
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
2023-05-15 13:41:53 -04:00
|
|
|
return generator;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
computeSecret(otherPublicKey: ArrayBufferView): Buffer;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: string,
|
|
|
|
inputEncoding: BinaryToTextEncoding,
|
|
|
|
): Buffer;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: ArrayBufferView,
|
|
|
|
outputEncoding: BinaryToTextEncoding,
|
|
|
|
): string;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: string,
|
|
|
|
inputEncoding: BinaryToTextEncoding,
|
|
|
|
outputEncoding: BinaryToTextEncoding,
|
|
|
|
): string;
|
|
|
|
computeSecret(
|
2023-05-15 13:41:53 -04:00
|
|
|
otherPublicKey: ArrayBufferView | string,
|
|
|
|
inputEncoding?: BinaryToTextEncoding,
|
|
|
|
outputEncoding?: BinaryToTextEncoding,
|
2023-02-14 11:38:45 -05:00
|
|
|
): Buffer | string {
|
2023-05-15 13:41:53 -04:00
|
|
|
let buf;
|
|
|
|
if (inputEncoding != undefined && inputEncoding != "buffer") {
|
|
|
|
buf = Buffer.from(otherPublicKey.buffer, inputEncoding);
|
|
|
|
} else {
|
|
|
|
buf = Buffer.from(otherPublicKey.buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
const sharedSecret = ops.op_node_dh_compute_secret(
|
|
|
|
this.#prime,
|
|
|
|
this.#privateKey,
|
|
|
|
buf,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (outputEncoding == undefined || outputEncoding == "buffer") {
|
|
|
|
return Buffer.from(sharedSecret.buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Buffer.from(sharedSecret.buffer).toString(outputEncoding);
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
generateKeys(): Buffer;
|
|
|
|
generateKeys(encoding: BinaryToTextEncoding): string;
|
|
|
|
generateKeys(_encoding?: BinaryToTextEncoding): Buffer | string {
|
2023-05-15 13:41:53 -04:00
|
|
|
const generator = this.#checkGenerator();
|
|
|
|
const [privateKey, publicKey] = ops.op_node_dh_generate2(
|
|
|
|
this.#prime,
|
|
|
|
this.#primeLength,
|
|
|
|
generator,
|
|
|
|
);
|
|
|
|
|
|
|
|
this.#privateKey = Buffer.from(privateKey.buffer);
|
|
|
|
this.#publicKey = Buffer.from(publicKey.buffer);
|
|
|
|
|
|
|
|
return this.#publicKey;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getGenerator(): Buffer;
|
|
|
|
getGenerator(encoding: BinaryToTextEncoding): string;
|
2023-05-15 13:41:53 -04:00
|
|
|
getGenerator(encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
if (encoding !== undefined && encoding != "buffer") {
|
|
|
|
return this.#generator.toString(encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.#generator;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrime(): Buffer;
|
|
|
|
getPrime(encoding: BinaryToTextEncoding): string;
|
2023-05-15 13:41:53 -04:00
|
|
|
getPrime(encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
if (encoding !== undefined && encoding != "buffer") {
|
|
|
|
return this.#prime.toString(encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.#prime;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrivateKey(): Buffer;
|
|
|
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
2023-05-15 13:41:53 -04:00
|
|
|
getPrivateKey(encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
if (encoding !== undefined && encoding != "buffer") {
|
|
|
|
return this.#privateKey.toString(encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.#privateKey;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getPublicKey(): Buffer;
|
|
|
|
getPublicKey(encoding: BinaryToTextEncoding): string;
|
2023-05-15 13:41:53 -04:00
|
|
|
getPublicKey(encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
if (encoding !== undefined && encoding != "buffer") {
|
|
|
|
return this.#publicKey.toString(encoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.#publicKey;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setPrivateKey(privateKey: ArrayBufferView): void;
|
|
|
|
setPrivateKey(privateKey: string, encoding: BufferEncoding): void;
|
|
|
|
setPrivateKey(
|
2023-05-15 13:41:53 -04:00
|
|
|
privateKey: ArrayBufferView | string,
|
|
|
|
encoding?: BufferEncoding,
|
2023-02-14 11:38:45 -05:00
|
|
|
) {
|
2023-05-15 13:41:53 -04:00
|
|
|
if (encoding == undefined || encoding == "buffer") {
|
|
|
|
this.#privateKey = Buffer.from(privateKey);
|
|
|
|
} else {
|
|
|
|
this.#privateKey = Buffer.from(privateKey, encoding);
|
|
|
|
}
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setPublicKey(publicKey: ArrayBufferView): void;
|
|
|
|
setPublicKey(publicKey: string, encoding: BufferEncoding): void;
|
|
|
|
setPublicKey(
|
2023-05-15 13:41:53 -04:00
|
|
|
publicKey: ArrayBufferView | string,
|
|
|
|
encoding?: BufferEncoding,
|
2023-02-14 11:38:45 -05:00
|
|
|
) {
|
2023-05-15 13:41:53 -04:00
|
|
|
if (encoding == undefined || encoding == "buffer") {
|
|
|
|
this.#publicKey = Buffer.from(publicKey);
|
|
|
|
} else {
|
|
|
|
this.#publicKey = Buffer.from(publicKey, encoding);
|
|
|
|
}
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DiffieHellmanGroup {
|
|
|
|
verifyError!: number;
|
|
|
|
|
|
|
|
constructor(_name: string) {
|
|
|
|
notImplemented("crypto.DiffieHellmanGroup");
|
|
|
|
}
|
|
|
|
|
|
|
|
computeSecret(otherPublicKey: ArrayBufferView): Buffer;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: string,
|
|
|
|
inputEncoding: BinaryToTextEncoding,
|
|
|
|
): Buffer;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: ArrayBufferView,
|
|
|
|
outputEncoding: BinaryToTextEncoding,
|
|
|
|
): string;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: string,
|
|
|
|
inputEncoding: BinaryToTextEncoding,
|
|
|
|
outputEncoding: BinaryToTextEncoding,
|
|
|
|
): string;
|
|
|
|
computeSecret(
|
|
|
|
_otherPublicKey: ArrayBufferView | string,
|
|
|
|
_inputEncoding?: BinaryToTextEncoding,
|
|
|
|
_outputEncoding?: BinaryToTextEncoding,
|
|
|
|
): Buffer | string {
|
|
|
|
notImplemented("crypto.DiffieHellman.prototype.computeSecret");
|
|
|
|
}
|
|
|
|
|
|
|
|
generateKeys(): Buffer;
|
|
|
|
generateKeys(encoding: BinaryToTextEncoding): string;
|
|
|
|
generateKeys(_encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
notImplemented("crypto.DiffieHellman.prototype.generateKeys");
|
|
|
|
}
|
|
|
|
|
|
|
|
getGenerator(): Buffer;
|
|
|
|
getGenerator(encoding: BinaryToTextEncoding): string;
|
|
|
|
getGenerator(_encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
notImplemented("crypto.DiffieHellman.prototype.getGenerator");
|
|
|
|
}
|
|
|
|
|
|
|
|
getPrime(): Buffer;
|
|
|
|
getPrime(encoding: BinaryToTextEncoding): string;
|
|
|
|
getPrime(_encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
notImplemented("crypto.DiffieHellman.prototype.getPrime");
|
|
|
|
}
|
|
|
|
|
|
|
|
getPrivateKey(): Buffer;
|
|
|
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
|
|
|
getPrivateKey(_encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
notImplemented("crypto.DiffieHellman.prototype.getPrivateKey");
|
|
|
|
}
|
|
|
|
|
|
|
|
getPublicKey(): Buffer;
|
|
|
|
getPublicKey(encoding: BinaryToTextEncoding): string;
|
|
|
|
getPublicKey(_encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
notImplemented("crypto.DiffieHellman.prototype.getPublicKey");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ECDH {
|
2023-04-27 12:31:35 -04:00
|
|
|
#curve: EllipticCurve; // the selected curve
|
|
|
|
#privbuf: Buffer; // the private key
|
|
|
|
#pubbuf: Buffer; // the public key
|
|
|
|
|
2023-02-14 11:38:45 -05:00
|
|
|
constructor(curve: string) {
|
|
|
|
validateString(curve, "curve");
|
|
|
|
|
2023-04-27 12:31:35 -04:00
|
|
|
const c = ellipticCurves.find((x) => x.name == curve);
|
|
|
|
if (c == undefined) {
|
|
|
|
throw new Error("invalid curve");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.#curve = c;
|
|
|
|
this.#pubbuf = Buffer.alloc(this.#curve.publicKeySize);
|
|
|
|
this.#privbuf = Buffer.alloc(this.#curve.privateKeySize);
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static convertKey(
|
|
|
|
_key: BinaryLike,
|
|
|
|
_curve: string,
|
|
|
|
_inputEncoding?: BinaryToTextEncoding,
|
|
|
|
_outputEncoding?: "latin1" | "hex" | "base64" | "base64url",
|
|
|
|
_format?: "uncompressed" | "compressed" | "hybrid",
|
|
|
|
): Buffer | string {
|
|
|
|
notImplemented("crypto.ECDH.prototype.convertKey");
|
|
|
|
}
|
|
|
|
|
|
|
|
computeSecret(otherPublicKey: ArrayBufferView): Buffer;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: string,
|
|
|
|
inputEncoding: BinaryToTextEncoding,
|
|
|
|
): Buffer;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: ArrayBufferView,
|
|
|
|
outputEncoding: BinaryToTextEncoding,
|
|
|
|
): string;
|
|
|
|
computeSecret(
|
|
|
|
otherPublicKey: string,
|
|
|
|
inputEncoding: BinaryToTextEncoding,
|
|
|
|
outputEncoding: BinaryToTextEncoding,
|
|
|
|
): string;
|
|
|
|
computeSecret(
|
2023-04-27 12:31:35 -04:00
|
|
|
otherPublicKey: ArrayBufferView | string,
|
2023-02-14 11:38:45 -05:00
|
|
|
_inputEncoding?: BinaryToTextEncoding,
|
|
|
|
_outputEncoding?: BinaryToTextEncoding,
|
|
|
|
): Buffer | string {
|
2023-04-27 12:31:35 -04:00
|
|
|
const secretBuf = Buffer.alloc(this.#curve.sharedSecretSize);
|
|
|
|
|
|
|
|
ops.op_node_ecdh_compute_secret(
|
|
|
|
this.#curve.name,
|
|
|
|
this.#privbuf,
|
|
|
|
otherPublicKey,
|
|
|
|
secretBuf,
|
|
|
|
);
|
|
|
|
|
|
|
|
return secretBuf;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
generateKeys(): Buffer;
|
|
|
|
generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
|
|
|
|
generateKeys(
|
2023-04-27 12:31:35 -04:00
|
|
|
encoding?: BinaryToTextEncoding,
|
2023-02-14 11:38:45 -05:00
|
|
|
_format?: ECDHKeyFormat,
|
|
|
|
): Buffer | string {
|
2023-04-27 12:31:35 -04:00
|
|
|
ops.op_node_ecdh_generate_keys(
|
|
|
|
this.#curve.name,
|
|
|
|
this.#pubbuf,
|
|
|
|
this.#privbuf,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (encoding !== undefined) {
|
|
|
|
return this.#pubbuf.toString(encoding);
|
|
|
|
}
|
|
|
|
return this.#pubbuf;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrivateKey(): Buffer;
|
|
|
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
2023-04-27 12:31:35 -04:00
|
|
|
getPrivateKey(encoding?: BinaryToTextEncoding): Buffer | string {
|
|
|
|
if (encoding !== undefined) {
|
|
|
|
return this.#privbuf.toString(encoding);
|
|
|
|
}
|
|
|
|
return this.#privbuf;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
getPublicKey(): Buffer;
|
|
|
|
getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
|
|
|
|
getPublicKey(
|
2023-04-27 12:31:35 -04:00
|
|
|
encoding?: BinaryToTextEncoding,
|
2023-02-14 11:38:45 -05:00
|
|
|
_format?: ECDHKeyFormat,
|
|
|
|
): Buffer | string {
|
2023-04-27 12:31:35 -04:00
|
|
|
if (encoding !== undefined) {
|
|
|
|
return this.#pubbuf.toString(encoding);
|
|
|
|
}
|
|
|
|
return this.#pubbuf;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setPrivateKey(privateKey: ArrayBufferView): void;
|
|
|
|
setPrivateKey(privateKey: string, encoding: BinaryToTextEncoding): void;
|
|
|
|
setPrivateKey(
|
2023-04-27 12:31:35 -04:00
|
|
|
privateKey: ArrayBufferView | string,
|
|
|
|
encoding?: BinaryToTextEncoding,
|
2023-02-14 11:38:45 -05:00
|
|
|
): Buffer | string {
|
2023-04-27 12:31:35 -04:00
|
|
|
this.#privbuf = privateKey;
|
|
|
|
this.#pubbuf = Buffer.alloc(this.#curve.publicKeySize);
|
|
|
|
|
|
|
|
ops.op_node_ecdh_compute_public_key(
|
|
|
|
this.#curve.name,
|
|
|
|
this.#privbuf,
|
|
|
|
this.#pubbuf,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (encoding !== undefined) {
|
|
|
|
return this.#pubbuf.toString(encoding);
|
|
|
|
}
|
|
|
|
return this.#pubbuf;
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function diffieHellman(_options: {
|
|
|
|
privateKey: KeyObject;
|
|
|
|
publicKey: KeyObject;
|
|
|
|
}): Buffer {
|
|
|
|
notImplemented("crypto.diffieHellman");
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
DiffieHellman,
|
|
|
|
DiffieHellmanGroup,
|
|
|
|
ECDH,
|
|
|
|
diffieHellman,
|
|
|
|
};
|