From fb2c952f82064d747dbecb6ce66365ae4cc03513 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Wed, 6 Mar 2024 19:17:15 +0100
Subject: [PATCH 07/59] RH: Add FIPS_mode compatibility macro

Patch-name: 0008-Add-FIPS_mode-compatibility-macro.patch
Patch-id: 8
Patch-status: |
    # # Add FIPS_mode() compatibility macro
From-dist-git-commit: 4334bc837fbc64d14890fdc51679a80770d498ce
---
 include/openssl/fips.h | 26 ++++++++++++++++++++++++++
 test/property_test.c   | 14 ++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 include/openssl/fips.h

diff --git a/include/openssl/fips.h b/include/openssl/fips.h
new file mode 100644
index 0000000000..4162cbf88e
--- /dev/null
+++ b/include/openssl/fips.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#ifndef OPENSSL_FIPS_H
+# define OPENSSL_FIPS_H
+# pragma once
+
+# include <openssl/evp.h>
+# include <openssl/macros.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define FIPS_mode() EVP_default_properties_is_fips_enabled(NULL)
+
+# ifdef __cplusplus
+}
+# endif
+#endif
diff --git a/test/property_test.c b/test/property_test.c
index e62ff247c4..37489e4694 100644
--- a/test/property_test.c
+++ b/test/property_test.c
@@ -703,6 +703,19 @@ static int test_property_list_to_string_bounds(void)
     return ret;
 }
 
+#include <openssl/fips.h>
+static int test_downstream_FIPS_mode(void)
+{
+    int ret = 0;
+
+    ret = TEST_true(EVP_set_default_properties(NULL, "fips=yes"))
+          && TEST_true(FIPS_mode())
+          && TEST_true(EVP_set_default_properties(NULL, "fips=no"))
+          && TEST_false(FIPS_mode());
+
+    return ret;
+}
+
 int setup_tests(void)
 {
     ADD_TEST(test_property_string);
@@ -716,6 +729,7 @@ int setup_tests(void)
     ADD_TEST(test_property);
     ADD_TEST(test_query_cache_stochastic);
     ADD_TEST(test_fips_mode);
+    ADD_TEST(test_downstream_FIPS_mode);
     ADD_ALL_TESTS(test_property_list_to_string, OSSL_NELEM(to_string_tests));
     ADD_TEST(test_property_list_to_string_bounds);
     return 1;
-- 
2.51.0

