Blame pr1983-rh1565658-support_using_the_system_installation_of_nss_with_the_sunec_provider_jdk8.patch

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