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 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
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 | |
70 | |
71 | CK_VOID_PTR jMechParamToCKMechParamPtrSlow(JNIEnv *env, jobject jParam, |
72 | CK_MECHANISM_TYPE ckMech, CK_ULONG *ckpLength); |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | jobject 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 | |
92 | jDateClass = (*env)->FindClass(env, CLASS_DATE); |
93 | if (jDateClass == NULL) { return NULL; } |
94 | |
95 | |
96 | jCtrId = (*env)->GetMethodID(env, jDateClass, "<init>", "([C[C[C)V"); |
97 | if (jCtrId == NULL) { return NULL; } |
98 | |
99 | |
100 | jYear = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->year), 4); |
101 | if (jYear == NULL) { return NULL; } |
102 | jMonth = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->month), 2); |
103 | if (jMonth == NULL) { return NULL; } |
104 | jDay = ckCharArrayToJCharArray(env, (CK_CHAR_PTR)(ckpDate->day), 2); |
105 | if (jDay == NULL) { return NULL; } |
106 | |
107 | |
108 | jDateObject = |
109 | (*env)->NewObject(env, jDateClass, jCtrId, jYear, jMonth, jDay); |
110 | if (jDateObject == NULL) { return NULL; } |
111 | |
112 | |
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 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | jobject 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 | |
137 | jVersionClass = (*env)->FindClass(env, CLASS_VERSION); |
138 | if (jVersionClass == NULL) { return NULL; } |
139 | |
140 | |
141 | jCtrId = (*env)->GetMethodID(env, jVersionClass, "<init>", "(II)V"); |
142 | if (jCtrId == NULL) { return NULL; } |
143 | |
144 | |
145 | jMajor = ckpVersion->major; |
146 | jMinor = ckpVersion->minor; |
147 | |
148 | |
149 | jVersionObject = |
150 | (*env)->NewObject(env, jVersionClass, jCtrId, jMajor, jMinor); |
151 | if (jVersionObject == NULL) { return NULL; } |
152 | |
153 | |
154 | (*env)->DeleteLocalRef(env, jVersionClass); |
155 | |
156 | return jVersionObject ; |
157 | } |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | jobject 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 | |
177 | jSessionInfoClass = (*env)->FindClass(env, CLASS_SESSION_INFO); |
178 | if (jSessionInfoClass == NULL) { return NULL; } |
179 | |
180 | |
181 | jCtrId = (*env)->GetMethodID(env, jSessionInfoClass, "<init>", "(JJJJ)V"); |
182 | if (jCtrId == NULL) { return NULL; } |
183 | |
184 | |
185 | jSlotID = ckULongToJLong(ckpSessionInfo->slotID); |
186 | jState = ckULongToJLong(ckpSessionInfo->state); |
187 | jFlags = ckULongToJLong(ckpSessionInfo->flags); |
188 | jDeviceError = ckULongToJLong(ckpSessionInfo->ulDeviceError); |
189 | |
190 | |
191 | jSessionInfoObject = |
192 | (*env)->NewObject(env, jSessionInfoClass, jCtrId, jSlotID, jState, |
193 | jFlags, jDeviceError); |
194 | if (jSessionInfoObject == NULL) { return NULL; } |
195 | |
196 | |
197 | (*env)->DeleteLocalRef(env, jSessionInfoClass); |
198 | |
199 | return jSessionInfoObject ; |
200 | } |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | jobject 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; |
216 | |
217 | jAttributeClass = (*env)->FindClass(env, CLASS_ATTRIBUTE); |
218 | if (jAttributeClass == NULL) { return NULL; } |
219 | |
220 | |
221 | jCtrId = (*env)->GetMethodID(env, jAttributeClass, "<init>", "(JLjava/lang/Object;)V"); |
222 | if (jCtrId == NULL) { return NULL; } |
223 | |
224 | |
225 | jType = ckULongToJLong(ckpAttribute->type); |
226 | jPValue = ckAttributeValueToJObject(env, ckpAttribute); |
227 | if ((*env)->ExceptionCheck(env)) { return NULL; } |
228 | |
229 | |
230 | jAttributeObject = |
231 | (*env)->NewObject(env, jAttributeClass, jCtrId, jType, jPValue); |
232 | if (jAttributeObject == NULL) { return NULL; } |
233 | |
234 | |
235 | (*env)->DeleteLocalRef(env, jAttributeClass); |
236 | (*env)->DeleteLocalRef(env, jPValue); |
237 | |
238 | return jAttributeObject; |
239 | } |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | |
249 | CK_VERSION_PTR |
250 | jVersionToCKVersionPtr(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) { |
258 | return NULL; |
259 | } |
260 | |
261 | |
262 | jVersionClass = (*env)->GetObjectClass(env, jVersion); |
263 | if (jVersionClass == NULL) { return NULL; } |
264 | jFieldID = (*env)->GetFieldID(env, jVersionClass, "major", "B"); |
265 | if (jFieldID == NULL) { return NULL; } |
266 | jMajor = (*env)->GetByteField(env, jVersion, jFieldID); |
267 | jFieldID = (*env)->GetFieldID(env, jVersionClass, "minor", "B"); |
268 | if (jFieldID == NULL) { return NULL; } |
269 | jMinor = (*env)->GetByteField(env, jVersion, jFieldID); |
270 | |
271 | |
272 | ckpVersion = (CK_VERSION_PTR) calloc(1, sizeof(CK_VERSION)); |
273 | if (ckpVersion == NULL) { |
274 | throwOutOfMemoryError(env, 0); |
275 | return NULL; |
276 | } |
277 | |
278 | |
279 | ckpVersion->major = jByteToCKByte(jMajor); |
280 | ckpVersion->minor = jByteToCKByte(jMinor); |
281 | |
282 | return ckpVersion; |
283 | } |
284 | |
285 | |
286 | |
287 | |
288 | |
289 | |
290 | |
291 | |
292 | |
293 | CK_DATE * jDateObjectToCKDatePtr(JNIEnv *env, jobject jDate) |
294 | { |
295 | CK_DATE * ckpDate = NULL; |
296 | CK_ULONG ckLength; |
297 | jclass jDateClass; |
298 | jfieldID jFieldID; |
299 | jobject jYear, jMonth, jDay; |
300 | jchar *jTempChars = NULL; |
301 | CK_ULONG i; |
302 | |
303 | if (jDate == NULL) { |
304 | return NULL; |
305 | } |
306 | |
307 | |
308 | jDateClass = (*env)->FindClass(env, CLASS_DATE); |
309 | if (jDateClass == NULL) { return NULL; } |
310 | jFieldID = (*env)->GetFieldID(env, jDateClass, "year", "[C"); |
311 | if (jFieldID == NULL) { return NULL; } |
312 | jYear = (*env)->GetObjectField(env, jDate, jFieldID); |
313 | jFieldID = (*env)->GetFieldID(env, jDateClass, "month", "[C"); |
314 | if (jFieldID == NULL) { return NULL; } |
315 | jMonth = (*env)->GetObjectField(env, jDate, jFieldID); |
316 | jFieldID = (*env)->GetFieldID(env, jDateClass, "day", "[C"); |
317 | if (jFieldID == NULL) { return NULL; } |
318 | jDay = (*env)->GetObjectField(env, jDate, jFieldID); |
319 | |
320 | |
321 | ckpDate = (CK_DATE *) calloc(1, sizeof(CK_DATE)); |
322 | if (ckpDate == NULL) { |
323 | throwOutOfMemoryError(env, 0); |
324 | return NULL; |
325 | } |
326 | |
327 | |
328 | if (jYear == NULL) { |
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) { |
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]); |
347 | } |
348 | free(jTempChars); |
349 | } |
350 | |
351 | if (jMonth == NULL) { |
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) { |
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]); |
368 | } |
369 | free(jTempChars); |
370 | } |
371 | |
372 | if (jDay == NULL) { |
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) { |
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]); |
389 | } |
390 | free(jTempChars); |
391 | } |
392 | |
393 | return ckpDate; |
394 | cleanup: |
395 | free(jTempChars); |
396 | free(ckpDate); |
397 | return NULL; |
398 | } |
399 | |
400 | |
401 | |
402 | |
403 | |
404 | |
405 | |
406 | |
407 | |
408 | CK_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 | |
419 | TRACE0("\nDEBUG: jAttributeToCKAttribute"); |
420 | |
421 | |
422 | TRACE0(", getting attribute object class"); |
423 | jAttributeClass = (*env)->GetObjectClass(env, jAttribute); |
424 | if (jAttributeClass == NULL) { return ckAttribute; } |
425 | |
426 | |
427 | TRACE0(", getting type field"); |
428 | jFieldID = (*env)->GetFieldID(env, jAttributeClass, "type", "J"); |
429 | if (jFieldID == NULL) { return ckAttribute; } |
430 | jType = (*env)->GetLongField(env, jAttribute, jFieldID); |
431 | TRACE1(", type=0x%lX", jType); |
432 | |
433 | |
434 | TRACE0(", getting pValue field"); |
435 | jFieldID = (*env)->GetFieldID(env, jAttributeClass, "pValue", "Ljava/lang/Object;"); |
436 | if (jFieldID == NULL) { return ckAttribute; } |
437 | jPValue = (*env)->GetObjectField(env, jAttribute, jFieldID); |
438 | TRACE1(", pValue=%p", jPValue); |
439 | |
440 | ckAttribute.type = jLongToCKULong(jType); |
441 | TRACE0(", converting pValue to primitive object"); |
442 | |
443 | |
444 | ckAttribute.pValue = jObjectToPrimitiveCKObjectPtr(env, jPValue, &(ckAttribute.ulValueLen)); |
445 | |
446 | TRACE0("\nDEBUG: jAttributeToCKAttribute FINISHED\n"); |
447 | |
448 | return ckAttribute ; |
449 | } |
450 | |
451 | void 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 | |
460 | fieldID = (*env)->GetFieldID(env, masterKeyDeriveParamClass, "RandomInfo", |
461 | "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;"); |
462 | if (fieldID == NULL) { return; } |
463 | jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID); |
464 | jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA); |
465 | if (jSsl3RandomDataClass == NULL) { return; } |
466 | fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B"); |
467 | if (fieldID == NULL) { return; } |
468 | jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); |
469 | fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B"); |
470 | if (fieldID == NULL) { 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) { return; } |
475 | jVersion = (*env)->GetObjectField(env, jParam, fieldID); |
476 | |
477 | |
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; |
493 | cleanup: |
494 | free(*cKMasterKeyDeriveParamVersion); |
495 | free(cKMasterKeyDeriveParamRandomInfo->pClientRandom); |
496 | cKMasterKeyDeriveParamRandomInfo->ulClientRandomLen = 0L; |
497 | free(cKMasterKeyDeriveParamRandomInfo->pServerRandom); |
498 | cKMasterKeyDeriveParamRandomInfo->ulServerRandomLen = 0L; |
499 | |
500 | *cKMasterKeyDeriveParamVersion = NULL; |
501 | cKMasterKeyDeriveParamRandomInfo->pClientRandom = NULL; |
502 | cKMasterKeyDeriveParamRandomInfo->pServerRandom = NULL; |
503 | } |
504 | |
505 | |
506 | |
507 | |
508 | |
509 | |
510 | |
511 | |
512 | |
513 | |
514 | CK_SSL3_MASTER_KEY_DERIVE_PARAMS_PTR |
515 | jSsl3MasterKeyDeriveParamToCKSsl3MasterKeyDeriveParamPtr(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 != NULL) { |
| |
522 | *pLength = 0L; |
523 | } |
524 | |
525 | |
526 | ckParamPtr = calloc(1, sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS)); |
| |
527 | if (ckParamPtr == NULL) { |
| 16 | | Assuming 'ckParamPtr' is not equal to NULL | |
|
| |
528 | throwOutOfMemoryError(env, 0); |
529 | return NULL; |
530 | } |
531 | |
532 | |
533 | jSsl3MasterKeyDeriveParamsClass = |
534 | (*env)->FindClass(env, CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS); |
535 | if (jSsl3MasterKeyDeriveParamsClass == NULL) { |
| 18 | | Assuming 'jSsl3MasterKeyDeriveParamsClass' is not equal to NULL | |
|
| |
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 | |
|
| |
542 | goto cleanup; |
543 | } |
544 | |
545 | if (pLength != NULL) { |
| |
546 | *pLength = sizeof(CK_SSL3_MASTER_KEY_DERIVE_PARAMS); |
547 | } |
548 | return ckParamPtr; |
549 | cleanup: |
550 | free(ckParamPtr); |
551 | return NULL; |
552 | } |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | CK_TLS12_MASTER_KEY_DERIVE_PARAMS_PTR |
564 | jTls12MasterKeyDeriveParamToCKTls12MasterKeyDeriveParamPtr(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) { |
573 | *pLength = 0L; |
574 | } |
575 | |
576 | |
577 | jTls12MasterKeyDeriveParamsClass = |
578 | (*env)->FindClass(env, CLASS_TLS12_MASTER_KEY_DERIVE_PARAMS); |
579 | if (jTls12MasterKeyDeriveParamsClass == NULL) { return NULL; } |
580 | fieldID = (*env)->GetFieldID(env, |
581 | jTls12MasterKeyDeriveParamsClass, "prfHashMechanism", "J"); |
582 | if (fieldID == NULL) { return NULL; } |
583 | prfHashMechanism = (*env)->GetLongField(env, jParam, fieldID); |
584 | |
585 | |
586 | ckParamPtr = calloc(1, sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS)); |
587 | if (ckParamPtr == NULL) { |
588 | throwOutOfMemoryError(env, 0); |
589 | return NULL; |
590 | } |
591 | |
592 | |
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) { |
603 | *pLength = sizeof(CK_TLS12_MASTER_KEY_DERIVE_PARAMS); |
604 | } |
605 | return ckParamPtr; |
606 | cleanup: |
607 | free(ckParamPtr); |
608 | return NULL; |
609 | } |
610 | |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | |
617 | |
618 | |
619 | CK_TLS_PRF_PARAMS_PTR |
620 | jTlsPrfParamsToCKTlsPrfParamPtr(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) { |
628 | *pLength = 0; |
629 | } |
630 | |
631 | |
632 | jTlsPrfParamsClass = (*env)->FindClass(env, CLASS_TLS_PRF_PARAMS); |
633 | if (jTlsPrfParamsClass == NULL) { return NULL; } |
634 | fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pSeed", "[B"); |
635 | if (fieldID == NULL) { return NULL; } |
636 | jSeed = (*env)->GetObjectField(env, jParam, fieldID); |
637 | fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pLabel", "[B"); |
638 | if (fieldID == NULL) { return NULL; } |
639 | jLabel = (*env)->GetObjectField(env, jParam, fieldID); |
640 | fieldID = (*env)->GetFieldID(env, jTlsPrfParamsClass, "pOutput", "[B"); |
641 | if (fieldID == NULL) { return NULL; } |
642 | jOutput = (*env)->GetObjectField(env, jParam, fieldID); |
643 | |
644 | |
645 | ckParamPtr = calloc(1, sizeof(CK_TLS_PRF_PARAMS)); |
646 | if (ckParamPtr == NULL) { |
647 | throwOutOfMemoryError(env, 0); |
648 | return NULL; |
649 | } |
650 | |
651 | |
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) { |
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) { |
670 | *pLength = sizeof(CK_TLS_PRF_PARAMS); |
671 | } |
672 | return ckParamPtr; |
673 | cleanup: |
674 | free(ckParamPtr->pSeed); |
675 | free(ckParamPtr->pLabel); |
676 | free(ckParamPtr->pOutput); |
677 | free(ckParamPtr->pulOutputLen); |
678 | free(ckParamPtr); |
679 | return NULL; |
680 | } |
681 | |
682 | |
683 | |
684 | |
685 | |
686 | |
687 | |
688 | |
689 | |
690 | |
691 | CK_TLS_MAC_PARAMS_PTR |
692 | jTlsMacParamsToCKTlsMacParamPtr(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) { |
700 | *pLength = 0L; |
701 | } |
702 | |
703 | |
704 | jTlsMacParamsClass = (*env)->FindClass(env, CLASS_TLS_MAC_PARAMS); |
705 | if (jTlsMacParamsClass == NULL) { return NULL; } |
706 | fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "prfMechanism", "J"); |
707 | if (fieldID == NULL) { return NULL; } |
708 | jPrfMechanism = (*env)->GetLongField(env, jParam, fieldID); |
709 | fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "ulMacLength", "J"); |
710 | if (fieldID == NULL) { return NULL; } |
711 | jUlMacLength = (*env)->GetLongField(env, jParam, fieldID); |
712 | fieldID = (*env)->GetFieldID(env, jTlsMacParamsClass, "ulServerOrClient", "J"); |
713 | if (fieldID == NULL) { return NULL; } |
714 | jUlServerOrClient = (*env)->GetLongField(env, jParam, fieldID); |
715 | |
716 | |
717 | ckParamPtr = calloc(1, sizeof(CK_TLS_MAC_PARAMS)); |
718 | if (ckParamPtr == NULL) { |
719 | throwOutOfMemoryError(env, 0); |
720 | return NULL; |
721 | } |
722 | |
723 | |
724 | ckParamPtr->prfHashMechanism = jLongToCKULong(jPrfMechanism); |
725 | ckParamPtr->ulMacLength = jLongToCKULong(jUlMacLength); |
726 | ckParamPtr->ulServerOrClient = jLongToCKULong(jUlServerOrClient); |
727 | |
728 | if (pLength != NULL) { |
729 | *pLength = sizeof(CK_TLS_MAC_PARAMS); |
730 | } |
731 | return ckParamPtr; |
732 | } |
733 | |
734 | void 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 | |
752 | |
753 | |
754 | fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulMacSizeInBits", "J"); |
755 | if (fieldID == NULL) { return; } |
756 | jMacSizeInBits = (*env)->GetLongField(env, jParam, fieldID); |
757 | fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulKeySizeInBits", "J"); |
758 | if (fieldID == NULL) { return; } |
759 | jKeySizeInBits = (*env)->GetLongField(env, jParam, fieldID); |
760 | fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "ulIVSizeInBits", "J"); |
761 | if (fieldID == NULL) { return; } |
762 | jIVSizeInBits = (*env)->GetLongField(env, jParam, fieldID); |
763 | fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "bIsExport", "Z"); |
764 | if (fieldID == NULL) { return; } |
765 | jIsExport = (*env)->GetBooleanField(env, jParam, fieldID); |
766 | jSsl3RandomDataClass = (*env)->FindClass(env, CLASS_SSL3_RANDOM_DATA); |
767 | if (jSsl3RandomDataClass == NULL) { return; } |
768 | fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "RandomInfo", |
769 | "Lsun/security/pkcs11/wrapper/CK_SSL3_RANDOM_DATA;"); |
770 | if (fieldID == NULL) { return; } |
771 | jRandomInfo = (*env)->GetObjectField(env, jParam, fieldID); |
772 | fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pClientRandom", "[B"); |
773 | if (fieldID == NULL) { return; } |
774 | jRIClientRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); |
775 | fieldID = (*env)->GetFieldID(env, jSsl3RandomDataClass, "pServerRandom", "[B"); |
776 | if (fieldID == NULL) { return; } |
777 | jRIServerRandom = (*env)->GetObjectField(env, jRandomInfo, fieldID); |
778 | jSsl3KeyMatOutClass = (*env)->FindClass(env, CLASS_SSL3_KEY_MAT_OUT); |
779 | if (jSsl3KeyMatOutClass == NULL) { return; } |
780 | fieldID = (*env)->GetFieldID(env, jKeyMatParamClass, "pReturnedKeyMaterial", |
781 | "Lsun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_OUT;"); |
782 | if (fieldID == NULL) { return; } |
783 | jReturnedKeyMaterial = (*env)->GetObjectField(env, jParam, fieldID); |
784 | fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVClient", "[B"); |
785 | if (fieldID == NULL) { return; } |
786 | jRMIvClient = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID); |
787 | fieldID = (*env)->GetFieldID(env, jSsl3KeyMatOutClass, "pIVServer", "[B"); |
788 | if (fieldID == NULL) { return; } |
789 | jRMIvServer = (*env)->GetObjectField(env, jReturnedKeyMaterial, fieldID); |
790 | |
791 | |
792 | *cKKeyMatParamUlMacSizeInBits = jLongToCKULong(jMacSizeInBits); |
793 | *cKKeyMatParamUlKeySizeInBits = jLongToCKULong(jKeySizeInBits); |
794 | *cKKeyMatParamUlIVSizeInBits = jLongToCKULong(jIVSizeInBits); |
795 | *cKKeyMatParamBIsExport = jBooleanToCKBBool(jIsExport); |
796 | jByteArrayToCKByteArray(env, jRIClientRandom, |
797 | &(cKKeyMatParamRandomInfo->pClientRandom), |
798 | &(cKKeyMatParamRandomInfo->ulClientRandomLen)); |
799 | if ((*env)->ExceptionCheck(env)) { |
800 | |
801 | return; |
802 | } |
803 | jByteArrayToCKByteArray(env, jRIServerRandom, |
804 | &(cKKeyMatParamRandomInfo->pServerRandom), |
805 | &(cKKeyMatParamRandomInfo->ulServerRandomLen)); |
806 | if ((*env)->ExceptionCheck(env)) { |
807 | goto cleanup; |
808 | } |
809 | |
810 | *cKKeyMatParamPReturnedKeyMaterial = |
811 | (CK_SSL3_KEY_MAT_OUT_PTR) calloc(1, sizeof(CK_SSL3_KEY_MAT_OUT)); |
812 | if (*cKKeyMatParamPReturnedKeyMaterial == NULL) { |
813 | throwOutOfMemoryError(env, 0); |
814 | goto cleanup; |
815 | } |
816 | |
817 | |
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; |
835 | cleanup: |
836 | free(cKKeyMatParamRandomInfo->pClientRandom); |
837 | free(cKKeyMatParamRandomInfo->pServerRandom); |
838 | if ((*cKKeyMatParamPReturnedKeyMaterial) != NULL) { |
839 | free((*cKKeyMatParamPReturnedKeyMaterial)->pIVClient); |
840 | free(*cKKeyMatParamPReturnedKeyMaterial); |
841 | } |
842 | |
843 | cKKeyMatParamRandomInfo->pClientRandom = NULL; |
844 | cKKeyMatParamRandomInfo->pServerRandom = NULL; |
845 | *cKKeyMatParamPReturnedKeyMaterial = NULL; |
846 | return; |
847 | } |
848 | |
849 | |
850 | |
851 | |
852 | |
853 | |
854 | |
855 | |
856 | |
857 | CK_SSL3_KEY_MAT_PARAMS_PTR |
858 | jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(JNIEnv *env, jobject jParam, CK_ULONG *pLength) |
859 | { |
860 | CK_SSL3_KEY_MAT_PARAMS_PTR ckParamPtr; |
861 | jclass jSsl3KeyMatParamsClass; |
862 | |
863 | if (pLength != NULL) { |
864 | *pLength = 0; |
865 | } |
866 | |
867 | |
868 | ckParamPtr = calloc(1, sizeof(CK_SSL3_KEY_MAT_PARAMS)); |
869 | if (ckParamPtr == NULL) { |
870 | throwOutOfMemoryError(env, 0); |
871 | return NULL; |
872 | } |
873 | |
874 | |
875 | jSsl3KeyMatParamsClass = (*env)->FindClass(env, |
876 | CLASS_SSL3_KEY_MAT_PARAMS); |
877 | if (jSsl3KeyMatParamsClass == NULL) { |
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) { |
889 | *pLength = sizeof(CK_SSL3_KEY_MAT_PARAMS); |
890 | } |
891 | return ckParamPtr; |
892 | cleanup: |
893 | free(ckParamPtr); |
894 | return NULL; |
895 | } |
896 | |
897 | |
898 | |
899 | |
900 | |
901 | |
902 | |
903 | |
904 | |
905 | |
906 | CK_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) { |
915 | *pLength = 0; |
916 | } |
917 | |
918 | |
919 | jTls12KeyMatParamsClass = (*env)->FindClass(env, |
920 | CLASS_TLS12_KEY_MAT_PARAMS); |
921 | if (jTls12KeyMatParamsClass == NULL) { return NULL; } |
922 | fieldID = (*env)->GetFieldID(env, jTls12KeyMatParamsClass, |
923 | "prfHashMechanism", "J"); |
924 | if (fieldID == NULL) { return NULL; } |
925 | prfHashMechanism = (*env)->GetLongField(env, jParam, fieldID); |
926 | |
927 | |
928 | ckParamPtr = calloc(1, sizeof(CK_TLS12_KEY_MAT_PARAMS)); |
929 | if (ckParamPtr == NULL) { |
930 | throwOutOfMemoryError(env, 0); |
931 | return NULL; |
932 | } |
933 | |
934 | |
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) { |
945 | *pLength = sizeof(CK_TLS12_KEY_MAT_PARAMS); |
946 | } |
947 | return ckParamPtr; |
948 | cleanup: |
949 | free(ckParamPtr); |
950 | return NULL; |
951 | } |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | |
958 | |
959 | |
960 | |
961 | CK_AES_CTR_PARAMS_PTR |
962 | jAesCtrParamsToCKAesCtrParamPtr(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; |
970 | CK_ULONG ckTemp; |
971 | |
972 | if (pLength != NULL) { |
973 | *pLength = 0L; |
974 | } |
975 | |
976 | |
977 | jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS); |
978 | if (jAesCtrParamsClass == NULL) { return NULL; } |
979 | if (!(*env)->IsInstanceOf(env, jParam, jAesCtrParamsClass)) { |
980 | return NULL; |
981 | } |
982 | fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "ulCounterBits", "J"); |
983 | if (fieldID == NULL) { return NULL; } |
984 | jCounterBits = (*env)->GetLongField(env, jParam, fieldID); |
985 | fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "cb", "[B"); |
986 | if (fieldID == NULL) { return NULL; } |
987 | jCb = (*env)->GetObjectField(env, jParam, fieldID); |
988 | |
989 | |
990 | ckParamPtr = calloc(1, sizeof(CK_AES_CTR_PARAMS)); |
991 | if (ckParamPtr == NULL) { |
992 | throwOutOfMemoryError(env, 0); |
993 | return NULL; |
994 | } |
995 | |
996 | |
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); |
1005 | |
1006 | if (pLength != NULL) { |
1007 | *pLength = sizeof(CK_AES_CTR_PARAMS); |
1008 | } |
1009 | return ckParamPtr; |
1010 | cleanup: |
1011 | free(ckBytes); |
1012 | free(ckParamPtr); |
1013 | return NULL; |
1014 | } |
1015 | |
1016 | |
1017 | |
1018 | |
1019 | |
1020 | |
1021 | |
1022 | |
1023 | |
1024 | |
1025 | CK_GCM_PARAMS_NO_IVBITS_PTR |
1026 | jGCMParamsToCKGCMParamPtr(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) { |
1037 | *pLength = 0L; |
1038 | } |
1039 | |
1040 | |
1041 | jGcmParamsClass = (*env)->FindClass(env, CLASS_GCM_PARAMS); |
1042 | if (jGcmParamsClass == NULL) { return NULL; } |
1043 | if (!(*env)->IsInstanceOf(env, jParam, jGcmParamsClass)) { |
1044 | return NULL; |
1045 | } |
1046 | fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "iv", "[B"); |
1047 | if (fieldID == NULL) { return NULL; } |
1048 | jIv = (*env)->GetObjectField(env, jParam, fieldID); |
1049 | fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "aad", "[B"); |
1050 | if (fieldID == NULL) { return NULL; } |
1051 | jAad = (*env)->GetObjectField(env, jParam, fieldID); |
1052 | fieldID = (*env)->GetFieldID(env, jGcmParamsClass, "tagBits", "J"); |
1053 | if (fieldID == NULL) { return NULL; } |
1054 | jTagLen = (*env)->GetLongField(env, jParam, fieldID); |
1055 | |
1056 | |
1057 | ckParamPtr = calloc(1, sizeof(CK_GCM_PARAMS_NO_IVBITS)); |
1058 | if (ckParamPtr == NULL) { |
1059 | throwOutOfMemoryError(env, 0); |
1060 | return NULL; |
1061 | } |
1062 | |
1063 | |
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); |
1075 | |
1076 | if (pLength != NULL) { |
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; |
1081 | cleanup: |
1082 | free(ckParamPtr->pIv); |
1083 | free(ckParamPtr->pAAD); |
1084 | free(ckParamPtr); |
1085 | return NULL; |
1086 | } |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | CK_CCM_PARAMS_PTR |
1097 | jCCMParamsToCKCCMParamPtr(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) { |
1106 | *pLength = 0; |
1107 | } |
1108 | |
1109 | |
1110 | jCcmParamsClass = (*env)->FindClass(env, CLASS_CCM_PARAMS); |
1111 | if (jCcmParamsClass == NULL) { return NULL; } |
1112 | if (!(*env)->IsInstanceOf(env, jParam, jCcmParamsClass)) { |
1113 | return NULL; |
1114 | } |
1115 | fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "dataLen", "J"); |
1116 | if (fieldID == NULL) { return NULL; } |
1117 | jDataLen = (*env)->GetLongField(env, jParam, fieldID); |
1118 | fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "nonce", "[B"); |
1119 | if (fieldID == NULL) { return NULL; } |
1120 | jNonce = (*env)->GetObjectField(env, jParam, fieldID); |
1121 | fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "aad", "[B"); |
1122 | if (fieldID == NULL) { return NULL; } |
1123 | jAad = (*env)->GetObjectField(env, jParam, fieldID); |
1124 | fieldID = (*env)->GetFieldID(env, jCcmParamsClass, "macLen", "J"); |
1125 | if (fieldID == NULL) { return NULL; } |
1126 | jMacLen = (*env)->GetLongField(env, jParam, fieldID); |
1127 | |
1128 | |
1129 | ckParamPtr = calloc(1, sizeof(CK_CCM_PARAMS)); |
1130 | if (ckParamPtr == NULL) { |
1131 | throwOutOfMemoryError(env, 0); |
1132 | return NULL; |
1133 | } |
1134 | |
1135 | |
1136 | ckParamPtr->ulDataLen = jLongToCKULong(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); |
1150 | |
1151 | if (pLength != NULL) { |
1152 | *pLength = sizeof(CK_CCM_PARAMS); |
1153 | } |
1154 | return ckParamPtr; |
1155 | cleanup: |
1156 | free(ckParamPtr->pNonce); |
1157 | free(ckParamPtr->pAAD); |
1158 | free(ckParamPtr); |
1159 | return NULL; |
1160 | } |
1161 | |
1162 | |
1163 | |
1164 | |
1165 | |
1166 | |
1167 | |
1168 | |
1169 | |
1170 | |
1171 | |
1172 | CK_SALSA20_CHACHA20_POLY1305_PARAMS_PTR |
1173 | jSalsaChaChaPolyParamsToCKSalsaChaChaPolyParamPtr( |
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) { |
1182 | *pLength = 0; |
1183 | } |
1184 | |
1185 | |
1186 | jParamsClass = (*env)->FindClass(env, |
1187 | CLASS_SALSA20_CHACHA20_POLY1305_PARAMS); |
1188 | if (jParamsClass == NULL) { return NULL; } |
1189 | if (!(*env)->IsInstanceOf(env, jParam, jParamsClass)) { |
1190 | return NULL; |
1191 | } |
1192 | fieldID = (*env)->GetFieldID(env, jParamsClass, "nonce", "[B"); |
1193 | if (fieldID == NULL) { return NULL; } |
1194 | jNonce = (*env)->GetObjectField(env, jParam, fieldID); |
1195 | fieldID = (*env)->GetFieldID(env, jParamsClass, "aad", "[B"); |
1196 | if (fieldID == NULL) { return NULL; } |
1197 | jAad = (*env)->GetObjectField(env, jParam, fieldID); |
1198 | |
1199 | ckParamPtr = calloc(1, sizeof(CK_SALSA20_CHACHA20_POLY1305_PARAMS)); |
1200 | if (ckParamPtr == NULL) { |
1201 | throwOutOfMemoryError(env, 0); |
1202 | return NULL; |
1203 | } |
1204 | |
1205 | |
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) { |
1219 | *pLength = sizeof(CK_SALSA20_CHACHA20_POLY1305_PARAMS); |
1220 | } |
1221 | return ckParamPtr; |
1222 | cleanup: |
1223 | free(ckParamPtr->pNonce); |
1224 | free(ckParamPtr->pAAD); |
1225 | free(ckParamPtr); |
1226 | return NULL; |
1227 | } |
1228 | |
1229 | |
1230 | |
1231 | |
1232 | |
1233 | |
1234 | |
1235 | |
1236 | |
1237 | CK_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 | |
1244 | ckpMech = (CK_MECHANISM_PTR) calloc(1, sizeof(CK_MECHANISM)); |
1245 | if (ckpMech == NULL) { |
| 1 | Assuming 'ckpMech' is not equal to NULL | |
|
| |
1246 | throwOutOfMemoryError(env, 0); |
1247 | return NULL; |
1248 | } |
1249 | TRACE1("DEBUG jMechanismToCKMechanismPtr: allocated mech %p\n", ckpMech); |
1250 | |
1251 | ckpMech->mechanism = jLongToCKULong(jMechType); |
1252 | |
1253 | |
1254 | |
1255 | |
1256 | if (jParam == NULL) { |
| 3 | | Assuming 'jParam' is not equal to NULL | |
|
| |
1257 | ckpMech->pParameter = NULL; |
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 | |
1268 | |
1269 | |
1270 | |
1271 | |
1272 | |
1273 | |
1274 | |
1275 | |
1276 | |
1277 | jobject ckAttributeValueToJObject(JNIEnv *env, const CK_ATTRIBUTE_PTR ckpAttribute) |
1278 | { |
1279 | jint jValueLength; |
1280 | jobject jValueObject = NULL; |
1281 | |
1282 | jValueLength = ckULongToJInt(ckpAttribute->ulValueLen); |
1283 | |
1284 | if ((jValueLength <= 0) || (ckpAttribute->pValue == NULL)) { |
1285 | return NULL ; |
1286 | } |
1287 | |
1288 | switch(ckpAttribute->type) { |
1289 | case CKA_CLASS: |
1290 | |
1291 | case CKA_KEY_TYPE: |
1292 | |
1293 | case CKA_CERTIFICATE_TYPE: |
1294 | |
1295 | case CKA_HW_FEATURE_TYPE: |
1296 | |
1297 | case CKA_MODULUS_BITS: |
1298 | case CKA_VALUE_BITS: |
1299 | case CKA_VALUE_LEN: |
1300 | case CKA_KEY_GEN_MECHANISM: |
1301 | case CKA_PRIME_BITS: |
1302 | case CKA_SUB_PRIME_BITS: |
1303 | |
1304 | jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue); |
1305 | break; |
1306 | |
1307 | |
1308 | case CKA_VALUE: |
1309 | case CKA_OBJECT_ID: |
1310 | case CKA_SUBJECT: |
1311 | case CKA_ID: |
1312 | case CKA_ISSUER: |
1313 | case CKA_SERIAL_NUMBER: |
1314 | case CKA_OWNER: |
1315 | case CKA_AC_ISSUER: |
1316 | case CKA_ATTR_TYPES: |
1317 | case CKA_ECDSA_PARAMS: |
1318 | |
1319 | case CKA_EC_POINT: |
1320 | case CKA_PRIVATE_EXPONENT: |
1321 | case CKA_PRIME_1: |
1322 | case CKA_PRIME_2: |
1323 | case CKA_EXPONENT_1: |
1324 | case CKA_EXPONENT_2: |
1325 | case CKA_COEFFICIENT: |
1326 | |
1327 | jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength); |
1328 | break; |
1329 | |
1330 | case CKA_RESET_ON_INIT: |
1331 | case CKA_HAS_RESET: |
1332 | case CKA_TOKEN: |
1333 | case CKA_PRIVATE: |
1334 | case CKA_MODIFIABLE: |
1335 | case CKA_DERIVE: |
1336 | case CKA_LOCAL: |
1337 | case CKA_ENCRYPT: |
1338 | case CKA_VERIFY: |
1339 | case CKA_VERIFY_RECOVER: |
1340 | case CKA_WRAP: |
1341 | case CKA_SENSITIVE: |
1342 | case CKA_SECONDARY_AUTH: |
1343 | case CKA_DECRYPT: |
1344 | case CKA_SIGN: |
1345 | case CKA_SIGN_RECOVER: |
1346 | case CKA_UNWRAP: |
1347 | case CKA_EXTRACTABLE: |
1348 | case CKA_ALWAYS_SENSITIVE: |
1349 | case CKA_NEVER_EXTRACTABLE: |
1350 | case CKA_TRUSTED: |
1351 | |
1352 | jValueObject = ckBBoolPtrToJBooleanObject(env, (CK_BBOOL*) ckpAttribute->pValue); |
1353 | break; |
1354 | |
1355 | case CKA_LABEL: |
1356 | case CKA_APPLICATION: |
1357 | |
1358 | jValueObject = ckUTF8CharArrayToJCharArray(env, (CK_UTF8CHAR*) ckpAttribute->pValue, jValueLength); |
1359 | break; |
1360 | |
1361 | case CKA_START_DATE: |
1362 | case CKA_END_DATE: |
1363 | |
1364 | jValueObject = ckDatePtrToJDateObject(env, (CK_DATE*) ckpAttribute->pValue); |
1365 | break; |
1366 | |
1367 | case CKA_MODULUS: |
1368 | case CKA_PUBLIC_EXPONENT: |
1369 | case CKA_PRIME: |
1370 | case CKA_SUBPRIME: |
1371 | case CKA_BASE: |
1372 | |
1373 | jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength); |
1374 | break; |
1375 | |
1376 | case CKA_AUTH_PIN_FLAGS: |
1377 | jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue); |
1378 | |
1379 | break; |
1380 | |
1381 | case CKA_VENDOR_DEFINED: |
1382 | |
1383 | jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength); |
1384 | break; |
1385 | |
1386 | |
1387 | case CKA_NETSCAPE_TRUST_SERVER_AUTH: |
1388 | case CKA_NETSCAPE_TRUST_CLIENT_AUTH: |
1389 | case CKA_NETSCAPE_TRUST_CODE_SIGNING: |
1390 | case CKA_NETSCAPE_TRUST_EMAIL_PROTECTION: |
1391 | |
1392 | jValueObject = ckULongPtrToJLongObject(env, (CK_ULONG*) ckpAttribute->pValue); |
1393 | break; |
1394 | |
1395 | default: |
1396 | |
1397 | jValueObject = ckByteArrayToJByteArray(env, (CK_BYTE*) ckpAttribute->pValue, jValueLength); |
1398 | break; |
1399 | } |
1400 | |
1401 | return jValueObject ; |
1402 | } |
1403 | |
1404 | |
1405 | |
1406 | |
1407 | |
1408 | |
1409 | |
1410 | |
1411 | |
1412 | |
1413 | |
1414 | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 | CK_VOID_PTR jMechParamToCKMechParamPtr(JNIEnv *env, jobject jParam, |
1429 | CK_MECHANISM_TYPE ckMech, CK_ULONG *ckpLength) |
1430 | { |
1431 | CK_VOID_PTR ckpParamPtr; |
1432 | if (jParam == NULL) { |
| |
1433 | ckpParamPtr = NULL; |
1434 | *ckpLength = 0; |
1435 | } else if ((*env)->IsInstanceOf(env, jParam, jByteArrayClass)) { |
| 7 | | Assuming the condition is false | |
|
| |
1436 | jByteArrayToCKByteArray(env, jParam, (CK_BYTE_PTR *) &ckpParamPtr, ckpLength); |
1437 | } else if ((*env)->IsInstanceOf(env, jParam, jLongClass)) { |
| 9 | | Assuming the condition is false | |
|
| |
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 | |
1446 | CK_VOID_PTR jMechParamToCKMechParamPtrSlow(JNIEnv *env, jobject jParam, |
1447 | CK_MECHANISM_TYPE ckMech, CK_ULONG *ckpLength) |
1448 | { |
1449 | CK_VOID_PTR ckpParamPtr = NULL; |
1450 | |
1451 | |
1452 | |
1453 | |
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_GEN: |
1459 | case CKM_TLS_PRE_MASTER_KEY_GEN: |
1460 | ckpParamPtr = jVersionToCKVersionPtr(env, jParam); |
1461 | if (ckpParamPtr != NULL) { |
1462 | *ckpLength = sizeof(CK_VERSION); |
1463 | } else { |
1464 | *ckpLength = 0; |
1465 | } |
1466 | break; |
1467 | case CKM_SSL3_MASTER_KEY_DERIVE: |
1468 | case CKM_TLS_MASTER_KEY_DERIVE: |
1469 | case CKM_SSL3_MASTER_KEY_DERIVE_DH: |
1470 | case CKM_TLS_MASTER_KEY_DERIVE_DH: |
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_DERIVE: |
1475 | case CKM_TLS_KEY_AND_MAC_DERIVE: |
1476 | ckpParamPtr = jSsl3KeyMatParamToCKSsl3KeyMatParamPtr(env, jParam, |
1477 | ckpLength); |
1478 | break; |
1479 | case CKM_TLS12_KEY_AND_MAC_DERIVE: |
1480 | ckpParamPtr = jTls12KeyMatParamToCKTls12KeyMatParamPtr(env, jParam, |
1481 | ckpLength); |
1482 | break; |
1483 | case CKM_TLS12_MASTER_KEY_DERIVE: |
1484 | case CKM_TLS12_MASTER_KEY_DERIVE_DH: |
1485 | ckpParamPtr = jTls12MasterKeyDeriveParamToCKTls12MasterKeyDeriveParamPtr(env, jParam, |
1486 | ckpLength); |
1487 | break; |
1488 | case CKM_TLS_PRF: |
1489 | case CKM_NSS_TLS_PRF_GENERAL: |
1490 | ckpParamPtr = jTlsPrfParamsToCKTlsPrfParamPtr(env, jParam, |
1491 | ckpLength); |
1492 | break; |
1493 | case CKM_TLS_MAC: |
1494 | ckpParamPtr = jTlsMacParamsToCKTlsMacParamPtr(env, jParam, |
1495 | ckpLength); |
1496 | break; |
1497 | case CKM_AES_CTR: |
1498 | ckpParamPtr = jAesCtrParamsToCKAesCtrParamPtr(env, jParam, |
1499 | ckpLength); |
1500 | break; |
1501 | case CKM_AES_GCM: |
1502 | ckpParamPtr = jGCMParamsToCKGCMParamPtr(env, jParam, ckpLength); |
1503 | break; |
1504 | case CKM_AES_CCM: |
1505 | ckpParamPtr = jCCMParamsToCKCCMParamPtr(env, jParam, ckpLength); |
1506 | break; |
1507 | case CKM_CHACHA20_POLY1305: |
1508 | ckpParamPtr = |
1509 | jSalsaChaChaPolyParamsToCKSalsaChaChaPolyParamPtr(env, |
1510 | jParam, ckpLength); |
1511 | break; |
1512 | case CKM_RSA_PKCS_OAEP: |
1513 | ckpParamPtr = jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(env, jParam, ckpLength); |
1514 | break; |
1515 | case CKM_PBE_SHA1_DES3_EDE_CBC: |
1516 | case CKM_PBE_SHA1_DES2_EDE_CBC: |
1517 | case CKM_PBA_SHA1_WITH_SHA1_HMAC: |
1518 | ckpParamPtr = jPbeParamToCKPbeParamPtr(env, jParam, ckpLength); |
1519 | break; |
1520 | case CKM_PKCS5_PBKD2: |
1521 | ckpParamPtr = jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(env, jParam, ckpLength); |
1522 | break; |
1523 | case CKM_RSA_PKCS_PSS: |
1524 | case CKM_SHA1_RSA_PKCS_PSS: |
1525 | case CKM_SHA256_RSA_PKCS_PSS: |
1526 | case CKM_SHA384_RSA_PKCS_PSS: |
1527 | case CKM_SHA512_RSA_PKCS_PSS: |
1528 | case CKM_SHA224_RSA_PKCS_PSS: |
1529 | ckpParamPtr = jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(env, jParam, ckpLength); |
1530 | break; |
1531 | case CKM_ECDH1_DERIVE: |
1532 | case CKM_ECDH1_COFACTOR_DERIVE: |
1533 | ckpParamPtr = jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(env, jParam, ckpLength); |
1534 | break; |
1535 | case CKM_ECMQV_DERIVE: |
1536 | ckpParamPtr = jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(env, jParam, ckpLength); |
1537 | break; |
1538 | case CKM_X9_42_DH_DERIVE: |
1539 | ckpParamPtr = jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(env, jParam, ckpLength); |
1540 | break; |
1541 | case CKM_X9_42_DH_HYBRID_DERIVE: |
1542 | case CKM_X9_42_MQV_DERIVE: |
1543 | ckpParamPtr = jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(env, jParam, ckpLength); |
1544 | break; |
1545 | |
1546 | case CKM_KEA_DERIVE: |
1547 | case CKM_RC2_CBC: |
1548 | case CKM_RC2_MAC_GENERAL: |
1549 | case CKM_RC5_ECB: |
1550 | case CKM_RC5_MAC: |
1551 | case CKM_RC5_CBC: |
1552 | case CKM_RC5_MAC_GENERAL: |
1553 | case CKM_SKIPJACK_PRIVATE_WRAP: |
1554 | case CKM_SKIPJACK_RELAYX: |
1555 | case CKM_KEY_WRAP_SET_OAEP: |
1556 | throwPKCS11RuntimeException(env, "No parameter support for this mchanism"); |
1557 | break; |
1558 | default: |
1559 | |
1560 | |
1561 | ckpParamPtr = jObjectToPrimitiveCKObjectPtr(env, jParam, ckpLength); |
1562 | |
1563 | |
1564 | } |
1565 | TRACE0("\nDEBUG: jMechParamToCKMechParamPtrSlow FINISHED\n"); |
1566 | |
1567 | if ((*env)->ExceptionCheck(env)) { |
| 25 | | Assuming the condition is true | |
|
| |
1568 | return NULL; |
| 27 | | Potential leak of memory pointed to by 'ckpParamPtr' |
|
1569 | } |
1570 | |
1571 | return ckpParamPtr; |
1572 | } |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | |
1579 | |
1580 | |
1581 | |
1582 | |
1583 | CK_RSA_PKCS_OAEP_PARAMS_PTR |
1584 | jRsaPkcsOaepParamToCKRsaPkcsOaepParamPtr(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) { |
1593 | *pLength = 0L; |
1594 | } |
1595 | |
1596 | |
1597 | jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS); |
1598 | if (jRsaPkcsOaepParamsClass == NULL) { return NULL; } |
1599 | fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "hashAlg", "J"); |
1600 | if (fieldID == NULL) { return NULL; } |
1601 | jHashAlg = (*env)->GetLongField(env, jParam, fieldID); |
1602 | fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "mgf", "J"); |
1603 | if (fieldID == NULL) { return NULL; } |
1604 | jMgf = (*env)->GetLongField(env, jParam, fieldID); |
1605 | fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "source", "J"); |
1606 | if (fieldID == NULL) { return NULL; } |
1607 | jSource = (*env)->GetLongField(env, jParam, fieldID); |
1608 | fieldID = (*env)->GetFieldID(env, jRsaPkcsOaepParamsClass, "pSourceData", "[B"); |
1609 | if (fieldID == NULL) { return NULL; } |
1610 | jSourceData = (*env)->GetObjectField(env, jParam, fieldID); |
1611 | |
1612 | |
1613 | ckParamPtr = calloc(1, sizeof(CK_RSA_PKCS_OAEP_PARAMS)); |
1614 | if (ckParamPtr == NULL) { |
1615 | throwOutOfMemoryError(env, 0); |
1616 | return NULL; |
1617 | } |
1618 | |
1619 | |
1620 | ckParamPtr->hashAlg = jLongToCKULong(jHashAlg); |
1621 | ckParamPtr->mgf = jLongToCKULong(jMgf); |
1622 | ckParamPtr->source = jLongToCKULong(jSource); |
1623 | jByteArrayToCKByteArray(env, jSourceData, (CK_BYTE_PTR*) &(ckParamPtr->pSourceData), |
1624 | &(ckParamPtr->ulSourceDataLen)); |
1625 | if ((*env)->ExceptionCheck(env)) { |
1626 | free(ckParamPtr); |
1627 | return NULL; |
1628 | } |
1629 | |
1630 | if (pLength!= NULL) { |
1631 | *pLength = sizeof(CK_RSA_PKCS_OAEP_PARAMS); |
1632 | } |
1633 | return ckParamPtr; |
1634 | } |
1635 | |
1636 | |
1637 | |
1638 | |
1639 | |
1640 | |
1641 | |
1642 | |
1643 | |
1644 | CK_PBE_PARAMS_PTR |
1645 | jPbeParamToCKPbeParamPtr(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) { |
1655 | *pLength = 0; |
1656 | } |
1657 | |
1658 | |
1659 | jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); |
1660 | if (jPbeParamsClass == NULL) { return NULL; } |
1661 | fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVector", "[C"); |
1662 | if (fieldID == NULL) { return NULL; } |
1663 | jInitVector = (*env)->GetObjectField(env, jParam, fieldID); |
1664 | fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pPassword", "[C"); |
1665 | if (fieldID == NULL) { return NULL; } |
1666 | jPassword = (*env)->GetObjectField(env, jParam, fieldID); |
1667 | fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pSalt", "[C"); |
1668 | if (fieldID == NULL) { return NULL; } |
1669 | jSalt = (*env)->GetObjectField(env, jParam, fieldID); |
1670 | fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "ulIteration", "J"); |
1671 | if (fieldID == NULL) { return NULL; } |
1672 | jIteration = (*env)->GetLongField(env, jParam, fieldID); |
1673 | |
1674 | |
1675 | ckParamPtr = calloc(1, sizeof(CK_PBE_PARAMS)); |
1676 | if (ckParamPtr == NULL) { |
1677 | throwOutOfMemoryError(env, 0); |
1678 | return NULL; |
1679 | } |
1680 | |
1681 | |
1682 | ckParamPtr->ulIteration = jLongToCKULong(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) { |
1697 | *pLength = sizeof(CK_PBE_PARAMS); |
1698 | } |
1699 | return ckParamPtr; |
1700 | cleanup: |
1701 | free(ckParamPtr->pInitVector); |
1702 | free(ckParamPtr->pPassword); |
1703 | free(ckParamPtr->pSalt); |
1704 | free(ckParamPtr); |
1705 | return NULL; |
1706 | } |
1707 | |
1708 | |
1709 | |
1710 | |
1711 | |
1712 | |
1713 | |
1714 | void 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 | |
1729 | jMechanismClass = (*env)->FindClass(env, CLASS_MECHANISM); |
1730 | if (jMechanismClass == NULL) { return; } |
1731 | fieldID = (*env)->GetFieldID(env, jMechanismClass, "mechanism", "J"); |
1732 | if (fieldID == NULL) { return; } |
1733 | jMechanismType = (*env)->GetLongField(env, jMechanism, fieldID); |
1734 | ckMechanismType = jLongToCKULong(jMechanismType); |
1735 | if (ckMechanismType != ckMechanism->mechanism) { |
1736 | |
1737 | return; |
1738 | } |
1739 | |
1740 | jPbeParamsClass = (*env)->FindClass(env, CLASS_PBE_PARAMS); |
1741 | if (jPbeParamsClass == NULL) { return; } |
1742 | ckParam = (CK_PBE_PARAMS *) ckMechanism->pParameter; |
1743 | if (ckParam != NULL_PTR) { |
1744 | initVector = ckParam->pInitVector; |
1745 | if (initVector != NULL_PTR) { |
1746 | |
1747 | fieldID = (*env)->GetFieldID(env, jMechanismClass, "pParameter", "Ljava/lang/Object;"); |
1748 | if (fieldID == NULL) { return; } |
1749 | jParameter = (*env)->GetObjectField(env, jMechanism, fieldID); |
1750 | fieldID = (*env)->GetFieldID(env, jPbeParamsClass, "pInitVektor", "[C"); |
1751 | if (fieldID == NULL) { return; } |
1752 | jInitVector = (*env)->GetObjectField(env, jParameter, fieldID); |
1753 | |
1754 | if (jInitVector != NULL) { |
1755 | jInitVectorLength = (*env)->GetArrayLength(env, jInitVector); |
1756 | jInitVectorChars = (*env)->GetCharArrayElements(env, jInitVector, NULL); |
1757 | if (jInitVectorChars == NULL) { return; } |
1758 | |
1759 | |
1760 | for (i=0; i < jInitVectorLength; i++) { |
1761 | jInitVectorChars[i] = ckCharToJChar(initVector[i]); |
1762 | } |
1763 | |
1764 | (*env)->ReleaseCharArrayElements(env, jInitVector, jInitVectorChars, 0); |
1765 | } |
1766 | } |
1767 | } |
1768 | } |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | |
1776 | |
1777 | |
1778 | |
1779 | CK_PKCS5_PBKD2_PARAMS_PTR |
1780 | jPkcs5Pbkd2ParamToCKPkcs5Pbkd2ParamPtr(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) { |
1789 | *pLength = 0L; |
1790 | } |
1791 | |
1792 | |
1793 | jPkcs5Pbkd2ParamsClass = (*env)->FindClass(env, CLASS_PKCS5_PBKD2_PARAMS); |
1794 | if (jPkcs5Pbkd2ParamsClass == NULL) { return NULL; } |
1795 | fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "saltSource", "J"); |
1796 | if (fieldID == NULL) { return NULL; } |
1797 | jSaltSource = (*env)->GetLongField(env, jParam, fieldID); |
1798 | fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pSaltSourceData", "[B"); |
1799 | if (fieldID == NULL) { return NULL; } |
1800 | jSaltSourceData = (*env)->GetObjectField(env, jParam, fieldID); |
1801 | fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "iterations", "J"); |
1802 | if (fieldID == NULL) { return NULL; } |
1803 | jIteration = (*env)->GetLongField(env, jParam, fieldID); |
1804 | fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "prf", "J"); |
1805 | if (fieldID == NULL) { return NULL; } |
1806 | jPrf = (*env)->GetLongField(env, jParam, fieldID); |
1807 | fieldID = (*env)->GetFieldID(env, jPkcs5Pbkd2ParamsClass, "pPrfData", "[B"); |
1808 | if (fieldID == NULL) { return NULL; } |
1809 | jPrfData = (*env)->GetObjectField(env, jParam, fieldID); |
1810 | |
1811 | |
1812 | ckParamPtr = calloc(1, sizeof(CK_PKCS5_PBKD2_PARAMS)); |
1813 | if (ckParamPtr == NULL) { |
1814 | throwOutOfMemoryError(env, 0); |
1815 | return NULL; |
1816 | } |
1817 | |
1818 | |
1819 | ckParamPtr->saltSource = jLongToCKULong(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); |
1826 | ckParamPtr->prf = jLongToCKULong(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) { |
1834 | *pLength = sizeof(CK_PKCS5_PBKD2_PARAMS); |
1835 | } |
1836 | return ckParamPtr; |
1837 | cleanup: |
1838 | free(ckParamPtr->pSaltSourceData); |
1839 | free(ckParamPtr->pPrfData); |
1840 | free(ckParamPtr); |
1841 | return NULL; |
1842 | |
1843 | } |
1844 | |
1845 | |
1846 | |
1847 | |
1848 | |
1849 | |
1850 | |
1851 | |
1852 | |
1853 | |
1854 | CK_RSA_PKCS_PSS_PARAMS_PTR |
1855 | jRsaPkcsPssParamToCKRsaPkcsPssParamPtr(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) { |
1863 | *pLength = 0; |
1864 | } |
1865 | |
1866 | |
1867 | jRsaPkcsPssParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_PSS_PARAMS); |
1868 | if (jRsaPkcsPssParamsClass == NULL) { return NULL; } |
1869 | fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "hashAlg", "J"); |
1870 | if (fieldID == NULL) { return NULL; } |
1871 | jHashAlg = (*env)->GetLongField(env, jParam, fieldID); |
1872 | fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "mgf", "J"); |
1873 | if (fieldID == NULL) { return NULL; } |
1874 | jMgf = (*env)->GetLongField(env, jParam, fieldID); |
1875 | fieldID = (*env)->GetFieldID(env, jRsaPkcsPssParamsClass, "sLen", "J"); |
1876 | if (fieldID == NULL) { return NULL; } |
1877 | jSLen = (*env)->GetLongField(env, jParam, fieldID); |
1878 | |
1879 | |
1880 | ckParamPtr = calloc(1, sizeof(CK_RSA_PKCS_PSS_PARAMS)); |
1881 | if (ckParamPtr == NULL) { |
1882 | throwOutOfMemoryError(env, 0); |
1883 | return NULL; |
1884 | } |
1885 | |
1886 | |
1887 | ckParamPtr->hashAlg = jLongToCKULong(jHashAlg); |
1888 | ckParamPtr->mgf = jLongToCKULong(jMgf); |
1889 | ckParamPtr->sLen = jLongToCKULong(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) { |
1895 | *pLength = sizeof(CK_RSA_PKCS_PSS_PARAMS); |
1896 | } |
1897 | return ckParamPtr; |
1898 | |
1899 | } |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | |
1905 | |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | CK_ECDH1_DERIVE_PARAMS_PTR |
1911 | jEcdh1DeriveParamToCKEcdh1DeriveParamPtr(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) { |
1920 | *pLength = 0; |
1921 | } |
1922 | |
1923 | |
1924 | jEcdh1DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH1_DERIVE_PARAMS); |
1925 | if (jEcdh1DeriveParamsClass == NULL) { return NULL; } |
1926 | fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "kdf", "J"); |
1927 | if (fieldID == NULL) { return NULL; } |
1928 | jLong = (*env)->GetLongField(env, jParam, fieldID); |
1929 | fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pSharedData", "[B"); |
1930 | if (fieldID == NULL) { return NULL; } |
1931 | jSharedData = (*env)->GetObjectField(env, jParam, fieldID); |
1932 | fieldID = (*env)->GetFieldID(env, jEcdh1DeriveParamsClass, "pPublicData", "[B"); |
1933 | if (fieldID == NULL) { return NULL; } |
1934 | jPublicData = (*env)->GetObjectField(env, jParam, fieldID); |
1935 | |
1936 | |
1937 | ckParamPtr = calloc(1, sizeof(CK_ECDH1_DERIVE_PARAMS)); |
1938 | if (ckParamPtr == NULL) { |
1939 | throwOutOfMemoryError(env, 0); |
1940 | return NULL; |
1941 | } |
1942 | |
1943 | |
1944 | ckParamPtr->kdf = jLongToCKULong(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) { |
1957 | *pLength = sizeof(CK_ECDH1_DERIVE_PARAMS); |
1958 | } |
1959 | return ckParamPtr; |
1960 | cleanup: |
1961 | free(ckParamPtr->pSharedData); |
1962 | free(ckParamPtr->pPublicData); |
1963 | free(ckParamPtr); |
1964 | return NULL; |
1965 | } |
1966 | |
1967 | |
1968 | |
1969 | |
1970 | |
1971 | |
1972 | |
1973 | |
1974 | |
1975 | |
1976 | CK_ECDH2_DERIVE_PARAMS_PTR |
1977 | jEcdh2DeriveParamToCKEcdh2DeriveParamPtr(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 | |
1986 | jEcdh2DeriveParamsClass = (*env)->FindClass(env, CLASS_ECDH2_DERIVE_PARAMS); |
1987 | if (jEcdh2DeriveParamsClass == NULL) { return NULL; } |
1988 | fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "kdf", "J"); |
1989 | if (fieldID == NULL) { return NULL; } |
1990 | jKdf = (*env)->GetLongField(env, jParam, fieldID); |
1991 | fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pSharedData", "[B"); |
1992 | if (fieldID == NULL) { return NULL; } |
1993 | jSharedData = (*env)->GetObjectField(env, jParam, fieldID); |
1994 | fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData", "[B"); |
1995 | if (fieldID == NULL) { return NULL; } |
1996 | jPublicData = (*env)->GetObjectField(env, jParam, fieldID); |
1997 | fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "ulPrivateDataLen", "J"); |
1998 | if (fieldID == NULL) { return NULL; } |
1999 | jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID); |
2000 | fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "hPrivateData", "J"); |
2001 | if (fieldID == NULL) { return NULL; } |
2002 | jPrivateData = (*env)->GetLongField(env, jParam, fieldID); |
2003 | fieldID = (*env)->GetFieldID(env, jEcdh2DeriveParamsClass, "pPublicData2", "[B"); |
2004 | if (fieldID == NULL) { return NULL; } |
2005 | jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID); |
2006 | |
2007 | |
2008 | ckParamPtr = calloc(1, sizeof(CK_ECDH2_DERIVE_PARAMS)); |
2009 | if (ckParamPtr == NULL) { |
2010 | throwOutOfMemoryError(env, 0); |
2011 | return NULL; |
2012 | } |
2013 | |
2014 | |
2015 | ckParamPtr->kdf = jLongToCKULong(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); |
2027 | ckParamPtr->hPrivateData = jLongToCKULong(jPrivateData); |
2028 | jByteArrayToCKByteArray(env, jPublicData2, &(ckParamPtr->pPublicData2), |
2029 | &(ckParamPtr->ulPublicDataLen2)); |
2030 | if ((*env)->ExceptionCheck(env)) { |
2031 | goto cleanup; |
2032 | } |
2033 | |
2034 | if (pLength != NULL) { |
2035 | *pLength = sizeof(CK_ECDH2_DERIVE_PARAMS); |
2036 | } |
2037 | return ckParamPtr; |
2038 | cleanup: |
2039 | free(ckParamPtr->pSharedData); |
2040 | free(ckParamPtr->pPublicData); |
2041 | free(ckParamPtr->pPublicData2); |
2042 | free(ckParamPtr); |
2043 | return NULL; |
2044 | } |
2045 | |
2046 | |
2047 | |
2048 | |
2049 | |
2050 | |
2051 | |
2052 | |
2053 | |
2054 | |
2055 | CK_X9_42_DH1_DERIVE_PARAMS_PTR |
2056 | jX942Dh1DeriveParamToCKX942Dh1DeriveParamPtr(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) { |
2065 | *pLength = 0; |
2066 | } |
2067 | |
2068 | |
2069 | jX942Dh1DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH1_DERIVE_PARAMS); |
2070 | if (jX942Dh1DeriveParamsClass == NULL) { return NULL; } |
2071 | fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "kdf", "J"); |
2072 | if (fieldID == NULL) { return NULL; } |
2073 | jKdf = (*env)->GetLongField(env, jParam, fieldID); |
2074 | fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pOtherInfo", "[B"); |
2075 | if (fieldID == NULL) { return NULL; } |
2076 | jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID); |
2077 | fieldID = (*env)->GetFieldID(env, jX942Dh1DeriveParamsClass, "pPublicData", "[B"); |
2078 | if (fieldID == NULL) { return NULL; } |
2079 | jPublicData = (*env)->GetObjectField(env, jParam, fieldID); |
2080 | |
2081 | |
2082 | ckParamPtr = calloc(1, sizeof(CK_X9_42_DH1_DERIVE_PARAMS)); |
2083 | if (ckParamPtr == NULL) { |
2084 | throwOutOfMemoryError(env, 0); |
2085 | return NULL; |
2086 | } |
2087 | |
2088 | |
2089 | ckParamPtr->kdf = jLongToCKULong(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) { |
2102 | *pLength = sizeof(CK_X9_42_DH1_DERIVE_PARAMS); |
2103 | } |
2104 | return ckParamPtr; |
2105 | cleanup: |
2106 | free(ckParamPtr->pOtherInfo); |
2107 | free(ckParamPtr->pPublicData); |
2108 | free(ckParamPtr); |
2109 | return NULL; |
2110 | } |
2111 | |
2112 | |
2113 | |
2114 | |
2115 | |
2116 | |
2117 | |
2118 | |
2119 | |
2120 | |
2121 | CK_X9_42_DH2_DERIVE_PARAMS_PTR |
2122 | jX942Dh2DeriveParamToCKX942Dh2DeriveParamPtr(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) { |
2131 | *pLength = 0L; |
2132 | } |
2133 | |
2134 | |
2135 | jX942Dh2DeriveParamsClass = (*env)->FindClass(env, CLASS_X9_42_DH2_DERIVE_PARAMS); |
2136 | if (jX942Dh2DeriveParamsClass == NULL) { return NULL; } |
2137 | fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "kdf", "J"); |
2138 | if (fieldID == NULL) { return NULL; } |
2139 | jKdf = (*env)->GetLongField(env, jParam, fieldID); |
2140 | fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pOtherInfo", "[B"); |
2141 | if (fieldID == NULL) { return NULL; } |
2142 | jOtherInfo = (*env)->GetObjectField(env, jParam, fieldID); |
2143 | fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData", "[B"); |
2144 | if (fieldID == NULL) { return NULL; } |
2145 | jPublicData = (*env)->GetObjectField(env, jParam, fieldID); |
2146 | fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "ulPrivateDataLen", "J"); |
2147 | if (fieldID == NULL) { return NULL; } |
2148 | jPrivateDataLen = (*env)->GetLongField(env, jParam, fieldID); |
2149 | fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "hPrivateData", "J"); |
2150 | if (fieldID == NULL) { return NULL; } |
2151 | jPrivateData = (*env)->GetLongField(env, jParam, fieldID); |
2152 | fieldID = (*env)->GetFieldID(env, jX942Dh2DeriveParamsClass, "pPublicData2", "[B"); |
2153 | if (fieldID == NULL) { return NULL; } |
2154 | jPublicData2 = (*env)->GetObjectField(env, jParam, fieldID); |
2155 | |
2156 | |
2157 | ckParamPtr = calloc(1, sizeof(CK_X9_42_DH2_DERIVE_PARAMS)); |
2158 | if (ckParamPtr == NULL) { |
2159 | throwOutOfMemoryError(env, 0); |
2160 | return NULL; |
2161 | } |
2162 | |
2163 | |
2164 | ckParamPtr->kdf = jLongToCKULong(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); |
2176 | ckParamPtr->hPrivateData = jLongToCKULong(jPrivateData); |
2177 | jByteArrayToCKByteArray(env, jPublicData2, &(ckParamPtr->pPublicData2), |
2178 | &(ckParamPtr->ulPublicDataLen2)); |
2179 | if ((*env)->ExceptionCheck(env)) { |
2180 | goto cleanup; |
2181 | } |
2182 | |
2183 | if (pLength != NULL) { |
2184 | *pLength = sizeof(CK_X9_42_DH2_DERIVE_PARAMS); |
2185 | } |
2186 | return ckParamPtr; |
2187 | cleanup: |
2188 | free(ckParamPtr->pOtherInfo); |
2189 | free(ckParamPtr->pPublicData); |
2190 | free(ckParamPtr->pPublicData2); |
2191 | free(ckParamPtr); |
2192 | return NULL; |
2193 | } |