Blame SOURCES/pr2934-sunec_provider_throwing_keyexception_withine.separator_current_nss_thus_initialise_the_random_number_generator_and_feed_the_seed_to_it.patch

045ef6
# HG changeset patch
045ef6
# User andrew
045ef6
# Date 1461349033 -3600
045ef6
#      Fri Apr 22 19:17:13 2016 +0100
045ef6
# Node ID dab76de2f91cf1791c03560a3f45aaa69f8351fd
045ef6
# Parent  3fa42705acab6d69b6141f47ebba4f85739a338c
045ef6
PR2934: SunEC provider throwing KeyException with current NSS
045ef6
Summary: Initialise the random number generator and feed the seed to it.
045ef6
Updated 2017/07/04 to accomodate 8175110
045ef6
045ef6
diff -r 8aed1e903a4c src/share/native/sun/security/ec/ECC_JNI.cpp
045ef6
--- openjdk/jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
045ef6
+++ openjdk/jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
045ef6
@@ -134,8 +134,17 @@
045ef6
     env->GetByteArrayRegion(seed, 0, jSeedLength, pSeedBuffer);
045ef6
 
045ef6
     // Generate the new keypair (using the supplied seed)
045ef6
+#ifdef SYSTEM_NSS
045ef6
+    if (RNG_RandomUpdate((unsigned char *) pSeedBuffer, jSeedLength)
045ef6
+	!= SECSuccess) {
045ef6
+	ThrowException(env, KEY_EXCEPTION);
045ef6
+	goto cleanup;
045ef6
+    }
045ef6
+    if (EC_NewKey(ecparams, &privKey) != SECSuccess) {
045ef6
+#else
045ef6
     if (EC_NewKey(ecparams, &privKey, (unsigned char *) pSeedBuffer,
045ef6
         jSeedLength, 0) != SECSuccess) {
045ef6
+#endif
045ef6
         ThrowException(env, KEY_EXCEPTION);
045ef6
         goto cleanup;
045ef6
     }
045ef6
@@ -267,8 +276,18 @@
045ef6
     env->GetByteArrayRegion(seed, 0, jSeedLength, pSeedBuffer);
045ef6
 
045ef6
     // Sign the digest (using the supplied seed)
045ef6
+#ifdef SYSTEM_NSS
045ef6
+    if (RNG_RandomUpdate((unsigned char *) pSeedBuffer, jSeedLength)
045ef6
+	!= SECSuccess) {
045ef6
+	ThrowException(env, KEY_EXCEPTION);
045ef6
+	goto cleanup;
045ef6
+    }
045ef6
+    if (ECDSA_SignDigest(&privKey, &signature_item, &digest_item)
045ef6
+	!= SECSuccess) {
045ef6
+#else
045ef6
     if (ECDSA_SignDigest(&privKey, &signature_item, &digest_item,
045ef6
         (unsigned char *) pSeedBuffer, jSeedLength, 0, timing) != SECSuccess) {
045ef6
+#endif
045ef6
         ThrowException(env, KEY_EXCEPTION);
045ef6
         goto cleanup;
045ef6
     }
045ef6
@@ -499,6 +518,9 @@
045ef6
     if (SECOID_Init() != SECSuccess) {
045ef6
 	ThrowException(env, INTERNAL_ERROR);
045ef6
     }
045ef6
+    if (RNG_RNGInit() != SECSuccess) {
045ef6
+	ThrowException(env, INTERNAL_ERROR);
045ef6
+    }
045ef6
 #endif
045ef6
 }
045ef6
 
045ef6
@@ -507,6 +529,7 @@
045ef6
   (JNIEnv *env, jclass UNUSED(clazz))
045ef6
 {
045ef6
 #ifdef SYSTEM_NSS
045ef6
+    RNG_RNGShutdown();
045ef6
     if (SECOID_Shutdown() != SECSuccess) {
045ef6
 	ThrowException(env, INTERNAL_ERROR);
045ef6
     }
045ef6
diff -r 8aed1e903a4c src/share/native/sun/security/ec/ecc_impl.h
045ef6
--- openjdk/jdk/src/share/native/sun/security/ec/ecc_impl.h
045ef6
+++ openjdk/jdk/src/share/native/sun/security/ec/ecc_impl.h
045ef6
@@ -254,8 +254,10 @@
045ef6
  This function is no longer required because the random bytes are now
045ef6
  supplied by the caller. Force a failure.
045ef6
 */
045ef6
+#ifndef SYSTEM_NSS
045ef6
 #define RNG_GenerateGlobalRandomBytes(p,l) SECFailure
045ef6
 #endif
045ef6
+#endif
045ef6
 #define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup
045ef6
 #define MP_TO_SEC_ERROR(err)
045ef6
 
045ef6
@@ -267,8 +269,6 @@
045ef6
 
045ef6
 #ifdef SYSTEM_NSS
045ef6
 #define EC_DecodeParams(a,b,c) EC_DecodeParams(a,b)
045ef6
-#define EC_NewKey(a,b,c,d,e) EC_NewKey(a,b)
045ef6
-#define ECDSA_SignDigest(a,b,c,d,e,f,g) ECDSA_SignDigest(a,b,c)
045ef6
 #define ECDSA_VerifyDigest(a,b,c,d) ECDSA_VerifyDigest(a,b,c)
045ef6
 #define ECDH_Derive(a,b,c,d,e,f) ECDH_Derive(a,b,c,d,e)
045ef6
 #else