From 922f2f0eb279d4d073ad2bb604a69630c65f866e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 24 Feb 2021 13:13:42 +0100 Subject: [PATCH] crypto: add optional callback to crypto.sign and crypto.verify PR-URL: https://github.com/nodejs/node/pull/37500 Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- doc/api/crypto.md | 26 +++- lib/internal/crypto/dsa.js | 4 +- lib/internal/crypto/ec.js | 4 +- lib/internal/crypto/rsa.js | 3 +- lib/internal/crypto/sig.js | 117 +++++++++++++--- src/crypto/crypto_ec.cc | 127 +++++++++++++----- src/crypto/crypto_ec.h | 4 +- src/crypto/crypto_sig.cc | 36 ++++- src/crypto/crypto_sig.h | 4 +- src/crypto/crypto_util.h | 2 +- .../parallel/test-crypto-async-sign-verify.js | 108 +++++++++++++++ 11 files changed, 361 insertions(+), 74 deletions(-) create mode 100644 test/parallel/test-crypto-async-sign-verify.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 4c55bcaa9cab81..96dcac7f2c460e 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -3822,10 +3822,13 @@ added: v10.0.0 Enables the FIPS compliant crypto provider in a FIPS-enabled Node.js build. Throws an error if FIPS mode is not available. -### `crypto.sign(algorithm, data, key)` +### `crypto.sign(algorithm, data, key[, callback])` Calculates and returns the signature for `data` using the given private key and @@ -3864,6 +3870,8 @@ additional properties can be passed: size, `crypto.constants.RSA_PSS_SALTLEN_MAX_SIGN` (default) sets it to the maximum permissible value. +If the `callback` function is provided this function uses libuv's threadpool. + ### `crypto.timingSafeEqual(a, b)` Verifies the given signature for `data` using the given key and algorithm. If @@ -3945,6 +3961,8 @@ The `signature` argument is the previously calculated signature for the `data`. Because public keys can be derived from private keys, a private key or a public key may be passed for `key`. +If the `callback` function is provided this function uses libuv's threadpool. + ### `crypto.webcrypto`