Skip to content

Commit 899c1d8

Browse files
Address comments
1 parent 98bcf82 commit 899c1d8

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

closed/src/java.base/share/classes/jdk/crypto/jniprovider/NativeCrypto.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class NativeCrypto {
7171
private static final boolean traceEnabled = Boolean.parseBoolean(
7272
GetPropertyAction.privilegedGetProperty("jdk.nativeCryptoTrace", "false"));
7373

74-
private static final Set<String> disallowedAlgosFIPS = Set.of("MD5", "ChaCha20");
74+
private static final Set<String> disallowedAlgosFIPS = Set.of("ChaCha20", "MD5");
7575

7676
private static final class InstanceHolder {
7777
private static final NativeCrypto instance = new NativeCrypto();
@@ -205,18 +205,18 @@ public static final boolean isAlgorithmAvailable(String algorithm) {
205205
if (isAllowedAndLoaded()) {
206206
if (isOpenSSLFIPSVersion()) {
207207
if (disallowedAlgosFIPS.contains(algorithm)) {
208-
return false;
208+
isAlgorithmAvailable = false;
209209
}
210210
}
211211
switch (algorithm) {
212212
case "MD5":
213-
return isMD5Available();
213+
isAlgorithmAvailable = isMD5Available();
214214
default:
215-
return true;
215+
isAlgorithmAvailable = true;
216216
}
217217
}
218218

219-
//Issue a message indicating whether the crypto implementation is available.
219+
// Issue a message indicating whether the crypto implementation is available.
220220
if (traceEnabled) {
221221
if (isAlgorithmAvailable) {
222222
System.err.println(algorithm + " native crypto implementation is available.");
@@ -251,10 +251,10 @@ public void run() {
251251

252252
private static final native long loadCrypto(boolean trace);
253253

254-
private static final native boolean isOpenSSLFIPS();
255-
256254
public static final native boolean isMD5Available();
257255

256+
private static final native boolean isOpenSSLFIPS();
257+
258258
public final native long DigestCreateContext(long nativeBuffer,
259259
int algoIndex);
260260

closed/src/java.base/share/native/libjncrypto/NativeCrypto.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ int OSSL102_RSA_set0_crt_params(RSA *, BIGNUM *, BIGNUM *, BIGNUM *);
8282
#define EVP_CTRL_AEAD_SET_TAG EVP_CTRL_GCM_SET_TAG
8383
#endif
8484

85-
/* Check whether loaded library is in FIPS mode. */
86-
jboolean OSSL_IS_FIPS;
85+
/* Whether loaded library is in FIPS mode. */
86+
static jboolean OSSL_IS_FIPS;
8787

8888
/* Header for EC algorithm */
8989
jboolean OSSL_ECGF2M;
@@ -375,7 +375,7 @@ static void *crypto_library = NULL;
375375
* Signature: ()Z
376376
*/
377377
JNIEXPORT jboolean JNICALL Java_jdk_crypto_jniprovider_NativeCrypto_isOpenSSLFIPS
378-
(JNIEnv *env, jclass thisObj)
378+
(JNIEnv *env, jclass clazz)
379379
{
380380
return OSSL_IS_FIPS;
381381
}
@@ -458,18 +458,16 @@ JNIEXPORT jlong JNICALL Java_jdk_crypto_jniprovider_NativeCrypto_loadCrypto
458458
/* Check whether the loaded OpenSSL library is in FIPS mode. */
459459
if (ossl_ver >= OPENSSL_VERSION_3_0_0) {
460460
typedef int OSSL_fipsmode_t(OSSL_LIB_CTX *);
461-
OSSL_fipsmode_t* OSSL_fipsmode;
462-
OSSL_fipsmode = (OSSL_fipsmode_t*)find_crypto_symbol(crypto_library, "EVP_default_properties_is_fips_enabled");
463-
if ((NULL != OSSL_fipsmode) && ((*OSSL_fipsmode)(NULL) == 1)) {
461+
OSSL_fipsmode_t* OSSL_fipsmode = (OSSL_fipsmode_t*)find_crypto_symbol(crypto_library, "EVP_default_properties_is_fips_enabled");
462+
if ((NULL != OSSL_fipsmode) && (1 == (*OSSL_fipsmode)(NULL))) {
464463
OSSL_IS_FIPS = JNI_TRUE;
465464
} else {
466465
OSSL_IS_FIPS = JNI_FALSE;
467466
}
468467
} else {
469468
typedef int OSSL_fipsmode_t(void);
470-
OSSL_fipsmode_t* OSSL_fipsmode;
471-
OSSL_fipsmode = (OSSL_fipsmode_t*)find_crypto_symbol(crypto_library, "FIPS_mode");
472-
if ((NULL != OSSL_fipsmode) && ((*OSSL_fipsmode)() == 1)) {
469+
OSSL_fipsmode_t* OSSL_fipsmode = (OSSL_fipsmode_t*)find_crypto_symbol(crypto_library, "FIPS_mode");
470+
if ((NULL != OSSL_fipsmode) && (1 == (*OSSL_fipsmode)())) {
473471
OSSL_IS_FIPS = JNI_TRUE;
474472
} else {
475473
OSSL_IS_FIPS = JNI_FALSE;

src/java.base/share/classes/sun/security/ec/SunEC.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,30 @@ public final class SunEC extends Provider {
6565
/* The property 'jdk.nativeEC' is used to control enablement of the native
6666
* ECDH implementation.
6767
*/
68-
private static final boolean useNativeECDH = NativeCrypto.isAlgorithmEnabled("jdk.nativeEC", "ECDH");
68+
private static final boolean useNativeECDH = NativeCrypto.isAlgorithmEnabled("jdk.nativeEC", "SunEC");
6969

7070
/* The property 'jdk.nativeECKeyGen' is used to control enablement of the native
7171
* ECKeyGeneration implementation.
7272
* OpenSSL 1.1.0 or above is required for EC key generation support.
7373
*/
74-
private static final boolean useNativeECKeyGen = NativeCrypto.isAlgorithmEnabled("jdk.nativeECKeyGen", "ECKeyGen");
74+
private static final boolean useNativeECKeyGen = NativeCrypto.isAlgorithmEnabled("jdk.nativeECKeyGen", "SunEC");
7575

7676
/* The property 'jdk.nativeECDSA' is used to control enablement of the native
7777
* ECDSA signature implementation.
7878
*/
79-
private static final boolean useNativeECDSA = NativeCrypto.isAlgorithmEnabled("jdk.nativeECDSA", "ECDSA");
79+
private static final boolean useNativeECDSA = NativeCrypto.isAlgorithmEnabled("jdk.nativeECDSA", "SunEC");
8080

8181
/* The property 'jdk.nativeXDHKeyAgreement' is used to control enablement of the native
8282
* XDH key agreement. XDH key agreement is only supported in OpenSSL 1.1.1 and above.
8383
*/
8484
private static final boolean useNativeXDHKeyAgreement =
85-
NativeCrypto.isAlgorithmEnabled("jdk.nativeXDHKeyAgreement", "XDHKeyAgreement");
85+
NativeCrypto.isAlgorithmEnabled("jdk.nativeXDHKeyAgreement", "SunEC");
8686

8787
/* The property 'jdk.nativeXDHKeyGen' is used to control enablement of the native
8888
* XDH key generation. XDH key generation is only supported in OpenSSL 1.1.1 and above.
8989
*/
9090
private static final boolean useNativeXDHKeyGen =
91-
NativeCrypto.isAlgorithmEnabled("jdk.nativeXDHKeyGen", "XDHKeyGen");
91+
NativeCrypto.isAlgorithmEnabled("jdk.nativeXDHKeyGen", "SunEC");
9292

9393
private static class ProviderServiceA extends ProviderService {
9494
ProviderServiceA(Provider p, String type, String algo, String cn,

0 commit comments

Comments
 (0)