Skip to content

Commit b6a9111

Browse files
panvanodejs-github-bot
authored andcommitted
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 <panva.ip@gmail.com> PR-URL: #64776 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent e0e37fe commit b6a9111

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

deps/ncrypto/ncrypto.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,15 +2832,24 @@ DataPointer argon2(const Buffer<const char>& pass,
28322832
return {};
28332833
}
28342834

2835-
// creates a new library context to avoid locking when running concurrently
2836-
auto ctx = DeleteFnPtr<OSSL_LIB_CTX, OSSL_LIB_CTX_free>{OSSL_LIB_CTX_new()};
2837-
if (!ctx) {
2838-
return {};
2839-
}
2835+
// A new library context is only needed for OSSL_set_max_threads(), which is
2836+
// per-context. It inherits no configuration, so availability is checked
2837+
// against the default context, otherwise Argon2 works in FIPS mode.
2838+
DeleteFnPtr<OSSL_LIB_CTX, OSSL_LIB_CTX_free> ctx;
2839+
if (lanes > 1) {
2840+
if (!DeleteFnPtr<EVP_KDF, EVP_KDF_free>{
2841+
EVP_KDF_fetch(nullptr, algorithm.data(), nullptr)}) {
2842+
return {};
2843+
}
28402844

2841-
// required if threads > 1
2842-
if (lanes > 1 && OSSL_set_max_threads(ctx.get(), lanes) != 1) {
2843-
return {};
2845+
ctx.reset(OSSL_LIB_CTX_new());
2846+
if (!ctx) {
2847+
return {};
2848+
}
2849+
2850+
if (OSSL_set_max_threads(ctx.get(), lanes) != 1) {
2851+
return {};
2852+
}
28442853
}
28452854

28462855
auto kdf = DeleteFnPtr<EVP_KDF, EVP_KDF_free>{

0 commit comments

Comments
 (0)