Debian Codegraph @

lib/hcrypto/evp-pkcs11.c

raw
1 /*
2 * Copyright (c) 2015-2016, Secure Endpoints Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /* PKCS#11 provider */
32
33 #include <config.h>
34 #include <roken.h>
35 #include <assert.h>
36 #ifdef HAVE_DLFCN_H
37 #include <dlfcn.h>
38 #ifndef RTLD_LAZY
39 #define RTLD_LAZY 0
40 #endif
41 #ifndef RTLD_LOCAL
42 #define RTLD_LOCAL 0
43 #endif
44 #ifndef RTLD_GROUP
45 #define RTLD_GROUP 0
46 #endif
47 #ifndef RTLD_NODELETE
48 #define RTLD_NODELETE 0
49 #endif
50 #else
51 #error PKCS11 support requires dlfcn.h
52 #endif
53
54 #include <heimbase.h>
55
56 #include <evp.h>
57 #include <evp-hcrypto.h>
58 #include <evp-pkcs11.h>
59
60 #include <ref/pkcs11.h>
61
62 #if __sun && !defined(PKCS11_MODULE_PATH)
63 # ifdef _LP64
64 # define PKCS11_MODULE_PATH "/usr/lib/64/libpkcs11.so"
65 # else
66 # define PKCS11_MODULE_PATH "/usr/lib/libpkcs11.so"
67 # endif
68 #elif defined(__linux__)
69 /*
70 * XXX We should have an autoconf check for OpenCryptoki and such
71 * things. However, there's no AC_CHECK_OBJECT(), and we'd have to
72 * write one. Today I'm feeling lazy. Another possibility would be to
73 * have a symlink from the libdir we'll install into, and then we could
74 * dlopen() that on all platforms.
75 *
76 * XXX Also, we should pick an appropriate shared object based on 32- vs
77 * 64-bits.
78 */
79 # define PKCS11_MODULE_PATH "/usr/lib/pkcs11/PKCS11_API.so"
80 #endif
81
82 static CK_FUNCTION_LIST_PTR p11_module;
83
84 static int
85 p11_cleanup(EVP_CIPHER_CTX *ctx);
86
87 struct pkcs11_cipher_ctx {
88 CK_SESSION_HANDLE hSession;
89 CK_OBJECT_HANDLE hSecret;
90 };
91
92 struct pkcs11_md_ctx {
93 CK_SESSION_HANDLE hSession;
94 };
95
96 static void *pkcs11_module_handle;
97
98 static CK_RV
99 p11_module_load(CK_FUNCTION_LIST_PTR_PTR ppFunctionList)
100 {
101 CK_RV rv;
102 CK_RV (*C_GetFunctionList_fn)(CK_FUNCTION_LIST_PTR_PTR);
103
104 *ppFunctionList = NULL;
105
106 if (!issuid()) {
107 char *pkcs11ModulePath = getenv("PKCS11_MODULE_PATH");
108 if (pkcs11ModulePath != NULL) {
109 pkcs11_module_handle =
110 dlopen(pkcs11ModulePath,
111 RTLD_LAZY | RTLD_LOCAL | RTLD_GROUP | RTLD_NODELETE);
112 if (pkcs11_module_handle == NULL)
113 fprintf(stderr, "p11_module_load(%s): %s\n", pkcs11ModulePath, dlerror());
114 }
115 }
116 #ifdef PKCS11_MODULE_PATH
117 if (pkcs11_module_handle == NULL) {
118 pkcs11_module_handle =
119 dlopen(PKCS11_MODULE_PATH,
120 RTLD_LAZY | RTLD_LOCAL | RTLD_GROUP | RTLD_NODELETE);
121 if (pkcs11_module_handle == NULL)
122 fprintf(stderr, "p11_module_load(%s): %s\n", PKCS11_MODULE_PATH, dlerror());
123 }
124 #endif
125 if (pkcs11_module_handle == NULL)
126 return CKR_LIBRARY_LOAD_FAILED;
127
128 C_GetFunctionList_fn = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
129 dlsym(pkcs11_module_handle, "C_GetFunctionList");
130 if (C_GetFunctionList_fn == NULL) {
131 dlclose(pkcs11_module_handle);
132 return CKR_LIBRARY_LOAD_FAILED;
133 }
134
135 rv = C_GetFunctionList_fn(ppFunctionList);
136 if (rv != CKR_OK) {
137 dlclose(pkcs11_module_handle);
138 return rv;
139 }
140
141 return CKR_OK;
142 }
143
144 static void
145 p11_module_load_once(void *context)
146 {
147 p11_module_load((CK_FUNCTION_LIST_PTR_PTR)context);
148 }
149
150 static CK_RV
151 p11_module_init(void)
152 {
153 static heim_base_once_t once = HEIM_BASE_ONCE_INIT;
154 CK_RV rv;
155
156 heim_base_once_f(&once, &p11_module, p11_module_load_once);
157
158 if (p11_module == NULL)
159 return CKR_LIBRARY_LOAD_FAILED;
160
161 /*
162 * Call C_Initialize() on every call, because it will be invalid after fork().
163 * Caching the initialization status using a once control and invalidating it
164 * on fork provided no measurable performance benefit on Solaris 11. Other
165 * approaches would not be thread-safe or would involve more intrusive code
166 * changes, such as exposing heimbase's atomics.
167 */
168 rv = p11_module->C_Initialize(NULL);
169 if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED)
170 rv = CKR_OK;
171
172 return rv;
173 }
174
175 static CK_RV
176 p11_session_init(CK_MECHANISM_TYPE mechanismType,
177 CK_SESSION_HANDLE_PTR phSession,
178 CK_FLAGS *pFlags)
179 {
180 CK_RV rv;
181 CK_ULONG i, ulSlotCount = 0;
182 CK_SLOT_ID_PTR pSlotList = NULL;
183 CK_MECHANISM_INFO info;
184
185 if (phSession != NULL)
186 *phSession = CK_INVALID_HANDLE;
187
188 *pFlags = 0;
189
190 rv = p11_module_init();
191 if (rv != CKR_OK)
192 goto cleanup;
193
194 assert(p11_module != NULL);
195
196 rv = p11_module->C_GetSlotList(CK_FALSE, NULL, &ulSlotCount);
197 if (rv != CKR_OK)
198 goto cleanup;
199
200 pSlotList = (CK_SLOT_ID_PTR)calloc(ulSlotCount, sizeof(CK_SLOT_ID));
201 if (pSlotList == NULL) {
202 rv = CKR_HOST_MEMORY;
203 goto cleanup;
204 }
205
206 rv = p11_module->C_GetSlotList(CK_FALSE, pSlotList, &ulSlotCount);
207 if (rv != CKR_OK)
208 goto cleanup;
209
210 /*
211 * Note that this approach of using the first slot that supports the desired
212 * mechanism may not always be what the user wants (for example it may prefer
213 * software to hardware crypto). We're going to assume that this code will be
214 * principally used on Solaris (which has a meta-slot provider that sorts by
215 * hardware first) or in situations where the user can configure the slots in
216 * order of provider preference. In the future we should make this configurable.
217 */
218 for (i = 0; i < ulSlotCount; i++) {
219 rv = p11_module->C_GetMechanismInfo(pSlotList[i], mechanismType, &info);
220 if (rv == CKR_OK) {
221 *pFlags = info.flags;
222 break;
223 }
224 }
225
226 if (i == ulSlotCount) {
227 rv = CKR_MECHANISM_INVALID;
228 goto cleanup;
229 }
230
231 if (phSession != NULL) {
232 rv = p11_module->C_OpenSession(pSlotList[i], CKF_SERIAL_SESSION, NULL, NULL, phSession);
233 if (rv != CKR_OK)
234 goto cleanup;
235 }
236
237 cleanup:
238 free(pSlotList);
239
240 return rv;
241 }
242
243 static int
244 p11_mech_available_p(CK_MECHANISM_TYPE mechanismType, CK_FLAGS reqFlags)
245 {
246 CK_RV rv;
247 CK_FLAGS flags;
248
249 rv = p11_session_init(mechanismType, NULL, &flags);
250 if (rv != CKR_OK)
251 return 0;
252
253 return (flags & reqFlags) == reqFlags;
254 }
255
256 static CK_KEY_TYPE
257 p11_key_type_for_mech(CK_MECHANISM_TYPE mechanismType)
258 {
259 CK_KEY_TYPE keyType = 0;
260
261 switch (mechanismType) {
262 case CKM_RC2_CBC:
263 keyType = CKK_RC2;
264 break;
265 case CKM_RC4:
266 keyType = CKK_RC4;
267 break;
268 case CKM_DES_CBC:
269 keyType = CKK_DES;
270 break;
271 case CKM_DES3_CBC:
272 keyType = CKK_DES3;
273 break;
274 case CKM_AES_CBC:
275 case CKM_AES_CFB8:
276 keyType = CKK_AES;
277 break;
278 case CKM_CAMELLIA_CBC:
279 keyType = CKK_CAMELLIA;
280 break;
281 default:
282 assert(0 && "Unknown PKCS#11 mechanism type");
283 break;
284 }
285
286 return keyType;
287 }
288
289 static int
290 p11_key_init(EVP_CIPHER_CTX *ctx,
291 const unsigned char *key,
292 const unsigned char *iv,
293 int encp)
294 {
295 CK_RV rv;
296 CK_BBOOL bFalse = CK_FALSE;
297 CK_BBOOL bTrue = CK_TRUE;
298 CK_MECHANISM_TYPE mechanismType = (CK_MECHANISM_TYPE)ctx->cipher->app_data;
299 CK_KEY_TYPE keyType = p11_key_type_for_mech(mechanismType);
300 CK_OBJECT_CLASS objectClass = CKO_SECRET_KEY;
301 CK_ATTRIBUTE_TYPE op = encp ? CKA_ENCRYPT : CKA_DECRYPT;
302 CK_ATTRIBUTE attributes[] = {
303 { CKA_EXTRACTABLE, &bFalse, sizeof(bFalse) },
304 { CKA_CLASS, &objectClass, sizeof(objectClass) },
305 { CKA_KEY_TYPE, &keyType, sizeof(keyType) },
306 { CKA_TOKEN, &bFalse, sizeof(bFalse) },
307 { CKA_PRIVATE, &bFalse, sizeof(bFalse) },
308 { CKA_SENSITIVE, &bTrue, sizeof(bTrue) },
309 { CKA_VALUE, (void *)key, ctx->key_len },
310 { op, &bTrue, sizeof(bTrue) }
311 };
312 CK_MECHANISM mechanism = {
313 mechanismType,
314 ctx->cipher->iv_len ? ctx->iv : NULL,
315 ctx->cipher->iv_len
316 };
317 struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
318 CK_FLAGS flags;
319
320 rv = CKR_OK;
321
322 if (p11ctx->hSession != CK_INVALID_HANDLE && key != NULL)
323 p11_cleanup(ctx); /* refresh session with new key */
324
325 if (p11ctx->hSession == CK_INVALID_HANDLE) {
326 rv = p11_session_init(mechanismType, &p11ctx->hSession, &flags);
327 if (rv != CKR_OK)
328 goto cleanup;
329
330 if ((flags & (CKF_ENCRYPT|CKF_DECRYPT)) != (CKF_ENCRYPT|CKF_DECRYPT)) {
331 rv = CKR_MECHANISM_INVALID;
332 goto cleanup;
333 }
334 }
335
336 if (key != NULL) {
337 assert(p11_module != NULL);
338 assert(p11ctx->hSecret == CK_INVALID_HANDLE);
339
340 rv = p11_module->C_CreateObject(p11ctx->hSession, attributes,
341 sizeof(attributes) / sizeof(attributes[0]),
342 &p11ctx->hSecret);
343 if (rv != CKR_OK)
344 goto cleanup;
345 }
346
347 if (p11ctx->hSecret != CK_INVALID_HANDLE) {
348 if (op == CKA_ENCRYPT)
349 rv = p11_module->C_EncryptInit(p11ctx->hSession, &mechanism, p11ctx->hSecret);
350 else
351 rv = p11_module->C_DecryptInit(p11ctx->hSession, &mechanism, p11ctx->hSecret);
352 if (rv != CKR_OK)
353 goto cleanup;
354 }
355
356 cleanup:
357 if (rv != CKR_OK)
358 p11_cleanup(ctx);
359
360 return rv == CKR_OK;
361 }
362
363 static int
364 p11_do_cipher(EVP_CIPHER_CTX *ctx,
365 unsigned char *out,
366 const unsigned char *in,
367 unsigned int size)
368 {
369 struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
370 CK_RV rv;
371 CK_ULONG ulCipherTextLen = size;
372
373 assert(p11_module != NULL);
374 assert(EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_STREAM_CIPHER ||
375 (size % ctx->cipher->block_size) == 0);
376
377 if (ctx->encrypt)
378 rv = p11_module->C_EncryptUpdate(p11ctx->hSession, (unsigned char *)in, size, out, &ulCipherTextLen);
379 else
380 rv = p11_module->C_DecryptUpdate(p11ctx->hSession, (unsigned char *)in, size, out, &ulCipherTextLen);
381
382 return rv == CKR_OK;
383 }
384
385 static int
386 p11_cleanup(EVP_CIPHER_CTX *ctx)
387 {
388 struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
389
390 if (p11ctx->hSecret != CK_INVALID_HANDLE) {
391 p11_module->C_DestroyObject(p11ctx->hSession, p11ctx->hSecret);
392 p11ctx->hSecret = CK_INVALID_HANDLE;
393 }
394 if (p11ctx->hSession != CK_INVALID_HANDLE) {
395 p11_module->C_CloseSession(p11ctx->hSession);
396 p11ctx->hSession = CK_INVALID_HANDLE;
397 }
398
399 return 1;
400 }
401
402 static int
403 p11_md_cleanup(EVP_MD_CTX *ctx);
404
405 static int
406 p11_md_hash_init(CK_MECHANISM_TYPE mechanismType, EVP_MD_CTX *ctx)
407 {
408 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
409 CK_RV rv;
410 CK_FLAGS flags;
411 CK_MECHANISM mechanism = { mechanismType, NULL, 0 };
412
413 if (p11ctx->hSession != CK_INVALID_HANDLE)
414 p11_md_cleanup(ctx);
415
416 rv = p11_session_init(mechanismType, &p11ctx->hSession, &flags);
417 if (rv != CKR_OK)
418 goto cleanup;
419
420 if ((flags & CKF_DIGEST) != CKF_DIGEST) {
421 rv = CKR_MECHANISM_INVALID;
422 goto cleanup;
423 }
424
425 assert(p11_module != NULL);
426
427 rv = p11_module->C_DigestInit(p11ctx->hSession, &mechanism);
428
429 cleanup:
430 return rv == CKR_OK;
431 }
432
433 static int
434 p11_md_update(EVP_MD_CTX *ctx, const void *data, size_t length)
435 {
436 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
437 CK_RV rv;
438
439 assert(p11_module != NULL);
440 assert(data != NULL || length == 0);
441
442 rv = p11_module->C_DigestUpdate(p11ctx->hSession,
443 data ? (CK_BYTE_PTR)data : (CK_BYTE_PTR)"",
444 length);
445
446 return rv == CKR_OK;
447 }
448
449 static int
450 p11_md_final(void *digest, EVP_MD_CTX *ctx)
451 {
452 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
453 CK_RV rv;
454 CK_ULONG digestLen = 0;
455
456 assert(p11_module != NULL);
457
458 rv = p11_module->C_DigestFinal(p11ctx->hSession, NULL, &digestLen);
459 if (rv == CKR_OK)
460 rv = p11_module->C_DigestFinal(p11ctx->hSession, digest, &digestLen);
461
462 return rv == CKR_OK;
463 }
464
465 static int
466 p11_md_cleanup(EVP_MD_CTX *ctx)
467 {
468 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
469 CK_RV rv;
470
471 assert(p11_module != NULL);
472
473 rv = p11_module->C_CloseSession(p11ctx->hSession);
474 if (rv == CKR_OK)
475 p11ctx->hSession = CK_INVALID_HANDLE;
476
477 return rv == CKR_OK;
478 }
479
480 #define PKCS11_CIPHER_ALGORITHM(name, mechanismType, block_size, \
481 key_len, iv_len, flags) \
482 \
483 static EVP_CIPHER \
484 pkcs11_##name = { \
485 0, \
486 block_size, \
487 key_len, \
488 iv_len, \
489 (flags) | EVP_CIPH_ALWAYS_CALL_INIT, \
490 p11_key_init, \
491 p11_do_cipher, \
492 p11_cleanup, \
493 sizeof(struct pkcs11_cipher_ctx), \
494 NULL, \
495 NULL, \
496 NULL, \
497 (void *)mechanismType \
498 }; \
499 \
500 const EVP_CIPHER * \
501 hc_EVP_pkcs11_##name(void) \
502 { \
503 if (p11_mech_available_p(mechanismType, CKF_ENCRYPT|CKF_DECRYPT)) \
504 return &pkcs11_##name; \
505 else \
506 return NULL; \
507 } \
508 \
509 static void \
510 pkcs11_hcrypto_##name##_init_once(void *context) \
511 { \
512 const EVP_CIPHER *cipher; \
513 \
514 cipher = hc_EVP_pkcs11_ ##name(); \
515 if (cipher == NULL && HCRYPTO_FALLBACK) \
516 cipher = hc_EVP_hcrypto_ ##name(); \
517 \
518 *((const EVP_CIPHER **)context) = cipher; \
519 } \
520 \
521 const EVP_CIPHER * \
522 hc_EVP_pkcs11_hcrypto_##name(void) \
523 { \
524 static const EVP_CIPHER *__cipher; \
525 static heim_base_once_t __init = HEIM_BASE_ONCE_INIT; \
526 \
527 heim_base_once_f(&__init, &__cipher, \
528 pkcs11_hcrypto_##name##_init_once); \
529 \
530 return __cipher; \
531 }
532
533 #define PKCS11_MD_ALGORITHM(name, mechanismType, hash_size, block_size) \
534 \
535 static int p11_##name##_init(EVP_MD_CTX *ctx) \
536 { \
537 return p11_md_hash_init(mechanismType, ctx); \
538 } \
539 \
540 const EVP_MD * \
541 hc_EVP_pkcs11_##name(void) \
542 { \
543 static struct hc_evp_md name = { \
544 hash_size, \
545 block_size, \
546 sizeof(struct pkcs11_md_ctx), \
547 p11_##name##_init, \
548 p11_md_update, \
549 p11_md_final, \
550 p11_md_cleanup \
551 }; \
552 \
553 if (p11_mech_available_p(mechanismType, CKF_DIGEST)) \
554 return &name; \
555 else \
556 return NULL; \
557 } \
558 \
559 static void \
560 pkcs11_hcrypto_##name##_init_once(void *context) \
561 { \
562 const EVP_MD *md; \
563 \
564 md = hc_EVP_pkcs11_ ##name(); \
565 if (md == NULL && HCRYPTO_FALLBACK) \
566 md = hc_EVP_hcrypto_ ##name(); \
567 \
568 *((const EVP_MD **)context) = md; \
569 } \
570 \
571 const EVP_MD * \
572 hc_EVP_pkcs11_hcrypto_##name(void) \
573 { \
574 static const EVP_MD *__md; \
575 static heim_base_once_t __init = HEIM_BASE_ONCE_INIT; \
576 \
577 heim_base_once_f(&__init, &__md, \
578 pkcs11_hcrypto_##name##_init_once); \
579 \
580 return __md; \
581 }
582
583 #define PKCS11_MD_ALGORITHM_UNAVAILABLE(name) \
584 \
585 const EVP_MD * \
586 hc_EVP_pkcs11_##name(void) \
587 { \
588 return NULL; \
589 } \
590 \
591 const EVP_MD * \
592 hc_EVP_pkcs11_hcrypto_##name(void) \
593 { \
594 return hc_EVP_hcrypto_ ##name(); \
595 }
596
597 /**
598 * The triple DES cipher type (PKCS#11 provider)
599 *
600 * @return the DES-EDE3-CBC EVP_CIPHER pointer.
601 *
602 * @ingroup hcrypto_evp
603 */
604
605 PKCS11_CIPHER_ALGORITHM(des_ede3_cbc,
606 CKM_DES3_CBC,
607 8,
608 24,
609 8,
610 EVP_CIPH_CBC_MODE)
611
612 /**
613 * The DES cipher type (PKCS#11 provider)
614 *
615 * @return the DES-CBC EVP_CIPHER pointer.
616 *
617 * @ingroup hcrypto_evp
618 */
619
620 PKCS11_CIPHER_ALGORITHM(des_cbc,
621 CKM_DES_CBC,
622 8,
623 8,
624 8,
625 EVP_CIPH_CBC_MODE)
626
627 /**
628 * The AES-128 cipher type (PKCS#11 provider)
629 *
630 * @return the AES-128-CBC EVP_CIPHER pointer.
631 *
632 * @ingroup hcrypto_evp
633 */
634
635 PKCS11_CIPHER_ALGORITHM(aes_128_cbc,
636 CKM_AES_CBC,
637 16,
638 16,
639 16,
640 EVP_CIPH_CBC_MODE)
641
642 /**
643 * The AES-192 cipher type (PKCS#11 provider)
644 *
645 * @return the AES-192-CBC EVP_CIPHER pointer.
646 *
647 * @ingroup hcrypto_evp
648 */
649
650 PKCS11_CIPHER_ALGORITHM(aes_192_cbc,
651 CKM_AES_CBC,
652 16,
653 24,
654 16,
655 EVP_CIPH_CBC_MODE)
656
657 /**
658 * The AES-256 cipher type (PKCS#11 provider)
659 *
660 * @return the AES-256-CBC EVP_CIPHER pointer.
661 *
662 * @ingroup hcrypto_evp
663 */
664
665 PKCS11_CIPHER_ALGORITHM(aes_256_cbc,
666 CKM_AES_CBC,
667 16,
668 32,
669 16,
670 EVP_CIPH_CBC_MODE)
671
672 /**
673 * The AES-128 CFB8 cipher type (PKCS#11 provider)
674 *
675 * @return the AES-128-CFB8 EVP_CIPHER pointer.
676 *
677 * @ingroup hcrypto_evp
678 */
679
680 PKCS11_CIPHER_ALGORITHM(aes_128_cfb8,
681 CKM_AES_CFB8,
682 16,
683 16,
684 16,
685 EVP_CIPH_CFB8_MODE)
686
687 /**
688 * The AES-192 CFB8 cipher type (PKCS#11 provider)
689 *
690 * @return the AES-192-CFB8 EVP_CIPHER pointer.
691 *
692 * @ingroup hcrypto_evp
693 */
694
695 PKCS11_CIPHER_ALGORITHM(aes_192_cfb8,
696 CKM_AES_CFB8,
697 16,
698 24,
699 16,
700 EVP_CIPH_CFB8_MODE)
701
702 /**
703 * The AES-256 CFB8 cipher type (PKCS#11 provider)
704 *
705 * @return the AES-256-CFB8 EVP_CIPHER pointer.
706 *
707 * @ingroup hcrypto_evp
708 */
709
710 PKCS11_CIPHER_ALGORITHM(aes_256_cfb8,
711 CKM_AES_CFB8,
712 16,
713 32,
714 16,
715 EVP_CIPH_CFB8_MODE)
716
717 /**
718 * The RC2 cipher type - PKCS#11
719 *
720 * @return the RC2 EVP_CIPHER pointer.
721 *
722 * @ingroup hcrypto_evp
723 */
724
725 PKCS11_CIPHER_ALGORITHM(rc2_cbc,
726 CKM_RC2_CBC,
727 8,
728 16,
729 8,
730 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH)
731
732 /**
733 * The RC2-40 cipher type - PKCS#11
734 *
735 * @return the RC2-40 EVP_CIPHER pointer.
736 *
737 * @ingroup hcrypto_evp
738 */
739
740 PKCS11_CIPHER_ALGORITHM(rc2_40_cbc,
741 CKM_RC2_CBC,
742 8,
743 5,
744 8,
745 EVP_CIPH_CBC_MODE)
746
747 /**
748 * The RC2-64 cipher type - PKCS#11
749 *
750 * @return the RC2-64 EVP_CIPHER pointer.
751 *
752 * @ingroup hcrypto_evp
753 */
754
755 PKCS11_CIPHER_ALGORITHM(rc2_64_cbc,
756 CKM_RC2_CBC,
757 8,
758 8,
759 8,
760 EVP_CIPH_CBC_MODE)
761
762 /**
763 * The Camellia-128 cipher type - PKCS#11
764 *
765 * @return the Camellia-128 EVP_CIPHER pointer.
766 *
767 * @ingroup hcrypto_evp
768 */
769
770 PKCS11_CIPHER_ALGORITHM(camellia_128_cbc,
771 CKM_CAMELLIA_CBC,
772 16,
773 16,
774 16,
775 EVP_CIPH_CBC_MODE)
776
777 /**
778 * The Camellia-198 cipher type - PKCS#11
779 *
780 * @return the Camellia-198 EVP_CIPHER pointer.
781 *
782 * @ingroup hcrypto_evp
783 */
784
785 PKCS11_CIPHER_ALGORITHM(camellia_192_cbc,
786 CKM_CAMELLIA_CBC,
787 16,
788 24,
789 16,
790 EVP_CIPH_CBC_MODE)
791
792 /**
793 * The Camellia-256 cipher type - PKCS#11
794 *
795 * @return the Camellia-256 EVP_CIPHER pointer.
796 *
797 * @ingroup hcrypto_evp
798 */
799
800 PKCS11_CIPHER_ALGORITHM(camellia_256_cbc,
801 CKM_CAMELLIA_CBC,
802 16,
803 32,
804 16,
805 EVP_CIPH_CBC_MODE)
806
807 /**
808 * The RC4 cipher type (PKCS#11 provider)
809 *
810 * @return the RC4 EVP_CIPHER pointer.
811 *
812 * @ingroup hcrypto_evp
813 */
814
815 PKCS11_CIPHER_ALGORITHM(rc4,
816 CKM_RC4,
817 1,
818 16,
819 0,
820 EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH)
821
822 /**
823 * The RC4-40 cipher type (PKCS#11 provider)
824 *
825 * @return the RC4 EVP_CIPHER pointer.
826 *
827 * @ingroup hcrypto_evp
828 */
829
830 PKCS11_CIPHER_ALGORITHM(rc4_40,
831 CKM_RC4,
832 1,
833 5,
834 0,
835 EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH)
836
837 #ifdef CKM_MD4 /* non-standard extension */
838 PKCS11_MD_ALGORITHM(md4, CKM_MD4, 16, 64)
839 #else
840 PKCS11_MD_ALGORITHM_UNAVAILABLE(md4)
841 #endif
842 PKCS11_MD_ALGORITHM(md5, CKM_MD5, 16, 64)
843 PKCS11_MD_ALGORITHM(sha1, CKM_SHA_1, 20, 64)
844 PKCS11_MD_ALGORITHM(sha256, CKM_SHA256, 32, 64)
845 PKCS11_MD_ALGORITHM(sha384, CKM_SHA384, 48, 128)
846 PKCS11_MD_ALGORITHM(sha512, CKM_SHA512, 64, 128)