allow run-time selection of zero-copy or not
[cryptodev-linux.git] / cryptodev.h
blob613fe8524a67f6793aa7e3fd54b1b3538851d1cf
1 /* This is a source compatible implementation with the original API of
2 * cryptodev by Angelos D. Keromytis, found at openbsd cryptodev.h.
3 * Placed under public domain */
5 #ifndef L_CRYPTODEV_H
6 #define L_CRYPTODEV_H
8 #ifndef __KERNEL__
9 #include <inttypes.h>
10 #endif
12 /* API extensions for linux */
13 #define CRYPTO_HMAC_MAX_KEY_LEN 512
14 #define CRYPTO_CIPHER_MAX_KEY_LEN 64
16 /* All the supported algorithms
18 typedef enum {
19 CRYPTO_DES_CBC=1,
20 CRYPTO_3DES_CBC=2,
21 CRYPTO_BLF_CBC=3,
22 CRYPTO_CAST_CBC=4,
23 CRYPTO_SKIPJACK_CBC=5,
24 CRYPTO_MD5_HMAC=6,
25 CRYPTO_SHA1_HMAC=7,
26 CRYPTO_RIPEMD160_HMAC=8,
27 CRYPTO_MD5_KPDK=9,
28 CRYPTO_SHA1_KPDK=10,
29 CRYPTO_RIJNDAEL128_CBC=11,
30 CRYPTO_AES_CBC=CRYPTO_RIJNDAEL128_CBC,
31 CRYPTO_ARC4=12,
32 CRYPTO_MD5=13,
33 CRYPTO_SHA1=14,
34 CRYPTO_DEFLATE_COMP=15,
35 CRYPTO_NULL=16,
36 CRYPTO_LZS_COMP=17,
37 CRYPTO_SHA2_256_HMAC=18,
38 CRYPTO_SHA2_384_HMAC=19,
39 CRYPTO_SHA2_512_HMAC=20,
40 CRYPTO_AES_CTR=21,
41 CRYPTO_AES_XTS=22,
43 CRYPTO_CAMELLIA_CBC=101,
44 CRYPTO_RIPEMD160,
45 CRYPTO_SHA2_256,
46 CRYPTO_SHA2_384,
47 CRYPTO_SHA2_512,
48 CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */
49 } cryptodev_crypto_op_t;
50 #define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1)
52 /* Values for ciphers */
53 #define DES_BLOCK_LEN 8
54 #define DES3_BLOCK_LEN 8
55 #define RIJNDAEL128_BLOCK_LEN 16
56 #define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN
57 #define CAMELLIA_BLOCK_LEN
58 #define BLOWFISH_BLOCK_LEN 8
59 #define SKIPJACK_BLOCK_LEN 8
60 #define CAST128_BLOCK_LEN 8
62 /* the maximum of the above */
63 #define EALG_MAX_BLOCK_LEN 16
65 /* Values for hashes/MAC */
66 #define AALG_MAX_RESULT_LEN 64
68 /* input of CIOCGSESSION */
69 struct session_op {
70 /* Specify either cipher or mac
72 uint32_t cipher; /* cryptodev_crypto_op_t */
73 uint32_t mac; /* cryptodev_crypto_op_t */
75 uint32_t keylen;
76 uint8_t * key;
77 uint32_t mackeylen;
78 uint8_t * mackey;
80 uint32_t ses; /* session identifier */
83 #define COP_ENCRYPT 0
84 #define COP_DECRYPT 1
86 /* input of CIOCCRYPT */
87 struct crypt_op {
88 uint32_t ses; /* session identifier */
89 uint16_t op; /* COP_ENCRYPT or COP_DECRYPT */
90 uint16_t flags; /* operational switches, use 0 in doubt */
91 uint32_t len; /* length of source data */
92 uint8_t * src; /* source data */
93 uint8_t * dst; /* pointer to output data */
94 uint8_t * mac; /* pointer to output data for hash/MAC operations */
95 uint8_t * iv; /* initialization vector for encryption operations */
98 /* struct crypt_op flags */
100 #define COP_FLAG_NONE (0 << 0) /* totally no flag */
101 #define COP_FLAG_ZCOPY (1 << 0) /* operate directly on the userspace buffer */
103 /* Stuff for bignum arithmetic and public key
104 * cryptography - not supported yet by linux
105 * cryptodev.
108 #define CRYPTO_ALG_FLAG_SUPPORTED 1
109 #define CRYPTO_ALG_FLAG_RNG_ENABLE 2
110 #define CRYPTO_ALG_FLAG_DSA_SHA 4
112 struct crparam {
113 uint8_t* crp_p;
114 uint32_t crp_nbits;
117 #define CRK_MAXPARAM 8
119 /* input of CIOCKEY */
120 struct crypt_kop {
121 uint32_t crk_op; /* cryptodev_crk_ot_t */
122 uint32_t crk_status;
123 uint16_t crk_iparams;
124 uint16_t crk_oparams;
125 uint32_t crk_pad1;
126 struct crparam crk_param[CRK_MAXPARAM];
129 typedef enum {
130 CRK_MOD_EXP=0,
131 CRK_MOD_EXP_CRT=1,
132 CRK_DSA_SIGN=2,
133 CRK_DSA_VERIFY=3,
134 CRK_DH_COMPUTE_KEY=4,
135 CRK_ALGORITHM_ALL
136 } cryptodev_crk_op_t;
138 #define CRK_ALGORITHM_MAX CRK_ALGORITHM_ALL-1
140 /* features to be queried with CIOCASYMFEAT ioctl
142 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
143 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
144 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
145 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
146 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
149 /* ioctl's. Compatible with old linux cryptodev.h
151 #define CRIOGET _IOWR('c', 101, uint32_t)
152 #define CIOCGSESSION _IOWR('c', 102, struct session_op)
153 #define CIOCFSESSION _IOW('c', 103, uint32_t)
154 #define CIOCCRYPT _IOWR('c', 104, struct crypt_op)
155 #define CIOCKEY _IOWR('c', 105, struct crypt_kop)
156 #define CIOCASYMFEAT _IOR('c', 106, uint32_t)
158 #endif /* L_CRYPTODEV_H */