Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / isc / win32 / pk11_api.c
blob102c2bcd69bcd48daf3d82161876bba92cf25d15
1 /* $NetBSD: pk11_api.c,v 1.1.1.4 2014/12/10 03:34:45 christos Exp $ */
3 /*
4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
19 /* Id */
21 /*! \file */
23 /* missing code for WIN32 */
25 #include <config.h>
27 #include <string.h>
28 #include <windows.h>
30 #include <isc/log.h>
31 #include <isc/mem.h>
32 #include <isc/once.h>
33 #include <isc/stdio.h>
34 #include <isc/thread.h>
35 #include <isc/util.h>
37 #include <pk11/pk11.h>
38 #include <pk11/internal.h>
40 #define HAVE_GETPASSPHRASE
42 char *
43 getpassphrase(const char *prompt) {
44 static char buf[128];
45 HANDLE h;
46 DWORD cc, mode;
47 int cnt;
49 h = GetStdHandle(STD_INPUT_HANDLE);
50 fputs(prompt, stderr);
51 fflush(stderr);
52 fflush(stdout);
53 FlushConsoleInputBuffer(h);
54 GetConsoleMode(h, &mode);
55 SetConsoleMode(h, ENABLE_PROCESSED_INPUT);
57 for (cnt = 0; cnt < sizeof(buf) - 1; cnt++)
59 ReadFile(h, buf + cnt, 1, &cc, NULL);
60 if (buf[cnt] == '\r')
61 break;
62 fputc('*', stdout);
63 fflush(stderr);
64 fflush(stdout);
67 SetConsoleMode(h, mode);
68 buf[cnt] = '\0';
69 fputs("\n", stderr);
70 return (buf);
73 /* load PKCS11 DLL */
75 static HINSTANCE hPK11 = NULL;
77 CK_RV
78 pkcs_C_Initialize(CK_VOID_PTR pReserved) {
79 CK_C_Initialize sym;
80 const char *lib_name = pk11_get_lib_name();
82 if (hPK11 != NULL)
83 return (CKR_LIBRARY_ALREADY_INITIALIZED);
85 if (lib_name == NULL)
86 return (CKR_LIBRARY_FAILED_TO_LOAD);
87 /* Visual Studio convertion issue... */
88 if (*lib_name == ' ')
89 lib_name++;
91 hPK11 = LoadLibraryA(lib_name);
93 if (hPK11 == NULL)
94 return (CKR_LIBRARY_FAILED_TO_LOAD);
95 sym = (CK_C_Initialize)GetProcAddress(hPK11, "C_Initialize");
96 if (sym == NULL)
97 return (CKR_SYMBOL_RESOLUTION_FAILED);
98 return (*sym)(pReserved);
101 CK_RV
102 pkcs_C_Finalize(CK_VOID_PTR pReserved) {
103 CK_C_Finalize sym;
104 CK_RV rv;
106 if (hPK11 == NULL)
107 return (CKR_LIBRARY_FAILED_TO_LOAD);
108 sym = (CK_C_Finalize)GetProcAddress(hPK11, "C_Finalize");
109 if (sym == NULL)
110 return (CKR_SYMBOL_RESOLUTION_FAILED);
111 rv = (*sym)(pReserved);
112 if ((rv == CKR_OK) && (FreeLibrary(hPK11) == 0))
113 return (CKR_LIBRARY_FAILED_TO_LOAD);
114 hPK11 = NULL;
115 return (rv);
118 CK_RV
119 pkcs_C_GetSlotList(CK_BBOOL tokenPresent,
120 CK_SLOT_ID_PTR pSlotList,
121 CK_ULONG_PTR pulCount)
123 static CK_C_GetSlotList sym = NULL;
125 if (hPK11 == NULL)
126 return (CKR_LIBRARY_FAILED_TO_LOAD);
127 if (sym == NULL)
128 sym = (CK_C_GetSlotList)GetProcAddress(hPK11, "C_GetSlotList");
129 if (sym == NULL)
130 return (CKR_SYMBOL_RESOLUTION_FAILED);
131 return (*sym)(tokenPresent, pSlotList, pulCount);
134 CK_RV
135 pkcs_C_GetTokenInfo(CK_SLOT_ID slotID,
136 CK_TOKEN_INFO_PTR pInfo)
138 static CK_C_GetTokenInfo sym = NULL;
140 if (hPK11 == NULL)
141 return (CKR_LIBRARY_FAILED_TO_LOAD);
142 if (sym == NULL)
143 sym = (CK_C_GetTokenInfo)GetProcAddress(hPK11,
144 "C_GetTokenInfo");
145 if (sym == NULL)
146 return (CKR_SYMBOL_RESOLUTION_FAILED);
147 return (*sym)(slotID, pInfo);
150 CK_RV
151 pkcs_C_GetMechanismInfo(CK_SLOT_ID slotID,
152 CK_MECHANISM_TYPE type,
153 CK_MECHANISM_INFO_PTR pInfo)
155 static CK_C_GetMechanismInfo sym = NULL;
157 if (hPK11 == NULL)
158 return (CKR_LIBRARY_FAILED_TO_LOAD);
159 if (sym == NULL)
160 sym = (CK_C_GetMechanismInfo)GetProcAddress(hPK11,
161 "C_GetMechanismInfo");
162 if (sym == NULL)
163 return (CKR_SYMBOL_RESOLUTION_FAILED);
164 return (*sym)(slotID, type, pInfo);
167 CK_RV
168 pkcs_C_OpenSession(CK_SLOT_ID slotID,
169 CK_FLAGS flags,
170 CK_VOID_PTR pApplication,
171 CK_RV (*Notify) (CK_SESSION_HANDLE hSession,
172 CK_NOTIFICATION event,
173 CK_VOID_PTR pApplication),
174 CK_SESSION_HANDLE_PTR phSession)
176 static CK_C_OpenSession sym = NULL;
178 if (hPK11 == NULL)
179 hPK11 = LoadLibraryA(pk11_get_lib_name());
180 if (hPK11 == NULL)
181 return (CKR_LIBRARY_FAILED_TO_LOAD);
182 if (sym == NULL)
183 sym = (CK_C_OpenSession)GetProcAddress(hPK11, "C_OpenSession");
184 if (sym == NULL)
185 return (CKR_SYMBOL_RESOLUTION_FAILED);
186 return (*sym)(slotID, flags, pApplication, Notify, phSession);
189 CK_RV
190 pkcs_C_CloseSession(CK_SESSION_HANDLE hSession) {
191 static CK_C_CloseSession sym = NULL;
193 if (hPK11 == NULL)
194 return (CKR_LIBRARY_FAILED_TO_LOAD);
195 if (sym == NULL)
196 sym = (CK_C_CloseSession)GetProcAddress(hPK11,
197 "C_CloseSession");
198 if (sym == NULL)
199 return (CKR_SYMBOL_RESOLUTION_FAILED);
200 return (*sym)(hSession);
203 CK_RV
204 pkcs_C_Login(CK_SESSION_HANDLE hSession,
205 CK_USER_TYPE userType,
206 CK_CHAR_PTR pPin,
207 CK_ULONG usPinLen)
209 static CK_C_Login sym = NULL;
211 if (hPK11 == NULL)
212 return (CKR_LIBRARY_FAILED_TO_LOAD);
213 if (sym == NULL)
214 sym = (CK_C_Login)GetProcAddress(hPK11, "C_Login");
215 if (sym == NULL)
216 return (CKR_SYMBOL_RESOLUTION_FAILED);
217 return (*sym)(hSession, userType, pPin, usPinLen);
220 CK_RV
221 pkcs_C_Logout(CK_SESSION_HANDLE hSession) {
222 static CK_C_Logout sym = NULL;
224 if (hPK11 == NULL)
225 return (CKR_LIBRARY_FAILED_TO_LOAD);
226 if (sym == NULL)
227 sym = (CK_C_Logout)GetProcAddress(hPK11, "C_Logout");
228 if (sym == NULL)
229 return (CKR_SYMBOL_RESOLUTION_FAILED);
230 return (*sym)(hSession);
233 CK_RV
234 pkcs_C_CreateObject(CK_SESSION_HANDLE hSession,
235 CK_ATTRIBUTE_PTR pTemplate,
236 CK_ULONG usCount,
237 CK_OBJECT_HANDLE_PTR phObject)
239 static CK_C_CreateObject sym = NULL;
241 if (hPK11 == NULL)
242 return (CKR_LIBRARY_FAILED_TO_LOAD);
243 if (sym == NULL)
244 sym = (CK_C_CreateObject)GetProcAddress(hPK11,
245 "C_CreateObject");
246 if (sym == NULL)
247 return (CKR_SYMBOL_RESOLUTION_FAILED);
248 return (*sym)(hSession, pTemplate, usCount, phObject);
251 CK_RV
252 pkcs_C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) {
253 static CK_C_DestroyObject sym = NULL;
255 if (hPK11 == NULL)
256 return (CKR_LIBRARY_FAILED_TO_LOAD);
257 if (sym == NULL)
258 sym = (CK_C_DestroyObject)GetProcAddress(hPK11,
259 "C_DestroyObject");
260 if (sym == NULL)
261 return (CKR_SYMBOL_RESOLUTION_FAILED);
262 return (*sym)(hSession, hObject);
265 CK_RV
266 pkcs_C_GetAttributeValue(CK_SESSION_HANDLE hSession,
267 CK_OBJECT_HANDLE hObject,
268 CK_ATTRIBUTE_PTR pTemplate,
269 CK_ULONG usCount)
271 static CK_C_GetAttributeValue sym = NULL;
273 if (hPK11 == NULL)
274 return (CKR_LIBRARY_FAILED_TO_LOAD);
275 if (sym == NULL)
276 sym = (CK_C_GetAttributeValue)GetProcAddress(hPK11,
277 "C_GetAttributeValue");
278 if (sym == NULL)
279 return (CKR_SYMBOL_RESOLUTION_FAILED);
280 return (*sym)(hSession, hObject, pTemplate, usCount);
283 CK_RV
284 pkcs_C_SetAttributeValue(CK_SESSION_HANDLE hSession,
285 CK_OBJECT_HANDLE hObject,
286 CK_ATTRIBUTE_PTR pTemplate,
287 CK_ULONG usCount)
289 static CK_C_SetAttributeValue sym = NULL;
291 if (hPK11 == NULL)
292 return (CKR_LIBRARY_FAILED_TO_LOAD);
293 if (sym == NULL)
294 sym = (CK_C_SetAttributeValue)GetProcAddress(hPK11,
295 "C_SetAttributeValue");
296 if (sym == NULL)
297 return (CKR_SYMBOL_RESOLUTION_FAILED);
298 return (*sym)(hSession, hObject, pTemplate, usCount);
301 CK_RV
302 pkcs_C_FindObjectsInit(CK_SESSION_HANDLE hSession,
303 CK_ATTRIBUTE_PTR pTemplate,
304 CK_ULONG usCount)
306 static CK_C_FindObjectsInit sym = NULL;
308 if (hPK11 == NULL)
309 return (CKR_LIBRARY_FAILED_TO_LOAD);
310 if (sym == NULL)
311 sym = (CK_C_FindObjectsInit)GetProcAddress(hPK11,
312 "C_FindObjectsInit");
313 if (sym == NULL)
314 return (CKR_SYMBOL_RESOLUTION_FAILED);
315 return (*sym)(hSession, pTemplate, usCount);
318 CK_RV
319 pkcs_C_FindObjects(CK_SESSION_HANDLE hSession,
320 CK_OBJECT_HANDLE_PTR phObject,
321 CK_ULONG usMaxObjectCount,
322 CK_ULONG_PTR pusObjectCount)
324 static CK_C_FindObjects sym = NULL;
326 if (hPK11 == NULL)
327 return (CKR_LIBRARY_FAILED_TO_LOAD);
328 if (sym == NULL)
329 sym = (CK_C_FindObjects)GetProcAddress(hPK11, "C_FindObjects");
330 if (sym == NULL)
331 return (CKR_SYMBOL_RESOLUTION_FAILED);
332 return (*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount);
335 CK_RV
336 pkcs_C_FindObjectsFinal(CK_SESSION_HANDLE hSession) {
337 static CK_C_FindObjectsFinal sym = NULL;
339 if (hPK11 == NULL)
340 return (CKR_LIBRARY_FAILED_TO_LOAD);
341 if (sym == NULL)
342 sym = (CK_C_FindObjectsFinal)GetProcAddress(hPK11,
343 "C_FindObjectsFinal");
344 if (sym == NULL)
345 return (CKR_SYMBOL_RESOLUTION_FAILED);
346 return (*sym)(hSession);
349 CK_RV
350 pkcs_C_EncryptInit(CK_SESSION_HANDLE hSession,
351 CK_MECHANISM_PTR pMechanism,
352 CK_OBJECT_HANDLE hKey)
354 static CK_C_EncryptInit sym = NULL;
356 if (hPK11 == NULL)
357 return (CKR_LIBRARY_FAILED_TO_LOAD);
358 if (sym == NULL)
359 sym = (CK_C_EncryptInit)GetProcAddress(hPK11, "C_EncryptInit");
360 if (sym == NULL)
361 return (CKR_SYMBOL_RESOLUTION_FAILED);
362 return (*sym)(hSession, pMechanism, hKey);
365 CK_RV
366 pkcs_C_Encrypt(CK_SESSION_HANDLE hSession,
367 CK_BYTE_PTR pData,
368 CK_ULONG ulDataLen,
369 CK_BYTE_PTR pEncryptedData,
370 CK_ULONG_PTR pulEncryptedDataLen)
372 static CK_C_Encrypt sym = NULL;
374 if (hPK11 == NULL)
375 return (CKR_LIBRARY_FAILED_TO_LOAD);
376 if (sym == NULL)
377 sym = (CK_C_Encrypt)GetProcAddress(hPK11, "C_Encrypt");
378 if (sym == NULL)
379 return (CKR_SYMBOL_RESOLUTION_FAILED);
380 return (*sym)(hSession, pData, ulDataLen,
381 pEncryptedData, pulEncryptedDataLen);
384 CK_RV
385 pkcs_C_DigestInit(CK_SESSION_HANDLE hSession,
386 CK_MECHANISM_PTR pMechanism)
388 static CK_C_DigestInit sym = NULL;
390 if (hPK11 == NULL)
391 return (CKR_LIBRARY_FAILED_TO_LOAD);
392 if (sym == NULL)
393 sym = (CK_C_DigestInit)GetProcAddress(hPK11, "C_DigestInit");
394 if (sym == NULL)
395 return (CKR_SYMBOL_RESOLUTION_FAILED);
396 return (*sym)(hSession, pMechanism);
399 CK_RV
400 pkcs_C_DigestUpdate(CK_SESSION_HANDLE hSession,
401 CK_BYTE_PTR pPart,
402 CK_ULONG ulPartLen)
404 static CK_C_DigestUpdate sym = NULL;
406 if (hPK11 == NULL)
407 return (CKR_LIBRARY_FAILED_TO_LOAD);
408 if (sym == NULL)
409 sym = (CK_C_DigestUpdate)GetProcAddress(hPK11,
410 "C_DigestUpdate");
411 if (sym == NULL)
412 return (CKR_SYMBOL_RESOLUTION_FAILED);
413 return (*sym)(hSession, pPart, ulPartLen);
416 CK_RV
417 pkcs_C_DigestFinal(CK_SESSION_HANDLE hSession,
418 CK_BYTE_PTR pDigest,
419 CK_ULONG_PTR pulDigestLen)
421 static CK_C_DigestFinal sym = NULL;
423 if (hPK11 == NULL)
424 return (CKR_LIBRARY_FAILED_TO_LOAD);
425 if (sym == NULL)
426 sym = (CK_C_DigestFinal)GetProcAddress(hPK11, "C_DigestFinal");
427 if (sym == NULL)
428 return (CKR_SYMBOL_RESOLUTION_FAILED);
429 return (*sym)(hSession, pDigest, pulDigestLen);
432 CK_RV
433 pkcs_C_SignInit(CK_SESSION_HANDLE hSession,
434 CK_MECHANISM_PTR pMechanism,
435 CK_OBJECT_HANDLE hKey)
437 static CK_C_SignInit sym = NULL;
439 if (hPK11 == NULL)
440 return (CKR_LIBRARY_FAILED_TO_LOAD);
441 if (sym == NULL)
442 sym = (CK_C_SignInit)GetProcAddress(hPK11, "C_SignInit");
443 if (sym == NULL)
444 return (CKR_SYMBOL_RESOLUTION_FAILED);
445 return (*sym)(hSession, pMechanism, hKey);
448 CK_RV
449 pkcs_C_Sign(CK_SESSION_HANDLE hSession,
450 CK_BYTE_PTR pData,
451 CK_ULONG ulDataLen,
452 CK_BYTE_PTR pSignature,
453 CK_ULONG_PTR pulSignatureLen)
455 static CK_C_Sign sym = NULL;
457 if (hPK11 == NULL)
458 return (CKR_LIBRARY_FAILED_TO_LOAD);
459 if (sym == NULL)
460 sym = (CK_C_Sign)GetProcAddress(hPK11, "C_Sign");
461 if (sym == NULL)
462 return (CKR_SYMBOL_RESOLUTION_FAILED);
463 return (*sym)(hSession, pData, ulDataLen, pSignature, pulSignatureLen);
466 CK_RV
467 pkcs_C_SignUpdate(CK_SESSION_HANDLE hSession,
468 CK_BYTE_PTR pPart,
469 CK_ULONG ulPartLen)
471 static CK_C_SignUpdate sym = NULL;
473 if (hPK11 == NULL)
474 return (CKR_LIBRARY_FAILED_TO_LOAD);
475 if (sym == NULL)
476 sym = (CK_C_SignUpdate)GetProcAddress(hPK11, "C_SignUpdate");
477 if (sym == NULL)
478 return (CKR_SYMBOL_RESOLUTION_FAILED);
479 return (*sym)(hSession, pPart, ulPartLen);
482 CK_RV
483 pkcs_C_SignFinal(CK_SESSION_HANDLE hSession,
484 CK_BYTE_PTR pSignature,
485 CK_ULONG_PTR pulSignatureLen)
487 static CK_C_SignFinal sym = NULL;
489 if (hPK11 == NULL)
490 return (CKR_LIBRARY_FAILED_TO_LOAD);
491 if (sym == NULL)
492 sym = (CK_C_SignFinal)GetProcAddress(hPK11, "C_SignFinal");
493 if (sym == NULL)
494 return (CKR_SYMBOL_RESOLUTION_FAILED);
495 return (*sym)(hSession, pSignature, pulSignatureLen);
498 CK_RV
499 pkcs_C_VerifyInit(CK_SESSION_HANDLE hSession,
500 CK_MECHANISM_PTR pMechanism,
501 CK_OBJECT_HANDLE hKey)
503 static CK_C_VerifyInit sym = NULL;
505 if (hPK11 == NULL)
506 return (CKR_LIBRARY_FAILED_TO_LOAD);
507 if (sym == NULL)
508 sym = (CK_C_VerifyInit)GetProcAddress(hPK11, "C_VerifyInit");
509 if (sym == NULL)
510 return (CKR_SYMBOL_RESOLUTION_FAILED);
511 return (*sym)(hSession, pMechanism, hKey);
514 CK_RV
515 pkcs_C_Verify(CK_SESSION_HANDLE hSession,
516 CK_BYTE_PTR pData,
517 CK_ULONG ulDataLen,
518 CK_BYTE_PTR pSignature,
519 CK_ULONG ulSignatureLen)
521 static CK_C_Verify sym = NULL;
523 if (hPK11 == NULL)
524 return (CKR_LIBRARY_FAILED_TO_LOAD);
525 if (sym == NULL)
526 sym = (CK_C_Verify)GetProcAddress(hPK11, "C_Verify");
527 if (sym == NULL)
528 return (CKR_SYMBOL_RESOLUTION_FAILED);
529 return (*sym)(hSession, pData, ulDataLen, pSignature, ulSignatureLen);
532 CK_RV
533 pkcs_C_VerifyUpdate(CK_SESSION_HANDLE hSession,
534 CK_BYTE_PTR pPart,
535 CK_ULONG ulPartLen)
537 static CK_C_VerifyUpdate sym = NULL;
539 if (hPK11 == NULL)
540 return (CKR_LIBRARY_FAILED_TO_LOAD);
541 if (sym == NULL)
542 sym = (CK_C_VerifyUpdate)GetProcAddress(hPK11,
543 "C_VerifyUpdate");
544 if (sym == NULL)
545 return (CKR_SYMBOL_RESOLUTION_FAILED);
546 return (*sym)(hSession, pPart, ulPartLen);
549 CK_RV
550 pkcs_C_VerifyFinal(CK_SESSION_HANDLE hSession,
551 CK_BYTE_PTR pSignature,
552 CK_ULONG ulSignatureLen)
554 static CK_C_VerifyFinal sym = NULL;
556 if (hPK11 == NULL)
557 return (CKR_LIBRARY_FAILED_TO_LOAD);
558 if (sym == NULL)
559 sym = (CK_C_VerifyFinal)GetProcAddress(hPK11, "C_VerifyFinal");
560 if (sym == NULL)
561 return (CKR_SYMBOL_RESOLUTION_FAILED);
562 return (*sym)(hSession, pSignature, ulSignatureLen);
565 CK_RV
566 pkcs_C_GenerateKey(CK_SESSION_HANDLE hSession,
567 CK_MECHANISM_PTR pMechanism,
568 CK_ATTRIBUTE_PTR pTemplate,
569 CK_ULONG ulCount,
570 CK_OBJECT_HANDLE_PTR phKey)
572 static CK_C_GenerateKey sym = NULL;
574 if (hPK11 == NULL)
575 return (CKR_LIBRARY_FAILED_TO_LOAD);
576 if (sym == NULL)
577 sym = (CK_C_GenerateKey)GetProcAddress(hPK11, "C_GenerateKey");
578 if (sym == NULL)
579 return (CKR_SYMBOL_RESOLUTION_FAILED);
580 return (*sym)(hSession, pMechanism, pTemplate, ulCount, phKey);
583 CK_RV
584 pkcs_C_GenerateKeyPair(CK_SESSION_HANDLE hSession,
585 CK_MECHANISM_PTR pMechanism,
586 CK_ATTRIBUTE_PTR pPublicKeyTemplate,
587 CK_ULONG usPublicKeyAttributeCount,
588 CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
589 CK_ULONG usPrivateKeyAttributeCount,
590 CK_OBJECT_HANDLE_PTR phPrivateKey,
591 CK_OBJECT_HANDLE_PTR phPublicKey)
593 static CK_C_GenerateKeyPair sym = NULL;
595 if (hPK11 == NULL)
596 return (CKR_LIBRARY_FAILED_TO_LOAD);
597 if (sym == NULL)
598 sym = (CK_C_GenerateKeyPair)GetProcAddress(hPK11,
599 "C_GenerateKeyPair");
600 if (sym == NULL)
601 return (CKR_SYMBOL_RESOLUTION_FAILED);
602 return (*sym)(hSession,
603 pMechanism,
604 pPublicKeyTemplate,
605 usPublicKeyAttributeCount,
606 pPrivateKeyTemplate,
607 usPrivateKeyAttributeCount,
608 phPrivateKey,
609 phPublicKey);
612 CK_RV
613 pkcs_C_DeriveKey(CK_SESSION_HANDLE hSession,
614 CK_MECHANISM_PTR pMechanism,
615 CK_OBJECT_HANDLE hBaseKey,
616 CK_ATTRIBUTE_PTR pTemplate,
617 CK_ULONG ulAttributeCount,
618 CK_OBJECT_HANDLE_PTR phKey)
620 static CK_C_DeriveKey sym = NULL;
622 if (hPK11 == NULL)
623 return (CKR_LIBRARY_FAILED_TO_LOAD);
624 if (sym == NULL)
625 sym = (CK_C_DeriveKey)GetProcAddress(hPK11, "C_DeriveKey");
626 if (sym == NULL)
627 return (CKR_SYMBOL_RESOLUTION_FAILED);
628 return (*sym)(hSession,
629 pMechanism,
630 hBaseKey,
631 pTemplate,
632 ulAttributeCount,
633 phKey);
636 CK_RV
637 pkcs_C_SeedRandom(CK_SESSION_HANDLE hSession,
638 CK_BYTE_PTR pSeed,
639 CK_ULONG ulSeedLen)
641 static CK_C_SeedRandom sym = NULL;
643 if (hPK11 == NULL)
644 return (CKR_LIBRARY_FAILED_TO_LOAD);
645 if (sym == NULL)
646 sym = (CK_C_SeedRandom)GetProcAddress(hPK11, "C_SeedRandom");
647 if (sym == NULL)
648 return (CKR_SYMBOL_RESOLUTION_FAILED);
649 return (*sym)(hSession, pSeed, ulSeedLen);
652 CK_RV
653 pkcs_C_GenerateRandom(CK_SESSION_HANDLE hSession,
654 CK_BYTE_PTR RandomData,
655 CK_ULONG ulRandomLen)
657 static CK_C_GenerateRandom sym = NULL;
659 if (hPK11 == NULL)
660 return (CKR_LIBRARY_FAILED_TO_LOAD);
661 if (sym == NULL)
662 sym = (CK_C_GenerateRandom)GetProcAddress(hPK11,
663 "C_GenerateRandom");
664 if (sym == NULL)
665 return (CKR_SYMBOL_RESOLUTION_FAILED);
666 return (*sym)(hSession, RandomData, ulRandomLen);