< prev index next >

src/java.base/share/classes/java/security/Provider.java

Print this page
rev 13987 : 8051408: NIST SP 800-90A SecureRandom implementations

@@ -140,12 +140,27 @@
         throws Exception {
         if (ctrParamClz == null) {
             Constructor<?> con = clazz.getConstructor();
             return con.newInstance();
         } else {
+            // Looking for the constructor with a params first and fallback
+            // to one without if not found. This is to support the enhanced
+            // SecureRandom. Before jdk9, there was no params support
+            // (only getInstance(alg)) and an impl only had the no-params
+            // constructor. Since jdk9, there is getInstance(alg,params)
+            // and an impl can contain a Impl(params) constructor.
+            try {
             Constructor<?> con = clazz.getConstructor(ctrParamClz);
             return con.newInstance(ctorParamObj);
+            } catch (NoSuchMethodException nsme) {
+                if (ctorParamObj == null) {
+                    Constructor<?> con = clazz.getConstructor();
+                    return con.newInstance();
+                } else {
+                    throw new IllegalArgumentException(nsme);
+                }
+            }
         }
     }
 
     /**
      * Constructs a provider with the specified name, version number,

@@ -1382,11 +1397,12 @@
         addEngine("AlgorithmParameters",                false, null);
         addEngine("KeyFactory",                         false, null);
         addEngine("KeyPairGenerator",                   false, null);
         addEngine("KeyStore",                           false, null);
         addEngine("MessageDigest",                      false, null);
-        addEngine("SecureRandom",                       false, null);
+        addEngine("SecureRandom",                       false,
+                "java.security.SecureRandomInstantiateParameters");
         addEngine("Signature",                          true,  null);
         addEngine("CertificateFactory",                 false, null);
         addEngine("CertPathBuilder",                    false, null);
         addEngine("CertPathValidator",                  false, null);
         addEngine("CertStore",                          false,

@@ -1676,10 +1692,11 @@
                                     + " for engine type " + type);
                             }
                         }
                     }
                 }
+                // constructorParameter can be null if not provided
                 return newInstanceUtil(getImplClass(), ctrParamClz, constructorParameter);
             } catch (NoSuchAlgorithmException e) {
                 throw e;
             } catch (InvocationTargetException e) {
                 throw new NoSuchAlgorithmException
< prev index next >