Blame SOURCES/pr1983-rh1565658-support_using_the_system_installation_of_nss_with_the_sunec_provider_jdk8.patch

045ef6
# HG changeset patch
045ef6
# User andrew
045ef6
# Date 1453863246 0
045ef6
#      Wed Jan 27 02:54:06 2016 +0000
045ef6
# Node ID 48c15869ecd568263249af4b9a4e98d4e57f9a8f
045ef6
# Parent  afd392dfaed501ac674a7cc3e37353ce300969c7
045ef6
PR1983: Support using the system installation of NSS with the SunEC provider
045ef6
Summary: Apply code changes from PR1699 & PR1742 & forward-port Makefile changes to the new build.
045ef6
Updated 2017/07/04 to accomodate 8175110
045ef6
045ef6
diff -r 984a4af2ed4e make/lib/SecurityLibraries.gmk
045ef6
--- openjdk/jdk/make/lib/SecurityLibraries.gmk
045ef6
+++ openjdk/jdk/make/lib/SecurityLibraries.gmk
045ef6
@@ -218,8 +218,17 @@
045ef6
 
045ef6
 ifeq ($(ENABLE_INTREE_EC), yes)
045ef6
 
045ef6
-  BUILD_LIBSUNEC_FLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/security/ec \
045ef6
+  BUILD_LIBSUNEC_FLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/security/ec
045ef6
+
045ef6
+  ifeq ($(USE_EXTERNAL_NSS), true)
045ef6
+    BUILD_LIBSUNEC_IMPL_DIR :=
045ef6
+    BUILD_LIBSUNEC_FLAGS += $(NSS_CFLAGS) -DSYSTEM_NSS -DNSS_ENABLE_ECC
045ef6
+  else
045ef6
+    BUILD_LIBSUNEC_IMPL_DIR := \
045ef6
+      $(JDK_TOPDIR)/src/share/native/sun/security/ec/impl
045ef6
+    BUILD_LIBSUNEC_FLAGS += \
045ef6
       -I$(JDK_TOPDIR)/src/share/native/sun/security/ec/impl
045ef6
+  endif
045ef6
 
045ef6
   #
045ef6
   # On sol-sparc...all libraries are compiled with -xregs=no%appl
045ef6
@@ -235,8 +244,8 @@
045ef6
   $(eval $(call SetupNativeCompilation,BUILD_LIBSUNEC, \
045ef6
       LIBRARY := sunec, \
045ef6
       OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
045ef6
-      SRC := $(JDK_TOPDIR)/src/share/native/sun/security/ec \
045ef6
-          $(JDK_TOPDIR)/src/share/native/sun/security/ec/impl, \
045ef6
+      SRC := $(JDK_TOPDIR)/src/share/native/sun/security/ec/ECC_JNI.cpp \
045ef6
+          $(BUILD_LIBSUNEC_IMPL_DIR), \
045ef6
       LANG := C++, \
045ef6
       OPTIMIZATION := LOW, \
045ef6
       CFLAGS := $(filter-out $(ECC_JNI_SOLSPARC_FILTER), $(CFLAGS_JDKLIB)) \
9fd28f
@@ -245,11 +254,12 @@
9fd28f
       CXXFLAGS := $(filter-out $(ECC_JNI_SOLSPARC_FILTER), $(CXXFLAGS_JDKLIB)) \
9fd28f
           $(BUILD_LIBSUNEC_FLAGS), \
9fd28f
       MAPFILE := $(JDK_TOPDIR)/make/mapfiles/libsunec/mapfile-vers, \
9fd28f
-      LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK), \
9fd28f
+      LDFLAGS := $(subst -Xlinker --as-needed,, \
9fd28f
+        $(subst -Wl$(COMMA)--as-needed,, $(LDFLAGS_JDKLIB))) $(LDFLAGS_CXX_JDK), \
045ef6
       LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN), \
045ef6
       LDFLAGS_SUFFIX := $(LIBCXX), \
045ef6
-      LDFLAGS_SUFFIX_linux := -lc, \
045ef6
-      LDFLAGS_SUFFIX_solaris := -lc, \
045ef6
+      LDFLAGS_SUFFIX_linux := -lc $(NSS_LIBS), \
045ef6
+      LDFLAGS_SUFFIX_solaris := -lc $(NSS_LIBS), \
045ef6
       VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
045ef6
       RC_FLAGS := $(RC_FLAGS) \
045ef6
           -D "JDK_FNAME=sunec.dll" \
045ef6
diff -r 984a4af2ed4e 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
@@ -24,7 +24,7 @@
045ef6
  */
