1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #ifndef _CRYPTO_CRYPTO_H_
53 #define _CRYPTO_CRYPTO_H_
54
55 #include <sys/ioccom.h>
56
57
58 #define CRYPTO_DRIVERS_INITIAL 4
59 #define CRYPTO_SW_SESSIONS 32
60
61
62 #define HMAC_BLOCK_LEN 64
63 #define HMAC_IPAD_VAL 0x36
64 #define HMAC_OPAD_VAL 0x5C
65
66
67 #define DES_BLOCK_LEN 8
68 #define DES3_BLOCK_LEN 8
69 #define BLOWFISH_BLOCK_LEN 8
70 #define SKIPJACK_BLOCK_LEN 8
71 #define CAST128_BLOCK_LEN 8
72 #define RIJNDAEL128_BLOCK_LEN 16
73 #define EALG_MAX_BLOCK_LEN 16
74
75
76 #define AALG_MAX_RESULT_LEN 64
77
78 #define CRYPTO_DES_CBC 1
79 #define CRYPTO_3DES_CBC 2
80 #define CRYPTO_BLF_CBC 3
81 #define CRYPTO_CAST_CBC 4
82 #define CRYPTO_SKIPJACK_CBC 5
83 #define CRYPTO_MD5_HMAC 6
84 #define CRYPTO_SHA1_HMAC 7
85 #define CRYPTO_RIPEMD160_HMAC 8
86 #define CRYPTO_MD5_KPDK 9
87 #define CRYPTO_SHA1_KPDK 10
88 #define CRYPTO_RIJNDAEL128_CBC 11
89 #define CRYPTO_AES_CBC 11
90 #define CRYPTO_ARC4 12
91 #define CRYPTO_MD5 13
92 #define CRYPTO_SHA1 14
93 #define CRYPTO_DEFLATE_COMP 15
94 #define CRYPTO_NULL 16
95 #define CRYPTO_LZS_COMP 17
96 #define CRYPTO_SHA2_256_HMAC 18
97 #define CRYPTO_SHA2_384_HMAC 19
98 #define CRYPTO_SHA2_512_HMAC 20
99 #define CRYPTO_AES_CTR 21
100 #define CRYPTO_ALGORITHM_MAX 21
101
102 #define CRYPTO_ALGORITHM_ALL (CRYPTO_ALGORITHM_MAX + 1)
103
104
105 #define CRYPTO_ALG_FLAG_SUPPORTED 0x01
106 #define CRYPTO_ALG_FLAG_RNG_ENABLE 0x02
107 #define CRYPTO_ALG_FLAG_DSA_SHA 0x04
108
109
110 struct cryptoini {
111 int cri_alg;
112 int cri_klen;
113 int cri_rnd;
114 caddr_t cri_key;
115 u_int8_t cri_iv[EALG_MAX_BLOCK_LEN];
116 struct cryptoini *cri_next;
117 };
118
119
120 struct cryptodesc {
121 int crd_skip;
122 int crd_len;
123 int crd_inject;
124 int crd_flags;
125
126 #define CRD_F_ENCRYPT 0x01
127 #define CRD_F_IV_PRESENT 0x02
128
129 #define CRD_F_IV_EXPLICIT 0x04
130 #define CRD_F_DSA_SHA_NEEDED 0x08
131 #define CRD_F_COMP 0x10
132
133 struct cryptoini CRD_INI;
134 #define crd_iv CRD_INI.cri_iv
135 #define crd_key CRD_INI.cri_key
136 #define crd_rnd CRD_INI.cri_rnd
137 #define crd_alg CRD_INI.cri_alg
138 #define crd_klen CRD_INI.cri_klen
139
140 struct cryptodesc *crd_next;
141 };
142
143
144 struct cryptop {
145 u_int64_t crp_sid;
146 int crp_ilen;
147 int crp_olen;
148 int crp_alloctype;
149
150 int crp_etype;
151
152
153
154
155
156
157
158
159
160 int crp_flags;
161
162 #define CRYPTO_F_IMBUF 0x0001
163 #define CRYPTO_F_IOV 0x0002
164 #define CRYPTO_F_REL 0x0004
165 #define CRYPTO_F_NOQUEUE 0x0008
166 #define CRYPTO_F_DONE 0x0010
167
168 void *crp_buf;
169 void *crp_opaque;
170 struct cryptodesc *crp_desc;
171
172 int (*crp_callback)(struct cryptop *);
173
174 struct cryptop *crp_next;
175 caddr_t crp_mac;
176 };
177
178 #define CRYPTO_BUF_IOV 0x1
179 #define CRYPTO_BUF_MBUF 0x2
180
181 #define CRYPTO_OP_DECRYPT 0x0
182 #define CRYPTO_OP_ENCRYPT 0x1
183
184
185 struct crparam {
186 caddr_t crp_p;
187 u_int crp_nbits;
188 };
189
190 #define CRK_MAXPARAM 8
191
192 struct crypt_kop {
193 u_int crk_op;
194 u_int crk_status;
195 u_short crk_iparams;
196 u_short crk_oparams;
197 u_int crk_pad1;
198 struct crparam crk_param[CRK_MAXPARAM];
199 };
200 #define CRK_MOD_EXP 0
201 #define CRK_MOD_EXP_CRT 1
202 #define CRK_DSA_SIGN 2
203 #define CRK_DSA_VERIFY 3
204 #define CRK_DH_COMPUTE_KEY 4
205 #define CRK_ALGORITHM_MAX 4
206
207 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
208 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
209 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
210 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
211 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
212
213 struct cryptkop {
214 u_int krp_op;
215 u_int krp_status;
216 u_short krp_iparams;
217 u_short krp_oparams;
218 u_int32_t krp_hid;
219 struct crparam krp_param[CRK_MAXPARAM];
220 int (*krp_callback)(struct cryptkop *);
221 struct cryptkop *krp_next;
222 };
223
224
225 struct cryptocap {
226 u_int64_t cc_operations;
227 u_int64_t cc_bytes;
228 u_int64_t cc_koperations;
229
230 u_int32_t cc_sessions;
231
232
233 int cc_alg[CRYPTO_ALGORITHM_MAX + 1];
234
235
236 int cc_kalg[CRK_ALGORITHM_MAX + 1];
237
238 int cc_queued;
239
240 u_int8_t cc_flags;
241 #define CRYPTOCAP_F_CLEANUP 0x01
242 #define CRYPTOCAP_F_SOFTWARE 0x02
243 #define CRYPTOCAP_F_ENCRYPT_MAC 0x04
244 #define CRYPTOCAP_F_MAC_ENCRYPT 0x08
245
246 int (*cc_newsession) (u_int32_t *, struct cryptoini *);
247 int (*cc_process) (struct cryptop *);
248 int (*cc_freesession) (u_int64_t);
249 int (*cc_kprocess) (struct cryptkop *);
250 };
251
252
253
254
255 struct session_op {
256 u_int32_t cipher;
257 u_int32_t mac;
258
259 u_int32_t keylen;
260 caddr_t key;
261 int mackeylen;
262 caddr_t mackey;
263
264 u_int32_t ses;
265 };
266
267
268
269
270 struct crypt_op {
271 u_int32_t ses;
272 u_int16_t op;
273 #define COP_ENCRYPT 1
274 #define COP_DECRYPT 2
275 u_int16_t flags;
276
277 u_int len;
278 caddr_t src, dst;
279 caddr_t mac;
280 caddr_t iv;
281 };
282
283 #define CRYPTO_MAX_MAC_LEN 20
284
285
286
287
288
289 #define CRIOGET _IOWR('c', 100, u_int32_t)
290
291
292 #define CIOCGSESSION _IOWR('c', 101, struct session_op)
293 #define CIOCFSESSION _IOW('c', 102, u_int32_t)
294 #define CIOCCRYPT _IOWR('c', 103, struct crypt_op)
295 #define CIOCKEY _IOWR('c', 104, struct crypt_kop)
296
297 #define CIOCASYMFEAT _IOR('c', 105, u_int32_t)
298
299 #ifdef _KERNEL
300 int crypto_newsession(u_int64_t *, struct cryptoini *, int);
301 int crypto_freesession(u_int64_t);
302 int crypto_dispatch(struct cryptop *);
303 int crypto_kdispatch(struct cryptkop *);
304 int crypto_register(u_int32_t, int *,
305 int (*)(u_int32_t *, struct cryptoini *), int (*)(u_int64_t),
306 int (*)(struct cryptop *));
307 int crypto_kregister(u_int32_t, int *, int (*)(struct cryptkop *));
308 int crypto_unregister(u_int32_t, int);
309 int32_t crypto_get_driverid(u_int8_t);
310 void crypto_thread(void);
311 int crypto_invoke(struct cryptop *);
312 int crypto_kinvoke(struct cryptkop *);
313 void crypto_done(struct cryptop *);
314 void crypto_kdone(struct cryptkop *);
315 int crypto_getfeat(int *);
316
317 void cuio_copydata(struct uio *, int, int, caddr_t);
318 void cuio_copyback(struct uio *, int, int, const void *);
319 int cuio_getptr(struct uio *, int, int *);
320 int cuio_apply(struct uio *, int, int,
321 int (*f)(caddr_t, caddr_t, unsigned int), caddr_t);
322
323 struct cryptop *crypto_getreq(int);
324 void crypto_freereq(struct cryptop *);
325 #endif
326 #endif