diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-01-11 07:37:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 15:37:25 -0700 |
commit | 515a34b4de222e35c7ade1b92614d746e73d4c2e (patch) | |
tree | 8284201fc826a33f12597959a8a8be14e0f524bd /ext/node/polyfills/internal/crypto/diffiehellman.ts | |
parent | d4893eb51a01c5a692d8ca74a3b8ff95c5fd1d9f (diff) |
refactor: use `core.ensureFastOps()` (#21888)
Diffstat (limited to 'ext/node/polyfills/internal/crypto/diffiehellman.ts')
-rw-r--r-- | ext/node/polyfills/internal/crypto/diffiehellman.ts | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts index 315c37278..fbcdab185 100644 --- a/ext/node/polyfills/internal/crypto/diffiehellman.ts +++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts @@ -4,6 +4,18 @@ // TODO(petamoriken): enable prefer-primordials for node polyfills // deno-lint-ignore-file prefer-primordials +import { core } from "ext:core/mod.js"; +const { + op_node_dh_compute_secret, + op_node_dh_generate2, + op_node_ecdh_compute_secret, + op_node_ecdh_generate_keys, + op_node_ecdh_compute_public_key, +} = core.ensureFastOps(); +const { + op_node_gen_prime, +} = core.ensureFastOps(true); + import { notImplemented } from "ext:deno_node/_utils.ts"; import { isAnyArrayBuffer, @@ -33,8 +45,6 @@ import type { import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts"; import type { BufferEncoding } from "ext:deno_node/_global.d.ts"; -const { ops } = Deno.core; - const DH_GENERATOR = 2; export class DiffieHellman { @@ -92,7 +102,7 @@ export class DiffieHellman { } this.#prime = Buffer.from( - ops.op_node_gen_prime(this.#primeLength).buffer, + op_node_gen_prime(this.#primeLength).buffer, ); } @@ -173,7 +183,7 @@ export class DiffieHellman { buf = Buffer.from(otherPublicKey.buffer); } - const sharedSecret = ops.op_node_dh_compute_secret( + const sharedSecret = op_node_dh_compute_secret( this.#prime, this.#privateKey, buf, @@ -190,7 +200,7 @@ export class DiffieHellman { generateKeys(encoding: BinaryToTextEncoding): string; generateKeys(_encoding?: BinaryToTextEncoding): Buffer | string { const generator = this.#checkGenerator(); - const [privateKey, publicKey] = ops.op_node_dh_generate2( + const [privateKey, publicKey] = op_node_dh_generate2( this.#prime, this.#primeLength ?? 0, generator, @@ -1215,7 +1225,7 @@ export class ECDH { ): Buffer | string { const secretBuf = Buffer.alloc(this.#curve.sharedSecretSize); - ops.op_node_ecdh_compute_secret( + op_node_ecdh_compute_secret( this.#curve.name, this.#privbuf, otherPublicKey, @@ -1231,7 +1241,7 @@ export class ECDH { encoding?: BinaryToTextEncoding, _format?: ECDHKeyFormat, ): Buffer | string { - ops.op_node_ecdh_generate_keys( + op_node_ecdh_generate_keys( this.#curve.name, this.#pubbuf, this.#privbuf, @@ -1273,7 +1283,7 @@ export class ECDH { this.#privbuf = privateKey; this.#pubbuf = Buffer.alloc(this.#curve.publicKeySize); - ops.op_node_ecdh_compute_public_key( + op_node_ecdh_compute_public_key( this.#curve.name, this.#privbuf, this.#pubbuf, |