Blame SOURCES/fips-17u-765f970aef1.patch

d9bc5f
diff --git a/make/autoconf/lib-sysconf.m4 b/make/autoconf/lib-sysconf.m4
d9bc5f
new file mode 100644
d9bc5f
index 00000000000..b2b1c1787da
d9bc5f
--- /dev/null
d9bc5f
+++ b/make/autoconf/lib-sysconf.m4
d9bc5f
@@ -0,0 +1,84 @@
d9bc5f
+#
d9bc5f
+# Copyright (c) 2021, Red Hat, Inc.
d9bc5f
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9bc5f
+#
d9bc5f
+# This code is free software; you can redistribute it and/or modify it
d9bc5f
+# under the terms of the GNU General Public License version 2 only, as
d9bc5f
+# published by the Free Software Foundation.  Oracle designates this
d9bc5f
+# particular file as subject to the "Classpath" exception as provided
d9bc5f
+# by Oracle in the LICENSE file that accompanied this code.
d9bc5f
+#
d9bc5f
+# This code is distributed in the hope that it will be useful, but WITHOUT
d9bc5f
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9bc5f
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9bc5f
+# version 2 for more details (a copy is included in the LICENSE file that
d9bc5f
+# accompanied this code).
d9bc5f
+#
d9bc5f
+# You should have received a copy of the GNU General Public License version
d9bc5f
+# 2 along with this work; if not, write to the Free Software Foundation,
d9bc5f
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9bc5f
+#
d9bc5f
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9bc5f
+# or visit www.oracle.com if you need additional information or have any
d9bc5f
+# questions.
d9bc5f
+#
d9bc5f
+
d9bc5f
+################################################################################
d9bc5f
+# Setup system configuration libraries
d9bc5f
+################################################################################
d9bc5f
+AC_DEFUN_ONCE([LIB_SETUP_SYSCONF_LIBS],
d9bc5f
+[
d9bc5f
+  ###############################################################################
d9bc5f
+  #
d9bc5f
+  # Check for the NSS library
d9bc5f
+  #
d9bc5f
+
d9bc5f
+  AC_MSG_CHECKING([whether to use the system NSS library with the System Configurator (libsysconf)])
d9bc5f
+
d9bc5f
+  # default is not available
d9bc5f
+  DEFAULT_SYSCONF_NSS=no
d9bc5f
+
d9bc5f
+  AC_ARG_ENABLE([sysconf-nss], [AS_HELP_STRING([--enable-sysconf-nss],
d9bc5f
+     [build the System Configurator (libsysconf) using the system NSS library if available @<:@disabled@:>@])],
d9bc5f
+  [
d9bc5f
+    case "${enableval}" in
d9bc5f
+      yes)
d9bc5f
+        sysconf_nss=yes
d9bc5f
+        ;;
d9bc5f
+      *)
d9bc5f
+        sysconf_nss=no
d9bc5f
+        ;;
d9bc5f
+    esac
d9bc5f
+  ],
d9bc5f
+  [
d9bc5f
+    sysconf_nss=${DEFAULT_SYSCONF_NSS}
d9bc5f
+  ])
d9bc5f
+  AC_MSG_RESULT([$sysconf_nss])
d9bc5f
+
d9bc5f
+  USE_SYSCONF_NSS=false
d9bc5f
+  if test "x${sysconf_nss}" = "xyes"; then
d9bc5f
+      PKG_CHECK_MODULES(NSS, nss >= 3.53, [NSS_FOUND=yes], [NSS_FOUND=no])
d9bc5f
+      if test "x${NSS_FOUND}" = "xyes"; then
d9bc5f
+         AC_MSG_CHECKING([for system FIPS support in NSS])
d9bc5f
+         saved_libs="${LIBS}"
d9bc5f
+         saved_cflags="${CFLAGS}"
d9bc5f
+         CFLAGS="${CFLAGS} ${NSS_CFLAGS}"
d9bc5f
+         LIBS="${LIBS} ${NSS_LIBS}"
d9bc5f
+         AC_LANG_PUSH([C])
d9bc5f
+         AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nss3/pk11pub.h>]],
d9bc5f
+                                         [[SECMOD_GetSystemFIPSEnabled()]])],
d9bc5f
+                        [AC_MSG_RESULT([yes])],
d9bc5f
+                        [AC_MSG_RESULT([no])
d9bc5f
+                        AC_MSG_ERROR([System NSS FIPS detection unavailable])])
d9bc5f
+         AC_LANG_POP([C])
d9bc5f
+         CFLAGS="${saved_cflags}"
d9bc5f
+         LIBS="${saved_libs}"
d9bc5f
+         USE_SYSCONF_NSS=true
d9bc5f
+      else
d9bc5f
+         dnl NSS 3.53 is the one that introduces the SECMOD_GetSystemFIPSEnabled API
d9bc5f
+         dnl in nss3/pk11pub.h.
d9bc5f
+         AC_MSG_ERROR([--enable-sysconf-nss specified, but NSS 3.53 or above not found.])
d9bc5f
+      fi
d9bc5f
+  fi
d9bc5f
+  AC_SUBST(USE_SYSCONF_NSS)
d9bc5f
+])
d9bc5f
diff --git a/make/autoconf/libraries.m4 b/make/autoconf/libraries.m4
d9bc5f
index a65d91ee974..a8f054c1397 100644
d9bc5f
--- a/make/autoconf/libraries.m4
d9bc5f
+++ b/make/autoconf/libraries.m4
d9bc5f
@@ -33,6 +33,7 @@ m4_include([lib-std.m4])
d9bc5f
 m4_include([lib-x11.m4])
d9bc5f
 m4_include([lib-fontconfig.m4])
d9bc5f
 m4_include([lib-tests.m4])
d9bc5f
+m4_include([lib-sysconf.m4])
d9bc5f
 
d9bc5f
 ################################################################################
d9bc5f
 # Determine which libraries are needed for this configuration
d9bc5f
@@ -104,6 +105,7 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES],
d9bc5f
   LIB_SETUP_BUNDLED_LIBS
d9bc5f
   LIB_SETUP_MISC_LIBS
d9bc5f
   LIB_TESTS_SETUP_GTEST
d9bc5f
+  LIB_SETUP_SYSCONF_LIBS
d9bc5f
 
d9bc5f
   BASIC_JDKLIB_LIBS=""
d9bc5f
   if test "x$TOOLCHAIN_TYPE" != xmicrosoft; then
d9bc5f
diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in
d9bc5f
index c2c9c4adf3a..9d105b37acf 100644
d9bc5f
--- a/make/autoconf/spec.gmk.in
d9bc5f
+++ b/make/autoconf/spec.gmk.in
d9bc5f
@@ -836,6 +836,10 @@ INSTALL_SYSCONFDIR=@sysconfdir@
d9bc5f
 # Libraries
d9bc5f
 #
d9bc5f
 
d9bc5f
+USE_SYSCONF_NSS:=@USE_SYSCONF_NSS@
d9bc5f
+NSS_LIBS:=@NSS_LIBS@
d9bc5f
+NSS_CFLAGS:=@NSS_CFLAGS@
d9bc5f
+
d9bc5f
 USE_EXTERNAL_LCMS:=@USE_EXTERNAL_LCMS@
d9bc5f
 LCMS_CFLAGS:=@LCMS_CFLAGS@
d9bc5f
 LCMS_LIBS:=@LCMS_LIBS@
d9bc5f
diff --git a/make/modules/java.base/Lib.gmk b/make/modules/java.base/Lib.gmk
d9bc5f
index 5658ff342e5..cb7a56852f7 100644
d9bc5f
--- a/make/modules/java.base/Lib.gmk
d9bc5f
+++ b/make/modules/java.base/Lib.gmk
d9bc5f
@@ -167,6 +167,31 @@ ifeq ($(call isTargetOsType, unix), true)
d9bc5f
   endif
d9bc5f
 endif
d9bc5f
 
d9bc5f
+################################################################################
d9bc5f
+# Create the systemconf library
d9bc5f
+
d9bc5f
+LIBSYSTEMCONF_CFLAGS :=
d9bc5f
+LIBSYSTEMCONF_CXXFLAGS :=
d9bc5f
+
d9bc5f
+ifeq ($(USE_SYSCONF_NSS), true)
d9bc5f
+  LIBSYSTEMCONF_CFLAGS += $(NSS_CFLAGS) -DSYSCONF_NSS
d9bc5f
+  LIBSYSTEMCONF_CXXFLAGS += $(NSS_CFLAGS) -DSYSCONF_NSS
d9bc5f
+endif
d9bc5f
+
d9bc5f
+ifeq ($(OPENJDK_BUILD_OS), linux)
d9bc5f
+  $(eval $(call SetupJdkLibrary, BUILD_LIBSYSTEMCONF, \
d9bc5f
+      NAME := systemconf, \
d9bc5f
+      OPTIMIZATION := LOW, \
d9bc5f
+      CFLAGS := $(CFLAGS_JDKLIB) $(LIBSYSTEMCONF_CFLAGS), \
d9bc5f
+      CXXFLAGS := $(CXXFLAGS_JDKLIB) $(LIBSYSTEMCONF_CXXFLAGS), \
d9bc5f
+      LDFLAGS := $(LDFLAGS_JDKLIB) \
d9bc5f
+          $(call SET_SHARED_LIBRARY_ORIGIN), \
d9bc5f
+      LIBS_unix := $(LIBDL) $(NSS_LIBS), \
d9bc5f
+  ))
d9bc5f
+
d9bc5f
+  TARGETS += $(BUILD_LIBSYSTEMCONF)
d9bc5f
+endif
d9bc5f
+
d9bc5f
 ################################################################################
d9bc5f
 # Create the symbols file for static builds.
d9bc5f
 
d9bc5f
diff --git a/src/java.base/linux/native/libsystemconf/systemconf.c b/src/java.base/linux/native/libsystemconf/systemconf.c
d9bc5f
new file mode 100644
d9bc5f
index 00000000000..8dcb7d9073f
d9bc5f
--- /dev/null
d9bc5f
+++ b/src/java.base/linux/native/libsystemconf/systemconf.c
d9bc5f
@@ -0,0 +1,224 @@
d9bc5f
+/*
d9bc5f
+ * Copyright (c) 2021, Red Hat, Inc.
d9bc5f
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9bc5f
+ *
d9bc5f
+ * This code is free software; you can redistribute it and/or modify it
d9bc5f
+ * under the terms of the GNU General Public License version 2 only, as
d9bc5f
+ * published by the Free Software Foundation.  Oracle designates this
d9bc5f
+ * particular file as subject to the "Classpath" exception as provided
d9bc5f
+ * by Oracle in the LICENSE file that accompanied this code.
d9bc5f
+ *
d9bc5f
+ * This code is distributed in the hope that it will be useful, but WITHOUT
d9bc5f
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9bc5f
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9bc5f
+ * version 2 for more details (a copy is included in the LICENSE file that
d9bc5f
+ * accompanied this code).
d9bc5f
+ *
d9bc5f
+ * You should have received a copy of the GNU General Public License version
d9bc5f
+ * 2 along with this work; if not, write to the Free Software Foundation,
d9bc5f
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9bc5f
+ *
d9bc5f
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9bc5f
+ * or visit www.oracle.com if you need additional information or have any
d9bc5f
+ * questions.
d9bc5f
+ */
d9bc5f
+
d9bc5f
+#include <jni.h>
d9bc5f
+#include <jni_util.h>
d9bc5f
+#include "jvm_md.h"
d9bc5f
+#include <stdio.h>
d9bc5f
+
d9bc5f
+#ifdef SYSCONF_NSS
d9bc5f
+#include <nss3/pk11pub.h>
d9bc5f
+#else
d9bc5f
+#include <dlfcn.h>
d9bc5f
+#endif //SYSCONF_NSS
d9bc5f
+
d9bc5f
+#include "java_security_SystemConfigurator.h"
d9bc5f
+
d9bc5f
+#define MSG_MAX_SIZE 256
d9bc5f
+#define FIPS_ENABLED_PATH "/proc/sys/crypto/fips_enabled"
d9bc5f
+
d9bc5f
+typedef int (SECMOD_GET_SYSTEM_FIPS_ENABLED_TYPE)(void);
d9bc5f
+
d9bc5f
+static SECMOD_GET_SYSTEM_FIPS_ENABLED_TYPE *getSystemFIPSEnabled;
d9bc5f
+static jmethodID debugPrintlnMethodID = NULL;
d9bc5f
+static jobject debugObj = NULL;
d9bc5f
+
d9bc5f
+static void dbgPrint(JNIEnv *env, const char* msg)
d9bc5f
+{
d9bc5f
+    jstring jMsg;
d9bc5f
+    if (debugObj != NULL) {
d9bc5f
+        jMsg = (*env)->NewStringUTF(env, msg);
d9bc5f
+        CHECK_NULL(jMsg);
d9bc5f
+        (*env)->CallVoidMethod(env, debugObj, debugPrintlnMethodID, jMsg);
d9bc5f
+    }
d9bc5f
+}
d9bc5f
+
d9bc5f
+static void throwIOException(JNIEnv *env, const char *msg)
d9bc5f
+{
d9bc5f
+    jclass cls = (*env)->FindClass(env, "java/io/IOException");
d9bc5f
+    if (cls != 0)
d9bc5f
+        (*env)->ThrowNew(env, cls, msg);
d9bc5f
+}
d9bc5f
+
d9bc5f
+static void handle_msg(JNIEnv *env, const char* msg, int msg_bytes)
d9bc5f
+{
d9bc5f
+  if (msg_bytes > 0 && msg_bytes < MSG_MAX_SIZE) {
d9bc5f
+    dbgPrint(env, msg);
d9bc5f
+  } else {
d9bc5f
+    dbgPrint(env, "systemconf: cannot render message");
d9bc5f
+  }
d9bc5f
+}
d9bc5f
+
d9bc5f
+// Only used when NSS is not linked at build time
d9bc5f
+#ifndef SYSCONF_NSS
d9bc5f
+
d9bc5f
+static void *nss_handle;
d9bc5f
+
d9bc5f
+static jboolean loadNSS(JNIEnv *env)
d9bc5f
+{
d9bc5f
+  char msg[MSG_MAX_SIZE];
d9bc5f
+  int msg_bytes;
d9bc5f
+  const char* errmsg;
d9bc5f
+
d9bc5f
+  nss_handle = dlopen(JNI_LIB_NAME("nss3"), RTLD_LAZY);
d9bc5f
+  if (nss_handle == NULL) {
d9bc5f
+    errmsg = dlerror();
d9bc5f
+    msg_bytes = snprintf(msg, MSG_MAX_SIZE, "loadNSS: dlopen: %s\n",
d9bc5f
+                         errmsg);
d9bc5f
+    handle_msg(env, msg, msg_bytes);
d9bc5f
+    return JNI_FALSE;
d9bc5f
+  }
d9bc5f
+  dlerror(); /* Clear errors */
d9bc5f
+  getSystemFIPSEnabled = (SECMOD_GET_SYSTEM_FIPS_ENABLED_TYPE*)dlsym(nss_handle, "SECMOD_GetSystemFIPSEnabled");
d9bc5f
+  if ((errmsg = dlerror()) != NULL) {
d9bc5f
+    msg_bytes = snprintf(msg, MSG_MAX_SIZE, "loadNSS: dlsym: %s\n",
d9bc5f
+                         errmsg);
d9bc5f
+    handle_msg(env, msg, msg_bytes);
d9bc5f
+    return JNI_FALSE;
d9bc5f
+  }
d9bc5f
+  return JNI_TRUE;
d9bc5f
+}
d9bc5f
+
d9bc5f
+static void closeNSS(JNIEnv *env)
d9bc5f
+{
d9bc5f
+  char msg[MSG_MAX_SIZE];
d9bc5f
+  int msg_bytes;
d9bc5f
+  const char* errmsg;
d9bc5f
+
d9bc5f
+  if (dlclose(nss_handle) != 0) {
d9bc5f
+    errmsg = dlerror();
d9bc5f
+    msg_bytes = snprintf(msg, MSG_MAX_SIZE, "closeNSS: dlclose: %s\n",
d9bc5f
+                         errmsg);
d9bc5f
+    handle_msg(env, msg, msg_bytes);
d9bc5f
+  }
d9bc5f
+}
d9bc5f
+
d9bc5f
+#endif
d9bc5f
+
d9bc5f
+/*
d9bc5f
+ * Class:     java_security_SystemConfigurator
d9bc5f
+ * Method:    JNI_OnLoad
d9bc5f
+ */
d9bc5f
+JNIEXPORT jint JNICALL DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
d9bc5f
+{
d9bc5f
+    JNIEnv *env;
d9bc5f
+    jclass sysConfCls, debugCls;
d9bc5f
+    jfieldID sdebugFld;
d9bc5f
+
d9bc5f
+    if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_2) != JNI_OK) {
d9bc5f
+        return JNI_EVERSION; /* JNI version not supported */
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    sysConfCls = (*env)->FindClass(env,"java/security/SystemConfigurator");
d9bc5f
+    if (sysConfCls == NULL) {
d9bc5f
+        printf("libsystemconf: SystemConfigurator class not found\n");
d9bc5f
+        return JNI_ERR;
d9bc5f
+    }
d9bc5f
+    sdebugFld = (*env)->GetStaticFieldID(env, sysConfCls,
d9bc5f
+            "sdebug", "Lsun/security/util/Debug;");
d9bc5f
+    if (sdebugFld == NULL) {
d9bc5f
+        printf("libsystemconf: SystemConfigurator::sdebug field not found\n");
d9bc5f
+        return JNI_ERR;
d9bc5f
+    }
d9bc5f
+    debugObj = (*env)->GetStaticObjectField(env, sysConfCls, sdebugFld);
d9bc5f
+    if (debugObj != NULL) {
d9bc5f
+        debugCls = (*env)->FindClass(env,"sun/security/util/Debug");
d9bc5f
+        if (debugCls == NULL) {
d9bc5f
+            printf("libsystemconf: Debug class not found\n");
d9bc5f
+            return JNI_ERR;
d9bc5f
+        }
d9bc5f
+        debugPrintlnMethodID = (*env)->GetMethodID(env, debugCls,
d9bc5f
+                "println", "(Ljava/lang/String;)V");
d9bc5f
+        if (debugPrintlnMethodID == NULL) {
d9bc5f
+            printf("libsystemconf: Debug::println(String) method not found\n");
d9bc5f
+            return JNI_ERR;
d9bc5f
+        }
d9bc5f
+        debugObj = (*env)->NewGlobalRef(env, debugObj);
d9bc5f
+    }
d9bc5f
+
d9bc5f
+#ifdef SYSCONF_NSS
d9bc5f
+    getSystemFIPSEnabled = *SECMOD_GetSystemFIPSEnabled;
d9bc5f
+#else
d9bc5f
+    if (loadNSS(env) == JNI_FALSE) {
d9bc5f
+      dbgPrint(env, "libsystemconf: Failed to load NSS library.");
d9bc5f
+    }
d9bc5f
+#endif
d9bc5f
+
d9bc5f
+    return (*env)->GetVersion(env);
d9bc5f
+}
d9bc5f
+
d9bc5f
+/*
d9bc5f
+ * Class:     java_security_SystemConfigurator
d9bc5f
+ * Method:    JNI_OnUnload
d9bc5f
+ */
d9bc5f
+JNIEXPORT void JNICALL DEF_JNI_OnUnload(JavaVM *vm, void *reserved)
d9bc5f
+{
d9bc5f
+    JNIEnv *env;
d9bc5f
+
d9bc5f
+    if (debugObj != NULL) {
d9bc5f
+        if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_2) != JNI_OK) {
d9bc5f
+            return; /* Should not happen */
d9bc5f
+        }
d9bc5f
+#ifndef SYSCONF_NSS
d9bc5f
+        closeNSS(env);
d9bc5f
+#endif
d9bc5f
+        (*env)->DeleteGlobalRef(env, debugObj);
d9bc5f
+    }
d9bc5f
+}
d9bc5f
+
d9bc5f
+JNIEXPORT jboolean JNICALL Java_java_security_SystemConfigurator_getSystemFIPSEnabled
d9bc5f
+  (JNIEnv *env, jclass cls)
d9bc5f
+{
d9bc5f
+    int fips_enabled;
d9bc5f
+    char msg[MSG_MAX_SIZE];
d9bc5f
+    int msg_bytes;
d9bc5f
+
d9bc5f
+    if (getSystemFIPSEnabled != NULL) {
d9bc5f
+      dbgPrint(env, "getSystemFIPSEnabled: calling SECMOD_GetSystemFIPSEnabled");
d9bc5f
+      fips_enabled = (*getSystemFIPSEnabled)();
d9bc5f
+      msg_bytes = snprintf(msg, MSG_MAX_SIZE, "getSystemFIPSEnabled:"   \
d9bc5f
+                           " SECMOD_GetSystemFIPSEnabled returned 0x%x", fips_enabled);
d9bc5f
+      handle_msg(env, msg, msg_bytes);
d9bc5f
+      return (fips_enabled == 1 ? JNI_TRUE : JNI_FALSE);
d9bc5f
+    } else {
d9bc5f
+      FILE *fe;
d9bc5f
+
d9bc5f
+      dbgPrint(env, "getSystemFIPSEnabled: reading " FIPS_ENABLED_PATH);
d9bc5f
+      if ((fe = fopen(FIPS_ENABLED_PATH, "r")) == NULL) {
d9bc5f
+        throwIOException(env, "Cannot open " FIPS_ENABLED_PATH);
d9bc5f
+        return JNI_FALSE;
d9bc5f
+      }
d9bc5f
+      fips_enabled = fgetc(fe);
d9bc5f
+      fclose(fe);
d9bc5f
+      if (fips_enabled == EOF) {
d9bc5f
+        throwIOException(env, "Cannot read " FIPS_ENABLED_PATH);
d9bc5f
+        return JNI_FALSE;
d9bc5f
+      }
d9bc5f
+      msg_bytes = snprintf(msg, MSG_MAX_SIZE, "getSystemFIPSEnabled:"   \
d9bc5f
+                           " read character is '%c'", fips_enabled);
d9bc5f
+      handle_msg(env, msg, msg_bytes);
d9bc5f
+      return (fips_enabled == '1' ? JNI_TRUE : JNI_FALSE);
d9bc5f
+    }
d9bc5f
+}
d9bc5f
diff --git a/src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java b/src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java
d9bc5f
index a020e1c15d8..6d459fdec01 100644
d9bc5f
--- a/src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java
d9bc5f
+++ b/src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java
d9bc5f
@@ -31,6 +31,7 @@ import java.security.SecureRandom;
d9bc5f
 import java.security.PrivilegedAction;
