author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58489 | 2faeaa5933a6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
#include "pkcs11wrapper.h" |
|
50 |
||
51 |
#include <stdio.h> |
|
52 |
#include <stdlib.h> |
|
53 |
#include <string.h> |
|
54 |
#include <assert.h> |
|
55 |
||
56 |
#include "sun_security_pkcs11_wrapper_PKCS11.h" |
|
57 |
||
58 |
#ifdef P11_ENABLE_C_ENCRYPTINIT |
|
59 |
/* |
|
60 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
61 |
* Method: C_EncryptInit |
|
62 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V |
|
63 |
* Parametermapping: *PKCS11* |
|
64 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
65 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
66 |
* @param jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
67 |
*/ |
|
68 |
JNIEXPORT void JNICALL |
|
69 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptInit |
|
70 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
71 |
jobject jMechanism, jlong jKeyHandle) |
|
72 |
{ |
|
73 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
74 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
75 |
CK_MECHANISM_PTR ckpTemp; |
2 | 76 |
CK_OBJECT_HANDLE ckKeyHandle; |
77 |
CK_RV rv; |
|
78 |
||
79 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
80 |
if (ckpFunctions == NULL) { return; } |
|
81 |
||
82 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
83 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
84 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
85 |
TRACE1("DEBUG C_EncryptInit: created pMech = %p\n", |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
86 |
ckpMechanism); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
87 |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
88 |
if ((*env)->ExceptionCheck(env)) { return; } |
2 | 89 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
90 |
rv = (*ckpFunctions->C_EncryptInit)(ckSessionHandle, ckpMechanism, |
2 | 91 |
ckKeyHandle); |
92 |
||
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
93 |
if (ckpMechanism->mechanism == CKM_AES_GCM) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
94 |
if (rv == CKR_ARGUMENTS_BAD || rv == CKR_MECHANISM_PARAM_INVALID) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
95 |
// retry with CKM_GCM_PARAMS structure in pkcs11t.h |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
96 |
TRACE0("DEBUG C_EncryptInit: retry with CK_GCM_PARAMS\n"); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
97 |
ckpTemp = updateGCMParams(env, ckpMechanism); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
98 |
if (ckpTemp != NULL) { // only re-call if conversion succeeds |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
99 |
ckpMechanism = ckpTemp; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
100 |
rv = (*ckpFunctions->C_EncryptInit)(ckSessionHandle, ckpMechanism, |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
101 |
ckKeyHandle); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
102 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
103 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
104 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
105 |
|
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
106 |
TRACE1("DEBUG C_EncryptInit: freed pMech = %p\n", ckpMechanism); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
107 |
freeCKMechanismPtr(ckpMechanism); |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
108 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 109 |
|
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
110 |
TRACE0("FINISHED\n"); |
2 | 111 |
} |
112 |
#endif |
|
113 |
||
114 |
#ifdef P11_ENABLE_C_ENCRYPT |
|
115 |
/* |
|
116 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
117 |
* Method: C_Encrypt |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
118 |
* Signature: (JJ[BIIJ[BII)I |
2 | 119 |
* Parametermapping: *PKCS11* |
120 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
121 |
* @param jlong directIn CK_BYTE_PTR pData |
2 | 122 |
* @param jbyteArray jData CK_BYTE_PTR pData |
123 |
* CK_ULONG ulDataLen |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
124 |
* @param jlong directOut CK_BYTE_PTR pEncryptedData |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
125 |
* @return jint encryptedDataLen CK_BYTE_PTR pEncryptedData |
2 | 126 |
* CK_ULONG_PTR pulEncryptedDataLen |
127 |
*/ |
|
128 |
JNIEXPORT jint JNICALL |
|
129 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Encrypt |
|
130 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
131 |
jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen, |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
132 |
jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
2 | 133 |
{ |
134 |
CK_SESSION_HANDLE ckSessionHandle; |
|
135 |
CK_RV rv; |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
136 |
|
2 | 137 |
CK_BYTE_PTR inBufP; |
138 |
CK_BYTE_PTR outBufP; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
139 |
CK_ULONG ckEncryptedLen = 0; |
2 | 140 |
|
141 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
142 |
if (ckpFunctions == NULL) { return 0; } |
|
143 |
||
144 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
145 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
146 |
if (directIn != 0) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
147 |
inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
148 |
} else { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
149 |
inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
150 |
if (inBufP == NULL) { return 0; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
151 |
} |
2 | 152 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
153 |
if (directOut != 0) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
154 |
outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
155 |
} else { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
156 |
outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
157 |
if (outBufP == NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
158 |
goto cleanup; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
159 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
160 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
161 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
162 |
ckEncryptedLen = jOutLen; |
2 | 163 |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
164 |
rv = (*ckpFunctions->C_Encrypt)(ckSessionHandle, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
165 |
(CK_BYTE_PTR)(inBufP + jInOfs), jInLen, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
166 |
(CK_BYTE_PTR)(outBufP + jOutOfs), |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
167 |
&ckEncryptedLen); |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
168 |
|
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
169 |
ckAssertReturnValueOK(env, rv); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
170 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
171 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
172 |
if (directIn == 0 && inBufP != NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
173 |
(*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
174 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
175 |
if (directOut == 0 && outBufP != NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
176 |
(*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
177 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
178 |
return ckEncryptedLen; |
2 | 179 |
} |
180 |
#endif |
|
181 |
||
182 |
#ifdef P11_ENABLE_C_ENCRYPTUPDATE |
|
183 |
/* |
|
184 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
185 |
* Method: C_EncryptUpdate |
|
186 |
* Signature: (J[BII[BII)I |
|
187 |
* Parametermapping: *PKCS11* |
|
188 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
189 |
* @param jbyteArray jPart CK_BYTE_PTR pPart |
|
190 |
* CK_ULONG ulPartLen |
|
191 |
* @return jbyteArray jEncryptedPart CK_BYTE_PTR pEncryptedPart |
|
192 |
* CK_ULONG_PTR pulEncryptedPartLen |
|
193 |
*/ |
|
194 |
JNIEXPORT jint JNICALL |
|
195 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptUpdate |
|
196 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
197 |
jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen, |
|
198 |
jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
|
199 |
{ |
|
200 |
CK_SESSION_HANDLE ckSessionHandle; |
|
201 |
CK_RV rv; |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
202 |
|
2 | 203 |
CK_BYTE_PTR inBufP; |
204 |
CK_BYTE_PTR outBufP; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
205 |
CK_ULONG ckEncryptedPartLen = 0; |
2 | 206 |
|
207 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
208 |
if (ckpFunctions == NULL) { return 0; } |
|
209 |
||
210 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
211 |
||
212 |
if (directIn != 0) { |
|
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
6894
diff
changeset
|
213 |
inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn); |
2 | 214 |
} else { |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
215 |
inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
216 |
if (inBufP == NULL) { return 0; } |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
217 |
} |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
218 |
|
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
219 |
if (directOut != 0) { |
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
6894
diff
changeset
|
220 |
outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut); |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
221 |
} else { |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
222 |
outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
223 |
if (outBufP == NULL) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
224 |
goto cleanup; |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
225 |
} |
2 | 226 |
} |
227 |
||
228 |
ckEncryptedPartLen = jOutLen; |
|
229 |
||
230 |
rv = (*ckpFunctions->C_EncryptUpdate)(ckSessionHandle, |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
231 |
(CK_BYTE_PTR)(inBufP + jInOfs), jInLen, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
232 |
(CK_BYTE_PTR)(outBufP + jOutOfs), |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
233 |
&ckEncryptedPartLen); |
2 | 234 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
235 |
ckAssertReturnValueOK(env, rv); |
2 | 236 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
237 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
238 |
if (directIn == 0 && inBufP != NULL) { |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
239 |
(*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT); |
2 | 240 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
241 |
if (directOut == 0 && outBufP != NULL) { |
27487
106d0156648d
8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
25859
diff
changeset
|
242 |
(*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT); |
2 | 243 |
} |
244 |
return ckEncryptedPartLen; |
|
245 |
} |
|
246 |
#endif |
|
247 |
||
248 |
#ifdef P11_ENABLE_C_ENCRYPTFINAL |
|
249 |
/* |
|
250 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
251 |
* Method: C_EncryptFinal |
|
252 |
* Signature: (J[BII)I |
|
253 |
* Parametermapping: *PKCS11* |
|
254 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
255 |
* @return jbyteArray jLastEncryptedPart CK_BYTE_PTR pLastEncryptedDataPart |
|
256 |
* CK_ULONG_PTR pulLastEncryptedDataPartLen |
|
257 |
*/ |
|
258 |
JNIEXPORT jint JNICALL |
|
259 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1EncryptFinal |
|
260 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
261 |
jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
|
262 |
{ |
|
263 |
CK_SESSION_HANDLE ckSessionHandle; |
|
264 |
CK_RV rv; |
|
265 |
CK_BYTE_PTR outBufP; |
|
266 |
CK_ULONG ckLastEncryptedPartLen; |
|
267 |
||
268 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
269 |
if (ckpFunctions == NULL) { return 0; } |
|
270 |
||
271 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
272 |
||
273 |
if (directOut != 0) { |
|
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
6894
diff
changeset
|
274 |
outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut); |
2 | 275 |
} else { |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
276 |
outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
277 |
if (outBufP == NULL) { return 0; } |
2 | 278 |
} |
279 |
||
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
280 |
ckLastEncryptedPartLen = jOutLen; |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
281 |
|
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
282 |
rv = (*ckpFunctions->C_EncryptFinal)(ckSessionHandle, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
283 |
(CK_BYTE_PTR)(outBufP + jOutOfs), |
2 | 284 |
&ckLastEncryptedPartLen); |
285 |
||
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
286 |
if (directOut == 0) { |
27487
106d0156648d
8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
25859
diff
changeset
|
287 |
(*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT); |
2 | 288 |
} |
289 |
||
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
290 |
ckAssertReturnValueOK(env, rv); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
291 |
|
2 | 292 |
return ckLastEncryptedPartLen; |
293 |
} |
|
294 |
#endif |
|
295 |
||
296 |
#ifdef P11_ENABLE_C_DECRYPTINIT |
|
297 |
/* |
|
298 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
299 |
* Method: C_DecryptInit |
|
300 |
* Signature: (JLsun/security/pkcs11/wrapper/CK_MECHANISM;J)V |
|
301 |
* Parametermapping: *PKCS11* |
|
302 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
303 |
* @param jobject jMechanism CK_MECHANISM_PTR pMechanism |
|
304 |
* @param jlong jKeyHandle CK_OBJECT_HANDLE hKey |
|
305 |
*/ |
|
306 |
JNIEXPORT void JNICALL |
|
307 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptInit |
|
308 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
309 |
jobject jMechanism, jlong jKeyHandle) |
|
310 |
{ |
|
311 |
CK_SESSION_HANDLE ckSessionHandle; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
312 |
CK_MECHANISM_PTR ckpMechanism = NULL; |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
313 |
CK_MECHANISM_PTR ckpTemp; |
2 | 314 |
CK_OBJECT_HANDLE ckKeyHandle; |
315 |
CK_RV rv; |
|
316 |
||
317 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
318 |
if (ckpFunctions == NULL) { return; } |
|
319 |
||
320 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
321 |
ckKeyHandle = jLongToCKULong(jKeyHandle); |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
322 |
ckpMechanism = jMechanismToCKMechanismPtr(env, jMechanism); |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
323 |
TRACE1("DEBUG C_DecryptInit: created pMech = %p\n", |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
324 |
ckpMechanism); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
325 |
|
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
326 |
if ((*env)->ExceptionCheck(env)) { return; } |
2 | 327 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
328 |
rv = (*ckpFunctions->C_DecryptInit)(ckSessionHandle, ckpMechanism, |
2 | 329 |
ckKeyHandle); |
330 |
||
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
331 |
if (ckpMechanism->mechanism == CKM_AES_GCM) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
332 |
if (rv == CKR_ARGUMENTS_BAD || rv == CKR_MECHANISM_PARAM_INVALID) { |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
333 |
// retry with CKM_GCM_PARAMS structure in pkcs11t.h |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
334 |
TRACE0("DEBUG C_DecryptInit: retry with CK_GCM_PARAMS\n"); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
335 |
ckpTemp = updateGCMParams(env, ckpMechanism); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
336 |
if (ckpTemp != NULL) { // only re-call if conversion succeeds |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
337 |
ckpMechanism = ckpTemp; |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
338 |
rv = (*ckpFunctions->C_DecryptInit)(ckSessionHandle, ckpMechanism, |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
339 |
ckKeyHandle); |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
340 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
341 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
342 |
} |
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
343 |
|
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
344 |
TRACE1("DEBUG C_DecryptInit: freed pMech = %p\n", ckpMechanism); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
345 |
freeCKMechanismPtr(ckpMechanism); |
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
346 |
if (ckAssertReturnValueOK(env, rv) != CK_ASSERT_OK) { return; } |
2 | 347 |
|
58489
2faeaa5933a6
8229243: SunPKCS11-Solaris provider tests failing on Solaris 11.4
valeriep
parents:
55332
diff
changeset
|
348 |
TRACE0("FINISHED\n"); |
2 | 349 |
} |
350 |
#endif |
|
351 |
||
352 |
#ifdef P11_ENABLE_C_DECRYPT |
|
353 |
/* |
|
354 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
355 |
* Method: C_Decrypt |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
356 |
* Signature: (JJ[BIIJ[BII)I |
2 | 357 |
* Parametermapping: *PKCS11* |
358 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
359 |
* @param jbyteArray jEncryptedData CK_BYTE_PTR pEncryptedData |
|
360 |
* CK_ULONG ulEncryptedDataLen |
|
361 |
* @return jbyteArray jData CK_BYTE_PTR pData |
|
362 |
* CK_ULONG_PTR pulDataLen |
|
363 |
*/ |
|
364 |
JNIEXPORT jint JNICALL |
|
365 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1Decrypt |
|
366 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
367 |
jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen, |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
368 |
jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
2 | 369 |
{ |
370 |
CK_SESSION_HANDLE ckSessionHandle; |
|
371 |
CK_RV rv; |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
372 |
|
2 | 373 |
CK_BYTE_PTR inBufP; |
374 |
CK_BYTE_PTR outBufP; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
375 |
CK_ULONG ckOutLen = 0; |
2 | 376 |
|
377 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
378 |
if (ckpFunctions == NULL) { return 0; } |
|
379 |
||
380 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
381 |
||
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
382 |
if (directIn != 0) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
383 |
inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
384 |
} else { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
385 |
inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
386 |
if (inBufP == NULL) { return 0; } |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
387 |
} |
2 | 388 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
389 |
if (directOut != 0) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
390 |
outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
391 |
} else { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
392 |
outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
393 |
if (outBufP == NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
394 |
goto cleanup; |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
395 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
396 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
397 |
ckOutLen = jOutLen; |
2 | 398 |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
399 |
rv = (*ckpFunctions->C_Decrypt)(ckSessionHandle, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
400 |
(CK_BYTE_PTR)(inBufP + jInOfs), jInLen, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
401 |
(CK_BYTE_PTR)(outBufP + jOutOfs), |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
402 |
&ckOutLen); |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
403 |
|
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
404 |
ckAssertReturnValueOK(env, rv); |
2 | 405 |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
406 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
407 |
if (directIn == 0 && inBufP != NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
408 |
(*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
409 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
410 |
if (directOut == 0 && outBufP != NULL) { |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
411 |
(*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
412 |
} |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
413 |
return ckOutLen; |
2 | 414 |
} |
415 |
#endif |
|
416 |
||
417 |
#ifdef P11_ENABLE_C_DECRYPTUPDATE |
|
418 |
/* |
|
419 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
420 |
* Method: C_DecryptUpdate |
|
421 |
* Signature: (J[BII[BII)I |
|
422 |
* Parametermapping: *PKCS11* |
|
423 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
424 |
* @param jbyteArray jEncryptedPart CK_BYTE_PTR pEncryptedPart |
|
425 |
* CK_ULONG ulEncryptedPartLen |
|
426 |
* @return jbyteArray jPart CK_BYTE_PTR pPart |
|
427 |
* CK_ULONG_PTR pulPartLen |
|
428 |
*/ |
|
429 |
JNIEXPORT jint JNICALL |
|
430 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptUpdate |
|
431 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
432 |
jlong directIn, jbyteArray jIn, jint jInOfs, jint jInLen, |
|
433 |
jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
|
434 |
{ |
|
435 |
CK_SESSION_HANDLE ckSessionHandle; |
|
436 |
CK_RV rv; |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
437 |
|
2 | 438 |
CK_BYTE_PTR inBufP; |
439 |
CK_BYTE_PTR outBufP; |
|
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
440 |
CK_ULONG ckDecryptedPartLen = 0; |
2 | 441 |
|
442 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
443 |
if (ckpFunctions == NULL) { return 0; } |
|
444 |
||
445 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
446 |
||
447 |
if (directIn != 0) { |
|
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
6894
diff
changeset
|
448 |
inBufP = (CK_BYTE_PTR) jlong_to_ptr(directIn); |
2 | 449 |
} else { |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
450 |
inBufP = (*env)->GetPrimitiveArrayCritical(env, jIn, NULL); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
451 |
if (inBufP == NULL) { return 0; } |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
452 |
} |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
453 |
|
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
454 |
if (directOut != 0) { |
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
6894
diff
changeset
|
455 |
outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut); |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
456 |
} else { |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
457 |
outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
458 |
if (outBufP == NULL) { |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
459 |
goto cleanup; |
2180
9994f4f08a59
6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents:
2
diff
changeset
|
460 |
} |
2 | 461 |
} |
462 |
||
463 |
ckDecryptedPartLen = jOutLen; |
|
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
464 |
rv = (*ckpFunctions->C_DecryptUpdate)(ckSessionHandle, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
465 |
(CK_BYTE_PTR)(inBufP + jInOfs), jInLen, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
466 |
(CK_BYTE_PTR)(outBufP + jOutOfs), |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
467 |
&ckDecryptedPartLen); |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
468 |
ckAssertReturnValueOK(env, rv); |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
469 |
|
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
470 |
cleanup: |
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
471 |
if (directIn == 0 && inBufP != NULL) { |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
472 |
(*env)->ReleasePrimitiveArrayCritical(env, jIn, inBufP, JNI_ABORT); |
2 | 473 |
} |
55332
f492567244ab
8080462: Update SunPKCS11 provider with PKCS11 v2.40 support
valeriep
parents:
47216
diff
changeset
|
474 |
if (directOut == 0 && outBufP != NULL) { |
27487
106d0156648d
8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
25859
diff
changeset
|
475 |
(*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT); |
2 | 476 |
} |
477 |
return ckDecryptedPartLen; |
|
478 |
} |
|
479 |
||
480 |
#endif |
|
481 |
||
482 |
#ifdef P11_ENABLE_C_DECRYPTFINAL |
|
483 |
/* |
|
484 |
* Class: sun_security_pkcs11_wrapper_PKCS11 |
|
485 |
* Method: C_DecryptFinal |
|
486 |
* Signature: (J[BII)I |
|
487 |
* Parametermapping: *PKCS11* |
|
488 |
* @param jlong jSessionHandle CK_SESSION_HANDLE hSession |
|
489 |
* @return jbyteArray jLastPart CK_BYTE_PTR pLastPart |
|
490 |
* CK_ULONG_PTR pulLastPartLen |
|
491 |
*/ |
|
492 |
JNIEXPORT jint JNICALL |
|
493 |
Java_sun_security_pkcs11_wrapper_PKCS11_C_1DecryptFinal |
|
494 |
(JNIEnv *env, jobject obj, jlong jSessionHandle, |
|
495 |
jlong directOut, jbyteArray jOut, jint jOutOfs, jint jOutLen) |
|
496 |
{ |
|
497 |
CK_SESSION_HANDLE ckSessionHandle; |
|
498 |
CK_RV rv; |
|
499 |
CK_BYTE_PTR outBufP; |
|
500 |
CK_ULONG ckLastPartLen; |
|
501 |
||
502 |
CK_FUNCTION_LIST_PTR ckpFunctions = getFunctionList(env, obj); |
|
503 |
if (ckpFunctions == NULL) { return 0; } |
|
504 |
||
505 |
ckSessionHandle = jLongToCKULong(jSessionHandle); |
|
506 |
||
507 |
if (directOut != 0) { |
|
14414
f338be3ef659
8001579: Cleanup warnings in security native code
jzavgren
parents:
6894
diff
changeset
|
508 |
outBufP = (CK_BYTE_PTR) jlong_to_ptr(directOut); |
2 | 509 |
} else { |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
510 |
outBufP = (*env)->GetPrimitiveArrayCritical(env, jOut, NULL); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
511 |
if (outBufP == NULL) { return 0; } |
2 | 512 |
} |
513 |
||
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
514 |
ckLastPartLen = jOutLen; |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
515 |
|
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
516 |
rv = (*ckpFunctions->C_DecryptFinal)(ckSessionHandle, |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
517 |
(CK_BYTE_PTR)(outBufP + jOutOfs), |
2 | 518 |
&ckLastPartLen); |
519 |
||
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
520 |
if (directOut == 0) { |
27487
106d0156648d
8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
25859
diff
changeset
|
521 |
(*env)->ReleasePrimitiveArrayCritical(env, jOut, outBufP, JNI_COMMIT); |
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
522 |
|
2 | 523 |
} |
524 |
||
6894
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
525 |
ckAssertReturnValueOK(env, rv); |
361524087cdb
6988081: Use GetPrimitiveArrayCritical instead GetByteArray to Reduce allocation in some sunpkcs jni wrappers
valeriep
parents:
5506
diff
changeset
|
526 |
|
2 | 527 |
return ckLastPartLen; |
528 |
} |
|
529 |
#endif |