1*4afad4b7Schristos /* $NetBSD: pk11_api.c,v 1.1 2024/02/18 20:57:57 christos Exp $ */
2*4afad4b7Schristos
3*4afad4b7Schristos /*
4*4afad4b7Schristos * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5*4afad4b7Schristos *
6*4afad4b7Schristos * SPDX-License-Identifier: MPL-2.0
7*4afad4b7Schristos *
8*4afad4b7Schristos * This Source Code Form is subject to the terms of the Mozilla Public
9*4afad4b7Schristos * License, v. 2.0. If a copy of the MPL was not distributed with this
10*4afad4b7Schristos * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11*4afad4b7Schristos *
12*4afad4b7Schristos * See the COPYRIGHT file distributed with this work for additional
13*4afad4b7Schristos * information regarding copyright ownership.
14*4afad4b7Schristos */
15*4afad4b7Schristos
16*4afad4b7Schristos /*! \file */
17*4afad4b7Schristos
18*4afad4b7Schristos #include <dlfcn.h>
19*4afad4b7Schristos #include <string.h>
20*4afad4b7Schristos
21*4afad4b7Schristos #include <isc/log.h>
22*4afad4b7Schristos #include <isc/mem.h>
23*4afad4b7Schristos #include <isc/once.h>
24*4afad4b7Schristos #include <isc/print.h>
25*4afad4b7Schristos #include <isc/stdio.h>
26*4afad4b7Schristos #include <isc/thread.h>
27*4afad4b7Schristos #include <isc/util.h>
28*4afad4b7Schristos
29*4afad4b7Schristos #include <pkcs11/pkcs11.h>
30*4afad4b7Schristos
31*4afad4b7Schristos #define KEEP_PKCS11_NAMES
32*4afad4b7Schristos #include <pk11/internal.h>
33*4afad4b7Schristos #include <pk11/pk11.h>
34*4afad4b7Schristos
35*4afad4b7Schristos static void *hPK11 = NULL;
36*4afad4b7Schristos static char loaderrmsg[1024];
37*4afad4b7Schristos
38*4afad4b7Schristos CK_RV
pkcs_C_Initialize(CK_VOID_PTR pReserved)39*4afad4b7Schristos pkcs_C_Initialize(CK_VOID_PTR pReserved) {
40*4afad4b7Schristos CK_C_Initialize sym;
41*4afad4b7Schristos
42*4afad4b7Schristos if (hPK11 != NULL) {
43*4afad4b7Schristos return (CKR_CRYPTOKI_ALREADY_INITIALIZED);
44*4afad4b7Schristos }
45*4afad4b7Schristos
46*4afad4b7Schristos hPK11 = dlopen(pk11_get_lib_name(), RTLD_NOW);
47*4afad4b7Schristos
48*4afad4b7Schristos if (hPK11 == NULL) {
49*4afad4b7Schristos snprintf(loaderrmsg, sizeof(loaderrmsg),
50*4afad4b7Schristos "dlopen(\"%s\") failed: %s\n", pk11_get_lib_name(),
51*4afad4b7Schristos dlerror());
52*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
53*4afad4b7Schristos }
54*4afad4b7Schristos sym = (CK_C_Initialize)dlsym(hPK11, "C_Initialize");
55*4afad4b7Schristos if (sym == NULL) {
56*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
57*4afad4b7Schristos }
58*4afad4b7Schristos return ((*sym)(pReserved));
59*4afad4b7Schristos }
60*4afad4b7Schristos
61*4afad4b7Schristos char *
pk11_get_load_error_message(void)62*4afad4b7Schristos pk11_get_load_error_message(void) {
63*4afad4b7Schristos return (loaderrmsg);
64*4afad4b7Schristos }
65*4afad4b7Schristos
66*4afad4b7Schristos CK_RV
pkcs_C_Finalize(CK_VOID_PTR pReserved)67*4afad4b7Schristos pkcs_C_Finalize(CK_VOID_PTR pReserved) {
68*4afad4b7Schristos CK_C_Finalize sym;
69*4afad4b7Schristos CK_RV rv;
70*4afad4b7Schristos
71*4afad4b7Schristos if (hPK11 == NULL) {
72*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
73*4afad4b7Schristos }
74*4afad4b7Schristos sym = (CK_C_Finalize)dlsym(hPK11, "C_Finalize");
75*4afad4b7Schristos if (sym == NULL) {
76*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
77*4afad4b7Schristos }
78*4afad4b7Schristos rv = (*sym)(pReserved);
79*4afad4b7Schristos if ((rv == CKR_OK) && (dlclose(hPK11) != 0)) {
80*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
81*4afad4b7Schristos }
82*4afad4b7Schristos hPK11 = NULL;
83*4afad4b7Schristos return (rv);
84*4afad4b7Schristos }
85*4afad4b7Schristos
86*4afad4b7Schristos CK_RV
pkcs_C_GetSlotList(CK_BBOOL tokenPresent,CK_SLOT_ID_PTR pSlotList,CK_ULONG_PTR pulCount)87*4afad4b7Schristos pkcs_C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList,
88*4afad4b7Schristos CK_ULONG_PTR pulCount) {
89*4afad4b7Schristos static CK_C_GetSlotList sym = NULL;
90*4afad4b7Schristos static void *pPK11 = NULL;
91*4afad4b7Schristos
92*4afad4b7Schristos if (hPK11 == NULL) {
93*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
94*4afad4b7Schristos }
95*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
96*4afad4b7Schristos pPK11 = hPK11;
97*4afad4b7Schristos sym = (CK_C_GetSlotList)dlsym(hPK11, "C_GetSlotList");
98*4afad4b7Schristos }
99*4afad4b7Schristos if (sym == NULL) {
100*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
101*4afad4b7Schristos }
102*4afad4b7Schristos return ((*sym)(tokenPresent, pSlotList, pulCount));
103*4afad4b7Schristos }
104*4afad4b7Schristos
105*4afad4b7Schristos CK_RV
pkcs_C_GetTokenInfo(CK_SLOT_ID slotID,CK_TOKEN_INFO_PTR pInfo)106*4afad4b7Schristos pkcs_C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) {
107*4afad4b7Schristos static CK_C_GetTokenInfo sym = NULL;
108*4afad4b7Schristos static void *pPK11 = NULL;
109*4afad4b7Schristos
110*4afad4b7Schristos if (hPK11 == NULL) {
111*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
112*4afad4b7Schristos }
113*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
114*4afad4b7Schristos pPK11 = hPK11;
115*4afad4b7Schristos sym = (CK_C_GetTokenInfo)dlsym(hPK11, "C_GetTokenInfo");
116*4afad4b7Schristos }
117*4afad4b7Schristos if (sym == NULL) {
118*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
119*4afad4b7Schristos }
120*4afad4b7Schristos return ((*sym)(slotID, pInfo));
121*4afad4b7Schristos }
122*4afad4b7Schristos
123*4afad4b7Schristos CK_RV
pkcs_C_GetMechanismInfo(CK_SLOT_ID slotID,CK_MECHANISM_TYPE type,CK_MECHANISM_INFO_PTR pInfo)124*4afad4b7Schristos pkcs_C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type,
125*4afad4b7Schristos CK_MECHANISM_INFO_PTR pInfo) {
126*4afad4b7Schristos static CK_C_GetMechanismInfo sym = NULL;
127*4afad4b7Schristos static void *pPK11 = NULL;
128*4afad4b7Schristos
129*4afad4b7Schristos if (hPK11 == NULL) {
130*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
131*4afad4b7Schristos }
132*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
133*4afad4b7Schristos pPK11 = hPK11;
134*4afad4b7Schristos sym = (CK_C_GetMechanismInfo)dlsym(hPK11, "C_GetMechanismInfo");
135*4afad4b7Schristos }
136*4afad4b7Schristos if (sym == NULL) {
137*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
138*4afad4b7Schristos }
139*4afad4b7Schristos return ((*sym)(slotID, type, pInfo));
140*4afad4b7Schristos }
141*4afad4b7Schristos
142*4afad4b7Schristos CK_RV
pkcs_C_OpenSession(CK_SLOT_ID slotID,CK_FLAGS flags,CK_VOID_PTR pApplication,CK_RV (* Notify)(CK_SESSION_HANDLE hSession,CK_NOTIFICATION event,CK_VOID_PTR pApplication),CK_SESSION_HANDLE_PTR phSession)143*4afad4b7Schristos pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication,
144*4afad4b7Schristos CK_RV (*Notify)(CK_SESSION_HANDLE hSession,
145*4afad4b7Schristos CK_NOTIFICATION event,
146*4afad4b7Schristos CK_VOID_PTR pApplication),
147*4afad4b7Schristos CK_SESSION_HANDLE_PTR phSession) {
148*4afad4b7Schristos static CK_C_OpenSession sym = NULL;
149*4afad4b7Schristos static void *pPK11 = NULL;
150*4afad4b7Schristos
151*4afad4b7Schristos if (hPK11 == NULL) {
152*4afad4b7Schristos hPK11 = dlopen(pk11_get_lib_name(), RTLD_NOW);
153*4afad4b7Schristos }
154*4afad4b7Schristos if (hPK11 == NULL) {
155*4afad4b7Schristos snprintf(loaderrmsg, sizeof(loaderrmsg),
156*4afad4b7Schristos "dlopen(\"%s\") failed: %s\n", pk11_get_lib_name(),
157*4afad4b7Schristos dlerror());
158*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
159*4afad4b7Schristos }
160*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
161*4afad4b7Schristos pPK11 = hPK11;
162*4afad4b7Schristos sym = (CK_C_OpenSession)dlsym(hPK11, "C_OpenSession");
163*4afad4b7Schristos }
164*4afad4b7Schristos if (sym == NULL) {
165*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
166*4afad4b7Schristos }
167*4afad4b7Schristos return ((*sym)(slotID, flags, pApplication, Notify, phSession));
168*4afad4b7Schristos }
169*4afad4b7Schristos
170*4afad4b7Schristos CK_RV
pkcs_C_CloseSession(CK_SESSION_HANDLE hSession)171*4afad4b7Schristos pkcs_C_CloseSession(CK_SESSION_HANDLE hSession) {
172*4afad4b7Schristos static CK_C_CloseSession sym = NULL;
173*4afad4b7Schristos static void *pPK11 = NULL;
174*4afad4b7Schristos
175*4afad4b7Schristos if (hPK11 == NULL) {
176*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
177*4afad4b7Schristos }
178*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
179*4afad4b7Schristos pPK11 = hPK11;
180*4afad4b7Schristos sym = (CK_C_CloseSession)dlsym(hPK11, "C_CloseSession");
181*4afad4b7Schristos }
182*4afad4b7Schristos if (sym == NULL) {
183*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
184*4afad4b7Schristos }
185*4afad4b7Schristos return ((*sym)(hSession));
186*4afad4b7Schristos }
187*4afad4b7Schristos
188*4afad4b7Schristos CK_RV
pkcs_C_Login(CK_SESSION_HANDLE hSession,CK_USER_TYPE userType,CK_CHAR_PTR pPin,CK_ULONG usPinLen)189*4afad4b7Schristos pkcs_C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType,
190*4afad4b7Schristos CK_CHAR_PTR pPin, CK_ULONG usPinLen) {
191*4afad4b7Schristos static CK_C_Login sym = NULL;
192*4afad4b7Schristos static void *pPK11 = NULL;
193*4afad4b7Schristos
194*4afad4b7Schristos if (hPK11 == NULL) {
195*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
196*4afad4b7Schristos }
197*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
198*4afad4b7Schristos pPK11 = hPK11;
199*4afad4b7Schristos sym = (CK_C_Login)dlsym(hPK11, "C_Login");
200*4afad4b7Schristos }
201*4afad4b7Schristos if (sym == NULL) {
202*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
203*4afad4b7Schristos }
204*4afad4b7Schristos return ((*sym)(hSession, userType, pPin, usPinLen));
205*4afad4b7Schristos }
206*4afad4b7Schristos
207*4afad4b7Schristos CK_RV
pkcs_C_Logout(CK_SESSION_HANDLE hSession)208*4afad4b7Schristos pkcs_C_Logout(CK_SESSION_HANDLE hSession) {
209*4afad4b7Schristos static CK_C_Logout sym = NULL;
210*4afad4b7Schristos static void *pPK11 = NULL;
211*4afad4b7Schristos
212*4afad4b7Schristos if (hPK11 == NULL) {
213*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
214*4afad4b7Schristos }
215*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
216*4afad4b7Schristos pPK11 = hPK11;
217*4afad4b7Schristos sym = (CK_C_Logout)dlsym(hPK11, "C_Logout");
218*4afad4b7Schristos }
219*4afad4b7Schristos if (sym == NULL) {
220*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
221*4afad4b7Schristos }
222*4afad4b7Schristos return ((*sym)(hSession));
223*4afad4b7Schristos }
224*4afad4b7Schristos
225*4afad4b7Schristos CK_RV
pkcs_C_CreateObject(CK_SESSION_HANDLE hSession,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG usCount,CK_OBJECT_HANDLE_PTR phObject)226*4afad4b7Schristos pkcs_C_CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate,
227*4afad4b7Schristos CK_ULONG usCount, CK_OBJECT_HANDLE_PTR phObject) {
228*4afad4b7Schristos static CK_C_CreateObject sym = NULL;
229*4afad4b7Schristos static void *pPK11 = NULL;
230*4afad4b7Schristos
231*4afad4b7Schristos if (hPK11 == NULL) {
232*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
233*4afad4b7Schristos }
234*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
235*4afad4b7Schristos pPK11 = hPK11;
236*4afad4b7Schristos sym = (CK_C_CreateObject)dlsym(hPK11, "C_CreateObject");
237*4afad4b7Schristos }
238*4afad4b7Schristos if (sym == NULL) {
239*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
240*4afad4b7Schristos }
241*4afad4b7Schristos return ((*sym)(hSession, pTemplate, usCount, phObject));
242*4afad4b7Schristos }
243*4afad4b7Schristos
244*4afad4b7Schristos CK_RV
pkcs_C_DestroyObject(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject)245*4afad4b7Schristos pkcs_C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) {
246*4afad4b7Schristos static CK_C_DestroyObject sym = NULL;
247*4afad4b7Schristos static void *pPK11 = NULL;
248*4afad4b7Schristos
249*4afad4b7Schristos if (hPK11 == NULL) {
250*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
251*4afad4b7Schristos }
252*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
253*4afad4b7Schristos pPK11 = hPK11;
254*4afad4b7Schristos sym = (CK_C_DestroyObject)dlsym(hPK11, "C_DestroyObject");
255*4afad4b7Schristos }
256*4afad4b7Schristos if (sym == NULL) {
257*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
258*4afad4b7Schristos }
259*4afad4b7Schristos return ((*sym)(hSession, hObject));
260*4afad4b7Schristos }
261*4afad4b7Schristos
262*4afad4b7Schristos CK_RV
pkcs_C_GetAttributeValue(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG usCount)263*4afad4b7Schristos pkcs_C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
264*4afad4b7Schristos CK_ATTRIBUTE_PTR pTemplate, CK_ULONG usCount) {
265*4afad4b7Schristos static CK_C_GetAttributeValue sym = NULL;
266*4afad4b7Schristos static void *pPK11 = NULL;
267*4afad4b7Schristos
268*4afad4b7Schristos if (hPK11 == NULL) {
269*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
270*4afad4b7Schristos }
271*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
272*4afad4b7Schristos pPK11 = hPK11;
273*4afad4b7Schristos sym = (CK_C_GetAttributeValue)dlsym(hPK11, "C_"
274*4afad4b7Schristos "GetAttributeValue");
275*4afad4b7Schristos }
276*4afad4b7Schristos if (sym == NULL) {
277*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
278*4afad4b7Schristos }
279*4afad4b7Schristos return ((*sym)(hSession, hObject, pTemplate, usCount));
280*4afad4b7Schristos }
281*4afad4b7Schristos
282*4afad4b7Schristos CK_RV
pkcs_C_SetAttributeValue(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE hObject,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG usCount)283*4afad4b7Schristos pkcs_C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
284*4afad4b7Schristos CK_ATTRIBUTE_PTR pTemplate, CK_ULONG usCount) {
285*4afad4b7Schristos static CK_C_SetAttributeValue sym = NULL;
286*4afad4b7Schristos static void *pPK11 = NULL;
287*4afad4b7Schristos
288*4afad4b7Schristos if (hPK11 == NULL) {
289*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
290*4afad4b7Schristos }
291*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
292*4afad4b7Schristos pPK11 = hPK11;
293*4afad4b7Schristos sym = (CK_C_SetAttributeValue)dlsym(hPK11, "C_"
294*4afad4b7Schristos "SetAttributeValue");
295*4afad4b7Schristos }
296*4afad4b7Schristos if (sym == NULL) {
297*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
298*4afad4b7Schristos }
299*4afad4b7Schristos return ((*sym)(hSession, hObject, pTemplate, usCount));
300*4afad4b7Schristos }
301*4afad4b7Schristos
302*4afad4b7Schristos CK_RV
pkcs_C_FindObjectsInit(CK_SESSION_HANDLE hSession,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG usCount)303*4afad4b7Schristos pkcs_C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate,
304*4afad4b7Schristos CK_ULONG usCount) {
305*4afad4b7Schristos static CK_C_FindObjectsInit sym = NULL;
306*4afad4b7Schristos static void *pPK11 = NULL;
307*4afad4b7Schristos
308*4afad4b7Schristos if (hPK11 == NULL) {
309*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
310*4afad4b7Schristos }
311*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
312*4afad4b7Schristos pPK11 = hPK11;
313*4afad4b7Schristos sym = (CK_C_FindObjectsInit)dlsym(hPK11, "C_FindObjectsInit");
314*4afad4b7Schristos }
315*4afad4b7Schristos if (sym == NULL) {
316*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
317*4afad4b7Schristos }
318*4afad4b7Schristos return ((*sym)(hSession, pTemplate, usCount));
319*4afad4b7Schristos }
320*4afad4b7Schristos
321*4afad4b7Schristos CK_RV
pkcs_C_FindObjects(CK_SESSION_HANDLE hSession,CK_OBJECT_HANDLE_PTR phObject,CK_ULONG usMaxObjectCount,CK_ULONG_PTR pusObjectCount)322*4afad4b7Schristos pkcs_C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject,
323*4afad4b7Schristos CK_ULONG usMaxObjectCount, CK_ULONG_PTR pusObjectCount) {
324*4afad4b7Schristos static CK_C_FindObjects sym = NULL;
325*4afad4b7Schristos static void *pPK11 = NULL;
326*4afad4b7Schristos
327*4afad4b7Schristos if (hPK11 == NULL) {
328*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
329*4afad4b7Schristos }
330*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
331*4afad4b7Schristos pPK11 = hPK11;
332*4afad4b7Schristos sym = (CK_C_FindObjects)dlsym(hPK11, "C_FindObjects");
333*4afad4b7Schristos }
334*4afad4b7Schristos if (sym == NULL) {
335*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
336*4afad4b7Schristos }
337*4afad4b7Schristos return ((*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount));
338*4afad4b7Schristos }
339*4afad4b7Schristos
340*4afad4b7Schristos CK_RV
pkcs_C_FindObjectsFinal(CK_SESSION_HANDLE hSession)341*4afad4b7Schristos pkcs_C_FindObjectsFinal(CK_SESSION_HANDLE hSession) {
342*4afad4b7Schristos static CK_C_FindObjectsFinal sym = NULL;
343*4afad4b7Schristos static void *pPK11 = NULL;
344*4afad4b7Schristos
345*4afad4b7Schristos if (hPK11 == NULL) {
346*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
347*4afad4b7Schristos }
348*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
349*4afad4b7Schristos pPK11 = hPK11;
350*4afad4b7Schristos sym = (CK_C_FindObjectsFinal)dlsym(hPK11, "C_FindObjectsFinal");
351*4afad4b7Schristos }
352*4afad4b7Schristos if (sym == NULL) {
353*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
354*4afad4b7Schristos }
355*4afad4b7Schristos return ((*sym)(hSession));
356*4afad4b7Schristos }
357*4afad4b7Schristos
358*4afad4b7Schristos CK_RV
pkcs_C_EncryptInit(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism,CK_OBJECT_HANDLE hKey)359*4afad4b7Schristos pkcs_C_EncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
360*4afad4b7Schristos CK_OBJECT_HANDLE hKey) {
361*4afad4b7Schristos static CK_C_EncryptInit sym = NULL;
362*4afad4b7Schristos static void *pPK11 = NULL;
363*4afad4b7Schristos
364*4afad4b7Schristos if (hPK11 == NULL) {
365*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
366*4afad4b7Schristos }
367*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
368*4afad4b7Schristos pPK11 = hPK11;
369*4afad4b7Schristos sym = (CK_C_EncryptInit)dlsym(hPK11, "C_EncryptInit");
370*4afad4b7Schristos }
371*4afad4b7Schristos if (sym == NULL) {
372*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
373*4afad4b7Schristos }
374*4afad4b7Schristos return ((*sym)(hSession, pMechanism, hKey));
375*4afad4b7Schristos }
376*4afad4b7Schristos
377*4afad4b7Schristos CK_RV
pkcs_C_Encrypt(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pData,CK_ULONG ulDataLen,CK_BYTE_PTR pEncryptedData,CK_ULONG_PTR pulEncryptedDataLen)378*4afad4b7Schristos pkcs_C_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData,
379*4afad4b7Schristos CK_ULONG ulDataLen, CK_BYTE_PTR pEncryptedData,
380*4afad4b7Schristos CK_ULONG_PTR pulEncryptedDataLen) {
381*4afad4b7Schristos static CK_C_Encrypt sym = NULL;
382*4afad4b7Schristos static void *pPK11 = NULL;
383*4afad4b7Schristos
384*4afad4b7Schristos if (hPK11 == NULL) {
385*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
386*4afad4b7Schristos }
387*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
388*4afad4b7Schristos pPK11 = hPK11;
389*4afad4b7Schristos sym = (CK_C_Encrypt)dlsym(hPK11, "C_Encrypt");
390*4afad4b7Schristos }
391*4afad4b7Schristos if (sym == NULL) {
392*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
393*4afad4b7Schristos }
394*4afad4b7Schristos return ((*sym)(hSession, pData, ulDataLen, pEncryptedData,
395*4afad4b7Schristos pulEncryptedDataLen));
396*4afad4b7Schristos }
397*4afad4b7Schristos
398*4afad4b7Schristos CK_RV
pkcs_C_DigestInit(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism)399*4afad4b7Schristos pkcs_C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism) {
400*4afad4b7Schristos static CK_C_DigestInit sym = NULL;
401*4afad4b7Schristos static void *pPK11 = NULL;
402*4afad4b7Schristos
403*4afad4b7Schristos if (hPK11 == NULL) {
404*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
405*4afad4b7Schristos }
406*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
407*4afad4b7Schristos pPK11 = hPK11;
408*4afad4b7Schristos sym = (CK_C_DigestInit)dlsym(hPK11, "C_DigestInit");
409*4afad4b7Schristos }
410*4afad4b7Schristos if (sym == NULL) {
411*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
412*4afad4b7Schristos }
413*4afad4b7Schristos return ((*sym)(hSession, pMechanism));
414*4afad4b7Schristos }
415*4afad4b7Schristos
416*4afad4b7Schristos CK_RV
pkcs_C_DigestUpdate(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pPart,CK_ULONG ulPartLen)417*4afad4b7Schristos pkcs_C_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
418*4afad4b7Schristos CK_ULONG ulPartLen) {
419*4afad4b7Schristos static CK_C_DigestUpdate sym = NULL;
420*4afad4b7Schristos static void *pPK11 = NULL;
421*4afad4b7Schristos
422*4afad4b7Schristos if (hPK11 == NULL) {
423*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
424*4afad4b7Schristos }
425*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
426*4afad4b7Schristos pPK11 = hPK11;
427*4afad4b7Schristos sym = (CK_C_DigestUpdate)dlsym(hPK11, "C_DigestUpdate");
428*4afad4b7Schristos }
429*4afad4b7Schristos if (sym == NULL) {
430*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
431*4afad4b7Schristos }
432*4afad4b7Schristos return ((*sym)(hSession, pPart, ulPartLen));
433*4afad4b7Schristos }
434*4afad4b7Schristos
435*4afad4b7Schristos CK_RV
pkcs_C_DigestFinal(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pDigest,CK_ULONG_PTR pulDigestLen)436*4afad4b7Schristos pkcs_C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest,
437*4afad4b7Schristos CK_ULONG_PTR pulDigestLen) {
438*4afad4b7Schristos static CK_C_DigestFinal sym = NULL;
439*4afad4b7Schristos static void *pPK11 = NULL;
440*4afad4b7Schristos
441*4afad4b7Schristos if (hPK11 == NULL) {
442*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
443*4afad4b7Schristos }
444*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
445*4afad4b7Schristos pPK11 = hPK11;
446*4afad4b7Schristos sym = (CK_C_DigestFinal)dlsym(hPK11, "C_DigestFinal");
447*4afad4b7Schristos }
448*4afad4b7Schristos if (sym == NULL) {
449*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
450*4afad4b7Schristos }
451*4afad4b7Schristos return ((*sym)(hSession, pDigest, pulDigestLen));
452*4afad4b7Schristos }
453*4afad4b7Schristos
454*4afad4b7Schristos CK_RV
pkcs_C_SignInit(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism,CK_OBJECT_HANDLE hKey)455*4afad4b7Schristos pkcs_C_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
456*4afad4b7Schristos CK_OBJECT_HANDLE hKey) {
457*4afad4b7Schristos static CK_C_SignInit sym = NULL;
458*4afad4b7Schristos static void *pPK11 = NULL;
459*4afad4b7Schristos
460*4afad4b7Schristos if (hPK11 == NULL) {
461*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
462*4afad4b7Schristos }
463*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
464*4afad4b7Schristos pPK11 = hPK11;
465*4afad4b7Schristos sym = (CK_C_SignInit)dlsym(hPK11, "C_SignInit");
466*4afad4b7Schristos }
467*4afad4b7Schristos if (sym == NULL) {
468*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
469*4afad4b7Schristos }
470*4afad4b7Schristos return ((*sym)(hSession, pMechanism, hKey));
471*4afad4b7Schristos }
472*4afad4b7Schristos
473*4afad4b7Schristos CK_RV
pkcs_C_Sign(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pData,CK_ULONG ulDataLen,CK_BYTE_PTR pSignature,CK_ULONG_PTR pulSignatureLen)474*4afad4b7Schristos pkcs_C_Sign(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
475*4afad4b7Schristos CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) {
476*4afad4b7Schristos static CK_C_Sign sym = NULL;
477*4afad4b7Schristos static void *pPK11 = NULL;
478*4afad4b7Schristos
479*4afad4b7Schristos if (hPK11 == NULL) {
480*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
481*4afad4b7Schristos }
482*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
483*4afad4b7Schristos pPK11 = hPK11;
484*4afad4b7Schristos sym = (CK_C_Sign)dlsym(hPK11, "C_Sign");
485*4afad4b7Schristos }
486*4afad4b7Schristos if (sym == NULL) {
487*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
488*4afad4b7Schristos }
489*4afad4b7Schristos return ((*sym)(hSession, pData, ulDataLen, pSignature,
490*4afad4b7Schristos pulSignatureLen));
491*4afad4b7Schristos }
492*4afad4b7Schristos
493*4afad4b7Schristos CK_RV
pkcs_C_SignUpdate(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pPart,CK_ULONG ulPartLen)494*4afad4b7Schristos pkcs_C_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
495*4afad4b7Schristos CK_ULONG ulPartLen) {
496*4afad4b7Schristos static CK_C_SignUpdate sym = NULL;
497*4afad4b7Schristos static void *pPK11 = NULL;
498*4afad4b7Schristos
499*4afad4b7Schristos if (hPK11 == NULL) {
500*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
501*4afad4b7Schristos }
502*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
503*4afad4b7Schristos pPK11 = hPK11;
504*4afad4b7Schristos sym = (CK_C_SignUpdate)dlsym(hPK11, "C_SignUpdate");
505*4afad4b7Schristos }
506*4afad4b7Schristos if (sym == NULL) {
507*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
508*4afad4b7Schristos }
509*4afad4b7Schristos return ((*sym)(hSession, pPart, ulPartLen));
510*4afad4b7Schristos }
511*4afad4b7Schristos
512*4afad4b7Schristos CK_RV
pkcs_C_SignFinal(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pSignature,CK_ULONG_PTR pulSignatureLen)513*4afad4b7Schristos pkcs_C_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
514*4afad4b7Schristos CK_ULONG_PTR pulSignatureLen) {
515*4afad4b7Schristos static CK_C_SignFinal sym = NULL;
516*4afad4b7Schristos static void *pPK11 = NULL;
517*4afad4b7Schristos
518*4afad4b7Schristos if (hPK11 == NULL) {
519*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
520*4afad4b7Schristos }
521*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
522*4afad4b7Schristos pPK11 = hPK11;
523*4afad4b7Schristos sym = (CK_C_SignFinal)dlsym(hPK11, "C_SignFinal");
524*4afad4b7Schristos }
525*4afad4b7Schristos if (sym == NULL) {
526*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
527*4afad4b7Schristos }
528*4afad4b7Schristos return ((*sym)(hSession, pSignature, pulSignatureLen));
529*4afad4b7Schristos }
530*4afad4b7Schristos
531*4afad4b7Schristos CK_RV
pkcs_C_VerifyInit(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism,CK_OBJECT_HANDLE hKey)532*4afad4b7Schristos pkcs_C_VerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
533*4afad4b7Schristos CK_OBJECT_HANDLE hKey) {
534*4afad4b7Schristos static CK_C_VerifyInit sym = NULL;
535*4afad4b7Schristos static void *pPK11 = NULL;
536*4afad4b7Schristos
537*4afad4b7Schristos if (hPK11 == NULL) {
538*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
539*4afad4b7Schristos }
540*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
541*4afad4b7Schristos pPK11 = hPK11;
542*4afad4b7Schristos sym = (CK_C_VerifyInit)dlsym(hPK11, "C_VerifyInit");
543*4afad4b7Schristos }
544*4afad4b7Schristos if (sym == NULL) {
545*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
546*4afad4b7Schristos }
547*4afad4b7Schristos return ((*sym)(hSession, pMechanism, hKey));
548*4afad4b7Schristos }
549*4afad4b7Schristos
550*4afad4b7Schristos CK_RV
pkcs_C_Verify(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pData,CK_ULONG ulDataLen,CK_BYTE_PTR pSignature,CK_ULONG ulSignatureLen)551*4afad4b7Schristos pkcs_C_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen,
552*4afad4b7Schristos CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen) {
553*4afad4b7Schristos static CK_C_Verify sym = NULL;
554*4afad4b7Schristos static void *pPK11 = NULL;
555*4afad4b7Schristos
556*4afad4b7Schristos if (hPK11 == NULL) {
557*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
558*4afad4b7Schristos }
559*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
560*4afad4b7Schristos pPK11 = hPK11;
561*4afad4b7Schristos sym = (CK_C_Verify)dlsym(hPK11, "C_Verify");
562*4afad4b7Schristos }
563*4afad4b7Schristos if (sym == NULL) {
564*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
565*4afad4b7Schristos }
566*4afad4b7Schristos return ((*sym)(hSession, pData, ulDataLen, pSignature, ulSignatureLen));
567*4afad4b7Schristos }
568*4afad4b7Schristos
569*4afad4b7Schristos CK_RV
pkcs_C_VerifyUpdate(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pPart,CK_ULONG ulPartLen)570*4afad4b7Schristos pkcs_C_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart,
571*4afad4b7Schristos CK_ULONG ulPartLen) {
572*4afad4b7Schristos static CK_C_VerifyUpdate sym = NULL;
573*4afad4b7Schristos static void *pPK11 = NULL;
574*4afad4b7Schristos
575*4afad4b7Schristos if (hPK11 == NULL) {
576*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
577*4afad4b7Schristos }
578*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
579*4afad4b7Schristos pPK11 = hPK11;
580*4afad4b7Schristos sym = (CK_C_VerifyUpdate)dlsym(hPK11, "C_VerifyUpdate");
581*4afad4b7Schristos }
582*4afad4b7Schristos if (sym == NULL) {
583*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
584*4afad4b7Schristos }
585*4afad4b7Schristos return ((*sym)(hSession, pPart, ulPartLen));
586*4afad4b7Schristos }
587*4afad4b7Schristos
588*4afad4b7Schristos CK_RV
pkcs_C_VerifyFinal(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pSignature,CK_ULONG ulSignatureLen)589*4afad4b7Schristos pkcs_C_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature,
590*4afad4b7Schristos CK_ULONG ulSignatureLen) {
591*4afad4b7Schristos static CK_C_VerifyFinal sym = NULL;
592*4afad4b7Schristos static void *pPK11 = NULL;
593*4afad4b7Schristos
594*4afad4b7Schristos if (hPK11 == NULL) {
595*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
596*4afad4b7Schristos }
597*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
598*4afad4b7Schristos pPK11 = hPK11;
599*4afad4b7Schristos sym = (CK_C_VerifyFinal)dlsym(hPK11, "C_VerifyFinal");
600*4afad4b7Schristos }
601*4afad4b7Schristos if (sym == NULL) {
602*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
603*4afad4b7Schristos }
604*4afad4b7Schristos return ((*sym)(hSession, pSignature, ulSignatureLen));
605*4afad4b7Schristos }
606*4afad4b7Schristos
607*4afad4b7Schristos CK_RV
pkcs_C_GenerateKey(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulCount,CK_OBJECT_HANDLE_PTR phKey)608*4afad4b7Schristos pkcs_C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
609*4afad4b7Schristos CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount,
610*4afad4b7Schristos CK_OBJECT_HANDLE_PTR phKey) {
611*4afad4b7Schristos static CK_C_GenerateKey sym = NULL;
612*4afad4b7Schristos static void *pPK11 = NULL;
613*4afad4b7Schristos
614*4afad4b7Schristos if (hPK11 == NULL) {
615*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
616*4afad4b7Schristos }
617*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
618*4afad4b7Schristos pPK11 = hPK11;
619*4afad4b7Schristos sym = (CK_C_GenerateKey)dlsym(hPK11, "C_GenerateKey");
620*4afad4b7Schristos }
621*4afad4b7Schristos if (sym == NULL) {
622*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
623*4afad4b7Schristos }
624*4afad4b7Schristos return ((*sym)(hSession, pMechanism, pTemplate, ulCount, phKey));
625*4afad4b7Schristos }
626*4afad4b7Schristos
627*4afad4b7Schristos CK_RV
pkcs_C_GenerateKeyPair(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism,CK_ATTRIBUTE_PTR pPublicKeyTemplate,CK_ULONG usPublicKeyAttributeCount,CK_ATTRIBUTE_PTR pPrivateKeyTemplate,CK_ULONG usPrivateKeyAttributeCount,CK_OBJECT_HANDLE_PTR phPrivateKey,CK_OBJECT_HANDLE_PTR phPublicKey)628*4afad4b7Schristos pkcs_C_GenerateKeyPair(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
629*4afad4b7Schristos CK_ATTRIBUTE_PTR pPublicKeyTemplate,
630*4afad4b7Schristos CK_ULONG usPublicKeyAttributeCount,
631*4afad4b7Schristos CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
632*4afad4b7Schristos CK_ULONG usPrivateKeyAttributeCount,
633*4afad4b7Schristos CK_OBJECT_HANDLE_PTR phPrivateKey,
634*4afad4b7Schristos CK_OBJECT_HANDLE_PTR phPublicKey) {
635*4afad4b7Schristos static CK_C_GenerateKeyPair sym = NULL;
636*4afad4b7Schristos static void *pPK11 = NULL;
637*4afad4b7Schristos
638*4afad4b7Schristos if (hPK11 == NULL) {
639*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
640*4afad4b7Schristos }
641*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
642*4afad4b7Schristos pPK11 = hPK11;
643*4afad4b7Schristos sym = (CK_C_GenerateKeyPair)dlsym(hPK11, "C_GenerateKeyPair");
644*4afad4b7Schristos }
645*4afad4b7Schristos if (sym == NULL) {
646*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
647*4afad4b7Schristos }
648*4afad4b7Schristos return ((*sym)(hSession, pMechanism, pPublicKeyTemplate,
649*4afad4b7Schristos usPublicKeyAttributeCount, pPrivateKeyTemplate,
650*4afad4b7Schristos usPrivateKeyAttributeCount, phPrivateKey, phPublicKey));
651*4afad4b7Schristos }
652*4afad4b7Schristos
653*4afad4b7Schristos CK_RV
pkcs_C_DeriveKey(CK_SESSION_HANDLE hSession,CK_MECHANISM_PTR pMechanism,CK_OBJECT_HANDLE hBaseKey,CK_ATTRIBUTE_PTR pTemplate,CK_ULONG ulAttributeCount,CK_OBJECT_HANDLE_PTR phKey)654*4afad4b7Schristos pkcs_C_DeriveKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism,
655*4afad4b7Schristos CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate,
656*4afad4b7Schristos CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey) {
657*4afad4b7Schristos static CK_C_DeriveKey sym = NULL;
658*4afad4b7Schristos static void *pPK11 = NULL;
659*4afad4b7Schristos
660*4afad4b7Schristos if (hPK11 == NULL) {
661*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
662*4afad4b7Schristos }
663*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
664*4afad4b7Schristos pPK11 = hPK11;
665*4afad4b7Schristos sym = (CK_C_DeriveKey)dlsym(hPK11, "C_DeriveKey");
666*4afad4b7Schristos }
667*4afad4b7Schristos if (sym == NULL) {
668*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
669*4afad4b7Schristos }
670*4afad4b7Schristos return ((*sym)(hSession, pMechanism, hBaseKey, pTemplate,
671*4afad4b7Schristos ulAttributeCount, phKey));
672*4afad4b7Schristos }
673*4afad4b7Schristos
674*4afad4b7Schristos CK_RV
pkcs_C_SeedRandom(CK_SESSION_HANDLE hSession,CK_BYTE_PTR pSeed,CK_ULONG ulSeedLen)675*4afad4b7Schristos pkcs_C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed,
676*4afad4b7Schristos CK_ULONG ulSeedLen) {
677*4afad4b7Schristos static CK_C_SeedRandom sym = NULL;
678*4afad4b7Schristos static void *pPK11 = NULL;
679*4afad4b7Schristos
680*4afad4b7Schristos if (hPK11 == NULL) {
681*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
682*4afad4b7Schristos }
683*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
684*4afad4b7Schristos pPK11 = hPK11;
685*4afad4b7Schristos sym = (CK_C_SeedRandom)dlsym(hPK11, "C_SeedRandom");
686*4afad4b7Schristos }
687*4afad4b7Schristos if (sym == NULL) {
688*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
689*4afad4b7Schristos }
690*4afad4b7Schristos return ((*sym)(hSession, pSeed, ulSeedLen));
691*4afad4b7Schristos }
692*4afad4b7Schristos
693*4afad4b7Schristos CK_RV
pkcs_C_GenerateRandom(CK_SESSION_HANDLE hSession,CK_BYTE_PTR RandomData,CK_ULONG ulRandomLen)694*4afad4b7Schristos pkcs_C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR RandomData,
695*4afad4b7Schristos CK_ULONG ulRandomLen) {
696*4afad4b7Schristos static CK_C_GenerateRandom sym = NULL;
697*4afad4b7Schristos static void *pPK11 = NULL;
698*4afad4b7Schristos
699*4afad4b7Schristos if (hPK11 == NULL) {
700*4afad4b7Schristos return (CKR_LIBRARY_LOAD_FAILED);
701*4afad4b7Schristos }
702*4afad4b7Schristos if ((sym == NULL) || (hPK11 != pPK11)) {
703*4afad4b7Schristos pPK11 = hPK11;
704*4afad4b7Schristos sym = (CK_C_GenerateRandom)dlsym(hPK11, "C_GenerateRandom");
705*4afad4b7Schristos }
706*4afad4b7Schristos if (sym == NULL) {
707*4afad4b7Schristos return (CKR_FUNCTION_NOT_SUPPORTED);
708*4afad4b7Schristos }
709*4afad4b7Schristos return ((*sym)(hSession, RandomData, ulRandomLen));
710*4afad4b7Schristos }
711