d9bc5f
 import java.util.HashMap;
d9bc5f
 import java.util.List;
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import static sun.security.util.SecurityConstants.PROVIDER_VER;
d9bc5f
 import static sun.security.util.SecurityProviderConstants.*;
d9bc5f
 
d9bc5f
@@ -78,6 +79,10 @@ import static sun.security.util.SecurityProviderConstants.*;
d9bc5f
 
d9bc5f
 public final class SunJCE extends Provider {
d9bc5f
 
d9bc5f
+    private static final boolean systemFipsEnabled =
d9bc5f
+            SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+            .isSystemFipsEnabled();
d9bc5f
+
d9bc5f
     @java.io.Serial
d9bc5f
     private static final long serialVersionUID = 6812507587804302833L;
d9bc5f
 
d9bc5f
@@ -143,285 +148,287 @@ public final class SunJCE extends Provider {
d9bc5f
     void putEntries() {
d9bc5f
         // reuse attribute map and reset before each reuse
d9bc5f
         HashMap<String, String> attrs = new HashMap<>(3);
d9bc5f
-        attrs.put("SupportedModes", "ECB");
d9bc5f
-        attrs.put("SupportedPaddings", "NOPADDING|PKCS1PADDING|OAEPPADDING"
d9bc5f
-                + "|OAEPWITHMD5ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA1ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-1ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-224ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-256ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-384ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-512ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-512/224ANDMGF1PADDING"
d9bc5f
-                + "|OAEPWITHSHA-512/256ANDMGF1PADDING");
d9bc5f
-        attrs.put("SupportedKeyClasses",
d9bc5f
-                "java.security.interfaces.RSAPublicKey" +
d9bc5f
-                "|java.security.interfaces.RSAPrivateKey");
d9bc5f
-        ps("Cipher", "RSA",
d9bc5f
-                "com.sun.crypto.provider.RSACipher", null, attrs);
d9bc5f
-
d9bc5f
-        // common block cipher modes, pads
d9bc5f
-        final String BLOCK_MODES = "ECB|CBC|PCBC|CTR|CTS|CFB|OFB" +
d9bc5f
-            "|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64" +
d9bc5f
-            "|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64";
d9bc5f
-        final String BLOCK_MODES128 = BLOCK_MODES +
d9bc5f
-            "|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128" +
d9bc5f
-            "|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128";
d9bc5f
-        final String BLOCK_PADS = "NOPADDING|PKCS5PADDING|ISO10126PADDING";
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedModes", BLOCK_MODES);
d9bc5f
-        attrs.put("SupportedPaddings", BLOCK_PADS);
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        ps("Cipher", "DES",
d9bc5f
-                "com.sun.crypto.provider.DESCipher", null, attrs);
d9bc5f
-        psA("Cipher", "DESede", "com.sun.crypto.provider.DESedeCipher",
d9bc5f
-                attrs);
d9bc5f
-        ps("Cipher", "Blowfish",
d9bc5f
-                "com.sun.crypto.provider.BlowfishCipher", null, attrs);
d9bc5f
-
d9bc5f
-        ps("Cipher", "RC2",
d9bc5f
-                "com.sun.crypto.provider.RC2Cipher", null, attrs);
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedModes", BLOCK_MODES128);
d9bc5f
-        attrs.put("SupportedPaddings", BLOCK_PADS);
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        psA("Cipher", "AES",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$General", attrs);
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        psA("Cipher", "AES/KW/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES_KW_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        ps("Cipher", "AES/KW/PKCS5Padding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES_KW_PKCS5Padding",
d9bc5f
-                null, attrs);
d9bc5f
-        psA("Cipher", "AES/KWP/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES_KWP_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-
d9bc5f
-        psA("Cipher", "AES_128/ECB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES128_ECB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_128/CBC/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES128_CBC_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_128/OFB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES128_OFB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_128/CFB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES128_CFB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_128/KW/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES128_KW_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        ps("Cipher", "AES_128/KW/PKCS5Padding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES128_KW_PKCS5Padding",
d9bc5f
-                null, attrs);
d9bc5f
-        psA("Cipher", "AES_128/KWP/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES128_KWP_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-
d9bc5f
-        psA("Cipher", "AES_192/ECB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES192_ECB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_192/CBC/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES192_CBC_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_192/OFB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES192_OFB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_192/CFB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES192_CFB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_192/KW/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES192_KW_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        ps("Cipher", "AES_192/KW/PKCS5Padding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES192_KW_PKCS5Padding",
d9bc5f
-                null, attrs);
d9bc5f
-        psA("Cipher", "AES_192/KWP/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES192_KWP_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-
d9bc5f
-        psA("Cipher", "AES_256/ECB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES256_ECB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_256/CBC/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES256_CBC_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_256/OFB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES256_OFB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_256/CFB/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.AESCipher$AES256_CFB_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_256/KW/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES256_KW_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-        ps("Cipher", "AES_256/KW/PKCS5Padding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES256_KW_PKCS5Padding",
d9bc5f
-                null, attrs);
d9bc5f
-        psA("Cipher", "AES_256/KWP/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.KeyWrapCipher$AES256_KWP_NoPadding",
d9bc5f
-                attrs);
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedModes", "GCM");
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-
d9bc5f
-        ps("Cipher", "AES/GCM/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.GaloisCounterMode$AESGCM", null,
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_128/GCM/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.GaloisCounterMode$AES128",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_192/GCM/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.GaloisCounterMode$AES192",
d9bc5f
-                attrs);
d9bc5f
-        psA("Cipher", "AES_256/GCM/NoPadding",
d9bc5f
-                "com.sun.crypto.provider.GaloisCounterMode$AES256",
d9bc5f
-                attrs);
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedModes", "CBC");
d9bc5f
-        attrs.put("SupportedPaddings", "NOPADDING");
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        ps("Cipher", "DESedeWrap",
d9bc5f
-                "com.sun.crypto.provider.DESedeWrapCipher", null, attrs);
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedModes", "ECB");
d9bc5f
-        attrs.put("SupportedPaddings", "NOPADDING");
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        psA("Cipher", "ARCFOUR",
d9bc5f
-                "com.sun.crypto.provider.ARCFOURCipher", attrs);
d9bc5f
-
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        ps("Cipher",  "ChaCha20",
d9bc5f
-                "com.sun.crypto.provider.ChaCha20Cipher$ChaCha20Only",
d9bc5f
-                null, attrs);
d9bc5f
-        psA("Cipher",  "ChaCha20-Poly1305",
d9bc5f
-                "com.sun.crypto.provider.ChaCha20Cipher$ChaCha20Poly1305",
d9bc5f
-                attrs);
d9bc5f
-
d9bc5f
-        // PBES1
d9bc5f
-        psA("Cipher", "PBEWithMD5AndDES",
d9bc5f
-                "com.sun.crypto.provider.PBEWithMD5AndDESCipher",
d9bc5f
-                null);
d9bc5f
-        ps("Cipher", "PBEWithMD5AndTripleDES",
d9bc5f
-                "com.sun.crypto.provider.PBEWithMD5AndTripleDESCipher");
d9bc5f
-        psA("Cipher", "PBEWithSHA1AndDESede",
d9bc5f
-                "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede",
d9bc5f
-                null);
d9bc5f
-        psA("Cipher", "PBEWithSHA1AndRC2_40",
d9bc5f
-                "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_40",
d9bc5f
-                null);
d9bc5f
-        psA("Cipher", "PBEWithSHA1AndRC2_128",
d9bc5f
-                "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_128",
d9bc5f
-                null);
d9bc5f
-        psA("Cipher", "PBEWithSHA1AndRC4_40",
d9bc5f
-                "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC4_40",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("Cipher", "PBEWithSHA1AndRC4_128",
d9bc5f
-                "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC4_128",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        // PBES2
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA1AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_128");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA224AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA224AndAES_128");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA256AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA256AndAES_128");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA384AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA384AndAES_128");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA512AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA512AndAES_128");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA1AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_256");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA224AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA224AndAES_256");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA256AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA256AndAES_256");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA384AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA384AndAES_256");
d9bc5f
-
d9bc5f
-        ps("Cipher", "PBEWithHmacSHA512AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBES2Core$HmacSHA512AndAES_256");
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Key(pair) Generator engines
d9bc5f
-         */
d9bc5f
-        ps("KeyGenerator", "DES",
d9bc5f
-                "com.sun.crypto.provider.DESKeyGenerator");
d9bc5f
-        psA("KeyGenerator", "DESede",
d9bc5f
-                "com.sun.crypto.provider.DESedeKeyGenerator",
d9bc5f
-                null);
d9bc5f
-        ps("KeyGenerator", "Blowfish",
d9bc5f
-                "com.sun.crypto.provider.BlowfishKeyGenerator");
d9bc5f
-        psA("KeyGenerator", "AES",
d9bc5f
-                "com.sun.crypto.provider.AESKeyGenerator",
d9bc5f
-                null);
d9bc5f
-        ps("KeyGenerator", "RC2",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$RC2KeyGenerator");
d9bc5f
-        psA("KeyGenerator", "ARCFOUR",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$ARCFOURKeyGenerator",
d9bc5f
-                null);
d9bc5f
-        ps("KeyGenerator", "ChaCha20",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$ChaCha20KeyGenerator");
d9bc5f
-        ps("KeyGenerator", "HmacMD5",
d9bc5f
-                "com.sun.crypto.provider.HmacMD5KeyGenerator");
d9bc5f
-
d9bc5f
-        psA("KeyGenerator", "HmacSHA1",
d9bc5f
-                "com.sun.crypto.provider.HmacSHA1KeyGenerator", null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA224",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA224",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA256",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA256",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA384",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA384",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA512",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA512",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA512/224",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA512_224",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA512/256",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA512_256",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("KeyGenerator", "HmacSHA3-224",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_224",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA3-256",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_256",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA3-384",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_384",
d9bc5f
-                null);
d9bc5f
-        psA("KeyGenerator", "HmacSHA3-512",
d9bc5f
-                "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_512",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("KeyPairGenerator", "DiffieHellman",
d9bc5f
-                "com.sun.crypto.provider.DHKeyPairGenerator",
d9bc5f
-                null);
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            attrs.put("SupportedModes", "ECB");
d9bc5f
+            attrs.put("SupportedPaddings", "NOPADDING|PKCS1PADDING|OAEPPADDING"
d9bc5f
+                    + "|OAEPWITHMD5ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA1ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-1ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-224ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-256ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-384ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-512ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-512/224ANDMGF1PADDING"
d9bc5f
+                    + "|OAEPWITHSHA-512/256ANDMGF1PADDING");
d9bc5f
+            attrs.put("SupportedKeyClasses",
d9bc5f
+                    "java.security.interfaces.RSAPublicKey" +
d9bc5f
+                    "|java.security.interfaces.RSAPrivateKey");
d9bc5f
+            ps("Cipher", "RSA",
d9bc5f
+                    "com.sun.crypto.provider.RSACipher", null, attrs);
d9bc5f
+
d9bc5f
+            // common block cipher modes, pads
d9bc5f
+            final String BLOCK_MODES = "ECB|CBC|PCBC|CTR|CTS|CFB|OFB" +
d9bc5f
+                "|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64" +
d9bc5f
+                "|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64";
d9bc5f
+            final String BLOCK_MODES128 = BLOCK_MODES +
d9bc5f
+                "|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128" +
d9bc5f
+                "|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128";
d9bc5f
+            final String BLOCK_PADS = "NOPADDING|PKCS5PADDING|ISO10126PADDING";
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedModes", BLOCK_MODES);
d9bc5f
+            attrs.put("SupportedPaddings", BLOCK_PADS);
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            ps("Cipher", "DES",
d9bc5f
+                    "com.sun.crypto.provider.DESCipher", null, attrs);
d9bc5f
+            psA("Cipher", "DESede", "com.sun.crypto.provider.DESedeCipher",
d9bc5f
+                    attrs);
d9bc5f
+            ps("Cipher", "Blowfish",
d9bc5f
+                    "com.sun.crypto.provider.BlowfishCipher", null, attrs);
d9bc5f
+
d9bc5f
+            ps("Cipher", "RC2",
d9bc5f
+                    "com.sun.crypto.provider.RC2Cipher", null, attrs);
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedModes", BLOCK_MODES128);
d9bc5f
+            attrs.put("SupportedPaddings", BLOCK_PADS);
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            psA("Cipher", "AES",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$General", attrs);
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            psA("Cipher", "AES/KW/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES_KW_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            ps("Cipher", "AES/KW/PKCS5Padding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES_KW_PKCS5Padding",
d9bc5f
+                    null, attrs);
d9bc5f
+            psA("Cipher", "AES/KWP/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES_KWP_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            psA("Cipher", "AES_128/ECB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES128_ECB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_128/CBC/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES128_CBC_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_128/OFB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES128_OFB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_128/CFB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES128_CFB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_128/KW/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES128_KW_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            ps("Cipher", "AES_128/KW/PKCS5Padding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES128_KW_PKCS5Padding",
d9bc5f
+                    null, attrs);
d9bc5f
+            psA("Cipher", "AES_128/KWP/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES128_KWP_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            psA("Cipher", "AES_192/ECB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES192_ECB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_192/CBC/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES192_CBC_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_192/OFB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES192_OFB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_192/CFB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES192_CFB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_192/KW/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES192_KW_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            ps("Cipher", "AES_192/KW/PKCS5Padding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES192_KW_PKCS5Padding",
d9bc5f
+                    null, attrs);
d9bc5f
+            psA("Cipher", "AES_192/KWP/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES192_KWP_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            psA("Cipher", "AES_256/ECB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES256_ECB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_256/CBC/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES256_CBC_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_256/OFB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES256_OFB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_256/CFB/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.AESCipher$AES256_CFB_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_256/KW/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES256_KW_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+            ps("Cipher", "AES_256/KW/PKCS5Padding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES256_KW_PKCS5Padding",
d9bc5f
+                    null, attrs);
d9bc5f
+            psA("Cipher", "AES_256/KWP/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.KeyWrapCipher$AES256_KWP_NoPadding",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedModes", "GCM");
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+
d9bc5f
+            ps("Cipher", "AES/GCM/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.GaloisCounterMode$AESGCM", null,
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_128/GCM/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.GaloisCounterMode$AES128",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_192/GCM/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.GaloisCounterMode$AES192",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Cipher", "AES_256/GCM/NoPadding",
d9bc5f
+                    "com.sun.crypto.provider.GaloisCounterMode$AES256",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedModes", "CBC");
d9bc5f
+            attrs.put("SupportedPaddings", "NOPADDING");
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            ps("Cipher", "DESedeWrap",
d9bc5f
+                    "com.sun.crypto.provider.DESedeWrapCipher", null, attrs);
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedModes", "ECB");
d9bc5f
+            attrs.put("SupportedPaddings", "NOPADDING");
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            psA("Cipher", "ARCFOUR",
d9bc5f
+                    "com.sun.crypto.provider.ARCFOURCipher", attrs);
d9bc5f
+
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            ps("Cipher",  "ChaCha20",
d9bc5f
+                    "com.sun.crypto.provider.ChaCha20Cipher$ChaCha20Only",
d9bc5f
+                    null, attrs);
d9bc5f
+            psA("Cipher",  "ChaCha20-Poly1305",
d9bc5f
+                    "com.sun.crypto.provider.ChaCha20Cipher$ChaCha20Poly1305",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            // PBES1
d9bc5f
+            psA("Cipher", "PBEWithMD5AndDES",
d9bc5f
+                    "com.sun.crypto.provider.PBEWithMD5AndDESCipher",
d9bc5f
+                    null);
d9bc5f
+            ps("Cipher", "PBEWithMD5AndTripleDES",
d9bc5f
+                    "com.sun.crypto.provider.PBEWithMD5AndTripleDESCipher");
d9bc5f
+            psA("Cipher", "PBEWithSHA1AndDESede",
d9bc5f
+                    "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede",
d9bc5f
+                    null);
d9bc5f
+            psA("Cipher", "PBEWithSHA1AndRC2_40",
d9bc5f
+                    "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_40",
d9bc5f
+                    null);
d9bc5f
+            psA("Cipher", "PBEWithSHA1AndRC2_128",
d9bc5f
+                    "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_128",
d9bc5f
+                    null);
d9bc5f
+            psA("Cipher", "PBEWithSHA1AndRC4_40",
d9bc5f
+                    "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC4_40",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("Cipher", "PBEWithSHA1AndRC4_128",
d9bc5f
+                    "com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC4_128",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            // PBES2
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA1AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_128");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA224AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA224AndAES_128");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA256AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA256AndAES_128");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA384AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA384AndAES_128");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA512AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA512AndAES_128");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA1AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA1AndAES_256");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA224AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA224AndAES_256");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA256AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA256AndAES_256");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA384AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA384AndAES_256");
d9bc5f
+
d9bc5f
+            ps("Cipher", "PBEWithHmacSHA512AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBES2Core$HmacSHA512AndAES_256");
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * Key(pair) Generator engines
d9bc5f
+             */
d9bc5f
+            ps("KeyGenerator", "DES",
d9bc5f
+                    "com.sun.crypto.provider.DESKeyGenerator");
d9bc5f
+            psA("KeyGenerator", "DESede",
d9bc5f
+                    "com.sun.crypto.provider.DESedeKeyGenerator",
d9bc5f
+                    null);
d9bc5f
+            ps("KeyGenerator", "Blowfish",
d9bc5f
+                    "com.sun.crypto.provider.BlowfishKeyGenerator");
d9bc5f
+            psA("KeyGenerator", "AES",
d9bc5f
+                    "com.sun.crypto.provider.AESKeyGenerator",
d9bc5f
+                    null);
d9bc5f
+            ps("KeyGenerator", "RC2",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$RC2KeyGenerator");
d9bc5f
+            psA("KeyGenerator", "ARCFOUR",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$ARCFOURKeyGenerator",
d9bc5f
+                    null);
d9bc5f
+            ps("KeyGenerator", "ChaCha20",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$ChaCha20KeyGenerator");
d9bc5f
+            ps("KeyGenerator", "HmacMD5",
d9bc5f
+                    "com.sun.crypto.provider.HmacMD5KeyGenerator");
d9bc5f
+
d9bc5f
+            psA("KeyGenerator", "HmacSHA1",
d9bc5f
+                    "com.sun.crypto.provider.HmacSHA1KeyGenerator", null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA224",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA224",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA256",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA256",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA384",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA384",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA512",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA512",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA512/224",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA512_224",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA512/256",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA512_256",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("KeyGenerator", "HmacSHA3-224",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_224",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA3-256",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_256",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA3-384",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_384",
d9bc5f
+                    null);
d9bc5f
+            psA("KeyGenerator", "HmacSHA3-512",
d9bc5f
+                    "com.sun.crypto.provider.KeyGeneratorCore$HmacKG$SHA3_512",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("KeyPairGenerator", "DiffieHellman",
d9bc5f
+                    "com.sun.crypto.provider.DHKeyPairGenerator",
d9bc5f
+                    null);
d9bc5f
+        }
d9bc5f
 
d9bc5f
         /*
d9bc5f
          * Algorithm parameter generation engines
d9bc5f
@@ -430,15 +437,17 @@ public final class SunJCE extends Provider {
d9bc5f
                 "DiffieHellman", "com.sun.crypto.provider.DHParameterGenerator",
d9bc5f
                 null);
d9bc5f
 
d9bc5f
-        /*
d9bc5f
-         * Key Agreement engines
d9bc5f
-         */
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedKeyClasses", "javax.crypto.interfaces.DHPublicKey" +
d9bc5f
-                        "|javax.crypto.interfaces.DHPrivateKey");
d9bc5f
-        psA("KeyAgreement", "DiffieHellman",
d9bc5f
-                "com.sun.crypto.provider.DHKeyAgreement",
d9bc5f
-                attrs);
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            /*
d9bc5f
+             * Key Agreement engines
d9bc5f
+             */
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedKeyClasses", "javax.crypto.interfaces.DHPublicKey" +
d9bc5f
+                            "|javax.crypto.interfaces.DHPrivateKey");
d9bc5f
+            psA("KeyAgreement", "DiffieHellman",
d9bc5f
+                    "com.sun.crypto.provider.DHKeyAgreement",
d9bc5f
+                    attrs);
d9bc5f
+        }
d9bc5f
 
d9bc5f
         /*
d9bc5f
          * Algorithm Parameter engines
d9bc5f
@@ -531,197 +540,199 @@ public final class SunJCE extends Provider {
d9bc5f
         psA("AlgorithmParameters", "ChaCha20-Poly1305",
d9bc5f
                 "com.sun.crypto.provider.ChaCha20Poly1305Parameters", null);
d9bc5f
 
d9bc5f
-        /*
d9bc5f
-         * Key factories
d9bc5f
-         */
d9bc5f
-        psA("KeyFactory", "DiffieHellman",
d9bc5f
-                "com.sun.crypto.provider.DHKeyFactory",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Secret-key factories
d9bc5f
-         */
d9bc5f
-        ps("SecretKeyFactory", "DES",
d9bc5f
-                "com.sun.crypto.provider.DESKeyFactory");
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "DESede",
d9bc5f
-                "com.sun.crypto.provider.DESedeKeyFactory", null);
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "PBEWithMD5AndDES",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndDES",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Internal in-house crypto algorithm used for
d9bc5f
-         * the JCEKS keystore type.  Since this was developed
d9bc5f
-         * internally, there isn't an OID corresponding to this
d9bc5f
-         * algorithm.
d9bc5f
-         */
d9bc5f
-        ps("SecretKeyFactory", "PBEWithMD5AndTripleDES",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndTripleDES");
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "PBEWithSHA1AndDESede",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndDESede",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "PBEWithSHA1AndRC2_40",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_40",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "PBEWithSHA1AndRC2_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_128",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "PBEWithSHA1AndRC4_40",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC4_40",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        psA("SecretKeyFactory", "PBEWithSHA1AndRC4_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC4_128",
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA1AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA1AndAES_128");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA224AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA224AndAES_128");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA256AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA256AndAES_128");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA384AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA384AndAES_128");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA512AndAES_128",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512AndAES_128");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA1AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA1AndAES_256");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA224AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA224AndAES_256");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA256AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA256AndAES_256");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA384AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA384AndAES_256");
d9bc5f
-
d9bc5f
-        ps("SecretKeyFactory", "PBEWithHmacSHA512AndAES_256",
d9bc5f
-                "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512AndAES_256");
d9bc5f
-
d9bc5f
-        // PBKDF2
d9bc5f
-        psA("SecretKeyFactory", "PBKDF2WithHmacSHA1",
d9bc5f
-                "com.sun.crypto.provider.PBKDF2Core$HmacSHA1",
d9bc5f
-                null);
d9bc5f
-        ps("SecretKeyFactory", "PBKDF2WithHmacSHA224",
d9bc5f
-                "com.sun.crypto.provider.PBKDF2Core$HmacSHA224");
d9bc5f
-        ps("SecretKeyFactory", "PBKDF2WithHmacSHA256",
d9bc5f
-                "com.sun.crypto.provider.PBKDF2Core$HmacSHA256");
d9bc5f
-        ps("SecretKeyFactory", "PBKDF2WithHmacSHA384",
d9bc5f
-                "com.sun.crypto.provider.PBKDF2Core$HmacSHA384");
d9bc5f
-        ps("SecretKeyFactory", "PBKDF2WithHmacSHA512",
d9bc5f
-                "com.sun.crypto.provider.PBKDF2Core$HmacSHA512");
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * MAC
d9bc5f
-         */
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
-        ps("Mac", "HmacMD5", "com.sun.crypto.provider.HmacMD5", null, attrs);
d9bc5f
-        psA("Mac", "HmacSHA1", "com.sun.crypto.provider.HmacSHA1",
d9bc5f
-                attrs);
d9bc5f
-        psA("Mac", "HmacSHA224",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA224", attrs);
d9bc5f
-        psA("Mac", "HmacSHA256",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA256", attrs);
d9bc5f
-        psA("Mac", "HmacSHA384",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA384", attrs);
d9bc5f
-        psA("Mac", "HmacSHA512",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA512", attrs);
d9bc5f
-        psA("Mac", "HmacSHA512/224",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA512_224", attrs);
d9bc5f
-        psA("Mac", "HmacSHA512/256",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA512_256", attrs);
d9bc5f
-        psA("Mac", "HmacSHA3-224",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA3_224", attrs);
d9bc5f
-        psA("Mac", "HmacSHA3-256",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA3_256", attrs);
d9bc5f
-        psA("Mac", "HmacSHA3-384",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA3_384", attrs);
d9bc5f
-        psA("Mac", "HmacSHA3-512",
d9bc5f
-                "com.sun.crypto.provider.HmacCore$HmacSHA3_512", attrs);
d9bc5f
-
d9bc5f
-        ps("Mac", "HmacPBESHA1",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA1",
d9bc5f
-                null, attrs);
d9bc5f
-        ps("Mac", "HmacPBESHA224",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA224",
d9bc5f
-                null, attrs);
d9bc5f
-        ps("Mac", "HmacPBESHA256",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA256",
d9bc5f
-                null, attrs);
d9bc5f
-        ps("Mac", "HmacPBESHA384",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA384",
d9bc5f
-                null, attrs);
d9bc5f
-        ps("Mac", "HmacPBESHA512",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA512",
d9bc5f
-                null, attrs);
d9bc5f
-        ps("Mac", "HmacPBESHA512/224",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA512_224",
d9bc5f
-                null, attrs);
d9bc5f
-        ps("Mac", "HmacPBESHA512/256",
d9bc5f
-                "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA512_256",
d9bc5f
-                null, attrs);
d9bc5f
-
d9bc5f
-
d9bc5f
-        // PBMAC1
d9bc5f
-        ps("Mac", "PBEWithHmacSHA1",
d9bc5f
-                "com.sun.crypto.provider.PBMAC1Core$HmacSHA1", null, attrs);
d9bc5f
-        ps("Mac", "PBEWithHmacSHA224",
d9bc5f
-                "com.sun.crypto.provider.PBMAC1Core$HmacSHA224", null, attrs);
d9bc5f
-        ps("Mac", "PBEWithHmacSHA256",
d9bc5f
-                "com.sun.crypto.provider.PBMAC1Core$HmacSHA256", null, attrs);
d9bc5f
-        ps("Mac", "PBEWithHmacSHA384",
d9bc5f
-                "com.sun.crypto.provider.PBMAC1Core$HmacSHA384", null, attrs);
d9bc5f
-        ps("Mac", "PBEWithHmacSHA512",
d9bc5f
-                "com.sun.crypto.provider.PBMAC1Core$HmacSHA512", null, attrs);
d9bc5f
-        ps("Mac", "SslMacMD5",
d9bc5f
-                "com.sun.crypto.provider.SslMacCore$SslMacMD5", null, attrs);
d9bc5f
-        ps("Mac", "SslMacSHA1",
d9bc5f
-                "com.sun.crypto.provider.SslMacCore$SslMacSHA1", null, attrs);
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * KeyStore
d9bc5f
-         */
d9bc5f
-        ps("KeyStore", "JCEKS",
d9bc5f
-                "com.sun.crypto.provider.JceKeyStore");
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * SSL/TLS mechanisms
d9bc5f
-         *
d9bc5f
-         * These are strictly internal implementations and may
d9bc5f
-         * be changed at any time.  These names were chosen
d9bc5f
-         * because PKCS11/SunPKCS11 does not yet have TLS1.2
d9bc5f
-         * mechanisms, and it will cause calls to come here.
d9bc5f
-         */
d9bc5f
-        ps("KeyGenerator", "SunTlsPrf",
d9bc5f
-                "com.sun.crypto.provider.TlsPrfGenerator$V10");
d9bc5f
-        ps("KeyGenerator", "SunTls12Prf",
d9bc5f
-                "com.sun.crypto.provider.TlsPrfGenerator$V12");
d9bc5f
-
d9bc5f
-        ps("KeyGenerator", "SunTlsMasterSecret",
d9bc5f
-                "com.sun.crypto.provider.TlsMasterSecretGenerator",
d9bc5f
-                List.of("SunTls12MasterSecret", "SunTlsExtendedMasterSecret"),
d9bc5f
-                null);
d9bc5f
-
d9bc5f
-        ps("KeyGenerator", "SunTlsKeyMaterial",
d9bc5f
-                "com.sun.crypto.provider.TlsKeyMaterialGenerator",
d9bc5f
-                List.of("SunTls12KeyMaterial"), null);
d9bc5f
-
d9bc5f
-        ps("KeyGenerator", "SunTlsRsaPremasterSecret",
d9bc5f
-                "com.sun.crypto.provider.TlsRsaPremasterSecretGenerator",
d9bc5f
-                List.of("SunTls12RsaPremasterSecret"), null);
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            /*
d9bc5f
+             * Key factories
d9bc5f
+             */
d9bc5f
+            psA("KeyFactory", "DiffieHellman",
d9bc5f
+                    "com.sun.crypto.provider.DHKeyFactory",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * Secret-key factories
d9bc5f
+             */
d9bc5f
+            ps("SecretKeyFactory", "DES",
d9bc5f
+                    "com.sun.crypto.provider.DESKeyFactory");
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "DESede",
d9bc5f
+                    "com.sun.crypto.provider.DESedeKeyFactory", null);
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "PBEWithMD5AndDES",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndDES",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * Internal in-house crypto algorithm used for
d9bc5f
+             * the JCEKS keystore type.  Since this was developed
d9bc5f
+             * internally, there isn't an OID corresponding to this
d9bc5f
+             * algorithm.
d9bc5f
+             */
d9bc5f
+            ps("SecretKeyFactory", "PBEWithMD5AndTripleDES",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithMD5AndTripleDES");
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "PBEWithSHA1AndDESede",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndDESede",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "PBEWithSHA1AndRC2_40",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_40",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "PBEWithSHA1AndRC2_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC2_128",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "PBEWithSHA1AndRC4_40",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC4_40",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            psA("SecretKeyFactory", "PBEWithSHA1AndRC4_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithSHA1AndRC4_128",
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA1AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA1AndAES_128");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA224AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA224AndAES_128");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA256AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA256AndAES_128");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA384AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA384AndAES_128");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA512AndAES_128",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512AndAES_128");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA1AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA1AndAES_256");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA224AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA224AndAES_256");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA256AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA256AndAES_256");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA384AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA384AndAES_256");
d9bc5f
+
d9bc5f
+            ps("SecretKeyFactory", "PBEWithHmacSHA512AndAES_256",
d9bc5f
+                    "com.sun.crypto.provider.PBEKeyFactory$PBEWithHmacSHA512AndAES_256");
d9bc5f
+
d9bc5f
+            // PBKDF2
d9bc5f
+            psA("SecretKeyFactory", "PBKDF2WithHmacSHA1",
d9bc5f
+                    "com.sun.crypto.provider.PBKDF2Core$HmacSHA1",
d9bc5f
+                    null);
d9bc5f
+            ps("SecretKeyFactory", "PBKDF2WithHmacSHA224",
d9bc5f
+                    "com.sun.crypto.provider.PBKDF2Core$HmacSHA224");
d9bc5f
+            ps("SecretKeyFactory", "PBKDF2WithHmacSHA256",
d9bc5f
+                    "com.sun.crypto.provider.PBKDF2Core$HmacSHA256");
d9bc5f
+            ps("SecretKeyFactory", "PBKDF2WithHmacSHA384",
d9bc5f
+                    "com.sun.crypto.provider.PBKDF2Core$HmacSHA384");
d9bc5f
+            ps("SecretKeyFactory", "PBKDF2WithHmacSHA512",
d9bc5f
+                    "com.sun.crypto.provider.PBKDF2Core$HmacSHA512");
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * MAC
d9bc5f
+             */
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("SupportedKeyFormats", "RAW");
d9bc5f
+            ps("Mac", "HmacMD5", "com.sun.crypto.provider.HmacMD5", null, attrs);
d9bc5f
+            psA("Mac", "HmacSHA1", "com.sun.crypto.provider.HmacSHA1",
d9bc5f
+                    attrs);
d9bc5f
+            psA("Mac", "HmacSHA224",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA224", attrs);
d9bc5f
+            psA("Mac", "HmacSHA256",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA256", attrs);
d9bc5f
+            psA("Mac", "HmacSHA384",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA384", attrs);
d9bc5f
+            psA("Mac", "HmacSHA512",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA512", attrs);
d9bc5f
+            psA("Mac", "HmacSHA512/224",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA512_224", attrs);
d9bc5f
+            psA("Mac", "HmacSHA512/256",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA512_256", attrs);
d9bc5f
+            psA("Mac", "HmacSHA3-224",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA3_224", attrs);
d9bc5f
+            psA("Mac", "HmacSHA3-256",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA3_256", attrs);
d9bc5f
+            psA("Mac", "HmacSHA3-384",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA3_384", attrs);
d9bc5f
+            psA("Mac", "HmacSHA3-512",
d9bc5f
+                    "com.sun.crypto.provider.HmacCore$HmacSHA3_512", attrs);
d9bc5f
+
d9bc5f
+            ps("Mac", "HmacPBESHA1",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA1",
d9bc5f
+                    null, attrs);
d9bc5f
+            ps("Mac", "HmacPBESHA224",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA224",
d9bc5f
+                    null, attrs);
d9bc5f
+            ps("Mac", "HmacPBESHA256",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA256",
d9bc5f
+                    null, attrs);
d9bc5f
+            ps("Mac", "HmacPBESHA384",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA384",
d9bc5f
+                    null, attrs);
d9bc5f
+            ps("Mac", "HmacPBESHA512",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA512",
d9bc5f
+                    null, attrs);
d9bc5f
+            ps("Mac", "HmacPBESHA512/224",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA512_224",
d9bc5f
+                    null, attrs);
d9bc5f
+            ps("Mac", "HmacPBESHA512/256",
d9bc5f
+                    "com.sun.crypto.provider.HmacPKCS12PBECore$HmacPKCS12PBE_SHA512_256",
d9bc5f
+                    null, attrs);
d9bc5f
+
d9bc5f
+
d9bc5f
+            // PBMAC1
d9bc5f
+            ps("Mac", "PBEWithHmacSHA1",
d9bc5f
+                    "com.sun.crypto.provider.PBMAC1Core$HmacSHA1", null, attrs);
d9bc5f
+            ps("Mac", "PBEWithHmacSHA224",
d9bc5f
+                    "com.sun.crypto.provider.PBMAC1Core$HmacSHA224", null, attrs);
d9bc5f
+            ps("Mac", "PBEWithHmacSHA256",
d9bc5f
+                    "com.sun.crypto.provider.PBMAC1Core$HmacSHA256", null, attrs);
d9bc5f
+            ps("Mac", "PBEWithHmacSHA384",
d9bc5f
+                    "com.sun.crypto.provider.PBMAC1Core$HmacSHA384", null, attrs);
d9bc5f
+            ps("Mac", "PBEWithHmacSHA512",
d9bc5f
+                    "com.sun.crypto.provider.PBMAC1Core$HmacSHA512", null, attrs);
d9bc5f
+            ps("Mac", "SslMacMD5",
d9bc5f
+                    "com.sun.crypto.provider.SslMacCore$SslMacMD5", null, attrs);
d9bc5f
+            ps("Mac", "SslMacSHA1",
d9bc5f
+                    "com.sun.crypto.provider.SslMacCore$SslMacSHA1", null, attrs);
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * KeyStore
d9bc5f
+             */
d9bc5f
+            ps("KeyStore", "JCEKS",
d9bc5f
+                    "com.sun.crypto.provider.JceKeyStore");
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * SSL/TLS mechanisms
d9bc5f
+             *
d9bc5f
+             * These are strictly internal implementations and may
d9bc5f
+             * be changed at any time.  These names were chosen
d9bc5f
+             * because PKCS11/SunPKCS11 does not yet have TLS1.2
d9bc5f
+             * mechanisms, and it will cause calls to come here.
d9bc5f
+             */
d9bc5f
+            ps("KeyGenerator", "SunTlsPrf",
d9bc5f
+                    "com.sun.crypto.provider.TlsPrfGenerator$V10");
d9bc5f
+            ps("KeyGenerator", "SunTls12Prf",
d9bc5f
+                    "com.sun.crypto.provider.TlsPrfGenerator$V12");
d9bc5f
+
d9bc5f
+            ps("KeyGenerator", "SunTlsMasterSecret",
d9bc5f
+                    "com.sun.crypto.provider.TlsMasterSecretGenerator",
d9bc5f
+                    List.of("SunTls12MasterSecret", "SunTlsExtendedMasterSecret"),
d9bc5f
+                    null);
d9bc5f
+
d9bc5f
+            ps("KeyGenerator", "SunTlsKeyMaterial",
d9bc5f
+                    "com.sun.crypto.provider.TlsKeyMaterialGenerator",
d9bc5f
+                    List.of("SunTls12KeyMaterial"), null);
d9bc5f
+
d9bc5f
+            ps("KeyGenerator", "SunTlsRsaPremasterSecret",
d9bc5f
+                    "com.sun.crypto.provider.TlsRsaPremasterSecretGenerator",
d9bc5f
+                    List.of("SunTls12RsaPremasterSecret"), null);
d9bc5f
+        }
d9bc5f
     }
d9bc5f
 
d9bc5f
     // Return the instance of this class or create one if needed.
d9bc5f
diff --git a/src/java.base/share/classes/java/security/Security.java b/src/java.base/share/classes/java/security/Security.java
d9bc5f
index ff2bc942c03..96a3ba4040c 100644
d9bc5f
--- a/src/java.base/share/classes/java/security/Security.java
d9bc5f
+++ b/src/java.base/share/classes/java/security/Security.java
d9bc5f
@@ -32,6 +32,7 @@ import java.net.URL;
d9bc5f
 
d9bc5f
 import jdk.internal.event.EventHelper;
d9bc5f
 import jdk.internal.event.SecurityPropertyModificationEvent;
d9bc5f
+import jdk.internal.access.JavaSecuritySystemConfiguratorAccess;
d9bc5f
 import jdk.internal.access.SharedSecrets;
d9bc5f
 import jdk.internal.util.StaticProperty;
d9bc5f
 import sun.security.util.Debug;
d9bc5f
@@ -47,12 +48,20 @@ import sun.security.jca.*;
d9bc5f
  * implementation-specific location, which is typically the properties file
d9bc5f
  * {@code conf/security/java.security} in the Java installation directory.
d9bc5f
  *
d9bc5f
+ * 

Additional default values of security properties are read from a

d9bc5f
+ * system-specific location, if available.

d9bc5f
+ *
d9bc5f
  * @author Benjamin Renaud
d9bc5f
  * @since 1.1
d9bc5f
  */
d9bc5f
 
d9bc5f
 public final class Security {
d9bc5f
 
d9bc5f
+    private static final String SYS_PROP_SWITCH =
d9bc5f
+        "java.security.disableSystemPropertiesFile";
d9bc5f
+    private static final String SEC_PROP_SWITCH =
d9bc5f
+        "security.useSystemPropertiesFile";
d9bc5f
+
d9bc5f
     /* Are we debugging? -- for developers */
d9bc5f
     private static final Debug sdebug =
d9bc5f
                         Debug.getInstance("properties");
d9bc5f
@@ -67,6 +76,19 @@ public final class Security {
d9bc5f
     }
d9bc5f
 
d9bc5f
     static {
d9bc5f
+        // Initialise here as used by code with system properties disabled
d9bc5f
+        SharedSecrets.setJavaSecuritySystemConfiguratorAccess(
d9bc5f
+            new JavaSecuritySystemConfiguratorAccess() {
d9bc5f
+                @Override
d9bc5f
+                public boolean isSystemFipsEnabled() {
d9bc5f
+                    return SystemConfigurator.isSystemFipsEnabled();
d9bc5f
+                }
d9bc5f
+                @Override
d9bc5f
+                public boolean isPlainKeySupportEnabled() {
d9bc5f
+                    return SystemConfigurator.isPlainKeySupportEnabled();
d9bc5f
+                }
d9bc5f
+            });
d9bc5f
+
d9bc5f
         // doPrivileged here because there are multiple
d9bc5f
         // things in initialize that might require privs.
d9bc5f
         // (the FileInputStream call and the File.exists call,
d9bc5f
@@ -84,6 +106,7 @@ public final class Security {
d9bc5f
         props = new Properties();
d9bc5f
         boolean loadedProps = false;
d9bc5f
         boolean overrideAll = false;
d9bc5f
+        boolean systemSecPropsEnabled = false;
d9bc5f
 
d9bc5f
         // first load the system properties file
d9bc5f
         // to determine the value of security.overridePropertiesFile
d9bc5f
@@ -99,6 +122,7 @@ public final class Security {
d9bc5f
                 if (sdebug != null) {
d9bc5f
                     sdebug.println("reading security properties file: " +
d9bc5f
                                 propFile);
d9bc5f
+                    sdebug.println(props.toString());
d9bc5f
                 }
d9bc5f
             } catch (IOException e) {
d9bc5f
                 if (sdebug != null) {
d9bc5f
@@ -193,6 +217,61 @@ public final class Security {
d9bc5f
             }
d9bc5f
         }
d9bc5f
 
d9bc5f
+        boolean sysUseProps = Boolean.valueOf(System.getProperty(SYS_PROP_SWITCH, "false"));
d9bc5f
+        boolean secUseProps = Boolean.valueOf(props.getProperty(SEC_PROP_SWITCH));
d9bc5f
+        if (sdebug != null) {
d9bc5f
+            sdebug.println(SYS_PROP_SWITCH + "=" + sysUseProps);
d9bc5f
+            sdebug.println(SEC_PROP_SWITCH + "=" + secUseProps);
d9bc5f
+        }
d9bc5f
+        if (!sysUseProps && secUseProps) {
d9bc5f
+            systemSecPropsEnabled = SystemConfigurator.configureSysProps(props);
d9bc5f
+            if (!systemSecPropsEnabled) {
d9bc5f
+                if (sdebug != null) {
d9bc5f
+                    sdebug.println("WARNING: System security properties could not be loaded.");
d9bc5f
+                }
d9bc5f
+            }
d9bc5f
+        } else {
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("System security property support disabled by user.");
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+
d9bc5f
+        // FIPS support depends on the contents of java.security so
d9bc5f
+        // ensure it has loaded first
d9bc5f
+        if (loadedProps && systemSecPropsEnabled) {
d9bc5f
+            boolean shouldEnable;
d9bc5f
+            String sysProp = System.getProperty("com.redhat.fips");
d9bc5f
+            if (sysProp == null) {
d9bc5f
+                shouldEnable = true;
d9bc5f
+                if (sdebug != null) {
d9bc5f
+                    sdebug.println("com.redhat.fips unset, using default value of true");
d9bc5f
+                }
d9bc5f
+            } else {
d9bc5f
+                shouldEnable = Boolean.valueOf(sysProp);
d9bc5f
+                if (sdebug != null) {
d9bc5f
+                    sdebug.println("com.redhat.fips set, using its value " + shouldEnable);
d9bc5f
+                }
d9bc5f
+            }
d9bc5f
+            if (shouldEnable) {
d9bc5f
+                boolean fipsEnabled = SystemConfigurator.configureFIPS(props);
d9bc5f
+                if (sdebug != null) {
d9bc5f
+                    if (fipsEnabled) {
d9bc5f
+                        sdebug.println("FIPS mode support configured and enabled.");
d9bc5f
+                    } else {
d9bc5f
+                        sdebug.println("FIPS mode support disabled.");
d9bc5f
+                    }
d9bc5f
+                }
d9bc5f
+            } else {
d9bc5f
+                if (sdebug != null ) {
d9bc5f
+                    sdebug.println("FIPS mode support disabled by user.");
d9bc5f
+                }
d9bc5f
+            }
d9bc5f
+        } else {
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("WARNING: FIPS mode support can not be enabled without " +
d9bc5f
+                               "system security properties being enabled.");
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
     }
d9bc5f
 
d9bc5f
     /*
d9bc5f
diff --git a/src/java.base/share/classes/java/security/SystemConfigurator.java b/src/java.base/share/classes/java/security/SystemConfigurator.java
d9bc5f
new file mode 100644
d9bc5f
index 00000000000..98ffced455b
d9bc5f
--- /dev/null
d9bc5f
+++ b/src/java.base/share/classes/java/security/SystemConfigurator.java
d9bc5f
@@ -0,0 +1,249 @@
d9bc5f
+/*
d9bc5f
+ * Copyright (c) 2019, 2021, Red Hat, Inc.
d9bc5f
+ *
d9bc5f
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9bc5f
+ *
d9bc5f
+ * This code is free software; you can redistribute it and/or modify it
d9bc5f
+ * under the terms of the GNU General Public License version 2 only, as
d9bc5f
+ * published by the Free Software Foundation.  Oracle designates this
d9bc5f
+ * particular file as subject to the "Classpath" exception as provided
d9bc5f
+ * by Oracle in the LICENSE file that accompanied this code.
d9bc5f
+ *
d9bc5f
+ * This code is distributed in the hope that it will be useful, but WITHOUT
d9bc5f
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9bc5f
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9bc5f
+ * version 2 for more details (a copy is included in the LICENSE file that
d9bc5f
+ * accompanied this code).
d9bc5f
+ *
d9bc5f
+ * You should have received a copy of the GNU General Public License version
d9bc5f
+ * 2 along with this work; if not, write to the Free Software Foundation,
d9bc5f
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9bc5f
+ *
d9bc5f
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9bc5f
+ * or visit www.oracle.com if you need additional information or have any
d9bc5f
+ * questions.
d9bc5f
+ */
d9bc5f
+
d9bc5f
+package java.security;
d9bc5f
+
d9bc5f
+import java.io.BufferedInputStream;
d9bc5f
+import java.io.FileInputStream;
d9bc5f
+import java.io.IOException;
d9bc5f
+
d9bc5f
+import java.util.Iterator;
d9bc5f
+import java.util.Map.Entry;
d9bc5f
+import java.util.Properties;
d9bc5f
+
d9bc5f
+import sun.security.util.Debug;
d9bc5f
+
d9bc5f
+/**
d9bc5f
+ * Internal class to align OpenJDK with global crypto-policies.
d9bc5f
+ * Called from java.security.Security class initialization,
d9bc5f
+ * during startup.
d9bc5f
+ *
d9bc5f
+ */
d9bc5f
+
d9bc5f
+final class SystemConfigurator {
d9bc5f
+
d9bc5f
+    private static final Debug sdebug =
d9bc5f
+            Debug.getInstance("properties");
d9bc5f
+
d9bc5f
+    private static final String CRYPTO_POLICIES_BASE_DIR =
d9bc5f
+            "/etc/crypto-policies";
d9bc5f
+
d9bc5f
+    private static final String CRYPTO_POLICIES_JAVA_CONFIG =
d9bc5f
+            CRYPTO_POLICIES_BASE_DIR + "/back-ends/java.config";
d9bc5f
+
d9bc5f
+    private static boolean systemFipsEnabled = false;
d9bc5f
+    private static boolean plainKeySupportEnabled = false;
d9bc5f
+
d9bc5f
+    private static final String SYSTEMCONF_NATIVE_LIB = "systemconf";
d9bc5f
+
d9bc5f
+    private static native boolean getSystemFIPSEnabled()
d9bc5f
+            throws IOException;
d9bc5f
+
d9bc5f
+    static {
d9bc5f
+        @SuppressWarnings("removal")
d9bc5f
+        var dummy = AccessController.doPrivileged(new PrivilegedAction<Void>() {
d9bc5f
+            public Void run() {
d9bc5f
+                System.loadLibrary(SYSTEMCONF_NATIVE_LIB);
d9bc5f
+                return null;
d9bc5f
+            }
d9bc5f
+        });
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    /*
d9bc5f
+     * Invoked when java.security.Security class is initialized, if
d9bc5f
+     * java.security.disableSystemPropertiesFile property is not set and
d9bc5f
+     * security.useSystemPropertiesFile is true.
d9bc5f
+     */
d9bc5f
+    static boolean configureSysProps(Properties props) {
d9bc5f
+        boolean systemSecPropsLoaded = false;
d9bc5f
+
d9bc5f
+        try (BufferedInputStream bis =
d9bc5f
+                new BufferedInputStream(
d9bc5f
+                        new FileInputStream(CRYPTO_POLICIES_JAVA_CONFIG))) {
d9bc5f
+            props.load(bis);
d9bc5f
+            systemSecPropsLoaded = true;
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("reading system security properties file " +
d9bc5f
+                        CRYPTO_POLICIES_JAVA_CONFIG);
d9bc5f
+                sdebug.println(props.toString());
d9bc5f
+            }
d9bc5f
+        } catch (IOException e) {
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("unable to load security properties from " +
d9bc5f
+                        CRYPTO_POLICIES_JAVA_CONFIG);
d9bc5f
+                e.printStackTrace();
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        return systemSecPropsLoaded;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    /*
d9bc5f
+     * Invoked at the end of java.security.Security initialisation
d9bc5f
+     * if java.security properties have been loaded
d9bc5f
+     */
d9bc5f
+    static boolean configureFIPS(Properties props) {
d9bc5f
+        boolean loadedProps = false;
d9bc5f
+
d9bc5f
+        try {
d9bc5f
+            if (enableFips()) {
d9bc5f
+                if (sdebug != null) { sdebug.println("FIPS mode detected"); }
d9bc5f
+                // Remove all security providers
d9bc5f
+                Iterator<Entry<Object, Object>> i = props.entrySet().iterator();
d9bc5f
+                while (i.hasNext()) {
d9bc5f
+                    Entry<Object, Object> e = i.next();
d9bc5f
+                    if (((String) e.getKey()).startsWith("security.provider")) {
d9bc5f
+                        if (sdebug != null) { sdebug.println("Removing provider: " + e); }
d9bc5f
+                        i.remove();
d9bc5f
+                    }
d9bc5f
+                }
d9bc5f
+                // Add FIPS security providers
d9bc5f
+                String fipsProviderValue = null;
d9bc5f
+                for (int n = 1;
d9bc5f
+                     (fipsProviderValue = (String) props.get("fips.provider." + n)) != null; n++) {
d9bc5f
+                    String fipsProviderKey = "security.provider." + n;
d9bc5f
+                    if (sdebug != null) {
d9bc5f
+                        sdebug.println("Adding provider " + n + ": " +
d9bc5f
+                                fipsProviderKey + "=" + fipsProviderValue);
d9bc5f
+                    }
d9bc5f
+                    props.put(fipsProviderKey, fipsProviderValue);
d9bc5f
+                }
d9bc5f
+                // Add other security properties
d9bc5f
+                String keystoreTypeValue = (String) props.get("fips.keystore.type");
d9bc5f
+                if (keystoreTypeValue != null) {
d9bc5f
+                    String nonFipsKeystoreType = props.getProperty("keystore.type");
d9bc5f
+                    props.put("keystore.type", keystoreTypeValue);
d9bc5f
+                    if (keystoreTypeValue.equals("PKCS11")) {
d9bc5f
+                        // If keystore.type is PKCS11, javax.net.ssl.keyStore
d9bc5f
+                        // must be "NONE". See JDK-8238264.
d9bc5f
+                        System.setProperty("javax.net.ssl.keyStore", "NONE");
d9bc5f
+                    }
d9bc5f
+                    if (System.getProperty("javax.net.ssl.trustStoreType") == null) {
d9bc5f
+                        // If no trustStoreType has been set, use the
d9bc5f
+                        // previous keystore.type under FIPS mode. In
d9bc5f
+                        // a default configuration, the Trust Store will
d9bc5f
+                        // be 'cacerts' (JKS type).
d9bc5f
+                        System.setProperty("javax.net.ssl.trustStoreType",
d9bc5f
+                                nonFipsKeystoreType);
d9bc5f
+                    }
d9bc5f
+                    if (sdebug != null) {
d9bc5f
+                        sdebug.println("FIPS mode default keystore.type = " +
d9bc5f
+                                keystoreTypeValue);
d9bc5f
+                        sdebug.println("FIPS mode javax.net.ssl.keyStore = " +
d9bc5f
+                                System.getProperty("javax.net.ssl.keyStore", ""));
d9bc5f
+                        sdebug.println("FIPS mode javax.net.ssl.trustStoreType = " +
d9bc5f
+                                System.getProperty("javax.net.ssl.trustStoreType", ""));
d9bc5f
+                    }
d9bc5f
+                }
d9bc5f
+                loadedProps = true;
d9bc5f
+                systemFipsEnabled = true;
d9bc5f
+                String plainKeySupport = System.getProperty("com.redhat.fips.plainKeySupport",
d9bc5f
+                                                            "true");
d9bc5f
+                plainKeySupportEnabled = !"false".equals(plainKeySupport);
d9bc5f
+                if (sdebug != null) {
d9bc5f
+                    if (plainKeySupportEnabled) {
d9bc5f
+                        sdebug.println("FIPS support enabled with plain key support");
d9bc5f
+                    } else {
d9bc5f
+                        sdebug.println("FIPS support enabled without plain key support");
d9bc5f
+                    }
d9bc5f
+                }
d9bc5f
+            } else {
d9bc5f
+                if (sdebug != null) { sdebug.println("FIPS mode not detected"); }
d9bc5f
+            }
d9bc5f
+        } catch (Exception e) {
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("unable to load FIPS configuration");
d9bc5f
+                e.printStackTrace();
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        return loadedProps;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    /**
d9bc5f
+     * Returns whether or not global system FIPS alignment is enabled.
d9bc5f
+     *
d9bc5f
+     * Value is always 'false' before java.security.Security class is
d9bc5f
+     * initialized.
d9bc5f
+     *
d9bc5f
+     * Call from out of this package through SharedSecrets:
d9bc5f
+     *   SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+     *           .isSystemFipsEnabled();
d9bc5f
+     *
d9bc5f
+     * @return  a boolean value indicating whether or not global
d9bc5f
+     *          system FIPS alignment is enabled.
d9bc5f
+     */
d9bc5f
+    static boolean isSystemFipsEnabled() {
d9bc5f
+        return systemFipsEnabled;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    /**
d9bc5f
+     * Returns {@code true} if system FIPS alignment is enabled
d9bc5f
+     * and plain key support is allowed.  Plain key support is
d9bc5f
+     * enabled by default but can be disabled with
d9bc5f
+     * {@code -Dcom.redhat.fips.plainKeySupport=false}.
d9bc5f
+     *
d9bc5f
+     * @return a boolean indicating whether plain key support
d9bc5f
+     *         should be enabled.
d9bc5f
+     */
d9bc5f
+    static boolean isPlainKeySupportEnabled() {
d9bc5f
+        return plainKeySupportEnabled;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    /**
d9bc5f
+     * Determines whether FIPS mode should be enabled.
d9bc5f
+     *
d9bc5f
+     * OpenJDK FIPS mode will be enabled only if the system is in
d9bc5f
+     * FIPS mode.
d9bc5f
+     *
d9bc5f
+     * Calls to this method only occur if the system property
d9bc5f
+     * com.redhat.fips is not set to false.
d9bc5f
+     *
d9bc5f
+     * There are 2 possible ways in which OpenJDK detects that the system
d9bc5f
+     * is in FIPS mode: 1) if the NSS SECMOD_GetSystemFIPSEnabled API is
d9bc5f
+     * available at OpenJDK's built-time, it is called; 2) otherwise, the
d9bc5f
+     * /proc/sys/crypto/fips_enabled file is read.
d9bc5f
+     *
d9bc5f
+     * @return true if the system is in FIPS mode
d9bc5f
+     */
d9bc5f
+    private static boolean enableFips() throws Exception {
d9bc5f
+        if (sdebug != null) {
d9bc5f
+            sdebug.println("Calling getSystemFIPSEnabled (libsystemconf)...");
d9bc5f
+        }
d9bc5f
+        try {
d9bc5f
+            boolean fipsEnabled = getSystemFIPSEnabled();
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("Call to getSystemFIPSEnabled (libsystemconf) returned: "
d9bc5f
+                               + fipsEnabled);
d9bc5f
+            }
d9bc5f
+            return fipsEnabled;
d9bc5f
+        } catch (IOException e) {
d9bc5f
+            if (sdebug != null) {
d9bc5f
+                sdebug.println("Call to getSystemFIPSEnabled (libsystemconf) failed:");
d9bc5f
+                sdebug.println(e.getMessage());
d9bc5f
+            }
d9bc5f
+            throw e;
d9bc5f
+        }
d9bc5f
+    }
d9bc5f
+}
d9bc5f
diff --git a/src/java.base/share/classes/jdk/internal/access/JavaSecuritySystemConfiguratorAccess.java b/src/java.base/share/classes/jdk/internal/access/JavaSecuritySystemConfiguratorAccess.java
d9bc5f
new file mode 100644
d9bc5f
index 00000000000..3f3caac64dc
d9bc5f
--- /dev/null
d9bc5f
+++ b/src/java.base/share/classes/jdk/internal/access/JavaSecuritySystemConfiguratorAccess.java
d9bc5f
@@ -0,0 +1,31 @@
d9bc5f
+/*
d9bc5f
+ * Copyright (c) 2020, Red Hat, Inc.
d9bc5f
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9bc5f
+ *
d9bc5f
+ * This code is free software; you can redistribute it and/or modify it
d9bc5f
+ * under the terms of the GNU General Public License version 2 only, as
d9bc5f
+ * published by the Free Software Foundation.  Oracle designates this
d9bc5f
+ * particular file as subject to the "Classpath" exception as provided
d9bc5f
+ * by Oracle in the LICENSE file that accompanied this code.
d9bc5f
+ *
d9bc5f
+ * This code is distributed in the hope that it will be useful, but WITHOUT
d9bc5f
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9bc5f
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9bc5f
+ * version 2 for more details (a copy is included in the LICENSE file that
d9bc5f
+ * accompanied this code).
d9bc5f
+ *
d9bc5f
+ * You should have received a copy of the GNU General Public License version
d9bc5f
+ * 2 along with this work; if not, write to the Free Software Foundation,
d9bc5f
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9bc5f
+ *
d9bc5f
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9bc5f
+ * or visit www.oracle.com if you need additional information or have any
d9bc5f
+ * questions.
d9bc5f
+ */
d9bc5f
+
d9bc5f
+package jdk.internal.access;
d9bc5f
+
d9bc5f
+public interface JavaSecuritySystemConfiguratorAccess {
d9bc5f
+    boolean isSystemFipsEnabled();
d9bc5f
+    boolean isPlainKeySupportEnabled();
d9bc5f
+}
d9bc5f
diff --git a/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java b/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
d9bc5f
index f6d3638c3dd..a1ee182d913 100644
d9bc5f
--- a/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
d9bc5f
+++ b/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java
d9bc5f
@@ -39,6 +39,7 @@ import java.io.FilePermission;
d9bc5f
 import java.io.ObjectInputStream;
d9bc5f
 import java.io.RandomAccessFile;
d9bc5f
 import java.security.ProtectionDomain;
d9bc5f
+import java.security.Security;
d9bc5f
 import java.security.Signature;
d9bc5f
 
d9bc5f
 /** A repository of "shared secrets", which are a mechanism for
d9bc5f
@@ -81,6 +82,7 @@ public class SharedSecrets {
d9bc5f
     private static JavaSecuritySpecAccess javaSecuritySpecAccess;
d9bc5f
     private static JavaxCryptoSealedObjectAccess javaxCryptoSealedObjectAccess;
d9bc5f
     private static JavaxCryptoSpecAccess javaxCryptoSpecAccess;
d9bc5f
+    private static JavaSecuritySystemConfiguratorAccess javaSecuritySystemConfiguratorAccess;
d9bc5f
 
d9bc5f
     public static void setJavaUtilCollectionAccess(JavaUtilCollectionAccess juca) {
d9bc5f
         javaUtilCollectionAccess = juca;
d9bc5f
@@ -442,4 +444,15 @@ public class SharedSecrets {
d9bc5f
             MethodHandles.lookup().ensureInitialized(c);
d9bc5f
         } catch (IllegalAccessException e) {}
d9bc5f
     }
d9bc5f
+
d9bc5f
+    public static void setJavaSecuritySystemConfiguratorAccess(JavaSecuritySystemConfiguratorAccess jssca) {
d9bc5f
+        javaSecuritySystemConfiguratorAccess = jssca;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    public static JavaSecuritySystemConfiguratorAccess getJavaSecuritySystemConfiguratorAccess() {
d9bc5f
+        if (javaSecuritySystemConfiguratorAccess == null) {
d9bc5f
+            ensureClassInitialized(Security.class);
d9bc5f
+        }
d9bc5f
+        return javaSecuritySystemConfiguratorAccess;
d9bc5f
+    }
d9bc5f
 }
d9bc5f
diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java
d9bc5f
index 63bb580eb3a..dbbf11bbb22 100644
d9bc5f
--- a/src/java.base/share/classes/module-info.java
d9bc5f
+++ b/src/java.base/share/classes/module-info.java
d9bc5f
@@ -152,6 +152,8 @@ module java.base {
d9bc5f
         java.naming,
d9bc5f
         java.rmi,
d9bc5f
         jdk.charsets,
d9bc5f
+        jdk.crypto.cryptoki,
d9bc5f
+        jdk.crypto.ec,
d9bc5f
         jdk.jartool,
d9bc5f
         jdk.jlink,
d9bc5f
         jdk.net,
d9bc5f
diff --git a/src/java.base/share/classes/sun/security/provider/SunEntries.java b/src/java.base/share/classes/sun/security/provider/SunEntries.java
d9bc5f
index 912cad59714..709d32912ca 100644
d9bc5f
--- a/src/java.base/share/classes/sun/security/provider/SunEntries.java
d9bc5f
+++ b/src/java.base/share/classes/sun/security/provider/SunEntries.java
d9bc5f
@@ -30,6 +30,7 @@ import java.net.*;
d9bc5f
 import java.util.*;
d9bc5f
 import java.security.*;
d9bc5f
 
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import jdk.internal.util.StaticProperty;
d9bc5f
 import sun.security.action.GetPropertyAction;
d9bc5f
 import sun.security.util.SecurityProviderConstants;
d9bc5f
@@ -83,6 +84,10 @@ import static sun.security.util.SecurityProviderConstants.getAliases;
d9bc5f
 
d9bc5f
 public final class SunEntries {
d9bc5f
 
d9bc5f
+    private static final boolean systemFipsEnabled =
d9bc5f
+            SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+            .isSystemFipsEnabled();
d9bc5f
+
d9bc5f
     // the default algo used by SecureRandom class for new SecureRandom() calls
d9bc5f
     public static final String DEF_SECURE_RANDOM_ALGO;
d9bc5f
 
d9bc5f
@@ -94,99 +99,101 @@ public final class SunEntries {
d9bc5f
         // common attribute map
d9bc5f
         HashMap<String, String> attrs = new HashMap<>(3);
d9bc5f
 
d9bc5f
-        /*
d9bc5f
-         * SecureRandom engines
d9bc5f
-         */
d9bc5f
-        attrs.put("ThreadSafe", "true");
d9bc5f
-        if (NativePRNG.isAvailable()) {
d9bc5f
-            add(p, "SecureRandom", "NativePRNG",
d9bc5f
-                    "sun.security.provider.NativePRNG", attrs);
d9bc5f
-        }
d9bc5f
-        if (NativePRNG.Blocking.isAvailable()) {
d9bc5f
-            add(p, "SecureRandom", "NativePRNGBlocking",
d9bc5f
-                    "sun.security.provider.NativePRNG$Blocking", attrs);
d9bc5f
-        }
d9bc5f
-        if (NativePRNG.NonBlocking.isAvailable()) {
d9bc5f
-            add(p, "SecureRandom", "NativePRNGNonBlocking",
d9bc5f
-                    "sun.security.provider.NativePRNG$NonBlocking", attrs);
d9bc5f
-        }
d9bc5f
-        attrs.put("ImplementedIn", "Software");
d9bc5f
-        add(p, "SecureRandom", "DRBG", "sun.security.provider.DRBG", attrs);
d9bc5f
-        add(p, "SecureRandom", "SHA1PRNG",
d9bc5f
-                "sun.security.provider.SecureRandom", attrs);
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Signature engines
d9bc5f
-         */
d9bc5f
-        attrs.clear();
d9bc5f
-        String dsaKeyClasses = "java.security.interfaces.DSAPublicKey" +
d9bc5f
-                "|java.security.interfaces.DSAPrivateKey";
d9bc5f
-        attrs.put("SupportedKeyClasses", dsaKeyClasses);
d9bc5f
-        attrs.put("ImplementedIn", "Software");
d9bc5f
-
d9bc5f
-        attrs.put("KeySize", "1024"); // for NONE and SHA1 DSA signatures
d9bc5f
-
d9bc5f
-        addWithAlias(p, "Signature", "SHA1withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA1withDSA", attrs);
d9bc5f
-        addWithAlias(p, "Signature", "NONEwithDSA",
d9bc5f
-                "sun.security.provider.DSA$RawDSA", attrs);
d9bc5f
-
d9bc5f
-        // for DSA signatures with 224/256-bit digests
d9bc5f
-        attrs.put("KeySize", "2048");
d9bc5f
-
d9bc5f
-        addWithAlias(p, "Signature", "SHA224withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA224withDSA", attrs);
d9bc5f
-        addWithAlias(p, "Signature", "SHA256withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA256withDSA", attrs);
d9bc5f
-
d9bc5f
-        addWithAlias(p, "Signature", "SHA3-224withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA3_224withDSA", attrs);
d9bc5f
-        addWithAlias(p, "Signature", "SHA3-256withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA3_256withDSA", attrs);
d9bc5f
-
d9bc5f
-        attrs.put("KeySize", "3072"); // for DSA sig using 384/512-bit digests
d9bc5f
-
d9bc5f
-        addWithAlias(p, "Signature", "SHA384withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA384withDSA", attrs);
d9bc5f
-        addWithAlias(p, "Signature", "SHA512withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA512withDSA", attrs);
d9bc5f
-        addWithAlias(p, "Signature", "SHA3-384withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA3_384withDSA", attrs);
d9bc5f
-        addWithAlias(p, "Signature", "SHA3-512withDSA",
d9bc5f
-                "sun.security.provider.DSA$SHA3_512withDSA", attrs);
d9bc5f
-
d9bc5f
-        attrs.remove("KeySize");
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            /*
d9bc5f
+             * SecureRandom engines
d9bc5f
+             */
d9bc5f
+            attrs.put("ThreadSafe", "true");
d9bc5f
+            if (NativePRNG.isAvailable()) {
d9bc5f
+                add(p, "SecureRandom", "NativePRNG",
d9bc5f
+                        "sun.security.provider.NativePRNG", attrs);
d9bc5f
+            }
d9bc5f
+            if (NativePRNG.Blocking.isAvailable()) {
d9bc5f
+                add(p, "SecureRandom", "NativePRNGBlocking",
d9bc5f
+                        "sun.security.provider.NativePRNG$Blocking", attrs);
d9bc5f
+            }
d9bc5f
+            if (NativePRNG.NonBlocking.isAvailable()) {
d9bc5f
+                add(p, "SecureRandom", "NativePRNGNonBlocking",
d9bc5f
+                        "sun.security.provider.NativePRNG$NonBlocking", attrs);
d9bc5f
+            }
d9bc5f
+            attrs.put("ImplementedIn", "Software");
d9bc5f
+            add(p, "SecureRandom", "DRBG", "sun.security.provider.DRBG", attrs);
d9bc5f
+            add(p, "SecureRandom", "SHA1PRNG",
d9bc5f
+                    "sun.security.provider.SecureRandom", attrs);
d9bc5f
 
d9bc5f
-        add(p, "Signature", "SHA1withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA1withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "NONEwithDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$RawDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA224withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA224withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA256withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA256withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA384withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA384withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA512withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA512withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA3-224withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA3_224withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA3-256withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA3_256withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA3-384withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA3_384withDSAinP1363Format");
d9bc5f
-        add(p, "Signature", "SHA3-512withDSAinP1363Format",
d9bc5f
-                "sun.security.provider.DSA$SHA3_512withDSAinP1363Format");
d9bc5f
-        /*
d9bc5f
-         *  Key Pair Generator engines
d9bc5f
-         */
d9bc5f
-        attrs.clear();
d9bc5f
-        attrs.put("ImplementedIn", "Software");
d9bc5f
-        attrs.put("KeySize", "2048"); // for DSA KPG and APG only
d9bc5f
+            /*
d9bc5f
+             * Signature engines
d9bc5f
+             */
d9bc5f
+            attrs.clear();
d9bc5f
+            String dsaKeyClasses = "java.security.interfaces.DSAPublicKey" +
d9bc5f
+                    "|java.security.interfaces.DSAPrivateKey";
d9bc5f
+            attrs.put("SupportedKeyClasses", dsaKeyClasses);
d9bc5f
+            attrs.put("ImplementedIn", "Software");
d9bc5f
+
d9bc5f
+            attrs.put("KeySize", "1024"); // for NONE and SHA1 DSA signatures
d9bc5f
+
d9bc5f
+            addWithAlias(p, "Signature", "SHA1withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA1withDSA", attrs);
d9bc5f
+            addWithAlias(p, "Signature", "NONEwithDSA",
d9bc5f
+                    "sun.security.provider.DSA$RawDSA", attrs);
d9bc5f
+
d9bc5f
+            // for DSA signatures with 224/256-bit digests
d9bc5f
+            attrs.put("KeySize", "2048");
d9bc5f
+
d9bc5f
+            addWithAlias(p, "Signature", "SHA224withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA224withDSA", attrs);
d9bc5f
+            addWithAlias(p, "Signature", "SHA256withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA256withDSA", attrs);
d9bc5f
+
d9bc5f
+            addWithAlias(p, "Signature", "SHA3-224withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_224withDSA", attrs);
d9bc5f
+            addWithAlias(p, "Signature", "SHA3-256withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_256withDSA", attrs);
d9bc5f
+
d9bc5f
+            attrs.put("KeySize", "3072"); // for DSA sig using 384/512-bit digests
d9bc5f
+
d9bc5f
+            addWithAlias(p, "Signature", "SHA384withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA384withDSA", attrs);
d9bc5f
+            addWithAlias(p, "Signature", "SHA512withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA512withDSA", attrs);
d9bc5f
+            addWithAlias(p, "Signature", "SHA3-384withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_384withDSA", attrs);
d9bc5f
+            addWithAlias(p, "Signature", "SHA3-512withDSA",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_512withDSA", attrs);
d9bc5f
+
d9bc5f
+            attrs.remove("KeySize");
d9bc5f
+
d9bc5f
+            add(p, "Signature", "SHA1withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA1withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "NONEwithDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$RawDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA224withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA224withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA256withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA256withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA384withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA384withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA512withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA512withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA3-224withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_224withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA3-256withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_256withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA3-384withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_384withDSAinP1363Format");
d9bc5f
+            add(p, "Signature", "SHA3-512withDSAinP1363Format",
d9bc5f
+                    "sun.security.provider.DSA$SHA3_512withDSAinP1363Format");
d9bc5f
+            /*
d9bc5f
+             *  Key Pair Generator engines
d9bc5f
+             */
d9bc5f
+            attrs.clear();
d9bc5f
+            attrs.put("ImplementedIn", "Software");
d9bc5f
+            attrs.put("KeySize", "2048"); // for DSA KPG and APG only
d9bc5f
 
d9bc5f
-        String dsaKPGImplClass = "sun.security.provider.DSAKeyPairGenerator$";
d9bc5f
-        dsaKPGImplClass += (useLegacyDSA? "Legacy" : "Current");
d9bc5f
-        addWithAlias(p, "KeyPairGenerator", "DSA", dsaKPGImplClass, attrs);
d9bc5f
+            String dsaKPGImplClass = "sun.security.provider.DSAKeyPairGenerator$";
d9bc5f
+            dsaKPGImplClass += (useLegacyDSA? "Legacy" : "Current");
d9bc5f
+            addWithAlias(p, "KeyPairGenerator", "DSA", dsaKPGImplClass, attrs);
d9bc5f
+        }
d9bc5f
 
d9bc5f
         /*
d9bc5f
          * Algorithm Parameter Generator engines
d9bc5f
@@ -201,40 +208,42 @@ public final class SunEntries {
d9bc5f
         addWithAlias(p, "AlgorithmParameters", "DSA",
d9bc5f
                 "sun.security.provider.DSAParameters", attrs);
d9bc5f
 
d9bc5f
-        /*
d9bc5f
-         * Key factories
d9bc5f
-         */
d9bc5f
-        addWithAlias(p, "KeyFactory", "DSA",
d9bc5f
-                "sun.security.provider.DSAKeyFactory", attrs);
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Digest engines
d9bc5f
-         */
d9bc5f
-        add(p, "MessageDigest", "MD2", "sun.security.provider.MD2", attrs);
d9bc5f
-        add(p, "MessageDigest", "MD5", "sun.security.provider.MD5", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-1", "sun.security.provider.SHA",
d9bc5f
-                attrs);
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            /*
d9bc5f
+             * Key factories
d9bc5f
+             */
d9bc5f
+            addWithAlias(p, "KeyFactory", "DSA",
d9bc5f
+                    "sun.security.provider.DSAKeyFactory", attrs);
d9bc5f
 
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-224",
d9bc5f
-                "sun.security.provider.SHA2$SHA224", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-256",
d9bc5f
-                "sun.security.provider.SHA2$SHA256", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-384",
d9bc5f
-                "sun.security.provider.SHA5$SHA384", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-512",
d9bc5f
-                "sun.security.provider.SHA5$SHA512", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-512/224",
d9bc5f
-                "sun.security.provider.SHA5$SHA512_224", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA-512/256",
d9bc5f
-                "sun.security.provider.SHA5$SHA512_256", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA3-224",
d9bc5f
-                "sun.security.provider.SHA3$SHA224", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA3-256",
d9bc5f
-                "sun.security.provider.SHA3$SHA256", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA3-384",
d9bc5f
-                "sun.security.provider.SHA3$SHA384", attrs);
d9bc5f
-        addWithAlias(p, "MessageDigest", "SHA3-512",
d9bc5f
-                "sun.security.provider.SHA3$SHA512", attrs);
d9bc5f
+            /*
d9bc5f
+             * Digest engines
d9bc5f
+             */
d9bc5f
+            add(p, "MessageDigest", "MD2", "sun.security.provider.MD2", attrs);
d9bc5f
+            add(p, "MessageDigest", "MD5", "sun.security.provider.MD5", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-1", "sun.security.provider.SHA",
d9bc5f
+                    attrs);
d9bc5f
+
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-224",
d9bc5f
+                    "sun.security.provider.SHA2$SHA224", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-256",
d9bc5f
+                    "sun.security.provider.SHA2$SHA256", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-384",
d9bc5f
+                    "sun.security.provider.SHA5$SHA384", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-512",
d9bc5f
+                    "sun.security.provider.SHA5$SHA512", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-512/224",
d9bc5f
+                    "sun.security.provider.SHA5$SHA512_224", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA-512/256",
d9bc5f
+                    "sun.security.provider.SHA5$SHA512_256", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA3-224",
d9bc5f
+                    "sun.security.provider.SHA3$SHA224", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA3-256",
d9bc5f
+                    "sun.security.provider.SHA3$SHA256", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA3-384",
d9bc5f
+                    "sun.security.provider.SHA3$SHA384", attrs);
d9bc5f
+            addWithAlias(p, "MessageDigest", "SHA3-512",
d9bc5f
+                    "sun.security.provider.SHA3$SHA512", attrs);
d9bc5f
+        }
d9bc5f
 
d9bc5f
         /*
d9bc5f
          * Certificates
d9bc5f
diff --git a/src/java.base/share/classes/sun/security/rsa/SunRsaSignEntries.java b/src/java.base/share/classes/sun/security/rsa/SunRsaSignEntries.java
d9bc5f
index ca79f25cc44..16c5ad2e227 100644
d9bc5f
--- a/src/java.base/share/classes/sun/security/rsa/SunRsaSignEntries.java
d9bc5f
+++ b/src/java.base/share/classes/sun/security/rsa/SunRsaSignEntries.java
d9bc5f
@@ -27,6 +27,7 @@ package sun.security.rsa;
d9bc5f
 
d9bc5f
 import java.util.*;
d9bc5f
 import java.security.Provider;
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import static sun.security.util.SecurityProviderConstants.getAliases;
d9bc5f
 
d9bc5f
 /**
d9bc5f
@@ -36,6 +37,10 @@ import static sun.security.util.SecurityProviderConstants.getAliases;
d9bc5f
  */
d9bc5f
 public final class SunRsaSignEntries {
d9bc5f
 
d9bc5f
+    private static final boolean systemFipsEnabled =
d9bc5f
+            SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+            .isSystemFipsEnabled();
d9bc5f
+
d9bc5f
     private void add(Provider p, String type, String algo, String cn,
d9bc5f
              List<String> aliases, HashMap<String, String> attrs) {
d9bc5f
          services.add(new Provider.Service(p, type, algo, cn,
d9bc5f
@@ -56,49 +61,52 @@ public final class SunRsaSignEntries {
d9bc5f
         // start populating content using the specified provider
d9bc5f
         // common attribute map
d9bc5f
         HashMap<String, String> attrs = new HashMap<>(3);
d9bc5f
-        attrs.put("SupportedKeyClasses",
d9bc5f
-                "java.security.interfaces.RSAPublicKey" +
d9bc5f
-                "|java.security.interfaces.RSAPrivateKey");
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            attrs.put("SupportedKeyClasses",
d9bc5f
+                    "java.security.interfaces.RSAPublicKey" +
d9bc5f
+                    "|java.security.interfaces.RSAPrivateKey");
d9bc5f
+
d9bc5f
+            add(p, "KeyFactory", "RSA",
d9bc5f
+                    "sun.security.rsa.RSAKeyFactory$Legacy",
d9bc5f
+                    getAliases("PKCS1"), null);
d9bc5f
+            add(p, "KeyPairGenerator", "RSA",
d9bc5f
+                    "sun.security.rsa.RSAKeyPairGenerator$Legacy",
d9bc5f
+                    getAliases("PKCS1"), null);
d9bc5f
+            addA(p, "Signature", "MD2withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$MD2withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "MD5withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$MD5withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA1withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA1withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA224withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA224withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA256withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA256withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA384withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA384withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA512withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA512withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA512/224withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA512_224withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA512/256withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA512_256withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA3-224withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA3_224withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA3-256withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA3_256withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA3-384withRSA",
d9bc5f
+                   "sun.security.rsa.RSASignature$SHA3_384withRSA", attrs);
d9bc5f
+            addA(p, "Signature", "SHA3-512withRSA",
d9bc5f
+                    "sun.security.rsa.RSASignature$SHA3_512withRSA", attrs);
d9bc5f
 
d9bc5f
-        add(p, "KeyFactory", "RSA",
d9bc5f
-                "sun.security.rsa.RSAKeyFactory$Legacy",
d9bc5f
-                getAliases("PKCS1"), null);
d9bc5f
-        add(p, "KeyPairGenerator", "RSA",
d9bc5f
-                "sun.security.rsa.RSAKeyPairGenerator$Legacy",
d9bc5f
-                getAliases("PKCS1"), null);
d9bc5f
-        addA(p, "Signature", "MD2withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$MD2withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "MD5withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$MD5withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA1withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA1withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA224withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA224withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA256withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA256withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA384withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA384withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA512withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA512withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA512/224withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA512_224withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA512/256withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA512_256withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA3-224withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA3_224withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA3-256withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA3_256withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA3-384withRSA",
d9bc5f
-               "sun.security.rsa.RSASignature$SHA3_384withRSA", attrs);
d9bc5f
-        addA(p, "Signature", "SHA3-512withRSA",
d9bc5f
-                "sun.security.rsa.RSASignature$SHA3_512withRSA", attrs);
d9bc5f
+            addA(p, "KeyFactory", "RSASSA-PSS",
d9bc5f
+                    "sun.security.rsa.RSAKeyFactory$PSS", attrs);
d9bc5f
+            addA(p, "KeyPairGenerator", "RSASSA-PSS",
d9bc5f
+                    "sun.security.rsa.RSAKeyPairGenerator$PSS", attrs);
d9bc5f
+            addA(p, "Signature", "RSASSA-PSS",
d9bc5f
+                    "sun.security.rsa.RSAPSSSignature", attrs);
d9bc5f
+        }
d9bc5f
 
d9bc5f
-        addA(p, "KeyFactory", "RSASSA-PSS",
d9bc5f
-                "sun.security.rsa.RSAKeyFactory$PSS", attrs);
d9bc5f
-        addA(p, "KeyPairGenerator", "RSASSA-PSS",
d9bc5f
-                "sun.security.rsa.RSAKeyPairGenerator$PSS", attrs);
d9bc5f
-        addA(p, "Signature", "RSASSA-PSS",
d9bc5f
-                "sun.security.rsa.RSAPSSSignature", attrs);
d9bc5f
         addA(p, "AlgorithmParameters", "RSASSA-PSS",
d9bc5f
                 "sun.security.rsa.PSSParameters", null);
d9bc5f
     }
d9bc5f
diff --git a/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java b/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
d9bc5f
index 6ffdfeda18d..775b185fb06 100644
d9bc5f
--- a/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
d9bc5f
+++ b/src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java
d9bc5f
@@ -32,6 +32,7 @@ import java.security.cert.*;
d9bc5f
 import java.util.*;
d9bc5f
 import java.util.concurrent.locks.ReentrantLock;
d9bc5f
 import javax.net.ssl.*;
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import sun.security.action.GetPropertyAction;
d9bc5f
 import sun.security.provider.certpath.AlgorithmChecker;
d9bc5f
 import sun.security.validator.Validator;
d9bc5f
@@ -536,22 +537,40 @@ public abstract class SSLContextImpl extends SSLContextSpi {
d9bc5f
         private static final List<CipherSuite> serverDefaultCipherSuites;
d9bc5f
 
d9bc5f
         static {
d9bc5f
-            supportedProtocols = Arrays.asList(
d9bc5f
-                ProtocolVersion.TLS13,
d9bc5f
-                ProtocolVersion.TLS12,
d9bc5f
-                ProtocolVersion.TLS11,
d9bc5f
-                ProtocolVersion.TLS10,
d9bc5f
-                ProtocolVersion.SSL30,
d9bc5f
-                ProtocolVersion.SSL20Hello
d9bc5f
-            );
d9bc5f
-
d9bc5f
-            serverDefaultProtocols = getAvailableProtocols(
d9bc5f
-                    new ProtocolVersion[] {
d9bc5f
-                ProtocolVersion.TLS13,
d9bc5f
-                ProtocolVersion.TLS12,
d9bc5f
-                ProtocolVersion.TLS11,
d9bc5f
-                ProtocolVersion.TLS10
d9bc5f
-            });
d9bc5f
+            if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+                    .isSystemFipsEnabled()) {
d9bc5f
+                // RH1860986: TLSv1.3 key derivation not supported with
d9bc5f
+                // the Security Providers available in system FIPS mode.
d9bc5f
+                supportedProtocols = Arrays.asList(
d9bc5f
+                    ProtocolVersion.TLS12,
d9bc5f
+                    ProtocolVersion.TLS11,
d9bc5f
+                    ProtocolVersion.TLS10
d9bc5f
+                );
d9bc5f
+
d9bc5f
+                serverDefaultProtocols = getAvailableProtocols(
d9bc5f
+                        new ProtocolVersion[] {
d9bc5f
+                    ProtocolVersion.TLS12,
d9bc5f
+                    ProtocolVersion.TLS11,
d9bc5f
+                    ProtocolVersion.TLS10
d9bc5f
+                });
d9bc5f
+            } else {
d9bc5f
+                supportedProtocols = Arrays.asList(
d9bc5f
+                    ProtocolVersion.TLS13,
d9bc5f
+                    ProtocolVersion.TLS12,
d9bc5f
+                    ProtocolVersion.TLS11,
d9bc5f
+                    ProtocolVersion.TLS10,
d9bc5f
+                    ProtocolVersion.SSL30,
d9bc5f
+                    ProtocolVersion.SSL20Hello
d9bc5f
+                );
d9bc5f
+
d9bc5f
+                serverDefaultProtocols = getAvailableProtocols(
d9bc5f
+                        new ProtocolVersion[] {
d9bc5f
+                    ProtocolVersion.TLS13,
d9bc5f
+                    ProtocolVersion.TLS12,
d9bc5f
+                    ProtocolVersion.TLS11,
d9bc5f
+                    ProtocolVersion.TLS10
d9bc5f
+                });
d9bc5f
+            }
d9bc5f
 
d9bc5f
             supportedCipherSuites = getApplicableSupportedCipherSuites(
d9bc5f
                     supportedProtocols);
d9bc5f
@@ -842,12 +861,23 @@ public abstract class SSLContextImpl extends SSLContextSpi {
d9bc5f
             ProtocolVersion[] candidates;
d9bc5f
             if (refactored.isEmpty()) {
d9bc5f
                 // Client and server use the same default protocols.
d9bc5f
-                candidates = new ProtocolVersion[] {
d9bc5f
-                        ProtocolVersion.TLS13,
d9bc5f
-                        ProtocolVersion.TLS12,
d9bc5f
-                        ProtocolVersion.TLS11,
d9bc5f
-                        ProtocolVersion.TLS10
d9bc5f
-                    };
d9bc5f
+                if (SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+                        .isSystemFipsEnabled()) {
d9bc5f
+                    // RH1860986: TLSv1.3 key derivation not supported with
d9bc5f
+                    // the Security Providers available in system FIPS mode.
d9bc5f
+                    candidates = new ProtocolVersion[] {
d9bc5f
+                            ProtocolVersion.TLS12,
d9bc5f
+                            ProtocolVersion.TLS11,
d9bc5f
+                            ProtocolVersion.TLS10
d9bc5f
+                        };
d9bc5f
+                } else {
d9bc5f
+                    candidates = new ProtocolVersion[] {
d9bc5f
+                            ProtocolVersion.TLS13,
d9bc5f
+                            ProtocolVersion.TLS12,
d9bc5f
+                            ProtocolVersion.TLS11,
d9bc5f
+                            ProtocolVersion.TLS10
d9bc5f
+                        };
d9bc5f
+                }
d9bc5f
             } else {
d9bc5f
                 // Use the customized TLS protocols.
d9bc5f
                 candidates =
d9bc5f
diff --git a/src/java.base/share/classes/sun/security/ssl/SunJSSE.java b/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
d9bc5f
index 894e26dfad8..8b16378b96b 100644
d9bc5f
--- a/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
d9bc5f
+++ b/src/java.base/share/classes/sun/security/ssl/SunJSSE.java
d9bc5f
@@ -27,6 +27,8 @@ package sun.security.ssl;
d9bc5f
 
d9bc5f
 import java.security.*;
d9bc5f
 import java.util.*;
d9bc5f
+
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import static sun.security.util.SecurityConstants.PROVIDER_VER;
d9bc5f
 
d9bc5f
 /**
d9bc5f
@@ -102,8 +104,13 @@ public class SunJSSE extends java.security.Provider {
d9bc5f
             "sun.security.ssl.SSLContextImpl$TLS11Context", null, null);
d9bc5f
         ps("SSLContext", "TLSv1.2",
d9bc5f
             "sun.security.ssl.SSLContextImpl$TLS12Context", null, null);
d9bc5f
-        ps("SSLContext", "TLSv1.3",
d9bc5f
-            "sun.security.ssl.SSLContextImpl$TLS13Context", null, null);
d9bc5f
+        if (!SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+                .isSystemFipsEnabled()) {
d9bc5f
+            // RH1860986: TLSv1.3 key derivation not supported with
d9bc5f
+            // the Security Providers available in system FIPS mode.
d9bc5f
+            ps("SSLContext", "TLSv1.3",
d9bc5f
+                "sun.security.ssl.SSLContextImpl$TLS13Context", null, null);
d9bc5f
+        }
d9bc5f
         ps("SSLContext", "TLS",
d9bc5f
             "sun.security.ssl.SSLContextImpl$TLSContext",
d9bc5f
             List.of("SSL"), null);
d9bc5f
diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security
d9bc5f
index 6d91e3f8e4e..adfaf57d29e 100644
d9bc5f
--- a/src/java.base/share/conf/security/java.security
d9bc5f
+++ b/src/java.base/share/conf/security/java.security
d9bc5f
@@ -79,6 +79,16 @@ security.provider.tbd=Apple
d9bc5f
 #endif
d9bc5f
 security.provider.tbd=SunPKCS11
d9bc5f
 
d9bc5f
+#
d9bc5f
+# Security providers used when FIPS mode support is active
d9bc5f
+#
d9bc5f
+fips.provider.1=SunPKCS11 ${java.home}/conf/security/nss.fips.cfg
d9bc5f
+fips.provider.2=SUN
d9bc5f
+fips.provider.3=SunEC
d9bc5f
+fips.provider.4=SunJSSE
d9bc5f
+fips.provider.5=SunJCE
d9bc5f
+fips.provider.6=SunRsaSign
d9bc5f
+
d9bc5f
 #
d9bc5f
 # A list of preferred providers for specific algorithms. These providers will
d9bc5f
 # be searched for matching algorithms before the list of registered providers.
d9bc5f
@@ -289,6 +299,11 @@ policy.ignoreIdentityScope=false
d9bc5f
 #
d9bc5f
 keystore.type=pkcs12
d9bc5f
 
d9bc5f
+#
d9bc5f
+# Default keystore type used when global crypto-policies are set to FIPS.
d9bc5f
+#
d9bc5f
+fips.keystore.type=PKCS11
d9bc5f
+
d9bc5f
 #
d9bc5f
 # Controls compatibility mode for JKS and PKCS12 keystore types.
d9bc5f
 #
d9bc5f
@@ -326,6 +341,13 @@ package.definition=sun.misc.,\
d9bc5f
 #
d9bc5f
 security.overridePropertiesFile=true
d9bc5f
 
d9bc5f
+#
d9bc5f
+# Determines whether this properties file will be appended to
d9bc5f
+# using the system properties file stored at
d9bc5f
+# /etc/crypto-policies/back-ends/java.config
d9bc5f
+#
d9bc5f
+security.useSystemPropertiesFile=false
d9bc5f
+
d9bc5f
 #
d9bc5f
 # Determines the default key and trust manager factory algorithms for
d9bc5f
 # the javax.net.ssl package.
d9bc5f
diff --git a/src/java.base/share/lib/security/default.policy b/src/java.base/share/lib/security/default.policy
d9bc5f
index b22f26947af..3ee2ce6ea88 100644
d9bc5f
--- a/src/java.base/share/lib/security/default.policy
d9bc5f
+++ b/src/java.base/share/lib/security/default.policy
d9bc5f
@@ -121,6 +121,7 @@ grant codeBase "jrt:/jdk.charsets" {
d9bc5f
 grant codeBase "jrt:/jdk.crypto.ec" {
d9bc5f
     permission java.lang.RuntimePermission
d9bc5f
                    "accessClassInPackage.sun.security.*";
d9bc5f
+    permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.access";
d9bc5f
     permission java.lang.RuntimePermission "loadLibrary.sunec";
d9bc5f
     permission java.security.SecurityPermission "putProviderProperty.SunEC";
d9bc5f
     permission java.security.SecurityPermission "clearProviderProperties.SunEC";
d9bc5f
@@ -130,6 +131,7 @@ grant codeBase "jrt:/jdk.crypto.ec" {
d9bc5f
 grant codeBase "jrt:/jdk.crypto.cryptoki" {
d9bc5f
     permission java.lang.RuntimePermission
d9bc5f
                    "accessClassInPackage.com.sun.crypto.provider";
d9bc5f
+    permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.access";
d9bc5f
     permission java.lang.RuntimePermission "accessClassInPackage.jdk.internal.misc";
d9bc5f
     permission java.lang.RuntimePermission
d9bc5f
                    "accessClassInPackage.sun.security.*";
d9bc5f
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java
d9bc5f
new file mode 100644
d9bc5f
index 00000000000..bee3a1e1537
d9bc5f
--- /dev/null
d9bc5f
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/FIPSKeyImporter.java
d9bc5f
@@ -0,0 +1,291 @@
d9bc5f
+/*
d9bc5f
+ * Copyright (c) 2021, Red Hat, Inc.
d9bc5f
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9bc5f
+ *
d9bc5f
+ * This code is free software; you can redistribute it and/or modify it
d9bc5f
+ * under the terms of the GNU General Public License version 2 only, as
d9bc5f
+ * published by the Free Software Foundation.  Oracle designates this
d9bc5f
+ * particular file as subject to the "Classpath" exception as provided
d9bc5f
+ * by Oracle in the LICENSE file that accompanied this code.
d9bc5f
+ *
d9bc5f
+ * This code is distributed in the hope that it will be useful, but WITHOUT
d9bc5f
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9bc5f
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9bc5f
+ * version 2 for more details (a copy is included in the LICENSE file that
d9bc5f
+ * accompanied this code).
d9bc5f
+ *
d9bc5f
+ * You should have received a copy of the GNU General Public License version
d9bc5f
+ * 2 along with this work; if not, write to the Free Software Foundation,
d9bc5f
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9bc5f
+ *
d9bc5f
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9bc5f
+ * or visit www.oracle.com if you need additional information or have any
d9bc5f
+ * questions.
d9bc5f
+ */
d9bc5f
+
d9bc5f
+package sun.security.pkcs11;
d9bc5f
+
d9bc5f
+import java.math.BigInteger;
d9bc5f
+import java.security.KeyFactory;
d9bc5f
+import java.security.Provider;
d9bc5f
+import java.security.Security;
d9bc5f
+import java.util.HashMap;
d9bc5f
+import java.util.Map;
d9bc5f
+import java.util.concurrent.locks.ReentrantLock;
d9bc5f
+
d9bc5f
+import javax.crypto.Cipher;
d9bc5f
+import javax.crypto.spec.DHPrivateKeySpec;
d9bc5f
+import javax.crypto.spec.IvParameterSpec;
d9bc5f
+
d9bc5f
+import sun.security.jca.JCAUtil;
d9bc5f
+import sun.security.pkcs11.TemplateManager;
d9bc5f
+import sun.security.pkcs11.wrapper.CK_ATTRIBUTE;
d9bc5f
+import sun.security.pkcs11.wrapper.CK_MECHANISM;
d9bc5f
+import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
d9bc5f
+import static sun.security.pkcs11.wrapper.PKCS11Exception.*;
d9bc5f
+import sun.security.pkcs11.wrapper.PKCS11Exception;
d9bc5f
+import sun.security.rsa.RSAUtil.KeyType;
d9bc5f
+import sun.security.util.Debug;
d9bc5f
+import sun.security.util.ECUtil;
d9bc5f
+
d9bc5f
+final class FIPSKeyImporter {
d9bc5f
+
d9bc5f
+    private static final Debug debug =
d9bc5f
+            Debug.getInstance("sunpkcs11");
d9bc5f
+
d9bc5f
+    private static P11Key importerKey = null;
d9bc5f
+    private static final ReentrantLock importerKeyLock = new ReentrantLock();
d9bc5f
+    private static CK_MECHANISM importerKeyMechanism = null;
d9bc5f
+    private static Cipher importerCipher = null;
d9bc5f
+
d9bc5f
+    private static Provider sunECProvider = null;
d9bc5f
+    private static final ReentrantLock sunECProviderLock = new ReentrantLock();
d9bc5f
+
d9bc5f
+    private static KeyFactory DHKF = null;
d9bc5f
+    private static final ReentrantLock DHKFLock = new ReentrantLock();
d9bc5f
+
d9bc5f
+    static Long importKey(SunPKCS11 sunPKCS11, long hSession, CK_ATTRIBUTE[] attributes)
d9bc5f
+            throws PKCS11Exception {
d9bc5f
+        long keyID = -1;
d9bc5f
+        Token token = sunPKCS11.getToken();
d9bc5f
+        if (debug != null) {
d9bc5f
+            debug.println("Private or Secret key will be imported in" +
d9bc5f
+                    " system FIPS mode.");
d9bc5f
+        }
d9bc5f
+        if (importerKey == null) {
d9bc5f
+            importerKeyLock.lock();
d9bc5f
+            try {
d9bc5f
+                if (importerKey == null) {
d9bc5f
+                    if (importerKeyMechanism == null) {
d9bc5f
+                        // Importer Key creation has not been tried yet. Try it.
d9bc5f
+                        createImporterKey(token);
d9bc5f
+                    }
d9bc5f
+                    if (importerKey == null || importerCipher == null) {
d9bc5f
+                        if (debug != null) {
d9bc5f
+                            debug.println("Importer Key could not be" +
d9bc5f
+                                    " generated.");
d9bc5f
+                        }
d9bc5f
+                        throw new PKCS11Exception(CKR_GENERAL_ERROR);
d9bc5f
+                    }
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Importer Key successfully" +
d9bc5f
+                                " generated.");
d9bc5f
+                    }
d9bc5f
+                }
d9bc5f
+            } finally {
d9bc5f
+                importerKeyLock.unlock();
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        long importerKeyID = importerKey.getKeyID();
d9bc5f
+        try {
d9bc5f
+            byte[] keyBytes = null;
d9bc5f
+            byte[] encKeyBytes = null;
d9bc5f
+            long keyClass = 0L;
d9bc5f
+            long keyType = 0L;
d9bc5f
+            Map<Long, CK_ATTRIBUTE> attrsMap = new HashMap<>();
d9bc5f
+            for (CK_ATTRIBUTE attr : attributes) {
d9bc5f
+                if (attr.type == CKA_CLASS) {
d9bc5f
+                    keyClass = attr.getLong();
d9bc5f
+                } else if (attr.type == CKA_KEY_TYPE) {
d9bc5f
+                    keyType = attr.getLong();
d9bc5f
+                }
d9bc5f
+                attrsMap.put(attr.type, attr);
d9bc5f
+            }
d9bc5f
+            BigInteger v = null;
d9bc5f
+            if (keyClass == CKO_PRIVATE_KEY) {
d9bc5f
+                if (keyType == CKK_RSA) {
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Importing an RSA private key...");
d9bc5f
+                    }
d9bc5f
+                    keyBytes = sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(
d9bc5f
+                            KeyType.RSA,
d9bc5f
+                            null,
d9bc5f
+                            ((v = attrsMap.get(CKA_MODULUS).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_PUBLIC_EXPONENT).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_PRIVATE_EXPONENT).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_PRIME_1).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_PRIME_2).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_EXPONENT_1).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_EXPONENT_2).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_COEFFICIENT).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO
d9bc5f
+                            ).getEncoded();
d9bc5f
+                } else if (keyType == CKK_DSA) {
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Importing a DSA private key...");
d9bc5f
+                    }
d9bc5f
+                    keyBytes = new sun.security.provider.DSAPrivateKey(
d9bc5f
+                            ((v = attrsMap.get(CKA_VALUE).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_PRIME).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_SUBPRIME).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_BASE).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO
d9bc5f
+                            ).getEncoded();
d9bc5f
+                    if (token.config.getNssNetscapeDbWorkaround() &&
d9bc5f
+                            attrsMap.get(CKA_NETSCAPE_DB) == null) {
d9bc5f
+                        attrsMap.put(CKA_NETSCAPE_DB,
d9bc5f
+                                new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
d9bc5f
+                    }
d9bc5f
+                } else if (keyType == CKK_EC) {
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Importing an EC private key...");
d9bc5f
+                    }
d9bc5f
+                    if (sunECProvider == null) {
d9bc5f
+                        sunECProviderLock.lock();
d9bc5f
+                        try {
d9bc5f
+                            if (sunECProvider == null) {
d9bc5f
+                                sunECProvider = Security.getProvider("SunEC");
d9bc5f
+                            }
d9bc5f
+                        } finally {
d9bc5f
+                            sunECProviderLock.unlock();
d9bc5f
+                        }
d9bc5f
+                    }
d9bc5f
+                    keyBytes = ECUtil.generateECPrivateKey(
d9bc5f
+                            ((v = attrsMap.get(CKA_VALUE).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ECUtil.getECParameterSpec(sunECProvider,
d9bc5f
+                                    attrsMap.get(CKA_EC_PARAMS).getByteArray()))
d9bc5f
+                            .getEncoded();
d9bc5f
+                    if (token.config.getNssNetscapeDbWorkaround() &&
d9bc5f
+                            attrsMap.get(CKA_NETSCAPE_DB) == null) {
d9bc5f
+                        attrsMap.put(CKA_NETSCAPE_DB,
d9bc5f
+                                new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
d9bc5f
+                    }
d9bc5f
+                } else if (keyType == CKK_DH) {
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Importing a Diffie-Hellman private key...");
d9bc5f
+                    }
d9bc5f
+                    if (DHKF == null) {
d9bc5f
+                        DHKFLock.lock();
d9bc5f
+                        try {
d9bc5f
+                            if (DHKF == null) {
d9bc5f
+                                DHKF = KeyFactory.getInstance(
d9bc5f
+                                        "DH", P11Util.getSunJceProvider());
d9bc5f
+                            }
d9bc5f
+                        } finally {
d9bc5f
+                            DHKFLock.unlock();
d9bc5f
+                        }
d9bc5f
+                    }
d9bc5f
+                    DHPrivateKeySpec spec = new DHPrivateKeySpec
d9bc5f
+                            (((v = attrsMap.get(CKA_VALUE).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_PRIME).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO,
d9bc5f
+                            ((v = attrsMap.get(CKA_BASE).getBigInteger()) != null)
d9bc5f
+                                    ? v : BigInteger.ZERO);
d9bc5f
+                    keyBytes = DHKF.generatePrivate(spec).getEncoded();
d9bc5f
+                    if (token.config.getNssNetscapeDbWorkaround() &&
d9bc5f
+                            attrsMap.get(CKA_NETSCAPE_DB) == null) {
d9bc5f
+                        attrsMap.put(CKA_NETSCAPE_DB,
d9bc5f
+                                new CK_ATTRIBUTE(CKA_NETSCAPE_DB, BigInteger.ZERO));
d9bc5f
+                    }
d9bc5f
+                } else {
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Unrecognized private key type.");
d9bc5f
+                    }
d9bc5f
+                    throw new PKCS11Exception(CKR_GENERAL_ERROR);
d9bc5f
+                }
d9bc5f
+            } else if (keyClass == CKO_SECRET_KEY) {
d9bc5f
+                if (debug != null) {
d9bc5f
+                    debug.println("Importing a secret key...");
d9bc5f
+                }
d9bc5f
+                keyBytes = attrsMap.get(CKA_VALUE).getByteArray();
d9bc5f
+            }
d9bc5f
+            if (keyBytes == null || keyBytes.length == 0) {
d9bc5f
+                if (debug != null) {
d9bc5f
+                    debug.println("Private or secret key plain bytes could" +
d9bc5f
+                            " not be obtained. Import failed.");
d9bc5f
+                }
d9bc5f
+                throw new PKCS11Exception(CKR_GENERAL_ERROR);
d9bc5f
+            }
d9bc5f
+            importerCipher.init(Cipher.ENCRYPT_MODE, importerKey,
d9bc5f
+                    new IvParameterSpec((byte[])importerKeyMechanism.pParameter),
d9bc5f
+                    null);
d9bc5f
+            attributes = new CK_ATTRIBUTE[attrsMap.size()];
d9bc5f
+            attrsMap.values().toArray(attributes);
d9bc5f
+            encKeyBytes = importerCipher.doFinal(keyBytes);
d9bc5f
+            attributes = token.getAttributes(TemplateManager.O_IMPORT,
d9bc5f
+                    keyClass, keyType, attributes);
d9bc5f
+            keyID = token.p11.C_UnwrapKey(hSession,
d9bc5f
+                    importerKeyMechanism, importerKeyID, encKeyBytes, attributes);
d9bc5f
+            if (debug != null) {
d9bc5f
+                debug.println("Imported key ID: " + keyID);
d9bc5f
+            }
d9bc5f
+        } catch (Throwable t) {
d9bc5f
+            throw new PKCS11Exception(CKR_GENERAL_ERROR);
d9bc5f
+        } finally {
d9bc5f
+            importerKey.releaseKeyID();
d9bc5f
+        }
d9bc5f
+        return Long.valueOf(keyID);
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    private static void createImporterKey(Token token) {
d9bc5f
+        if (debug != null) {
d9bc5f
+            debug.println("Generating Importer Key...");
d9bc5f
+        }
d9bc5f
+        byte[] iv = new byte[16];
d9bc5f
+        JCAUtil.getSecureRandom().nextBytes(iv);
d9bc5f
+        importerKeyMechanism = new CK_MECHANISM(CKM_AES_CBC_PAD, iv);
d9bc5f
+        try {
d9bc5f
+            CK_ATTRIBUTE[] attributes = token.getAttributes(TemplateManager.O_GENERATE,
d9bc5f
+                            CKO_SECRET_KEY, CKK_AES, new CK_ATTRIBUTE[] {
d9bc5f
+                                    new CK_ATTRIBUTE(CKA_CLASS, CKO_SECRET_KEY),
d9bc5f
+                                    new CK_ATTRIBUTE(CKA_VALUE_LEN, 256 >> 3)});
d9bc5f
+            Session s = null;
d9bc5f
+            try {
d9bc5f
+                s = token.getObjSession();
d9bc5f
+                long keyID = token.p11.C_GenerateKey(
d9bc5f
+                        s.id(), new CK_MECHANISM(CKM_AES_KEY_GEN),
d9bc5f
+                        attributes);
d9bc5f
+                if (debug != null) {
d9bc5f
+                    debug.println("Importer Key ID: " + keyID);
d9bc5f
+                }
d9bc5f
+                importerKey = (P11Key)P11Key.secretKey(s, keyID, "AES",
d9bc5f
+                        256 >> 3, null);
d9bc5f
+            } catch (PKCS11Exception e) {
d9bc5f
+                // best effort
d9bc5f
+            } finally {
d9bc5f
+                token.releaseSession(s);
d9bc5f
+            }
d9bc5f
+            if (importerKey != null) {
d9bc5f
+                importerCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
d9bc5f
+            }
d9bc5f
+        } catch (Throwable t) {
d9bc5f
+            // best effort
d9bc5f
+            importerKey = null;
d9bc5f
+            importerCipher = null;
d9bc5f
+            // importerKeyMechanism value is kept initialized to indicate that
d9bc5f
+            // Importer Key creation has been tried and failed.
d9bc5f
+        }
d9bc5f
+    }
d9bc5f
+}
d9bc5f
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
d9bc5f
index 112b639aa96..42c72b393fd 100644
d9bc5f
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
d9bc5f
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
d9bc5f
@@ -26,6 +26,9 @@
d9bc5f
 package sun.security.pkcs11;
d9bc5f
 
d9bc5f
 import java.io.*;
d9bc5f
+import java.lang.invoke.MethodHandle;
d9bc5f
+import java.lang.invoke.MethodHandles;
d9bc5f
+import java.lang.invoke.MethodType;
d9bc5f
 import java.util.*;
d9bc5f
 
d9bc5f
 import java.security.*;
d9bc5f
@@ -42,6 +45,7 @@ import javax.security.auth.callback.PasswordCallback;
d9bc5f
 
d9bc5f
 import com.sun.crypto.provider.ChaCha20Poly1305Parameters;
d9bc5f
 
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import jdk.internal.misc.InnocuousThread;
d9bc5f
 import sun.security.util.Debug;
d9bc5f
 import sun.security.util.ResourcesMgr;
d9bc5f
@@ -62,6 +66,29 @@ import static sun.security.pkcs11.wrapper.PKCS11Exception.*;
d9bc5f
  */
d9bc5f
 public final class SunPKCS11 extends AuthProvider {
d9bc5f
 
d9bc5f
+    private static final boolean systemFipsEnabled = SharedSecrets
d9bc5f
+            .getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled();
d9bc5f
+
d9bc5f
+    private static final boolean plainKeySupportEnabled = SharedSecrets
d9bc5f
+            .getJavaSecuritySystemConfiguratorAccess().isPlainKeySupportEnabled();
d9bc5f
+
d9bc5f
+    private static final MethodHandle fipsImportKey;
d9bc5f
+    static {
d9bc5f
+        MethodHandle fipsImportKeyTmp = null;
d9bc5f
+        if (plainKeySupportEnabled) {
d9bc5f
+            try {
d9bc5f
+                fipsImportKeyTmp = MethodHandles.lookup().findStatic(
d9bc5f
+                        FIPSKeyImporter.class, "importKey",
d9bc5f
+                        MethodType.methodType(Long.class, SunPKCS11.class,
d9bc5f
+                        long.class, CK_ATTRIBUTE[].class));
d9bc5f
+            } catch (Throwable t) {
d9bc5f
+                throw new SecurityException("FIPS key importer initialization" +
d9bc5f
+                        " failed", t);
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        fipsImportKey = fipsImportKeyTmp;
d9bc5f
+    }
d9bc5f
+
d9bc5f
     private static final long serialVersionUID = -1354835039035306505L;
d9bc5f
 
d9bc5f
     static final Debug debug = Debug.getInstance("sunpkcs11");
d9bc5f
@@ -320,10 +347,15 @@ public final class SunPKCS11 extends AuthProvider {
d9bc5f
             // request multithreaded access first
d9bc5f
             initArgs.flags = CKF_OS_LOCKING_OK;
d9bc5f
             PKCS11 tmpPKCS11;
d9bc5f
+            MethodHandle fipsKeyImporter = null;
d9bc5f
+            if (plainKeySupportEnabled) {
d9bc5f
+                fipsKeyImporter = MethodHandles.insertArguments(
d9bc5f
+                        fipsImportKey, 0, this);
d9bc5f
+            }
d9bc5f
             try {
d9bc5f
                 tmpPKCS11 = PKCS11.getInstance(
d9bc5f
                     library, functionList, initArgs,
d9bc5f
-                    config.getOmitInitialize());
d9bc5f
+                    config.getOmitInitialize(), fipsKeyImporter);
d9bc5f
             } catch (PKCS11Exception e) {
d9bc5f
                 if (debug != null) {
d9bc5f
                     debug.println("Multi-threaded initialization failed: " + e);
d9bc5f
@@ -339,7 +371,7 @@ public final class SunPKCS11 extends AuthProvider {
d9bc5f
                     initArgs.flags = 0;
d9bc5f
                 }
d9bc5f
                 tmpPKCS11 = PKCS11.getInstance(library,
d9bc5f
-                    functionList, initArgs, config.getOmitInitialize());
d9bc5f
+                    functionList, initArgs, config.getOmitInitialize(), fipsKeyImporter);
d9bc5f
             }
d9bc5f
             p11 = tmpPKCS11;
d9bc5f
 
d9bc5f
@@ -379,6 +411,24 @@ public final class SunPKCS11 extends AuthProvider {
d9bc5f
             if (nssModule != null) {
d9bc5f
                 nssModule.setProvider(this);
d9bc5f
             }
d9bc5f
+            if (systemFipsEnabled) {
d9bc5f
+                // The NSS Software Token in FIPS 140-2 mode requires a user
d9bc5f
+                // login for most operations. See sftk_fipsCheck. The NSS DB
d9bc5f
+                // (/etc/pki/nssdb) PIN is empty.
d9bc5f
+                Session session = null;
d9bc5f
+                try {
d9bc5f
+                    session = token.getOpSession();
d9bc5f
+                    p11.C_Login(session.id(), CKU_USER, new char[] {});
d9bc5f
+                } catch (PKCS11Exception p11e) {
d9bc5f
+                    if (debug != null) {
d9bc5f
+                        debug.println("Error during token login: " +
d9bc5f
+                                p11e.getMessage());
d9bc5f
+                    }
d9bc5f
+                    throw p11e;
d9bc5f
+                } finally {
d9bc5f
+                    token.releaseSession(session);
d9bc5f
+                }
d9bc5f
+            }
d9bc5f
         } catch (Exception e) {
d9bc5f
             if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) {
d9bc5f
                 throw new UnsupportedOperationException
d9bc5f
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java
d9bc5f
index 5c0aacd1a67..0e4a1235084 100644
d9bc5f
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java
d9bc5f
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java
d9bc5f
@@ -49,6 +49,7 @@ package sun.security.pkcs11.wrapper;
d9bc5f
 
d9bc5f
 import java.io.File;
d9bc5f
 import java.io.IOException;
d9bc5f
+import java.lang.invoke.MethodHandle;
d9bc5f
 import java.util.*;
d9bc5f
 
d9bc5f
 import java.security.AccessController;
d9bc5f
@@ -150,18 +151,41 @@ public class PKCS11 {
d9bc5f
         this.pkcs11ModulePath = pkcs11ModulePath;
d9bc5f
     }
d9bc5f
 
d9bc5f
+    /*
d9bc5f
+     * Compatibility wrapper to allow this method to work as before
d9bc5f
+     * when FIPS mode support is not active.
d9bc5f
+     */
d9bc5f
+    public static synchronized PKCS11 getInstance(String pkcs11ModulePath,
d9bc5f
+           String functionList, CK_C_INITIALIZE_ARGS pInitArgs,
d9bc5f
+           boolean omitInitialize) throws IOException, PKCS11Exception {
d9bc5f
+        return getInstance(pkcs11ModulePath, functionList,
d9bc5f
+                           pInitArgs, omitInitialize, null);
d9bc5f
+    }
d9bc5f
+
d9bc5f
     public static synchronized PKCS11 getInstance(String pkcs11ModulePath,
d9bc5f
             String functionList, CK_C_INITIALIZE_ARGS pInitArgs,
d9bc5f
-            boolean omitInitialize) throws IOException, PKCS11Exception {
d9bc5f
+            boolean omitInitialize, MethodHandle fipsKeyImporter)
d9bc5f
+                    throws IOException, PKCS11Exception {
d9bc5f
         // we may only call C_Initialize once per native .so/.dll
d9bc5f
         // so keep a cache using the (non-canonicalized!) path
d9bc5f
         PKCS11 pkcs11 = moduleMap.get(pkcs11ModulePath);
d9bc5f
         if (pkcs11 == null) {
d9bc5f
+            boolean nssFipsMode = fipsKeyImporter != null;
d9bc5f
             if ((pInitArgs != null)
d9bc5f
                     && ((pInitArgs.flags & CKF_OS_LOCKING_OK) != 0)) {
d9bc5f
-                pkcs11 = new PKCS11(pkcs11ModulePath, functionList);
d9bc5f
+                if (nssFipsMode) {
d9bc5f
+                    pkcs11 = new FIPSPKCS11(pkcs11ModulePath, functionList,
d9bc5f
+                            fipsKeyImporter);
d9bc5f
+                } else {
d9bc5f
+                    pkcs11 = new PKCS11(pkcs11ModulePath, functionList);
d9bc5f
+                }
d9bc5f
             } else {
d9bc5f
-                pkcs11 = new SynchronizedPKCS11(pkcs11ModulePath, functionList);
d9bc5f
+                if (nssFipsMode) {
d9bc5f
+                    pkcs11 = new SynchronizedFIPSPKCS11(pkcs11ModulePath,
d9bc5f
+                            functionList, fipsKeyImporter);
d9bc5f
+                } else {
d9bc5f
+                    pkcs11 = new SynchronizedPKCS11(pkcs11ModulePath, functionList);
d9bc5f
+                }
d9bc5f
             }
d9bc5f
             if (omitInitialize == false) {
d9bc5f
                 try {
d9bc5f
@@ -1911,4 +1935,69 @@ static class SynchronizedPKCS11 extends PKCS11 {
d9bc5f
         super.C_GenerateRandom(hSession, randomData);
d9bc5f
     }
d9bc5f
 }
d9bc5f
+
d9bc5f
+// PKCS11 subclass that allows using plain private or secret keys in
d9bc5f
+// FIPS-configured NSS Software Tokens. Only used when System FIPS
d9bc5f
+// is enabled.
d9bc5f
+static class FIPSPKCS11 extends PKCS11 {
d9bc5f
+    private MethodHandle fipsKeyImporter;
d9bc5f
+    FIPSPKCS11(String pkcs11ModulePath, String functionListName,
d9bc5f
+            MethodHandle fipsKeyImporter) throws IOException {
d9bc5f
+        super(pkcs11ModulePath, functionListName);
d9bc5f
+        this.fipsKeyImporter = fipsKeyImporter;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    public synchronized long C_CreateObject(long hSession,
d9bc5f
+            CK_ATTRIBUTE[] pTemplate) throws PKCS11Exception {
d9bc5f
+        // Creating sensitive key objects from plain key material in a
d9bc5f
+        // FIPS-configured NSS Software Token is not allowed. We apply
d9bc5f
+        // a key-unwrapping scheme to achieve so.
d9bc5f
+        if (FIPSPKCS11Helper.isSensitiveObject(pTemplate)) {
d9bc5f
+            try {
d9bc5f
+                return ((Long)fipsKeyImporter.invoke(hSession, pTemplate))
d9bc5f
+                        .longValue();
d9bc5f
+            } catch (Throwable t) {
d9bc5f
+                throw new PKCS11Exception(CKR_GENERAL_ERROR);
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        return super.C_CreateObject(hSession, pTemplate);
d9bc5f
+    }
d9bc5f
+}
d9bc5f
+
d9bc5f
+// FIPSPKCS11 synchronized counterpart.
d9bc5f
+static class SynchronizedFIPSPKCS11 extends SynchronizedPKCS11 {
d9bc5f
+    private MethodHandle fipsKeyImporter;
d9bc5f
+    SynchronizedFIPSPKCS11(String pkcs11ModulePath, String functionListName,
d9bc5f
+            MethodHandle fipsKeyImporter) throws IOException {
d9bc5f
+        super(pkcs11ModulePath, functionListName);
d9bc5f
+        this.fipsKeyImporter = fipsKeyImporter;
d9bc5f
+    }
d9bc5f
+
d9bc5f
+    public synchronized long C_CreateObject(long hSession,
d9bc5f
+            CK_ATTRIBUTE[] pTemplate) throws PKCS11Exception {
d9bc5f
+        // See FIPSPKCS11::C_CreateObject.
d9bc5f
+        if (FIPSPKCS11Helper.isSensitiveObject(pTemplate)) {
d9bc5f
+            try {
d9bc5f
+                return ((Long)fipsKeyImporter.invoke(hSession, pTemplate))
d9bc5f
+                        .longValue();
d9bc5f
+            } catch (Throwable t) {
d9bc5f
+                throw new PKCS11Exception(CKR_GENERAL_ERROR);
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        return super.C_CreateObject(hSession, pTemplate);
d9bc5f
+    }
d9bc5f
+}
d9bc5f
+
d9bc5f
+private static class FIPSPKCS11Helper {
d9bc5f
+    static boolean isSensitiveObject(CK_ATTRIBUTE[] pTemplate) {
d9bc5f
+        for (CK_ATTRIBUTE attr : pTemplate) {
d9bc5f
+            if (attr.type == CKA_CLASS &&
d9bc5f
+                    (attr.getLong() == CKO_PRIVATE_KEY ||
d9bc5f
+                    attr.getLong() == CKO_SECRET_KEY)) {
d9bc5f
+                return true;
d9bc5f
+            }
d9bc5f
+        }
d9bc5f
+        return false;
d9bc5f
+    }
d9bc5f
+}
d9bc5f
 }
d9bc5f
diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11Exception.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11Exception.java
d9bc5f
index e2d6d371bec..dc5e7eefdd3 100644
d9bc5f
--- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11Exception.java
d9bc5f
+++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11Exception.java
d9bc5f
@@ -219,6 +219,14 @@ public class PKCS11Exception extends Exception {
d9bc5f
         return "0x" + Functions.toFullHexString((int)errorCode);
d9bc5f
     }
d9bc5f
 
d9bc5f
+    /**
d9bc5f
+     * Constructor taking the error code (the CKR_* constants in PKCS#11) with
d9bc5f
+     * no extra info for the error message.
d9bc5f
+     */
d9bc5f
+    public PKCS11Exception(long errorCode) {
d9bc5f
+        this(errorCode, null);
d9bc5f
+    }
d9bc5f
+
d9bc5f
     /**
d9bc5f
      * Constructor taking the error code (the CKR_* constants in PKCS#11) and
d9bc5f
      * extra info for error message.
d9bc5f
diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java
d9bc5f
index 8c9e4f9dbe6..883dc04758e 100644
d9bc5f
--- a/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java
d9bc5f
+++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/SunEC.java
d9bc5f
@@ -38,6 +38,7 @@ import java.util.HashMap;
d9bc5f
 import java.util.Iterator;
d9bc5f
 import java.util.List;
d9bc5f
 
d9bc5f
+import jdk.internal.access.SharedSecrets;
d9bc5f
 import sun.security.ec.ed.EdDSAAlgorithmParameters;
d9bc5f
 import sun.security.ec.ed.EdDSAKeyFactory;
d9bc5f
 import sun.security.ec.ed.EdDSAKeyPairGenerator;
d9bc5f
@@ -56,6 +57,10 @@ public final class SunEC extends Provider {
d9bc5f
 
d9bc5f
     private static final long serialVersionUID = -2279741672933606418L;
d9bc5f
 
d9bc5f
+    private static final boolean systemFipsEnabled =
d9bc5f
+            SharedSecrets.getJavaSecuritySystemConfiguratorAccess()
d9bc5f
+            .isSystemFipsEnabled();
d9bc5f
+
d9bc5f
     private static class ProviderServiceA extends ProviderService {
d9bc5f
         ProviderServiceA(Provider p, String type, String algo, String cn,
d9bc5f
             HashMap<String, String> attrs) {
d9bc5f
@@ -249,85 +254,86 @@ public final class SunEC extends Provider {
d9bc5f
 
d9bc5f
         putXDHEntries();
d9bc5f
         putEdDSAEntries();
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Signature engines
d9bc5f
-         */
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-            "NONEwithECDSA", "sun.security.ec.ECDSASignature$Raw",
d9bc5f
-            null, ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA1withECDSA", "sun.security.ec.ECDSASignature$SHA1",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA224withECDSA", "sun.security.ec.ECDSASignature$SHA224",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA256withECDSA", "sun.security.ec.ECDSASignature$SHA256",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA384withECDSA", "sun.security.ec.ECDSASignature$SHA384",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA512withECDSA", "sun.security.ec.ECDSASignature$SHA512",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA3-224withECDSA", "sun.security.ec.ECDSASignature$SHA3_224",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA3-256withECDSA", "sun.security.ec.ECDSASignature$SHA3_256",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA3-384withECDSA", "sun.security.ec.ECDSASignature$SHA3_384",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "SHA3-512withECDSA", "sun.security.ec.ECDSASignature$SHA3_512",
d9bc5f
-            ATTRS));
d9bc5f
-
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-             "NONEwithECDSAinP1363Format",
d9bc5f
-             "sun.security.ec.ECDSASignature$RawinP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-             "SHA1withECDSAinP1363Format",
d9bc5f
-             "sun.security.ec.ECDSASignature$SHA1inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-             "SHA224withECDSAinP1363Format",
d9bc5f
-             "sun.security.ec.ECDSASignature$SHA224inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-             "SHA256withECDSAinP1363Format",
d9bc5f
-             "sun.security.ec.ECDSASignature$SHA256inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-            "SHA384withECDSAinP1363Format",
d9bc5f
-            "sun.security.ec.ECDSASignature$SHA384inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-            "SHA512withECDSAinP1363Format",
d9bc5f
-            "sun.security.ec.ECDSASignature$SHA512inP1363Format"));
d9bc5f
-
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-             "SHA3-224withECDSAinP1363Format",
d9bc5f
-             "sun.security.ec.ECDSASignature$SHA3_224inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-             "SHA3-256withECDSAinP1363Format",
d9bc5f
-             "sun.security.ec.ECDSASignature$SHA3_256inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-            "SHA3-384withECDSAinP1363Format",
d9bc5f
-            "sun.security.ec.ECDSASignature$SHA3_384inP1363Format"));
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-            "SHA3-512withECDSAinP1363Format",
d9bc5f
-            "sun.security.ec.ECDSASignature$SHA3_512inP1363Format"));
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         *  Key Pair Generator engine
d9bc5f
-         */
d9bc5f
-        putService(new ProviderService(this, "KeyPairGenerator",
d9bc5f
-            "EC", "sun.security.ec.ECKeyPairGenerator",
d9bc5f
-            List.of("EllipticCurve"), ATTRS));
d9bc5f
-
d9bc5f
-        /*
d9bc5f
-         * Key Agreement engine
d9bc5f
-         */
d9bc5f
-        putService(new ProviderService(this, "KeyAgreement",
d9bc5f
-            "ECDH", "sun.security.ec.ECDHKeyAgreement", null, ATTRS));
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            /*
d9bc5f
+             * Signature engines
d9bc5f
+             */
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                "NONEwithECDSA", "sun.security.ec.ECDSASignature$Raw",
d9bc5f
+                null, ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA1withECDSA", "sun.security.ec.ECDSASignature$SHA1",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA224withECDSA", "sun.security.ec.ECDSASignature$SHA224",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA256withECDSA", "sun.security.ec.ECDSASignature$SHA256",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA384withECDSA", "sun.security.ec.ECDSASignature$SHA384",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA512withECDSA", "sun.security.ec.ECDSASignature$SHA512",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA3-224withECDSA", "sun.security.ec.ECDSASignature$SHA3_224",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA3-256withECDSA", "sun.security.ec.ECDSASignature$SHA3_256",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA3-384withECDSA", "sun.security.ec.ECDSASignature$SHA3_384",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "SHA3-512withECDSA", "sun.security.ec.ECDSASignature$SHA3_512",
d9bc5f
+                ATTRS));
d9bc5f
+
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                 "NONEwithECDSAinP1363Format",
d9bc5f
+                 "sun.security.ec.ECDSASignature$RawinP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                 "SHA1withECDSAinP1363Format",
d9bc5f
+                 "sun.security.ec.ECDSASignature$SHA1inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                 "SHA224withECDSAinP1363Format",
d9bc5f
+                 "sun.security.ec.ECDSASignature$SHA224inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                 "SHA256withECDSAinP1363Format",
d9bc5f
+                 "sun.security.ec.ECDSASignature$SHA256inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                "SHA384withECDSAinP1363Format",
d9bc5f
+                "sun.security.ec.ECDSASignature$SHA384inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                "SHA512withECDSAinP1363Format",
d9bc5f
+                "sun.security.ec.ECDSASignature$SHA512inP1363Format"));
d9bc5f
+
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                 "SHA3-224withECDSAinP1363Format",
d9bc5f
+                 "sun.security.ec.ECDSASignature$SHA3_224inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                 "SHA3-256withECDSAinP1363Format",
d9bc5f
+                 "sun.security.ec.ECDSASignature$SHA3_256inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                "SHA3-384withECDSAinP1363Format",
d9bc5f
+                "sun.security.ec.ECDSASignature$SHA3_384inP1363Format"));
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                "SHA3-512withECDSAinP1363Format",
d9bc5f
+                "sun.security.ec.ECDSASignature$SHA3_512inP1363Format"));
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             *  Key Pair Generator engine
d9bc5f
+             */
d9bc5f
+            putService(new ProviderService(this, "KeyPairGenerator",
d9bc5f
+                "EC", "sun.security.ec.ECKeyPairGenerator",
d9bc5f
+                List.of("EllipticCurve"), ATTRS));
d9bc5f
+
d9bc5f
+            /*
d9bc5f
+             * Key Agreement engine
d9bc5f
+             */
d9bc5f
+            putService(new ProviderService(this, "KeyAgreement",
d9bc5f
+                "ECDH", "sun.security.ec.ECDHKeyAgreement", null, ATTRS));
d9bc5f
+        }
d9bc5f
     }
d9bc5f
 
d9bc5f
     private void putXDHEntries() {
d9bc5f
@@ -344,23 +350,25 @@ public final class SunEC extends Provider {
d9bc5f
             "X448", "sun.security.ec.XDHKeyFactory.X448",
d9bc5f
             ATTRS));
d9bc5f
 
d9bc5f
-        putService(new ProviderService(this, "KeyPairGenerator",
d9bc5f
-            "XDH", "sun.security.ec.XDHKeyPairGenerator", null, ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
-            "X25519", "sun.security.ec.XDHKeyPairGenerator.X25519",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
-            "X448", "sun.security.ec.XDHKeyPairGenerator.X448",
d9bc5f
-            ATTRS));
d9bc5f
-
d9bc5f
-        putService(new ProviderService(this, "KeyAgreement",
d9bc5f
-            "XDH", "sun.security.ec.XDHKeyAgreement", null, ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "KeyAgreement",
d9bc5f
-            "X25519", "sun.security.ec.XDHKeyAgreement.X25519",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "KeyAgreement",
d9bc5f
-            "X448", "sun.security.ec.XDHKeyAgreement.X448",
d9bc5f
-            ATTRS));
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            putService(new ProviderService(this, "KeyPairGenerator",
d9bc5f
+                "XDH", "sun.security.ec.XDHKeyPairGenerator", null, ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
+                "X25519", "sun.security.ec.XDHKeyPairGenerator.X25519",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
+                "X448", "sun.security.ec.XDHKeyPairGenerator.X448",
d9bc5f
+                ATTRS));
d9bc5f
+
d9bc5f
+            putService(new ProviderService(this, "KeyAgreement",
d9bc5f
+                "XDH", "sun.security.ec.XDHKeyAgreement", null, ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "KeyAgreement",
d9bc5f
+                "X25519", "sun.security.ec.XDHKeyAgreement.X25519",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "KeyAgreement",
d9bc5f
+                "X448", "sun.security.ec.XDHKeyAgreement.X448",
d9bc5f
+                ATTRS));
d9bc5f
+        }
d9bc5f
     }
d9bc5f
 
d9bc5f
     private void putEdDSAEntries() {
d9bc5f
@@ -375,21 +383,23 @@ public final class SunEC extends Provider {
d9bc5f
         putService(new ProviderServiceA(this, "KeyFactory",
d9bc5f
             "Ed448", "sun.security.ec.ed.EdDSAKeyFactory.Ed448", ATTRS));
d9bc5f
 
d9bc5f
-        putService(new ProviderService(this, "KeyPairGenerator",
d9bc5f
-            "EdDSA", "sun.security.ec.ed.EdDSAKeyPairGenerator", null, ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
-            "Ed25519", "sun.security.ec.ed.EdDSAKeyPairGenerator.Ed25519",
d9bc5f
-            ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
-            "Ed448", "sun.security.ec.ed.EdDSAKeyPairGenerator.Ed448",
d9bc5f
-            ATTRS));
d9bc5f
-
d9bc5f
-        putService(new ProviderService(this, "Signature",
d9bc5f
-            "EdDSA", "sun.security.ec.ed.EdDSASignature", null, ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "Ed25519", "sun.security.ec.ed.EdDSASignature.Ed25519", ATTRS));
d9bc5f
-        putService(new ProviderServiceA(this, "Signature",
d9bc5f
-            "Ed448", "sun.security.ec.ed.EdDSASignature.Ed448", ATTRS));
d9bc5f
+        if (!systemFipsEnabled) {
d9bc5f
+            putService(new ProviderService(this, "KeyPairGenerator",
d9bc5f
+                "EdDSA", "sun.security.ec.ed.EdDSAKeyPairGenerator", null, ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
+                "Ed25519", "sun.security.ec.ed.EdDSAKeyPairGenerator.Ed25519",
d9bc5f
+                ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "KeyPairGenerator",
d9bc5f
+                "Ed448", "sun.security.ec.ed.EdDSAKeyPairGenerator.Ed448",
d9bc5f
+                ATTRS));
d9bc5f
+
d9bc5f
+            putService(new ProviderService(this, "Signature",
d9bc5f
+                "EdDSA", "sun.security.ec.ed.EdDSASignature", null, ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "Ed25519", "sun.security.ec.ed.EdDSASignature.Ed25519", ATTRS));
d9bc5f
+            putService(new ProviderServiceA(this, "Signature",
d9bc5f
+                "Ed448", "sun.security.ec.ed.EdDSASignature.Ed448", ATTRS));
d9bc5f
+        }
d9bc5f
 
d9bc5f
     }
d9bc5f
 }