Skip to content

Crypto: switched to OpenSSL EVP for hashing.#1039

Merged
xeioex merged 1 commit intonginx:masterfrom
xeioex:crypto_switch_to_openssl
Mar 31, 2026
Merged

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

Conversation

@xeioex
Copy link
Copy Markdown
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 2 times, most recently 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
@VadimZhestikov
Copy link
Copy Markdown
Contributor

Couple of non blocking things:

-- md stored in the digest/hmac structs appears unused after initialization/copy, so it may be removable?

-- since this PR intentionally changes standalone crypto availability for --no-openssl builds, it would be nice to add one explicit regression test (or at least a release note) covering that behavior change?

VadimZhestikov
VadimZhestikov previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Contributor

@VadimZhestikov VadimZhestikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

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
Copy link
Copy Markdown
Contributor Author

xeioex commented Mar 31, 2026

@VadimZhestikov

-- md stored in the digest/hmac structs appears unused after initialization/copy, so it may be removable?

agree. removed.

-- since this PR intentionally changes standalone crypto availability for --no-openssl builds, it would be nice to add one explicit regression test (or at least a release note) covering that behavior change?

  1. we do not have different tests for no-openssl builds, so it will be awkward.
  2. I will definitely mention it in the notes.

@xeioex xeioex requested a review from VadimZhestikov March 31, 2026 00:11
Copy link
Copy Markdown
Contributor

@VadimZhestikov VadimZhestikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, if tests are ok

@xeioex xeioex merged commit 3185ce8 into nginx:master Mar 31, 2026
2 checks passed
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

2 participants