1 /* $FreeBSD: stable/12/sys/opencrypto/cryptodev.h 370613 2021-09-16 11:22:57Z git2svn $ */ 2 /* $OpenBSD: cryptodev.h,v 1.31 2002/06/11 11:14:29 beck Exp $ */ 3 4 /*- 5 * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) 6 * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting 7 * 8 * This code was written by Angelos D. Keromytis in Athens, Greece, in 9 * February 2000. Network Security Technologies Inc. (NSTI) kindly 10 * supported the development of this code. 11 * 12 * Copyright (c) 2000 Angelos D. Keromytis 13 * 14 * Permission to use, copy, and modify this software with or without fee 15 * is hereby granted, provided that this entire notice is included in 16 * all source code copies of any software which is or includes a copy or 17 * modification of this software. 18 * 19 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 20 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY 21 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 22 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 23 * PURPOSE. 24 * 25 * Copyright (c) 2001 Theo de Raadt 26 * Copyright (c) 2014 The FreeBSD Foundation 27 * All rights reserved. 28 * 29 * Portions of this software were developed by John-Mark Gurney 30 * under sponsorship of the FreeBSD Foundation and 31 * Rubicon Communications, LLC (Netgate). 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 37 * 1. Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 2. Redistributions in binary form must reproduce the above copyright 40 * notice, this list of conditions and the following disclaimer in the 41 * documentation and/or other materials provided with the distribution. 42 * 3. The name of the author may not be used to endorse or promote products 43 * derived from this software without specific prior written permission. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 48 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 * 56 * Effort sponsored in part by the Defense Advanced Research Projects 57 * Agency (DARPA) and Air Force Research Laboratory, Air Force 58 * Materiel Command, USAF, under agreement number F30602-01-2-0537. 59 * 60 */ 61 62 #ifndef _CRYPTO_CRYPTO_H_ 63 #define _CRYPTO_CRYPTO_H_ 64 65 #include <sys/ioccom.h> 66 67 #ifdef _KERNEL 68 #include <opencrypto/_cryptodev.h> 69 #include <sys/_task.h> 70 #endif 71 72 /* Some initial values */ 73 #define CRYPTO_DRIVERS_INITIAL 4 74 #define CRYPTO_SW_SESSIONS 32 75 76 /* Hash values */ 77 #define NULL_HASH_LEN 16 78 #define MD5_HASH_LEN 16 79 #define SHA1_HASH_LEN 20 80 #define RIPEMD160_HASH_LEN 20 81 #define SHA2_224_HASH_LEN 28 82 #define SHA2_256_HASH_LEN 32 83 #define SHA2_384_HASH_LEN 48 84 #define SHA2_512_HASH_LEN 64 85 #define MD5_KPDK_HASH_LEN 16 86 #define SHA1_KPDK_HASH_LEN 20 87 #define AES_GMAC_HASH_LEN 16 88 #define POLY1305_HASH_LEN 16 89 #define AES_CBC_MAC_HASH_LEN 16 90 /* Maximum hash algorithm result length */ 91 #define HASH_MAX_LEN SHA2_512_HASH_LEN /* Keep this updated */ 92 93 #define MD5_BLOCK_LEN 64 94 #define SHA1_BLOCK_LEN 64 95 #define RIPEMD160_BLOCK_LEN 64 96 #define SHA2_224_BLOCK_LEN 64 97 #define SHA2_256_BLOCK_LEN 64 98 #define SHA2_384_BLOCK_LEN 128 99 #define SHA2_512_BLOCK_LEN 128 100 101 /* HMAC values */ 102 #define NULL_HMAC_BLOCK_LEN 64 103 /* Maximum HMAC block length */ 104 #define HMAC_MAX_BLOCK_LEN SHA2_512_BLOCK_LEN /* Keep this updated */ 105 #define HMAC_IPAD_VAL 0x36 106 #define HMAC_OPAD_VAL 0x5C 107 /* HMAC Key Length */ 108 #define AES_128_GMAC_KEY_LEN 16 109 #define AES_192_GMAC_KEY_LEN 24 110 #define AES_256_GMAC_KEY_LEN 32 111 #define AES_128_CBC_MAC_KEY_LEN 16 112 #define AES_192_CBC_MAC_KEY_LEN 24 113 #define AES_256_CBC_MAC_KEY_LEN 32 114 115 #define POLY1305_KEY_LEN 32 116 117 /* Encryption algorithm block sizes */ 118 #define NULL_BLOCK_LEN 4 /* IPsec to maintain alignment */ 119 #define DES_BLOCK_LEN 8 120 #define DES3_BLOCK_LEN 8 121 #define BLOWFISH_BLOCK_LEN 8 122 #define SKIPJACK_BLOCK_LEN 8 123 #define CAST128_BLOCK_LEN 8 124 #define RIJNDAEL128_BLOCK_LEN 16 125 #define AES_BLOCK_LEN 16 126 #define AES_ICM_BLOCK_LEN 1 127 #define ARC4_BLOCK_LEN 1 128 #define CAMELLIA_BLOCK_LEN 16 129 #define CHACHA20_NATIVE_BLOCK_LEN 64 130 #define EALG_MAX_BLOCK_LEN CHACHA20_NATIVE_BLOCK_LEN /* Keep this updated */ 131 132 /* IV Lengths */ 133 134 #define ARC4_IV_LEN 1 135 #define AES_GCM_IV_LEN 12 136 #define AES_CCM_IV_LEN 12 137 #define AES_XTS_IV_LEN 8 138 #define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */ 139 140 /* Min and Max Encryption Key Sizes */ 141 #define NULL_MIN_KEY 0 142 #define NULL_MAX_KEY 256 /* 2048 bits, max key */ 143 #define DES_MIN_KEY 8 144 #define DES_MAX_KEY DES_MIN_KEY 145 #define TRIPLE_DES_MIN_KEY 24 146 #define TRIPLE_DES_MAX_KEY TRIPLE_DES_MIN_KEY 147 #define BLOWFISH_MIN_KEY 5 148 #define BLOWFISH_MAX_KEY 56 /* 448 bits, max key */ 149 #define CAST_MIN_KEY 5 150 #define CAST_MAX_KEY 16 151 #define SKIPJACK_MIN_KEY 10 152 #define SKIPJACK_MAX_KEY SKIPJACK_MIN_KEY 153 #define RIJNDAEL_MIN_KEY 16 154 #define RIJNDAEL_MAX_KEY 32 155 #define AES_MIN_KEY RIJNDAEL_MIN_KEY 156 #define AES_MAX_KEY RIJNDAEL_MAX_KEY 157 #define AES_XTS_MIN_KEY (2 * AES_MIN_KEY) 158 #define AES_XTS_MAX_KEY (2 * AES_MAX_KEY) 159 #define ARC4_MIN_KEY 1 160 #define ARC4_MAX_KEY 32 161 #define CAMELLIA_MIN_KEY 16 162 #define CAMELLIA_MAX_KEY 32 163 164 /* Maximum hash algorithm result length */ 165 #define AALG_MAX_RESULT_LEN 64 /* Keep this updated */ 166 167 #define CRYPTO_ALGORITHM_MIN 1 168 #define CRYPTO_DES_CBC 1 169 #define CRYPTO_3DES_CBC 2 170 #define CRYPTO_BLF_CBC 3 171 #define CRYPTO_CAST_CBC 4 172 #define CRYPTO_SKIPJACK_CBC 5 173 #define CRYPTO_MD5_HMAC 6 174 #define CRYPTO_SHA1_HMAC 7 175 #define CRYPTO_RIPEMD160_HMAC 8 176 #define CRYPTO_MD5_KPDK 9 177 #define CRYPTO_SHA1_KPDK 10 178 #define CRYPTO_RIJNDAEL128_CBC 11 /* 128 bit blocksize */ 179 #define CRYPTO_AES_CBC 11 /* 128 bit blocksize -- the same as above */ 180 #define CRYPTO_ARC4 12 181 #define CRYPTO_MD5 13 182 #define CRYPTO_SHA1 14 183 #define CRYPTO_NULL_HMAC 15 184 #define CRYPTO_NULL_CBC 16 185 #define CRYPTO_DEFLATE_COMP 17 /* Deflate compression algorithm */ 186 #define CRYPTO_SHA2_256_HMAC 18 187 #define CRYPTO_SHA2_384_HMAC 19 188 #define CRYPTO_SHA2_512_HMAC 20 189 #define CRYPTO_CAMELLIA_CBC 21 190 #define CRYPTO_AES_XTS 22 191 #define CRYPTO_AES_ICM 23 /* commonly known as CTR mode */ 192 #define CRYPTO_AES_NIST_GMAC 24 /* cipher side */ 193 #define CRYPTO_AES_NIST_GCM_16 25 /* 16 byte ICV */ 194 #define CRYPTO_AES_128_NIST_GMAC 26 /* auth side */ 195 #define CRYPTO_AES_192_NIST_GMAC 27 /* auth side */ 196 #define CRYPTO_AES_256_NIST_GMAC 28 /* auth side */ 197 #define CRYPTO_BLAKE2B 29 /* Blake2b hash */ 198 #define CRYPTO_BLAKE2S 30 /* Blake2s hash */ 199 #define CRYPTO_CHACHA20 31 /* Chacha20 stream cipher */ 200 #define CRYPTO_SHA2_224_HMAC 32 201 #define CRYPTO_RIPEMD160 33 202 #define CRYPTO_SHA2_224 34 203 #define CRYPTO_SHA2_256 35 204 #define CRYPTO_SHA2_384 36 205 #define CRYPTO_SHA2_512 37 206 #define CRYPTO_POLY1305 38 207 #define CRYPTO_AES_CCM_CBC_MAC 39 /* auth side */ 208 #define CRYPTO_AES_CCM_16 40 /* cipher side */ 209 #define CRYPTO_ALGORITHM_MAX 40 /* Keep updated - see below */ 210 211 #define CRYPTO_ALGO_VALID(x) ((x) >= CRYPTO_ALGORITHM_MIN && \ 212 (x) <= CRYPTO_ALGORITHM_MAX) 213 214 /* Algorithm flags */ 215 #define CRYPTO_ALG_FLAG_SUPPORTED 0x01 /* Algorithm is supported */ 216 #define CRYPTO_ALG_FLAG_RNG_ENABLE 0x02 /* Has HW RNG for DH/DSA */ 217 #define CRYPTO_ALG_FLAG_DSA_SHA 0x04 /* Can do SHA on msg */ 218 219 /* 220 * Crypto driver/device flags. They can set in the crid 221 * parameter when creating a session or submitting a key 222 * op to affect the device/driver assigned. If neither 223 * of these are specified then the crid is assumed to hold 224 * the driver id of an existing (and suitable) device that 225 * must be used to satisfy the request. 226 */ 227 #define CRYPTO_FLAG_HARDWARE 0x01000000 /* hardware accelerated */ 228 #define CRYPTO_FLAG_SOFTWARE 0x02000000 /* software implementation */ 229 230 /* NB: deprecated */ 231 struct session_op { 232 u_int32_t cipher; /* ie. CRYPTO_DES_CBC */ 233 u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */ 234 235 u_int32_t keylen; /* cipher key */ 236 c_caddr_t key; 237 int mackeylen; /* mac key */ 238 c_caddr_t mackey; 239 240 u_int32_t ses; /* returns: session # */ 241 }; 242 243 /* 244 * session and crypt _op structs are used by userspace programs to interact 245 * with /dev/crypto. Confusingly, the internal kernel interface is named 246 * "cryptop" (no underscore). 247 */ 248 struct session2_op { 249 u_int32_t cipher; /* ie. CRYPTO_DES_CBC */ 250 u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */ 251 252 u_int32_t keylen; /* cipher key */ 253 c_caddr_t key; 254 int mackeylen; /* mac key */ 255 c_caddr_t mackey; 256 257 u_int32_t ses; /* returns: session # */ 258 int crid; /* driver id + flags (rw) */ 259 int pad[4]; /* for future expansion */ 260 }; 261 262 struct crypt_op { 263 u_int32_t ses; 264 u_int16_t op; /* i.e. COP_ENCRYPT */ 265 #define COP_ENCRYPT 1 266 #define COP_DECRYPT 2 267 u_int16_t flags; 268 #define COP_F_CIPHER_FIRST 0x0001 /* Cipher before MAC. */ 269 #define COP_F_BATCH 0x0008 /* Batch op if possible */ 270 u_int len; 271 c_caddr_t src; /* become iov[] inside kernel */ 272 caddr_t dst; 273 caddr_t mac; /* must be big enough for chosen MAC */ 274 c_caddr_t iv; 275 }; 276 277 /* op and flags the same as crypt_op */ 278 struct crypt_aead { 279 u_int32_t ses; 280 u_int16_t op; /* i.e. COP_ENCRYPT */ 281 u_int16_t flags; 282 u_int len; 283 u_int aadlen; 284 u_int ivlen; 285 c_caddr_t src; /* become iov[] inside kernel */ 286 caddr_t dst; 287 c_caddr_t aad; /* additional authenticated data */ 288 caddr_t tag; /* must fit for chosen TAG length */ 289 c_caddr_t iv; 290 }; 291 292 /* 293 * Parameters for looking up a crypto driver/device by 294 * device name or by id. The latter are returned for 295 * created sessions (crid) and completed key operations. 296 */ 297 struct crypt_find_op { 298 int crid; /* driver id + flags */ 299 char name[32]; /* device/driver name */ 300 }; 301 302 /* bignum parameter, in packed bytes, ... */ 303 struct crparam { 304 caddr_t crp_p; 305 u_int crp_nbits; 306 }; 307 308 #define CRK_MAXPARAM 8 309 310 struct crypt_kop { 311 u_int crk_op; /* ie. CRK_MOD_EXP or other */ 312 u_int crk_status; /* return status */ 313 u_short crk_iparams; /* # of input parameters */ 314 u_short crk_oparams; /* # of output parameters */ 315 u_int crk_crid; /* NB: only used by CIOCKEY2 (rw) */ 316 struct crparam crk_param[CRK_MAXPARAM]; 317 }; 318 #define CRK_ALGORITM_MIN 0 319 #define CRK_MOD_EXP 0 320 #define CRK_MOD_EXP_CRT 1 321 #define CRK_DSA_SIGN 2 322 #define CRK_DSA_VERIFY 3 323 #define CRK_DH_COMPUTE_KEY 4 324 #define CRK_ALGORITHM_MAX 4 /* Keep updated - see below */ 325 326 #define CRF_MOD_EXP (1 << CRK_MOD_EXP) 327 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT) 328 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN) 329 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY) 330 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY) 331 332 /* 333 * done against open of /dev/crypto, to get a cloned descriptor. 334 * Please use F_SETFD against the cloned descriptor. 335 */ 336 #define CRIOGET _IOWR('c', 100, u_int32_t) 337 #define CRIOASYMFEAT CIOCASYMFEAT 338 #define CRIOFINDDEV CIOCFINDDEV 339 340 /* the following are done against the cloned descriptor */ 341 #define CIOCGSESSION _IOWR('c', 101, struct session_op) 342 #define CIOCFSESSION _IOW('c', 102, u_int32_t) 343 #define CIOCCRYPT _IOWR('c', 103, struct crypt_op) 344 #define CIOCKEY _IOWR('c', 104, struct crypt_kop) 345 #define CIOCASYMFEAT _IOR('c', 105, u_int32_t) 346 #define CIOCGSESSION2 _IOWR('c', 106, struct session2_op) 347 #define CIOCKEY2 _IOWR('c', 107, struct crypt_kop) 348 #define CIOCFINDDEV _IOWR('c', 108, struct crypt_find_op) 349 #define CIOCCRYPTAEAD _IOWR('c', 109, struct crypt_aead) 350 351 struct cryptostats { 352 uint64_t cs_ops; /* symmetric crypto ops submitted */ 353 uint64_t cs_errs; /* symmetric crypto ops that failed */ 354 uint64_t cs_kops; /* asymetric/key ops submitted */ 355 uint64_t cs_kerrs; /* asymetric/key ops that failed */ 356 uint64_t cs_intrs; /* crypto swi thread activations */ 357 uint64_t cs_rets; /* crypto return thread activations */ 358 uint64_t cs_blocks; /* symmetric op driver block */ 359 uint64_t cs_kblocks; /* symmetric op driver block */ 360 }; 361 362 #ifdef _KERNEL 363 364 #if 0 365 #define CRYPTDEB(s, ...) do { \ 366 printf("%s:%d: " s "\n", __FILE__, __LINE__, ## __VA_ARGS__); \ 367 } while (0) 368 #else 369 #define CRYPTDEB(...) do { } while (0) 370 #endif 371 372 /* Standard initialization structure beginning */ 373 struct cryptoini { 374 int cri_alg; /* Algorithm to use */ 375 int cri_klen; /* Key length, in bits */ 376 int cri_mlen; /* Number of bytes we want from the 377 entire hash. 0 means all. */ 378 caddr_t cri_key; /* key to use */ 379 u_int8_t cri_iv[EALG_MAX_BLOCK_LEN]; /* IV to use */ 380 struct cryptoini *cri_next; 381 }; 382 383 /* Describe boundaries of a single crypto operation */ 384 struct cryptodesc { 385 int crd_skip; /* How many bytes to ignore from start */ 386 int crd_len; /* How many bytes to process */ 387 int crd_inject; /* Where to inject results, if applicable */ 388 int crd_flags; 389 390 #define CRD_F_ENCRYPT 0x01 /* Set when doing encryption */ 391 #define CRD_F_IV_PRESENT 0x02 /* When encrypting, IV is already in 392 place, so don't copy. */ 393 #define CRD_F_IV_EXPLICIT 0x04 /* IV explicitly provided */ 394 #define CRD_F_DSA_SHA_NEEDED 0x08 /* Compute SHA-1 of buffer for DSA */ 395 #define CRD_F_COMP 0x0f /* Set when doing compression */ 396 #define CRD_F_KEY_EXPLICIT 0x10 /* Key explicitly provided */ 397 398 struct cryptoini CRD_INI; /* Initialization/context data */ 399 #define crd_esn CRD_INI.cri_esn 400 #define crd_iv CRD_INI.cri_iv 401 #define crd_key CRD_INI.cri_key 402 #define crd_alg CRD_INI.cri_alg 403 #define crd_klen CRD_INI.cri_klen 404 405 struct cryptodesc *crd_next; 406 }; 407 408 /* Structure describing complete operation */ 409 struct cryptop { 410 TAILQ_ENTRY(cryptop) crp_next; 411 412 struct task crp_task; 413 414 crypto_session_t crp_session; /* Session */ 415 int crp_ilen; /* Input data total length */ 416 int crp_olen; /* Result total length */ 417 418 int crp_etype; /* 419 * Error type (zero means no error). 420 * All error codes except EAGAIN 421 * indicate possible data corruption (as in, 422 * the data have been touched). On all 423 * errors, the crp_session may have changed 424 * (reset to a new one), so the caller 425 * should always check and use the new 426 * value on future requests. 427 */ 428 int crp_flags; 429 430 #define CRYPTO_F_IMBUF 0x0001 /* Input/output are mbuf chains */ 431 #define CRYPTO_F_IOV 0x0002 /* Input/output are uio */ 432 #define CRYPTO_F_BATCH 0x0008 /* Batch op if possible */ 433 #define CRYPTO_F_CBIMM 0x0010 /* Do callback immediately */ 434 #define CRYPTO_F_DONE 0x0020 /* Operation completed */ 435 #define CRYPTO_F_CBIFSYNC 0x0040 /* Do CBIMM if op is synchronous */ 436 #define CRYPTO_F_ASYNC 0x0080 /* Dispatch crypto jobs on several threads 437 * if op is synchronous 438 */ 439 #define CRYPTO_F_ASYNC_KEEPORDER 0x0100 /* 440 * Dispatch the crypto jobs in the same 441 * order there are submitted. Applied only 442 * if CRYPTO_F_ASYNC flags is set 443 */ 444 445 union { 446 caddr_t crp_buf; /* Data to be processed */ 447 struct mbuf *crp_mbuf; 448 struct uio *crp_uio; 449 }; 450 void * crp_opaque; /* Opaque pointer, passed along */ 451 struct cryptodesc *crp_desc; /* Linked list of processing descriptors */ 452 453 int (*crp_callback)(struct cryptop *); /* Callback function */ 454 455 struct bintime crp_tstamp; /* performance time stamp */ 456 uint32_t crp_seq; /* used for ordered dispatch */ 457 uint32_t crp_retw_id; /* 458 * the return worker to be used, 459 * used for ordered dispatch 460 */ 461 }; 462 463 #define CRYPTOP_ASYNC(crp) \ 464 (((crp)->crp_flags & CRYPTO_F_ASYNC) && \ 465 crypto_ses2caps((crp)->crp_session) & CRYPTOCAP_F_SYNC) 466 #define CRYPTOP_ASYNC_KEEPORDER(crp) \ 467 (CRYPTOP_ASYNC(crp) && \ 468 (crp)->crp_flags & CRYPTO_F_ASYNC_KEEPORDER) 469 470 #define CRYPTO_BUF_CONTIG 0x0 471 #define CRYPTO_BUF_IOV 0x1 472 #define CRYPTO_BUF_MBUF 0x2 473 474 #define CRYPTO_OP_DECRYPT 0x0 475 #define CRYPTO_OP_ENCRYPT 0x1 476 477 /* 478 * Hints passed to process methods. 479 */ 480 #define CRYPTO_HINT_MORE 0x1 /* more ops coming shortly */ 481 482 struct cryptkop { 483 TAILQ_ENTRY(cryptkop) krp_next; 484 485 u_int krp_op; /* ie. CRK_MOD_EXP or other */ 486 u_int krp_status; /* return status */ 487 u_short krp_iparams; /* # of input parameters */ 488 u_short krp_oparams; /* # of output parameters */ 489 u_int krp_crid; /* desired device, etc. */ 490 u_int32_t krp_hid; 491 struct crparam krp_param[CRK_MAXPARAM]; /* kvm */ 492 int (*krp_callback)(struct cryptkop *); 493 }; 494 495 uint32_t crypto_ses2hid(crypto_session_t crypto_session); 496 uint32_t crypto_ses2caps(crypto_session_t crypto_session); 497 void *crypto_get_driver_session(crypto_session_t crypto_session); 498 499 MALLOC_DECLARE(M_CRYPTO_DATA); 500 501 extern int crypto_newsession(crypto_session_t *cses, struct cryptoini *cri, int hard); 502 extern void crypto_freesession(crypto_session_t cses); 503 #define CRYPTOCAP_F_HARDWARE CRYPTO_FLAG_HARDWARE 504 #define CRYPTOCAP_F_SOFTWARE CRYPTO_FLAG_SOFTWARE 505 #define CRYPTOCAP_F_SYNC 0x04000000 /* operates synchronously */ 506 extern int32_t crypto_get_driverid(device_t dev, size_t session_size, 507 int flags); 508 extern int crypto_find_driver(const char *); 509 extern device_t crypto_find_device_byhid(int hid); 510 extern int crypto_getcaps(int hid); 511 extern int crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen, 512 u_int32_t flags); 513 extern int crypto_kregister(u_int32_t, int, u_int32_t); 514 extern int crypto_unregister(u_int32_t driverid, int alg); 515 extern int crypto_unregister_all(u_int32_t driverid); 516 extern int crypto_dispatch(struct cryptop *crp); 517 extern int crypto_kdispatch(struct cryptkop *); 518 #define CRYPTO_SYMQ 0x1 519 #define CRYPTO_ASYMQ 0x2 520 extern int crypto_unblock(u_int32_t, int); 521 extern void crypto_done(struct cryptop *crp); 522 extern void crypto_kdone(struct cryptkop *); 523 extern int crypto_getfeat(int *); 524 525 extern void crypto_freereq(struct cryptop *crp); 526 extern struct cryptop *crypto_getreq(int num); 527 528 extern int crypto_usercrypto; /* userland may do crypto requests */ 529 extern int crypto_userasymcrypto; /* userland may do asym crypto reqs */ 530 extern int crypto_devallowsoft; /* only use hardware crypto */ 531 532 /* Helper routines for drivers to initialize auth contexts for HMAC. */ 533 struct auth_hash; 534 535 void hmac_init_ipad(const struct auth_hash *axf, const char *key, int klen, 536 void *auth_ctx); 537 void hmac_init_opad(const struct auth_hash *axf, const char *key, int klen, 538 void *auth_ctx); 539 540 /* 541 * Crypto-related utility routines used mainly by drivers. 542 * 543 * XXX these don't really belong here; but for now they're 544 * kept apart from the rest of the system. 545 */ 546 struct uio; 547 extern void cuio_copydata(struct uio* uio, int off, int len, caddr_t cp); 548 extern void cuio_copyback(struct uio* uio, int off, int len, c_caddr_t cp); 549 extern int cuio_getptr(struct uio *uio, int loc, int *off); 550 extern int cuio_apply(struct uio *uio, int off, int len, 551 int (*f)(void *, void *, u_int), void *arg); 552 553 struct mbuf; 554 struct iovec; 555 extern int crypto_mbuftoiov(struct mbuf *mbuf, struct iovec **iovptr, 556 int *cnt, int *allocated); 557 558 extern void crypto_copyback(int flags, caddr_t buf, int off, int size, 559 c_caddr_t in); 560 extern void crypto_copydata(int flags, caddr_t buf, int off, int size, 561 caddr_t out); 562 extern int crypto_apply(int flags, caddr_t buf, int off, int len, 563 int (*f)(void *, void *, u_int), void *arg); 564 565 extern void *crypto_contiguous_subsegment(int, void *, size_t, size_t); 566 567 #endif /* _KERNEL */ 568 #endif /* _CRYPTO_CRYPTO_H_ */ 569