e52367a
From 48c763ed9cc889806bc01222382ce6f918a408a2 Mon Sep 17 00:00:00 2001
e52367a
From: Dmitry Belyavskiy <dbelyavs@redhat.com>
e52367a
Date: Mon, 21 Aug 2023 16:12:33 +0200
e52367a
Subject: [PATCH 46/48] 
e52367a
 0112-pbdkf2-Set-indicator-if-pkcs5-param-disabled-checks.patch
e52367a
e52367a
Patch-name: 0112-pbdkf2-Set-indicator-if-pkcs5-param-disabled-checks.patch
e52367a
Patch-id: 112
e52367a
---
e52367a
 providers/implementations/kdfs/pbkdf2.c | 40 +++++++++++++++++++++++--
e52367a
 1 file changed, 37 insertions(+), 3 deletions(-)
e52367a
e52367a
diff --git a/providers/implementations/kdfs/pbkdf2.c b/providers/implementations/kdfs/pbkdf2.c
e52367a
index 11820d1e69..bae2238ab5 100644
e52367a
--- a/providers/implementations/kdfs/pbkdf2.c
e52367a
+++ b/providers/implementations/kdfs/pbkdf2.c
e52367a
@@ -284,11 +284,42 @@ static const OSSL_PARAM *kdf_pbkdf2_settable_ctx_params(ossl_unused void *ctx,
e52367a
 
e52367a
 static int kdf_pbkdf2_get_ctx_params(void *vctx, OSSL_PARAM params[])
e52367a
 {
e52367a
+#ifdef FIPS_MODULE
e52367a
+    KDF_PBKDF2 *ctx = (KDF_PBKDF2 *)vctx;
e52367a
+#endif /* defined(FIPS_MODULE) */
e52367a
     OSSL_PARAM *p;
e52367a
+    int any_valid = 0; /* set to 1 when at least one parameter was valid */
e52367a
+
e52367a
+    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL) {
e52367a
+        any_valid = 1;
e52367a
+
e52367a
+        if (!OSSL_PARAM_set_size_t(p, SIZE_MAX))
e52367a
+            return 0;
e52367a
+    }
e52367a
+
e52367a
+#ifdef FIPS_MODULE
e52367a
+    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_REDHAT_FIPS_INDICATOR))
e52367a
+            != NULL) {
e52367a
+        int fips_indicator = EVP_KDF_REDHAT_FIPS_INDICATOR_APPROVED;
e52367a
+
e52367a
+        /* The lower_bound_checks parameter enables checks required by FIPS. If
e52367a
+         * those checks are disabled, the PBKDF2 implementation will also
e52367a
+         * support non-approved parameters (e.g., salt lengths < 16 bytes, see
e52367a
+         * NIST SP 800-132 section 5.1). */
e52367a
+        if (!ctx->lower_bound_checks)
e52367a
+            fips_indicator = EVP_KDF_REDHAT_FIPS_INDICATOR_NOT_APPROVED;
e52367a
 
e52367a
-    if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL)
e52367a
-        return OSSL_PARAM_set_size_t(p, SIZE_MAX);
e52367a
-    return -2;
e52367a
+        if (!OSSL_PARAM_set_int(p, fips_indicator))
e52367a
+            return 0;
e52367a
+
e52367a
+        any_valid = 1;
e52367a
+    }
e52367a
+#endif /* defined(FIPS_MODULE) */
e52367a
+
e52367a
+    if (!any_valid)
e52367a
+        return -2;
e52367a
+
e52367a
+    return 1;
e52367a
 }
e52367a
 
e52367a
 static const OSSL_PARAM *kdf_pbkdf2_gettable_ctx_params(ossl_unused void *ctx,
e52367a
@@ -296,6 +327,9 @@ static const OSSL_PARAM *kdf_pbkdf2_gettable_ctx_params(ossl_unused void *ctx,
e52367a
 {
e52367a
     static const OSSL_PARAM known_gettable_ctx_params[] = {
e52367a
         OSSL_PARAM_size_t(OSSL_KDF_PARAM_SIZE, NULL),
e52367a
+#ifdef FIPS_MODULE
e52367a
+        OSSL_PARAM_int(OSSL_KDF_PARAM_REDHAT_FIPS_INDICATOR, NULL),
e52367a
+#endif /* defined(FIPS_MODULE) */
e52367a
         OSSL_PARAM_END
e52367a
     };
e52367a
     return known_gettable_ctx_params;
e52367a
-- 
e52367a
2.41.0
e52367a