1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_CRYPTO_IMPL_H 27 #define _SYS_CRYPTO_IMPL_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 /* 32 * Kernel Cryptographic Framework private implementation definitions. 33 */ 34 35 #include <sys/types.h> 36 #include <sys/param.h> 37 38 #ifdef _KERNEL 39 #include <sys/crypto/common.h> 40 #include <sys/crypto/api.h> 41 #include <sys/crypto/spi.h> 42 #include <sys/crypto/ioctl.h> 43 #include <sys/tnf_probe.h> 44 #include <sys/atomic.h> 45 #include <sys/project.h> 46 #include <sys/taskq.h> 47 #include <sys/rctl.h> 48 #endif /* _KERNEL */ 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 #ifdef _KERNEL 55 56 #define KCF_MODULE "kcf" 57 58 /* 59 * Prefixes convention: structures internal to the kernel cryptographic 60 * framework start with 'kcf_'. Exposed structure start with 'crypto_'. 61 */ 62 63 /* Provider stats. Not protected. */ 64 typedef struct kcf_prov_stats { 65 kstat_named_t ps_ops_total; 66 kstat_named_t ps_ops_passed; 67 kstat_named_t ps_ops_failed; 68 kstat_named_t ps_ops_busy_rval; 69 } kcf_prov_stats_t; 70 71 /* Various kcf stats. Not protected. */ 72 typedef struct kcf_stats { 73 kstat_named_t ks_thrs_in_pool; 74 kstat_named_t ks_idle_thrs; 75 kstat_named_t ks_minthrs; 76 kstat_named_t ks_maxthrs; 77 kstat_named_t ks_swq_njobs; 78 kstat_named_t ks_swq_maxjobs; 79 kstat_named_t ks_taskq_minalloc; 80 kstat_named_t ks_taskq_maxalloc; 81 } kcf_stats_t; 82 83 /* 84 * Keep all the information needed by the scheduler from 85 * this provider. 86 */ 87 typedef struct kcf_sched_info { 88 /* The number of operations dispatched. */ 89 uint64_t ks_ndispatches; 90 91 /* The number of operations that failed. */ 92 uint64_t ks_nfails; 93 94 /* The number of operations that returned CRYPTO_BUSY. */ 95 uint64_t ks_nbusy_rval; 96 97 /* taskq used to dispatch crypto requests */ 98 taskq_t *ks_taskq; 99 } kcf_sched_info_t; 100 101 #define KCF_PROV_INCRSTATS(pd, error) { \ 102 (pd)->pd_sched_info.ks_ndispatches++; \ 103 if (error == CRYPTO_BUSY) \ 104 (pd)->pd_sched_info.ks_nbusy_rval++; \ 105 else if (error != CRYPTO_SUCCESS && error != CRYPTO_QUEUED) \ 106 (pd)->pd_sched_info.ks_nfails++; \ 107 } 108 109 110 /* 111 * The following two macros should be 112 * #define KCF_OPS_CLASSSIZE (KCF_LAST_OPSCLASS - KCF_FIRST_OPSCLASS + 2) 113 * #define KCF_MAXMECHTAB KCF_MAXCIPHER 114 * 115 * However, doing that would involve reorganizing the header file a bit. 116 * When impl.h is broken up (bug# 4703218), this will be done. For now, 117 * we hardcode these values. 118 */ 119 #define KCF_OPS_CLASSSIZE 8 120 #define KCF_MAXMECHTAB 32 121 122 /* 123 * Valid values for the state of a provider. The order of 124 * the elements is important. 125 * 126 * Routines which get a provider or the list of providers 127 * should pick only those that are either in KCF_PROV_READY state 128 * or in KCF_PROV_BUSY state. 129 */ 130 typedef enum { 131 KCF_PROV_ALLOCATED = 1, 132 KCF_PROV_UNVERIFIED, 133 /* 134 * state < KCF_PROV_READY means the provider can not 135 * be used at all. 136 */ 137 KCF_PROV_READY, 138 KCF_PROV_BUSY, 139 /* 140 * state > KCF_PROV_BUSY means the provider can not 141 * be used for new requests. 142 */ 143 KCF_PROV_FAILED, 144 /* 145 * Threads setting the following two states should do so only 146 * if the current state < KCF_PROV_DISABLED. 147 */ 148 KCF_PROV_DISABLED, 149 KCF_PROV_REMOVED, 150 KCF_PROV_FREED 151 } kcf_prov_state_t; 152 153 #define KCF_IS_PROV_UNVERIFIED(pd) ((pd)->pd_state == KCF_PROV_UNVERIFIED) 154 #define KCF_IS_PROV_USABLE(pd) ((pd)->pd_state == KCF_PROV_READY || \ 155 (pd)->pd_state == KCF_PROV_BUSY) 156 #define KCF_IS_PROV_REMOVED(pd) ((pd)->pd_state >= KCF_PROV_REMOVED) 157 158 /* Internal flags valid for pd_flags field */ 159 #define KCF_PROV_RESTRICTED 0x40000000 160 #define KCF_LPROV_MEMBER 0x80000000 /* is member of a logical provider */ 161 162 /* 163 * A provider descriptor structure. There is one such structure per 164 * provider. It is allocated and initialized at registration time and 165 * freed when the provider unregisters. 166 * 167 * pd_prov_type: Provider type, hardware or software 168 * pd_sid: Session ID of the provider used by kernel clients. 169 * This is valid only for session-oriented providers. 170 * pd_refcnt: Reference counter to this provider descriptor 171 * pd_irefcnt: References held by the framework internal structs 172 * pd_lock: lock protects pd_state and pd_provider_list 173 * pd_state: State value of the provider 174 * pd_provider_list: Used to cross-reference logical providers and their 175 * members. Not used for software providers. 176 * pd_resume_cv: cv to wait for state to change from KCF_PROV_BUSY 177 * pd_prov_handle: Provider handle specified by provider 178 * pd_ops_vector: The ops vector specified by Provider 179 * pd_mech_indx: Lookup table which maps a core framework mechanism 180 * number to an index in pd_mechanisms array 181 * pd_mechanisms: Array of mechanisms supported by the provider, specified 182 * by the provider during registration 183 * pd_sched_info: Scheduling information associated with the provider 184 * pd_mech_list_count: The number of entries in pi_mechanisms, specified 185 * by the provider during registration 186 * pd_name: Device name or module name 187 * pd_instance: Device instance 188 * pd_module_id: Module ID returned by modload 189 * pd_mctlp: Pointer to modctl structure for this provider 190 * pd_remove_cv: cv to wait on while the provider queue drains 191 * pd_description: Provider description string 192 * pd_flags bitwise OR of pi_flags from crypto_provider_info_t 193 * and other internal flags defined above. 194 * pd_hash_limit Maximum data size that hash mechanisms of this provider 195 * can support. 196 * pd_kcf_prov_handle: KCF-private handle assigned by KCF 197 * pd_prov_id: Identification # assigned by KCF to provider 198 * pd_kstat: kstat associated with the provider 199 * pd_ks_data: kstat data 200 */ 201 typedef struct kcf_provider_desc { 202 crypto_provider_type_t pd_prov_type; 203 crypto_session_id_t pd_sid; 204 uint_t pd_refcnt; 205 uint_t pd_irefcnt; 206 kmutex_t pd_lock; 207 kcf_prov_state_t pd_state; 208 struct kcf_provider_list *pd_provider_list; 209 kcondvar_t pd_resume_cv; 210 crypto_provider_handle_t pd_prov_handle; 211 crypto_ops_t *pd_ops_vector; 212 ushort_t pd_mech_indx[KCF_OPS_CLASSSIZE]\ 213 [KCF_MAXMECHTAB]; 214 crypto_mech_info_t *pd_mechanisms; 215 kcf_sched_info_t pd_sched_info; 216 uint_t pd_mech_list_count; 217 char *pd_name; 218 uint_t pd_instance; 219 int pd_module_id; 220 struct modctl *pd_mctlp; 221 kcondvar_t pd_remove_cv; 222 char *pd_description; 223 uint_t pd_flags; 224 uint_t pd_hash_limit; 225 crypto_kcf_provider_handle_t pd_kcf_prov_handle; 226 crypto_provider_id_t pd_prov_id; 227 kstat_t *pd_kstat; 228 kcf_prov_stats_t pd_ks_data; 229 } kcf_provider_desc_t; 230 231 /* useful for making a list of providers */ 232 typedef struct kcf_provider_list { 233 struct kcf_provider_list *pl_next; 234 struct kcf_provider_desc *pl_provider; 235 } kcf_provider_list_t; 236 237 /* 238 * If a component has a reference to a kcf_provider_desc_t, 239 * it REFHOLD()s. A new provider descriptor which is referenced only 240 * by the providers table has a reference counter of one. 241 */ 242 #define KCF_PROV_REFHOLD(desc) { \ 243 atomic_add_32(&(desc)->pd_refcnt, 1); \ 244 ASSERT((desc)->pd_refcnt != 0); \ 245 } 246 247 #define KCF_PROV_IREFHOLD(desc) { \ 248 atomic_add_32(&(desc)->pd_irefcnt, 1); \ 249 ASSERT((desc)->pd_irefcnt != 0); \ 250 } 251 252 #define KCF_PROV_IREFRELE(desc) { \ 253 ASSERT((desc)->pd_irefcnt != 0); \ 254 membar_exit(); \ 255 if (atomic_add_32_nv(&(desc)->pd_irefcnt, -1) == 0) { \ 256 cv_broadcast(&(desc)->pd_remove_cv); \ 257 } \ 258 } 259 260 #define KCF_PROV_REFHELD(desc) ((desc)->pd_refcnt >= 1) 261 262 #define KCF_PROV_REFRELE(desc) { \ 263 ASSERT((desc)->pd_refcnt != 0); \ 264 membar_exit(); \ 265 if (atomic_add_32_nv(&(desc)->pd_refcnt, -1) == 0) { \ 266 kcf_provider_zero_refcnt((desc)); \ 267 } \ 268 } 269 270 271 /* list of crypto_mech_info_t valid as the second mech in a dual operation */ 272 273 typedef struct crypto_mech_info_list { 274 struct crypto_mech_info_list *ml_next; 275 crypto_mech_type_t ml_kcf_mechid; /* KCF's id */ 276 crypto_mech_info_t ml_mech_info; 277 } crypto_mech_info_list_t; 278 279 /* 280 * An element in a mechanism provider descriptors chain. 281 * The kcf_prov_mech_desc_t is duplicated in every chain the provider belongs 282 * to. This is a small tradeoff memory vs mutex spinning time to access the 283 * common provider field. 284 */ 285 286 typedef struct kcf_prov_mech_desc { 287 struct kcf_mech_entry *pm_me; /* Back to the head */ 288 struct kcf_prov_mech_desc *pm_next; /* Next in the chain */ 289 crypto_mech_info_t pm_mech_info; /* Provider mech info */ 290 crypto_mech_info_list_t *pm_mi_list; /* list for duals */ 291 kcf_provider_desc_t *pm_prov_desc; /* Common desc. */ 292 } kcf_prov_mech_desc_t; 293 294 /* and the notation shortcuts ... */ 295 #define pm_provider_type pm_prov_desc.pd_provider_type 296 #define pm_provider_handle pm_prov_desc.pd_provider_handle 297 #define pm_ops_vector pm_prov_desc.pd_ops_vector 298 299 300 #define KCF_CPU_PAD (128 - sizeof (crypto_mech_name_t) - \ 301 sizeof (crypto_mech_type_t) - \ 302 sizeof (kmutex_t) - 2 * sizeof (kcf_prov_mech_desc_t *) - \ 303 sizeof (int) - sizeof (uint32_t) - sizeof (size_t)) 304 305 /* 306 * A mechanism entry in an xxx_mech_tab[]. KCF_CPU_PAD needs 307 * to be adjusted if this structure is changed. 308 */ 309 typedef struct kcf_mech_entry { 310 crypto_mech_name_t me_name; /* mechanism name */ 311 crypto_mech_type_t me_mechid; /* Internal id for mechanism */ 312 kmutex_t me_mutex; /* access protection */ 313 kcf_prov_mech_desc_t *me_hw_prov_chain; /* list of HW providers */ 314 kcf_prov_mech_desc_t *me_sw_prov; /* SW provider */ 315 /* 316 * Number of HW providers in the chain. There is only one 317 * SW provider. So, we need only a count of HW providers. 318 */ 319 int me_num_hwprov; 320 /* 321 * When a SW provider is present, this is the generation number that 322 * ensures no objects from old SW providers are used in the new one 323 */ 324 uint32_t me_gen_swprov; 325 /* 326 * threshold for using hardware providers for this mech 327 */ 328 size_t me_threshold; 329 uint8_t me_pad[KCF_CPU_PAD]; 330 } kcf_mech_entry_t; 331 332 /* 333 * A policy descriptor structure. It is allocated and initialized 334 * when administrative ioctls load disabled mechanisms. 335 * 336 * pd_prov_type: Provider type, hardware or software 337 * pd_name: Device name or module name. 338 * pd_instance: Device instance. 339 * pd_refcnt: Reference counter for this policy descriptor 340 * pd_mutex: Protects array and count of disabled mechanisms. 341 * pd_disabled_count: Count of disabled mechanisms. 342 * pd_disabled_mechs: Array of disabled mechanisms. 343 */ 344 typedef struct kcf_policy_desc { 345 crypto_provider_type_t pd_prov_type; 346 char *pd_name; 347 uint_t pd_instance; 348 uint_t pd_refcnt; 349 kmutex_t pd_mutex; 350 uint_t pd_disabled_count; 351 crypto_mech_name_t *pd_disabled_mechs; 352 } kcf_policy_desc_t; 353 354 /* 355 * If a component has a reference to a kcf_policy_desc_t, 356 * it REFHOLD()s. A new policy descriptor which is referenced only 357 * by the policy table has a reference count of one. 358 */ 359 #define KCF_POLICY_REFHOLD(desc) { \ 360 atomic_add_32(&(desc)->pd_refcnt, 1); \ 361 ASSERT((desc)->pd_refcnt != 0); \ 362 } 363 364 /* 365 * Releases a reference to a policy descriptor. When the last 366 * reference is released, the descriptor is freed. 367 */ 368 #define KCF_POLICY_REFRELE(desc) { \ 369 ASSERT((desc)->pd_refcnt != 0); \ 370 membar_exit(); \ 371 if (atomic_add_32_nv(&(desc)->pd_refcnt, -1) == 0) \ 372 kcf_policy_free_desc(desc); \ 373 } 374 375 /* 376 * This entry stores the name of a software module and its 377 * mechanisms. The mechanisms are 'hints' that are used to 378 * trigger loading of the module. 379 */ 380 typedef struct kcf_soft_conf_entry { 381 struct kcf_soft_conf_entry *ce_next; 382 char *ce_name; 383 crypto_mech_name_t *ce_mechs; 384 uint_t ce_count; 385 } kcf_soft_conf_entry_t; 386 387 extern kmutex_t soft_config_mutex; 388 extern kcf_soft_conf_entry_t *soft_config_list; 389 390 /* 391 * Global tables. The sizes are from the predefined PKCS#11 v2.20 mechanisms, 392 * with a margin of few extra empty entry points 393 */ 394 395 #define KCF_MAXDIGEST 16 /* Digests */ 396 #define KCF_MAXCIPHER 64 /* Ciphers */ 397 #define KCF_MAXMAC 40 /* Message authentication codes */ 398 #define KCF_MAXSIGN 24 /* Sign/Verify */ 399 #define KCF_MAXKEYOPS 116 /* Key generation and derivation */ 400 #define KCF_MAXMISC 16 /* Others ... */ 401 402 #define KCF_MAXMECHS KCF_MAXDIGEST + KCF_MAXCIPHER + KCF_MAXMAC + \ 403 KCF_MAXSIGN + KCF_MAXKEYOPS + \ 404 KCF_MAXMISC 405 406 extern kcf_mech_entry_t kcf_digest_mechs_tab[]; 407 extern kcf_mech_entry_t kcf_cipher_mechs_tab[]; 408 extern kcf_mech_entry_t kcf_mac_mechs_tab[]; 409 extern kcf_mech_entry_t kcf_sign_mechs_tab[]; 410 extern kcf_mech_entry_t kcf_keyops_mechs_tab[]; 411 extern kcf_mech_entry_t kcf_misc_mechs_tab[]; 412 413 extern kmutex_t kcf_mech_tabs_lock; 414 415 typedef enum { 416 KCF_DIGEST_CLASS = 1, 417 KCF_CIPHER_CLASS, 418 KCF_MAC_CLASS, 419 KCF_SIGN_CLASS, 420 KCF_KEYOPS_CLASS, 421 KCF_MISC_CLASS 422 } kcf_ops_class_t; 423 424 #define KCF_FIRST_OPSCLASS KCF_DIGEST_CLASS 425 #define KCF_LAST_OPSCLASS KCF_MISC_CLASS 426 427 /* The table of all the kcf_xxx_mech_tab[]s, indexed by kcf_ops_class */ 428 429 typedef struct kcf_mech_entry_tab { 430 int met_size; /* Size of the met_tab[] */ 431 kcf_mech_entry_t *met_tab; /* the table */ 432 } kcf_mech_entry_tab_t; 433 434 extern kcf_mech_entry_tab_t kcf_mech_tabs_tab[]; 435 436 #define KCF_MECHID(class, index) \ 437 (((crypto_mech_type_t)(class) << 32) | (crypto_mech_type_t)(index)) 438 439 #define KCF_MECH2CLASS(mech_type) ((kcf_ops_class_t)((mech_type) >> 32)) 440 441 #define KCF_MECH2INDEX(mech_type) ((int)(mech_type)) 442 443 #define KCF_TO_PROV_MECH_INDX(pd, mech_type) \ 444 ((pd)->pd_mech_indx[KCF_MECH2CLASS(mech_type)] \ 445 [KCF_MECH2INDEX(mech_type)]) 446 447 #define KCF_TO_PROV_MECHINFO(pd, mech_type) \ 448 ((pd)->pd_mechanisms[KCF_TO_PROV_MECH_INDX(pd, mech_type)]) 449 450 #define KCF_TO_PROV_MECHNUM(pd, mech_type) \ 451 (KCF_TO_PROV_MECHINFO(pd, mech_type).cm_mech_number) 452 453 #define KCF_CAN_SHARE_OPSTATE(pd, mech_type) \ 454 ((KCF_TO_PROV_MECHINFO(pd, mech_type).cm_mech_flags) & \ 455 CRYPTO_CAN_SHARE_OPSTATE) 456 457 /* ps_refcnt is protected by cm_lock in the crypto_minor structure */ 458 typedef struct crypto_provider_session { 459 struct crypto_provider_session *ps_next; 460 crypto_session_id_t ps_session; 461 kcf_provider_desc_t *ps_provider; 462 kcf_provider_desc_t *ps_real_provider; 463 uint_t ps_refcnt; 464 } crypto_provider_session_t; 465 466 typedef struct crypto_session_data { 467 kmutex_t sd_lock; 468 kcondvar_t sd_cv; 469 uint32_t sd_flags; 470 crypto_ctx_t *sd_digest_ctx; 471 crypto_ctx_t *sd_encr_ctx; 472 crypto_ctx_t *sd_decr_ctx; 473 crypto_ctx_t *sd_sign_ctx; 474 crypto_ctx_t *sd_verify_ctx; 475 crypto_ctx_t *sd_sign_recover_ctx; 476 crypto_ctx_t *sd_verify_recover_ctx; 477 kcf_provider_desc_t *sd_provider; 478 void *sd_find_init_cookie; 479 crypto_provider_session_t *sd_provider_session; 480 } crypto_session_data_t; 481 482 #define CRYPTO_SESSION_IN_USE 0x00000001 483 #define CRYPTO_SESSION_IS_BUSY 0x00000002 484 #define CRYPTO_SESSION_IS_CLOSED 0x00000004 485 486 #define KCF_MAX_PIN_LEN 1024 487 488 /* 489 * Per-minor info. 490 * 491 * cm_lock protects everything in this structure except for cm_refcnt. 492 */ 493 typedef struct crypto_minor { 494 uint_t cm_refcnt; 495 kmutex_t cm_lock; 496 kcondvar_t cm_cv; 497 crypto_session_data_t **cm_session_table; 498 uint_t cm_session_table_count; 499 kcf_provider_desc_t **cm_provider_array; 500 uint_t cm_provider_count; 501 crypto_provider_session_t *cm_provider_session; 502 } crypto_minor_t; 503 504 /* resource control framework handle used by /dev/crypto */ 505 extern rctl_hndl_t rc_project_crypto_mem; 506 /* 507 * Return codes for internal functions 508 */ 509 #define KCF_SUCCESS 0x0 /* Successful call */ 510 #define KCF_INVALID_MECH_NUMBER 0x1 /* invalid mechanism number */ 511 #define KCF_INVALID_MECH_NAME 0x2 /* invalid mechanism name */ 512 #define KCF_INVALID_MECH_CLASS 0x3 /* invalid mechanism class */ 513 #define KCF_MECH_TAB_FULL 0x4 /* Need more room in the mech tabs. */ 514 #define KCF_INVALID_INDX ((ushort_t)-1) 515 516 /* 517 * kCF internal mechanism and function group for tracking RNG providers. 518 */ 519 #define SUN_RANDOM "random" 520 #define CRYPTO_FG_RANDOM 0x80000000 /* generate_random() */ 521 522 /* 523 * Wrappers for ops vectors. In the wrapper definitions below, the pd 524 * argument always corresponds to a pointer to a provider descriptor 525 * of type kcf_prov_desc_t. 526 */ 527 528 #define KCF_PROV_CONTROL_OPS(pd) ((pd)->pd_ops_vector->co_control_ops) 529 #define KCF_PROV_CTX_OPS(pd) ((pd)->pd_ops_vector->co_ctx_ops) 530 #define KCF_PROV_DIGEST_OPS(pd) ((pd)->pd_ops_vector->co_digest_ops) 531 #define KCF_PROV_CIPHER_OPS(pd) ((pd)->pd_ops_vector->co_cipher_ops) 532 #define KCF_PROV_MAC_OPS(pd) ((pd)->pd_ops_vector->co_mac_ops) 533 #define KCF_PROV_SIGN_OPS(pd) ((pd)->pd_ops_vector->co_sign_ops) 534 #define KCF_PROV_VERIFY_OPS(pd) ((pd)->pd_ops_vector->co_verify_ops) 535 #define KCF_PROV_DUAL_OPS(pd) ((pd)->pd_ops_vector->co_dual_ops) 536 #define KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) \ 537 ((pd)->pd_ops_vector->co_dual_cipher_mac_ops) 538 #define KCF_PROV_RANDOM_OPS(pd) ((pd)->pd_ops_vector->co_random_ops) 539 #define KCF_PROV_SESSION_OPS(pd) ((pd)->pd_ops_vector->co_session_ops) 540 #define KCF_PROV_OBJECT_OPS(pd) ((pd)->pd_ops_vector->co_object_ops) 541 #define KCF_PROV_KEY_OPS(pd) ((pd)->pd_ops_vector->co_key_ops) 542 #define KCF_PROV_PROVIDER_OPS(pd) ((pd)->pd_ops_vector->co_provider_ops) 543 #define KCF_PROV_MECH_OPS(pd) ((pd)->pd_ops_vector->co_mech_ops) 544 #define KCF_PROV_NOSTORE_KEY_OPS(pd) \ 545 ((pd)->pd_ops_vector->co_nostore_key_ops) 546 547 /* 548 * Wrappers for crypto_control_ops(9S) entry points. 549 */ 550 551 #define KCF_PROV_STATUS(pd, status) ( \ 552 (KCF_PROV_CONTROL_OPS(pd) && \ 553 KCF_PROV_CONTROL_OPS(pd)->provider_status) ? \ 554 KCF_PROV_CONTROL_OPS(pd)->provider_status( \ 555 (pd)->pd_prov_handle, status) : \ 556 CRYPTO_NOT_SUPPORTED) 557 558 /* 559 * Wrappers for crypto_ctx_ops(9S) entry points. 560 */ 561 562 #define KCF_PROV_CREATE_CTX_TEMPLATE(pd, mech, key, template, size, req) ( \ 563 (KCF_PROV_CTX_OPS(pd) && KCF_PROV_CTX_OPS(pd)->create_ctx_template) ? \ 564 KCF_PROV_CTX_OPS(pd)->create_ctx_template( \ 565 (pd)->pd_prov_handle, mech, key, template, size, req) : \ 566 CRYPTO_NOT_SUPPORTED) 567 568 #define KCF_PROV_FREE_CONTEXT(pd, ctx) ( \ 569 (KCF_PROV_CTX_OPS(pd) && KCF_PROV_CTX_OPS(pd)->free_context) ? \ 570 KCF_PROV_CTX_OPS(pd)->free_context(ctx) : CRYPTO_NOT_SUPPORTED) 571 572 #define KCF_PROV_COPYIN_MECH(pd, umech, kmech, errorp, mode) ( \ 573 (KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->copyin_mechanism) ? \ 574 KCF_PROV_MECH_OPS(pd)->copyin_mechanism( \ 575 (pd)->pd_prov_handle, umech, kmech, errorp, mode) : \ 576 CRYPTO_NOT_SUPPORTED) 577 578 #define KCF_PROV_COPYOUT_MECH(pd, kmech, umech, errorp, mode) ( \ 579 (KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->copyout_mechanism) ? \ 580 KCF_PROV_MECH_OPS(pd)->copyout_mechanism( \ 581 (pd)->pd_prov_handle, kmech, umech, errorp, mode) : \ 582 CRYPTO_NOT_SUPPORTED) 583 584 #define KCF_PROV_FREE_MECH(pd, prov_mech) ( \ 585 (KCF_PROV_MECH_OPS(pd) && KCF_PROV_MECH_OPS(pd)->free_mechanism) ? \ 586 KCF_PROV_MECH_OPS(pd)->free_mechanism( \ 587 (pd)->pd_prov_handle, prov_mech) : CRYPTO_NOT_SUPPORTED) 588 589 /* 590 * Wrappers for crypto_digest_ops(9S) entry points. 591 */ 592 593 #define KCF_PROV_DIGEST_INIT(pd, ctx, mech, req) ( \ 594 (KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_init) ? \ 595 KCF_PROV_DIGEST_OPS(pd)->digest_init(ctx, mech, req) : \ 596 CRYPTO_NOT_SUPPORTED) 597 598 /* 599 * The _ (underscore) in _digest is needed to avoid replacing the 600 * function digest(). 601 */ 602 #define KCF_PROV_DIGEST(pd, ctx, data, _digest, req) ( \ 603 (KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest) ? \ 604 KCF_PROV_DIGEST_OPS(pd)->digest(ctx, data, _digest, req) : \ 605 CRYPTO_NOT_SUPPORTED) 606 607 #define KCF_PROV_DIGEST_UPDATE(pd, ctx, data, req) ( \ 608 (KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_update) ? \ 609 KCF_PROV_DIGEST_OPS(pd)->digest_update(ctx, data, req) : \ 610 CRYPTO_NOT_SUPPORTED) 611 612 #define KCF_PROV_DIGEST_KEY(pd, ctx, key, req) ( \ 613 (KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_key) ? \ 614 KCF_PROV_DIGEST_OPS(pd)->digest_key(ctx, key, req) : \ 615 CRYPTO_NOT_SUPPORTED) 616 617 #define KCF_PROV_DIGEST_FINAL(pd, ctx, digest, req) ( \ 618 (KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_final) ? \ 619 KCF_PROV_DIGEST_OPS(pd)->digest_final(ctx, digest, req) : \ 620 CRYPTO_NOT_SUPPORTED) 621 622 #define KCF_PROV_DIGEST_ATOMIC(pd, session, mech, data, digest, req) ( \ 623 (KCF_PROV_DIGEST_OPS(pd) && KCF_PROV_DIGEST_OPS(pd)->digest_atomic) ? \ 624 KCF_PROV_DIGEST_OPS(pd)->digest_atomic( \ 625 (pd)->pd_prov_handle, session, mech, data, digest, req) : \ 626 CRYPTO_NOT_SUPPORTED) 627 628 /* 629 * Wrappers for crypto_cipher_ops(9S) entry points. 630 */ 631 632 #define KCF_PROV_ENCRYPT_INIT(pd, ctx, mech, key, template, req) ( \ 633 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_init) ? \ 634 KCF_PROV_CIPHER_OPS(pd)->encrypt_init(ctx, mech, key, template, \ 635 req) : \ 636 CRYPTO_NOT_SUPPORTED) 637 638 #define KCF_PROV_ENCRYPT(pd, ctx, plaintext, ciphertext, req) ( \ 639 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt) ? \ 640 KCF_PROV_CIPHER_OPS(pd)->encrypt(ctx, plaintext, ciphertext, req) : \ 641 CRYPTO_NOT_SUPPORTED) 642 643 #define KCF_PROV_ENCRYPT_UPDATE(pd, ctx, plaintext, ciphertext, req) ( \ 644 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_update) ? \ 645 KCF_PROV_CIPHER_OPS(pd)->encrypt_update(ctx, plaintext, \ 646 ciphertext, req) : \ 647 CRYPTO_NOT_SUPPORTED) 648 649 #define KCF_PROV_ENCRYPT_FINAL(pd, ctx, ciphertext, req) ( \ 650 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_final) ? \ 651 KCF_PROV_CIPHER_OPS(pd)->encrypt_final(ctx, ciphertext, req) : \ 652 CRYPTO_NOT_SUPPORTED) 653 654 #define KCF_PROV_ENCRYPT_ATOMIC(pd, session, mech, key, plaintext, ciphertext, \ 655 template, req) ( \ 656 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->encrypt_atomic) ? \ 657 KCF_PROV_CIPHER_OPS(pd)->encrypt_atomic( \ 658 (pd)->pd_prov_handle, session, mech, key, plaintext, ciphertext, \ 659 template, req) : \ 660 CRYPTO_NOT_SUPPORTED) 661 662 #define KCF_PROV_DECRYPT_INIT(pd, ctx, mech, key, template, req) ( \ 663 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_init) ? \ 664 KCF_PROV_CIPHER_OPS(pd)->decrypt_init(ctx, mech, key, template, \ 665 req) : \ 666 CRYPTO_NOT_SUPPORTED) 667 668 #define KCF_PROV_DECRYPT(pd, ctx, ciphertext, plaintext, req) ( \ 669 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt) ? \ 670 KCF_PROV_CIPHER_OPS(pd)->decrypt(ctx, ciphertext, plaintext, req) : \ 671 CRYPTO_NOT_SUPPORTED) 672 673 #define KCF_PROV_DECRYPT_UPDATE(pd, ctx, ciphertext, plaintext, req) ( \ 674 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_update) ? \ 675 KCF_PROV_CIPHER_OPS(pd)->decrypt_update(ctx, ciphertext, \ 676 plaintext, req) : \ 677 CRYPTO_NOT_SUPPORTED) 678 679 #define KCF_PROV_DECRYPT_FINAL(pd, ctx, plaintext, req) ( \ 680 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_final) ? \ 681 KCF_PROV_CIPHER_OPS(pd)->decrypt_final(ctx, plaintext, req) : \ 682 CRYPTO_NOT_SUPPORTED) 683 684 #define KCF_PROV_DECRYPT_ATOMIC(pd, session, mech, key, ciphertext, plaintext, \ 685 template, req) ( \ 686 (KCF_PROV_CIPHER_OPS(pd) && KCF_PROV_CIPHER_OPS(pd)->decrypt_atomic) ? \ 687 KCF_PROV_CIPHER_OPS(pd)->decrypt_atomic( \ 688 (pd)->pd_prov_handle, session, mech, key, ciphertext, plaintext, \ 689 template, req) : \ 690 CRYPTO_NOT_SUPPORTED) 691 692 /* 693 * Wrappers for crypto_mac_ops(9S) entry points. 694 */ 695 696 #define KCF_PROV_MAC_INIT(pd, ctx, mech, key, template, req) ( \ 697 (KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_init) ? \ 698 KCF_PROV_MAC_OPS(pd)->mac_init(ctx, mech, key, template, req) \ 699 : CRYPTO_NOT_SUPPORTED) 700 701 /* 702 * The _ (underscore) in _mac is needed to avoid replacing the 703 * function mac(). 704 */ 705 #define KCF_PROV_MAC(pd, ctx, data, _mac, req) ( \ 706 (KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac) ? \ 707 KCF_PROV_MAC_OPS(pd)->mac(ctx, data, _mac, req) : \ 708 CRYPTO_NOT_SUPPORTED) 709 710 #define KCF_PROV_MAC_UPDATE(pd, ctx, data, req) ( \ 711 (KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_update) ? \ 712 KCF_PROV_MAC_OPS(pd)->mac_update(ctx, data, req) : \ 713 CRYPTO_NOT_SUPPORTED) 714 715 #define KCF_PROV_MAC_FINAL(pd, ctx, mac, req) ( \ 716 (KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_final) ? \ 717 KCF_PROV_MAC_OPS(pd)->mac_final(ctx, mac, req) : \ 718 CRYPTO_NOT_SUPPORTED) 719 720 #define KCF_PROV_MAC_ATOMIC(pd, session, mech, key, data, mac, template, \ 721 req) ( \ 722 (KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_atomic) ? \ 723 KCF_PROV_MAC_OPS(pd)->mac_atomic( \ 724 (pd)->pd_prov_handle, session, mech, key, data, mac, template, \ 725 req) : \ 726 CRYPTO_NOT_SUPPORTED) 727 728 #define KCF_PROV_MAC_VERIFY_ATOMIC(pd, session, mech, key, data, mac, \ 729 template, req) ( \ 730 (KCF_PROV_MAC_OPS(pd) && KCF_PROV_MAC_OPS(pd)->mac_verify_atomic) ? \ 731 KCF_PROV_MAC_OPS(pd)->mac_verify_atomic( \ 732 (pd)->pd_prov_handle, session, mech, key, data, mac, template, \ 733 req) : \ 734 CRYPTO_NOT_SUPPORTED) 735 736 /* 737 * Wrappers for crypto_sign_ops(9S) entry points. 738 */ 739 740 #define KCF_PROV_SIGN_INIT(pd, ctx, mech, key, template, req) ( \ 741 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_init) ? \ 742 KCF_PROV_SIGN_OPS(pd)->sign_init( \ 743 ctx, mech, key, template, req) : CRYPTO_NOT_SUPPORTED) 744 745 #define KCF_PROV_SIGN(pd, ctx, data, sig, req) ( \ 746 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign) ? \ 747 KCF_PROV_SIGN_OPS(pd)->sign(ctx, data, sig, req) : \ 748 CRYPTO_NOT_SUPPORTED) 749 750 #define KCF_PROV_SIGN_UPDATE(pd, ctx, data, req) ( \ 751 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_update) ? \ 752 KCF_PROV_SIGN_OPS(pd)->sign_update(ctx, data, req) : \ 753 CRYPTO_NOT_SUPPORTED) 754 755 #define KCF_PROV_SIGN_FINAL(pd, ctx, sig, req) ( \ 756 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_final) ? \ 757 KCF_PROV_SIGN_OPS(pd)->sign_final(ctx, sig, req) : \ 758 CRYPTO_NOT_SUPPORTED) 759 760 #define KCF_PROV_SIGN_ATOMIC(pd, session, mech, key, data, template, \ 761 sig, req) ( \ 762 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_atomic) ? \ 763 KCF_PROV_SIGN_OPS(pd)->sign_atomic( \ 764 (pd)->pd_prov_handle, session, mech, key, data, sig, template, \ 765 req) : CRYPTO_NOT_SUPPORTED) 766 767 #define KCF_PROV_SIGN_RECOVER_INIT(pd, ctx, mech, key, template, \ 768 req) ( \ 769 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_recover_init) ? \ 770 KCF_PROV_SIGN_OPS(pd)->sign_recover_init(ctx, mech, key, template, \ 771 req) : CRYPTO_NOT_SUPPORTED) 772 773 #define KCF_PROV_SIGN_RECOVER(pd, ctx, data, sig, req) ( \ 774 (KCF_PROV_SIGN_OPS(pd) && KCF_PROV_SIGN_OPS(pd)->sign_recover) ? \ 775 KCF_PROV_SIGN_OPS(pd)->sign_recover(ctx, data, sig, req) : \ 776 CRYPTO_NOT_SUPPORTED) 777 778 #define KCF_PROV_SIGN_RECOVER_ATOMIC(pd, session, mech, key, data, template, \ 779 sig, req) ( \ 780 (KCF_PROV_SIGN_OPS(pd) && \ 781 KCF_PROV_SIGN_OPS(pd)->sign_recover_atomic) ? \ 782 KCF_PROV_SIGN_OPS(pd)->sign_recover_atomic( \ 783 (pd)->pd_prov_handle, session, mech, key, data, sig, template, \ 784 req) : CRYPTO_NOT_SUPPORTED) 785 786 /* 787 * Wrappers for crypto_verify_ops(9S) entry points. 788 */ 789 790 #define KCF_PROV_VERIFY_INIT(pd, ctx, mech, key, template, req) ( \ 791 (KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_init) ? \ 792 KCF_PROV_VERIFY_OPS(pd)->verify_init(ctx, mech, key, template, \ 793 req) : CRYPTO_NOT_SUPPORTED) 794 795 #define KCF_PROV_VERIFY(pd, ctx, data, sig, req) ( \ 796 (KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify) ? \ 797 KCF_PROV_VERIFY_OPS(pd)->verify(ctx, data, sig, req) : \ 798 CRYPTO_NOT_SUPPORTED) 799 800 #define KCF_PROV_VERIFY_UPDATE(pd, ctx, data, req) ( \ 801 (KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_update) ? \ 802 KCF_PROV_VERIFY_OPS(pd)->verify_update(ctx, data, req) : \ 803 CRYPTO_NOT_SUPPORTED) 804 805 #define KCF_PROV_VERIFY_FINAL(pd, ctx, sig, req) ( \ 806 (KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_final) ? \ 807 KCF_PROV_VERIFY_OPS(pd)->verify_final(ctx, sig, req) : \ 808 CRYPTO_NOT_SUPPORTED) 809 810 #define KCF_PROV_VERIFY_ATOMIC(pd, session, mech, key, data, template, sig, \ 811 req) ( \ 812 (KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_atomic) ? \ 813 KCF_PROV_VERIFY_OPS(pd)->verify_atomic( \ 814 (pd)->pd_prov_handle, session, mech, key, data, sig, template, \ 815 req) : CRYPTO_NOT_SUPPORTED) 816 817 #define KCF_PROV_VERIFY_RECOVER_INIT(pd, ctx, mech, key, template, \ 818 req) ( \ 819 (KCF_PROV_VERIFY_OPS(pd) && \ 820 KCF_PROV_VERIFY_OPS(pd)->verify_recover_init) ? \ 821 KCF_PROV_VERIFY_OPS(pd)->verify_recover_init(ctx, mech, key, \ 822 template, req) : CRYPTO_NOT_SUPPORTED) 823 824 /* verify_recover() CSPI routine has different argument order than verify() */ 825 #define KCF_PROV_VERIFY_RECOVER(pd, ctx, sig, data, req) ( \ 826 (KCF_PROV_VERIFY_OPS(pd) && KCF_PROV_VERIFY_OPS(pd)->verify_recover) ? \ 827 KCF_PROV_VERIFY_OPS(pd)->verify_recover(ctx, sig, data, req) : \ 828 CRYPTO_NOT_SUPPORTED) 829 830 /* 831 * verify_recover_atomic() CSPI routine has different argument order 832 * than verify_atomic(). 833 */ 834 #define KCF_PROV_VERIFY_RECOVER_ATOMIC(pd, session, mech, key, sig, \ 835 template, data, req) ( \ 836 (KCF_PROV_VERIFY_OPS(pd) && \ 837 KCF_PROV_VERIFY_OPS(pd)->verify_recover_atomic) ? \ 838 KCF_PROV_VERIFY_OPS(pd)->verify_recover_atomic( \ 839 (pd)->pd_prov_handle, session, mech, key, sig, data, template, \ 840 req) : CRYPTO_NOT_SUPPORTED) 841 842 /* 843 * Wrappers for crypto_dual_ops(9S) entry points. 844 */ 845 846 #define KCF_PROV_DIGEST_ENCRYPT_UPDATE(digest_ctx, encrypt_ctx, plaintext, \ 847 ciphertext, req) ( \ 848 (KCF_PROV_DUAL_OPS(pd) && \ 849 KCF_PROV_DUAL_OPS(pd)->digest_encrypt_update) ? \ 850 KCF_PROV_DUAL_OPS(pd)->digest_encrypt_update( \ 851 digest_ctx, encrypt_ctx, plaintext, ciphertext, req) : \ 852 CRYPTO_NOT_SUPPORTED) 853 854 #define KCF_PROV_DECRYPT_DIGEST_UPDATE(decrypt_ctx, digest_ctx, ciphertext, \ 855 plaintext, req) ( \ 856 (KCF_PROV_DUAL_OPS(pd) && \ 857 KCF_PROV_DUAL_OPS(pd)->decrypt_digest_update) ? \ 858 KCF_PROV_DUAL_OPS(pd)->decrypt_digest_update( \ 859 decrypt_ctx, digest_ctx, ciphertext, plaintext, req) : \ 860 CRYPTO_NOT_SUPPORTED) 861 862 #define KCF_PROV_SIGN_ENCRYPT_UPDATE(sign_ctx, encrypt_ctx, plaintext, \ 863 ciphertext, req) ( \ 864 (KCF_PROV_DUAL_OPS(pd) && \ 865 KCF_PROV_DUAL_OPS(pd)->sign_encrypt_update) ? \ 866 KCF_PROV_DUAL_OPS(pd)->sign_encrypt_update( \ 867 sign_ctx, encrypt_ctx, plaintext, ciphertext, req) : \ 868 CRYPTO_NOT_SUPPORTED) 869 870 #define KCF_PROV_DECRYPT_VERIFY_UPDATE(decrypt_ctx, verify_ctx, ciphertext, \ 871 plaintext, req) ( \ 872 (KCF_PROV_DUAL_OPS(pd) && \ 873 KCF_PROV_DUAL_OPS(pd)->decrypt_verify_update) ? \ 874 KCF_PROV_DUAL_OPS(pd)->decrypt_verify_update( \ 875 decrypt_ctx, verify_ctx, ciphertext, plaintext, req) : \ 876 CRYPTO_NOT_SUPPORTED) 877 878 /* 879 * Wrappers for crypto_dual_cipher_mac_ops(9S) entry points. 880 */ 881 882 #define KCF_PROV_ENCRYPT_MAC_INIT(pd, ctx, encr_mech, encr_key, mac_mech, \ 883 mac_key, encr_ctx_template, mac_ctx_template, req) ( \ 884 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 885 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_init) ? \ 886 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_init( \ 887 ctx, encr_mech, encr_key, mac_mech, mac_key, encr_ctx_template, \ 888 mac_ctx_template, req) : \ 889 CRYPTO_NOT_SUPPORTED) 890 891 #define KCF_PROV_ENCRYPT_MAC(pd, ctx, plaintext, ciphertext, mac, req) ( \ 892 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 893 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac) ? \ 894 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac( \ 895 ctx, plaintext, ciphertext, mac, req) : \ 896 CRYPTO_NOT_SUPPORTED) 897 898 #define KCF_PROV_ENCRYPT_MAC_UPDATE(pd, ctx, plaintext, ciphertext, req) ( \ 899 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 900 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_update) ? \ 901 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_update( \ 902 ctx, plaintext, ciphertext, req) : \ 903 CRYPTO_NOT_SUPPORTED) 904 905 #define KCF_PROV_ENCRYPT_MAC_FINAL(pd, ctx, ciphertext, mac, req) ( \ 906 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 907 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_final) ? \ 908 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_final( \ 909 ctx, ciphertext, mac, req) : \ 910 CRYPTO_NOT_SUPPORTED) 911 912 #define KCF_PROV_ENCRYPT_MAC_ATOMIC(pd, session, encr_mech, encr_key, \ 913 mac_mech, mac_key, plaintext, ciphertext, mac, \ 914 encr_ctx_template, mac_ctx_template, req) ( \ 915 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 916 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_atomic) ? \ 917 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->encrypt_mac_atomic( \ 918 (pd)->pd_prov_handle, session, encr_mech, encr_key, \ 919 mac_mech, mac_key, plaintext, ciphertext, mac, \ 920 encr_ctx_template, mac_ctx_template, req) : \ 921 CRYPTO_NOT_SUPPORTED) 922 923 #define KCF_PROV_MAC_DECRYPT_INIT(pd, ctx, mac_mech, mac_key, decr_mech, \ 924 decr_key, mac_ctx_template, decr_ctx_template, req) ( \ 925 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 926 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_init) ? \ 927 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_init( \ 928 ctx, mac_mech, mac_key, decr_mech, decr_key, mac_ctx_template, \ 929 decr_ctx_template, req) : \ 930 CRYPTO_NOT_SUPPORTED) 931 932 #define KCF_PROV_MAC_DECRYPT(pd, ctx, ciphertext, mac, plaintext, req) ( \ 933 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 934 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt) ? \ 935 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt( \ 936 ctx, ciphertext, mac, plaintext, req) : \ 937 CRYPTO_NOT_SUPPORTED) 938 939 #define KCF_PROV_MAC_DECRYPT_UPDATE(pd, ctx, ciphertext, plaintext, req) ( \ 940 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 941 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_update) ? \ 942 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_update( \ 943 ctx, ciphertext, plaintext, req) : \ 944 CRYPTO_NOT_SUPPORTED) 945 946 #define KCF_PROV_MAC_DECRYPT_FINAL(pd, ctx, mac, plaintext, req) ( \ 947 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 948 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_final) ? \ 949 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_final( \ 950 ctx, mac, plaintext, req) : \ 951 CRYPTO_NOT_SUPPORTED) 952 953 #define KCF_PROV_MAC_DECRYPT_ATOMIC(pd, session, mac_mech, mac_key, \ 954 decr_mech, decr_key, ciphertext, mac, plaintext, \ 955 mac_ctx_template, decr_ctx_template, req) ( \ 956 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 957 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_atomic) ? \ 958 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_decrypt_atomic( \ 959 (pd)->pd_prov_handle, session, mac_mech, mac_key, \ 960 decr_mech, decr_key, ciphertext, mac, plaintext, \ 961 mac_ctx_template, decr_ctx_template, req) : \ 962 CRYPTO_NOT_SUPPORTED) 963 964 #define KCF_PROV_MAC_VERIFY_DECRYPT_ATOMIC(pd, session, mac_mech, mac_key, \ 965 decr_mech, decr_key, ciphertext, mac, plaintext, \ 966 mac_ctx_template, decr_ctx_template, req) ( \ 967 (KCF_PROV_DUAL_CIPHER_MAC_OPS(pd) && \ 968 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_verify_decrypt_atomic \ 969 != NULL) ? \ 970 KCF_PROV_DUAL_CIPHER_MAC_OPS(pd)->mac_verify_decrypt_atomic( \ 971 (pd)->pd_prov_handle, session, mac_mech, mac_key, \ 972 decr_mech, decr_key, ciphertext, mac, plaintext, \ 973 mac_ctx_template, decr_ctx_template, req) : \ 974 CRYPTO_NOT_SUPPORTED) 975 976 /* 977 * Wrappers for crypto_random_number_ops(9S) entry points. 978 */ 979 980 #define KCF_PROV_SEED_RANDOM(pd, session, buf, len, est, flags, req) ( \ 981 (KCF_PROV_RANDOM_OPS(pd) && KCF_PROV_RANDOM_OPS(pd)->seed_random) ? \ 982 KCF_PROV_RANDOM_OPS(pd)->seed_random((pd)->pd_prov_handle, \ 983 session, buf, len, est, flags, req) : CRYPTO_NOT_SUPPORTED) 984 985 #define KCF_PROV_GENERATE_RANDOM(pd, session, buf, len, req) ( \ 986 (KCF_PROV_RANDOM_OPS(pd) && \ 987 KCF_PROV_RANDOM_OPS(pd)->generate_random) ? \ 988 KCF_PROV_RANDOM_OPS(pd)->generate_random((pd)->pd_prov_handle, \ 989 session, buf, len, req) : CRYPTO_NOT_SUPPORTED) 990 991 /* 992 * Wrappers for crypto_session_ops(9S) entry points. 993 * 994 * ops_pd is the provider descriptor that supplies the ops_vector. 995 * pd is the descriptor that supplies the provider handle. 996 * Only session open/close needs two handles. 997 */ 998 999 #define KCF_PROV_SESSION_OPEN(ops_pd, session, req, pd) ( \ 1000 (KCF_PROV_SESSION_OPS(ops_pd) && \ 1001 KCF_PROV_SESSION_OPS(ops_pd)->session_open) ? \ 1002 KCF_PROV_SESSION_OPS(ops_pd)->session_open((pd)->pd_prov_handle, \ 1003 session, req) : CRYPTO_NOT_SUPPORTED) 1004 1005 #define KCF_PROV_SESSION_CLOSE(ops_pd, session, req, pd) ( \ 1006 (KCF_PROV_SESSION_OPS(ops_pd) && \ 1007 KCF_PROV_SESSION_OPS(ops_pd)->session_close) ? \ 1008 KCF_PROV_SESSION_OPS(ops_pd)->session_close((pd)->pd_prov_handle, \ 1009 session, req) : CRYPTO_NOT_SUPPORTED) 1010 1011 #define KCF_PROV_SESSION_LOGIN(pd, session, user_type, pin, len, req) ( \ 1012 (KCF_PROV_SESSION_OPS(pd) && \ 1013 KCF_PROV_SESSION_OPS(pd)->session_login) ? \ 1014 KCF_PROV_SESSION_OPS(pd)->session_login((pd)->pd_prov_handle, \ 1015 session, user_type, pin, len, req) : CRYPTO_NOT_SUPPORTED) 1016 1017 #define KCF_PROV_SESSION_LOGOUT(pd, session, req) ( \ 1018 (KCF_PROV_SESSION_OPS(pd) && \ 1019 KCF_PROV_SESSION_OPS(pd)->session_logout) ? \ 1020 KCF_PROV_SESSION_OPS(pd)->session_logout((pd)->pd_prov_handle, \ 1021 session, req) : CRYPTO_NOT_SUPPORTED) 1022 1023 /* 1024 * Wrappers for crypto_object_ops(9S) entry points. 1025 */ 1026 1027 #define KCF_PROV_OBJECT_CREATE(pd, session, template, count, object, req) ( \ 1028 (KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_create) ? \ 1029 KCF_PROV_OBJECT_OPS(pd)->object_create((pd)->pd_prov_handle, \ 1030 session, template, count, object, req) : CRYPTO_NOT_SUPPORTED) 1031 1032 #define KCF_PROV_OBJECT_COPY(pd, session, object, template, count, \ 1033 new_object, req) ( \ 1034 (KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_copy) ? \ 1035 KCF_PROV_OBJECT_OPS(pd)->object_copy((pd)->pd_prov_handle, \ 1036 session, object, template, count, new_object, req) : \ 1037 CRYPTO_NOT_SUPPORTED) 1038 1039 #define KCF_PROV_OBJECT_DESTROY(pd, session, object, req) ( \ 1040 (KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_destroy) ? \ 1041 KCF_PROV_OBJECT_OPS(pd)->object_destroy((pd)->pd_prov_handle, \ 1042 session, object, req) : CRYPTO_NOT_SUPPORTED) 1043 1044 #define KCF_PROV_OBJECT_GET_SIZE(pd, session, object, size, req) ( \ 1045 (KCF_PROV_OBJECT_OPS(pd) && \ 1046 KCF_PROV_OBJECT_OPS(pd)->object_get_size) ? \ 1047 KCF_PROV_OBJECT_OPS(pd)->object_get_size((pd)->pd_prov_handle, \ 1048 session, object, size, req) : CRYPTO_NOT_SUPPORTED) 1049 1050 #define KCF_PROV_OBJECT_GET_ATTRIBUTE_VALUE(pd, session, object, template, \ 1051 count, req) ( \ 1052 (KCF_PROV_OBJECT_OPS(pd) && \ 1053 KCF_PROV_OBJECT_OPS(pd)->object_get_attribute_value) ? \ 1054 KCF_PROV_OBJECT_OPS(pd)->object_get_attribute_value( \ 1055 (pd)->pd_prov_handle, session, object, template, count, req) : \ 1056 CRYPTO_NOT_SUPPORTED) 1057 1058 #define KCF_PROV_OBJECT_SET_ATTRIBUTE_VALUE(pd, session, object, template, \ 1059 count, req) ( \ 1060 (KCF_PROV_OBJECT_OPS(pd) && \ 1061 KCF_PROV_OBJECT_OPS(pd)->object_set_attribute_value) ? \ 1062 KCF_PROV_OBJECT_OPS(pd)->object_set_attribute_value( \ 1063 (pd)->pd_prov_handle, session, object, template, count, req) : \ 1064 CRYPTO_NOT_SUPPORTED) 1065 1066 #define KCF_PROV_OBJECT_FIND_INIT(pd, session, template, count, ppriv, \ 1067 req) ( \ 1068 (KCF_PROV_OBJECT_OPS(pd) && \ 1069 KCF_PROV_OBJECT_OPS(pd)->object_find_init) ? \ 1070 KCF_PROV_OBJECT_OPS(pd)->object_find_init((pd)->pd_prov_handle, \ 1071 session, template, count, ppriv, req) : CRYPTO_NOT_SUPPORTED) 1072 1073 #define KCF_PROV_OBJECT_FIND(pd, ppriv, objects, max_objects, object_count, \ 1074 req) ( \ 1075 (KCF_PROV_OBJECT_OPS(pd) && KCF_PROV_OBJECT_OPS(pd)->object_find) ? \ 1076 KCF_PROV_OBJECT_OPS(pd)->object_find( \ 1077 (pd)->pd_prov_handle, ppriv, objects, max_objects, object_count, \ 1078 req) : CRYPTO_NOT_SUPPORTED) 1079 1080 #define KCF_PROV_OBJECT_FIND_FINAL(pd, ppriv, req) ( \ 1081 (KCF_PROV_OBJECT_OPS(pd) && \ 1082 KCF_PROV_OBJECT_OPS(pd)->object_find_final) ? \ 1083 KCF_PROV_OBJECT_OPS(pd)->object_find_final( \ 1084 (pd)->pd_prov_handle, ppriv, req) : CRYPTO_NOT_SUPPORTED) 1085 1086 /* 1087 * Wrappers for crypto_key_ops(9S) entry points. 1088 */ 1089 1090 #define KCF_PROV_KEY_GENERATE(pd, session, mech, template, count, object, \ 1091 req) ( \ 1092 (KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_generate) ? \ 1093 KCF_PROV_KEY_OPS(pd)->key_generate((pd)->pd_prov_handle, \ 1094 session, mech, template, count, object, req) : \ 1095 CRYPTO_NOT_SUPPORTED) 1096 1097 #define KCF_PROV_KEY_GENERATE_PAIR(pd, session, mech, pub_template, \ 1098 pub_count, priv_template, priv_count, pub_key, priv_key, req) ( \ 1099 (KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_generate_pair) ? \ 1100 KCF_PROV_KEY_OPS(pd)->key_generate_pair((pd)->pd_prov_handle, \ 1101 session, mech, pub_template, pub_count, priv_template, \ 1102 priv_count, pub_key, priv_key, req) : \ 1103 CRYPTO_NOT_SUPPORTED) 1104 1105 #define KCF_PROV_KEY_WRAP(pd, session, mech, wrapping_key, key, wrapped_key, \ 1106 wrapped_key_len, req) ( \ 1107 (KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_wrap) ? \ 1108 KCF_PROV_KEY_OPS(pd)->key_wrap((pd)->pd_prov_handle, \ 1109 session, mech, wrapping_key, key, wrapped_key, wrapped_key_len, \ 1110 req) : \ 1111 CRYPTO_NOT_SUPPORTED) 1112 1113 #define KCF_PROV_KEY_UNWRAP(pd, session, mech, unwrapping_key, wrapped_key, \ 1114 wrapped_key_len, template, count, key, req) ( \ 1115 (KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_unwrap) ? \ 1116 KCF_PROV_KEY_OPS(pd)->key_unwrap((pd)->pd_prov_handle, \ 1117 session, mech, unwrapping_key, wrapped_key, wrapped_key_len, \ 1118 template, count, key, req) : \ 1119 CRYPTO_NOT_SUPPORTED) 1120 1121 #define KCF_PROV_KEY_DERIVE(pd, session, mech, base_key, template, count, \ 1122 key, req) ( \ 1123 (KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_derive) ? \ 1124 KCF_PROV_KEY_OPS(pd)->key_derive((pd)->pd_prov_handle, \ 1125 session, mech, base_key, template, count, key, req) : \ 1126 CRYPTO_NOT_SUPPORTED) 1127 1128 #define KCF_PROV_KEY_CHECK(pd, mech, key) ( \ 1129 (KCF_PROV_KEY_OPS(pd) && KCF_PROV_KEY_OPS(pd)->key_check) ? \ 1130 KCF_PROV_KEY_OPS(pd)->key_check((pd)->pd_prov_handle, mech, key) : \ 1131 CRYPTO_NOT_SUPPORTED) 1132 1133 /* 1134 * Wrappers for crypto_provider_management_ops(9S) entry points. 1135 * 1136 * ops_pd is the provider descriptor that supplies the ops_vector. 1137 * pd is the descriptor that supplies the provider handle. 1138 * Only ext_info needs two handles. 1139 */ 1140 1141 #define KCF_PROV_EXT_INFO(ops_pd, provext_info, req, pd) ( \ 1142 (KCF_PROV_PROVIDER_OPS(ops_pd) && \ 1143 KCF_PROV_PROVIDER_OPS(ops_pd)->ext_info) ? \ 1144 KCF_PROV_PROVIDER_OPS(ops_pd)->ext_info((pd)->pd_prov_handle, \ 1145 provext_info, req) : CRYPTO_NOT_SUPPORTED) 1146 1147 #define KCF_PROV_INIT_TOKEN(pd, pin, pin_len, label, req) ( \ 1148 (KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->init_token) ? \ 1149 KCF_PROV_PROVIDER_OPS(pd)->init_token((pd)->pd_prov_handle, \ 1150 pin, pin_len, label, req) : CRYPTO_NOT_SUPPORTED) 1151 1152 #define KCF_PROV_INIT_PIN(pd, session, pin, pin_len, req) ( \ 1153 (KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->init_pin) ? \ 1154 KCF_PROV_PROVIDER_OPS(pd)->init_pin((pd)->pd_prov_handle, \ 1155 session, pin, pin_len, req) : CRYPTO_NOT_SUPPORTED) 1156 1157 #define KCF_PROV_SET_PIN(pd, session, old_pin, old_len, new_pin, new_len, \ 1158 req) ( \ 1159 (KCF_PROV_PROVIDER_OPS(pd) && KCF_PROV_PROVIDER_OPS(pd)->set_pin) ? \ 1160 KCF_PROV_PROVIDER_OPS(pd)->set_pin((pd)->pd_prov_handle, \ 1161 session, old_pin, old_len, new_pin, new_len, req) : \ 1162 CRYPTO_NOT_SUPPORTED) 1163 1164 /* 1165 * Wrappers for crypto_nostore_key_ops(9S) entry points. 1166 */ 1167 1168 #define KCF_PROV_NOSTORE_KEY_GENERATE(pd, session, mech, template, count, \ 1169 out_template, out_count, req) ( \ 1170 (KCF_PROV_NOSTORE_KEY_OPS(pd) && \ 1171 KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate) ? \ 1172 KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate( \ 1173 (pd)->pd_prov_handle, session, mech, template, count, \ 1174 out_template, out_count, req) : CRYPTO_NOT_SUPPORTED) 1175 1176 #define KCF_PROV_NOSTORE_KEY_GENERATE_PAIR(pd, session, mech, pub_template, \ 1177 pub_count, priv_template, priv_count, out_pub_template, \ 1178 out_pub_count, out_priv_template, out_priv_count, req) ( \ 1179 (KCF_PROV_NOSTORE_KEY_OPS(pd) && \ 1180 KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate_pair) ? \ 1181 KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_generate_pair( \ 1182 (pd)->pd_prov_handle, session, mech, pub_template, pub_count, \ 1183 priv_template, priv_count, out_pub_template, out_pub_count, \ 1184 out_priv_template, out_priv_count, req) : CRYPTO_NOT_SUPPORTED) 1185 1186 #define KCF_PROV_NOSTORE_KEY_DERIVE(pd, session, mech, base_key, template, \ 1187 count, out_template, out_count, req) ( \ 1188 (KCF_PROV_NOSTORE_KEY_OPS(pd) && \ 1189 KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_derive) ? \ 1190 KCF_PROV_NOSTORE_KEY_OPS(pd)->nostore_key_derive( \ 1191 (pd)->pd_prov_handle, session, mech, base_key, template, count, \ 1192 out_template, out_count, req) : CRYPTO_NOT_SUPPORTED) 1193 1194 /* 1195 * The following routines are exported by the kcf module (/kernel/misc/kcf) 1196 * to the crypto and cryptoadmin modules. 1197 */ 1198 1199 /* Digest/mac/cipher entry points that take a provider descriptor and session */ 1200 extern int crypto_digest_single(crypto_context_t, crypto_data_t *, 1201 crypto_data_t *, crypto_call_req_t *); 1202 1203 extern int crypto_mac_single(crypto_context_t, crypto_data_t *, 1204 crypto_data_t *, crypto_call_req_t *); 1205 1206 extern int crypto_encrypt_single(crypto_context_t, crypto_data_t *, 1207 crypto_data_t *, crypto_call_req_t *); 1208 1209 extern int crypto_decrypt_single(crypto_context_t, crypto_data_t *, 1210 crypto_data_t *, crypto_call_req_t *); 1211 1212 1213 /* Other private digest/mac/cipher entry points not exported through k-API */ 1214 extern int crypto_digest_key_prov(crypto_context_t, crypto_key_t *, 1215 crypto_call_req_t *); 1216 1217 /* Private sign entry points exported by KCF */ 1218 extern int crypto_sign_single(crypto_context_t, crypto_data_t *, 1219 crypto_data_t *, crypto_call_req_t *); 1220 1221 extern int crypto_sign_recover_single(crypto_context_t, crypto_data_t *, 1222 crypto_data_t *, crypto_call_req_t *); 1223 1224 /* Private verify entry points exported by KCF */ 1225 extern int crypto_verify_single(crypto_context_t, crypto_data_t *, 1226 crypto_data_t *, crypto_call_req_t *); 1227 1228 extern int crypto_verify_recover_single(crypto_context_t, crypto_data_t *, 1229 crypto_data_t *, crypto_call_req_t *); 1230 1231 /* Private dual operations entry points exported by KCF */ 1232 extern int crypto_digest_encrypt_update(crypto_context_t, crypto_context_t, 1233 crypto_data_t *, crypto_data_t *, crypto_call_req_t *); 1234 extern int crypto_decrypt_digest_update(crypto_context_t, crypto_context_t, 1235 crypto_data_t *, crypto_data_t *, crypto_call_req_t *); 1236 extern int crypto_sign_encrypt_update(crypto_context_t, crypto_context_t, 1237 crypto_data_t *, crypto_data_t *, crypto_call_req_t *); 1238 extern int crypto_decrypt_verify_update(crypto_context_t, crypto_context_t, 1239 crypto_data_t *, crypto_data_t *, crypto_call_req_t *); 1240 1241 /* Random Number Generation */ 1242 int crypto_seed_random(crypto_provider_handle_t provider, uchar_t *buf, 1243 size_t len, crypto_call_req_t *req); 1244 int crypto_generate_random(crypto_provider_handle_t provider, uchar_t *buf, 1245 size_t len, crypto_call_req_t *req); 1246 1247 /* Provider Management */ 1248 int crypto_get_provider_info(crypto_provider_id_t id, 1249 crypto_provider_info_t **info, crypto_call_req_t *req); 1250 int crypto_get_provider_mechanisms(crypto_minor_t *, crypto_provider_id_t id, 1251 uint_t *count, crypto_mech_name_t **list); 1252 int crypto_init_token(crypto_provider_handle_t provider, char *pin, 1253 size_t pin_len, char *label, crypto_call_req_t *); 1254 int crypto_init_pin(crypto_provider_handle_t provider, char *pin, 1255 size_t pin_len, crypto_call_req_t *req); 1256 int crypto_set_pin(crypto_provider_handle_t provider, char *old_pin, 1257 size_t old_len, char *new_pin, size_t new_len, crypto_call_req_t *req); 1258 void crypto_free_provider_list(crypto_provider_entry_t *list, uint_t count); 1259 void crypto_free_provider_info(crypto_provider_info_t *info); 1260 1261 /* Administrative */ 1262 int crypto_get_dev_list(uint_t *count, crypto_dev_list_entry_t **list); 1263 int crypto_get_soft_list(uint_t *count, char **list, size_t *len); 1264 int crypto_get_dev_info(char *name, uint_t instance, uint_t *count, 1265 crypto_mech_name_t **list); 1266 int crypto_get_soft_info(caddr_t name, uint_t *count, 1267 crypto_mech_name_t **list); 1268 int crypto_load_dev_disabled(char *name, uint_t instance, uint_t count, 1269 crypto_mech_name_t *list); 1270 int crypto_load_soft_disabled(caddr_t name, uint_t count, 1271 crypto_mech_name_t *list); 1272 int crypto_unload_soft_module(caddr_t path); 1273 int crypto_load_soft_config(caddr_t name, uint_t count, 1274 crypto_mech_name_t *list); 1275 int crypto_load_door(uint_t did); 1276 void crypto_free_mech_list(crypto_mech_name_t *list, uint_t count); 1277 void crypto_free_dev_list(crypto_dev_list_entry_t *list, uint_t count); 1278 1279 /* Miscellaneous */ 1280 int crypto_get_mechanism_number(caddr_t name, crypto_mech_type_t *number); 1281 int crypto_get_function_list(crypto_provider_id_t id, 1282 crypto_function_list_t **list, int kmflag); 1283 void crypto_free_function_list(crypto_function_list_t *list); 1284 int crypto_build_permitted_mech_names(kcf_provider_desc_t *, 1285 crypto_mech_name_t **, uint_t *, int); 1286 extern void kcf_init_mech_tabs(void); 1287 extern int kcf_add_mech_provider(short, kcf_provider_desc_t *, 1288 kcf_prov_mech_desc_t **); 1289 extern void kcf_remove_mech_provider(char *, kcf_provider_desc_t *); 1290 extern int kcf_get_mech_entry(crypto_mech_type_t, kcf_mech_entry_t **); 1291 extern kcf_provider_desc_t *kcf_alloc_provider_desc(crypto_provider_info_t *); 1292 extern void kcf_provider_zero_refcnt(kcf_provider_desc_t *); 1293 extern void kcf_free_provider_desc(kcf_provider_desc_t *); 1294 extern void kcf_soft_config_init(void); 1295 extern int get_sw_provider_for_mech(crypto_mech_name_t, char **); 1296 extern void kcf_dup_mech(crypto_mechanism_t *, crypto_mechanism_t *, 1297 crypto_mech_type_t *); 1298 extern crypto_mech_type_t crypto_mech2id_common(char *, boolean_t); 1299 extern void undo_register_provider(kcf_provider_desc_t *, boolean_t); 1300 extern void redo_register_provider(kcf_provider_desc_t *); 1301 extern void kcf_rnd_init(); 1302 extern boolean_t kcf_rngprov_check(void); 1303 extern int kcf_rnd_get_pseudo_bytes(uint8_t *, size_t); 1304 extern int kcf_rnd_get_bytes(uint8_t *, size_t, boolean_t, boolean_t); 1305 extern int random_add_pseudo_entropy(uint8_t *, size_t, uint_t); 1306 extern void kcf_rnd_chpoll(int, short *, struct pollhead **); 1307 extern void kcf_rnd_schedule_timeout(boolean_t); 1308 1309 /* Access to the provider's table */ 1310 extern void kcf_prov_tab_init(void); 1311 extern int kcf_prov_tab_add_provider(kcf_provider_desc_t *); 1312 extern int kcf_prov_tab_rem_provider(crypto_provider_id_t); 1313 extern kcf_provider_desc_t *kcf_prov_tab_lookup_by_name(char *); 1314 extern kcf_provider_desc_t *kcf_prov_tab_lookup_by_dev(char *, uint_t); 1315 extern int kcf_get_hw_prov_tab(uint_t *, kcf_provider_desc_t ***, int, 1316 char *, uint_t, boolean_t); 1317 extern int kcf_get_slot_list(uint_t *, kcf_provider_desc_t ***, boolean_t); 1318 extern void kcf_free_provider_tab(uint_t, kcf_provider_desc_t **); 1319 extern kcf_provider_desc_t *kcf_prov_tab_lookup(crypto_provider_id_t); 1320 extern int kcf_get_sw_prov(crypto_mech_type_t, kcf_provider_desc_t **, 1321 kcf_mech_entry_t **, boolean_t); 1322 1323 /* Access to the policy table */ 1324 extern boolean_t is_mech_disabled(kcf_provider_desc_t *, crypto_mech_name_t); 1325 extern boolean_t is_mech_disabled_byname(crypto_provider_type_t, char *, 1326 uint_t, crypto_mech_name_t); 1327 extern void kcf_policy_tab_init(void); 1328 extern void kcf_policy_free_desc(kcf_policy_desc_t *); 1329 extern void kcf_policy_remove_by_name(char *, uint_t *, crypto_mech_name_t **); 1330 extern void kcf_policy_remove_by_dev(char *, uint_t, uint_t *, 1331 crypto_mech_name_t **); 1332 extern kcf_policy_desc_t *kcf_policy_lookup_by_name(char *); 1333 extern kcf_policy_desc_t *kcf_policy_lookup_by_dev(char *, uint_t); 1334 extern int kcf_policy_load_soft_disabled(char *, uint_t, crypto_mech_name_t *, 1335 uint_t *, crypto_mech_name_t **); 1336 extern int kcf_policy_load_dev_disabled(char *, uint_t, uint_t, 1337 crypto_mech_name_t *, uint_t *, crypto_mech_name_t **); 1338 extern boolean_t in_soft_config_list(char *); 1339 1340 #endif /* _KERNEL */ 1341 1342 #ifdef __cplusplus 1343 } 1344 #endif 1345 1346 #endif /* _SYS_CRYPTO_IMPL_H */ 1347