99
99
100
100
public final class SunEntries {
101
101
102
- /* The property 'jdk.nativeDigest' is used to control enablement of the native
103
- * digest implementation.
104
- */
105
- private static final boolean useNativeDigest = NativeCrypto .isAlgorithmEnabled ("jdk.nativeDigest" , "MessageDigest" );
102
+ private static final boolean useNativeMD5 ;
103
+ private static final boolean useNativeSHA ;
104
+ private static final boolean useNativeSHA224 ;
105
+ private static final boolean useNativeSHA256 ;
106
+ private static final boolean useNativeSHA384 ;
107
+ private static final boolean useNativeSHA512 ;
108
+
109
+ static {
110
+ /* The property 'jdk.nativeDigest' is used to control enablement of all native
111
+ * digest implementations.
112
+ */
113
+ boolean useNativeDigest = NativeCrypto .isAlgorithmEnabled ("jdk.nativeDigest" , "MessageDigest" );
114
+
115
+ /* The property 'jdk.nativeMD5' is used to control enablement of the native
116
+ * MD5 implementation.
117
+ */
118
+ useNativeMD5 = useNativeDigest && NativeCrypto .isAlgorithmEnabled ("jdk.nativeMD5" , "MD5" );
119
+
120
+ /* The property 'jdk.nativeSHA' is used to control enablement of the native
121
+ * SHA implementation.
122
+ */
123
+ useNativeSHA = useNativeDigest && NativeCrypto .isAlgorithmEnabled ("jdk.nativeSHA" , "SHA" );
124
+
125
+ /* The property 'jdk.nativeSHA224' is used to control enablement of the native
126
+ * SHA-224 implementation.
127
+ */
128
+ useNativeSHA224 = useNativeDigest && NativeCrypto .isAlgorithmEnabled ("jdk.nativeSHA224" , "SHA-224" );
129
+
130
+ /* The property 'jdk.nativeSHA256' is used to control enablement of the native
131
+ * SHA-256 implementation.
132
+ */
133
+ useNativeSHA256 = useNativeDigest && NativeCrypto .isAlgorithmEnabled ("jdk.nativeSHA256" , "SHA-256" );
134
+
135
+ /* The property 'jdk.nativeSHA384' is used to control enablement of the native
136
+ * SHA-384 implementation.
137
+ */
138
+ useNativeSHA384 = useNativeDigest && NativeCrypto .isAlgorithmEnabled ("jdk.nativeSHA384" , "SHA-384" );
139
+
140
+ /* The property 'jdk.nativeSHA512' is used to control enablement of the native
141
+ * SHA-512 implementation.
142
+ */
143
+ useNativeSHA512 = useNativeDigest && NativeCrypto .isAlgorithmEnabled ("jdk.nativeSHA512" , "SHA-512" );
144
+ }
106
145
107
146
// the default algo used by SecureRandom class for new SecureRandom() calls
108
147
public static final String DEF_SECURE_RANDOM_ALGO ;
@@ -290,7 +329,7 @@ public final class SunEntries {
290
329
* enabled or not.
291
330
*/
292
331
/* Don't use native MD5 on AIX due to an observed performance regression. */
293
- if (useNativeDigest
332
+ if (useNativeMD5
294
333
&& NativeCrypto .isAllowedAndLoaded ()
295
334
&& NativeCrypto .isMD5Available ()
296
335
&& !OperatingSystem .isAix ()
@@ -300,19 +339,36 @@ public final class SunEntries {
300
339
providerMD5 = "sun.security.provider.MD5" ;
301
340
}
302
341
303
- if (useNativeDigest && NativeCrypto .isAllowedAndLoaded ()) {
342
+ if (useNativeSHA && NativeCrypto .isAllowedAndLoaded ()) {
304
343
providerSHA = "sun.security.provider.NativeSHA" ;
305
- providerSHA224 = "sun.security.provider.NativeSHA2$SHA224" ;
306
- providerSHA256 = "sun.security.provider.NativeSHA2$SHA256" ;
307
- providerSHA384 = "sun.security.provider.NativeSHA5$SHA384" ;
308
- providerSHA512 = "sun.security.provider.NativeSHA5$SHA512" ;
309
344
} else {
310
345
providerSHA = "sun.security.provider.SHA" ;
346
+ }
347
+
348
+ if (useNativeSHA224 && NativeCrypto .isAllowedAndLoaded ()) {
349
+ providerSHA224 = "sun.security.provider.NativeSHA2$SHA224" ;
350
+ } else {
311
351
providerSHA224 = "sun.security.provider.SHA2$SHA224" ;
352
+ }
353
+
354
+ if (useNativeSHA256 && NativeCrypto .isAllowedAndLoaded ()) {
355
+ providerSHA256 = "sun.security.provider.NativeSHA2$SHA256" ;
356
+ } else {
312
357
providerSHA256 = "sun.security.provider.SHA2$SHA256" ;
358
+ }
359
+
360
+ if (useNativeSHA384 && NativeCrypto .isAllowedAndLoaded ()) {
361
+ providerSHA384 = "sun.security.provider.NativeSHA5$SHA384" ;
362
+ } else {
313
363
providerSHA384 = "sun.security.provider.SHA5$SHA384" ;
364
+ }
365
+
366
+ if (useNativeSHA512 && NativeCrypto .isAllowedAndLoaded ()) {
367
+ providerSHA512 = "sun.security.provider.NativeSHA5$SHA512" ;
368
+ } else {
314
369
providerSHA512 = "sun.security.provider.SHA5$SHA512" ;
315
370
}
371
+
316
372
addWithAlias (p , "MessageDigest" , "MD2" , "sun.security.provider.MD2" ,
317
373
attrs );
318
374
addWithAlias (p , "MessageDigest" , "MD5" , providerMD5 ,
0 commit comments