base-files: fix ucert verification
[openwrt/staging/jogo.git] / package / libs / openssl / include / crypto / cryptodev.h
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 */
4
5 #ifndef L_CRYPTODEV_H
6 #define L_CRYPTODEV_H
7
8 #include <linux/types.h>
9 #ifndef __KERNEL__
10 #define __user
11 #endif
12
13 /* API extensions for linux */
14 #define CRYPTO_HMAC_MAX_KEY_LEN 512
15 #define CRYPTO_CIPHER_MAX_KEY_LEN 64
16
17 /* All the supported algorithms
18 */
19 enum cryptodev_crypto_op_t {
20 CRYPTO_DES_CBC = 1,
21 CRYPTO_3DES_CBC = 2,
22 CRYPTO_BLF_CBC = 3,
23 CRYPTO_CAST_CBC = 4,
24 CRYPTO_SKIPJACK_CBC = 5,
25 CRYPTO_MD5_HMAC = 6,
26 CRYPTO_SHA1_HMAC = 7,
27 CRYPTO_RIPEMD160_HMAC = 8,
28 CRYPTO_MD5_KPDK = 9,
29 CRYPTO_SHA1_KPDK = 10,
30 CRYPTO_RIJNDAEL128_CBC = 11,
31 CRYPTO_AES_CBC = CRYPTO_RIJNDAEL128_CBC,
32 CRYPTO_ARC4 = 12,
33 CRYPTO_MD5 = 13,
34 CRYPTO_SHA1 = 14,
35 CRYPTO_DEFLATE_COMP = 15,
36 CRYPTO_NULL = 16,
37 CRYPTO_LZS_COMP = 17,
38 CRYPTO_SHA2_256_HMAC = 18,
39 CRYPTO_SHA2_384_HMAC = 19,
40 CRYPTO_SHA2_512_HMAC = 20,
41 CRYPTO_AES_CTR = 21,
42 CRYPTO_AES_XTS = 22,
43 CRYPTO_AES_ECB = 23,
44 CRYPTO_AES_GCM = 50,
45
46 CRYPTO_CAMELLIA_CBC = 101,
47 CRYPTO_RIPEMD160,
48 CRYPTO_SHA2_224,
49 CRYPTO_SHA2_256,
50 CRYPTO_SHA2_384,
51 CRYPTO_SHA2_512,
52 CRYPTO_SHA2_224_HMAC,
53 CRYPTO_ALGORITHM_ALL, /* Keep updated - see below */
54 };
55
56 #define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1)
57
58 /* Values for ciphers */
59 #define DES_BLOCK_LEN 8
60 #define DES3_BLOCK_LEN 8
61 #define RIJNDAEL128_BLOCK_LEN 16
62 #define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN
63 #define CAMELLIA_BLOCK_LEN 16
64 #define BLOWFISH_BLOCK_LEN 8
65 #define SKIPJACK_BLOCK_LEN 8
66 #define CAST128_BLOCK_LEN 8
67
68 /* the maximum of the above */
69 #define EALG_MAX_BLOCK_LEN 16
70
71 /* Values for hashes/MAC */
72 #define AALG_MAX_RESULT_LEN 64
73
74 /* maximum length of verbose alg names (depends on CRYPTO_MAX_ALG_NAME) */
75 #define CRYPTODEV_MAX_ALG_NAME 64
76
77 #define HASH_MAX_LEN 64
78
79 /* input of CIOCGSESSION */
80 struct session_op {
81 /* Specify either cipher or mac
82 */
83 __u32 cipher; /* cryptodev_crypto_op_t */
84 __u32 mac; /* cryptodev_crypto_op_t */
85
86 __u32 keylen;
87 __u8 __user *key;
88 __u32 mackeylen;
89 __u8 __user *mackey;
90
91 __u32 ses; /* session identifier */
92 };
93
94 struct session_info_op {
95 __u32 ses; /* session identifier */
96
97 /* verbose names for the requested ciphers */
98 struct alg_info {
99 char cra_name[CRYPTODEV_MAX_ALG_NAME];
100 char cra_driver_name[CRYPTODEV_MAX_ALG_NAME];
101 } cipher_info, hash_info;
102
103 __u16 alignmask; /* alignment constraints */
104 __u32 flags; /* SIOP_FLAGS_* */
105 };
106
107 /* If this flag is set then this algorithm uses
108 * a driver only available in kernel (software drivers,
109 * or drivers based on instruction sets do not set this flag).
110 *
111 * If multiple algorithms are involved (as in AEAD case), then
112 * if one of them is kernel-driver-only this flag will be set.
113 */
114 #define SIOP_FLAG_KERNEL_DRIVER_ONLY 1
115
116 #define COP_ENCRYPT 0
117 #define COP_DECRYPT 1
118
119 /* input of CIOCCRYPT */
120 struct crypt_op {
121 __u32 ses; /* session identifier */
122 __u16 op; /* COP_ENCRYPT or COP_DECRYPT */
123 __u16 flags; /* see COP_FLAG_* */
124 __u32 len; /* length of source data */
125 __u8 __user *src; /* source data */
126 __u8 __user *dst; /* pointer to output data */
127 /* pointer to output data for hash/MAC operations */
128 __u8 __user *mac;
129 /* initialization vector for encryption operations */
130 __u8 __user *iv;
131 };
132
133 /* input of CIOCAUTHCRYPT */
134 struct crypt_auth_op {
135 __u32 ses; /* session identifier */
136 __u16 op; /* COP_ENCRYPT or COP_DECRYPT */
137 __u16 flags; /* see COP_FLAG_AEAD_* */
138 __u32 len; /* length of source data */
139 __u32 auth_len; /* length of auth data */
140 __u8 __user *auth_src; /* authenticated-only data */
141
142 /* The current implementation is more efficient if data are
143 * encrypted in-place (src==dst). */
144 __u8 __user *src; /* data to be encrypted and authenticated */
145 __u8 __user *dst; /* pointer to output data. Must have
146 * space for tag. For TLS this should be at least
147 * len + tag_size + block_size for padding */
148
149 __u8 __user *tag; /* where the tag will be copied to. TLS mode
150 * doesn't use that as tag is copied to dst.
151 * SRTP mode copies tag there. */
152 __u32 tag_len; /* the length of the tag. Use zero for digest size or max tag. */
153
154 /* initialization vector for encryption operations */
155 __u8 __user *iv;
156 __u32 iv_len;
157 };
158
159 /* In plain AEAD mode the following are required:
160 * flags : 0
161 * iv : the initialization vector (12 bytes)
162 * auth_len: the length of the data to be authenticated
163 * auth_src: the data to be authenticated
164 * len : length of data to be encrypted
165 * src : the data to be encrypted
166 * dst : space to hold encrypted data. It must have
167 * at least a size of len + tag_size.
168 * tag_size: the size of the desired authentication tag or zero to use
169 * the maximum tag output.
170 *
171 * Note tag isn't being used because the Linux AEAD interface
172 * copies the tag just after data.
173 */
174
175 /* In TLS mode (used for CBC ciphers that required padding)
176 * the following are required:
177 * flags : COP_FLAG_AEAD_TLS_TYPE
178 * iv : the initialization vector
179 * auth_len: the length of the data to be authenticated only
180 * len : length of data to be encrypted
181 * auth_src: the data to be authenticated
182 * src : the data to be encrypted
183 * dst : space to hold encrypted data (preferably in-place). It must have
184 * at least a size of len + tag_size + blocksize.
185 * tag_size: the size of the desired authentication tag or zero to use
186 * the default mac output.
187 *
188 * Note that the padding used is the minimum padding.
189 */
190
191 /* In SRTP mode the following are required:
192 * flags : COP_FLAG_AEAD_SRTP_TYPE
193 * iv : the initialization vector
194 * auth_len: the length of the data to be authenticated. This must
195 * include the SRTP header + SRTP payload (data to be encrypted) + rest
196 *
197 * len : length of data to be encrypted
198 * auth_src: pointer the data to be authenticated. Should point at the same buffer as src.
199 * src : pointer to the data to be encrypted.
200 * dst : This is mandatory to be the same as src (in-place only).
201 * tag_size: the size of the desired authentication tag or zero to use
202 * the default mac output.
203 * tag : Pointer to an address where the authentication tag will be copied.
204 */
205
206
207 /* struct crypt_op flags */
208
209 #define COP_FLAG_NONE (0 << 0) /* totally no flag */
210 #define COP_FLAG_UPDATE (1 << 0) /* multi-update hash mode */
211 #define COP_FLAG_FINAL (1 << 1) /* multi-update final hash mode */
212 #define COP_FLAG_WRITE_IV (1 << 2) /* update the IV during operation */
213 #define COP_FLAG_NO_ZC (1 << 3) /* do not zero-copy */
214 #define COP_FLAG_AEAD_TLS_TYPE (1 << 4) /* authenticate and encrypt using the
215 * TLS protocol rules */
216 #define COP_FLAG_AEAD_SRTP_TYPE (1 << 5) /* authenticate and encrypt using the
217 * SRTP protocol rules */
218 #define COP_FLAG_RESET (1 << 6) /* multi-update reset the state.
219 * should be used in combination
220 * with COP_FLAG_UPDATE */
221
222
223 /* Stuff for bignum arithmetic and public key
224 * cryptography - not supported yet by linux
225 * cryptodev.
226 */
227
228 #define CRYPTO_ALG_FLAG_SUPPORTED 1
229 #define CRYPTO_ALG_FLAG_RNG_ENABLE 2
230 #define CRYPTO_ALG_FLAG_DSA_SHA 4
231
232 struct crparam {
233 __u8 *crp_p;
234 __u32 crp_nbits;
235 };
236
237 #define CRK_MAXPARAM 8
238
239 /* input of CIOCKEY */
240 struct crypt_kop {
241 __u32 crk_op; /* cryptodev_crk_op_t */
242 __u32 crk_status;
243 __u16 crk_iparams;
244 __u16 crk_oparams;
245 __u32 crk_pad1;
246 struct crparam crk_param[CRK_MAXPARAM];
247 };
248
249 enum cryptodev_crk_op_t {
250 CRK_MOD_EXP = 0,
251 CRK_MOD_EXP_CRT = 1,
252 CRK_DSA_SIGN = 2,
253 CRK_DSA_VERIFY = 3,
254 CRK_DH_COMPUTE_KEY = 4,
255 CRK_ALGORITHM_ALL
256 };
257
258 #define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1)
259
260 /* features to be queried with CIOCASYMFEAT ioctl
261 */
262 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
263 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
264 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
265 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
266 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
267
268
269 /* ioctl's. Compatible with old linux cryptodev.h
270 */
271 #define CRIOGET _IOWR('c', 101, __u32)
272 #define CIOCGSESSION _IOWR('c', 102, struct session_op)
273 #define CIOCFSESSION _IOW('c', 103, __u32)
274 #define CIOCCRYPT _IOWR('c', 104, struct crypt_op)
275 #define CIOCKEY _IOWR('c', 105, struct crypt_kop)
276 #define CIOCASYMFEAT _IOR('c', 106, __u32)
277 #define CIOCGSESSINFO _IOWR('c', 107, struct session_info_op)
278
279 /* to indicate that CRIOGET is not required in linux
280 */
281 #define CRIOGET_NOT_NEEDED 1
282
283 /* additional ioctls for AEAD */
284 #define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op)
285
286 /* additional ioctls for asynchronous operation.
287 * These are conditionally enabled since version 1.6.
288 */
289 #define CIOCASYNCCRYPT _IOW('c', 110, struct crypt_op)
290 #define CIOCASYNCFETCH _IOR('c', 111, struct crypt_op)
291
292 #endif /* L_CRYPTODEV_H */