Blame SOURCES/pr1983-rh1565658-support_using_the_system_installation_of_nss_with_the_sunec_provider_jdk8.patch

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