1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include <security/cryptoki.h>
28*7c478bd9Sstevel@tonic-gate #include "pkcs11Global.h"
29*7c478bd9Sstevel@tonic-gate #include "pkcs11Session.h"
30*7c478bd9Sstevel@tonic-gate #include "pkcs11Slot.h"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  * C_CreateObject is a pure wrapper to the underlying provider.
34*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate CK_RV
C_CreateObject(CK_SESSION_HANDLE hSession,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulCount,CK_OBJECT_HANDLE_PTR phObject)37*7c478bd9Sstevel@tonic-gate C_CreateObject(CK_SESSION_HANDLE hSession,
38*7c478bd9Sstevel@tonic-gate     CK_ATTRIBUTE_PTR pTemplate,
39*7c478bd9Sstevel@tonic-gate     CK_ULONG ulCount,
40*7c478bd9Sstevel@tonic-gate     CK_OBJECT_HANDLE_PTR phObject)
41*7c478bd9Sstevel@tonic-gate {
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
44*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
47*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
48*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_CreateObject(hSession, pTemplate,
49*7c478bd9Sstevel@tonic-gate 			    ulCount, phObject));
50*7c478bd9Sstevel@tonic-gate 	}
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
53*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
54*7c478bd9Sstevel@tonic-gate 	}
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
57*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
60*7c478bd9Sstevel@tonic-gate 		return (rv);
61*7c478bd9Sstevel@tonic-gate 	}
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
64*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_CreateObject(sessp->se_handle,
65*7c478bd9Sstevel@tonic-gate 	    pTemplate, ulCount, phObject);
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
68*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
69*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
70*7c478bd9Sstevel@tonic-gate 	}
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	return (rv);
73*7c478bd9Sstevel@tonic-gate }
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate /*
76*7c478bd9Sstevel@tonic-gate  * C_CopyObject is a pure wrapper to the underlying provider.
77*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate CK_RV
C_CopyObject(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulCount,CK_OBJECT_HANDLE_PTR phNewObject)80*7c478bd9Sstevel@tonic-gate C_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
81*7c478bd9Sstevel@tonic-gate     CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
82*7c478bd9Sstevel@tonic-gate     CK_OBJECT_HANDLE_PTR phNewObject)
83*7c478bd9Sstevel@tonic-gate {
84*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
85*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
88*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
89*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_CopyObject(hSession, hObject,
90*7c478bd9Sstevel@tonic-gate 			    pTemplate, ulCount, phNewObject));
91*7c478bd9Sstevel@tonic-gate 	}
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
94*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
95*7c478bd9Sstevel@tonic-gate 	}
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
98*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
101*7c478bd9Sstevel@tonic-gate 		return (rv);
102*7c478bd9Sstevel@tonic-gate 	}
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
105*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_CopyObject(sessp->se_handle,
106*7c478bd9Sstevel@tonic-gate 	    hObject, pTemplate, ulCount, phNewObject);
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
109*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
110*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
111*7c478bd9Sstevel@tonic-gate 	}
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	return (rv);
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /*
117*7c478bd9Sstevel@tonic-gate  * C_DestroyObject is a pure wrapper to the underlying provider.
118*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
119*7c478bd9Sstevel@tonic-gate  */
120*7c478bd9Sstevel@tonic-gate CK_RV
C_DestroyObject(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject)121*7c478bd9Sstevel@tonic-gate C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
124*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
127*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
128*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_DestroyObject(hSession, hObject));
129*7c478bd9Sstevel@tonic-gate 	}
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
132*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
133*7c478bd9Sstevel@tonic-gate 	}
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
136*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
139*7c478bd9Sstevel@tonic-gate 		return (rv);
140*7c478bd9Sstevel@tonic-gate 	}
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
143*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_DestroyObject(sessp->se_handle,
144*7c478bd9Sstevel@tonic-gate 	    hObject);
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
147*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
148*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
149*7c478bd9Sstevel@tonic-gate 	}
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	return (rv);
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate /*
155*7c478bd9Sstevel@tonic-gate  * C_GetAttributeValue is a pure wrapper to the underlying provider.
156*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
157*7c478bd9Sstevel@tonic-gate  */
158*7c478bd9Sstevel@tonic-gate CK_RV
C_GetAttributeValue(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulCount)159*7c478bd9Sstevel@tonic-gate C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
160*7c478bd9Sstevel@tonic-gate     CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
161*7c478bd9Sstevel@tonic-gate {
162*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
163*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
166*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
167*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_GetAttributeValue(hSession, hObject,
168*7c478bd9Sstevel@tonic-gate 			    pTemplate, ulCount));
169*7c478bd9Sstevel@tonic-gate 	}
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
172*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
173*7c478bd9Sstevel@tonic-gate 	}
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
176*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
179*7c478bd9Sstevel@tonic-gate 		return (rv);
180*7c478bd9Sstevel@tonic-gate 	}
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
183*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_GetAttributeValue(sessp->se_handle,
184*7c478bd9Sstevel@tonic-gate 	    hObject, pTemplate, ulCount);
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
187*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
188*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	return (rv);
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate /*
196*7c478bd9Sstevel@tonic-gate  * C_SetAttributeValue is a pure wrapper to the underlying provider.
197*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
198*7c478bd9Sstevel@tonic-gate  */
199*7c478bd9Sstevel@tonic-gate CK_RV
C_SetAttributeValue(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulCount)200*7c478bd9Sstevel@tonic-gate C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
201*7c478bd9Sstevel@tonic-gate     CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount)
202*7c478bd9Sstevel@tonic-gate {
203*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
204*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
207*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
208*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_SetAttributeValue(hSession, hObject,
209*7c478bd9Sstevel@tonic-gate 			    pTemplate, ulCount));
210*7c478bd9Sstevel@tonic-gate 	}
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
213*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
214*7c478bd9Sstevel@tonic-gate 	}
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
217*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
220*7c478bd9Sstevel@tonic-gate 		return (rv);
221*7c478bd9Sstevel@tonic-gate 	}
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
224*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_SetAttributeValue(sessp->se_handle,
225*7c478bd9Sstevel@tonic-gate 	    hObject, pTemplate, ulCount);
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
228*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
229*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
230*7c478bd9Sstevel@tonic-gate 	}
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 	return (rv);
233*7c478bd9Sstevel@tonic-gate }
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate /*
236*7c478bd9Sstevel@tonic-gate  * C_GetObjectSize is a pure wrapper to the underlying provider.
237*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
238*7c478bd9Sstevel@tonic-gate  */
239*7c478bd9Sstevel@tonic-gate CK_RV
C_GetObjectSize(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject,CK_ULONG_PTR pulSize)240*7c478bd9Sstevel@tonic-gate C_GetObjectSize(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
241*7c478bd9Sstevel@tonic-gate     CK_ULONG_PTR pulSize)
242*7c478bd9Sstevel@tonic-gate {
243*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
244*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
247*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
248*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_GetObjectSize(hSession, hObject,
249*7c478bd9Sstevel@tonic-gate 			    pulSize));
250*7c478bd9Sstevel@tonic-gate 	}
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
253*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
254*7c478bd9Sstevel@tonic-gate 	}
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
257*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
260*7c478bd9Sstevel@tonic-gate 		return (rv);
261*7c478bd9Sstevel@tonic-gate 	}
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
264*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_GetObjectSize(sessp->se_handle,
265*7c478bd9Sstevel@tonic-gate 	    hObject, pulSize);
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
268*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
269*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
270*7c478bd9Sstevel@tonic-gate 	}
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate 	return (rv);
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate /*
276*7c478bd9Sstevel@tonic-gate  * C_FindObjectsInit is a pure wrapper to the underlying provider.
277*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
278*7c478bd9Sstevel@tonic-gate  */
279*7c478bd9Sstevel@tonic-gate CK_RV
C_FindObjectsInit(CK_SESSION_HANDLE hSession,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulCount)280*7c478bd9Sstevel@tonic-gate C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate,
281*7c478bd9Sstevel@tonic-gate     CK_ULONG ulCount)
282*7c478bd9Sstevel@tonic-gate {
283*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
284*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
287*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
288*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_FindObjectsInit(hSession, pTemplate,
289*7c478bd9Sstevel@tonic-gate 			    ulCount));
290*7c478bd9Sstevel@tonic-gate 	}
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
293*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
294*7c478bd9Sstevel@tonic-gate 	}
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
297*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
300*7c478bd9Sstevel@tonic-gate 		return (rv);
301*7c478bd9Sstevel@tonic-gate 	}
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
304*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_FindObjectsInit(sessp->se_handle,
305*7c478bd9Sstevel@tonic-gate 	    pTemplate, ulCount);
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
308*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
309*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
310*7c478bd9Sstevel@tonic-gate 	}
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 	return (rv);
313*7c478bd9Sstevel@tonic-gate }
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate /*
316*7c478bd9Sstevel@tonic-gate  * C_FindObjects is a pure wrapper to the underlying provider.
317*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
318*7c478bd9Sstevel@tonic-gate  */
319*7c478bd9Sstevel@tonic-gate CK_RV
C_FindObjects(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE_PTR phObject,CK_ULONG ulMaxObjectCount,CK_ULONG_PTR pulObjectCount)320*7c478bd9Sstevel@tonic-gate C_FindObjects(CK_SESSION_HANDLE hSession,
321*7c478bd9Sstevel@tonic-gate     CK_OBJECT_HANDLE_PTR phObject,
322*7c478bd9Sstevel@tonic-gate     CK_ULONG ulMaxObjectCount,
323*7c478bd9Sstevel@tonic-gate     CK_ULONG_PTR pulObjectCount)
324*7c478bd9Sstevel@tonic-gate {
325*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
326*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
327*7c478bd9Sstevel@tonic-gate 
328*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
329*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
330*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_FindObjects(hSession, phObject,
331*7c478bd9Sstevel@tonic-gate 			    ulMaxObjectCount, pulObjectCount));
332*7c478bd9Sstevel@tonic-gate 	}
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
335*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
336*7c478bd9Sstevel@tonic-gate 	}
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
339*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
342*7c478bd9Sstevel@tonic-gate 		return (rv);
343*7c478bd9Sstevel@tonic-gate 	}
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
346*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_FindObjects(sessp->se_handle,
347*7c478bd9Sstevel@tonic-gate 	    phObject, ulMaxObjectCount, pulObjectCount);
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
350*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
351*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
352*7c478bd9Sstevel@tonic-gate 	}
353*7c478bd9Sstevel@tonic-gate 
354*7c478bd9Sstevel@tonic-gate 	return (rv);
355*7c478bd9Sstevel@tonic-gate }
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate /*
358*7c478bd9Sstevel@tonic-gate  * C_FindObjectsFinal is a pure wrapper to the underlying provider.
359*7c478bd9Sstevel@tonic-gate  * The only argument checked is whether or not hSession is valid.
360*7c478bd9Sstevel@tonic-gate  */
361*7c478bd9Sstevel@tonic-gate CK_RV
C_FindObjectsFinal(CK_SESSION_HANDLE hSession)362*7c478bd9Sstevel@tonic-gate C_FindObjectsFinal(CK_SESSION_HANDLE hSession)
363*7c478bd9Sstevel@tonic-gate {
364*7c478bd9Sstevel@tonic-gate 	CK_RV rv;
365*7c478bd9Sstevel@tonic-gate 	pkcs11_session_t *sessp;
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate 	/* Check for a fastpath */
368*7c478bd9Sstevel@tonic-gate 	if (purefastpath || policyfastpath) {
369*7c478bd9Sstevel@tonic-gate 		return (fast_funcs->C_FindObjectsFinal(hSession));
370*7c478bd9Sstevel@tonic-gate 	}
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate 	if (!pkcs11_initialized) {
373*7c478bd9Sstevel@tonic-gate 		return (CKR_CRYPTOKI_NOT_INITIALIZED);
374*7c478bd9Sstevel@tonic-gate 	}
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate 	/* Obtain the session pointer */
377*7c478bd9Sstevel@tonic-gate 	HANDLE2SESSION(hSession, sessp, rv);
378*7c478bd9Sstevel@tonic-gate 
379*7c478bd9Sstevel@tonic-gate 	if (rv != CKR_OK) {
380*7c478bd9Sstevel@tonic-gate 		return (rv);
381*7c478bd9Sstevel@tonic-gate 	}
382*7c478bd9Sstevel@tonic-gate 
383*7c478bd9Sstevel@tonic-gate 	/* Pass data to the provider */
384*7c478bd9Sstevel@tonic-gate 	rv = FUNCLIST(sessp->se_slotid)->C_FindObjectsFinal(sessp->se_handle);
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate 	/* Present consistent interface to the application */
387*7c478bd9Sstevel@tonic-gate 	if (rv == CKR_FUNCTION_NOT_SUPPORTED) {
388*7c478bd9Sstevel@tonic-gate 		return (CKR_FUNCTION_FAILED);
389*7c478bd9Sstevel@tonic-gate 	}
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate 	return (rv);
392*7c478bd9Sstevel@tonic-gate }
393