Home | History | Annotate | Line # | Download | only in opencrypto
cryptodev.h revision 1.8.22.1
      1  1.8.22.1       mjf /*	$NetBSD: cryptodev.h,v 1.8.22.1 2008/02/18 21:07:18 mjf Exp $ */
      2       1.5  jonathan /*	$FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $	*/
      3       1.1  jonathan /*	$OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $	*/
      4       1.1  jonathan 
      5       1.1  jonathan /*
      6       1.1  jonathan  * The author of this code is Angelos D. Keromytis (angelos (at) cis.upenn.edu)
      7       1.1  jonathan  *
      8       1.1  jonathan  * This code was written by Angelos D. Keromytis in Athens, Greece, in
      9       1.1  jonathan  * February 2000. Network Security Technologies Inc. (NSTI) kindly
     10       1.1  jonathan  * supported the development of this code.
     11       1.1  jonathan  *
     12       1.1  jonathan  * Copyright (c) 2000 Angelos D. Keromytis
     13       1.1  jonathan  *
     14       1.1  jonathan  * Permission to use, copy, and modify this software with or without fee
     15       1.1  jonathan  * is hereby granted, provided that this entire notice is included in
     16       1.1  jonathan  * all source code copies of any software which is or includes a copy or
     17       1.1  jonathan  * modification of this software.
     18       1.1  jonathan  *
     19       1.1  jonathan  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
     20       1.1  jonathan  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
     21       1.1  jonathan  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
     22       1.1  jonathan  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
     23       1.1  jonathan  * PURPOSE.
     24       1.1  jonathan  *
     25       1.1  jonathan  * Copyright (c) 2001 Theo de Raadt
     26       1.1  jonathan  *
     27       1.1  jonathan  * Redistribution and use in source and binary forms, with or without
     28       1.1  jonathan  * modification, are permitted provided that the following conditions
     29       1.1  jonathan  * are met:
     30       1.1  jonathan  *
     31       1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     32       1.1  jonathan  *   notice, this list of conditions and the following disclaimer.
     33       1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     34       1.1  jonathan  *   notice, this list of conditions and the following disclaimer in the
     35       1.1  jonathan  *   documentation and/or other materials provided with the distribution.
     36       1.1  jonathan  * 3. The name of the author may not be used to endorse or promote products
     37       1.1  jonathan  *   derived from this software without specific prior written permission.
     38       1.1  jonathan  *
     39       1.1  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     40       1.1  jonathan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     41       1.1  jonathan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     42       1.1  jonathan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     43       1.1  jonathan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     44       1.1  jonathan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     45       1.1  jonathan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     46       1.1  jonathan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     47       1.1  jonathan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     48       1.1  jonathan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     49       1.1  jonathan  *
     50       1.1  jonathan  * Effort sponsored in part by the Defense Advanced Research Projects
     51       1.1  jonathan  * Agency (DARPA) and Air Force Research Laboratory, Air Force
     52       1.1  jonathan  * Materiel Command, USAF, under agreement number F30602-01-2-0537.
     53       1.1  jonathan  *
     54       1.1  jonathan  */
     55       1.1  jonathan 
     56       1.1  jonathan #ifndef _CRYPTO_CRYPTO_H_
     57       1.1  jonathan #define _CRYPTO_CRYPTO_H_
     58       1.1  jonathan 
     59       1.1  jonathan #include <sys/ioccom.h>
     60       1.1  jonathan 
     61       1.1  jonathan /* Some initial values */
     62       1.1  jonathan #define CRYPTO_DRIVERS_INITIAL	4
     63       1.1  jonathan #define CRYPTO_SW_SESSIONS	32
     64       1.1  jonathan 
     65       1.1  jonathan /* HMAC values */
     66       1.1  jonathan #define HMAC_BLOCK_LEN		64
     67       1.1  jonathan #define HMAC_IPAD_VAL		0x36
     68       1.1  jonathan #define HMAC_OPAD_VAL		0x5C
     69       1.1  jonathan 
     70       1.1  jonathan /* Encryption algorithm block sizes */
     71       1.1  jonathan #define DES_BLOCK_LEN		8
     72       1.1  jonathan #define DES3_BLOCK_LEN		8
     73       1.1  jonathan #define BLOWFISH_BLOCK_LEN	8
     74       1.1  jonathan #define SKIPJACK_BLOCK_LEN	8
     75       1.1  jonathan #define CAST128_BLOCK_LEN	8
     76       1.1  jonathan #define RIJNDAEL128_BLOCK_LEN	16
     77       1.1  jonathan #define EALG_MAX_BLOCK_LEN	16 /* Keep this updated */
     78       1.1  jonathan 
     79       1.1  jonathan /* Maximum hash algorithm result length */
     80       1.1  jonathan #define AALG_MAX_RESULT_LEN	64 /* Keep this updated */
     81       1.1  jonathan 
     82       1.1  jonathan #define	CRYPTO_ALGORITHM_MIN	1
     83       1.1  jonathan #define CRYPTO_DES_CBC		1
     84       1.1  jonathan #define CRYPTO_3DES_CBC		2
     85       1.1  jonathan #define CRYPTO_BLF_CBC		3
     86       1.1  jonathan #define CRYPTO_CAST_CBC		4
     87       1.1  jonathan #define CRYPTO_SKIPJACK_CBC	5
     88       1.1  jonathan #define CRYPTO_MD5_HMAC		6
     89       1.1  jonathan #define CRYPTO_SHA1_HMAC	7
     90       1.1  jonathan #define CRYPTO_RIPEMD160_HMAC	8
     91       1.1  jonathan #define CRYPTO_MD5_KPDK		9
     92       1.1  jonathan #define CRYPTO_SHA1_KPDK	10
     93       1.1  jonathan #define CRYPTO_RIJNDAEL128_CBC	11 /* 128 bit blocksize */
     94       1.1  jonathan #define CRYPTO_AES_CBC		11 /* 128 bit blocksize -- the same as above */
     95       1.1  jonathan #define CRYPTO_ARC4		12
     96       1.1  jonathan #define CRYPTO_MD5		13
     97       1.1  jonathan #define CRYPTO_SHA1		14
     98       1.1  jonathan #define	CRYPTO_SHA2_HMAC	15
     99       1.1  jonathan #define CRYPTO_NULL_HMAC	16
    100       1.1  jonathan #define CRYPTO_NULL_CBC		17
    101       1.1  jonathan #define CRYPTO_DEFLATE_COMP	18 /* Deflate compression algorithm */
    102  1.8.22.1       mjf #define CRYPTO_MD5_HMAC_96	19
    103  1.8.22.1       mjf #define CRYPTO_SHA1_HMAC_96	20
    104  1.8.22.1       mjf #define CRYPTO_RIPEMD160_HMAC_96	21
    105  1.8.22.1       mjf #define CRYPTO_ALGORITHM_MAX	22 /* Keep updated - see below */
    106       1.1  jonathan 
    107       1.1  jonathan /* Algorithm flags */
    108       1.1  jonathan #define	CRYPTO_ALG_FLAG_SUPPORTED	0x01 /* Algorithm is supported */
    109       1.1  jonathan #define	CRYPTO_ALG_FLAG_RNG_ENABLE	0x02 /* Has HW RNG for DH/DSA */
    110       1.1  jonathan #define	CRYPTO_ALG_FLAG_DSA_SHA		0x04 /* Can do SHA on msg */
    111       1.1  jonathan 
    112       1.1  jonathan struct session_op {
    113       1.1  jonathan 	u_int32_t	cipher;		/* ie. CRYPTO_DES_CBC */
    114       1.1  jonathan 	u_int32_t	mac;		/* ie. CRYPTO_MD5_HMAC */
    115       1.1  jonathan 
    116       1.1  jonathan 	u_int32_t	keylen;		/* cipher key */
    117       1.8  christos 	void *		key;
    118       1.1  jonathan 	int		mackeylen;	/* mac key */
    119       1.8  christos 	void *		mackey;
    120       1.1  jonathan 
    121       1.6     perry   	u_int32_t	ses;		/* returns: session # */
    122       1.1  jonathan };
    123       1.1  jonathan 
    124       1.1  jonathan struct crypt_op {
    125       1.1  jonathan 	u_int32_t	ses;
    126       1.1  jonathan 	u_int16_t	op;		/* i.e. COP_ENCRYPT */
    127       1.1  jonathan #define COP_ENCRYPT	1
    128       1.1  jonathan #define COP_DECRYPT	2
    129       1.1  jonathan 	u_int16_t	flags;
    130       1.1  jonathan #define	COP_F_BATCH 	0x0008		/* Dispatch as quickly as possible */
    131       1.1  jonathan 	u_int		len;
    132       1.8  christos 	void *		src, *dst;	/* become iov[] inside kernel */
    133       1.8  christos 	void *		mac;		/* must be big enough for chosen MAC */
    134       1.8  christos 	void *		iv;
    135       1.1  jonathan };
    136       1.1  jonathan 
    137       1.1  jonathan #define CRYPTO_MAX_MAC_LEN	20
    138       1.1  jonathan 
    139       1.1  jonathan /* bignum parameter, in packed bytes, ... */
    140       1.1  jonathan struct crparam {
    141       1.8  christos 	void *		crp_p;
    142       1.1  jonathan 	u_int		crp_nbits;
    143       1.1  jonathan };
    144       1.1  jonathan 
    145       1.1  jonathan #define CRK_MAXPARAM	8
    146       1.1  jonathan 
    147       1.1  jonathan struct crypt_kop {
    148       1.1  jonathan 	u_int		crk_op;		/* ie. CRK_MOD_EXP or other */
    149       1.1  jonathan 	u_int		crk_status;	/* return status */
    150       1.1  jonathan 	u_short		crk_iparams;	/* # of input parameters */
    151       1.1  jonathan 	u_short		crk_oparams;	/* # of output parameters */
    152       1.1  jonathan 	u_int		crk_pad1;
    153       1.1  jonathan 	struct crparam	crk_param[CRK_MAXPARAM];
    154       1.1  jonathan };
    155       1.1  jonathan #define	CRK_ALGORITM_MIN	0
    156       1.1  jonathan #define CRK_MOD_EXP		0
    157       1.1  jonathan #define CRK_MOD_EXP_CRT		1
    158       1.1  jonathan #define CRK_DSA_SIGN		2
    159       1.1  jonathan #define CRK_DSA_VERIFY		3
    160       1.1  jonathan #define CRK_DH_COMPUTE_KEY	4
    161  1.8.22.1       mjf #define CRK_MOD_ADD		5
    162  1.8.22.1       mjf #define CRK_MOD_ADDINV		6
    163  1.8.22.1       mjf #define CRK_MOD_SUB		7
    164  1.8.22.1       mjf #define CRK_MOD_MULT		8
    165  1.8.22.1       mjf #define CRK_MOD_MULTINV		9
    166  1.8.22.1       mjf #define CRK_MOD			10
    167  1.8.22.1       mjf #define CRK_ALGORITHM_MAX	10 /* Keep updated - see below */
    168       1.1  jonathan 
    169       1.1  jonathan #define CRF_MOD_EXP		(1 << CRK_MOD_EXP)
    170       1.1  jonathan #define CRF_MOD_EXP_CRT		(1 << CRK_MOD_EXP_CRT)
    171       1.1  jonathan #define CRF_DSA_SIGN		(1 << CRK_DSA_SIGN)
    172       1.1  jonathan #define CRF_DSA_VERIFY		(1 << CRK_DSA_VERIFY)
    173       1.1  jonathan #define CRF_DH_COMPUTE_KEY	(1 << CRK_DH_COMPUTE_KEY)
    174  1.8.22.1       mjf #define CRF_MOD_ADD		(1 << CRK_MOD_ADD)
    175  1.8.22.1       mjf #define CRF_MOD_ADDINV		(1 << CRK_MOD_ADDINV)
    176  1.8.22.1       mjf #define CRF_MOD_SUB		(1 << CRK_MOD_SUB)
    177  1.8.22.1       mjf #define CRF_MOD_MULT		(1 << CRK_MOD_MULT)
    178  1.8.22.1       mjf #define CRF_MOD_MULTINV		(1 << CRK_MOD_MULTINV)
    179  1.8.22.1       mjf #define CRF_MOD			(1 << CRK_MOD)
    180       1.1  jonathan 
    181       1.1  jonathan /*
    182       1.1  jonathan  * done against open of /dev/crypto, to get a cloned descriptor.
    183       1.1  jonathan  * Please use F_SETFD against the cloned descriptor.
    184       1.1  jonathan  */
    185       1.1  jonathan #define	CRIOGET		_IOWR('c', 100, u_int32_t)
    186       1.1  jonathan 
    187       1.1  jonathan /* the following are done against the cloned descriptor */
    188       1.1  jonathan #define	CIOCGSESSION	_IOWR('c', 101, struct session_op)
    189       1.1  jonathan #define	CIOCFSESSION	_IOW('c', 102, u_int32_t)
    190       1.1  jonathan #define CIOCCRYPT	_IOWR('c', 103, struct crypt_op)
    191       1.1  jonathan #define CIOCKEY		_IOWR('c', 104, struct crypt_kop)
    192       1.1  jonathan 
    193       1.1  jonathan #define CIOCASYMFEAT	_IOR('c', 105, u_int32_t)
    194       1.1  jonathan 
    195       1.1  jonathan struct cryptotstat {
    196       1.1  jonathan 	struct timespec	acc;		/* total accumulated time */
    197       1.1  jonathan 	struct timespec	min;		/* max time */
    198       1.1  jonathan 	struct timespec	max;		/* max time */
    199       1.1  jonathan 	u_int32_t	count;		/* number of observations */
    200       1.1  jonathan };
    201       1.1  jonathan 
    202       1.1  jonathan struct cryptostats {
    203       1.1  jonathan 	u_int32_t	cs_ops;		/* symmetric crypto ops submitted */
    204       1.1  jonathan 	u_int32_t	cs_errs;	/* symmetric crypto ops that failed */
    205       1.1  jonathan 	u_int32_t	cs_kops;	/* asymetric/key ops submitted */
    206       1.1  jonathan 	u_int32_t	cs_kerrs;	/* asymetric/key ops that failed */
    207       1.1  jonathan 	u_int32_t	cs_intrs;	/* crypto swi thread activations */
    208       1.1  jonathan 	u_int32_t	cs_rets;	/* crypto return thread activations */
    209       1.1  jonathan 	u_int32_t	cs_blocks;	/* symmetric op driver block */
    210       1.1  jonathan 	u_int32_t	cs_kblocks;	/* symmetric op driver block */
    211       1.1  jonathan 	/*
    212       1.1  jonathan 	 * When CRYPTO_TIMING is defined at compile time and the
    213       1.1  jonathan 	 * sysctl debug.crypto is set to 1, the crypto system will
    214       1.1  jonathan 	 * accumulate statistics about how long it takes to process
    215       1.1  jonathan 	 * crypto requests at various points during processing.
    216       1.1  jonathan 	 */
    217       1.1  jonathan 	struct cryptotstat cs_invoke;	/* crypto_dipsatch -> crypto_invoke */
    218       1.1  jonathan 	struct cryptotstat cs_done;	/* crypto_invoke -> crypto_done */
    219       1.1  jonathan 	struct cryptotstat cs_cb;	/* crypto_done -> callback */
    220       1.1  jonathan 	struct cryptotstat cs_finis;	/* callback -> callback return */
    221       1.1  jonathan };
    222       1.1  jonathan 
    223       1.1  jonathan #ifdef _KERNEL
    224       1.1  jonathan /* Standard initialization structure beginning */
    225       1.1  jonathan struct cryptoini {
    226       1.1  jonathan 	int		cri_alg;	/* Algorithm to use */
    227       1.1  jonathan 	int		cri_klen;	/* Key length, in bits */
    228       1.1  jonathan 	int		cri_rnd;	/* Algorithm rounds, where relevant */
    229       1.8  christos 	char	       *cri_key;	/* key to use */
    230       1.1  jonathan 	u_int8_t	cri_iv[EALG_MAX_BLOCK_LEN];	/* IV to use */
    231       1.1  jonathan 	struct cryptoini *cri_next;
    232       1.1  jonathan };
    233       1.1  jonathan 
    234       1.1  jonathan /* Describe boundaries of a single crypto operation */
    235       1.1  jonathan struct cryptodesc {
    236       1.1  jonathan 	int		crd_skip;	/* How many bytes to ignore from start */
    237       1.1  jonathan 	int		crd_len;	/* How many bytes to process */
    238       1.1  jonathan 	int		crd_inject;	/* Where to inject results, if applicable */
    239       1.1  jonathan 	int		crd_flags;
    240       1.1  jonathan 
    241       1.1  jonathan #define	CRD_F_ENCRYPT		0x01	/* Set when doing encryption */
    242       1.1  jonathan #define	CRD_F_IV_PRESENT	0x02	/* When encrypting, IV is already in
    243       1.1  jonathan 					   place, so don't copy. */
    244       1.1  jonathan #define	CRD_F_IV_EXPLICIT	0x04	/* IV explicitly provided */
    245       1.1  jonathan #define	CRD_F_DSA_SHA_NEEDED	0x08	/* Compute SHA-1 of buffer for DSA */
    246       1.1  jonathan #define CRD_F_COMP		0x0f    /* Set when doing compression */
    247       1.1  jonathan 
    248       1.1  jonathan 	struct cryptoini	CRD_INI; /* Initialization/context data */
    249       1.1  jonathan #define crd_iv		CRD_INI.cri_iv
    250       1.1  jonathan #define crd_key		CRD_INI.cri_key
    251       1.1  jonathan #define crd_rnd		CRD_INI.cri_rnd
    252       1.1  jonathan #define crd_alg		CRD_INI.cri_alg
    253       1.1  jonathan #define crd_klen	CRD_INI.cri_klen
    254       1.1  jonathan 
    255       1.1  jonathan 	struct cryptodesc *crd_next;
    256       1.1  jonathan };
    257       1.1  jonathan 
    258       1.1  jonathan /* Structure describing complete operation */
    259       1.1  jonathan struct cryptop {
    260       1.1  jonathan 	TAILQ_ENTRY(cryptop) crp_next;
    261       1.1  jonathan 
    262       1.1  jonathan 	u_int64_t	crp_sid;	/* Session ID */
    263       1.1  jonathan 	int		crp_ilen;	/* Input data total length */
    264       1.1  jonathan 	int		crp_olen;	/* Result total length */
    265       1.1  jonathan 
    266       1.1  jonathan 	int		crp_etype;	/*
    267       1.1  jonathan 					 * Error type (zero means no error).
    268       1.1  jonathan 					 * All error codes except EAGAIN
    269       1.1  jonathan 					 * indicate possible data corruption (as in,
    270       1.1  jonathan 					 * the data have been touched). On all
    271       1.1  jonathan 					 * errors, the crp_sid may have changed
    272       1.1  jonathan 					 * (reset to a new one), so the caller
    273       1.1  jonathan 					 * should always check and use the new
    274       1.1  jonathan 					 * value on future requests.
    275       1.1  jonathan 					 */
    276       1.1  jonathan 	int		crp_flags;
    277       1.1  jonathan 
    278       1.5  jonathan #define CRYPTO_F_IMBUF		0x0001	/* Input/output are mbuf chains */
    279       1.5  jonathan #define CRYPTO_F_IOV		0x0002	/* Input/output are uio */
    280       1.5  jonathan #define CRYPTO_F_REL		0x0004	/* Must return data in same place */
    281       1.5  jonathan #define	CRYPTO_F_BATCH		0x0008	/* Batch op if possible possible */
    282       1.5  jonathan #define	CRYPTO_F_CBIMM		0x0010	/* Do callback immediately */
    283       1.5  jonathan #define	CRYPTO_F_DONE		0x0020	/* Operation completed */
    284       1.5  jonathan #define	CRYPTO_F_CBIFSYNC	0x0040	/* Do CBIMM if op is synchronous */
    285  1.8.22.1       mjf #define	CRYPTO_F_ONRETQ		0x0080	/* Request is on return queue */
    286       1.1  jonathan 
    287       1.8  christos 	void *		crp_buf;	/* Data to be processed */
    288       1.8  christos 	void *		crp_opaque;	/* Opaque pointer, passed along */
    289       1.1  jonathan 	struct cryptodesc *crp_desc;	/* Linked list of processing descriptors */
    290       1.1  jonathan 
    291       1.1  jonathan 	int (*crp_callback)(struct cryptop *); /* Callback function */
    292       1.1  jonathan 
    293       1.8  christos 	void *		crp_mac;
    294       1.1  jonathan 	struct timespec	crp_tstamp;	/* performance time stamp */
    295  1.8.22.1       mjf 	kcondvar_t	crp_cv;
    296       1.1  jonathan };
    297       1.1  jonathan 
    298       1.1  jonathan #define CRYPTO_BUF_CONTIG	0x0
    299       1.1  jonathan #define CRYPTO_BUF_IOV		0x1
    300       1.1  jonathan #define CRYPTO_BUF_MBUF		0x2
    301       1.1  jonathan 
    302       1.1  jonathan #define CRYPTO_OP_DECRYPT	0x0
    303       1.1  jonathan #define CRYPTO_OP_ENCRYPT	0x1
    304       1.1  jonathan 
    305       1.1  jonathan /*
    306       1.1  jonathan  * Hints passed to process methods.
    307       1.1  jonathan  */
    308       1.1  jonathan #define	CRYPTO_HINT_MORE	0x1	/* more ops coming shortly */
    309       1.1  jonathan 
    310       1.1  jonathan struct cryptkop {
    311       1.1  jonathan 	TAILQ_ENTRY(cryptkop) krp_next;
    312       1.1  jonathan 
    313       1.1  jonathan 	u_int		krp_op;		/* ie. CRK_MOD_EXP or other */
    314       1.1  jonathan 	u_int		krp_status;	/* return status */
    315       1.1  jonathan 	u_short		krp_iparams;	/* # of input parameters */
    316       1.1  jonathan 	u_short		krp_oparams;	/* # of output parameters */
    317       1.1  jonathan 	u_int32_t	krp_hid;
    318       1.1  jonathan 	struct crparam	krp_param[CRK_MAXPARAM];	/* kvm */
    319       1.1  jonathan 	int		(*krp_callback)(struct cryptkop *);
    320  1.8.22.1       mjf 	int		krp_flags;	/* same values as crp_flags */
    321  1.8.22.1       mjf 	kcondvar_t	krp_cv;
    322       1.1  jonathan };
    323       1.1  jonathan 
    324       1.1  jonathan /* Crypto capabilities structure */
    325       1.1  jonathan struct cryptocap {
    326       1.1  jonathan 	u_int32_t	cc_sessions;
    327       1.1  jonathan 
    328       1.1  jonathan 	/*
    329       1.1  jonathan 	 * Largest possible operator length (in bits) for each type of
    330       1.1  jonathan 	 * encryption algorithm.
    331       1.1  jonathan 	 */
    332       1.1  jonathan 	u_int16_t	cc_max_op_len[CRYPTO_ALGORITHM_MAX + 1];
    333       1.1  jonathan 
    334       1.1  jonathan 	u_int8_t	cc_alg[CRYPTO_ALGORITHM_MAX + 1];
    335       1.1  jonathan 
    336       1.1  jonathan 	u_int8_t	cc_kalg[CRK_ALGORITHM_MAX + 1];
    337       1.1  jonathan 
    338       1.1  jonathan 	u_int8_t	cc_flags;
    339       1.1  jonathan 	u_int8_t	cc_qblocked;		/* symmetric q blocked */
    340       1.1  jonathan 	u_int8_t	cc_kqblocked;		/* asymmetric q blocked */
    341       1.5  jonathan #define CRYPTOCAP_F_CLEANUP	0x01		/* needs resource cleanup */
    342       1.5  jonathan #define CRYPTOCAP_F_SOFTWARE	0x02		/* software implementation */
    343       1.5  jonathan #define CRYPTOCAP_F_SYNC	0x04		/* operates synchronously */
    344       1.1  jonathan 
    345       1.1  jonathan 	void		*cc_arg;		/* callback argument */
    346       1.1  jonathan 	int		(*cc_newsession)(void*, u_int32_t*, struct cryptoini*);
    347       1.1  jonathan 	int		(*cc_process) (void*, struct cryptop *, int);
    348       1.1  jonathan 	int		(*cc_freesession) (void*, u_int64_t);
    349       1.1  jonathan 	void		*cc_karg;		/* callback argument */
    350       1.1  jonathan 	int		(*cc_kprocess) (void*, struct cryptkop *, int);
    351       1.1  jonathan };
    352       1.5  jonathan 
    353       1.5  jonathan /*
    354       1.5  jonathan  * Session ids are 64 bits.  The lower 32 bits contain a "local id" which
    355       1.5  jonathan  * is a driver-private session identifier.  The upper 32 bits contain a
    356       1.5  jonathan  * "hardware id" used by the core crypto code to identify the driver and
    357       1.5  jonathan  * a copy of the driver's capabilities that can be used by client code to
    358       1.5  jonathan  * optimize operation.
    359       1.5  jonathan  */
    360       1.5  jonathan #define	CRYPTO_SESID2HID(_sid)	(((_sid) >> 32) & 0xffffff)
    361       1.5  jonathan #define	CRYPTO_SESID2CAPS(_sid)	(((_sid) >> 56) & 0xff)
    362       1.5  jonathan #define	CRYPTO_SESID2LID(_sid)	(((u_int32_t) (_sid)) & 0xffffffff)
    363       1.1  jonathan 
    364       1.1  jonathan MALLOC_DECLARE(M_CRYPTO_DATA);
    365       1.1  jonathan 
    366       1.1  jonathan extern	int crypto_newsession(u_int64_t *sid, struct cryptoini *cri, int hard);
    367       1.1  jonathan extern	int crypto_freesession(u_int64_t sid);
    368       1.1  jonathan extern	int32_t crypto_get_driverid(u_int32_t flags);
    369       1.1  jonathan extern	int crypto_register(u_int32_t driverid, int alg, u_int16_t maxoplen,
    370       1.1  jonathan 	    u_int32_t flags,
    371       1.1  jonathan 	    int (*newses)(void*, u_int32_t*, struct cryptoini*),
    372       1.1  jonathan 	    int (*freeses)(void*, u_int64_t),
    373       1.1  jonathan 	    int (*process)(void*, struct cryptop *, int),
    374       1.1  jonathan 	    void *arg);
    375       1.1  jonathan extern	int crypto_kregister(u_int32_t, int, u_int32_t,
    376       1.1  jonathan 	    int (*)(void*, struct cryptkop *, int),
    377       1.1  jonathan 	    void *arg);
    378       1.1  jonathan extern	int crypto_unregister(u_int32_t driverid, int alg);
    379       1.1  jonathan extern	int crypto_unregister_all(u_int32_t driverid);
    380       1.1  jonathan extern	int crypto_dispatch(struct cryptop *crp);
    381       1.1  jonathan extern	int crypto_kdispatch(struct cryptkop *);
    382       1.1  jonathan #define	CRYPTO_SYMQ	0x1
    383       1.1  jonathan #define	CRYPTO_ASYMQ	0x2
    384       1.1  jonathan extern	int crypto_unblock(u_int32_t, int);
    385       1.1  jonathan extern	void crypto_done(struct cryptop *crp);
    386       1.1  jonathan extern	void crypto_kdone(struct cryptkop *);
    387       1.1  jonathan extern	int crypto_getfeat(int *);
    388       1.1  jonathan 
    389       1.8  christos void	cuio_copydata(struct uio *, int, int, void *);
    390       1.8  christos void	cuio_copyback(struct uio *, int, int, void *);
    391       1.1  jonathan int	cuio_apply(struct uio *, int, int,
    392       1.8  christos 	    int (*f)(void *, void *, unsigned int), void *);
    393       1.1  jonathan 
    394  1.8.22.1       mjf extern	int crypto_ret_q_remove(struct cryptop *);
    395  1.8.22.1       mjf extern	int crypto_ret_kq_remove(struct cryptkop *);
    396       1.1  jonathan extern	void crypto_freereq(struct cryptop *crp);
    397       1.1  jonathan extern	struct cryptop *crypto_getreq(int num);
    398       1.1  jonathan 
    399       1.1  jonathan extern	int crypto_usercrypto;		/* userland may do crypto requests */
    400       1.1  jonathan extern	int crypto_userasymcrypto;	/* userland may do asym crypto reqs */
    401       1.1  jonathan extern	int crypto_devallowsoft;	/* only use hardware crypto */
    402       1.3  jonathan 
    403  1.8.22.1       mjf /*
    404  1.8.22.1       mjf  * Asymmetric operations are allocated in cryptodev.c but can be
    405  1.8.22.1       mjf  * freed in crypto.c.
    406  1.8.22.1       mjf  */
    407  1.8.22.1       mjf extern	struct pool	cryptkop_pool;
    408  1.8.22.1       mjf 
    409  1.8.22.1       mjf /*
    410  1.8.22.1       mjf  * Mutual exclusion and its unwelcome friends.
    411  1.8.22.1       mjf  */
    412  1.8.22.1       mjf 
    413  1.8.22.1       mjf extern	kmutex_t	crypto_mtx;
    414       1.3  jonathan 
    415       1.3  jonathan /*
    416       1.3  jonathan  * initialize the crypto framework subsystem (not the pseudo-device).
    417       1.3  jonathan  * This must be called very early in boot, so the framework is ready
    418       1.3  jonathan  * to handle registration requests when crpto hardware is autoconfigured.
    419       1.3  jonathan  * (This declaration doesnt really belong here but there's no header
    420       1.3  jonathan  * for the raw framework.)
    421       1.3  jonathan  */
    422       1.7   thorpej void	crypto_init(void);
    423       1.1  jonathan 
    424       1.1  jonathan /*
    425       1.1  jonathan  * Crypto-related utility routines used mainly by drivers.
    426       1.1  jonathan  *
    427       1.1  jonathan  * XXX these don't really belong here; but for now they're
    428       1.1  jonathan  *     kept apart from the rest of the system.
    429       1.1  jonathan  */
    430       1.1  jonathan struct mbuf;
    431       1.1  jonathan struct	mbuf	*m_getptr(struct mbuf *, int, int *);
    432       1.1  jonathan 
    433       1.1  jonathan struct uio;
    434       1.8  christos extern	void cuio_copydata(struct uio* uio, int off, int len, void *cp);
    435       1.8  christos extern	void cuio_copyback(struct uio* uio, int off, int len, void *cp);
    436       1.1  jonathan extern int	cuio_getptr(struct uio *, int loc, int *off);
    437       1.1  jonathan 
    438  1.8.22.1       mjf #ifdef CRYPTO_DEBUG	/* yuck, netipsec defines these differently */
    439  1.8.22.1       mjf #ifndef DPRINTF
    440  1.8.22.1       mjf #define DPRINTF(a) uprintf a
    441  1.8.22.1       mjf #endif
    442  1.8.22.1       mjf #ifndef DCPRINTF
    443  1.8.22.1       mjf #define DCPRINTF(a) printf a
    444  1.8.22.1       mjf #endif
    445  1.8.22.1       mjf #else
    446  1.8.22.1       mjf #ifndef DPRINTF
    447  1.8.22.1       mjf #define DPRINTF(a)
    448  1.8.22.1       mjf #endif
    449  1.8.22.1       mjf #ifndef DCPRINTF
    450  1.8.22.1       mjf #define DCPRINTF(a)
    451  1.8.22.1       mjf #endif
    452  1.8.22.1       mjf #endif
    453       1.1  jonathan 
    454       1.1  jonathan #endif /* _KERNEL */
    455       1.1  jonathan #endif /* _CRYPTO_CRYPTO_H_ */
    456