From ba27e72ff80f5fd9ca83896d09b0c08e4258aeab Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 27 Jul 2026 11:47:21 +0200 Subject: [PATCH] crypto: fix Argon2 bypassing FIPS mode The private OSSL_LIB_CTX used for OSSL_set_max_threads() inherits no configuration, so Argon2 escaped FIPS mode and --openssl-config. Check availability against the default context, and create the private one only when lanes > 1. Signed-off-by: Filip Skokan PR-URL: https://github.com/nodejs/node/pull/64776 Reviewed-By: Yagiz Nizipli --- deps/ncrypto/ncrypto.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc index 11d90043e55..ef5330c9a01 100644 --- a/deps/ncrypto/ncrypto.cc +++ b/deps/ncrypto/ncrypto.cc @@ -1996,15 +1996,24 @@ DataPointer argon2(const Buffer& pass, return {}; } - // creates a new library context to avoid locking when running concurrently - auto ctx = DeleteFnPtr{OSSL_LIB_CTX_new()}; - if (!ctx) { - return {}; - } + // A new library context is only needed for OSSL_set_max_threads(), which is + // per-context. It inherits no configuration, so availability is checked + // against the default context, otherwise Argon2 works in FIPS mode. + DeleteFnPtr ctx; + if (lanes > 1) { + if (!DeleteFnPtr{ + EVP_KDF_fetch(nullptr, algorithm.data(), nullptr)}) { + return {}; + } - // required if threads > 1 - if (lanes > 1 && OSSL_set_max_threads(ctx.get(), lanes) != 1) { - return {}; + ctx.reset(OSSL_LIB_CTX_new()); + if (!ctx) { + return {}; + } + + if (OSSL_set_max_threads(ctx.get(), lanes) != 1) { + return {}; + } } auto kdf = DeleteFnPtr{