Skip to content

Commit 0a23c1a

Browse files
panvaaduh95
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 339d5a1 commit 0a23c1a

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
@@ -2793,15 +2793,24 @@ DataPointer argon2(const Buffer<const char>& pass,
27932793
return {};
27942794
}
27952795

2796-
// creates a new library context to avoid locking when running concurrently
2797-
auto ctx = DeleteFnPtr<OSSL_LIB_CTX, OSSL_LIB_CTX_free>{OSSL_LIB_CTX_new()};
2798-
if (!ctx) {
2799-
return {};
2800-
}
2796+
// A new library context is only needed for OSSL_set_max_threads(), which is
2797+
// per-context. It inherits no configuration, so availability is checked
2798+
// against the default context, otherwise Argon2 works in FIPS mode.
2799+
DeleteFnPtr<OSSL_LIB_CTX, OSSL_LIB_CTX_free> ctx;
2800+
if (lanes > 1) {
2801+
if (!DeleteFnPtr<EVP_KDF, EVP_KDF_free>{
2802+
EVP_KDF_fetch(nullptr, algorithm.data(), nullptr)}) {
2803+
return {};
2804+
}
28012805

2802-
// required if threads > 1
2803-
if (lanes > 1 && OSSL_set_max_threads(ctx.get(), lanes) != 1) {
2804-
return {};
2806+
ctx.reset(OSSL_LIB_CTX_new());
2807+
if (!ctx) {
2808+
return {};
2809+
}
2810+
2811+
if (OSSL_set_max_threads(ctx.get(), lanes) != 1) {
2812+
return {};
2813+
}
28052814
}
28062815

28072816
auto kdf = DeleteFnPtr<EVP_KDF, EVP_KDF_free>{

0 commit comments

Comments
 (0)