@@ -2937,7 +2937,9 @@ DataPointer argon2(const Buffer<const char>& pass, |
2937 | 2937 | // per-context. It inherits no configuration, so availability is checked |
2938 | 2938 | // against the default context, otherwise Argon2 works in FIPS mode. |
2939 | 2939 | DeleteFnPtr<OSSL_LIB_CTX, OSSL_LIB_CTX_free> ctx; |
2940 | | - if (lanes > 1) { |
| 2940 | + uint32_t threads = lanes == 0 ? 0 : 1; |
| 2941 | + if (lanes > 1 && (OSSL_get_thread_support_flags() & |
| 2942 | + OSSL_THREAD_SUPPORT_FLAG_DEFAULT_SPAWN) != 0) { |
2941 | 2943 | if (!KDF::Fetch(algorithm.data())) { |
2942 | 2944 | return {}; |
2943 | 2945 | } |
@@ -2947,8 +2949,13 @@ DataPointer argon2(const Buffer<const char>& pass, |
2947 | 2949 | return {}; |
2948 | 2950 | } |
2949 | 2951 |
|
2950 | | - if (OSSL_set_max_threads(ctx.get(), lanes) != 1) { |
2951 | | - return {}; |
| 2952 | + MarkPopErrorOnReturn mark_pop_error_on_return; |
| 2953 | + if (OSSL_set_max_threads(ctx.get(), lanes) == 1) { |
| 2954 | + threads = lanes; |
| 2955 | + } else { |
| 2956 | + // Lane count is an Argon2 input; worker threads are only an |
| 2957 | + // optimization. Compute the same lanes serially if unavailable. |
| 2958 | + ctx.reset(); |
2952 | 2959 | } |
2953 | 2960 | } |
2954 | 2961 |
|
@@ -2966,7 +2973,8 @@ DataPointer argon2(const Buffer<const char>& pass, |
2966 | 2973 | pass.len)); |
2967 | 2974 | params.push_back(OSSL_PARAM_construct_octet_string( |
2968 | 2975 | OSSL_KDF_PARAM_SALT, const_cast<unsigned char*>(salt.data), salt.len)); |
2969 | | - params.push_back(OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_THREADS, &lanes)); |
| 2976 | + params.push_back( |
| 2977 | + OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_THREADS, &threads)); |
2970 | 2978 | params.push_back( |
2971 | 2979 | OSSL_PARAM_construct_uint32(OSSL_KDF_PARAM_ARGON2_LANES, &lanes)); |
2972 | 2980 | params.push_back( |
|