Blame pr2934-sunec_provider_throwing_keyexception_withine.separator_current_nss_thus_initialise_the_random_number_generator_and_feed_the_seed_to_it.patch

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