Skip to content

Crypto: switched to OpenSSL EVP for hashing.#1039

Open
xeioex wants to merge 1 commit intonginx:masterfrom
xeioex:crypto_switch_to_openssl
Open

Crypto: switched to OpenSSL EVP for hashing.#1039
xeioex wants to merge 1 commit intonginx:masterfrom
xeioex:crypto_switch_to_openssl

Conversation

@xeioex
Copy link
Contributor

@xeioex xeioex commented Mar 24, 2026

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 pattern already established by 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.

@xeioex xeioex force-pushed the crypto_switch_to_openssl branch from 057de5b to 578f559 Compare March 24, 2026 05:27
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 nginx#1037 feature request on Github.
@xeioex xeioex force-pushed the crypto_switch_to_openssl branch from 578f559 to d6dd62f Compare March 25, 2026 02:04
@xeioex xeioex marked this pull request as ready for review March 25, 2026 02:51
@xeioex xeioex requested a review from VadimZhestikov March 25, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for other openssl algorithms in crypto functions

1 participant