1 /* $FreeBSD$ */ 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 #include <sys/_task.h> 67 68 #ifdef _KERNEL 69 #include <opencrypto/_cryptodev.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 /* Maximum hash algorithm result length */ 90 #define HASH_MAX_LEN SHA2_512_HASH_LEN /* Keep this updated */ 91 92 #define MD5_BLOCK_LEN 64 93 #define SHA1_BLOCK_LEN 64 94 #define RIPEMD160_BLOCK_LEN 64 95 #define SHA2_224_BLOCK_LEN 64 96 #define SHA2_256_BLOCK_LEN 64 97 #define SHA2_384_BLOCK_LEN 128 98 #define SHA2_512_BLOCK_LEN 128 99 100 /* HMAC values */ 101 #define NULL_HMAC_BLOCK_LEN 64 102 /* Maximum HMAC block length */ 103 #define HMAC_MAX_BLOCK_LEN SHA2_512_BLOCK_LEN /* Keep this updated */ 104 #define HMAC_IPAD_VAL 0x36 105 #define HMAC_OPAD_VAL 0x5C 106 /* HMAC Key Length */ 107 #define AES_128_GMAC_KEY_LEN 16 108 #define AES_192_GMAC_KEY_LEN 24 109 #define AES_256_GMAC_KEY_LEN 32 110 111 #define POLY1305_KEY_LEN 32 112 113 /* Encryption algorithm block sizes */ 114 #define NULL_BLOCK_LEN 4 /* IPsec to maintain alignment */ 115 #define DES_BLOCK_LEN 8 116 #define DES3_BLOCK_LEN 8 117 #define BLOWFISH_BLOCK_LEN 8 118 #define SKIPJACK_BLOCK_LEN 8 119 #define CAST128_BLOCK_LEN 8 120 #define RIJNDAEL128_BLOCK_LEN 16 121 #define AES_BLOCK_LEN 16 122 #define AES_ICM_BLOCK_LEN 1 123 #define ARC4_BLOCK_LEN 1 124 #define CAMELLIA_BLOCK_LEN 16 125 #define CHACHA20_NATIVE_BLOCK_LEN 64 126 #define EALG_MAX_BLOCK_LEN CHACHA20_NATIVE_BLOCK_LEN /* Keep this updated */ 127 128 /* IV Lengths */ 129 130 #define ARC4_IV_LEN 1 131 #define AES_GCM_IV_LEN 12 132 #define AES_XTS_IV_LEN 8 133 #define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */ 134 135 /* Min and Max Encryption Key Sizes */ 136 #define NULL_MIN_KEY 0 137 #define NULL_MAX_KEY 256 /* 2048 bits, max key */ 138 #define DES_MIN_KEY 8 139 #define DES_MAX_KEY DES_MIN_KEY 140 #define TRIPLE_DES_MIN_KEY 24 141 #define TRIPLE_DES_MAX_KEY TRIPLE_DES_MIN_KEY 142 #define BLOWFISH_MIN_KEY 5 143 #define BLOWFISH_MAX_KEY 56 /* 448 bits, max key */ 144 #define CAST_MIN_KEY 5 145 #define CAST_MAX_KEY 16 146 #define SKIPJACK_MIN_KEY 10 147 #define SKIPJACK_MAX_KEY SKIPJACK_MIN_KEY 148 #define RIJNDAEL_MIN_KEY 16 149 #define RIJNDAEL_MAX_KEY 32 150 #define AES_MIN_KEY RIJNDAEL_MIN_KEY 151 #define AES_MAX_KEY RIJNDAEL_MAX_KEY 152 #define AES_XTS_MIN_KEY (2 * AES_MIN_KEY) 153 #define AES_XTS_MAX_KEY (2 * AES_MAX_KEY) 154 #define ARC4_MIN_KEY 1 155 #define ARC4_MAX_KEY 32 156 #define CAMELLIA_MIN_KEY 8 157 #define CAMELLIA_MAX_KEY 32 158 159 /* Maximum hash algorithm result length */ 160 #define AALG_MAX_RESULT_LEN 64 /* Keep this updated */ 161 162 #define CRYPTO_ALGORITHM_MIN 1 163 #define CRYPTO_DES_CBC 1 164 #define CRYPTO_3DES_CBC 2 165 #define CRYPTO_BLF_CBC 3 166 #define CRYPTO_CAST_CBC 4 167 #define CRYPTO_SKIPJACK_CBC 5 168 #define CRYPTO_MD5_HMAC 6 169 #define CRYPTO_SHA1_HMAC 7 170 #define CRYPTO_RIPEMD160_HMAC 8 171 #define CRYPTO_MD5_KPDK 9 172 #define CRYPTO_SHA1_KPDK 10 173 #define CRYPTO_RIJNDAEL128_CBC 11 /* 128 bit blocksize */ 174 #define CRYPTO_AES_CBC 11 /* 128 bit blocksize -- the same as above */ 175 #define CRYPTO_ARC4 12 176 #define CRYPTO_MD5 13 177 #define CRYPTO_SHA1 14 178 #define CRYPTO_NULL_HMAC 15 179 #define CRYPTO_NULL_CBC 16 180 #define CRYPTO_DEFLATE_COMP 17 /* Deflate compression algorithm */ 181 #define CRYPTO_SHA2_256_HMAC 18 182 #define CRYPTO_SHA2_384_HMAC 19 183 #define CRYPTO_SHA2_512_HMAC 20 184 #define CRYPTO_CAMELLIA_CBC 21 185 #define CRYPTO_AES_XTS 22 186 #define CRYPTO_AES_ICM 23 /* commonly known as CTR mode */ 187 #define CRYPTO_AES_NIST_GMAC 24 /* cipher side */ 188 #define CRYPTO_AES_NIST_GCM_16 25 /* 16 byte ICV */ 189 #define CRYPTO_AES_128_NIST_GMAC 26 /* auth side */ 190 #define CRYPTO_AES_192_NIST_GMAC 27 /* auth side */ 191 #define CRYPTO_AES_256_NIST_GMAC 28 /* auth side */ 192 #define CRYPTO_BLAKE2B 29 /* Blake2b hash */ 193 #define CRYPTO_BLAKE2S 30 /* Blake2s hash */ 194 #define CRYPTO_CHACHA20 31 /* Chacha20 stream cipher */ 195 #define CRYPTO_SHA2_224_HMAC 32 196 #define CRYPTO_RIPEMD160 33 197 #define CRYPTO_SHA2_224 34 198 #define CRYPTO_SHA2_256 35 199 #define CRYPTO_SHA2_384 36 200 #define CRYPTO_SHA2_512 37 201 #define CRYPTO_POLY1305 38 202 #define CRYPTO_ALGORITHM_MAX 38 /* Keep updated - see below */ 203 204 #define CRYPTO_ALGO_VALID(x) ((x) >= CRYPTO_ALGORITHM_MIN && \ 205 (x) <= CRYPTO_ALGORITHM_MAX) 206 207 /* Algorithm flags */ 208 #define CRYPTO_ALG_FLAG_SUPPORTED 0x01 /* Algorithm is supported */ 209 #define CRYPTO_ALG_FLAG_RNG_ENABLE 0x02 /* Has HW RNG for DH/DSA */ 210 #define CRYPTO_ALG_FLAG_DSA_SHA 0x04 /* Can do SHA on msg */ 211 212 /* 213 * Crypto driver/device flags. They can set in the crid 214 * parameter when creating a session or submitting a key 215 * op to affect the device/driver assigned. If neither 216 * of these are specified then the crid is assumed to hold 217 * the driver id of an existing (and suitable) device that 218 * must be used to satisfy the request. 219 */ 220 #define CRYPTO_FLAG_HARDWARE 0x01000000 /* hardware accelerated */ 221 #define CRYPTO_FLAG_SOFTWARE 0x02000000 /* software implementation */ 222 223 /* NB: deprecated */ 224 struct session_op { 225 u_int32_t cipher; /* ie. CRYPTO_DES_CBC */ 226 u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */ 227 228 u_int32_t keylen; /* cipher key */ 229 c_caddr_t key; 230 int mackeylen; /* mac key */ 231 c_caddr_t mackey; 232 233 u_int32_t ses; /* returns: session # */ 234 }; 235 236 /* 237 * session and crypt _op structs are used by userspace programs to interact 238 * with /dev/crypto. Confusingly, the internal kernel interface is named 239 * "cryptop" (no underscore). 240 */ 241 struct session2_op { 242 u_int32_t cipher; /* ie. CRYPTO_DES_CBC */ 243 u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */ 244 245 u_int32_t keylen; /* cipher key */ 246 c_caddr_t key; 247 int mackeylen; /* mac key */ 248 c_caddr_t mackey; 249 250 u_int32_t ses; /* returns: session # */ 251 int crid; /* driver id + flags (rw) */ 252 int pad[4]; /* for future expansion */ 253 }; 254 255 struct crypt_op { 256 u_int32_t ses; 257 u_int16_t op; /* i.e. COP_ENCRYPT */ 258 #define COP_ENCRYPT 1 259 #define COP_DECRYPT 2 260 u_int16_t flags; 261 #define COP_F_CIPHER_FIRST 0x0001 /* Cipher before MAC. */ 262 #define COP_F_BATCH 0x0008 /* Batch op if possible */ 263 u_int len; 264 c_caddr_t src; /* become iov[] inside kernel */ 265 caddr_t dst; 266 caddr_t mac; /* must be big enough for chosen MAC */ 267 c_caddr_t iv; 268 }; 269 270 /* op and flags the same as crypt_op */ 271 struct crypt_aead { 272 u_int32_t ses; 273 u_int16_t op; /* i.e. COP_ENCRYPT */ 274 u_int16_t flags; 275 u_int len; 276 u_int aadlen; 277 u_int ivlen; 278 c_caddr_t src; /* become iov[] inside kernel */ 279 caddr_t dst; 280 c_caddr_t aad; /* additional authenticated data */ 281 caddr_t tag; /* must fit for chosen TAG length */ 282 c_caddr_t iv; 283 }; 284 285 /* 286 * Parameters for looking up a crypto driver/device by 287 * device name or by id. The latter are returned for 288 * created sessions (crid) and completed key operations. 289 */ 290 struct crypt_find_op { 291 int crid; /* driver id + flags */ 292 char name[32]; /* device/driver name */ 293 }; 294 295 /* bignum parameter, in packed bytes, ... */ 296 struct crparam { 297 caddr_t crp_p; 298 u_int crp_nbits; 299 }; 300 301 #define CRK_MAXPARAM 8 302 303 struct crypt_kop { 304 u_int crk_op; /* ie. CRK_MOD_EXP or other */ 305 u_int crk_status; /* return status */ 306 u_short crk_iparams; /* # of input parameters */ 307 u_short crk_oparams; /* # of output parameters */ 308 u_int crk_crid; /* NB: only used by CIOCKEY2 (rw) */ 309 struct crparam crk_param[CRK_MAXPARAM]; 310 }; 311 #define CRK_ALGORITM_MIN 0 312 #define CRK_MOD_EXP 0 313 #define CRK_MOD_EXP_CRT 1 314 #define CRK_DSA_SIGN 2 315 #define CRK_DSA_VERIFY 3 316 #define CRK_DH_COMPUTE_KEY 4 317 #define CRK_ALGORITHM_MAX 4 /* Keep updated - see below */ 318 319 #define CRF_MOD_EXP (1 << CRK_MOD_EXP) 320 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT) 321 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN) 322 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY) 323 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY) 324 325 /* 326 * done against open of /dev/crypto, to get a cloned descriptor. 327 * Please use F_SETFD against the cloned descriptor. 328 */ 329 #define CRIOGET _IOWR('c', 100, u_int32_t) 330 #define CRIOASYMFEAT CIOCASYMFEAT 331 #define CRIOFINDDEV CIOCFINDDEV 332 333 /* the following are done against the cloned descriptor */ 334 #define CIOCGSESSION _IOWR('c', 101, struct session_op) 335 #define CIOCFSESSION _IOW('c', 102, u_int32_t) 336 #define CIOCCRYPT _IOWR('c', 103, struct crypt_op) 337 #define CIOCKEY _IOWR('c', 104, struct crypt_kop) 338 #define CIOCASYMFEAT _IOR('c', 105, u_int32_t) 339 #define CIOCGSESSION2 _IOWR('c', 106, struct session2_op) 340 #define CIOCKEY2 _IOWR('c', 107, struct crypt_kop) 341 #define CIOCFINDDEV _IOWR('c', 108, struct crypt_find_op) 342 #define CIOCCRYPTAEAD _IOWR('c', 109, struct crypt_aead) 343 344 struct cryptotstat { 345 struct timespec acc; /* total accumulated time */ 346 struct timespec min; /* min time */ 347 struct timespec max; /* max time */ 348 u_int32_t count; /* number of observations */ 349 }; 350 351 struct cryptostats { 352 u_int32_t cs_ops; /* symmetric crypto ops submitted */ 353 u_int32_t cs_errs; /* symmetric crypto ops that failed */ 354 u_int32_t cs_kops; /* asymetric/key ops submitted */ 355 u_int32_t cs_kerrs; /* asymetric/key ops that failed */ 356 u_int32_t cs_intrs; /* crypto swi thread activations */ 357 u_int32_t cs_rets; /* crypto return thread activations */ 358 u_int32_t cs_blocks; /* symmetric op driver block */ 359 u_int32_t cs_kblocks; /* symmetric op driver block */ 360 /* 361 * When CRYPTO_TIMING is defined at compile time and the 362 * sysctl debug.crypto is set to 1, the crypto system will 363 * accumulate statistics about how long it takes to process 364 * crypto requests at various points during processing. 365 */ 366 struct cryptotstat cs_invoke; /* crypto_dipsatch -> crypto_invoke */ 367 struct cryptotstat cs_done; /* crypto_invoke -> crypto_done */ 368 struct cryptotstat cs_cb; /* crypto_done -> callback */ 369 struct cryptotstat cs_finis; /* callback -> callback return */ 370 }; 371 372 #ifdef _KERNEL 373 374 #if 0 375 #define CRYPTDEB(s, ...) do { \ 376 printf("%s:%d: " s "\n", __FILE__, __LINE__, ## __VA_ARGS__); \ 377 } while (0) 378 #else 379 #define CRYPTDEB(...) do { } while (0) 380 #endif 381 382 /* Standard initialization structure beginning */ 383 struct cryptoini { 384 int cri_alg; /* Algorithm to use */ 385 int cri_klen; /* Key length, in bits */ 386 int cri_mlen; /* Number of bytes we want from the 387 entire hash. 0 means all. */ 388 caddr_t cri_key; /* key to use */ 389 u_int8_t cri_iv[EALG_MAX_BLOCK_LEN]; /* IV to use */ 390 struct cryptoini *cri_next; 391 }; 392 393 /* Describe boundaries of a single crypto operation */ 394 struct cryptodesc { 395 int crd_skip; /* How many bytes to ignore from start */ 396 int crd_len; /* How many bytes to process */ 397 int crd_inject; /* Where to inject results, if applicable */ 398 int crd_flags; 399 400 #define CRD_F_ENCRYPT 0x01 /* Set when doing encryption */ 401 #define CRD_F_IV_PRESENT 0x02 /* When encrypting, IV is already in 402 place, so don't copy. */ 403 #define CRD_F_IV_EXPLICIT 0x04 /* IV explicitly provided */ 404 #define CRD_F_DSA_SHA_NEEDED 0x08 /* Compute SHA-1 of buffer for DSA */ 405 #define CRD_F_COMP 0x0f /* Set when doing compression */ 406 #define CRD_F_KEY_EXPLICIT 0x10 /* Key explicitly provided */ 407 408 struct cryptoini CRD_INI; /* Initialization/context data */ 409 #define crd_esn CRD_INI.cri_esn 410 #define crd_iv CRD_INI.cri_iv 411 #define crd_key CRD_INI.cri_key 412 #define crd_alg CRD_INI.cri_alg 413 #define crd_klen CRD_INI.cri_klen 414 415 struct cryptodesc *crd_next; 416 }; 417 418 /* Structure describing complete operation */ 419 struct cryptop { 420 TAILQ_ENTRY(cryptop) crp_next; 421 422 struct task crp_task; 423 424 crypto_session_t crp_session; /* Session */ 425 int crp_ilen; /* Input data total length */ 426 int crp_olen; /* Result total length */ 427 428 int crp_etype; /* 429 * Error type (zero means no error). 430 * All error codes except EAGAIN 431 * indicate possible data corruption (as in, 432 * the data have been touched). On all 433 * errors, the crp_session may have changed 434 * (reset to a new one), so the caller 435 * should always check and use the new 436 * value on future requests. 437 */ 438 int crp_flags; 439 440 #define CRYPTO_F_IMBUF 0x0001 /* Input/output are mbuf chains */ 441 #define CRYPTO_F_IOV 0x0002 /* Input/output are uio */ 442 #define CRYPTO_F_BATCH 0x0008 /* Batch op if possible */ 443 #define CRYPTO_F_CBIMM 0x0010 /* Do callback immediately */ 444 #define CRYPTO_F_DONE 0x0020 /* Operation completed */ 445 #define CRYPTO_F_CBIFSYNC 0x0040 /* Do CBIMM if op is synchronous */ 446 #define CRYPTO_F_ASYNC 0x0080 /* Dispatch crypto jobs on several threads 447 * if op is synchronous 448 */ 449 #define CRYPTO_F_ASYNC_KEEPORDER 0x0100 /* 450 * Dispatch the crypto jobs in the same 451 * order there are submitted. Applied only 452 * if CRYPTO_F_ASYNC flags is set 453 */ 454 455 union { 456 caddr_t crp_buf; /* Data to be processed */ 457 struct mbuf *crp_mbuf; 458 struct uio *crp_uio; 459 }; 460 void * crp_opaque; /* Opaque pointer, passed along */ 461 struct cryptodesc *crp_desc; /* Linked list of processing descriptors */ 462 463 int (*crp_callback)(struct cryptop *); /* Callback function */ 464 465 struct bintime crp_tstamp; /* performance time stamp */ 466 uint32_t crp_seq; /* used for ordered dispatch */ 467 uint32_t crp_retw_id; /* 468 * the return worker to be used, 469 * used for ordered dispatch 470 */ 471 }; 472 473 #define CRYPTOP_ASYNC(crp) \ 474 (((crp)->crp_flags & CRYPTO_F_ASYNC) && \ 475 crypto_ses2caps((crp)->crp_session) & CRYPTOCAP_F_SYNC) 476 #define CRYPTOP_ASYNC_KEEPORDER(crp) \ 477 (CRYPTOP_ASYNC(crp) && \ 478 (crp)->crp_flags & CRYPTO_F_ASYNC_KEEPORDER) 479 480 #define CRYPTO_BUF_CONTIG 0x0 481 #define CRYPTO_BUF_IOV 0x1 482 #define CRYPTO_BUF_MBUF 0x2 483 484 #define CRYPTO_OP_DECRYPT 0x0 485 #define CRYPTO_OP_ENCRYPT 0x1 486 487 /* 488 * Hints passed to process methods. 489 */ 490 #define CRYPTO_HINT_MORE 0x1 /* more ops coming shortly */ 491 492 struct cryptkop { 493 TAILQ_ENTRY(cryptkop) krp_next; 494 495 u_int krp_op; /* ie. CRK_MOD_EXP or other */ 496 u_int krp_status; /* return status */ 497 u_short krp_iparams; /* # of input parameters */ 498 u_short krp_oparams; /* # of output parameters */ 499 u_int krp_crid; /* desired device, etc. */ 500 u_int32_t krp_hid; 501 struct crparam krp_param[CRK_MAXPARAM]; /* kvm */ 502 int (*krp_callback)(struct cryptkop *); 503 }; 504 505 uint32_t crypto_ses2hid(crypto_session_t crypto_session); 506 uint32_t crypto_ses2caps(crypto_session_t crypto_session); 507 void *crypto_get_driver_session(crypto_session_t crypto_session); 508 509 MALLOC_DECLARE(M_CRYPTO_DATA); 510 511 extern int crypto_newsession(crypto_session_t *cses, struct cryptoini *cri, int hard); 512 extern void crypto_freesession(crypto_session_t cses); 513 #define CRYPTOCAP_F_HARDWARE CRYPTO_FLAG_HARDWARE 514 #define CRYPTOCAP_F_SOFTWARE CRYPTO_FLAG_SOFTWARE 515 #define CRYPTOCAP_F_SYNC 0x04000000 /* operates synchronously */ 516 extern int32_t crypto_get_driverid(device_t dev, size_t session_size, 517 int flags); 518 extern int crypto_find_driver(const char *); 519 extern device_t crypto_find_device_byhid(int hid); 520 extern int crypto_getcaps(int hid); 521 extern int crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen, 522 u_int32_t flags); 523 extern int crypto_kregister(u_int32_t, int, u_int32_t); 524 extern int crypto_unregister(u_int32_t driverid, int alg); 525 extern int crypto_unregister_all(u_int32_t driverid); 526 extern int crypto_dispatch(struct cryptop *crp); 527 extern int crypto_kdispatch(struct cryptkop *); 528 #define CRYPTO_SYMQ 0x1 529 #define CRYPTO_ASYMQ 0x2 530 extern int crypto_unblock(u_int32_t, int); 531 extern void crypto_done(struct cryptop *crp); 532 extern void crypto_kdone(struct cryptkop *); 533 extern int crypto_getfeat(int *); 534 535 extern void crypto_freereq(struct cryptop *crp); 536 extern struct cryptop *crypto_getreq(int num); 537 538 extern int crypto_usercrypto; /* userland may do crypto requests */ 539 extern int crypto_userasymcrypto; /* userland may do asym crypto reqs */ 540 extern int crypto_devallowsoft; /* only use hardware crypto */ 541 542 /* 543 * Crypto-related utility routines used mainly by drivers. 544 * 545 * XXX these don't really belong here; but for now they're 546 * kept apart from the rest of the system. 547 */ 548 struct uio; 549 extern void cuio_copydata(struct uio* uio, int off, int len, caddr_t cp); 550 extern void cuio_copyback(struct uio* uio, int off, int len, c_caddr_t cp); 551 extern int cuio_getptr(struct uio *uio, int loc, int *off); 552 extern int cuio_apply(struct uio *uio, int off, int len, 553 int (*f)(void *, void *, u_int), void *arg); 554 555 struct mbuf; 556 struct iovec; 557 extern int crypto_mbuftoiov(struct mbuf *mbuf, struct iovec **iovptr, 558 int *cnt, int *allocated); 559 560 extern void crypto_copyback(int flags, caddr_t buf, int off, int size, 561 c_caddr_t in); 562 extern void crypto_copydata(int flags, caddr_t buf, int off, int size, 563 caddr_t out); 564 extern int crypto_apply(int flags, caddr_t buf, int off, int len, 565 int (*f)(void *, void *, u_int), void *arg); 566 567 #endif /* _KERNEL */ 568 #endif /* _CRYPTO_CRYPTO_H_ */ 569