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