cryptodev.h revision 1.13.2.1 1 /* $NetBSD: cryptodev.h,v 1.13.2.1 2008/05/18 12:35:45 yamt Exp $ */
2 /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */
3 /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */
4
5 /*-
6 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Coyote Point Systems, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * The author of this code is Angelos D. Keromytis (angelos (at) cis.upenn.edu)
36 *
37 * This code was written by Angelos D. Keromytis in Athens, Greece, in
38 * February 2000. Network Security Technologies Inc. (NSTI) kindly
39 * supported the development of this code.
40 *
41 * Copyright (c) 2000 Angelos D. Keromytis
42 *
43 * Permission to use, copy, and modify this software with or without fee
44 * is hereby granted, provided that this entire notice is included in
45 * all source code copies of any software which is or includes a copy or
46 * modification of this software.
47 *
48 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
49 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
50 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
51 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
52 * PURPOSE.
53 *
54 * Copyright (c) 2001 Theo de Raadt
55 *
56 * Redistribution and use in source and binary forms, with or without
57 * modification, are permitted provided that the following conditions
58 * are met:
59 *
60 * 1. Redistributions of source code must retain the above copyright
61 * notice, this list of conditions and the following disclaimer.
62 * 2. Redistributions in binary form must reproduce the above copyright
63 * notice, this list of conditions and the following disclaimer in the
64 * documentation and/or other materials provided with the distribution.
65 * 3. The name of the author may not be used to endorse or promote products
66 * derived from this software without specific prior written permission.
67 *
68 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
69 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
71 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
72 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
73 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
77 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 *
79 * Effort sponsored in part by the Defense Advanced Research Projects
80 * Agency (DARPA) and Air Force Research Laboratory, Air Force
81 * Materiel Command, USAF, under agreement number F30602-01-2-0537.
82 *
83 */
84
85 #ifndef _CRYPTO_CRYPTO_H_
86 #define _CRYPTO_CRYPTO_H_
87
88 #include <sys/ioccom.h>
89
90 /* Some initial values */
91 #define CRYPTO_DRIVERS_INITIAL 4
92 #define CRYPTO_SW_SESSIONS 32
93
94 /* HMAC values */
95 #define HMAC_BLOCK_LEN 64
96 #define HMAC_IPAD_VAL 0x36
97 #define HMAC_OPAD_VAL 0x5C
98
99 /* Encryption algorithm block sizes */
100 #define DES_BLOCK_LEN 8
101 #define DES3_BLOCK_LEN 8
102 #define BLOWFISH_BLOCK_LEN 8
103 #define SKIPJACK_BLOCK_LEN 8
104 #define CAST128_BLOCK_LEN 8
105 #define RIJNDAEL128_BLOCK_LEN 16
106 #define EALG_MAX_BLOCK_LEN 16 /* Keep this updated */
107
108 /* Maximum hash algorithm result length */
109 #define AALG_MAX_RESULT_LEN 64 /* Keep this updated */
110
111 #define CRYPTO_ALGORITHM_MIN 1
112 #define CRYPTO_DES_CBC 1
113 #define CRYPTO_3DES_CBC 2
114 #define CRYPTO_BLF_CBC 3
115 #define CRYPTO_CAST_CBC 4
116 #define CRYPTO_SKIPJACK_CBC 5
117 #define CRYPTO_MD5_HMAC 6
118 #define CRYPTO_SHA1_HMAC 7
119 #define CRYPTO_RIPEMD160_HMAC 8
120 #define CRYPTO_MD5_KPDK 9
121 #define CRYPTO_SHA1_KPDK 10
122 #define CRYPTO_RIJNDAEL128_CBC 11 /* 128 bit blocksize */
123 #define CRYPTO_AES_CBC 11 /* 128 bit blocksize -- the same as above */
124 #define CRYPTO_ARC4 12
125 #define CRYPTO_MD5 13
126 #define CRYPTO_SHA1 14
127 #define CRYPTO_SHA2_HMAC 15
128 #define CRYPTO_NULL_HMAC 16
129 #define CRYPTO_NULL_CBC 17
130 #define CRYPTO_DEFLATE_COMP 18 /* Deflate compression algorithm */
131 #define CRYPTO_MD5_HMAC_96 19
132 #define CRYPTO_SHA1_HMAC_96 20
133 #define CRYPTO_RIPEMD160_HMAC_96 21
134 #define CRYPTO_ALGORITHM_MAX 22 /* Keep updated - see below */
135
136 /* Algorithm flags */
137 #define CRYPTO_ALG_FLAG_SUPPORTED 0x01 /* Algorithm is supported */
138 #define CRYPTO_ALG_FLAG_RNG_ENABLE 0x02 /* Has HW RNG for DH/DSA */
139 #define CRYPTO_ALG_FLAG_DSA_SHA 0x04 /* Can do SHA on msg */
140
141 struct session_op {
142 u_int32_t cipher; /* ie. CRYPTO_DES_CBC */
143 u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */
144
145 u_int32_t keylen; /* cipher key */
146 void * key;
147 int mackeylen; /* mac key */
148 void * mackey;
149
150 u_int32_t ses; /* returns: session # */
151 };
152
153 /* to support multiple session creation */
154
155 struct session_n_op {
156 u_int32_t cipher; /* ie. CRYPTO_DES_CBC */
157 u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */
158
159 u_int32_t keylen; /* cipher key */
160 void * key;
161 int mackeylen; /* mac key */
162 void * mackey;
163
164 u_int32_t ses; /* returns: session # */
165 int status;
166 };
167
168 struct crypt_op {
169 u_int32_t ses;
170 u_int16_t op; /* i.e. COP_ENCRYPT */
171 #define COP_ENCRYPT 1
172 #define COP_DECRYPT 2
173 u_int16_t flags;
174 #define COP_F_BATCH 0x0008 /* Dispatch as quickly as possible */
175 u_int len;
176 void * src, *dst; /* become iov[] inside kernel */
177 void * mac; /* must be big enough for chosen MAC */
178 void * iv;
179 };
180
181 /* to support multiple session creation */
182 /*
183 *
184 * The reqid field is filled when the operation has
185 * been accepted and started, and can be used to later retrieve
186 * the operation results via CIOCNCRYPTRET or identify the
187 * request in the completion list returned by CIOCNCRYPTRETM.
188 *
189 * The opaque pointer can be set arbitrarily by the user
190 * and it is passed back in the crypt_result structure
191 * when the request completes. This field can be used for example
192 * to track context for the request and avoid lookups in the
193 * user application.
194 */
195
196 struct crypt_n_op {
197 u_int32_t ses;
198 u_int16_t op; /* i.e. COP_ENCRYPT */
199 #define COP_ENCRYPT 1
200 #define COP_DECRYPT 2
201 u_int16_t flags;
202 #define COP_F_BATCH 0x0008 /* Dispatch as quickly as possible */
203 u_int len;
204
205 u_int32_t reqid; /* request id */
206 int status; /* status of request -accepted or not */
207 void *opaque; /* opaque pointer returned to user */
208 u_int32_t keylen; /* cipher key - optional */
209 void * key;
210 u_int32_t mackeylen; /* also optional */
211 void * mackey;
212
213 void * src, *dst; /* become iov[] inside kernel */
214 void * mac; /* must be big enough for chosen MAC */
215 void * iv;
216 };
217
218 /* CIOCNCRYPTM ioctl argument, supporting one or more asynchronous
219 * crypt_n_op operations.
220 * Each crypt_n_op will receive a request id which can be used to check its
221 * status via CIOCNCRYPTRET, or to watch for its completion in the list
222 * obtained via CIOCNCRYPTRETM.
223 */
224 struct crypt_mop {
225 size_t count; /* how many */
226 struct crypt_n_op * reqs; /* where to get them */
227 };
228
229 struct crypt_sfop {
230 size_t count;
231 u_int32_t *sesid;
232 };
233
234 struct crypt_sgop {
235 size_t count;
236 struct session_n_op * sessions;
237 };
238
239 #define CRYPTO_MAX_MAC_LEN 20
240
241 /* bignum parameter, in packed bytes, ... */
242 struct crparam {
243 void * crp_p;
244 u_int crp_nbits;
245 };
246
247 #define CRK_MAXPARAM 8
248
249 struct crypt_kop {
250 u_int crk_op; /* ie. CRK_MOD_EXP or other */
251 u_int crk_status; /* return status */
252 u_short crk_iparams; /* # of input parameters */
253 u_short crk_oparams; /* # of output parameters */
254 u_int crk_pad1;
255 struct crparam crk_param[CRK_MAXPARAM];
256 };
257
258 /*
259 * Used with the CIOCNFKEYM ioctl.
260 *
261 * This structure allows the OCF to return a request id
262 * for each of the kop operations specified in the CIOCNFKEYM call.
263 *
264 * The crk_opaque pointer can be arbitrarily set by the user
265 * and it is passed back in the crypt_result structure
266 * when the request completes. This field can be used for example
267 * to track context for the request and avoid lookups in the
268 * user application.
269 */
270 struct crypt_n_kop {
271 u_int crk_op; /* ie. CRK_MOD_EXP or other */
272 u_int crk_status; /* return status */
273 u_short crk_iparams; /* # of input parameters */
274 u_short crk_oparams; /* # of output parameters */
275 u_int32_t crk_reqid; /* request id */
276 struct crparam crk_param[CRK_MAXPARAM];
277 void *crk_opaque; /* opaque pointer returned to user */
278 };
279
280 struct crypt_mkop {
281 size_t count; /* how many */
282 struct crypt_n_kop * reqs; /* where to get them */
283 };
284
285 /* Asynchronous key or crypto result.
286 * Note that the status will be set in the crypt_result structure,
287 * not in the original crypt_kop structure (crk_status).
288 */
289 struct crypt_result {
290 u_int32_t reqid; /* request id */
291 u_int32_t status; /* status of request: 0 if successful */
292 void * opaque; /* Opaque pointer from the user, passed along */
293 };
294
295 struct cryptret {
296 size_t count; /* space for how many */
297 struct crypt_result * results; /* where to put them */
298 };
299
300
301 /* Assymetric key operations */
302 #define CRK_ALGORITM_MIN 0
303 #define CRK_MOD_EXP 0
304 #define CRK_MOD_EXP_CRT 1
305 #define CRK_DSA_SIGN 2
306 #define CRK_DSA_VERIFY 3
307 #define CRK_DH_COMPUTE_KEY 4
308 #define CRK_MOD_ADD 5
309 #define CRK_MOD_ADDINV 6
310 #define CRK_MOD_SUB 7
311 #define CRK_MOD_MULT 8
312 #define CRK_MOD_MULTINV 9
313 #define CRK_MOD 10
314 #define CRK_ALGORITHM_MAX 10 /* Keep updated - see below */
315
316 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
317 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
318 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
319 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
320 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
321 #define CRF_MOD_ADD (1 << CRK_MOD_ADD)
322 #define CRF_MOD_ADDINV (1 << CRK_MOD_ADDINV)
323 #define CRF_MOD_SUB (1 << CRK_MOD_SUB)
324 #define CRF_MOD_MULT (1 << CRK_MOD_MULT)
325 #define CRF_MOD_MULTINV (1 << CRK_MOD_MULTINV)
326 #define CRF_MOD (1 << CRK_MOD)
327
328 /*
329 * A large comment here once held descriptions of the ioctl
330 * requests implemented by the device. This text has been moved
331 * to the crypto(4) manual page and, later, removed from this file
332 * as it was always a step behind the times.
333 */
334
335 /*
336 * done against open of /dev/crypto, to get a cloned descriptor.
337 * Please use F_SETFD against the cloned descriptor. But this ioctl
338 * is obsolete (the device now clones): please, just don't use it.
339 */
340 #define CRIOGET _IOWR('c', 100, u_int32_t)
341
342 /* the following are done against the cloned descriptor */
343 #define CIOCGSESSION _IOWR('c', 101, struct session_op)
344 #define CIOCFSESSION _IOW('c', 102, u_int32_t)
345 #define CIOCCRYPT _IOWR('c', 103, struct crypt_op)
346 #define CIOCKEY _IOWR('c', 104, struct crypt_kop)
347 #define CIOCNGSESSION _IOWR('c', 106, struct crypt_sgop)
348 #define CIOCNCRYPTM _IOWR('c', 107, struct crypt_mop)
349 #define CIOCNFKEYM _IOWR('c', 108, struct crypt_mkop)
350 #define CIOCNFSESSION _IOW('c', 109, struct crypt_sfop)
351 #define CIOCNCRYPTRETM _IOWR('c', 110, struct cryptret)
352 #define CIOCNCRYPTRET _IOWR('c', 111, struct crypt_result)
353
354 #define CIOCASYMFEAT _IOR('c', 105, u_int32_t)
355
356 struct cryptotstat {
357 struct timespec acc; /* total accumulated time */
358 struct timespec min; /* max time */
359 struct timespec max; /* max time */
360 u_int32_t count; /* number of observations */
361 };
362
363 struct cryptostats {
364 u_int32_t cs_ops; /* symmetric crypto ops submitted */
365 u_int32_t cs_errs; /* symmetric crypto ops that failed */
366 u_int32_t cs_kops; /* asymetric/key ops submitted */
367 u_int32_t cs_kerrs; /* asymetric/key ops that failed */
368 u_int32_t cs_intrs; /* crypto swi thread activations */
369 u_int32_t cs_rets; /* crypto return thread activations */
370 u_int32_t cs_blocks; /* symmetric op driver block */
371 u_int32_t cs_kblocks; /* symmetric op driver block */
372 /*
373 * When CRYPTO_TIMING is defined at compile time and the
374 * sysctl debug.crypto is set to 1, the crypto system will
375 * accumulate statistics about how long it takes to process
376 * crypto requests at various points during processing.
377 */
378 struct cryptotstat cs_invoke; /* crypto_dipsatch -> crypto_invoke */
379 struct cryptotstat cs_done; /* crypto_invoke -> crypto_done */
380 struct cryptotstat cs_cb; /* crypto_done -> callback */
381 struct cryptotstat cs_finis; /* callback -> callback return */
382 };
383
384 #ifdef _KERNEL
385 /* Standard initialization structure beginning */
386 struct cryptoini {
387 int cri_alg; /* Algorithm to use */
388 int cri_klen; /* Key length, in bits */
389 int cri_rnd; /* Algorithm rounds, where relevant */
390 char *cri_key; /* key to use */
391 u_int8_t cri_iv[EALG_MAX_BLOCK_LEN]; /* IV to use */
392 struct cryptoini *cri_next;
393 };
394
395 /* Describe boundaries of a single crypto operation */
396 struct cryptodesc {
397 int crd_skip; /* How many bytes to ignore from start */
398 int crd_len; /* How many bytes to process */
399 int crd_inject; /* Where to inject results, if applicable */
400 int crd_flags;
401
402 #define CRD_F_ENCRYPT 0x01 /* Set when doing encryption */
403 #define CRD_F_IV_PRESENT 0x02 /* When encrypting, IV is already in
404 place, so don't copy. */
405 #define CRD_F_IV_EXPLICIT 0x04 /* IV explicitly provided */
406 #define CRD_F_DSA_SHA_NEEDED 0x08 /* Compute SHA-1 of buffer for DSA */
407 #define CRD_F_COMP 0x0f /* Set when doing compression */
408
409 struct cryptoini CRD_INI; /* Initialization/context data */
410 #define crd_iv CRD_INI.cri_iv
411 #define crd_key CRD_INI.cri_key
412 #define crd_rnd CRD_INI.cri_rnd
413 #define crd_alg CRD_INI.cri_alg
414 #define crd_klen CRD_INI.cri_klen
415
416 struct cryptodesc *crd_next;
417 };
418
419 /* Structure describing complete operation */
420 struct cryptop {
421 union {
422 TAILQ_ENTRY(cryptop) crp_tnext;
423 SLIST_ENTRY(cryptop) crp_lnext;
424 } crp_qun;
425 #define crp_next crp_qun.crp_tnext /* XXX compat */
426 u_int64_t crp_sid; /* Session ID */
427
428 u_int32_t crp_reqid; /* request id */
429 void * crp_usropaque; /* Opaque pointer from user, passed along */
430
431 int crp_ilen; /* Input data total length */
432 int crp_olen; /* Result total length */
433
434 int crp_etype; /*
435 * Error type (zero means no error).
436 * All error codes except EAGAIN
437 * indicate possible data corruption (as in,
438 * the data have been touched). On all
439 * errors, the crp_sid may have changed
440 * (reset to a new one), so the caller
441 * should always check and use the new
442 * value on future requests.
443 */
444 int crp_flags;
445
446 #define CRYPTO_F_IMBUF 0x0001 /* Input/output are mbuf chains */
447 #define CRYPTO_F_IOV 0x0002 /* Input/output are uio */
448 #define CRYPTO_F_REL 0x0004 /* Must return data in same place */
449 #define CRYPTO_F_BATCH 0x0008 /* Batch op if possible possible */
450 #define CRYPTO_F_CBIMM 0x0010 /* Do callback immediately */
451 #define CRYPTO_F_DONE 0x0020 /* Operation completed */
452 #define CRYPTO_F_CBIFSYNC 0x0040 /* Do CBIMM if op is synchronous */
453 #define CRYPTO_F_ONRETQ 0x0080 /* Request is on return queue */
454
455 void * crp_buf; /* Data to be processed */
456 void * crp_opaque; /* Opaque pointer, passed along */
457 struct cryptodesc *crp_desc; /* Linked list of processing descriptors */
458
459 int (*crp_callback)(struct cryptop *); /* Callback function */
460
461 void * crp_mac;
462 struct timespec crp_tstamp; /* performance time stamp */
463 kcondvar_t crp_cv;
464 struct fcrypt *fcrp;
465 void * dst;
466 void * mac;
467 u_int len;
468 u_char tmp_iv[EALG_MAX_BLOCK_LEN];
469 u_char tmp_mac[CRYPTO_MAX_MAC_LEN];
470
471 struct iovec iovec[1];
472 struct uio uio;
473 };
474
475 #define CRYPTO_BUF_CONTIG 0x0
476 #define CRYPTO_BUF_IOV 0x1
477 #define CRYPTO_BUF_MBUF 0x2
478
479 #define CRYPTO_OP_DECRYPT 0x0
480 #define CRYPTO_OP_ENCRYPT 0x1
481
482 /*
483 * Hints passed to process methods.
484 */
485 #define CRYPTO_HINT_MORE 0x1 /* more ops coming shortly */
486
487 struct cryptkop {
488 union {
489 TAILQ_ENTRY(cryptkop) krp_tnext;
490 SLIST_ENTRY(cryptkop) krp_lnext;
491 } krp_qun;
492 #define krp_next krp_qun.krp_tnext /* XXX compat */
493
494 u_int32_t krp_reqid; /* request id */
495 void * krp_usropaque; /* Opaque pointer from user, passed along */
496
497 u_int krp_op; /* ie. CRK_MOD_EXP or other */
498 u_int krp_status; /* return status */
499 u_short krp_iparams; /* # of input parameters */
500 u_short krp_oparams; /* # of output parameters */
501 u_int32_t krp_hid;
502 struct crparam krp_param[CRK_MAXPARAM]; /* kvm */
503 int (*krp_callback)(struct cryptkop *);
504 int krp_flags; /* same values as crp_flags */
505 kcondvar_t krp_cv;
506 struct fcrypt *fcrp;
507 struct crparam crk_param[CRK_MAXPARAM];
508 };
509
510 /* Crypto capabilities structure */
511 struct cryptocap {
512 u_int32_t cc_sessions;
513
514 /*
515 * Largest possible operator length (in bits) for each type of
516 * encryption algorithm.
517 */
518 u_int16_t cc_max_op_len[CRYPTO_ALGORITHM_MAX + 1];
519
520 u_int8_t cc_alg[CRYPTO_ALGORITHM_MAX + 1];
521
522 u_int8_t cc_kalg[CRK_ALGORITHM_MAX + 1];
523
524 u_int8_t cc_flags;
525 u_int8_t cc_qblocked; /* symmetric q blocked */
526 u_int8_t cc_kqblocked; /* asymmetric q blocked */
527 #define CRYPTOCAP_F_CLEANUP 0x01 /* needs resource cleanup */
528 #define CRYPTOCAP_F_SOFTWARE 0x02 /* software implementation */
529 #define CRYPTOCAP_F_SYNC 0x04 /* operates synchronously */
530
531 void *cc_arg; /* callback argument */
532 int (*cc_newsession)(void*, u_int32_t*, struct cryptoini*);
533 int (*cc_process) (void*, struct cryptop *, int);
534 int (*cc_freesession) (void*, u_int64_t);
535 void *cc_karg; /* callback argument */
536 int (*cc_kprocess) (void*, struct cryptkop *, int);
537 };
538
539 /*
540 * Session ids are 64 bits. The lower 32 bits contain a "local id" which
541 * is a driver-private session identifier. The upper 32 bits contain a
542 * "hardware id" used by the core crypto code to identify the driver and
543 * a copy of the driver's capabilities that can be used by client code to
544 * optimize operation.
545 */
546 #define CRYPTO_SESID2HID(_sid) (((_sid) >> 32) & 0xffffff)
547 #define CRYPTO_SESID2CAPS(_sid) (((_sid) >> 56) & 0xff)
548 #define CRYPTO_SESID2LID(_sid) (((u_int32_t) (_sid)) & 0xffffffff)
549
550 MALLOC_DECLARE(M_CRYPTO_DATA);
551
552 extern int crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard);
553 extern int crypto_freesession(u_int64_t sid);
554 extern int32_t crypto_get_driverid(u_int32_t flags);
555 extern int crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
556 u_int32_t flags,
557 int (*newses)(void*, u_int32_t*, struct cryptoini*),
558 int (*freeses)(void*, u_int64_t),
559 int (*process)(void*, struct cryptop *, int),
560 void *arg);
561 extern int crypto_kregister(u_int32_t, int, u_int32_t,
562 int (*)(void*, struct cryptkop *, int),
563 void *arg);
564 extern int crypto_unregister(u_int32_t driverid, int alg);
565 extern int crypto_unregister_all(u_int32_t driverid);
566 extern int crypto_dispatch(struct cryptop *crp);
567 extern int crypto_kdispatch(struct cryptkop *);
568 #define CRYPTO_SYMQ 0x1
569 #define CRYPTO_ASYMQ 0x2
570 extern int crypto_unblock(u_int32_t, int);
571 extern void crypto_done(struct cryptop *crp);
572 extern void crypto_kdone(struct cryptkop *);
573 extern int crypto_getfeat(int *);
574
575 void cuio_copydata(struct uio *, int, int, void *);
576 void cuio_copyback(struct uio *, int, int, void *);
577 int cuio_apply(struct uio *, int, int,
578 int (*f)(void *, void *, unsigned int), void *);
579
580 extern int crypto_ret_q_remove(struct cryptop *);
581 extern int crypto_ret_kq_remove(struct cryptkop *);
582 extern void crypto_freereq(struct cryptop *crp);
583 extern struct cryptop *crypto_getreq(int num);
584
585 extern int crypto_usercrypto; /* userland may do crypto requests */
586 extern int crypto_userasymcrypto; /* userland may do asym crypto reqs */
587 extern int crypto_devallowsoft; /* only use hardware crypto */
588
589 /*
590 * Asymmetric operations are allocated in cryptodev.c but can be
591 * freed in crypto.c.
592 */
593 extern struct pool cryptkop_pool;
594
595 /*
596 * Mutual exclusion and its unwelcome friends.
597 */
598
599 extern kmutex_t crypto_mtx;
600
601 /*
602 * initialize the crypto framework subsystem (not the pseudo-device).
603 * This must be called very early in boot, so the framework is ready
604 * to handle registration requests when crpto hardware is autoconfigured.
605 * (This declaration doesnt really belong here but there's no header
606 * for the raw framework.)
607 */
608 void crypto_init(void);
609
610 /*
611 * Crypto-related utility routines used mainly by drivers.
612 *
613 * XXX these don't really belong here; but for now they're
614 * kept apart from the rest of the system.
615 */
616 struct mbuf;
617 struct mbuf *m_getptr(struct mbuf *, int, int *);
618
619 struct uio;
620 extern void cuio_copydata(struct uio* uio, int off, int len, void *cp);
621 extern void cuio_copyback(struct uio* uio, int off, int len, void *cp);
622 extern int cuio_getptr(struct uio *, int loc, int *off);
623
624 #ifdef CRYPTO_DEBUG /* yuck, netipsec defines these differently */
625 #ifndef DPRINTF
626 #define DPRINTF(a) uprintf a
627 #endif
628 #ifndef DCPRINTF
629 #define DCPRINTF(a) printf a
630 #endif
631 #else
632 #ifndef DPRINTF
633 #define DPRINTF(a)
634 #endif
635 #ifndef DCPRINTF
636 #define DCPRINTF(a)
637 #endif
638 #endif
639
640 #endif /* _KERNEL */
641 #endif /* _CRYPTO_CRYPTO_H_ */
642