045ef6
 
045ef6
 #include <jni.h>
045ef6
-#include "impl/ecc_impl.h"
045ef6
+#include "ecc_impl.h"
045ef6
 
045ef6
 #define ILLEGAL_STATE_EXCEPTION "java/lang/IllegalStateException"
045ef6
 #define INVALID_ALGORITHM_PARAMETER_EXCEPTION \
045ef6
@@ -89,7 +89,7 @@
045ef6
  */
045ef6
 JNIEXPORT jobjectArray
045ef6
 JNICALL Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair
045ef6
-  (JNIEnv *env, jclass clazz, jint keySize, jbyteArray encodedParams, jbyteArray seed)
045ef6
+  (JNIEnv *env, jclass UNUSED(clazz), jint UNUSED(keySize), jbyteArray encodedParams, jbyteArray seed)
045ef6
 {
045ef6
     ECPrivateKey *privKey = NULL; // contains both public and private values
045ef6
     ECParams *ecparams = NULL;
045ef6
@@ -190,7 +190,7 @@
045ef6
  */
045ef6
 JNIEXPORT jbyteArray
045ef6
 JNICALL Java_sun_security_ec_ECDSASignature_signDigest
045ef6
-  (JNIEnv *env, jclass clazz, jbyteArray digest, jbyteArray privateKey, jbyteArray encodedParams, jbyteArray seed, jint timing)
045ef6
+  (JNIEnv *env, jclass UNUSED(clazz), jbyteArray digest, jbyteArray privateKey, jbyteArray encodedParams, jbyteArray seed, jint timing)
045ef6
 {
045ef6
     jbyte* pDigestBuffer = NULL;
045ef6
     jint jDigestLength = env->GetArrayLength(digest);
045ef6
@@ -299,7 +299,7 @@
045ef6
  */
045ef6
 JNIEXPORT jboolean
045ef6
 JNICALL Java_sun_security_ec_ECDSASignature_verifySignedDigest
045ef6
-  (JNIEnv *env, jclass clazz, jbyteArray signedDigest, jbyteArray digest, jbyteArray publicKey, jbyteArray encodedParams)
045ef6
+  (JNIEnv *env, jclass UNUSED(clazz), jbyteArray signedDigest, jbyteArray digest, jbyteArray publicKey, jbyteArray encodedParams)
045ef6
 {
045ef6
     jboolean isValid = false;
045ef6
 
045ef6
@@ -384,7 +384,7 @@
045ef6
  */
045ef6
 JNIEXPORT jbyteArray
045ef6
 JNICALL Java_sun_security_ec_ECDHKeyAgreement_deriveKey
045ef6
-  (JNIEnv *env, jclass clazz, jbyteArray privateKey, jbyteArray publicKey, jbyteArray encodedParams)
045ef6
+  (JNIEnv *env, jclass UNUSED(clazz), jbyteArray privateKey, jbyteArray publicKey, jbyteArray encodedParams)
045ef6
 {
045ef6
     jbyteArray jSecret = NULL;
045ef6
     ECParams *ecparams = NULL;
045ef6
diff -r 984a4af2ed4e src/share/native/sun/security/ec/ecc_impl.h
045ef6
--- /dev/null
045ef6
+++ openjdk/jdk/src/share/native/sun/security/ec/ecc_impl.h
045ef6
@@ -0,0 +1,298 @@
045ef6
+/*
045ef6
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
045ef6
+ * Use is subject to license terms.
045ef6
+ *
045ef6
+ * This library is free software; you can redistribute it and/or
045ef6
+ * modify it under the terms of the GNU Lesser General Public
045ef6
+ * License as published by the Free Software Foundation; either
045ef6
+ * version 2.1 of the License, or (at your option) any later version.
045ef6
+ *
045ef6
+ * This library is distributed in the hope that it will be useful,
045ef6
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
045ef6
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
045ef6
+ * Lesser General Public License for more details.
045ef6
+ *
045ef6
+ * You should have received a copy of the GNU Lesser General Public License
045ef6
+ * along with this library; if not, write to the Free Software Foundation,
045ef6
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
045ef6
+ *
045ef6
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
045ef6
+ * or visit www.oracle.com if you need additional information or have any
045ef6
+ * questions.
045ef6
+ */
045ef6
+
045ef6
+/* *********************************************************************
045ef6
+ *
045ef6
+ * The Original Code is the Netscape security libraries.
045ef6
+ *
045ef6
+ * The Initial Developer of the Original Code is
045ef6
+ * Netscape Communications Corporation.
045ef6
+ * Portions created by the Initial Developer are Copyright (C) 1994-2000
045ef6
+ * the Initial Developer. All Rights Reserved.
045ef6
+ *
045ef6
+ * Contributor(s):
045ef6
+ *   Dr Vipul Gupta <vipul.gupta@sun.com> and
045ef6
+ *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
045ef6
+ *
045ef6
+ * Last Modified Date from the Original Code: May 2017
045ef6
+ *********************************************************************** */
045ef6
+
045ef6
+#ifndef _ECC_IMPL_H
045ef6
+#define _ECC_IMPL_H
045ef6
+
045ef6
+#ifdef __cplusplus
045ef6
+extern "C" {
045ef6
+#endif
045ef6
+
045ef6
+#include <sys/types.h>
045ef6
+
045ef6
+#ifdef SYSTEM_NSS
045ef6
+#include <secitem.h>
045ef6
+#include <secerr.h>
045ef6
+#include <keythi.h>
045ef6
+#ifdef LEGACY_NSS
045ef6
+#include <softoken.h>
045ef6
+#else
045ef6
+#include <blapi.h>
045ef6
+#endif
045ef6
+#else
045ef6
+#include "ecl-exp.h"
045ef6
+#endif
045ef6
+
045ef6
+/*
045ef6
+ * Multi-platform definitions
045ef6
+ */
045ef6
+#ifdef __linux__
045ef6
+#define B_FALSE FALSE
045ef6
+#define B_TRUE TRUE
045ef6
+typedef unsigned char uint8_t;
045ef6
+typedef unsigned long ulong_t;
045ef6
+typedef enum { B_FALSE, B_TRUE } boolean_t;
045ef6
+#endif /* __linux__ */
045ef6
+
045ef6
+#ifdef _ALLBSD_SOURCE
045ef6
+#include <stdint.h>
045ef6
+#define B_FALSE FALSE
045ef6
+#define B_TRUE TRUE
045ef6
+typedef unsigned long ulong_t;
045ef6
+typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
045ef6
+#endif /* _ALLBSD_SOURCE */
045ef6
+
045ef6
+#ifdef AIX
045ef6
+#define B_FALSE FALSE
045ef6
+#define B_TRUE TRUE
045ef6
+typedef unsigned char uint8_t;
045ef6
+typedef unsigned long ulong_t;
045ef6
+#endif /* AIX */
045ef6
+
045ef6
+#ifdef _WIN32
045ef6
+typedef unsigned char uint8_t;
045ef6
+typedef unsigned long ulong_t;
045ef6
+typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
045ef6
+#define strdup _strdup          /* Replace POSIX name with ISO C++ name */
045ef6
+#endif /* _WIN32 */
045ef6
+
045ef6
+#ifndef _KERNEL
045ef6
+#include <stdlib.h>
045ef6
+#endif  /* _KERNEL */
045ef6
+
045ef6
+#define EC_MAX_DIGEST_LEN 1024  /* max digest that can be signed */
045ef6
+#define EC_MAX_POINT_LEN 145    /* max len of DER encoded Q */
045ef6
+#define EC_MAX_VALUE_LEN 72     /* max len of ANSI X9.62 private value d */
045ef6
+#define EC_MAX_SIG_LEN 144      /* max signature len for supported curves */
045ef6
+#define EC_MIN_KEY_LEN  112     /* min key length in bits */
045ef6
+#define EC_MAX_KEY_LEN  571     /* max key length in bits */
045ef6
+#define EC_MAX_OID_LEN 10       /* max length of OID buffer */
045ef6
+
045ef6
+/*
045ef6
+ * Various structures and definitions from NSS are here.
045ef6
+ */
045ef6
+
045ef6
+#ifndef SYSTEM_NSS
045ef6
+#ifdef _KERNEL
045ef6
+#define PORT_ArenaAlloc(a, n, f)        kmem_alloc((n), (f))
045ef6
+#define PORT_ArenaZAlloc(a, n, f)       kmem_zalloc((n), (f))
045ef6
+#define PORT_ArenaGrow(a, b, c, d)      NULL
045ef6
+#define PORT_ZAlloc(n, f)               kmem_zalloc((n), (f))
045ef6
+#define PORT_Alloc(n, f)                kmem_alloc((n), (f))
045ef6
+#else
045ef6
+#define PORT_ArenaAlloc(a, n, f)        malloc((n))
045ef6
+#define PORT_ArenaZAlloc(a, n, f)       calloc(1, (n))
045ef6
+#define PORT_ArenaGrow(a, b, c, d)      NULL
045ef6
+#define PORT_ZAlloc(n, f)               calloc(1, (n))
045ef6
+#define PORT_Alloc(n, f)                malloc((n))
045ef6
+#endif
045ef6
+
045ef6
+#define PORT_NewArena(b)                (char *)12345
045ef6
+#define PORT_ArenaMark(a)               NULL
045ef6
+#define PORT_ArenaUnmark(a, b)
045ef6
+#define PORT_ArenaRelease(a, m)
045ef6
+#define PORT_FreeArena(a, b)
045ef6
+#define PORT_Strlen(s)                  strlen((s))
045ef6
+#define PORT_SetError(e)
045ef6
+
045ef6
+#define PRBool                          boolean_t
045ef6
+#define PR_TRUE                         B_TRUE
045ef6
+#define PR_FALSE                        B_FALSE
045ef6
+
045ef6
+#ifdef _KERNEL
045ef6
+#define PORT_Assert                     ASSERT
045ef6
+#define PORT_Memcpy(t, f, l)            bcopy((f), (t), (l))
045ef6
+#else
045ef6
+#define PORT_Assert                     assert
045ef6
+#define PORT_Memcpy(t, f, l)            memcpy((t), (f), (l))
045ef6
+#endif
045ef6
+
045ef6
+#endif
045ef6
+
045ef6
+#define CHECK_OK(func) if (func == NULL) goto cleanup
045ef6
+#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup
045ef6
+
045ef6
+#ifndef SYSTEM_NSS
045ef6
+typedef enum {
045ef6
+        siBuffer = 0,
045ef6
+        siClearDataBuffer = 1,
045ef6
+        siCipherDataBuffer = 2,
045ef6
+        siDERCertBuffer = 3,
045ef6
+        siEncodedCertBuffer = 4,
045ef6
+        siDERNameBuffer = 5,
045ef6
+        siEncodedNameBuffer = 6,
045ef6
+        siAsciiNameString = 7,
045ef6
+        siAsciiString = 8,
045ef6
+        siDEROID = 9,
045ef6
+        siUnsignedInteger = 10,
045ef6
+        siUTCTime = 11,
045ef6
+        siGeneralizedTime = 12
045ef6
+} SECItemType;
045ef6
+
045ef6
+typedef struct SECItemStr SECItem;
045ef6
+
045ef6
+struct SECItemStr {
045ef6
+        SECItemType type;
045ef6
+        unsigned char *data;
045ef6
+        unsigned int len;
045ef6
+};
045ef6
+
045ef6
+typedef SECItem SECKEYECParams;
045ef6
+
045ef6
+typedef enum { ec_params_explicit,
045ef6
+               ec_params_named
045ef6
+} ECParamsType;
045ef6
+
045ef6
+typedef enum { ec_field_GFp = 1,
045ef6
+               ec_field_GF2m
045ef6
+} ECFieldType;
045ef6
+
045ef6
+struct ECFieldIDStr {
045ef6
+    int         size;   /* field size in bits */
045ef6
+    ECFieldType type;
045ef6
+    union {
045ef6
+        SECItem  prime; /* prime p for (GFp) */
045ef6
+        SECItem  poly;  /* irreducible binary polynomial for (GF2m) */
045ef6
+    } u;
045ef6
+    int         k1;     /* first coefficient of pentanomial or
045ef6
+                         * the only coefficient of trinomial
045ef6
+                         */
045ef6
+    int         k2;     /* two remaining coefficients of pentanomial */
045ef6
+    int         k3;
045ef6
+};
045ef6
+typedef struct ECFieldIDStr ECFieldID;
045ef6
+
045ef6
+struct ECCurveStr {
045ef6
+        SECItem a;      /* contains octet stream encoding of
045ef6
+                         * field element (X9.62 section 4.3.3)
045ef6
+                         */
045ef6
+        SECItem b;
045ef6
+        SECItem seed;
045ef6
+};
045ef6
+typedef struct ECCurveStr ECCurve;
045ef6
+
045ef6
+typedef void PRArenaPool;
045ef6
+
045ef6
+struct ECParamsStr {
045ef6
+    PRArenaPool * arena;
045ef6
+    ECParamsType  type;
045ef6
+    ECFieldID     fieldID;
045ef6
+    ECCurve       curve;
045ef6
+    SECItem       base;
045ef6
+    SECItem       order;
045ef6
+    int           cofactor;
045ef6
+    SECItem       DEREncoding;
045ef6
+    ECCurveName   name;
045ef6
+    SECItem       curveOID;
045ef6
+};
045ef6
+typedef struct ECParamsStr ECParams;
045ef6
+
045ef6
+struct ECPublicKeyStr {
045ef6
+    ECParams ecParams;
045ef6
+    SECItem publicValue;   /* elliptic curve point encoded as
045ef6
+                            * octet stream.
045ef6
+                            */
045ef6
+};
045ef6
+typedef struct ECPublicKeyStr ECPublicKey;
045ef6
+
045ef6
+struct ECPrivateKeyStr {
045ef6
+    ECParams ecParams;
045ef6
+    SECItem publicValue;   /* encoded ec point */
045ef6
+    SECItem privateValue;  /* private big integer */
045ef6
+    SECItem version;       /* As per SEC 1, Appendix C, Section C.4 */
045ef6
+};
045ef6
+typedef struct ECPrivateKeyStr ECPrivateKey;
045ef6
+
045ef6
+typedef enum _SECStatus {
045ef6
+        SECBufferTooSmall = -3,
045ef6
+        SECWouldBlock = -2,
045ef6
+        SECFailure = -1,
045ef6
+        SECSuccess = 0
045ef6
+} SECStatus;
045ef6
+#endif
045ef6
+
045ef6
+#ifdef _KERNEL
045ef6
+#define RNG_GenerateGlobalRandomBytes(p,l) ecc_knzero_random_generator((p), (l))
045ef6
+#else
045ef6
+/*
045ef6
+ This function is no longer required because the random bytes are now
045ef6
+ supplied by the caller. Force a failure.
045ef6
+*/
045ef6
+#define RNG_GenerateGlobalRandomBytes(p,l) SECFailure
045ef6
+#endif
045ef6
+#define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup
045ef6
+#define MP_TO_SEC_ERROR(err)
045ef6
+
045ef6
+#define SECITEM_TO_MPINT(it, mp)                                        \
045ef6
+        CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len))
045ef6
+
045ef6
+extern int ecc_knzero_random_generator(uint8_t *, size_t);
045ef6
+extern ulong_t soft_nzero_random_generator(uint8_t *, ulong_t);
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_NewKeyFromSeed(a,b,c,d)
045ef6
+#define ECDSA_SignDigest(a,b,c,d,e,f,g) ECDSA_SignDigestWithSeed(a,b,c,d,e)
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
045ef6
+extern SECStatus EC_DecodeParams(const SECItem *, ECParams **, int);
045ef6
+
045ef6
+extern SECItem * SECITEM_AllocItem(PRArenaPool *, SECItem *, unsigned int, int);
045ef6
+extern SECStatus SECITEM_CopyItem(PRArenaPool *, SECItem *, const SECItem *,
045ef6
+    int);
045ef6
+extern void SECITEM_FreeItem(SECItem *, boolean_t);
045ef6
+
045ef6
+/* This function has been modified to accept an array of random bytes */
045ef6
+extern SECStatus EC_NewKey(ECParams *ecParams, ECPrivateKey **privKey,
045ef6
+    const unsigned char* random, int randomlen, int);
045ef6
+/* This function has been modified to accept an array of random bytes */
045ef6
+extern SECStatus ECDSA_SignDigest(ECPrivateKey *, SECItem *, const SECItem *,
045ef6
+    const unsigned char* random, int randomlen, int, int timing);
045ef6
+extern SECStatus ECDSA_VerifyDigest(ECPublicKey *, const SECItem *,
045ef6
+    const SECItem *, int);
045ef6
+extern SECStatus ECDH_Derive(SECItem *, ECParams *, SECItem *, boolean_t,
045ef6
+    SECItem *, int);
045ef6
+#endif
045ef6
+
045ef6
+#ifdef  __cplusplus
045ef6
+}
045ef6
+#endif
045ef6
+
045ef6
+#endif /* _ECC_IMPL_H */
045ef6
diff -r 984a4af2ed4e src/share/native/sun/security/ec/impl/ecc_impl.h
045ef6
--- openjdk/jdk/src/share/native/sun/security/ec/impl/ecc_impl.h
045ef6
+++ /dev/null
045ef6
@@ -1,271 +0,0 @@
045ef6
-/*
045ef6
- * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
045ef6
- * Use is subject to license terms.
045ef6
- *
045ef6
- * This library is free software; you can redistribute it and/or
045ef6
- * modify it under the terms of the GNU Lesser General Public
045ef6
- * License as published by the Free Software Foundation; either
045ef6
- * version 2.1 of the License, or (at your option) any later version.
045ef6
- *
045ef6
- * This library is distributed in the hope that it will be useful,
045ef6
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
045ef6
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
045ef6
- * Lesser General Public License for more details.
045ef6
- *
045ef6
- * You should have received a copy of the GNU Lesser General Public License
045ef6
- * along with this library; if not, write to the Free Software Foundation,
045ef6
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
045ef6
- *
045ef6
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
045ef6
- * or visit www.oracle.com if you need additional information or have any
045ef6
- * questions.
045ef6
- */
045ef6
-
045ef6
-/* *********************************************************************
045ef6
- *
045ef6
- * The Original Code is the Netscape security libraries.
045ef6
- *
045ef6
- * The Initial Developer of the Original Code is
045ef6
- * Netscape Communications Corporation.
045ef6
- * Portions created by the Initial Developer are Copyright (C) 1994-2000
045ef6
- * the Initial Developer. All Rights Reserved.
045ef6
- *
045ef6
- * Contributor(s):
045ef6
- *   Dr Vipul Gupta <vipul.gupta@sun.com> and
045ef6
- *   Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
045ef6
- *
045ef6
- * Last Modified Date from the Original Code: May 2017
045ef6
- *********************************************************************** */
045ef6
-
045ef6
-#ifndef _ECC_IMPL_H
045ef6
-#define _ECC_IMPL_H
045ef6
-
045ef6
-#ifdef __cplusplus
045ef6
-extern "C" {
045ef6
-#endif
045ef6
-
045ef6
-#include <sys/types.h>
045ef6
-#include "ecl-exp.h"
045ef6
-
045ef6
-/*
045ef6
- * Multi-platform definitions
045ef6
- */
045ef6
-#ifdef __linux__
045ef6
-#define B_FALSE FALSE
045ef6
-#define B_TRUE TRUE
045ef6
-typedef unsigned char uint8_t;
045ef6
-typedef unsigned long ulong_t;
045ef6
-typedef enum { B_FALSE, B_TRUE } boolean_t;
045ef6
-#endif /* __linux__ */
045ef6
-
045ef6
-#ifdef _ALLBSD_SOURCE
045ef6
-#include <stdint.h>
045ef6
-#define B_FALSE FALSE
045ef6
-#define B_TRUE TRUE
045ef6
-typedef unsigned long ulong_t;
045ef6
-typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
045ef6
-#endif /* _ALLBSD_SOURCE */
045ef6
-
045ef6
-#ifdef AIX
045ef6
-#define B_FALSE FALSE
045ef6
-#define B_TRUE TRUE
045ef6
-typedef unsigned char uint8_t;
045ef6
-typedef unsigned long ulong_t;
045ef6
-#endif /* AIX */
045ef6
-
045ef6
-#ifdef _WIN32
045ef6
-typedef unsigned char uint8_t;
045ef6
-typedef unsigned long ulong_t;
045ef6
-typedef enum boolean { B_FALSE, B_TRUE } boolean_t;
045ef6
-#define strdup _strdup          /* Replace POSIX name with ISO C++ name */
045ef6
-#endif /* _WIN32 */
045ef6
-
045ef6
-#ifndef _KERNEL
045ef6
-#include <stdlib.h>
045ef6
-#endif  /* _KERNEL */
045ef6
-
045ef6
-#define EC_MAX_DIGEST_LEN 1024  /* max digest that can be signed */
045ef6
-#define EC_MAX_POINT_LEN 145    /* max len of DER encoded Q */
045ef6
-#define EC_MAX_VALUE_LEN 72     /* max len of ANSI X9.62 private value d */
045ef6
-#define EC_MAX_SIG_LEN 144      /* max signature len for supported curves */
045ef6
-#define EC_MIN_KEY_LEN  112     /* min key length in bits */
045ef6
-#define EC_MAX_KEY_LEN  571     /* max key length in bits */
045ef6
-#define EC_MAX_OID_LEN 10       /* max length of OID buffer */
045ef6
-
045ef6
-/*
045ef6
- * Various structures and definitions from NSS are here.
045ef6
- */
045ef6
-
045ef6
-#ifdef _KERNEL
045ef6
-#define PORT_ArenaAlloc(a, n, f)        kmem_alloc((n), (f))
045ef6
-#define PORT_ArenaZAlloc(a, n, f)       kmem_zalloc((n), (f))
045ef6
-#define PORT_ArenaGrow(a, b, c, d)      NULL
045ef6
-#define PORT_ZAlloc(n, f)               kmem_zalloc((n), (f))
045ef6
-#define PORT_Alloc(n, f)                kmem_alloc((n), (f))
045ef6
-#else
045ef6
-#define PORT_ArenaAlloc(a, n, f)        malloc((n))
045ef6
-#define PORT_ArenaZAlloc(a, n, f)       calloc(1, (n))
045ef6
-#define PORT_ArenaGrow(a, b, c, d)      NULL
045ef6
-#define PORT_ZAlloc(n, f)               calloc(1, (n))
045ef6
-#define PORT_Alloc(n, f)                malloc((n))
045ef6
-#endif
045ef6
-
045ef6
-#define PORT_NewArena(b)                (char *)12345
045ef6
-#define PORT_ArenaMark(a)               NULL
045ef6
-#define PORT_ArenaUnmark(a, b)
045ef6
-#define PORT_ArenaRelease(a, m)
045ef6
-#define PORT_FreeArena(a, b)
045ef6
-#define PORT_Strlen(s)                  strlen((s))
045ef6
-#define PORT_SetError(e)
045ef6
-
045ef6
-#define PRBool                          boolean_t
045ef6
-#define PR_TRUE                         B_TRUE
045ef6
-#define PR_FALSE                        B_FALSE
045ef6
-
045ef6
-#ifdef _KERNEL
045ef6
-#define PORT_Assert                     ASSERT
045ef6
-#define PORT_Memcpy(t, f, l)            bcopy((f), (t), (l))
045ef6
-#else
045ef6
-#define PORT_Assert                     assert
045ef6
-#define PORT_Memcpy(t, f, l)            memcpy((t), (f), (l))
045ef6
-#endif
045ef6
-
045ef6
-#define CHECK_OK(func) if (func == NULL) goto cleanup
045ef6
-#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup
045ef6
-
045ef6
-typedef enum {
045ef6
-        siBuffer = 0,
045ef6
-        siClearDataBuffer = 1,
045ef6
-        siCipherDataBuffer = 2,
045ef6
-        siDERCertBuffer = 3,
045ef6
-        siEncodedCertBuffer = 4,
045ef6
-        siDERNameBuffer = 5,
045ef6
-        siEncodedNameBuffer = 6,
045ef6
-        siAsciiNameString = 7,
045ef6
-        siAsciiString = 8,
045ef6
-        siDEROID = 9,
045ef6
-        siUnsignedInteger = 10,
045ef6
-        siUTCTime = 11,
045ef6
-        siGeneralizedTime = 12
045ef6
-} SECItemType;
045ef6
-
045ef6
-typedef struct SECItemStr SECItem;
045ef6
-
045ef6
-struct SECItemStr {
045ef6
-        SECItemType type;
045ef6
-        unsigned char *data;
045ef6
-        unsigned int len;
045ef6
-};
045ef6
-
045ef6
-typedef SECItem SECKEYECParams;
045ef6
-
045ef6
-typedef enum { ec_params_explicit,
045ef6
-               ec_params_named
045ef6
-} ECParamsType;
045ef6
-
045ef6
-typedef enum { ec_field_GFp = 1,
045ef6
-               ec_field_GF2m
045ef6
-} ECFieldType;
045ef6
-
045ef6
-struct ECFieldIDStr {
045ef6
-    int         size;   /* field size in bits */
045ef6
-    ECFieldType type;
045ef6
-    union {
045ef6
-        SECItem  prime; /* prime p for (GFp) */
045ef6
-        SECItem  poly;  /* irreducible binary polynomial for (GF2m) */
045ef6
-    } u;
045ef6
-    int         k1;     /* first coefficient of pentanomial or
045ef6
-                         * the only coefficient of trinomial
045ef6
-                         */
045ef6
-    int         k2;     /* two remaining coefficients of pentanomial */
045ef6
-    int         k3;
045ef6
-};
045ef6
-typedef struct ECFieldIDStr ECFieldID;
045ef6
-
045ef6
-struct ECCurveStr {
045ef6
-        SECItem a;      /* contains octet stream encoding of
045ef6
-                         * field element (X9.62 section 4.3.3)
045ef6
-                         */
045ef6
-        SECItem b;
045ef6
-        SECItem seed;
045ef6
-};
045ef6
-typedef struct ECCurveStr ECCurve;
045ef6
-
045ef6
-typedef void PRArenaPool;
045ef6
-
045ef6
-struct ECParamsStr {
045ef6
-    PRArenaPool * arena;
045ef6
-    ECParamsType  type;
045ef6
-    ECFieldID     fieldID;
045ef6
-    ECCurve       curve;
045ef6
-    SECItem       base;
045ef6
-    SECItem       order;
045ef6
-    int           cofactor;
045ef6
-    SECItem       DEREncoding;
045ef6
-    ECCurveName   name;
045ef6
-    SECItem       curveOID;
045ef6
-};
045ef6
-typedef struct ECParamsStr ECParams;
045ef6
-
045ef6
-struct ECPublicKeyStr {
045ef6
-    ECParams ecParams;
045ef6
-    SECItem publicValue;   /* elliptic curve point encoded as
045ef6
-                            * octet stream.
045ef6
-                            */
045ef6
-};
045ef6
-typedef struct ECPublicKeyStr ECPublicKey;
045ef6
-
045ef6
-struct ECPrivateKeyStr {
045ef6
-    ECParams ecParams;
045ef6
-    SECItem publicValue;   /* encoded ec point */
045ef6
-    SECItem privateValue;  /* private big integer */
045ef6
-    SECItem version;       /* As per SEC 1, Appendix C, Section C.4 */
045ef6
-};
045ef6
-typedef struct ECPrivateKeyStr ECPrivateKey;
045ef6
-
045ef6
-typedef enum _SECStatus {
045ef6
-        SECBufferTooSmall = -3,
045ef6
-        SECWouldBlock = -2,
045ef6
-        SECFailure = -1,
045ef6
-        SECSuccess = 0
045ef6
-} SECStatus;
045ef6
-
045ef6
-#ifdef _KERNEL
045ef6
-#define RNG_GenerateGlobalRandomBytes(p,l) ecc_knzero_random_generator((p), (l))
045ef6
-#else
045ef6
-/*
045ef6
- This function is no longer required because the random bytes are now
045ef6
- supplied by the caller. Force a failure.
045ef6
-*/
045ef6
-#define RNG_GenerateGlobalRandomBytes(p,l) SECFailure
045ef6
-#endif
045ef6
-#define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup
045ef6
-#define MP_TO_SEC_ERROR(err)
045ef6
-
045ef6
-#define SECITEM_TO_MPINT(it, mp)                                        \
045ef6
-        CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len))
045ef6
-
045ef6
-extern int ecc_knzero_random_generator(uint8_t *, size_t);
045ef6
-extern ulong_t soft_nzero_random_generator(uint8_t *, ulong_t);
045ef6
-
045ef6
-extern SECStatus EC_DecodeParams(const SECItem *, ECParams **, int);
045ef6
-extern SECItem * SECITEM_AllocItem(PRArenaPool *, SECItem *, unsigned int, int);
045ef6
-extern SECStatus SECITEM_CopyItem(PRArenaPool *, SECItem *, const SECItem *,
045ef6
-    int);
045ef6
-extern void SECITEM_FreeItem(SECItem *, boolean_t);
045ef6
-/* This function has been modified to accept an array of random bytes */
045ef6
-extern SECStatus EC_NewKey(ECParams *ecParams, ECPrivateKey **privKey,
045ef6
-    const unsigned char* random, int randomlen, int);
045ef6
-/* This function has been modified to accept an array of random bytes */
045ef6
-extern SECStatus ECDSA_SignDigest(ECPrivateKey *, SECItem *, const SECItem *,
045ef6
-    const unsigned char* random, int randomlen, int, int timing);
045ef6
-extern SECStatus ECDSA_VerifyDigest(ECPublicKey *, const SECItem *,
045ef6
-    const SECItem *, int);
045ef6
-extern SECStatus ECDH_Derive(SECItem *, ECParams *, SECItem *, boolean_t,
045ef6
-    SECItem *, int);
045ef6
-
045ef6
-#ifdef  __cplusplus
045ef6
-}
045ef6
-#endif
045ef6
-
045ef6
-#endif /* _ECC_IMPL_H */
045ef6
diff -r 984a4af2ed4e src/solaris/javavm/export/jni_md.h
045ef6
--- openjdk/jdk/src/solaris/javavm/export/jni_md.h
045ef6
+++ openjdk/jdk/src/solaris/javavm/export/jni_md.h
045ef6
@@ -36,6 +36,11 @@
045ef6
   #define JNIEXPORT
045ef6
   #define JNIIMPORT
045ef6
 #endif
045ef6
+#if (defined(__GNUC__)) || __has_attribute(unused)
045ef6
+  #define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
045ef6
+#else
045ef6
+  #define UNUSED(x) UNUSED_ ## x
045ef6
+#endif
045ef6
 
045ef6
 #define JNICALL
045ef6