Skip to content

Commit d6dd62f

Browse files
committed
Crypto: switched to OpenSSL EVP for hashing.
Previously, the crypto module used built-in software implementations for a limited set of hash algorithms (md5, sha1, sha256). This prevented users from using algorithms like sha384, sha512, and sha3 family, even when the underlying OpenSSL library supported them. The change replaces built-in hash implementations with OpenSSL EVP_MD_CTX for createHash() and HMAC_CTX for createHmac(), following the webcrypto module. Algorithm lookup now uses EVP_get_digestbyname(), making any digest supported by the linked OpenSSL available to JavaScript code. The module now requires OpenSSL and is conditionally compiled, same as the webcrypto module. Builds without OpenSSL (--no-openssl) will no longer have the crypto module available. Tested with OpenSSL 3.0, OpenSSL 1.1.1w, LibreSSL 3.9.2, and BoringSSL. SHA-3 tests are skipped when the SSL library does not support them (e.g. BoringSSL). This closes #1037 feature request on Github.
1 parent 8f42e99 commit d6dd62f

File tree

12 files changed

+417
-1202
lines changed

12 files changed

+417
-1202
lines changed

auto/modules

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ njs_module_srcs=src/njs_buffer.c
77

88
. auto/module
99

10-
njs_module_name=njs_crypto_module
11-
njs_module_incs=
12-
njs_module_srcs="external/njs_crypto_module.c \
13-
external/njs_md5.c \
14-
external/njs_sha1.c \
15-
external/njs_sha2.c"
10+
if [ $NJS_OPENSSL = YES -a $NJS_HAVE_OPENSSL = YES ]; then
11+
njs_module_name=njs_crypto_module
12+
njs_module_incs=
13+
njs_module_srcs=external/njs_crypto_module.c
1614

17-
. auto/module
15+
. auto/module
1816

19-
if [ $NJS_OPENSSL = YES -a $NJS_HAVE_OPENSSL = YES ]; then
2017
njs_module_name=njs_webcrypto_module
2118
njs_module_incs=
2219
njs_module_srcs=external/njs_webcrypto_module.c

auto/qjs_modules

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ njs_module_srcs=src/qjs_buffer.c
77

88
. auto/qjs_module
99

10-
njs_module_name=qjs_crypto_module
11-
njs_module_incs=
12-
njs_module_srcs=external/qjs_crypto_module.c
10+
if [ $NJS_OPENSSL = YES -a $NJS_HAVE_OPENSSL = YES ]; then
11+
njs_module_name=qjs_crypto_module
12+
njs_module_incs=
13+
njs_module_srcs=external/qjs_crypto_module.c
1314

14-
. auto/qjs_module
15+
. auto/qjs_module
16+
fi
1517

1618
njs_module_name=qjs_fs_module
1719
njs_module_incs=

0 commit comments

Comments
 (0)