xref: /titanic_41/usr/src/lib/pkcs11/libpkcs11/common/pkcs11DualCrypt.c (revision 37714ae43602c675f9dc59b070bfdf9fa702872c)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <security/cryptoki.h>
30 #include "pkcs11Global.h"
31 #include "pkcs11Session.h"
32 #include "pkcs11Slot.h"
33 
34 /*
35  * C_DigestEncryptUpdate is a pure wrapper to the underlying provider.
36  * Policy enforcement was done earlier by the mandatory calls to
37  * C_DigestInit and C_EncryptInit.
38  *
39  * The only argument checked is whether or not hSession is valid.
40  */
41 CK_RV
42 C_DigestEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
43     CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
44     CK_ULONG_PTR pulEncryptedPartLen)
45 {
46 	CK_RV rv;
47 	pkcs11_session_t *sessp;
48 
49 	/* Check for a fastpath */
50 	if (purefastpath || policyfastpath) {
51 		return (fast_funcs->C_DigestEncryptUpdate(hSession, pPart,
52 			    ulPartLen, pEncryptedPart, pulEncryptedPartLen));
53 	}
54 
55 	if (!pkcs11_initialized) {
56 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
57 	}
58 
59 	/* Obtain the session pointer */
60 	HANDLE2SESSION(hSession, sessp, rv);
61 
62 	if (rv != CKR_OK) {
63 		return (rv);
64 	}
65 
66 	/* Pass data to the provider */
67 	rv = FUNCLIST(sessp->se_slotid)->
68 	    C_DigestEncryptUpdate(sessp->se_handle, pPart, ulPartLen,
69 		pEncryptedPart, pulEncryptedPartLen);
70 
71 	/* Present consistent interface to the application */
72 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
73 		return (CKR_FUNCTION_FAILED);
74 	}
75 
76 	return (rv);
77 
78 }
79 
80 /*
81  * C_DecryptDigestUpdate is a pure wrapper to the underlying provider.
82  * Policy enforcement was done earlier by the mandatory calls to
83  * C_DigestInit and C_DecryptInit.
84  *
85  * The only argument checked is whether or not hSession is valid.
86  */
87 CK_RV
88 C_DecryptDigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart,
89     CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen)
90 {
91 	CK_RV rv;
92 	pkcs11_session_t *sessp;
93 
94 	/* Check for a fastpath */
95 	if (purefastpath || policyfastpath) {
96 		return (fast_funcs->C_DecryptDigestUpdate(hSession,
97 			    pEncryptedPart, ulEncryptedPartLen, pPart,
98 			    pulPartLen));
99 	}
100 
101 	if (!pkcs11_initialized) {
102 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
103 	}
104 
105 	/* Obtain the session pointer */
106 	HANDLE2SESSION(hSession, sessp, rv);
107 
108 	if (rv != CKR_OK) {
109 		return (rv);
110 	}
111 
112 	/* Pass data to the provider */
113 	rv = FUNCLIST(sessp->se_slotid)->
114 	    C_DecryptDigestUpdate(sessp->se_handle, pEncryptedPart,
115 		ulEncryptedPartLen, pPart, pulPartLen);
116 
117 	/* Present consistent interface to the application */
118 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
119 		return (CKR_FUNCTION_FAILED);
120 	}
121 
122 	return (rv);
123 }
124 
125 /*
126  * C_SignEncryptUpdate is a pure wrapper to the underlying provider.
127  * Policy enforcement was done earlier by the mandatory calls to
128  * C_SignInit and C_EncryptInit.
129  *
130  * The only argument checked is whether or not hSession is valid.
131  */
132 CK_RV
133 C_SignEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
134     CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart,
135     CK_ULONG_PTR pulEncryptedPartLen)
136 {
137 	CK_RV rv;
138 	pkcs11_session_t *sessp;
139 
140 	/* Check for a fastpath */
141 	if (purefastpath || policyfastpath) {
142 		return (fast_funcs->C_SignEncryptUpdate(hSession, pPart,
143 			    ulPartLen,  pEncryptedPart, pulEncryptedPartLen));
144 	}
145 
146 	if (!pkcs11_initialized) {
147 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
148 	}
149 
150 	/* Obtain the session pointer */
151 	HANDLE2SESSION(hSession, sessp, rv);
152 
153 	if (rv != CKR_OK) {
154 		return (rv);
155 	}
156 
157 	/* Pass data to the provider */
158 	rv = FUNCLIST(sessp->se_slotid)->
159 	    C_SignEncryptUpdate(sessp->se_handle, pPart, ulPartLen,
160 		pEncryptedPart, pulEncryptedPartLen);
161 
162 	/* Present consistent interface to the application */
163 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
164 		return (CKR_FUNCTION_FAILED);
165 	}
166 
167 	return (rv);
168 }
169 
170 /*
171  * C_DecryptVerifyUpdate is a pure wrapper to the underlying provider.
172  * Policy enforcement was done earlier by the mandatory calls to
173  * C_SignInit and C_EncryptInit.
174  *
175  * The only argument checked is whether or not hSession is valid.
176  */
177 CK_RV
178 C_DecryptVerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pEncryptedPart,
179     CK_ULONG ulEncryptedPartLen, CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen)
180 {
181 	CK_RV rv;
182 	pkcs11_session_t *sessp;
183 
184 	/* Check for a fastpath */
185 	if (purefastpath || policyfastpath) {
186 		return (fast_funcs->C_DecryptVerifyUpdate(hSession,
187 			    pEncryptedPart, ulEncryptedPartLen, pPart,
188 			    pulPartLen));
189 	}
190 
191 	if (!pkcs11_initialized) {
192 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
193 	}
194 
195 	/* Obtain the session pointer */
196 	HANDLE2SESSION(hSession, sessp, rv);
197 
198 	if (rv != CKR_OK) {
199 		return (rv);
200 	}
201 
202 	/* Pass data to the provider */
203 	rv = FUNCLIST(sessp->se_slotid)->
204 	    C_DecryptVerifyUpdate(sessp->se_handle, pEncryptedPart,
205 		ulEncryptedPartLen, pPart, pulPartLen);
206 
207 	/* Present consistent interface to the application */
208 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
209 		return (CKR_FUNCTION_FAILED);
210 	}
211 
212 	return (rv);
213 }
214