diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-12-26 18:30:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 02:30:26 +0100 |
commit | 0efe438f7c191d8504355e03b27fe7e3055c9387 (patch) | |
tree | b96fe9a897eb6941c87a95a04520662d26c02fbe /ext/node/polyfills/internal/crypto | |
parent | e33c5eb704c22fad69876e87d9b852a4e5072a7a (diff) |
perf: remove opAsync (#21690)
`opAsync` requires a lookup by name on each async call. This is a
mechanical translation of all opAsync calls to ensureFastOps.
The `opAsync` API on Deno.core will be removed at a later time.
Diffstat (limited to 'ext/node/polyfills/internal/crypto')
-rw-r--r-- | ext/node/polyfills/internal/crypto/_randomFill.mjs | 5 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/hkdf.ts | 5 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/keygen.ts | 32 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/pbkdf2.ts | 4 | ||||
-rw-r--r-- | ext/node/polyfills/internal/crypto/scrypt.ts | 6 |
5 files changed, 33 insertions, 19 deletions
diff --git a/ext/node/polyfills/internal/crypto/_randomFill.mjs b/ext/node/polyfills/internal/crypto/_randomFill.mjs index 6afc654b4..7f66cfb4b 100644 --- a/ext/node/polyfills/internal/crypto/_randomFill.mjs +++ b/ext/node/polyfills/internal/crypto/_randomFill.mjs @@ -11,6 +11,9 @@ import { isAnyArrayBuffer, isArrayBufferView } from "node:util/types"; import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts"; const { core } = globalThis.__bootstrap; const { ops } = core; +const { + op_node_generate_secret_async, +} = core.ensureFastOps(); const kBufferMaxLength = 0x7fffffff; @@ -52,7 +55,7 @@ export default function randomFill( assertOffset(offset, buf.length); assertSize(size, offset, buf.length); - core.opAsync("op_node_generate_secret_async", Math.floor(size)) + op_node_generate_secret_async(Math.floor(size)) .then( (randomData) => { const randomBuf = Buffer.from(randomData.buffer); diff --git a/ext/node/polyfills/internal/crypto/hkdf.ts b/ext/node/polyfills/internal/crypto/hkdf.ts index 4454b0488..8f3e8c7a9 100644 --- a/ext/node/polyfills/internal/crypto/hkdf.ts +++ b/ext/node/polyfills/internal/crypto/hkdf.ts @@ -33,6 +33,9 @@ import { const { core } = globalThis.__bootstrap; const { ops } = core; +const { + op_node_hkdf_async, +} = core.ensureFastOps(); const validateParameters = hideStackFrames((hash, key, salt, info, length) => { validateString(hash, "digest"); @@ -109,7 +112,7 @@ export function hkdf( validateFunction(callback, "callback"); - core.opAsync("op_node_hkdf_async", hash, key, salt, info, length) + op_node_hkdf_async(hash, key, salt, info, length) .then((okm) => callback(null, okm.buffer)) .catch((err) => callback(new ERR_CRYPTO_INVALID_DIGEST(err), undefined)); } diff --git a/ext/node/polyfills/internal/crypto/keygen.ts b/ext/node/polyfills/internal/crypto/keygen.ts index 29a062e00..f757f5eaf 100644 --- a/ext/node/polyfills/internal/crypto/keygen.ts +++ b/ext/node/polyfills/internal/crypto/keygen.ts @@ -31,6 +31,16 @@ import { KeyFormat, KeyType } from "ext:deno_node/internal/crypto/types.ts"; const { core } = globalThis.__bootstrap; const { ops } = core; +const { + op_node_dh_generate_async, + op_node_dh_generate_group_async, + op_node_dsa_generate_async, + op_node_ec_generate_async, + op_node_generate_rsa_async, + op_node_generate_secret_async, + op_node_ed25519_generate_async, + op_node_x25519_generate_async, +} = core.ensureFastOps(); function validateGenerateKey( type: "hmac" | "aes", @@ -81,7 +91,7 @@ export function generateKey( validateFunction(callback, "callback"); const { length } = options; - core.opAsync("op_node_generate_secret_async", Math.floor(length / 8)).then( + op_node_generate_secret_async(Math.floor(length / 8)).then( (key) => { callback(null, new SecretKeyObject(setOwnedKey(key))); }, @@ -799,8 +809,7 @@ function createJob(mode, type, options) { publicExponent, ); } else { - return core.opAsync( - "op_node_generate_rsa_async", + return op_node_generate_rsa_async( modulusLength, publicExponent, ); @@ -855,8 +864,7 @@ function createJob(mode, type, options) { publicExponent, ); } else { - return core.opAsync( - "op_node_generate_rsa_async", + return op_node_generate_rsa_async( modulusLength, publicExponent, ); @@ -877,8 +885,7 @@ function createJob(mode, type, options) { if (mode === kSync) { return ops.op_node_dsa_generate(modulusLength, divisorLength); } - return core.opAsync( - "op_node_dsa_generate_async", + return op_node_dsa_generate_async( modulusLength, divisorLength, ); @@ -900,20 +907,20 @@ function createJob(mode, type, options) { if (mode === kSync) { return ops.op_node_ec_generate(namedCurve); } else { - return core.opAsync("op_node_ec_generate_async", namedCurve); + return op_node_ec_generate_async(namedCurve); } } case "ed25519": { if (mode === kSync) { return ops.op_node_ed25519_generate(); } - return core.opAsync("op_node_ed25519_generate_async"); + return op_node_ed25519_generate_async(); } case "x25519": { if (mode === kSync) { return ops.op_node_x25519_generate(); } - return core.opAsync("op_node_x25519_generate_async"); + return op_node_x25519_generate_async(); } case "ed448": case "x448": { @@ -939,7 +946,7 @@ function createJob(mode, type, options) { if (mode === kSync) { return ops.op_node_dh_generate_group(group); } else { - return core.opAsync("op_node_dh_generate_group_async", group); + return op_node_dh_generate_group_async(group); } } @@ -966,8 +973,7 @@ function createJob(mode, type, options) { if (mode === kSync) { return ops.op_node_dh_generate(prime, primeLength ?? 0, g); } else { - return core.opAsync( - "op_node_dh_generate_async", + return op_node_dh_generate_async( prime, primeLength ?? 0, g, diff --git a/ext/node/polyfills/internal/crypto/pbkdf2.ts b/ext/node/polyfills/internal/crypto/pbkdf2.ts index f177d153a..50cc3a83e 100644 --- a/ext/node/polyfills/internal/crypto/pbkdf2.ts +++ b/ext/node/polyfills/internal/crypto/pbkdf2.ts @@ -8,6 +8,7 @@ import { HASH_DATA } from "ext:deno_node/internal/crypto/types.ts"; const { core } = globalThis.__bootstrap; const { ops } = core; +const { op_node_pbkdf2_async } = core.ensureFastOps(); export const MAX_ALLOC = Math.pow(2, 30) - 1; @@ -77,8 +78,7 @@ export function pbkdf2( throw new TypeError("Bad key length"); } - core.opAsync( - "op_node_pbkdf2_async", + op_node_pbkdf2_async( password, salt, iterations, diff --git a/ext/node/polyfills/internal/crypto/scrypt.ts b/ext/node/polyfills/internal/crypto/scrypt.ts index e87cdb856..2ceac5139 100644 --- a/ext/node/polyfills/internal/crypto/scrypt.ts +++ b/ext/node/polyfills/internal/crypto/scrypt.ts @@ -31,6 +31,9 @@ import { HASH_DATA } from "ext:deno_node/internal/crypto/types.ts"; const { core } = globalThis.__bootstrap; const { ops } = core; +const { + op_node_scrypt_async, +} = core.ensureFastOps(); type Opts = Partial<{ N: number; @@ -110,8 +113,7 @@ export function scrypt( } try { - core.opAsync( - "op_node_scrypt_async", + op_node_scrypt_async( password, salt, keylen, |