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