347681c
From 5b2ec9a54037d7b007324bf53e067e73511cdfe4 Mon Sep 17 00:00:00 2001
347681c
From: Tomas Mraz <tmraz@fedoraproject.org>
347681c
Date: Thu, 26 Nov 2020 14:00:16 +0100
347681c
Subject: Add FIPS_mode() compatibility macro
347681c
347681c
The macro calls EVP_default_properties_is_fips_enabled() on the
347681c
default context.
347681c
---
347681c
 include/openssl/crypto.h.in |  1 +
347681c
 include/openssl/fips.h      | 25 +++++++++++++++++++++++++
347681c
 test/property_test.c        | 13 +++++++++++++
347681c
 3 files changed, 39 insertions(+)
347681c
 create mode 100644 include/openssl/fips.h
347681c
347681c
diff --git a/include/openssl/crypto.h.in b/include/openssl/crypto.h.in
347681c
index 1036da9a2b..9d4896fcaf 100644
347681c
--- a/include/openssl/crypto.h.in
347681c
+++ b/include/openssl/crypto.h.in
347681c
@@ -38,6 +38,7 @@ use OpenSSL::stackhash qw(generate_stack_macros);
347681c
 # include <openssl/opensslconf.h>
347681c
 # include <openssl/cryptoerr.h>
347681c
 # include <openssl/core.h>
347681c
+# include <openssl/fips.h>
347681c
 
347681c
 # ifdef CHARSET_EBCDIC
347681c
 #  include <openssl/ebcdic.h>
347681c
diff --git a/include/openssl/fips.h b/include/openssl/fips.h
347681c
new file mode 100644
347681c
index 0000000000..c64f0f8e8f
347681c
--- /dev/null
347681c
+++ b/include/openssl/fips.h
347681c
@@ -0,0 +1,25 @@
347681c
+/*
347681c
+ * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
347681c
+ *
347681c
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
347681c
+ * this file except in compliance with the License.  You can obtain a copy
347681c
+ * in the file LICENSE in the source distribution or at
347681c
+ * https://www.openssl.org/source/license.html
347681c
+ */
347681c
+
347681c
+#ifndef OPENSSL_FIPS_H
347681c
+# define OPENSSL_FIPS_H
347681c
+# pragma once
347681c
+
347681c
+# include <openssl/macros.h>
347681c
+
347681c
+# ifdef __cplusplus
347681c
+extern "C" {
347681c
+# endif
347681c
+
347681c
+# define FIPS_mode() EVP_default_properties_is_fips_enabled(NULL)
347681c
+
347681c
+# ifdef __cplusplus
347681c
+}
347681c
+# endif
347681c
+#endif
347681c
diff -up openssl-3.0.0-beta1/test/property_test.c.fips-macro openssl-3.0.0-beta1/test/property_test.c
347681c
--- openssl-3.0.0-beta1/test/property_test.c.fips-macro	2021-06-29 12:14:58.851557698 +0200
347681c
+++ openssl-3.0.0-beta1/test/property_test.c	2021-06-29 12:17:14.630143832 +0200
347681c
@@ -488,6 +488,18 @@ static int test_property_list_to_string(
347681c
     return ret;
347681c
 }
347681c
 
347681c
+static int test_downstream_FIPS_mode(void)
347681c
+{
347681c
+    int ret = 0;
347681c
+
347681c
+    ret = TEST_true(EVP_set_default_properties(NULL, "fips=yes"))
347681c
+          && TEST_true(FIPS_mode())
347681c
+          && TEST_true(EVP_set_default_properties(NULL, "fips=no"))
347681c
+          && TEST_false(FIPS_mode());
347681c
+
347681c
+    return ret;
347681c
+}
347681c
+
347681c
 int setup_tests(void)
347681c
 {
347681c
     ADD_TEST(test_property_string);
347681c
@@ -500,6 +512,7 @@ int setup_tests(void)
347681c
     ADD_TEST(test_property);
347681c
     ADD_TEST(test_query_cache_stochastic);
347681c
     ADD_TEST(test_fips_mode);
347681c
+    ADD_TEST(test_downstream_FIPS_mode);
347681c
     ADD_ALL_TESTS(test_property_list_to_string, OSSL_NELEM(to_string_tests));
347681c
     return 1;
347681c
 }