Bug Summary

File:jdk/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c
Warning:line 1568, column 16
Potential leak of memory pointed to by 'ckpParamPtr'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name p11_convert.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/modules_include/java.base/linux -I /home/daniel/Projects/java/jdk/src/java.base/share/native/libjava -I /home/daniel/Projects/java/jdk/src/java.base/unix/native/libjava -I /home/daniel/Projects/java/jdk/src/hotspot/share/include -I /home/daniel/Projects/java/jdk/src/hotspot/os/posix/include -D LIBC=gnu -D _GNU_SOURCE -D _REENTRANT -D _LARGEFILE64_SOURCE -D LINUX -D DEBUG -D _LITTLE_ENDIAN -D ARCH="amd64" -D amd64 -D _LP64=1 -I /home/daniel/Projects/java/jdk/src/jdk.crypto.cryptoki/unix/native/libj2pkcs11 -I /home/daniel/Projects/java/jdk/src/jdk.crypto.cryptoki/share/native/libj2pkcs11 -I /home/daniel/Projects/java/jdk/build/linux-x86_64-server-fastdebug/support/headers/jdk.crypto.cryptoki -D _FORTIFY_SOURCE=2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wno-unused -std=c99 -fdebug-compilation-dir /home/daniel/Projects/java/jdk/make -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -stack-protector 1 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/daniel/Projects/java/scan/2021-12-21-193737-8510-1 -x c /home/daniel/Projects/java/jdk/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_convert.c
1/*
2 * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
3 */
4
5/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * 3. The end-user documentation included with the redistribution, if any, must
18 * include the following acknowledgment:
19 *
20 * "This product includes software developed by IAIK of Graz University of
21 * Technology."
22 *
23 * Alternately, this acknowledgment may appear in the software itself, if
24 * and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Graz University of Technology" and "IAIK of Graz University of
27 * Technology" must not be used to endorse or promote products derived from
28 * this software without prior written permission.
29 *
30 * 5. Products derived from this software may not be called
31 * "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
32 * written permission of Graz University of Technology.
33 *
34 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
35 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
38 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
41 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
42 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45 * POSSIBILITY OF SUCH DAMAGE.
46 */
47
48/*
49 * pkcs11wrapper.c
50 * 18.05.2001
51 *
52 * This is the implementation of the native functions of the Java to PKCS#11 interface.
53 * All function use some helper functions to convert the JNI types to PKCS#11 types.
54 *
55 * @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
56 * @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
57 */
58
59
60#include "pkcs11wrapper.h"
61
62#include <stdio.h>
63#include <stdlib.h>
64#include <string.h>
65#include <assert.h>
66
67#include "sun_security_pkcs11_wrapper_PKCS11.h"
68
69/* declare file private functions */
70
71CK_VOID_PTR jMechParamToCKMechParamPtrSlow(JNIEnv *env, jobject jParam,
72 CK_MECHANISM_TYPE ckMech, CK_ULONG *ckpLength);
73
74
75/*
76 * converts a CK_DATE pointer into a Java CK_DATE Object.
77 *
78 * @param env - used to call JNI funktions to create the new Java object
79 * @param ckpValue - the pointer to the CK_DATE structure
80 * @return - the new Java CK_DATE object
81 */
82jobject ckDatePtrToJDateObject(JNIEnv *env, const CK_DATE *ckpDate)
83{
84 jclass jDateClass;
85 jmethodID jCtrId;
86 jobject jDateObject;
87 jcharArray jYear;
88 jcharArray jMonth;
89 jcharArray jDay;
90
91 /* load CK_DATE class */
92 jDateClass = (*env)->FindClass(env, CLASS_DATE"sun/security/pkcs11/wrapper/CK_DATE");
93 if (jDateClass == NULL((void*)0)) { return NULL((void*)0); }
94
95 /* load CK_DATE constructor */
96 jCtrId = (*env)->GetMethodID(env, jDateClass, "<init>", "([C[C[C)V");
97 if (jCtrId == NULL((void*)0)) { return NULL((void*)0); }
98
99 /* prep all fields */
100 jYear = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->year), 4);
101 if (jYear == NULL((void*)0)) { return NULL((void*)0); }
102 jMonth = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->month), 2);
103 if (jMonth == NULL((void*)0)) { return NULL((void*)0); }
104 jDay = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->day), 2);
105 if (jDay == NULL((void*)0)) { return NULL((void*)0); }
106
107 /* create new CK_DATE object */
108 jDateObject =
109 (*env)->NewObject(env, jDateClass, jCtrId, jYear, jMonth, jDay);
110 if (jDateObject == NULL((void*)0)) { return NULL((void*)0); }
111
112 /* free local references */
113 (*env)->DeleteLocalRef(env, jDateClass);
114 (*env)->DeleteLocalRef(env, jYear);
115 (*env)->DeleteLocalRef(env, jMonth);
116 (*env)->DeleteLocalRef(env, jDay);
117
118 return jDateObject ;
119}
120
121/*
122 * converts a CK_VERSION pointer into a Java CK_VERSION Object.
123 *
124 * @param env - used to call JNI funktions to create the new Java object
125 * @param ckpVersion - the pointer to the CK_VERSION structure
126 * @return the new Java CK_VERSION object
127 */
128jobject ckVersionPtrToJVersion(JNIEnv *env, const CK_VERSION_PTR ckpVersion)
129{
130 jclass jVersionClass;
131 jmethodID jCtrId;
132 jobject jVersionObject;
133 jint jMajor;
134 jint jMinor;
135
136 /* load CK_VERSION class */
137 jVersionClass = (*env)->FindClass(env, CLASS_VERSION"sun/security/pkcs11/wrapper/CK_VERSION");
138 if (jVersionClass == NULL((void*)0)) { return NULL((void*)0); }
139
140 /* load CK_VERSION constructor */
141 jCtrId = (*env)->GetMethodID(env, jVersionClass, "<init>", "(II)V");
142 if (jCtrId == NULL((void*)0)) { return NULL((void*)0); }
143
144 /* prep both fields */
145 jMajor = ckpVersion->major;
146 jMinor = ckpVersion->minor;
147
148 /* create new CK_VERSION object */
149 jVersionObject =
150 (*env)->NewObject(env, jVersionClass, jCtrId, jMajor, jMinor);
151 if (jVersionObject == NULL((void*)0)) { return NULL((void*)0); }
152
153 /* free local references */
154 (*env)->DeleteLocalRef(env, jVersionClass);
155
156 return jVersionObject ;
157}
158
159/*
160 * converts a CK_SESSION_INFO pointer into a Java CK_SESSION_INFO Object.
161 *
162 * @param env - used to call JNI funktions to create the new Java object
163 * @param ckpSessionInfo - the pointer to the CK_SESSION_INFO structure
164 * @return the new Java CK_SESSION_INFO object
165 */
166jobject ckSessionInfoPtrToJSessionInfo(JNIEnv *env, const CK_SESSION_INFO_PTR ckpSessionInfo)
167{
168 jclass jSessionInfoClass;
169 jmethodID jCtrId;
170 jobject jSessionInfoObject;
171 jlong jSlotID;
172 jlong jState;
173 jlong jFlags;
174 jlong jDeviceError;
175
176 /* load CK_SESSION_INFO class */
177 jSessionInfoClass = (*env)->FindClass(env, CLASS_SESSION_INFO"sun/security/pkcs11/wrapper/CK_SESSION_INFO");
178 if (jSessionInfoClass == NULL((void*)0)) { return NULL((void*)0); }
179
180 /* load CK_SESSION_INFO constructor */
181 jCtrId = (*env)->GetMethodID(env, jSessionInfoClass, "<init>", "(JJJJ)V");
182 if (jCtrId == NULL((void*)0)) { return NULL((void*)0); }
183
184 /* prep all fields */
185 jSlotID = ckULongToJLong(ckpSessionInfo->slotID)((jlong) ckpSessionInfo->slotID);
186 jState = ckULongToJLong(ckpSessionInfo->state)((jlong) ckpSessionInfo->state);
187 jFlags = ckULongToJLong(ckpSessionInfo->flags)((jlong) ckpSessionInfo->flags);
188 jDeviceError = ckULongToJLong(ckpSessionInfo->ulDeviceError)((jlong) ckpSessionInfo->ulDeviceError);
189
190 /* create new CK_SESSION_INFO object */
191 jSessionInfoObject =
192 (*env)->NewObject(env, jSessionInfoClass, jCtrId, jSlotID, jState,
193 jFlags, jDeviceError);
194 if (jSessionInfoObject == NULL((void*)0)) { return NULL((void*)0); }
195
196 /* free local references */
197 (*env)->DeleteLocalRef(env, jSessionInfoClass);
198
199 return jSessionInfoObject ;
200}
201
202/*
203 * converts a CK_ATTRIBUTE pointer into a Java CK_ATTRIBUTE Object.
204 *
205 * @param env - used to call JNI funktions to create the new Java object
206 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure
207 * @return the new Java CK_ATTRIBUTE object
208 */
209jobject ckAttributePtrToJAttribute(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
210{
211 jclass jAttributeClass;
212 jmethodID jCtrId;
213 jobject jAttributeObject;
214 jlong jType;
215 jobject jPValue = NULL((void*)0);
216
217 jAttributeClass = (*env)->FindClass(env, CLASS_ATTRIBUTE"sun/security/pkcs11/wrapper/CK_ATTRIBUTE");
218 if (jAttributeClass == NULL((void*)0)) { return NULL((void*)0); }
219
220 /* load CK_INFO constructor */
221 jCtrId = (*env)->GetMethodID(env, jAttributeClass, "<init>", "(JLjava/lang/Object;)V");
222 if (jCtrId == NULL((void*)0)) { return NULL((void*)0); }
223
224 /* prep both fields */
225 jType = ckULongToJLong(ckpAttribute->type)((jlong) ckpAttribute->type);
226 jPValue = ckAttributeValueToJObject(env, ckpAttribute);
227 if ((*env)->ExceptionCheck(env)) { return NULL((void*)0); }
228
229 /* create new CK_ATTRIBUTE object */
230 jAttributeObject =
231 (*env)->NewObject(env, jAttributeClass, jCtrId, jType, jPValue);
232 if (jAttributeObject == NULL((void*)0)) { return NULL((void*)0); }
233
234 /* free local references */
235 (*env)->DeleteLocalRef(env, jAttributeClass);
236 (*env)->DeleteLocalRef(env, jPValue);
237
238 return jAttributeObject;
239}
240
241
242/*
243 * converts a Java CK_VERSION object into a CK_VERSION pointer
244 *
245 * @param env - used to call JNI funktions to get the values out of the Java object
246 * @param jVersion - the Java CK_VERSION object to convert
247 * @return pointer to the new CK_VERSION structure
248 */
249CK_VERSION_PTR
250jVersionToCKVersionPtr(JNIEnv *env, jobject jVersion)
251{
252 CK_VERSION_PTR ckpVersion;
253 jclass jVersionClass;
254 jfieldID jFieldID;
255 jbyte jMajor, jMinor;
256
257 if (jVersion == NULL((void*)0)) {
258 return NULL((void*)0);
259 }
260
261 // retrieve java values
262 jVersionClass = (*env)->GetObjectClass(env, jVersion);
263 if (jVersionClass == NULL((void*)0)) { return NULL((void*)0); }
264 jFieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B");
265 if (jFieldID == NULL((void*)0)) { return NULL((void*)0); }
266 jMajor = (*env)->GetByteField(env, jVersion, jFieldID);
267 jFieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B");
268 if (jFieldID == NULL((void*)0)) { return NULL((void*)0); }
269 jMinor = (*env)->GetByteField(env, jVersion, jFieldID);
270
271 // allocate memory for CK_VERSION pointer
272 ckpVersion = (CK_VERSION_PTR) calloc(1, sizeof(CK_VERSION));
273 if (ckpVersion == NULL((void*)0)) {
274 throwOutOfMemoryError(env, 0);
275 return NULL((void*)0);
276 }
277
278 // populate using java values
279 ckpVersion->major = jByteToCKByte(jMajor)((CK_BYTE) jMajor);
280 ckpVersion->minor = jByteToCKByte(jMinor)((CK_BYTE) jMinor);
281
282 return ckpVersion;
283}
284
285
286/*
287 * converts a Java CK_DATE object into a CK_DATE pointer
288 *
289 * @param env - used to call JNI functions to get the values out of the Java object
290 * @param jDate - the Java CK_DATE object to convert
291 * @return pointer to the new CK_DATE structure
292 */
293CK_DATE * jDateObjectToCKDatePtr(JNIEnv *env, jobject jDate)
294{
295 CK_DATE * ckpDate = NULL((void*)0);
296 CK_ULONG ckLength;
297 jclass jDateClass;
298 jfieldID jFieldID;
299 jobject jYear, jMonth, jDay;
300 jchar *jTempChars = NULL((void*)0);
301 CK_ULONG i;
302
303 if (jDate == NULL((void*)0)) {
304 return NULL((void*)0);
305 }
306
307 // retrieve java values
308 jDateClass = (*env)->FindClass(env, CLASS_DATE"sun/security/pkcs11/wrapper/CK_DATE");
309 if (jDateClass == NULL((void*)0)) { return NULL((void*)0); }
310 jFieldID = (*env)->GetFieldID(env, jDateClass, "year", "[C");
311 if (jFieldID == NULL((void*)0)) { return NULL((void*)0); }
312 jYear = (*env)->GetObjectField(env, jDate, jFieldID);
313 jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C");
314 if (jFieldID == NULL((void*)0)) { return NULL((void*)0); }
315 jMonth = (*env)->GetObjectField(env, jDate, jFieldID);
316 jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C");
317 if (jFieldID == NULL((void*)0)) { return NULL((void*)0); }
318 jDay = (*env)->GetObjectField(env, jDate, jFieldID);
319
320 // allocate memory for CK_DATE pointer
321 ckpDate = (CK_DATE *) calloc(1, sizeof(CK_DATE));
322 if (ckpDate == NULL((void*)0)) {
323 throwOutOfMemoryError(env, 0);
324 return NULL((void*)0);
325 }
326
327 // populate using java values
328 if (jYear == NULL((void*)0)) {
329 ckpDate->year[0] = 0;
330 ckpDate->year[1] = 0;
331 ckpDate->year[2] = 0;
332 ckpDate->year[3] = 0;
333 } else {
334 ckLength = (*env)->GetArrayLength(env, jYear);
335 jTempChars = (jchar*) calloc(ckLength, sizeof(jchar));
336 if (jTempChars == NULL((void*)0)) {
337 throwOutOfMemoryError(env, 0);
338 goto cleanup;
339 }
340 (*env)->GetCharArrayRegion(env, jYear, 0, ckLength, jTempChars);
341 if ((*env)->ExceptionCheck(env)) {
342 goto cleanup;
343 }
344
345 for (i = 0; (i < ckLength) && (i < 4) ; i++) {
346 ckpDate->year[i] = jCharToCKChar(jTempChars[i])((CK_CHAR) jTempChars[i]);
347 }
348 free(jTempChars);
349 }
350
351 if (jMonth == NULL((void*)0)) {
352 ckpDate->month[0] = 0;
353 ckpDate->month[1] = 0;
354 } else {
355 ckLength = (*env)->GetArrayLength(env, jMonth);
356 jTempChars = (jchar*) calloc(ckLength, sizeof(jchar));
357 if (jTempChars == NULL((void*)0)) {
358 throwOutOfMemoryError(env, 0);
359 goto cleanup;
360 }
361 (*env)->GetCharArrayRegion(env, jMonth, 0, ckLength, jTempChars);
362 if ((*env)->ExceptionCheck(env)) {
363 goto cleanup;
364 }
365
366 for (i = 0; (i < ckLength) && (i < 2) ; i++) {
367 ckpDate->month[i] = jCharToCKChar(jTempChars[i])((CK_CHAR) jTempChars[i]);
368 }
369 free(jTempChars);
370 }
371
372 if (jDay == NULL((void*)0)) {
373 ckpDate->day[0] = 0;
374 ckpDate->day[1] = 0;
375 } else {
376 ckLength = (*env)->GetArrayLength(env, jDay);
377 jTempChars = (jchar*) calloc(ckLength, sizeof(jchar));
378 if (jTempChars == NULL((void*)0)) {
379 throwOutOfMemoryError(env, 0);
380 goto cleanup;
381 }
382 (*env)->GetCharArrayRegion(env, jDay, 0, ckLength, jTempChars);
383 if ((*env)->ExceptionCheck(env)) {
384 goto cleanup;
385 }
386
387 for (i = 0; (i < ckLength) && (i < 2) ; i++) {
388 ckpDate->day[i] = jCharToCKChar(jTempChars[i])((CK_CHAR) jTempChars[i]);
389 }
390 free(jTempChars);
391 }
392
393 return ckpDate;
394cleanup:
395 free(jTempChars);
396 free(ckpDate);
397 return NULL((void*)0);
398}
399
400
401/*
402 * converts a Java CK_ATTRIBUTE object into a CK_ATTRIBUTE structure
403 *
404 * @param env - used to call JNI funktions to get the values out of the Java object
405 * @param jAttribute - the Java CK_ATTRIBUTE object to convert
406 * @return the new CK_ATTRIBUTE structure
407 */
408CK_ATTRIBUTE jAttributeToCKAttribute(JNIEnv *env, jobject jAttribute)
409{
410 CK_ATTRIBUTE ckAttribute;
411 jclass jAttributeClass;
412 jfieldID jFieldID;
413 jlong jType;
414 jobject jPValue;
415
416 memset(&ckAttribute, 0, sizeof(CK_ATTRIBUTE));
417
418 // TBD: what if jAttribute == NULL?!
419 TRACE0("\nDEBUG: jAttributeToCKAttribute");
420
421 /* get CK_ATTRIBUTE class */
422 TRACE0(", getting attribute object class");
423 jAttributeClass = (*env)->GetObjectClass(env, jAttribute);
424 if (jAttributeClass == NULL((void*)0)) { return ckAttribute; }
425
426 /* get type */
427 TRACE0(", getting type field");
428 jFieldID = (*env)->GetFieldID(env, jAttributeClass, "type", "J");
429 if (jFieldID == NULL((void*)0)) { return ckAttribute; }
430 jType = (*env)->GetLongField(env, jAttribute, jFieldID);
431 TRACE1(", type=0x%lX", jType);
432
433 /* get pValue */
434 TRACE0(", getting pValue field");
435 jFieldID = (*env)->GetFieldID(env, jAttributeClass, "pValue", "Ljava/lang/Object;");
436 if (jFieldID == NULL((void*)0)) { return ckAttribute; }
437 jPValue = (*env)->GetObjectField(env, jAttribute, jFieldID);
438 TRACE1(", pValue=%p", jPValue);
439
440 ckAttribute.type = jLongToCKULong(jType)((CK_ULONG) jType);
441 TRACE0(", converting pValue to primitive object");
442
443 /* convert the Java pValue object to a CK-type pValue pointer */
444 ckAttribute.pValue = jObjectToPrimitiveCKObjectPtr(env, jPValue, &(ckAttribute.ulValueLen));
445
446 TRACE0("\nDEBUG: jAttributeToCKAttribute FINISHED\n");
447
448 return ckAttribute ;
449}
450
451void masterKeyDeriveParamToCKMasterKeyDeriveParam(JNIEnv *env, jobject jParam,
452 jclass masterKeyDeriveParamClass,
453 CK_VERSION_PTR* cKMasterKeyDeriveParamVersion,
454 CK_SSL3_RANDOM_DATA* cKMasterKeyDeriveParamRandomInfo) {
455 jfieldID fieldID;
456 jclass jSsl3RandomDataClass;
457 jobject jRandomInfo, jRIClientRandom, jRIServerRandom, jVersion;
458
459 // retrieve java values
460 fieldID = (*env)->GetFieldID(env, masterKeyDeriveParamClass, "RandomInfo",
461 "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
462 if (fieldID == NULL((void*)0)) { return; }
463 jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
464 jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA"sun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA");
465 if (jSsl3RandomDataClass == NULL((void*)0)) { return; }
466 fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
467 if (fieldID == NULL((void*)0)) { return; }
468 jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
469 fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
470 if (fieldID == NULL((void*)0)) { return; }
471 jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
472 fieldID = (*env)->GetFieldID(env, masterKeyDeriveParamClass, "pVersion",
473 "Lsun/security/pkcs11/wrapper/CK_VERSION;");
474 if (fieldID == NULL((void*)0)) { return; }
475 jVersion = (*env)->GetObjectField(env, jParam, fieldID);
476
477 // populate using java values
478 *cKMasterKeyDeriveParamVersion = jVersionToCKVersionPtr(env, jVersion);
479 if ((*env)->ExceptionCheck(env)) { return; }
480 jByteArrayToCKByteArray(env, jRIClientRandom,
481 &(cKMasterKeyDeriveParamRandomInfo->pClientRandom),
482 &(cKMasterKeyDeriveParamRandomInfo->ulClientRandomLen));
483 if ((*env)->ExceptionCheck(env)) {
484 goto cleanup;
485 }
486 jByteArrayToCKByteArray(env, jRIServerRandom,
487 &(cKMasterKeyDeriveParamRandomInfo->pServerRandom),
488 &(cKMasterKeyDeriveParamRandomInfo->ulServerRandomLen));
489 if ((*env)->ExceptionCheck(env)) {
490 goto cleanup;
491 }
492 return;
493cleanup:
494 free(*cKMasterKeyDeriveParamVersion);
495 free(cKMasterKeyDeriveParamRandomInfo->pClientRandom);
496 cKMasterKeyDeriveParamRandomInfo->ulClientRandomLen = 0L;
497 free(cKMasterKeyDeriveParamRandomInfo->pServerRandom);
498 cKMasterKeyDeriveParamRandomInfo->ulServerRandomLen = 0L;
499 // explicitly set to NULL to ensure no double free possible
500 *cKMasterKeyDeriveParamVersion = NULL((void*)0);
501 cKMasterKeyDeriveParamRandomInfo->pClientRandom = NULL((void*)0);
502 cKMasterKeyDeriveParamRandomInfo->pServerRandom = NULL((void*)0);
503}
504
505/*
506 * converts the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to a
507 * CK_SSL3_MASTER_KEY_DERIVE_PARAMS pointer
508 *
509 * @param env - used to call JNI functions to get the Java classes and objects
510 * @param jParam - the Java CK_SSL3_MASTER_KEY_DERIVE_PARAMS object to convert
511 * @param pLength - length of the allocated memory of the returned pointer
512 * @return pointer to the new CK_SSL3_MASTER_KEY_DERIVE_PARAMS structure
513 */
514CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR
515jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr(JNIEnv *env,
516 jobject jParam, CK_ULONG *pLength)
517{
518 CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR ckParamPtr;
519 jclass jSsl3MasterKeyDeriveParamsClass;
520
521 if (pLength
13.1
'pLength' is not equal to NULL
!= NULL((void*)0)) {
14
Taking true branch
522 *pLength = 0L;
523 }
524
525 // allocate memory for CK_SSL3_MASTER_KEY_DERIVE_PARAMS pointer
526 ckParamPtr = calloc(1, sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS));
15
Memory is allocated
527 if (ckParamPtr == NULL((void*)0)) {
16
Assuming 'ckParamPtr' is not equal to NULL
17
Taking false branch
528 throwOutOfMemoryError(env, 0);
529 return NULL((void*)0);
530 }
531
532 // retrieve and populate using java values
533 jSsl3MasterKeyDeriveParamsClass =
534 (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS"sun/security/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS");
535 if (jSsl3MasterKeyDeriveParamsClass == NULL((void*)0)) {
18
Assuming 'jSsl3MasterKeyDeriveParamsClass' is not equal to NULL
19
Taking false branch
536 goto cleanup;
537 }
538 masterKeyDeriveParamToCKMasterKeyDeriveParam(env, jParam,
539 jSsl3MasterKeyDeriveParamsClass,
540 &(ckParamPtr->pVersion), &(ckParamPtr->RandomInfo));
541 if ((*env)->ExceptionCheck(env)) {
20
Assuming the condition is false
21
Taking false branch
542 goto cleanup;
543 }
544
545 if (pLength
21.1
'pLength' is not equal to NULL
!= NULL((void*)0)) {
22
Taking true branch
546 *pLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS);
547 }
548 return ckParamPtr;
549cleanup:
550 free(ckParamPtr);
551 return NULL((void*)0);
552}
553
554/*
555 * converts the Java CK_TLS12_MASTER_KEY_DERIVE_PARAMS object to a
556 * CK_TLS12_MASTER_KEY_DERIVE_PARAMS pointer
557 *
558 * @param env - used to call JNI functions to get the Java classes and objects
559 * @param jParam - the Java CK_TLS12_MASTER_KEY_DERIVE_PARAMS object to convert
560 * @param pLength - length of the allocated memory of the returned pointer
561 * @return pointer to the new CK_TLS12_MASTER_KEY_DERIVE_PARAMS structure
562 */
563CK_TLS12_MASTER_KEY_DERIVE_PARAMS_PTR
564jTls12MasterKeyDeriveParamToCKTls12MasterKeyDeriveParamPtr(JNIEnv *env,
565 jobject jParam, CK_ULONG *pLength)
566{
567 CK_TLS12_MASTER_KEY_DERIVE_PARAMS_PTR ckParamPtr;
568 jclass jTls12MasterKeyDeriveParamsClass;
569 jfieldID fieldID;
570 jlong prfHashMechanism;
571
572 if (pLength != NULL((void*)0)) {
573 *pLength = 0L;
574 }
575
576 // retrieve java values
577 jTls12MasterKeyDeriveParamsClass =
578 (*env)->FindClass(env, CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS"sun/security/pkcs11/wrapper/CK_TLS12_MASTER_KEY_DERIVE_PARAMS");
579 if (jTls12MasterKeyDeriveParamsClass == NULL((void*)0)) { return NULL((void*)0); }
580 fieldID = (*env)->GetFieldID(env,
581 jTls12MasterKeyDeriveParamsClass, "prfHashMechanism", "J");
582 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
583 prfHashMechanism = (*env)->GetLongField(env, jParam, fieldID);
584
585 // allocate memory for CK_TLS12_MASTER_KEY_DERIVE_PARAMS pointer
586 ckParamPtr = calloc(1, sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS));
587 if (ckParamPtr == NULL((void*)0)) {
588 throwOutOfMemoryError(env, 0);
589 return NULL((void*)0);
590 }
591
592 // populate using java values
593 masterKeyDeriveParamToCKMasterKeyDeriveParam(env, jParam,
594 jTls12MasterKeyDeriveParamsClass, &ckParamPtr->pVersion,
595 &ckParamPtr->RandomInfo);
596 if ((*env)->ExceptionCheck(env)) {
597 goto cleanup;
598 }
599
600 ckParamPtr->prfHashMechanism = (CK_MECHANISM_TYPE) prfHashMechanism;
601
602 if (pLength != NULL((void*)0)) {
603 *pLength = sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS);
604 }
605 return ckParamPtr;
606cleanup:
607 free(ckParamPtr);
608 return NULL((void*)0);
609}
610
611/*
612 * converts the Java CK_TLS_PRF_PARAMS object to a CK_TLS_PRF_PARAMS pointer
613 *
614 * @param env - used to call JNI functions to get the Java classes and objects
615 * @param jParam - the Java CK_TLS_PRF_PARAMS object to convert
616 * @param pLength - length of the allocated memory of the returned pointer
617 * @return pointer to the new CK_TLS_PRF_PARAMS structure
618 */
619CK_TLS_PRF_PARAMS_PTR
620jTlsPrfParamsToCKTlsPrfParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
621{
622 CK_TLS_PRF_PARAMS_PTR ckParamPtr;
623 jclass jTlsPrfParamsClass;
624 jfieldID fieldID;
625 jobject jSeed, jLabel, jOutput;
626
627 if (pLength != NULL((void*)0)) {
628 *pLength = 0;
629 }
630
631 // retrieve java values
632 jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS"sun/security/pkcs11/wrapper/CK_TLS_PRF_PARAMS");
633 if (jTlsPrfParamsClass == NULL((void*)0)) { return NULL((void*)0); }
634 fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pSeed", "[B");
635 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
636 jSeed = (*env)->GetObjectField(env, jParam, fieldID);
637 fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pLabel", "[B");
638 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
639 jLabel = (*env)->GetObjectField(env, jParam, fieldID);
640 fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pOutput", "[B");
641 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
642 jOutput = (*env)->GetObjectField(env, jParam, fieldID);
643
644 // allocate memory for CK_TLS_PRF_PARAMS pointer
645 ckParamPtr = calloc(1, sizeof(CK_TLS_PRF_PARAMS));
646 if (ckParamPtr == NULL((void*)0)) {
647 throwOutOfMemoryError(env, 0);
648 return NULL((void*)0);
649 }
650
651 // populate using java values
652 jByteArrayToCKByteArray(env, jSeed, &(ckParamPtr->pSeed), &(ckParamPtr->ulSeedLen));
653 if ((*env)->ExceptionCheck(env)) {
654 goto cleanup;
655 }
656 jByteArrayToCKByteArray(env, jLabel, &(ckParamPtr->pLabel), &(ckParamPtr->ulLabelLen));
657 if ((*env)->ExceptionCheck(env)) {
658 goto cleanup;
659 }
660 ckParamPtr->pulOutputLen = calloc(1, sizeof(CK_ULONG));
661 if (ckParamPtr->pulOutputLen == NULL((void*)0)) {
662 goto cleanup;
663 }
664 jByteArrayToCKByteArray(env, jOutput, &(ckParamPtr->pOutput), ckParamPtr->pulOutputLen);
665 if ((*env)->ExceptionCheck(env)) {
666 goto cleanup;
667 }
668
669 if (pLength != NULL((void*)0)) {
670 *pLength = sizeof(CK_TLS_PRF_PARAMS);
671 }
672 return ckParamPtr;
673cleanup:
674 free(ckParamPtr->pSeed);
675 free(ckParamPtr->pLabel);
676 free(ckParamPtr->pOutput);
677 free(ckParamPtr->pulOutputLen);
678 free(ckParamPtr);
679 return NULL((void*)0);
680}
681
682/*
683 * converts the Java CK_TLS_MAC_PARAMS object to a CK_TLS_MAC_PARAMS pointer
684 *
685 * @param env - used to call JNI functions to get the Java classes and objects
686 * @param jParam - the Java CK_TLS_MAC_PARAMS object to convert
687 * @param pLength - length of the allocated memory of the returned pointer
688 * @return pointer to the new CK_TLS_MAC_PARAMS structure
689 */
690
691CK_TLS_MAC_PARAMS_PTR
692jTlsMacParamsToCKTlsMacParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
693{
694 CK_TLS_MAC_PARAMS_PTR ckParamPtr;
695 jclass jTlsMacParamsClass;
696 jfieldID fieldID;
697 jlong jPrfMechanism, jUlMacLength, jUlServerOrClient;
698
699 if (pLength != NULL((void*)0)) {
700 *pLength = 0L;
701 }
702
703 // retrieve java values
704 jTlsMacParamsClass = (*env)->FindClass(env, CLASS_TLS_MAC_PARAMS"sun/security/pkcs11/wrapper/CK_TLS_MAC_PARAMS");
705 if (jTlsMacParamsClass == NULL((void*)0)) { return NULL((void*)0); }
706 fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "prfMechanism", "J");
707 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
708 jPrfMechanism = (*env)->GetLongField(env, jParam, fieldID);
709 fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "ulMacLength", "J");
710 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
711 jUlMacLength = (*env)->GetLongField(env, jParam, fieldID);
712 fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "ulServerOrClient", "J");
713 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
714 jUlServerOrClient = (*env)->GetLongField(env, jParam, fieldID);
715
716 // allocate memory for CK_TLS_MAC_PARAMS pointer
717 ckParamPtr = calloc(1, sizeof(CK_TLS_MAC_PARAMS));
718 if (ckParamPtr == NULL((void*)0)) {
719 throwOutOfMemoryError(env, 0);
720 return NULL((void*)0);
721 }
722
723 // populate using java values
724 ckParamPtr->prfHashMechanism = jLongToCKULong(jPrfMechanism)((CK_ULONG) jPrfMechanism);
725 ckParamPtr->ulMacLength = jLongToCKULong(jUlMacLength)((CK_ULONG) jUlMacLength);
726 ckParamPtr->ulServerOrClient = jLongToCKULong(jUlServerOrClient)((CK_ULONG) jUlServerOrClient);
727
728 if (pLength != NULL((void*)0)) {
729 *pLength = sizeof(CK_TLS_MAC_PARAMS);
730 }
731 return ckParamPtr;
732}
733
734void keyMatParamToCKKeyMatParam(JNIEnv *env, jobject jParam,
735 jclass jKeyMatParamClass,
736 CK_ULONG* cKKeyMatParamUlMacSizeInBits,
737 CK_ULONG* cKKeyMatParamUlKeySizeInBits,
738 CK_ULONG* cKKeyMatParamUlIVSizeInBits,
739 CK_BBOOL* cKKeyMatParamBIsExport,
740 CK_SSL3_RANDOM_DATA* cKKeyMatParamRandomInfo,
741 CK_SSL3_KEY_MAT_OUT_PTR* cKKeyMatParamPReturnedKeyMaterial)
742{
743 jclass jSsl3RandomDataClass, jSsl3KeyMatOutClass;
744 jfieldID fieldID;
745 jlong jMacSizeInBits, jKeySizeInBits, jIVSizeInBits;
746 jboolean jIsExport;
747 jobject jRandomInfo, jRIClientRandom, jRIServerRandom;
748 jobject jReturnedKeyMaterial, jRMIvClient, jRMIvServer;
749 CK_ULONG ckTemp;
750
751 // the pointer arguments should already be initialized by caller
752
753 // retrieve java values
754 fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulMacSizeInBits", "J");
755 if (fieldID == NULL((void*)0)) { return; }
756 jMacSizeInBits = (*env)->GetLongField(env, jParam, fieldID);
757 fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulKeySizeInBits", "J");
758 if (fieldID == NULL((void*)0)) { return; }
759 jKeySizeInBits = (*env)->GetLongField(env, jParam, fieldID);
760 fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulIVSizeInBits", "J");
761 if (fieldID == NULL((void*)0)) { return; }
762 jIVSizeInBits = (*env)->GetLongField(env, jParam, fieldID);
763 fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "bIsExport", "Z");
764 if (fieldID == NULL((void*)0)) { return; }
765 jIsExport = (*env)->GetBooleanField(env, jParam, fieldID);
766 jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA"sun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA");
767 if (jSsl3RandomDataClass == NULL((void*)0)) { return; }
768 fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "RandomInfo",
769 "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;");
770 if (fieldID == NULL((void*)0)) { return; }
771 jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID);
772 fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B");
773 if (fieldID == NULL((void*)0)) { return; }
774 jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
775 fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B");
776 if (fieldID == NULL((void*)0)) { return; }
777 jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID);
778 jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT"sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT");
779 if (jSsl3KeyMatOutClass == NULL((void*)0)) { return; }
780 fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "pReturnedKeyMaterial",
781 "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;");
782 if (fieldID == NULL((void*)0)) { return; }
783 jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID);
784 fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B");
785 if (fieldID == NULL((void*)0)) { return; }
786 jRMIvClient = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
787 fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B");
788 if (fieldID == NULL((void*)0)) { return; }
789 jRMIvServer = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID);
790
791 // populate the specified pointers using java values
792 *cKKeyMatParamUlMacSizeInBits = jLongToCKULong(jMacSizeInBits)((CK_ULONG) jMacSizeInBits);
793 *cKKeyMatParamUlKeySizeInBits = jLongToCKULong(jKeySizeInBits)((CK_ULONG) jKeySizeInBits);
794 *cKKeyMatParamUlIVSizeInBits = jLongToCKULong(jIVSizeInBits)((CK_ULONG) jIVSizeInBits);
795 *cKKeyMatParamBIsExport = jBooleanToCKBBool(jIsExport)((jIsExport == 1) ? 1 : 0);;
796 jByteArrayToCKByteArray(env, jRIClientRandom,
797 &(cKKeyMatParamRandomInfo->pClientRandom),
798 &(cKKeyMatParamRandomInfo->ulClientRandomLen));
799 if ((*env)->ExceptionCheck(env)) {
800 // just return as no memory allocation yet
801 return;
802 }
803 jByteArrayToCKByteArray(env, jRIServerRandom,
804 &(cKKeyMatParamRandomInfo->pServerRandom),
805 &(cKKeyMatParamRandomInfo->ulServerRandomLen));
806 if ((*env)->ExceptionCheck(env)) {
807 goto cleanup;
808 }
809 /* allocate memory for pReturnedKeyMaterial */
810 *cKKeyMatParamPReturnedKeyMaterial =
811 (CK_SSL3_KEY_MAT_OUT_PTR) calloc(1, sizeof(CK_SSL3_KEY_MAT_OUT));
812 if (*cKKeyMatParamPReturnedKeyMaterial == NULL((void*)0)) {
813 throwOutOfMemoryError(env, 0);
814 goto cleanup;
815 }
816
817 // the handles are output params only, no need to fetch them from Java
818 (*cKKeyMatParamPReturnedKeyMaterial)->hClientMacSecret = 0;
819 (*cKKeyMatParamPReturnedKeyMaterial)->hServerMacSecret = 0;
820 (*cKKeyMatParamPReturnedKeyMaterial)->hClientKey = 0;
821 (*cKKeyMatParamPReturnedKeyMaterial)->hServerKey = 0;
822
823 jByteArrayToCKByteArray(env, jRMIvClient,
824 &((*cKKeyMatParamPReturnedKeyMaterial)->pIVClient), &ckTemp);
825 if ((*env)->ExceptionCheck(env)) {
826 goto cleanup;
827 }
828 jByteArrayToCKByteArray(env, jRMIvServer,
829 &((*cKKeyMatParamPReturnedKeyMaterial)->pIVServer), &ckTemp);
830 if ((*env)->ExceptionCheck(env)) {
831 goto cleanup;
832 }
833
834 return;
835cleanup:
836 free(cKKeyMatParamRandomInfo->pClientRandom);
837 free(cKKeyMatParamRandomInfo->pServerRandom);
838 if ((*cKKeyMatParamPReturnedKeyMaterial) != NULL((void*)0)) {
839 free((*cKKeyMatParamPReturnedKeyMaterial)->pIVClient);
840 free(*cKKeyMatParamPReturnedKeyMaterial);
841 }
842 // explicitly set to NULL to ensure no double free possible
843 cKKeyMatParamRandomInfo->pClientRandom = NULL((void*)0);
844 cKKeyMatParamRandomInfo->pServerRandom = NULL((void*)0);
845 *cKKeyMatParamPReturnedKeyMaterial = NULL((void*)0);
846 return;
847}
848/*
849 * converts the Java CK_SSL3_KEY_MAT_PARAMS object to a
850 * CK_SSL3_KEY_MAT_PARAMS pointer
851 *
852 * @param env - used to call JNI funktions to get the Java classes and objects
853 * @param jParam - the Java CK_SSL3_KEY_MAT_PARAMS object to convert
854 * @param pLength - length of the allocated memory of the returned pointer
855 * @return pointer to the new CK_SSL3_KEY_MAT_PARAMS structure
856 */
857CK_SSL3_KEY_MAT_PARAMS_PTR
858jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
859{
860 CK_SSL3_KEY_MAT_PARAMS_PTR ckParamPtr;
861 jclass jSsl3KeyMatParamsClass;
862
863 if (pLength != NULL((void*)0)) {
864 *pLength = 0;
865 }
866
867 // allocate memory for CK_SSL3_KEY_MAT_PARAMS pointer
868 ckParamPtr = calloc(1, sizeof(CK_SSL3_KEY_MAT_PARAMS));
869 if (ckParamPtr == NULL((void*)0)) {
870 throwOutOfMemoryError(env, 0);
871 return NULL((void*)0);
872 }
873
874 // retrieve and populate using java values
875 jSsl3KeyMatParamsClass = (*env)->FindClass(env,
876 CLASS_SSL3_KEY_MAT_PARAMS"sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS");
877 if (jSsl3KeyMatParamsClass == NULL((void*)0)) {
878 goto cleanup;
879 }
880 keyMatParamToCKKeyMatParam(env, jParam, jSsl3KeyMatParamsClass,
881 &(ckParamPtr->ulMacSizeInBits), &(ckParamPtr->ulKeySizeInBits),
882 &(ckParamPtr->ulIVSizeInBits), &(ckParamPtr->bIsExport),
883 &(ckParamPtr->RandomInfo), &(ckParamPtr->pReturnedKeyMaterial));
884 if ((*env)->ExceptionCheck(env)) {
885 goto cleanup;
886 }
887
888 if (pLength != NULL((void*)0)) {
889 *pLength = sizeof(CK_SSL3_KEY_MAT_PARAMS);
890 }
891 return ckParamPtr;
892cleanup:
893 free(ckParamPtr);
894 return NULL((void*)0);
895}
896
897/*
898 * converts the Java CK_TLS12_KEY_MAT_PARAMS object to a
899 * CK_TLS12_KEY_MAT_PARAMS pointer
900 *
901 * @param env - used to call JNI functions to get the Java classes and objects
902 * @param jParam - the Java CK_TLS12_KEY_MAT_PARAMS object to convert
903 * @param pLength - length of the allocated memory of the returned pointer
904 * @return pointer to the new CK_TLS12_KEY_MAT_PARAMS structure
905 */
906CK_TLS12_KEY_MAT_PARAMS_PTR jTls12KeyMatParamToCKTls12KeyMatParamPtr(JNIEnv *env,
907 jobject jParam, CK_ULONG *pLength)
908{
909 CK_TLS12_KEY_MAT_PARAMS_PTR ckParamPtr;
910 jclass jTls12KeyMatParamsClass;
911 jfieldID fieldID;
912 jlong prfHashMechanism;
913
914 if (pLength != NULL((void*)0)) {
915 *pLength = 0;
916 }
917
918 // retrieve java values
919 jTls12KeyMatParamsClass = (*env)->FindClass(env,
920 CLASS_TLS12_KEY_MAT_PARAMS"sun/security/pkcs11/wrapper/CK_TLS12_KEY_MAT_PARAMS");
921 if (jTls12KeyMatParamsClass == NULL((void*)0)) { return NULL((void*)0); }
922 fieldID = (*env)->GetFieldID(env, jTls12KeyMatParamsClass,
923 "prfHashMechanism", "J");
924 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
925 prfHashMechanism = (*env)->GetLongField(env, jParam, fieldID);
926
927 // allocate memory for CK_TLS12_KEY_MAT_PARAMS pointer
928 ckParamPtr = calloc(1, sizeof(CK_TLS12_KEY_MAT_PARAMS));
929 if (ckParamPtr == NULL((void*)0)) {
930 throwOutOfMemoryError(env, 0);
931 return NULL((void*)0);
932 }
933
934 // populate using java values
935 keyMatParamToCKKeyMatParam(env, jParam, jTls12KeyMatParamsClass,
936 &(ckParamPtr->ulMacSizeInBits), &(ckParamPtr->ulKeySizeInBits),
937 &(ckParamPtr->ulIVSizeInBits), &(ckParamPtr->bIsExport),
938 &(ckParamPtr->RandomInfo), &(ckParamPtr->pReturnedKeyMaterial));
939 if ((*env)->ExceptionCheck(env)) {
940 goto cleanup;
941 }
942 ckParamPtr->prfHashMechanism = (CK_MECHANISM_TYPE)prfHashMechanism;
943
944 if (pLength != NULL((void*)0)) {
945 *pLength = sizeof(CK_TLS12_KEY_MAT_PARAMS);
946 }
947 return ckParamPtr;
948cleanup:
949 free(ckParamPtr);
950 return NULL((void*)0);
951}
952
953/*
954 * converts the Java CK_AES_CTR_PARAMS object to a CK_AES_CTR_PARAMS pointer
955 *
956 * @param env - used to call JNI funktions to get the Java classes and objects
957 * @param jParam - the Java CK_AES_CTR_PARAMS object to convert
958 * @param pLength - length of the allocated memory of the returned pointer
959 * @return pointer to the new CK_AES_CTR_PARAMS structure
960 */
961CK_AES_CTR_PARAMS_PTR
962jAesCtrParamsToCKAesCtrParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
963{
964 CK_AES_CTR_PARAMS_PTR ckParamPtr;
965 jclass jAesCtrParamsClass;
966 jfieldID fieldID;
967 jlong jCounterBits;
968 jobject jCb;
969 CK_BYTE_PTR ckBytes = NULL((void*)0);
970 CK_ULONG ckTemp;
971
972 if (pLength != NULL((void*)0)) {
973 *pLength = 0L;
974 }
975
976 // retrieve java values
977 jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS"sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS");
978 if (jAesCtrParamsClass == NULL((void*)0)) { return NULL((void*)0); }
979 if (!(*env)->IsInstanceOf(env, jParam, jAesCtrParamsClass)) {
980 return NULL((void*)0);
981 }
982 fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "ulCounterBits", "J");
983 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
984 jCounterBits = (*env)->GetLongField(env, jParam, fieldID);
985 fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "cb", "[B");
986 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
987 jCb = (*env)->GetObjectField(env, jParam, fieldID);
988
989 // allocate memory for CK_AES_CTR_PARAMS pointer
990 ckParamPtr = calloc(1, sizeof(CK_AES_CTR_PARAMS));
991 if (ckParamPtr == NULL((void*)0)) {
992 throwOutOfMemoryError(env, 0);
993 return NULL((void*)0);
994 }
995
996 // populate using java values
997 jByteArrayToCKByteArray(env, jCb, &ckBytes, &ckTemp);
998 if ((*env)->ExceptionCheck(env) || ckTemp != 16) {
999 goto cleanup;
1000 }
1001 memcpy(ckParamPtr->cb, ckBytes, ckTemp);
1002 free(ckBytes);
1003
1004 ckParamPtr->ulCounterBits = jLongToCKULong(jCounterBits)((CK_ULONG) jCounterBits);
1005
1006 if (pLength != NULL((void*)0)) {
1007 *pLength = sizeof(CK_AES_CTR_PARAMS);
1008 }
1009 return ckParamPtr;
1010cleanup:
1011 free(ckBytes);
1012 free(ckParamPtr);
1013 return NULL((void*)0);
1014}
1015
1016/*
1017 * converts the Java CK_GCM_PARAMS object to a CK_GCM_PARAMS_NO_IVBITS pointer
1018 * Note: Need to try NSS definition first to avoid SIGSEGV.
1019 *
1020 * @param env - used to call JNI funktions to get the Java classes and objects
1021 * @param jParam - the Java CK_GCM_PARAMS object to convert
1022 * @param pLength - length of the allocated memory of the returned pointer
1023 * @return pointer to the new CK_GCM_PARAMS_NO_IVBITS structure
1024 */
1025CK_GCM_PARAMS_NO_IVBITS_PTR
1026jGCMParamsToCKGCMParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1027{
1028 CK_GCM_PARAMS_NO_IVBITS_PTR ckParamPtr;
1029 jclass jGcmParamsClass;
1030 jfieldID fieldID;
1031 jobject jIv, jAad;
1032 jlong jTagLen;
1033
1034 TRACE0("DEBUG jGCMParamsToCKGCMParam is called\n");
1035
1036 if (pLength != NULL((void*)0)) {
1037 *pLength = 0L;
1038 }
1039
1040 // retrieve java values
1041 jGcmParamsClass = (*env)->FindClass(env, CLASS_GCM_PARAMS"sun/security/pkcs11/wrapper/CK_GCM_PARAMS");
1042 if (jGcmParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1043 if (!(*env)->IsInstanceOf(env, jParam, jGcmParamsClass)) {
1044 return NULL((void*)0);
1045 }
1046 fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "iv", "[B");
1047 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1048 jIv = (*env)->GetObjectField(env, jParam, fieldID);
1049 fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "aad", "[B");
1050 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1051 jAad = (*env)->GetObjectField(env, jParam, fieldID);
1052 fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "tagBits", "J");
1053 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1054 jTagLen = (*env)->GetLongField(env, jParam, fieldID);
1055
1056 // allocate memory for CK_GCM_PARAMS_NO_IVBITS pointer
1057 ckParamPtr = calloc(1, sizeof(CK_GCM_PARAMS_NO_IVBITS));
1058 if (ckParamPtr == NULL((void*)0)) {
1059 throwOutOfMemoryError(env, 0);
1060 return NULL((void*)0);
1061 }
1062
1063 // populate using java values
1064 jByteArrayToCKByteArray(env, jIv, &(ckParamPtr->pIv), &(ckParamPtr->ulIvLen));
1065 if ((*env)->ExceptionCheck(env)) {
1066 goto cleanup;
1067 }
1068
1069 jByteArrayToCKByteArray(env, jAad, &(ckParamPtr->pAAD), &(ckParamPtr->ulAADLen));
1070 if ((*env)->ExceptionCheck(env)) {
1071 goto cleanup;
1072 }
1073
1074 ckParamPtr->ulTagBits = jLongToCKULong(jTagLen)((CK_ULONG) jTagLen);
1075
1076 if (pLength != NULL((void*)0)) {
1077 *pLength = sizeof(CK_GCM_PARAMS_NO_IVBITS);
1078 }
1079 TRACE1("Created inner GCM_PARAMS PTR w/o ulIvBits %p\n", ckParamPtr);
1080 return ckParamPtr;
1081cleanup:
1082 free(ckParamPtr->pIv);
1083 free(ckParamPtr->pAAD);
1084 free(ckParamPtr);
1085 return NULL((void*)0);
1086}
1087
1088/*
1089 * converts the Java CK_CCM_PARAMS object to a CK_CCM_PARAMS pointer
1090 *
1091 * @param env - used to call JNI functions to get the Java classes and objects
1092 * @param jParam - the Java CK_CCM_PARAMS object to convert
1093 * @param pLength - length of the allocated memory of the returned pointer
1094 * @return pointer to the new CK_CCM_PARAMS structure
1095 */
1096CK_CCM_PARAMS_PTR
1097jCCMParamsToCKCCMParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1098{
1099 CK_CCM_PARAMS_PTR ckParamPtr;
1100 jclass jCcmParamsClass;
1101 jfieldID fieldID;
1102 jobject jNonce, jAad;
1103 jlong jDataLen, jMacLen;
1104
1105 if (pLength != NULL((void*)0)) {
1106 *pLength = 0;
1107 }
1108
1109 // retrieve java values
1110 jCcmParamsClass = (*env)->FindClass(env, CLASS_CCM_PARAMS"sun/security/pkcs11/wrapper/CK_CCM_PARAMS");
1111 if (jCcmParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1112 if (!(*env)->IsInstanceOf(env, jParam, jCcmParamsClass)) {
1113 return NULL((void*)0);
1114 }
1115 fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "dataLen", "J");
1116 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1117 jDataLen = (*env)->GetLongField(env, jParam, fieldID);
1118 fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "nonce", "[B");
1119 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1120 jNonce = (*env)->GetObjectField(env, jParam, fieldID);
1121 fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "aad", "[B");
1122 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1123 jAad = (*env)->GetObjectField(env, jParam, fieldID);
1124 fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "macLen", "J");
1125 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1126 jMacLen = (*env)->GetLongField(env, jParam, fieldID);
1127
1128 // allocate memory for CK_CCM_PARAMS pointer
1129 ckParamPtr = calloc(1, sizeof(CK_CCM_PARAMS));
1130 if (ckParamPtr == NULL((void*)0)) {
1131 throwOutOfMemoryError(env, 0);
1132 return NULL((void*)0);
1133 }
1134
1135 // populate using java values
1136 ckParamPtr->ulDataLen = jLongToCKULong(jDataLen)((CK_ULONG) jDataLen);
1137 jByteArrayToCKByteArray(env, jNonce, &(ckParamPtr->pNonce),
1138 &(ckParamPtr->ulNonceLen));
1139 if ((*env)->ExceptionCheck(env)) {
1140 goto cleanup;
1141 }
1142
1143 jByteArrayToCKByteArray(env, jAad, &(ckParamPtr->pAAD),
1144 &(ckParamPtr->ulAADLen));
1145 if ((*env)->ExceptionCheck(env)) {
1146 goto cleanup;
1147 }
1148
1149 ckParamPtr->ulMACLen = jLongToCKULong(jMacLen)((CK_ULONG) jMacLen);
1150
1151 if (pLength != NULL((void*)0)) {
1152 *pLength = sizeof(CK_CCM_PARAMS);
1153 }
1154 return ckParamPtr;
1155cleanup:
1156 free(ckParamPtr->pNonce);
1157 free(ckParamPtr->pAAD);
1158 free(ckParamPtr);
1159 return NULL((void*)0);
1160}
1161
1162/*
1163 * converts the Java CK_SALSA20_CHACHA20_POLY1305_PARAMS object to a
1164 * CK_SALSA20_CHACHA20_POLY1305_PARAMS pointer
1165 *
1166 * @param env - used to call JNI functions to get the Java classes and objects
1167 * @param jParam - the Java CK_SALSA20_CHACHA20_POLY1305_PARAMS object to
1168 * convert
1169 * @param pLength - length of the allocated memory of the returned pointer
1170 * @return pointer to the new CK_SALSA20_CHACHA20_POLY1305_PARAMS structure
1171 */
1172CK_SALSA20_CHACHA20_POLY1305_PARAMS_PTR
1173jSalsaChaChaPolyParamsToCKSalsaChaChaPolyParamPtr(
1174 JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1175{
1176 CK_SALSA20_CHACHA20_POLY1305_PARAMS_PTR ckParamPtr;
1177 jclass jParamsClass;
1178 jfieldID fieldID;
1179 jobject jNonce, jAad;
1180
1181 if (pLength != NULL((void*)0)) {
1182 *pLength = 0;
1183 }
1184
1185 // retrieve java values
1186 jParamsClass = (*env)->FindClass(env,
1187 CLASS_SALSA20_CHACHA20_POLY1305_PARAMS"sun/security/pkcs11/wrapper/CK_SALSA20_CHACHA20_POLY1305_PARAMS");
1188 if (jParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1189 if (!(*env)->IsInstanceOf(env, jParam, jParamsClass)) {
1190 return NULL((void*)0);
1191 }
1192 fieldID = (*env)->GetFieldID(env, jParamsClass, "nonce", "[B");
1193 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1194 jNonce = (*env)->GetObjectField(env, jParam, fieldID);
1195 fieldID = (*env)->GetFieldID(env, jParamsClass, "aad", "[B");
1196 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1197 jAad = (*env)->GetObjectField(env, jParam, fieldID);
1198 // allocate memory for CK_SALSA20_CHACHA20_POLY1305_PARAMS pointer
1199 ckParamPtr = calloc(1, sizeof(CK_SALSA20_CHACHA20_POLY1305_PARAMS));
1200 if (ckParamPtr == NULL((void*)0)) {
1201 throwOutOfMemoryError(env, 0);
1202 return NULL((void*)0);
1203 }
1204
1205 // populate using java values
1206 jByteArrayToCKByteArray(env, jNonce, &(ckParamPtr->pNonce),
1207 &(ckParamPtr->ulNonceLen));
1208 if ((*env)->ExceptionCheck(env)) {
1209 goto cleanup;
1210 }
1211
1212 jByteArrayToCKByteArray(env, jAad, &(ckParamPtr->pAAD),
1213 &(ckParamPtr->ulAADLen));
1214 if ((*env)->ExceptionCheck(env)) {
1215 goto cleanup;
1216 }
1217
1218 if (pLength != NULL((void*)0)) {
1219 *pLength = sizeof(CK_SALSA20_CHACHA20_POLY1305_PARAMS);
1220 }
1221 return ckParamPtr;
1222cleanup:
1223 free(ckParamPtr->pNonce);
1224 free(ckParamPtr->pAAD);
1225 free(ckParamPtr);
1226 return NULL((void*)0);
1227}
1228
1229/*
1230 * converts a Java CK_MECHANISM object into a CK_MECHANISM pointer
1231 * pointer.
1232 *
1233 * @param env - used to call JNI funktions to get the values out of the Java object
1234 * @param jMech - the Java CK_MECHANISM object to convert
1235 * @return pointer to the new CK_MECHANISM structure
1236 */
1237CK_MECHANISM_PTR jMechanismToCKMechanismPtr(JNIEnv *env, jobject jMech)
1238{
1239 CK_MECHANISM_PTR ckpMech;
1240 jlong jMechType = (*env)->GetLongField(env, jMech, mech_mechanismID);
1241 jobject jParam = (*env)->GetObjectField(env, jMech, mech_pParameterID);
1242
1243 /* allocate memory for CK_MECHANISM_PTR */
1244 ckpMech = (CK_MECHANISM_PTR) calloc(1, sizeof(CK_MECHANISM));
1245 if (ckpMech == NULL((void*)0)) {
1
Assuming 'ckpMech' is not equal to NULL
2
Taking false branch
1246 throwOutOfMemoryError(env, 0);
1247 return NULL((void*)0);
1248 }
1249 TRACE1("DEBUG jMechanismToCKMechanismPtr: allocated mech %p\n", ckpMech);
1250
1251 ckpMech->mechanism = jLongToCKULong(jMechType)((CK_ULONG) jMechType);
1252
1253 /* convert the specific Java mechanism parameter object to a pointer to a
1254 * CK-type mechanism structure
1255 */
1256 if (jParam == NULL((void*)0)) {
3
Assuming 'jParam' is not equal to NULL
4
Taking false branch
1257 ckpMech->pParameter = NULL((void*)0);
1258 ckpMech->ulParameterLen = 0;
1259 } else {
1260 ckpMech->pParameter = jMechParamToCKMechParamPtr(env, jParam,
5
Calling 'jMechParamToCKMechParamPtr'
1261 ckpMech->mechanism, &(ckpMech->ulParameterLen));
1262 }
1263 return ckpMech;
1264}
1265
1266/*
1267 * converts the pValue of a CK_ATTRIBUTE structure into a Java Object by
1268 * checking the type of the attribute. A PKCS#11 attribute value can
1269 * be a CK_ULONG, CK_BYTE[], CK_CHAR[], big integer, CK_BBOOL, CK_UTF8CHAR[],
1270 * CK_DATE or CK_FLAGS that gets converted to a corresponding Java object.
1271 *
1272 * @param env - used to call JNI functions to create the new Java object
1273 * @param ckpAttribute - the pointer to the CK_ATTRIBUTE structure that contains the type
1274 * and the pValue to convert
1275 * @return the new Java object of the CK-type pValue
1276 */
1277jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute)
1278{
1279 jint jValueLength;
1280 jobject jValueObject = NULL((void*)0);
1281
1282 jValueLength = ckULongToJInt(ckpAttribute->ulValueLen)((jint) ckpAttribute->ulValueLen);
1283
1284 if ((jValueLength <= 0) || (ckpAttribute->pValue == NULL((void*)0))) {
1285 return NULL((void*)0) ;
1286 }
1287
1288 switch(ckpAttribute->type) {
1289 case CKA_CLASS0x00000000UL:
1290 /* value CK_OBJECT_CLASS, defacto a CK_ULONG */
1291 case CKA_KEY_TYPE0x00000100UL:
1292 /* value CK_KEY_TYPE, defacto a CK_ULONG */
1293 case CKA_CERTIFICATE_TYPE0x00000080UL:
1294 /* value CK_CERTIFICATE_TYPE, defacto a CK_ULONG */
1295 case CKA_HW_FEATURE_TYPE0x00000300UL:
1296 /* value CK_HW_FEATURE_TYPE, defacto a CK_ULONG */
1297 case CKA_MODULUS_BITS0x00000121UL:
1298 case CKA_VALUE_BITS0x00000160UL:
1299 case CKA_VALUE_LEN0x00000161UL:
1300 case CKA_KEY_GEN_MECHANISM0x00000166UL:
1301 case CKA_PRIME_BITS0x00000133UL:
1302 case CKA_SUB_PRIME_BITS0x00000134UL:
1303 /* value CK_ULONG */
1304 jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
1305 break;
1306
1307 /* can be CK_BYTE[],CK_CHAR[] or big integer; defacto always CK_BYTE[] */
1308 case CKA_VALUE0x00000011UL:
1309 case CKA_OBJECT_ID0x00000012UL:
1310 case CKA_SUBJECT0x00000101UL:
1311 case CKA_ID0x00000102UL:
1312 case CKA_ISSUER0x00000081UL:
1313 case CKA_SERIAL_NUMBER0x00000082UL:
1314 case CKA_OWNER0x00000084UL:
1315 case CKA_AC_ISSUER0x00000083UL:
1316 case CKA_ATTR_TYPES0x00000085UL:
1317 case CKA_ECDSA_PARAMS0x00000180UL:
1318 /* CKA_EC_PARAMS is the same, these two are equivalent */
1319 case CKA_EC_POINT0x00000181UL:
1320 case CKA_PRIVATE_EXPONENT0x00000123UL:
1321 case CKA_PRIME_10x00000124UL:
1322 case CKA_PRIME_20x00000125UL:
1323 case CKA_EXPONENT_10x00000126UL:
1324 case CKA_EXPONENT_20x00000127UL:
1325 case CKA_COEFFICIENT0x00000128UL:
1326 /* value CK_BYTE[] */
1327 jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
1328 break;
1329
1330 case CKA_RESET_ON_INIT0x00000301UL:
1331 case CKA_HAS_RESET0x00000302UL:
1332 case CKA_TOKEN0x00000001UL:
1333 case CKA_PRIVATE0x00000002UL:
1334 case CKA_MODIFIABLE0x00000170UL:
1335 case CKA_DERIVE0x0000010CUL:
1336 case CKA_LOCAL0x00000163UL:
1337 case CKA_ENCRYPT0x00000104UL:
1338 case CKA_VERIFY0x0000010AUL:
1339 case CKA_VERIFY_RECOVER0x0000010BUL:
1340 case CKA_WRAP0x00000106UL:
1341 case CKA_SENSITIVE0x00000103UL:
1342 case CKA_SECONDARY_AUTH0x00000200UL:
1343 case CKA_DECRYPT0x00000105UL:
1344 case CKA_SIGN0x00000108UL:
1345 case CKA_SIGN_RECOVER0x00000109UL:
1346 case CKA_UNWRAP0x00000107UL:
1347 case CKA_EXTRACTABLE0x00000162UL:
1348 case CKA_ALWAYS_SENSITIVE0x00000165UL:
1349 case CKA_NEVER_EXTRACTABLE0x00000164UL:
1350 case CKA_TRUSTED0x00000086UL:
1351 /* value CK_BBOOL */
1352 jValueObject = ckBBoolPtrToJBooleanObject(env, (CK_BBOOL*) ckpAttribute->pValue);
1353 break;
1354
1355 case CKA_LABEL0x00000003UL:
1356 case CKA_APPLICATION0x00000010UL:
1357 /* value RFC 2279 (UTF-8) string */
1358 jValueObject = ckUTF8CharArrayToJCharArray(env, (CK_UTF8CHAR*) ckpAttribute->pValue, jValueLength);
1359 break;
1360
1361 case CKA_START_DATE0x00000110UL:
1362 case CKA_END_DATE0x00000111UL:
1363 /* value CK_DATE */
1364 jValueObject = ckDatePtrToJDateObject(env, (CK_DATE*) ckpAttribute->pValue);
1365 break;
1366
1367 case CKA_MODULUS0x00000120UL:
1368 case CKA_PUBLIC_EXPONENT0x00000122UL:
1369 case CKA_PRIME0x00000130UL:
1370 case CKA_SUBPRIME0x00000131UL:
1371 case CKA_BASE0x00000132UL:
1372 /* value big integer, i.e. CK_BYTE[] */
1373 jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
1374 break;
1375
1376 case CKA_AUTH_PIN_FLAGS0x00000201UL:
1377 jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
1378 /* value FLAGS, defacto a CK_ULONG */
1379 break;
1380
1381 case CKA_VENDOR_DEFINED0x80000000UL:
1382 /* we make a CK_BYTE[] out of this */
1383 jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
1384 break;
1385
1386 // Netscape trust attributes
1387 case CKA_NETSCAPE_TRUST_SERVER_AUTH(((0x80000000 + 0x4E534350) + 0x2000) + 8):
1388 case CKA_NETSCAPE_TRUST_CLIENT_AUTH(((0x80000000 + 0x4E534350) + 0x2000) + 9):
1389 case CKA_NETSCAPE_TRUST_CODE_SIGNING(((0x80000000 + 0x4E534350) + 0x2000) + 10):
1390 case CKA_NETSCAPE_TRUST_EMAIL_PROTECTION(((0x80000000 + 0x4E534350) + 0x2000) + 11):
1391 /* value CK_ULONG */
1392 jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue);
1393 break;
1394
1395 default:
1396 /* we make a CK_BYTE[] out of this */
1397 jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength);
1398 break;
1399 }
1400
1401 return jValueObject ;
1402}
1403
1404/*
1405 * the following functions convert a Java mechanism parameter object to a PKCS#11
1406 * mechanism parameter structure
1407 *
1408 * CK_<Param>_PARAMS j<Param>ParamToCK<Param>Param(JNIEnv *env,
1409 * jobject jParam);
1410 *
1411 * These functions get a Java object, that must be the right Java mechanism
1412 * object and they return the new PKCS#11 mechanism parameter structure.
1413 * Every field of the Java object is retrieved, gets converted to a corresponding
1414 * PKCS#11 type and is set in the new PKCS#11 structure.
1415 */
1416
1417/*
1418 * converts the given Java mechanism parameter to a CK mechanism parameter
1419 * pointer and store the length in bytes in the length variable.
1420 *
1421 * @param env - used to call JNI funktions to get the Java classes and objects
1422 * @param jParam - the Java mechanism parameter object to convert
1423 * @param ckMech - the PKCS#11 mechanism type
1424 * @param ckpLength - the reference of the length in bytes of the new CK mechanism parameter
1425 * structure
1426 * @return pointer to the new CK mechanism parameter structure
1427 */
1428CK_VOID_PTR jMechParamToCKMechParamPtr(JNIEnv *env, jobject jParam,
1429 CK_MECHANISM_TYPE ckMech, CK_ULONG *ckpLength)
1430{
1431 CK_VOID_PTR ckpParamPtr;
1432 if (jParam
5.1
'jParam' is not equal to NULL
== NULL((void*)0)) {
6
Taking false branch
1433 ckpParamPtr = NULL((void*)0);
1434 *ckpLength = 0;
1435 } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) {
7
Assuming the condition is false
8
Taking false branch
1436 jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *) &ckpParamPtr, ckpLength);
1437 } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) {
9
Assuming the condition is false
10
Taking false branch
1438 ckpParamPtr = jLongObjectToCKULongPtr(env, jParam);
1439 *ckpLength = sizeof(CK_ULONG);
1440 } else {
1441 ckpParamPtr = jMechParamToCKMechParamPtrSlow(env, jParam, ckMech, ckpLength);
11
Calling 'jMechParamToCKMechParamPtrSlow'
1442 }
1443 return ckpParamPtr;
1444}
1445
1446CK_VOID_PTR jMechParamToCKMechParamPtrSlow(JNIEnv *env, jobject jParam,
1447 CK_MECHANISM_TYPE ckMech, CK_ULONG *ckpLength)
1448{
1449 CK_VOID_PTR ckpParamPtr = NULL((void*)0);
1450
1451 /*
1452 * Most common cases, i.e. NULL/byte[]/long, are already handled by
1453 * jMechParamToCKMechParam before calling this method.
1454 */
1455 TRACE1("\nDEBUG: jMechParamToCKMechParamPtrSlow, mech=0x%lX\n", ckMech);
1456
1457 switch (ckMech) {
12
Control jumps to 'case 887:' at line 1470
1458 case CKM_SSL3_PRE_MASTER_KEY_GEN0x00000370UL:
1459 case CKM_TLS_PRE_MASTER_KEY_GEN0x00000374UL:
1460 ckpParamPtr = jVersionToCKVersionPtr(env, jParam);
1461 if (ckpParamPtr != NULL((void*)0)) {
1462 *ckpLength = sizeof(CK_VERSION);
1463 } else {
1464 *ckpLength = 0;
1465 }
1466 break;
1467 case CKM_SSL3_MASTER_KEY_DERIVE0x00000371UL:
1468 case CKM_TLS_MASTER_KEY_DERIVE0x00000375UL:
1469 case CKM_SSL3_MASTER_KEY_DERIVE_DH0x00000373UL:
1470 case CKM_TLS_MASTER_KEY_DERIVE_DH0x00000377UL:
1471 ckpParamPtr = jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr(env, jParam,
13
Calling 'jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr'
23
Returned allocated memory
1472 ckpLength);
1473 break;
24
Execution continues on line 1567
1474 case CKM_SSL3_KEY_AND_MAC_DERIVE0x00000372UL:
1475 case CKM_TLS_KEY_AND_MAC_DERIVE0x00000376UL:
1476 ckpParamPtr = jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(env, jParam,
1477 ckpLength);
1478 break;
1479 case CKM_TLS12_KEY_AND_MAC_DERIVE0x000003E1UL:
1480 ckpParamPtr = jTls12KeyMatParamToCKTls12KeyMatParamPtr(env, jParam,
1481 ckpLength);
1482 break;
1483 case CKM_TLS12_MASTER_KEY_DERIVE0x000003E0UL:
1484 case CKM_TLS12_MASTER_KEY_DERIVE_DH0x000003E2UL:
1485 ckpParamPtr = jTls12MasterKeyDeriveParamToCKTls12MasterKeyDeriveParamPtr(env, jParam,
1486 ckpLength);
1487 break;
1488 case CKM_TLS_PRF0x00000378UL:
1489 case CKM_NSS_TLS_PRF_GENERAL0x80000373:
1490 ckpParamPtr = jTlsPrfParamsToCKTlsPrfParamPtr(env, jParam,
1491 ckpLength);
1492 break;
1493 case CKM_TLS_MAC0x000003E4UL:
1494 ckpParamPtr = jTlsMacParamsToCKTlsMacParamPtr(env, jParam,
1495 ckpLength);
1496 break;
1497 case CKM_AES_CTR0x00001086UL:
1498 ckpParamPtr = jAesCtrParamsToCKAesCtrParamPtr(env, jParam,
1499 ckpLength);
1500 break;
1501 case CKM_AES_GCM0x00001087UL:
1502 ckpParamPtr = jGCMParamsToCKGCMParamPtr(env, jParam, ckpLength);
1503 break;
1504 case CKM_AES_CCM0x00001088UL:
1505 ckpParamPtr = jCCMParamsToCKCCMParamPtr(env, jParam, ckpLength);
1506 break;
1507 case CKM_CHACHA20_POLY13050x00004021UL:
1508 ckpParamPtr =
1509 jSalsaChaChaPolyParamsToCKSalsaChaChaPolyParamPtr(env,
1510 jParam, ckpLength);
1511 break;
1512 case CKM_RSA_PKCS_OAEP0x00000009UL:
1513 ckpParamPtr = jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(env, jParam, ckpLength);
1514 break;
1515 case CKM_PBE_SHA1_DES3_EDE_CBC0x000003A8UL:
1516 case CKM_PBE_SHA1_DES2_EDE_CBC0x000003A9UL:
1517 case CKM_PBA_SHA1_WITH_SHA1_HMAC0x000003C0UL:
1518 ckpParamPtr = jPbeParamToCKPbeParamPtr(env, jParam, ckpLength);
1519 break;
1520 case CKM_PKCS5_PBKD20x000003B0UL:
1521 ckpParamPtr = jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(env, jParam, ckpLength);
1522 break;
1523 case CKM_RSA_PKCS_PSS0x0000000DUL:
1524 case CKM_SHA1_RSA_PKCS_PSS0x0000000EUL:
1525 case CKM_SHA256_RSA_PKCS_PSS0x00000043UL:
1526 case CKM_SHA384_RSA_PKCS_PSS0x00000044UL:
1527 case CKM_SHA512_RSA_PKCS_PSS0x00000045UL:
1528 case CKM_SHA224_RSA_PKCS_PSS0x00000047UL:
1529 ckpParamPtr = jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(env, jParam, ckpLength);
1530 break;
1531 case CKM_ECDH1_DERIVE0x00001050UL:
1532 case CKM_ECDH1_COFACTOR_DERIVE0x00001051UL:
1533 ckpParamPtr = jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(env, jParam, ckpLength);
1534 break;
1535 case CKM_ECMQV_DERIVE0x00001052UL:
1536 ckpParamPtr = jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(env, jParam, ckpLength);
1537 break;
1538 case CKM_X9_42_DH_DERIVE0x00000031UL:
1539 ckpParamPtr = jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(env, jParam, ckpLength);
1540 break;
1541 case CKM_X9_42_DH_HYBRID_DERIVE0x00000032UL:
1542 case CKM_X9_42_MQV_DERIVE0x00000033UL:
1543 ckpParamPtr = jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(env, jParam, ckpLength);
1544 break;
1545 // defined by pkcs11.h but we don't support
1546 case CKM_KEA_DERIVE0x00001012UL: // CK_KEA_DERIVE_PARAMS
1547 case CKM_RC2_CBC0x00000102UL: // CK_RC2_CBC_PARAMS
1548 case CKM_RC2_MAC_GENERAL0x00000104UL: // CK_RC2_MAC_GENERAL_PARAMS
1549 case CKM_RC5_ECB0x00000331UL: // CK_RC5_PARAMS
1550 case CKM_RC5_MAC0x00000333UL: // CK_RC5_PARAMS
1551 case CKM_RC5_CBC0x00000332UL: // CK_RC5_CBC_PARAMS
1552 case CKM_RC5_MAC_GENERAL0x00000334UL: // CK_RC5_MAC_GENERAL_PARAMS
1553 case CKM_SKIPJACK_PRIVATE_WRAP0x00001009UL: // CK_SKIPJACK_PRIVATE_WRAP_PARAMS
1554 case CKM_SKIPJACK_RELAYX0x0000100aUL: // CK_SKIPJACK_RELAYX_PARAMS
1555 case CKM_KEY_WRAP_SET_OAEP0x00000401UL: // CK_KEY_WRAP_SET_OAEP_PARAMS
1556 throwPKCS11RuntimeException(env, "No parameter support for this mchanism");
1557 break;
1558 default:
1559 /* if everything faild up to here */
1560 /* try if the parameter is a primitive Java type */
1561 ckpParamPtr = jObjectToPrimitiveCKObjectPtr(env, jParam, ckpLength);
1562 /* *ckpParamPtr = jObjectToCKVoidPtr(jParam); */
1563 /* *ckpLength = 1; */
1564 }
1565 TRACE0("\nDEBUG: jMechParamToCKMechParamPtrSlow FINISHED\n");
1566
1567 if ((*env)->ExceptionCheck(env)) {
25
Assuming the condition is true
26
Taking true branch
1568 return NULL((void*)0);
27
Potential leak of memory pointed to by 'ckpParamPtr'
1569 }
1570
1571 return ckpParamPtr;
1572}
1573
1574/*
1575 * converts the Java CK_RSA_PKCS_OAEP_PARAMS object to a
1576 * CK_RSA_PKCS_OAEP_PARAMS pointer
1577 *
1578 * @param env - used to call JNI funktions to get the Java classes and objects
1579 * @param jParam - the Java CK_RSA_PKCS_OAEP_PARAMS object to convert
1580 * @param pLength - length of the allocated memory of the returned pointer
1581 * @return pointer to the new CK_RSA_PKCS_OAEP_PARAMS structure
1582 */
1583CK_RSA_PKCS_OAEP_PARAMS_PTR
1584jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1585{
1586 CK_RSA_PKCS_OAEP_PARAMS_PTR ckParamPtr;
1587 jclass jRsaPkcsOaepParamsClass;
1588 jfieldID fieldID;
1589 jlong jHashAlg, jMgf, jSource;
1590 jobject jSourceData;
1591
1592 if (pLength!= NULL((void*)0)) {
1593 *pLength = 0L;
1594 }
1595
1596 // retrieve java values
1597 jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS"sun/security/pkcs11/wrapper/CK_RSA_PKCS_OAEP_PARAMS");
1598 if (jRsaPkcsOaepParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1599 fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "hashAlg", "J");
1600 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1601 jHashAlg = (*env)->GetLongField(env, jParam, fieldID);
1602 fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "mgf", "J");
1603 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1604 jMgf = (*env)->GetLongField(env, jParam, fieldID);
1605 fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "source", "J");
1606 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1607 jSource = (*env)->GetLongField(env, jParam, fieldID);
1608 fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "pSourceData", "[B");
1609 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1610 jSourceData = (*env)->GetObjectField(env, jParam, fieldID);
1611
1612 // allocate memory for CK_RSA_PKCS_OAEP_PARAMS pointer
1613 ckParamPtr = calloc(1, sizeof(CK_RSA_PKCS_OAEP_PARAMS));
1614 if (ckParamPtr == NULL((void*)0)) {
1615 throwOutOfMemoryError(env, 0);
1616 return NULL((void*)0);
1617 }
1618
1619 // populate using java values
1620 ckParamPtr->hashAlg = jLongToCKULong(jHashAlg)((CK_ULONG) jHashAlg);
1621 ckParamPtr->mgf = jLongToCKULong(jMgf)((CK_ULONG) jMgf);
1622 ckParamPtr->source = jLongToCKULong(jSource)((CK_ULONG) jSource);
1623 jByteArrayToCKByteArray(env, jSourceData, (CK_BYTE_PTR*) &(ckParamPtr->pSourceData),
1624 &(ckParamPtr->ulSourceDataLen));
1625 if ((*env)->ExceptionCheck(env)) {
1626 free(ckParamPtr);
1627 return NULL((void*)0);
1628 }
1629
1630 if (pLength!= NULL((void*)0)) {
1631 *pLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS);
1632 }
1633 return ckParamPtr;
1634}
1635
1636/*
1637 * converts the Java CK_PBE_PARAMS object to a CK_PBE_PARAMS pointer
1638 *
1639 * @param env - used to call JNI funktions to get the Java classes and objects
1640 * @param jParam - the Java CK_PBE_PARAMS object to convert
1641 * @param pLength - length of the allocated memory of the returned pointer
1642 * @return pointer to the new CK_PBE_PARAMS structure
1643 */
1644CK_PBE_PARAMS_PTR
1645jPbeParamToCKPbeParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1646{
1647 CK_PBE_PARAMS_PTR ckParamPtr;
1648 jclass jPbeParamsClass;
1649 jfieldID fieldID;
1650 jlong jIteration;
1651 jobject jInitVector, jPassword, jSalt;
1652 CK_ULONG ckTemp;
1653
1654 if (pLength != NULL((void*)0)) {
1655 *pLength = 0;
1656 }
1657
1658 // retrieve java values
1659 jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS"sun/security/pkcs11/wrapper/CK_PBE_PARAMS");
1660 if (jPbeParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1661 fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVector", "[C");
1662 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1663 jInitVector = (*env)->GetObjectField(env, jParam, fieldID);
1664 fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pPassword", "[C");
1665 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1666 jPassword = (*env)->GetObjectField(env, jParam, fieldID);
1667 fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pSalt", "[C");
1668 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1669 jSalt = (*env)->GetObjectField(env, jParam, fieldID);
1670 fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "ulIteration", "J");
1671 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1672 jIteration = (*env)->GetLongField(env, jParam, fieldID);
1673
1674 // allocate memory for CK_PBE_PARAMS pointer
1675 ckParamPtr = calloc(1, sizeof(CK_PBE_PARAMS));
1676 if (ckParamPtr == NULL((void*)0)) {
1677 throwOutOfMemoryError(env, 0);
1678 return NULL((void*)0);
1679 }
1680
1681 // populate using java values
1682 ckParamPtr->ulIteration = jLongToCKULong(jIteration)((CK_ULONG) jIteration);
1683 jCharArrayToCKCharArray(env, jInitVector, &(ckParamPtr->pInitVector), &ckTemp);
1684 if ((*env)->ExceptionCheck(env)) {
1685 goto cleanup;
1686 }
1687 jCharArrayToCKCharArray(env, jPassword, &(ckParamPtr->pPassword), &(ckParamPtr->ulPasswordLen));
1688 if ((*env)->ExceptionCheck(env)) {
1689 goto cleanup;
1690 }
1691 jCharArrayToCKCharArray(env, jSalt, &(ckParamPtr->pSalt), &(ckParamPtr->ulSaltLen));
1692 if ((*env)->ExceptionCheck(env)) {
1693 goto cleanup;
1694 }
1695
1696 if (pLength != NULL((void*)0)) {
1697 *pLength = sizeof(CK_PBE_PARAMS);
1698 }
1699 return ckParamPtr;
1700cleanup:
1701 free(ckParamPtr->pInitVector);
1702 free(ckParamPtr->pPassword);
1703 free(ckParamPtr->pSalt);
1704 free(ckParamPtr);
1705 return NULL((void*)0);
1706}
1707
1708/*
1709 * Copy back the initialization vector from the native structure to the
1710 * Java object. This is only used for CKM_PBE_* mechanisms and their
1711 * CK_PBE_PARAMS parameters.
1712 *
1713 */
1714void copyBackPBEInitializationVector(JNIEnv *env, CK_MECHANISM *ckMechanism, jobject jMechanism)
1715{
1716 jclass jMechanismClass, jPbeParamsClass;
1717 CK_PBE_PARAMS *ckParam;
1718 jfieldID fieldID;
1719 CK_MECHANISM_TYPE ckMechanismType;
1720 jlong jMechanismType;
1721 jobject jParameter;
1722 jobject jInitVector;
1723 jint jInitVectorLength;
1724 CK_CHAR_PTR initVector;
1725 int i;
1726 jchar* jInitVectorChars;
1727
1728 /* get mechanism */
1729 jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM"sun/security/pkcs11/wrapper/CK_MECHANISM");
1730 if (jMechanismClass == NULL((void*)0)) { return; }
1731 fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J");
1732 if (fieldID == NULL((void*)0)) { return; }
1733 jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID);
1734 ckMechanismType = jLongToCKULong(jMechanismType)((CK_ULONG) jMechanismType);
1735 if (ckMechanismType != ckMechanism->mechanism) {
1736 /* we do not have matching types, this should not occur */
1737 return;
1738 }
1739
1740 jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS"sun/security/pkcs11/wrapper/CK_PBE_PARAMS");
1741 if (jPbeParamsClass == NULL((void*)0)) { return; }
1742 ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter;
1743 if (ckParam != NULL_PTR0) {
1744 initVector = ckParam->pInitVector;
1745 if (initVector != NULL_PTR0) {
1746 /* get pParameter */
1747 fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;");
1748 if (fieldID == NULL((void*)0)) { return; }
1749 jParameter = (*env)->GetObjectField(env, jMechanism, fieldID);
1750 fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVektor", "[C");
1751 if (fieldID == NULL((void*)0)) { return; }
1752 jInitVector = (*env)->GetObjectField(env, jParameter, fieldID);
1753
1754 if (jInitVector != NULL((void*)0)) {
1755 jInitVectorLength = (*env)->GetArrayLength(env, jInitVector);
1756 jInitVectorChars = (*env)->GetCharArrayElements(env, jInitVector, NULL((void*)0));
1757 if (jInitVectorChars == NULL((void*)0)) { return; }
1758
1759 /* copy the chars to the Java buffer */
1760 for (i=0; i < jInitVectorLength; i++) {
1761 jInitVectorChars[i] = ckCharToJChar(initVector[i])((jchar) initVector[i]);
1762 }
1763 /* copy back the Java buffer to the object */
1764 (*env)->ReleaseCharArrayElements(env, jInitVector, jInitVectorChars, 0);
1765 }
1766 }
1767 }
1768}
1769
1770/*
1771 * converts the Java CK_PKCS5_PBKD2_PARAMS object to a CK_PKCS5_PBKD2_PARAMS
1772 * pointer
1773 *
1774 * @param env - used to call JNI funktions to get the Java classes and objects
1775 * @param jParam - the Java CK_PKCS5_PBKD2_PARAMS object to convert
1776 * @param pLength - length of the allocated memory of the returned pointer
1777 * @return pointer to the new CK_PKCS5_PBKD2_PARAMS structure
1778 */
1779CK_PKCS5_PBKD2_PARAMS_PTR
1780jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1781{
1782 CK_PKCS5_PBKD2_PARAMS_PTR ckParamPtr;
1783 jclass jPkcs5Pbkd2ParamsClass;
1784 jfieldID fieldID;
1785 jlong jSaltSource, jIteration, jPrf;
1786 jobject jSaltSourceData, jPrfData;
1787
1788 if (pLength != NULL((void*)0)) {
1789 *pLength = 0L;
1790 }
1791
1792 // retrieve java values
1793 jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS"sun/security/pkcs11/wrapper/CK_PKCS5_PBKD2_PARAMS");
1794 if (jPkcs5Pbkd2ParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1795 fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "saltSource", "J");
1796 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1797 jSaltSource = (*env)->GetLongField(env, jParam, fieldID);
1798 fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pSaltSourceData", "[B");
1799 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1800 jSaltSourceData = (*env)->GetObjectField(env, jParam, fieldID);
1801 fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "iterations", "J");
1802 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1803 jIteration = (*env)->GetLongField(env, jParam, fieldID);
1804 fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "prf", "J");
1805 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1806 jPrf = (*env)->GetLongField(env, jParam, fieldID);
1807 fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pPrfData", "[B");
1808 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1809 jPrfData = (*env)->GetObjectField(env, jParam, fieldID);
1810
1811 // allocate memory for CK_PKCS5_PBKD2_PARAMS pointer
1812 ckParamPtr = calloc(1, sizeof(CK_PKCS5_PBKD2_PARAMS));
1813 if (ckParamPtr == NULL((void*)0)) {
1814 throwOutOfMemoryError(env, 0);
1815 return NULL((void*)0);
1816 }
1817
1818 // populate using java values
1819 ckParamPtr->saltSource = jLongToCKULong(jSaltSource)((CK_ULONG) jSaltSource);
1820 jByteArrayToCKByteArray(env, jSaltSourceData, (CK_BYTE_PTR *)
1821 &(ckParamPtr->pSaltSourceData), &(ckParamPtr->ulSaltSourceDataLen));
1822 if ((*env)->ExceptionCheck(env)) {
1823 goto cleanup;
1824 }
1825 ckParamPtr->iterations = jLongToCKULong(jIteration)((CK_ULONG) jIteration);
1826 ckParamPtr->prf = jLongToCKULong(jPrf)((CK_ULONG) jPrf);
1827 jByteArrayToCKByteArray(env, jPrfData, (CK_BYTE_PTR *)
1828 &(ckParamPtr->pPrfData), &(ckParamPtr->ulPrfDataLen));
1829 if ((*env)->ExceptionCheck(env)) {
1830 goto cleanup;
1831 }
1832
1833 if (pLength != NULL((void*)0)) {
1834 *pLength = sizeof(CK_PKCS5_PBKD2_PARAMS);
1835 }
1836 return ckParamPtr;
1837cleanup:
1838 free(ckParamPtr->pSaltSourceData);
1839 free(ckParamPtr->pPrfData);
1840 free(ckParamPtr);
1841 return NULL((void*)0);
1842
1843}
1844
1845/*
1846 * converts the Java CK_RSA_PKCS_PSS_PARAMS object to a CK_RSA_PKCS_PSS_PARAMS
1847 * pointer
1848 *
1849 * @param env - used to call JNI funktions to get the Java classes and objects
1850 * @param jParam - the Java CK_RSA_PKCS_PSS_PARAMS object to convert
1851 * @param pLength - length of the allocated memory of the returned pointer
1852 * @return pointer to the new CK_RSA_PKCS_PSS_PARAMS structure
1853 */
1854CK_RSA_PKCS_PSS_PARAMS_PTR
1855jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1856{
1857 CK_RSA_PKCS_PSS_PARAMS_PTR ckParamPtr;
1858 jclass jRsaPkcsPssParamsClass;
1859 jfieldID fieldID;
1860 jlong jHashAlg, jMgf, jSLen;
1861
1862 if (pLength != NULL((void*)0)) {
1863 *pLength = 0;
1864 }
1865
1866 // retrieve java values
1867 jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS"sun/security/pkcs11/wrapper/CK_RSA_PKCS_PSS_PARAMS");
1868 if (jRsaPkcsPssParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1869 fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "hashAlg", "J");
1870 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1871 jHashAlg = (*env)->GetLongField(env, jParam, fieldID);
1872 fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "mgf", "J");
1873 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1874 jMgf = (*env)->GetLongField(env, jParam, fieldID);
1875 fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "sLen", "J");
1876 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1877 jSLen = (*env)->GetLongField(env, jParam, fieldID);
1878
1879 // allocate memory for CK_RSA_PKCS_PSS_PARAMS pointer
1880 ckParamPtr = calloc(1, sizeof(CK_RSA_PKCS_PSS_PARAMS));
1881 if (ckParamPtr == NULL((void*)0)) {
1882 throwOutOfMemoryError(env, 0);
1883 return NULL((void*)0);
1884 }
1885
1886 // populate using java values
1887 ckParamPtr->hashAlg = jLongToCKULong(jHashAlg)((CK_ULONG) jHashAlg);
1888 ckParamPtr->mgf = jLongToCKULong(jMgf)((CK_ULONG) jMgf);
1889 ckParamPtr->sLen = jLongToCKULong(jSLen)((CK_ULONG) jSLen);
1890 TRACE1("DEBUG: jRsaPkcsPssParamToCKRsaPkcsPssParam, hashAlg=0x%lX\n", ckParamPtr->hashAlg);
1891 TRACE1("DEBUG: jRsaPkcsPssParamToCKRsaPkcsPssParam, mgf=0x%lX\n", ckParamPtr->mgf);
1892 TRACE1("DEBUG: jRsaPkcsPssParamToCKRsaPkcsPssParam, sLen=%lu\n", ckParamPtr->sLen);
1893
1894 if (pLength != NULL((void*)0)) {
1895 *pLength = sizeof(CK_RSA_PKCS_PSS_PARAMS);
1896 }
1897 return ckParamPtr;
1898
1899}
1900
1901/*
1902 * converts the Java CK_ECDH1_DERIVE_PARAMS object to a CK_ECDH1_DERIVE_PARAMS
1903 * pointer
1904 *
1905 * @param env - used to call JNI funktions to get the Java classes and objects
1906 * @param jParam - the Java CK_ECDH1_DERIVE_PARAMS object to convert
1907 * @param pLength - length of the allocated memory of the returned pointer
1908 * @retur pointer to nthe new CK_ECDH1_DERIVE_PARAMS structure
1909 */
1910CK_ECDH1_DERIVE_PARAMS_PTR
1911jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1912{
1913 CK_ECDH1_DERIVE_PARAMS_PTR ckParamPtr;
1914 jclass jEcdh1DeriveParamsClass;
1915 jfieldID fieldID;
1916 jlong jLong;
1917 jobject jSharedData, jPublicData;
1918
1919 if (pLength != NULL((void*)0)) {
1920 *pLength = 0;
1921 }
1922
1923 // retrieve java values
1924 jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS"sun/security/pkcs11/wrapper/CK_ECDH1_DERIVE_PARAMS");
1925 if (jEcdh1DeriveParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1926 fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "kdf", "J");
1927 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1928 jLong = (*env)->GetLongField(env, jParam, fieldID);
1929 fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pSharedData", "[B");
1930 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1931 jSharedData = (*env)->GetObjectField(env, jParam, fieldID);
1932 fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pPublicData", "[B");
1933 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1934 jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
1935
1936 // allocate memory for CK_ECDH1_DERIVE_PARAMS pointer
1937 ckParamPtr = calloc(1, sizeof(CK_ECDH1_DERIVE_PARAMS));
1938 if (ckParamPtr == NULL((void*)0)) {
1939 throwOutOfMemoryError(env, 0);
1940 return NULL((void*)0);
1941 }
1942
1943 // populate using java values
1944 ckParamPtr->kdf = jLongToCKULong(jLong)((CK_ULONG) jLong);
1945 jByteArrayToCKByteArray(env, jSharedData, &(ckParamPtr->pSharedData),
1946 &(ckParamPtr->ulSharedDataLen));
1947 if ((*env)->ExceptionCheck(env)) {
1948 goto cleanup;
1949 }
1950 jByteArrayToCKByteArray(env, jPublicData, &(ckParamPtr->pPublicData),
1951 &(ckParamPtr->ulPublicDataLen));
1952 if ((*env)->ExceptionCheck(env)) {
1953 goto cleanup;
1954 }
1955
1956 if (pLength != NULL((void*)0)) {
1957 *pLength = sizeof(CK_ECDH1_DERIVE_PARAMS);
1958 }
1959 return ckParamPtr;
1960cleanup:
1961 free(ckParamPtr->pSharedData);
1962 free(ckParamPtr->pPublicData);
1963 free(ckParamPtr);
1964 return NULL((void*)0);
1965}
1966
1967/*
1968 * converts the Java CK_ECDH2_DERIVE_PARAMS object to a CK_ECDH2_DERIVE_PARAMS
1969 * pointer
1970 *
1971 * @param env - used to call JNI funktions to get the Java classes and objects
1972 * @param jParam - the Java CK_ECDH2_DERIVE_PARAMS object to convert
1973 * @param pLength - length of the allocated memory of the returned pointer
1974 * @return pointer to the new CK_ECDH2_DERIVE_PARAMS structure
1975 */
1976CK_ECDH2_DERIVE_PARAMS_PTR
1977jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
1978{
1979 CK_ECDH2_DERIVE_PARAMS_PTR ckParamPtr;
1980 jclass jEcdh2DeriveParamsClass;
1981 jfieldID fieldID;
1982 jlong jKdf, jPrivateDataLen, jPrivateData;
1983 jobject jSharedData, jPublicData, jPublicData2;
1984
1985 // retrieve java values
1986 jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS"sun/security/pkcs11/wrapper/CK_ECDH2_DERIVE_PARAMS");
1987 if (jEcdh2DeriveParamsClass == NULL((void*)0)) { return NULL((void*)0); }
1988 fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "kdf", "J");
1989 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1990 jKdf = (*env)->GetLongField(env, jParam, fieldID);
1991 fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pSharedData", "[B");
1992 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1993 jSharedData = (*env)->GetObjectField(env, jParam, fieldID);
1994 fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData", "[B");
1995 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1996 jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
1997 fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "ulPrivateDataLen", "J");
1998 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
1999 jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID);
2000 fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "hPrivateData", "J");
2001 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2002 jPrivateData = (*env)->GetLongField(env, jParam, fieldID);
2003 fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData2", "[B");
2004 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2005 jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID);
2006
2007 // allocate memory for CK_ECDH2_DERIVE_PARAMS pointer
2008 ckParamPtr = calloc(1, sizeof(CK_ECDH2_DERIVE_PARAMS));
2009 if (ckParamPtr == NULL((void*)0)) {
2010 throwOutOfMemoryError(env, 0);
2011 return NULL((void*)0);
2012 }
2013
2014 // populate using java values
2015 ckParamPtr->kdf = jLongToCKULong(jKdf)((CK_ULONG) jKdf);
2016 jByteArrayToCKByteArray(env, jSharedData, &(ckParamPtr->pSharedData),
2017 &(ckParamPtr->ulSharedDataLen));
2018 if ((*env)->ExceptionCheck(env)) {
2019 goto cleanup;
2020 }
2021 jByteArrayToCKByteArray(env, jPublicData, &(ckParamPtr->pPublicData),
2022 &(ckParamPtr->ulPublicDataLen));
2023 if ((*env)->ExceptionCheck(env)) {
2024 goto cleanup;
2025 }
2026 ckParamPtr->ulPrivateDataLen = jLongToCKULong(jPrivateDataLen)((CK_ULONG) jPrivateDataLen);
2027 ckParamPtr->hPrivateData = jLongToCKULong(jPrivateData)((CK_ULONG) jPrivateData);
2028 jByteArrayToCKByteArray(env, jPublicData2, &(ckParamPtr->pPublicData2),
2029 &(ckParamPtr->ulPublicDataLen2));
2030 if ((*env)->ExceptionCheck(env)) {
2031 goto cleanup;
2032 }
2033
2034 if (pLength != NULL((void*)0)) {
2035 *pLength = sizeof(CK_ECDH2_DERIVE_PARAMS);
2036 }
2037 return ckParamPtr;
2038cleanup:
2039 free(ckParamPtr->pSharedData);
2040 free(ckParamPtr->pPublicData);
2041 free(ckParamPtr->pPublicData2);
2042 free(ckParamPtr);
2043 return NULL((void*)0);
2044}
2045
2046/*
2047 * converts the Java CK_X9_42_DH1_DERIVE_PARAMS object to a
2048 * CK_X9_42_DH1_DERIVE_PARAMS pointer
2049 *
2050 * @param env - used to call JNI funktions to get the Java classes and objects
2051 * @param jParam - the Java CK_X9_42_DH1_DERIVE_PARAMS object to convert
2052 * @param pLength - length of the allocated memory of the returned pointer
2053 * @return pointer to the new CK_X9_42_DH1_DERIVE_PARAMS structure
2054 */
2055CK_X9_42_DH1_DERIVE_PARAMS_PTR
2056jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
2057{
2058 CK_X9_42_DH1_DERIVE_PARAMS_PTR ckParamPtr;
2059 jclass jX942Dh1DeriveParamsClass;
2060 jfieldID fieldID;
2061 jlong jKdf;
2062 jobject jOtherInfo, jPublicData;
2063
2064 if (pLength != NULL((void*)0)) {
2065 *pLength = 0;
2066 }
2067
2068 // retrieve java values
2069 jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS"sun/security/pkcs11/wrapper/CK_X9_42_DH1_DERIVE_PARAMS");
2070 if (jX942Dh1DeriveParamsClass == NULL((void*)0)) { return NULL((void*)0); }
2071 fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "kdf", "J");
2072 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2073 jKdf = (*env)->GetLongField(env, jParam, fieldID);
2074 fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pOtherInfo", "[B");
2075 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2076 jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID);
2077 fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pPublicData", "[B");
2078 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2079 jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
2080
2081 // allocate memory for CK_X9_42_DH1_DERIVE_PARAMS pointer
2082 ckParamPtr = calloc(1, sizeof(CK_X9_42_DH1_DERIVE_PARAMS));
2083 if (ckParamPtr == NULL((void*)0)) {
2084 throwOutOfMemoryError(env, 0);
2085 return NULL((void*)0);
2086 }
2087
2088 // populate using java values
2089 ckParamPtr->kdf = jLongToCKULong(jKdf)((CK_ULONG) jKdf);
2090 jByteArrayToCKByteArray(env, jOtherInfo, &(ckParamPtr->pOtherInfo),
2091 &(ckParamPtr->ulOtherInfoLen));
2092 if ((*env)->ExceptionCheck(env)) {
2093 goto cleanup;
2094 }
2095 jByteArrayToCKByteArray(env, jPublicData, &(ckParamPtr->pPublicData),
2096 &(ckParamPtr->ulPublicDataLen));
2097 if ((*env)->ExceptionCheck(env)) {
2098 goto cleanup;
2099 }
2100
2101 if (pLength != NULL((void*)0)) {
2102 *pLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS);
2103 }
2104 return ckParamPtr;
2105cleanup:
2106 free(ckParamPtr->pOtherInfo);
2107 free(ckParamPtr->pPublicData);
2108 free(ckParamPtr);
2109 return NULL((void*)0);
2110}
2111
2112/*
2113 * converts the Java CK_X9_42_DH2_DERIVE_PARAMS object to a
2114 * CK_X9_42_DH2_DERIVE_PARAMS pointer
2115 *
2116 * @param env - used to call JNI funktions to get the Java classes and objects
2117 * @param jParam - the Java CK_X9_42_DH2_DERIVE_PARAMS object to convert
2118 * @param pLength - length of the allocated memory of the returned pointer
2119 * @return pointer to the new CK_X9_42_DH2_DERIVE_PARAMS structure
2120 */
2121CK_X9_42_DH2_DERIVE_PARAMS_PTR
2122jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength)
2123{
2124 CK_X9_42_DH2_DERIVE_PARAMS_PTR ckParamPtr;
2125 jclass jX942Dh2DeriveParamsClass;
2126 jfieldID fieldID;
2127 jlong jKdf, jPrivateDataLen, jPrivateData;
2128 jobject jOtherInfo, jPublicData, jPublicData2;
2129
2130 if (pLength != NULL((void*)0)) {
2131 *pLength = 0L;
2132 }
2133
2134 // retrieve java values
2135 jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS"sun/security/pkcs11/wrapper/CK_X9_42_DH2_DERIVE_PARAMS");
2136 if (jX942Dh2DeriveParamsClass == NULL((void*)0)) { return NULL((void*)0); }
2137 fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "kdf", "J");
2138 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2139 jKdf = (*env)->GetLongField(env, jParam, fieldID);
2140 fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pOtherInfo", "[B");
2141 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2142 jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID);
2143 fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData", "[B");
2144 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2145 jPublicData = (*env)->GetObjectField(env, jParam, fieldID);
2146 fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "ulPrivateDataLen", "J");
2147 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2148 jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID);
2149 fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "hPrivateData", "J");
2150 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2151 jPrivateData = (*env)->GetLongField(env, jParam, fieldID);
2152 fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData2", "[B");
2153 if (fieldID == NULL((void*)0)) { return NULL((void*)0); }
2154 jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID);
2155
2156 // allocate memory for CK_DATE pointer
2157 ckParamPtr = calloc(1, sizeof(CK_X9_42_DH2_DERIVE_PARAMS));
2158 if (ckParamPtr == NULL((void*)0)) {
2159 throwOutOfMemoryError(env, 0);
2160 return NULL((void*)0);
2161 }
2162
2163 // populate using java values
2164 ckParamPtr->kdf = jLongToCKULong(jKdf)((CK_ULONG) jKdf);
2165 jByteArrayToCKByteArray(env, jOtherInfo, &(ckParamPtr->pOtherInfo),
2166 &(ckParamPtr->ulOtherInfoLen));
2167 if ((*env)->ExceptionCheck(env)) {
2168 goto cleanup;
2169 }
2170 jByteArrayToCKByteArray(env, jPublicData, &(ckParamPtr->pPublicData),
2171 &(ckParamPtr->ulPublicDataLen));
2172 if ((*env)->ExceptionCheck(env)) {
2173 goto cleanup;
2174 }
2175 ckParamPtr->ulPrivateDataLen = jLongToCKULong(jPrivateDataLen)((CK_ULONG) jPrivateDataLen);
2176 ckParamPtr->hPrivateData = jLongToCKULong(jPrivateData)((CK_ULONG) jPrivateData);
2177 jByteArrayToCKByteArray(env, jPublicData2, &(ckParamPtr->pPublicData2),
2178 &(ckParamPtr->ulPublicDataLen2));
2179 if ((*env)->ExceptionCheck(env)) {
2180 goto cleanup;
2181 }
2182
2183 if (pLength != NULL((void*)0)) {
2184 *pLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS);
2185 }
2186 return ckParamPtr;
2187cleanup:
2188 free(ckParamPtr->pOtherInfo);
2189 free(ckParamPtr->pPublicData);
2190 free(ckParamPtr->pPublicData2);
2191 free(ckParamPtr);
2192 return NULL((void*)0);
2193}