author | ihse |
Mon, 27 Nov 2017 19:14:42 +0100 | |
changeset 47939 | fe7596497fb0 |
parent 47216 | 71c04702a3d5 |
child 50471 | f0aeede1b855 |
permissions | -rw-r--r-- |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
1 |
/* |
45883
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
2 |
* Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved. |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
4 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
10 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
15 |
* accompanied this code). |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
16 |
* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
24 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
25 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
26 |
#include <jni.h> |
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
26878
diff
changeset
|
27 |
#include "jni_util.h" |
3863
8e0f58b1c072
6884175: CR cleanup for 6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
3492
diff
changeset
|
28 |
#include "impl/ecc_impl.h" |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
29 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
30 |
#define ILLEGAL_STATE_EXCEPTION "java/lang/IllegalStateException" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
31 |
#define INVALID_ALGORITHM_PARAMETER_EXCEPTION \ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
32 |
"java/security/InvalidAlgorithmParameterException" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
33 |
#define INVALID_PARAMETER_EXCEPTION \ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
34 |
"java/security/InvalidParameterException" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
35 |
#define KEY_EXCEPTION "java/security/KeyException" |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
36 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
37 |
extern "C" { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
38 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
39 |
/* |
33653
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
26878
diff
changeset
|
40 |
* Declare library specific JNI_Onload entry if static build |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
26878
diff
changeset
|
41 |
*/ |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
26878
diff
changeset
|
42 |
DEF_STATIC_JNI_OnLoad |
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
26878
diff
changeset
|
43 |
|
c1ee09fe3274
8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents:
26878
diff
changeset
|
44 |
/* |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
45 |
* Throws an arbitrary Java exception. |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
46 |
*/ |
8175
27e80dc06104
6989705: ECC security code native code compiler warnings
vinnie
parents:
7668
diff
changeset
|
47 |
void ThrowException(JNIEnv *env, const char *exceptionName) |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
48 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
49 |
jclass exceptionClazz = env->FindClass(exceptionName); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
50 |
if (exceptionClazz != NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
51 |
env->ThrowNew(exceptionClazz, NULL); |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
52 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
53 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
54 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
55 |
/* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
56 |
* Deep free of the ECParams struct |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
57 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
58 |
void FreeECParams(ECParams *ecparams, jboolean freeStruct) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
59 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
60 |
// Use B_FALSE to free the SECItem->data element, but not the SECItem itself |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
61 |
// Use B_TRUE to free both |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
62 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
63 |
SECITEM_FreeItem(&ecparams->fieldID.u.prime, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
64 |
SECITEM_FreeItem(&ecparams->curve.a, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
65 |
SECITEM_FreeItem(&ecparams->curve.b, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
66 |
SECITEM_FreeItem(&ecparams->curve.seed, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
67 |
SECITEM_FreeItem(&ecparams->base, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
68 |
SECITEM_FreeItem(&ecparams->order, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
69 |
SECITEM_FreeItem(&ecparams->DEREncoding, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
70 |
SECITEM_FreeItem(&ecparams->curveOID, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
71 |
if (freeStruct) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
72 |
free(ecparams); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
73 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
74 |
|
25530 | 75 |
jbyteArray getEncodedBytes(JNIEnv *env, SECItem *hSECItem) |
76 |
{ |
|
77 |
SECItem *s = (SECItem *)hSECItem; |
|
78 |
||
79 |
jbyteArray jEncodedBytes = env->NewByteArray(s->len); |
|
80 |
if (jEncodedBytes == NULL) { |
|
81 |
return NULL; |
|
82 |
} |
|
83 |
// Copy bytes from a native SECItem buffer to Java byte array |
|
84 |
env->SetByteArrayRegion(jEncodedBytes, 0, s->len, (jbyte *)s->data); |
|
85 |
if (env->ExceptionCheck()) { // should never happen |
|
86 |
return NULL; |
|
87 |
} |
|
88 |
return jEncodedBytes; |
|
89 |
} |
|
90 |
||
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
91 |
/* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
92 |
* Class: sun_security_ec_ECKeyPairGenerator |
45883
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
93 |
* Method: isCurveSupported |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
94 |
* Signature: ([B)Z |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
95 |
*/ |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
96 |
JNIEXPORT jboolean |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
97 |
JNICALL Java_sun_security_ec_ECKeyPairGenerator_isCurveSupported |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
98 |
(JNIEnv *env, jclass clazz, jbyteArray encodedParams) |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
99 |
{ |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
100 |
SECKEYECParams params_item; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
101 |
ECParams *ecparams = NULL; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
102 |
jboolean result = JNI_FALSE; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
103 |
|
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
104 |
// The curve is supported if we can get parameters for it |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
105 |
params_item.len = env->GetArrayLength(encodedParams); |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
106 |
params_item.data = |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
107 |
(unsigned char *) env->GetByteArrayElements(encodedParams, 0); |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
108 |
if (params_item.data == NULL) { |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
109 |
goto cleanup; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
110 |
} |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
111 |
|
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
112 |
// Fill a new ECParams using the supplied OID |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
113 |
if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
114 |
/* bad curve OID */ |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
115 |
goto cleanup; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
116 |
} |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
117 |
|
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
118 |
// If we make it to here, then the curve is supported |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
119 |
result = JNI_TRUE; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
120 |
|
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
121 |
cleanup: |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
122 |
{ |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
123 |
if (params_item.data) { |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
124 |
env->ReleaseByteArrayElements(encodedParams, |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
125 |
(jbyte *) params_item.data, JNI_ABORT); |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
126 |
} |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
127 |
if (ecparams) { |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
128 |
FreeECParams(ecparams, true); |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
129 |
} |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
130 |
} |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
131 |
|
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
132 |
return result; |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
133 |
} |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
134 |
|
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
135 |
/* |
89df6f9465a3
8182999: SunEC throws ProviderException on invalid curves
apetcher
parents:
33653
diff
changeset
|
136 |
* Class: sun_security_ec_ECKeyPairGenerator |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
137 |
* Method: generateECKeyPair |
25530 | 138 |
* Signature: (I[B[B)[[B |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
139 |
*/ |
25530 | 140 |
JNIEXPORT jobjectArray |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
141 |
JNICALL Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
142 |
(JNIEnv *env, jclass clazz, jint keySize, jbyteArray encodedParams, jbyteArray seed) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
143 |
{ |
25530 | 144 |
ECPrivateKey *privKey = NULL; // contains both public and private values |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
145 |
ECParams *ecparams = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
146 |
SECKEYECParams params_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
147 |
jint jSeedLength; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
148 |
jbyte* pSeedBuffer = NULL; |
25530 | 149 |
jobjectArray result = NULL; |
150 |
jclass baCls = NULL; |
|
151 |
jbyteArray jba; |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
152 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
153 |
// Initialize the ECParams struct |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
154 |
params_item.len = env->GetArrayLength(encodedParams); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
155 |
params_item.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
156 |
(unsigned char *) env->GetByteArrayElements(encodedParams, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
157 |
if (params_item.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
158 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
159 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
160 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
161 |
// Fill a new ECParams using the supplied OID |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
162 |
if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
163 |
/* bad curve OID */ |
8175
27e80dc06104
6989705: ECC security code native code compiler warnings
vinnie
parents:
7668
diff
changeset
|
164 |
ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
165 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
166 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
167 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
168 |
// Copy seed from Java to native buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
169 |
jSeedLength = env->GetArrayLength(seed); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
170 |
pSeedBuffer = new jbyte[jSeedLength]; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
171 |
env->GetByteArrayRegion(seed, 0, jSeedLength, pSeedBuffer); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
172 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
173 |
// Generate the new keypair (using the supplied seed) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
174 |
if (EC_NewKey(ecparams, &privKey, (unsigned char *) pSeedBuffer, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
175 |
jSeedLength, 0) != SECSuccess) { |
8175
27e80dc06104
6989705: ECC security code native code compiler warnings
vinnie
parents:
7668
diff
changeset
|
176 |
ThrowException(env, KEY_EXCEPTION); |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
177 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
178 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
179 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
180 |
jboolean isCopy; |
25530 | 181 |
baCls = env->FindClass("[B"); |
182 |
if (baCls == NULL) { |
|
183 |
goto cleanup; |
|
184 |
} |
|
185 |
result = env->NewObjectArray(2, baCls, NULL); |
|
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
186 |
if (result == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
187 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
188 |
} |
25530 | 189 |
jba = getEncodedBytes(env, &(privKey->privateValue)); |
190 |
if (jba == NULL) { |
|
191 |
result = NULL; |
|
192 |
goto cleanup; |
|
193 |
} |
|
194 |
env->SetObjectArrayElement(result, 0, jba); // big integer |
|
195 |
if (env->ExceptionCheck()) { // should never happen |
|
196 |
result = NULL; |
|
197 |
goto cleanup; |
|
198 |
} |
|
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
199 |
|
25530 | 200 |
jba = getEncodedBytes(env, &(privKey->publicValue)); |
201 |
if (jba == NULL) { |
|
202 |
result = NULL; |
|
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
203 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
204 |
} |
25530 | 205 |
env->SetObjectArrayElement(result, 1, jba); // encoded ec point |
206 |
if (env->ExceptionCheck()) { // should never happen |
|
207 |
result = NULL; |
|
208 |
goto cleanup; |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
209 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
210 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
211 |
cleanup: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
212 |
{ |
25530 | 213 |
if (params_item.data) { |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
214 |
env->ReleaseByteArrayElements(encodedParams, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
215 |
(jbyte *) params_item.data, JNI_ABORT); |
25530 | 216 |
} |
217 |
if (ecparams) { |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
218 |
FreeECParams(ecparams, true); |
25530 | 219 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
220 |
if (privKey) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
221 |
FreeECParams(&privKey->ecParams, false); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
222 |
SECITEM_FreeItem(&privKey->version, B_FALSE); |
25530 | 223 |
SECITEM_FreeItem(&privKey->privateValue, B_FALSE); |
224 |
SECITEM_FreeItem(&privKey->publicValue, B_FALSE); |
|
225 |
free(privKey); |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
226 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
227 |
|
25530 | 228 |
if (pSeedBuffer) { |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
229 |
delete [] pSeedBuffer; |
25530 | 230 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
231 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
232 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
233 |
return result; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
234 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
235 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
236 |
/* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
237 |
* Class: sun_security_ec_ECDSASignature |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
238 |
* Method: signDigest |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
239 |
* Signature: ([B[B[B[B)[B |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
240 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
241 |
JNIEXPORT jbyteArray |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
242 |
JNICALL Java_sun_security_ec_ECDSASignature_signDigest |
45993 | 243 |
(JNIEnv *env, jclass clazz, jbyteArray digest, jbyteArray privateKey, jbyteArray encodedParams, jbyteArray seed, jint timing) |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
244 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
245 |
jbyte* pDigestBuffer = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
246 |
jint jDigestLength = env->GetArrayLength(digest); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
247 |
jbyteArray jSignedDigest = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
248 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
249 |
SECItem signature_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
250 |
jbyte* pSignedDigestBuffer = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
251 |
jbyteArray temp; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
252 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
253 |
jint jSeedLength = env->GetArrayLength(seed); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
254 |
jbyte* pSeedBuffer = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
255 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
256 |
// Copy digest from Java to native buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
257 |
pDigestBuffer = new jbyte[jDigestLength]; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
258 |
env->GetByteArrayRegion(digest, 0, jDigestLength, pDigestBuffer); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
259 |
SECItem digest_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
260 |
digest_item.data = (unsigned char *) pDigestBuffer; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
261 |
digest_item.len = jDigestLength; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
262 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
263 |
ECPrivateKey privKey; |
26878
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
264 |
privKey.privateValue.data = NULL; |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
265 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
266 |
// Initialize the ECParams struct |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
267 |
ECParams *ecparams = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
268 |
SECKEYECParams params_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
269 |
params_item.len = env->GetArrayLength(encodedParams); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
270 |
params_item.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
271 |
(unsigned char *) env->GetByteArrayElements(encodedParams, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
272 |
if (params_item.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
273 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
274 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
275 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
276 |
// Fill a new ECParams using the supplied OID |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
277 |
if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
278 |
/* bad curve OID */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
279 |
ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
280 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
281 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
282 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
283 |
// Extract private key data |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
284 |
privKey.ecParams = *ecparams; // struct assignment |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
285 |
privKey.privateValue.len = env->GetArrayLength(privateKey); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
286 |
privKey.privateValue.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
287 |
(unsigned char *) env->GetByteArrayElements(privateKey, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
288 |
if (privKey.privateValue.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
289 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
290 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
291 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
292 |
// Prepare a buffer for the signature (twice the key length) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
293 |
pSignedDigestBuffer = new jbyte[ecparams->order.len * 2]; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
294 |
signature_item.data = (unsigned char *) pSignedDigestBuffer; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
295 |
signature_item.len = ecparams->order.len * 2; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
296 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
297 |
// Copy seed from Java to native buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
298 |
pSeedBuffer = new jbyte[jSeedLength]; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
299 |
env->GetByteArrayRegion(seed, 0, jSeedLength, pSeedBuffer); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
300 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
301 |
// Sign the digest (using the supplied seed) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
302 |
if (ECDSA_SignDigest(&privKey, &signature_item, &digest_item, |
45993 | 303 |
(unsigned char *) pSeedBuffer, jSeedLength, 0, timing) != SECSuccess) { |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
304 |
ThrowException(env, KEY_EXCEPTION); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
305 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
306 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
307 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
308 |
// Create new byte array |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
309 |
temp = env->NewByteArray(signature_item.len); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
310 |
if (temp == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
311 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
312 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
313 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
314 |
// Copy data from native buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
315 |
env->SetByteArrayRegion(temp, 0, signature_item.len, pSignedDigestBuffer); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
316 |
jSignedDigest = temp; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
317 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
318 |
cleanup: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
319 |
{ |
25530 | 320 |
if (params_item.data) { |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
321 |
env->ReleaseByteArrayElements(encodedParams, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
322 |
(jbyte *) params_item.data, JNI_ABORT); |
25530 | 323 |
} |
324 |
if (privKey.privateValue.data) { |
|
325 |
env->ReleaseByteArrayElements(privateKey, |
|
326 |
(jbyte *) privKey.privateValue.data, JNI_ABORT); |
|
327 |
} |
|
328 |
if (pDigestBuffer) { |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
329 |
delete [] pDigestBuffer; |
25530 | 330 |
} |
331 |
if (pSignedDigestBuffer) { |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
332 |
delete [] pSignedDigestBuffer; |
25530 | 333 |
} |
334 |
if (pSeedBuffer) { |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
335 |
delete [] pSeedBuffer; |
25530 | 336 |
} |
337 |
if (ecparams) { |
|
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
338 |
FreeECParams(ecparams, true); |
25530 | 339 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
340 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
341 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
342 |
return jSignedDigest; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
343 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
344 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
345 |
/* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
346 |
* Class: sun_security_ec_ECDSASignature |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
347 |
* Method: verifySignedDigest |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
348 |
* Signature: ([B[B[B[B)Z |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
349 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
350 |
JNIEXPORT jboolean |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
351 |
JNICALL Java_sun_security_ec_ECDSASignature_verifySignedDigest |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
352 |
(JNIEnv *env, jclass clazz, jbyteArray signedDigest, jbyteArray digest, jbyteArray publicKey, jbyteArray encodedParams) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
353 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
354 |
jboolean isValid = false; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
355 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
356 |
// Copy signedDigest from Java to native buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
357 |
jbyte* pSignedDigestBuffer = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
358 |
jint jSignedDigestLength = env->GetArrayLength(signedDigest); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
359 |
pSignedDigestBuffer = new jbyte[jSignedDigestLength]; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
360 |
env->GetByteArrayRegion(signedDigest, 0, jSignedDigestLength, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
361 |
pSignedDigestBuffer); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
362 |
SECItem signature_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
363 |
signature_item.data = (unsigned char *) pSignedDigestBuffer; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
364 |
signature_item.len = jSignedDigestLength; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
365 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
366 |
// Copy digest from Java to native buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
367 |
jbyte* pDigestBuffer = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
368 |
jint jDigestLength = env->GetArrayLength(digest); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
369 |
pDigestBuffer = new jbyte[jDigestLength]; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
370 |
env->GetByteArrayRegion(digest, 0, jDigestLength, pDigestBuffer); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
371 |
SECItem digest_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
372 |
digest_item.data = (unsigned char *) pDigestBuffer; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
373 |
digest_item.len = jDigestLength; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
374 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
375 |
// Extract public key data |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
376 |
ECPublicKey pubKey; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
377 |
pubKey.publicValue.data = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
378 |
ECParams *ecparams = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
379 |
SECKEYECParams params_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
380 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
381 |
// Initialize the ECParams struct |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
382 |
params_item.len = env->GetArrayLength(encodedParams); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
383 |
params_item.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
384 |
(unsigned char *) env->GetByteArrayElements(encodedParams, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
385 |
if (params_item.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
386 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
387 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
388 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
389 |
// Fill a new ECParams using the supplied OID |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
390 |
if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
391 |
/* bad curve OID */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
392 |
ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
393 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
394 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
395 |
pubKey.ecParams = *ecparams; // struct assignment |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
396 |
pubKey.publicValue.len = env->GetArrayLength(publicKey); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
397 |
pubKey.publicValue.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
398 |
(unsigned char *) env->GetByteArrayElements(publicKey, 0); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
399 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
400 |
if (ECDSA_VerifyDigest(&pubKey, &signature_item, &digest_item, 0) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
401 |
!= SECSuccess) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
402 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
403 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
404 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
405 |
isValid = true; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
406 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
407 |
cleanup: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
408 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
409 |
if (params_item.data) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
410 |
env->ReleaseByteArrayElements(encodedParams, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
411 |
(jbyte *) params_item.data, JNI_ABORT); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
412 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
413 |
if (pubKey.publicValue.data) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
414 |
env->ReleaseByteArrayElements(publicKey, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
415 |
(jbyte *) pubKey.publicValue.data, JNI_ABORT); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
416 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
417 |
if (ecparams) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
418 |
FreeECParams(ecparams, true); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
419 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
420 |
if (pSignedDigestBuffer) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
421 |
delete [] pSignedDigestBuffer; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
422 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
423 |
if (pDigestBuffer) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
424 |
delete [] pDigestBuffer; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
425 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
426 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
427 |
return isValid; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
428 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
429 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
430 |
/* |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
431 |
* Class: sun_security_ec_ECDHKeyAgreement |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
432 |
* Method: deriveKey |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
433 |
* Signature: ([B[B[B)[B |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
434 |
*/ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
435 |
JNIEXPORT jbyteArray |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
436 |
JNICALL Java_sun_security_ec_ECDHKeyAgreement_deriveKey |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
437 |
(JNIEnv *env, jclass clazz, jbyteArray privateKey, jbyteArray publicKey, jbyteArray encodedParams) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
438 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
439 |
jbyteArray jSecret = NULL; |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
440 |
ECParams *ecparams = NULL; |
26878
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
441 |
SECItem privateValue_item; |
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
442 |
privateValue_item.data = NULL; |
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
443 |
SECItem publicValue_item; |
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
444 |
publicValue_item.data = NULL; |
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
445 |
SECKEYECParams params_item; |
57077013aeb6
8048512: Uninitialised memory in jdk/src/share/native/sun/security/ec/ECC_JNI.cpp
vinnie
parents:
25859
diff
changeset
|
446 |
params_item.data = NULL; |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
447 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
448 |
// Extract private key value |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
449 |
privateValue_item.len = env->GetArrayLength(privateKey); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
450 |
privateValue_item.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
451 |
(unsigned char *) env->GetByteArrayElements(privateKey, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
452 |
if (privateValue_item.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
453 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
454 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
455 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
456 |
// Extract public key value |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
457 |
publicValue_item.len = env->GetArrayLength(publicKey); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
458 |
publicValue_item.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
459 |
(unsigned char *) env->GetByteArrayElements(publicKey, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
460 |
if (publicValue_item.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
461 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
462 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
463 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
464 |
// Initialize the ECParams struct |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
465 |
params_item.len = env->GetArrayLength(encodedParams); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
466 |
params_item.data = |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
467 |
(unsigned char *) env->GetByteArrayElements(encodedParams, 0); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
468 |
if (params_item.data == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
469 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
470 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
471 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
472 |
// Fill a new ECParams using the supplied OID |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
473 |
if (EC_DecodeParams(¶ms_item, &ecparams, 0) != SECSuccess) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
474 |
/* bad curve OID */ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
475 |
ThrowException(env, INVALID_ALGORITHM_PARAMETER_EXCEPTION); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
476 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
477 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
478 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
479 |
// Prepare a buffer for the secret |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
480 |
SECItem secret_item; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
481 |
secret_item.data = NULL; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
482 |
secret_item.len = ecparams->order.len * 2; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
483 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
484 |
if (ECDH_Derive(&publicValue_item, ecparams, &privateValue_item, B_FALSE, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
485 |
&secret_item, 0) != SECSuccess) { |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
486 |
ThrowException(env, ILLEGAL_STATE_EXCEPTION); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
487 |
goto cleanup; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
488 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
489 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
490 |
// Create new byte array |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
491 |
jSecret = env->NewByteArray(secret_item.len); |
22645
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
492 |
if (jSecret == NULL) { |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
493 |
goto cleanup; |
636153f07b26
8028727: [parfait] warnings from b116 for jdk.src.share.native.sun.security.ec: JNI pending exceptions
vinnie
parents:
9035
diff
changeset
|
494 |
} |
3492
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
495 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
496 |
// Copy bytes from the SECItem buffer to a Java byte array |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
497 |
env->SetByteArrayRegion(jSecret, 0, secret_item.len, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
498 |
(jbyte *)secret_item.data); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
499 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
500 |
// Free the SECItem data buffer |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
501 |
SECITEM_FreeItem(&secret_item, B_FALSE); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
502 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
503 |
cleanup: |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
504 |
{ |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
505 |
if (privateValue_item.data) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
506 |
env->ReleaseByteArrayElements(privateKey, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
507 |
(jbyte *) privateValue_item.data, JNI_ABORT); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
508 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
509 |
if (publicValue_item.data) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
510 |
env->ReleaseByteArrayElements(publicKey, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
511 |
(jbyte *) publicValue_item.data, JNI_ABORT); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
512 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
513 |
if (params_item.data) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
514 |
env->ReleaseByteArrayElements(encodedParams, |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
515 |
(jbyte *) params_item.data, JNI_ABORT); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
516 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
517 |
if (ecparams) |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
518 |
FreeECParams(ecparams, true); |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
519 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
520 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
521 |
return jSecret; |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
522 |
} |
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
523 |
|
e549cea58864
6840752: Provide out-of-the-box support for ECC algorithms
vinnie
parents:
diff
changeset
|
524 |
} /* extern "C" */ |