Blame pr2934-sunec_provider_throwing_keyexception_withine.separator_current_nss_thus_initialise_the_random_number_generator_and_feed_the_seed_to_it.patch

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