Provide the correct principal name to verify_flags() for user2user tickets
[heimdal.git] / lib / hcrypto / evp-pkcs11.c
blobb44871fa4c4d3b7b6fe6359fdeb709759ebdb946
1 /*
2 * Copyright (c) 2015-2016, Secure Endpoints Inc.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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.
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.
31 /* PKCS#11 provider */
33 #include <config.h>
34 #include <roken.h>
35 #include <assert.h>
37 #ifndef HAVE_DLFCN_H
38 #error PKCS11 support requires dlfcn.h
39 #endif
41 #include <heimbase.h>
43 #include <evp.h>
44 #include <evp-hcrypto.h>
45 #include <evp-pkcs11.h>
47 #include <ref/pkcs11.h>
49 #if __sun && !defined(PKCS11_MODULE_PATH)
50 # ifdef _LP64
51 # define PKCS11_MODULE_PATH "/usr/lib/64/libpkcs11.so"
52 # else
53 # define PKCS11_MODULE_PATH "/usr/lib/libpkcs11.so"
54 # endif
55 #elif defined(__linux__)
57 * XXX We should have an autoconf check for OpenCryptoki and such
58 * things. However, there's no AC_CHECK_OBJECT(), and we'd have to
59 * write one. Today I'm feeling lazy. Another possibility would be to
60 * have a symlink from the libdir we'll install into, and then we could
61 * dlopen() that on all platforms.
63 * XXX Also, we should pick an appropriate shared object based on 32- vs
64 * 64-bits.
66 # define PKCS11_MODULE_PATH "/usr/lib/pkcs11/PKCS11_API.so"
67 #endif
69 static CK_FUNCTION_LIST_PTR p11_module;
71 static int
72 p11_cleanup(EVP_CIPHER_CTX *ctx);
74 struct pkcs11_cipher_ctx {
75 CK_SESSION_HANDLE hSession;
76 CK_OBJECT_HANDLE hSecret;
79 struct pkcs11_md_ctx {
80 CK_SESSION_HANDLE hSession;
83 static void *pkcs11_module_handle;
85 static CK_RV
86 p11_module_load(CK_FUNCTION_LIST_PTR_PTR ppFunctionList)
88 CK_RV rv;
89 CK_RV (*C_GetFunctionList_fn)(CK_FUNCTION_LIST_PTR_PTR);
90 char *pkcs11ModulePath = secure_getenv("PKCS11_MODULE_PATH");
92 *ppFunctionList = NULL;
94 if (pkcs11ModulePath != NULL) {
95 pkcs11_module_handle =
96 dlopen(pkcs11ModulePath,
97 RTLD_LAZY | RTLD_LOCAL | RTLD_GROUP | RTLD_NODELETE);
98 if (pkcs11_module_handle == NULL)
99 fprintf(stderr, "p11_module_load(%s): %s\n", pkcs11ModulePath, dlerror());
101 #ifdef PKCS11_MODULE_PATH
102 if (pkcs11_module_handle == NULL) {
103 pkcs11_module_handle =
104 dlopen(PKCS11_MODULE_PATH,
105 RTLD_LAZY | RTLD_LOCAL | RTLD_GROUP | RTLD_NODELETE);
106 if (pkcs11_module_handle == NULL)
107 fprintf(stderr, "p11_module_load(%s): %s\n", PKCS11_MODULE_PATH, dlerror());
109 #endif
110 if (pkcs11_module_handle == NULL)
111 return CKR_LIBRARY_LOAD_FAILED;
113 C_GetFunctionList_fn = (CK_RV (*)(CK_FUNCTION_LIST_PTR_PTR))
114 dlsym(pkcs11_module_handle, "C_GetFunctionList");
115 if (C_GetFunctionList_fn == NULL) {
116 dlclose(pkcs11_module_handle);
117 return CKR_LIBRARY_LOAD_FAILED;
120 rv = C_GetFunctionList_fn(ppFunctionList);
121 if (rv != CKR_OK) {
122 dlclose(pkcs11_module_handle);
123 return rv;
126 return CKR_OK;
129 static void
130 p11_module_load_once(void *context)
132 p11_module_load((CK_FUNCTION_LIST_PTR_PTR)context);
135 static CK_RV
136 p11_module_init(void)
138 static heim_base_once_t once = HEIM_BASE_ONCE_INIT;
139 CK_RV rv;
141 heim_base_once_f(&once, &p11_module, p11_module_load_once);
143 if (p11_module == NULL)
144 return CKR_LIBRARY_LOAD_FAILED;
147 * Call C_Initialize() on every call, because it will be invalid after fork().
148 * Caching the initialization status using a once control and invalidating it
149 * on fork provided no measurable performance benefit on Solaris 11. Other
150 * approaches would not be thread-safe or would involve more intrusive code
151 * changes, such as exposing heimbase's atomics.
153 rv = p11_module->C_Initialize(NULL);
154 if (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED)
155 rv = CKR_OK;
157 return rv;
160 static CK_RV
161 p11_session_init(CK_MECHANISM_TYPE mechanismType,
162 CK_SESSION_HANDLE_PTR phSession,
163 CK_FLAGS *pFlags)
165 CK_RV rv;
166 CK_ULONG i, ulSlotCount = 0;
167 CK_SLOT_ID_PTR pSlotList = NULL;
168 CK_MECHANISM_INFO info;
170 if (phSession != NULL)
171 *phSession = CK_INVALID_HANDLE;
173 *pFlags = 0;
175 rv = p11_module_init();
176 if (rv != CKR_OK)
177 goto cleanup;
179 assert(p11_module != NULL);
181 rv = p11_module->C_GetSlotList(CK_FALSE, NULL, &ulSlotCount);
182 if (rv != CKR_OK)
183 goto cleanup;
185 pSlotList = (CK_SLOT_ID_PTR)calloc(ulSlotCount, sizeof(CK_SLOT_ID));
186 if (pSlotList == NULL) {
187 rv = CKR_HOST_MEMORY;
188 goto cleanup;
191 rv = p11_module->C_GetSlotList(CK_FALSE, pSlotList, &ulSlotCount);
192 if (rv != CKR_OK)
193 goto cleanup;
196 * Note that this approach of using the first slot that supports the desired
197 * mechanism may not always be what the user wants (for example it may prefer
198 * software to hardware crypto). We're going to assume that this code will be
199 * principally used on Solaris (which has a meta-slot provider that sorts by
200 * hardware first) or in situations where the user can configure the slots in
201 * order of provider preference. In the future we should make this configurable.
203 for (i = 0; i < ulSlotCount; i++) {
204 rv = p11_module->C_GetMechanismInfo(pSlotList[i], mechanismType, &info);
205 if (rv == CKR_OK) {
206 *pFlags = info.flags;
207 break;
211 if (i == ulSlotCount) {
212 rv = CKR_MECHANISM_INVALID;
213 goto cleanup;
216 if (phSession != NULL) {
217 rv = p11_module->C_OpenSession(pSlotList[i], CKF_SERIAL_SESSION, NULL, NULL, phSession);
218 if (rv != CKR_OK)
219 goto cleanup;
222 cleanup:
223 free(pSlotList);
225 return rv;
228 static int
229 p11_mech_available_p(CK_MECHANISM_TYPE mechanismType, CK_FLAGS reqFlags)
231 CK_RV rv;
232 CK_FLAGS flags;
234 rv = p11_session_init(mechanismType, NULL, &flags);
235 if (rv != CKR_OK)
236 return 0;
238 return (flags & reqFlags) == reqFlags;
241 static CK_KEY_TYPE
242 p11_key_type_for_mech(CK_MECHANISM_TYPE mechanismType)
244 CK_KEY_TYPE keyType = 0;
246 switch (mechanismType) {
247 case CKM_RC2_CBC:
248 keyType = CKK_RC2;
249 break;
250 case CKM_RC4:
251 keyType = CKK_RC4;
252 break;
253 case CKM_DES_CBC:
254 keyType = CKK_DES;
255 break;
256 case CKM_DES3_CBC:
257 keyType = CKK_DES3;
258 break;
259 case CKM_AES_CBC:
260 case CKM_AES_CFB8:
261 keyType = CKK_AES;
262 break;
263 case CKM_CAMELLIA_CBC:
264 keyType = CKK_CAMELLIA;
265 break;
266 default:
267 assert(0 && "Unknown PKCS#11 mechanism type");
268 break;
271 return keyType;
274 static int
275 p11_key_init(EVP_CIPHER_CTX *ctx,
276 const unsigned char *key,
277 const unsigned char *iv,
278 int encp)
280 CK_RV rv;
281 CK_BBOOL bFalse = CK_FALSE;
282 CK_BBOOL bTrue = CK_TRUE;
283 CK_MECHANISM_TYPE mechanismType = (CK_MECHANISM_TYPE)ctx->cipher->app_data;
284 CK_KEY_TYPE keyType = p11_key_type_for_mech(mechanismType);
285 CK_OBJECT_CLASS objectClass = CKO_SECRET_KEY;
286 CK_ATTRIBUTE_TYPE op = encp ? CKA_ENCRYPT : CKA_DECRYPT;
287 CK_ATTRIBUTE attributes[] = {
288 { CKA_EXTRACTABLE, &bFalse, sizeof(bFalse) },
289 { CKA_CLASS, &objectClass, sizeof(objectClass) },
290 { CKA_KEY_TYPE, &keyType, sizeof(keyType) },
291 { CKA_TOKEN, &bFalse, sizeof(bFalse) },
292 { CKA_PRIVATE, &bFalse, sizeof(bFalse) },
293 { CKA_SENSITIVE, &bTrue, sizeof(bTrue) },
294 { CKA_VALUE, (void *)key, ctx->key_len },
295 { op, &bTrue, sizeof(bTrue) }
297 CK_MECHANISM mechanism = {
298 mechanismType,
299 ctx->cipher->iv_len ? ctx->iv : NULL,
300 ctx->cipher->iv_len
302 struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
303 CK_FLAGS flags;
305 rv = CKR_OK;
307 if (p11ctx->hSession != CK_INVALID_HANDLE && key != NULL)
308 p11_cleanup(ctx); /* refresh session with new key */
310 if (p11ctx->hSession == CK_INVALID_HANDLE) {
311 rv = p11_session_init(mechanismType, &p11ctx->hSession, &flags);
312 if (rv != CKR_OK)
313 goto cleanup;
315 if ((flags & (CKF_ENCRYPT|CKF_DECRYPT)) != (CKF_ENCRYPT|CKF_DECRYPT)) {
316 rv = CKR_MECHANISM_INVALID;
317 goto cleanup;
321 if (key != NULL) {
322 assert(p11_module != NULL);
323 assert(p11ctx->hSecret == CK_INVALID_HANDLE);
325 rv = p11_module->C_CreateObject(p11ctx->hSession, attributes,
326 sizeof(attributes) / sizeof(attributes[0]),
327 &p11ctx->hSecret);
328 if (rv != CKR_OK)
329 goto cleanup;
332 if (p11ctx->hSecret != CK_INVALID_HANDLE) {
333 if (op == CKA_ENCRYPT)
334 rv = p11_module->C_EncryptInit(p11ctx->hSession, &mechanism, p11ctx->hSecret);
335 else
336 rv = p11_module->C_DecryptInit(p11ctx->hSession, &mechanism, p11ctx->hSecret);
337 if (rv != CKR_OK)
338 goto cleanup;
341 cleanup:
342 if (rv != CKR_OK)
343 p11_cleanup(ctx);
345 return rv == CKR_OK;
348 static int
349 p11_do_cipher(EVP_CIPHER_CTX *ctx,
350 unsigned char *out,
351 const unsigned char *in,
352 unsigned int size)
354 struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
355 CK_RV rv;
356 CK_ULONG ulCipherTextLen = size;
358 assert(p11_module != NULL);
359 assert(EVP_CIPHER_CTX_mode(ctx) == EVP_CIPH_STREAM_CIPHER ||
360 (size % ctx->cipher->block_size) == 0);
362 if (ctx->encrypt)
363 rv = p11_module->C_EncryptUpdate(p11ctx->hSession, (unsigned char *)in, size, out, &ulCipherTextLen);
364 else
365 rv = p11_module->C_DecryptUpdate(p11ctx->hSession, (unsigned char *)in, size, out, &ulCipherTextLen);
367 return rv == CKR_OK;
370 static int
371 p11_cleanup(EVP_CIPHER_CTX *ctx)
373 struct pkcs11_cipher_ctx *p11ctx = (struct pkcs11_cipher_ctx *)ctx->cipher_data;
375 if (p11ctx->hSecret != CK_INVALID_HANDLE) {
376 p11_module->C_DestroyObject(p11ctx->hSession, p11ctx->hSecret);
377 p11ctx->hSecret = CK_INVALID_HANDLE;
379 if (p11ctx->hSession != CK_INVALID_HANDLE) {
380 p11_module->C_CloseSession(p11ctx->hSession);
381 p11ctx->hSession = CK_INVALID_HANDLE;
384 return 1;
387 static int
388 p11_md_cleanup(EVP_MD_CTX *ctx);
390 static int
391 p11_md_hash_init(CK_MECHANISM_TYPE mechanismType, EVP_MD_CTX *ctx)
393 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
394 CK_RV rv;
395 CK_FLAGS flags;
396 CK_MECHANISM mechanism = { mechanismType, NULL, 0 };
398 if (p11ctx->hSession != CK_INVALID_HANDLE)
399 p11_md_cleanup(ctx);
401 rv = p11_session_init(mechanismType, &p11ctx->hSession, &flags);
402 if (rv != CKR_OK)
403 goto cleanup;
405 if ((flags & CKF_DIGEST) != CKF_DIGEST) {
406 rv = CKR_MECHANISM_INVALID;
407 goto cleanup;
410 assert(p11_module != NULL);
412 rv = p11_module->C_DigestInit(p11ctx->hSession, &mechanism);
414 cleanup:
415 return rv == CKR_OK;
418 static int
419 p11_md_update(EVP_MD_CTX *ctx, const void *data, size_t length)
421 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
422 CK_RV rv;
424 assert(p11_module != NULL);
425 assert(data != NULL || length == 0);
427 rv = p11_module->C_DigestUpdate(p11ctx->hSession,
428 data ? (CK_BYTE_PTR)data : (CK_BYTE_PTR)"",
429 length);
431 return rv == CKR_OK;
434 static int
435 p11_md_final(void *digest, EVP_MD_CTX *ctx)
437 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
438 CK_RV rv;
439 CK_ULONG digestLen = 0;
441 assert(p11_module != NULL);
443 rv = p11_module->C_DigestFinal(p11ctx->hSession, NULL, &digestLen);
444 if (rv == CKR_OK)
445 rv = p11_module->C_DigestFinal(p11ctx->hSession, digest, &digestLen);
447 return rv == CKR_OK;
450 static int
451 p11_md_cleanup(EVP_MD_CTX *ctx)
453 struct pkcs11_md_ctx *p11ctx = (struct pkcs11_md_ctx *)ctx;
454 CK_RV rv;
456 assert(p11_module != NULL);
458 rv = p11_module->C_CloseSession(p11ctx->hSession);
459 if (rv == CKR_OK)
460 p11ctx->hSession = CK_INVALID_HANDLE;
462 return rv == CKR_OK;
465 #define PKCS11_CIPHER_ALGORITHM(name, mechanismType, block_size, \
466 key_len, iv_len, flags) \
468 static EVP_CIPHER \
469 pkcs11_##name = { \
470 0, \
471 block_size, \
472 key_len, \
473 iv_len, \
474 (flags) | EVP_CIPH_ALWAYS_CALL_INIT, \
475 p11_key_init, \
476 p11_do_cipher, \
477 p11_cleanup, \
478 sizeof(struct pkcs11_cipher_ctx), \
479 NULL, \
480 NULL, \
481 NULL, \
482 (void *)mechanismType \
483 }; \
485 const EVP_CIPHER * \
486 hc_EVP_pkcs11_##name(void) \
488 if (p11_mech_available_p(mechanismType, CKF_ENCRYPT|CKF_DECRYPT)) \
489 return &pkcs11_##name; \
490 else \
491 return NULL; \
494 static void \
495 pkcs11_hcrypto_##name##_init_once(void *context) \
497 const EVP_CIPHER *cipher; \
499 cipher = hc_EVP_pkcs11_ ##name(); \
500 if (cipher == NULL && HCRYPTO_FALLBACK) \
501 cipher = hc_EVP_hcrypto_ ##name(); \
503 *((const EVP_CIPHER **)context) = cipher; \
506 const EVP_CIPHER * \
507 hc_EVP_pkcs11_hcrypto_##name(void) \
509 static const EVP_CIPHER *__cipher; \
510 static heim_base_once_t __init = HEIM_BASE_ONCE_INIT; \
512 heim_base_once_f(&__init, &__cipher, \
513 pkcs11_hcrypto_##name##_init_once); \
515 return __cipher; \
518 #define PKCS11_MD_ALGORITHM(name, mechanismType, hash_size, block_size) \
520 static int p11_##name##_init(EVP_MD_CTX *ctx) \
522 return p11_md_hash_init(mechanismType, ctx); \
525 const EVP_MD * \
526 hc_EVP_pkcs11_##name(void) \
528 static struct hc_evp_md name = { \
529 hash_size, \
530 block_size, \
531 sizeof(struct pkcs11_md_ctx), \
532 p11_##name##_init, \
533 p11_md_update, \
534 p11_md_final, \
535 p11_md_cleanup \
536 }; \
538 if (p11_mech_available_p(mechanismType, CKF_DIGEST)) \
539 return &name; \
540 else \
541 return NULL; \
544 static void \
545 pkcs11_hcrypto_##name##_init_once(void *context) \
547 const EVP_MD *md; \
549 md = hc_EVP_pkcs11_ ##name(); \
550 if (md == NULL && HCRYPTO_FALLBACK) \
551 md = hc_EVP_hcrypto_ ##name(); \
553 *((const EVP_MD **)context) = md; \
556 const EVP_MD * \
557 hc_EVP_pkcs11_hcrypto_##name(void) \
559 static const EVP_MD *__md; \
560 static heim_base_once_t __init = HEIM_BASE_ONCE_INIT; \
562 heim_base_once_f(&__init, &__md, \
563 pkcs11_hcrypto_##name##_init_once); \
565 return __md; \
568 #define PKCS11_MD_ALGORITHM_UNAVAILABLE(name) \
570 const EVP_MD * \
571 hc_EVP_pkcs11_##name(void) \
573 return NULL; \
576 const EVP_MD * \
577 hc_EVP_pkcs11_hcrypto_##name(void) \
579 return hc_EVP_hcrypto_ ##name(); \
583 * The triple DES cipher type (PKCS#11 provider)
585 * @return the DES-EDE3-CBC EVP_CIPHER pointer.
587 * @ingroup hcrypto_evp
590 PKCS11_CIPHER_ALGORITHM(des_ede3_cbc,
591 CKM_DES3_CBC,
595 EVP_CIPH_CBC_MODE)
598 * The DES cipher type (PKCS#11 provider)
600 * @return the DES-CBC EVP_CIPHER pointer.
602 * @ingroup hcrypto_evp
605 PKCS11_CIPHER_ALGORITHM(des_cbc,
606 CKM_DES_CBC,
610 EVP_CIPH_CBC_MODE)
613 * The AES-128 cipher type (PKCS#11 provider)
615 * @return the AES-128-CBC EVP_CIPHER pointer.
617 * @ingroup hcrypto_evp
620 PKCS11_CIPHER_ALGORITHM(aes_128_cbc,
621 CKM_AES_CBC,
625 EVP_CIPH_CBC_MODE)
628 * The AES-192 cipher type (PKCS#11 provider)
630 * @return the AES-192-CBC EVP_CIPHER pointer.
632 * @ingroup hcrypto_evp
635 PKCS11_CIPHER_ALGORITHM(aes_192_cbc,
636 CKM_AES_CBC,
640 EVP_CIPH_CBC_MODE)
643 * The AES-256 cipher type (PKCS#11 provider)
645 * @return the AES-256-CBC EVP_CIPHER pointer.
647 * @ingroup hcrypto_evp
650 PKCS11_CIPHER_ALGORITHM(aes_256_cbc,
651 CKM_AES_CBC,
655 EVP_CIPH_CBC_MODE)
658 * The AES-128 CFB8 cipher type (PKCS#11 provider)
660 * @return the AES-128-CFB8 EVP_CIPHER pointer.
662 * @ingroup hcrypto_evp
665 PKCS11_CIPHER_ALGORITHM(aes_128_cfb8,
666 CKM_AES_CFB8,
670 EVP_CIPH_CFB8_MODE)
673 * The AES-192 CFB8 cipher type (PKCS#11 provider)
675 * @return the AES-192-CFB8 EVP_CIPHER pointer.
677 * @ingroup hcrypto_evp
680 PKCS11_CIPHER_ALGORITHM(aes_192_cfb8,
681 CKM_AES_CFB8,
685 EVP_CIPH_CFB8_MODE)
688 * The AES-256 CFB8 cipher type (PKCS#11 provider)
690 * @return the AES-256-CFB8 EVP_CIPHER pointer.
692 * @ingroup hcrypto_evp
695 PKCS11_CIPHER_ALGORITHM(aes_256_cfb8,
696 CKM_AES_CFB8,
700 EVP_CIPH_CFB8_MODE)
703 * The RC2 cipher type - PKCS#11
705 * @return the RC2 EVP_CIPHER pointer.
707 * @ingroup hcrypto_evp
710 PKCS11_CIPHER_ALGORITHM(rc2_cbc,
711 CKM_RC2_CBC,
715 EVP_CIPH_CBC_MODE | EVP_CIPH_VARIABLE_LENGTH)
718 * The RC2-40 cipher type - PKCS#11
720 * @return the RC2-40 EVP_CIPHER pointer.
722 * @ingroup hcrypto_evp
725 PKCS11_CIPHER_ALGORITHM(rc2_40_cbc,
726 CKM_RC2_CBC,
730 EVP_CIPH_CBC_MODE)
733 * The RC2-64 cipher type - PKCS#11
735 * @return the RC2-64 EVP_CIPHER pointer.
737 * @ingroup hcrypto_evp
740 PKCS11_CIPHER_ALGORITHM(rc2_64_cbc,
741 CKM_RC2_CBC,
745 EVP_CIPH_CBC_MODE)
748 * The Camellia-128 cipher type - PKCS#11
750 * @return the Camellia-128 EVP_CIPHER pointer.
752 * @ingroup hcrypto_evp
755 PKCS11_CIPHER_ALGORITHM(camellia_128_cbc,
756 CKM_CAMELLIA_CBC,
760 EVP_CIPH_CBC_MODE)
763 * The Camellia-198 cipher type - PKCS#11
765 * @return the Camellia-198 EVP_CIPHER pointer.
767 * @ingroup hcrypto_evp
770 PKCS11_CIPHER_ALGORITHM(camellia_192_cbc,
771 CKM_CAMELLIA_CBC,
775 EVP_CIPH_CBC_MODE)
778 * The Camellia-256 cipher type - PKCS#11
780 * @return the Camellia-256 EVP_CIPHER pointer.
782 * @ingroup hcrypto_evp
785 PKCS11_CIPHER_ALGORITHM(camellia_256_cbc,
786 CKM_CAMELLIA_CBC,
790 EVP_CIPH_CBC_MODE)
793 * The RC4 cipher type (PKCS#11 provider)
795 * @return the RC4 EVP_CIPHER pointer.
797 * @ingroup hcrypto_evp
800 PKCS11_CIPHER_ALGORITHM(rc4,
801 CKM_RC4,
805 EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH)
808 * The RC4-40 cipher type (PKCS#11 provider)
810 * @return the RC4 EVP_CIPHER pointer.
812 * @ingroup hcrypto_evp
815 PKCS11_CIPHER_ALGORITHM(rc4_40,
816 CKM_RC4,
820 EVP_CIPH_STREAM_CIPHER | EVP_CIPH_VARIABLE_LENGTH)
822 PKCS11_MD_ALGORITHM(md2, CKM_MD2, 16, 16)
823 #ifdef CKM_MD4 /* non-standard extension */
824 PKCS11_MD_ALGORITHM(md4, CKM_MD4, 16, 64)
825 #else
826 PKCS11_MD_ALGORITHM_UNAVAILABLE(md4)
827 #endif
828 PKCS11_MD_ALGORITHM(md5, CKM_MD5, 16, 64)
829 PKCS11_MD_ALGORITHM(sha1, CKM_SHA_1, 20, 64)
830 PKCS11_MD_ALGORITHM(sha256, CKM_SHA256, 32, 64)
831 PKCS11_MD_ALGORITHM(sha384, CKM_SHA384, 48, 128)
832 PKCS11_MD_ALGORITHM(sha512, CKM_SHA512, 64, 128)