Linux 2.6.22-rc3
[linux-2.6/next.git] / include / asm-cris / arch-v32 / cryptocop.h
blobdfa1f66fb987310726fa1ffbcc5e9edac324b223
1 /*
2 * The device /dev/cryptocop is accessible using this driver using
3 * CRYPTOCOP_MAJOR (254) and minor number 0.
4 */
6 #ifndef CRYPTOCOP_H
7 #define CRYPTOCOP_H
9 #include <linux/uio.h>
12 #define CRYPTOCOP_SESSION_ID_NONE (0)
14 typedef unsigned long long int cryptocop_session_id;
16 /* cryptocop ioctls */
17 #define ETRAXCRYPTOCOP_IOCTYPE (250)
19 #define CRYPTOCOP_IO_CREATE_SESSION _IOWR(ETRAXCRYPTOCOP_IOCTYPE, 1, struct strcop_session_op)
20 #define CRYPTOCOP_IO_CLOSE_SESSION _IOW(ETRAXCRYPTOCOP_IOCTYPE, 2, struct strcop_session_op)
21 #define CRYPTOCOP_IO_PROCESS_OP _IOWR(ETRAXCRYPTOCOP_IOCTYPE, 3, struct strcop_crypto_op)
22 #define CRYPTOCOP_IO_MAXNR (3)
24 typedef enum {
25 cryptocop_cipher_des = 0,
26 cryptocop_cipher_3des = 1,
27 cryptocop_cipher_aes = 2,
28 cryptocop_cipher_m2m = 3, /* mem2mem is essentially a NULL cipher with blocklength=1 */
29 cryptocop_cipher_none
30 } cryptocop_cipher_type;
32 typedef enum {
33 cryptocop_digest_sha1 = 0,
34 cryptocop_digest_md5 = 1,
35 cryptocop_digest_none
36 } cryptocop_digest_type;
38 typedef enum {
39 cryptocop_csum_le = 0,
40 cryptocop_csum_be = 1,
41 cryptocop_csum_none
42 } cryptocop_csum_type;
44 typedef enum {
45 cryptocop_cipher_mode_ecb = 0,
46 cryptocop_cipher_mode_cbc,
47 cryptocop_cipher_mode_none
48 } cryptocop_cipher_mode;
50 typedef enum {
51 cryptocop_3des_eee = 0,
52 cryptocop_3des_eed = 1,
53 cryptocop_3des_ede = 2,
54 cryptocop_3des_edd = 3,
55 cryptocop_3des_dee = 4,
56 cryptocop_3des_ded = 5,
57 cryptocop_3des_dde = 6,
58 cryptocop_3des_ddd = 7
59 } cryptocop_3des_mode;
61 /* Usermode accessible (ioctl) operations. */
62 struct strcop_session_op{
63 cryptocop_session_id ses_id;
65 cryptocop_cipher_type cipher; /* AES, DES, 3DES, m2m, none */
67 cryptocop_cipher_mode cmode; /* ECB, CBC, none */
68 cryptocop_3des_mode des3_mode;
70 cryptocop_digest_type digest; /* MD5, SHA1, none */
72 cryptocop_csum_type csum; /* BE, LE, none */
74 unsigned char *key;
75 size_t keylen;
78 #define CRYPTOCOP_CSUM_LENGTH (2)
79 #define CRYPTOCOP_MAX_DIGEST_LENGTH (20) /* SHA-1 20, MD5 16 */
80 #define CRYPTOCOP_MAX_IV_LENGTH (16) /* (3)DES==8, AES == 16 */
81 #define CRYPTOCOP_MAX_KEY_LENGTH (32)
83 struct strcop_crypto_op{
84 cryptocop_session_id ses_id;
86 /* Indata. */
87 unsigned char *indata;
88 size_t inlen; /* Total indata length. */
90 /* Cipher configuration. */
91 unsigned char do_cipher:1;
92 unsigned char decrypt:1; /* 1 == decrypt, 0 == encrypt */
93 unsigned char cipher_explicit:1;
94 size_t cipher_start;
95 size_t cipher_len;
96 /* cipher_iv is used if do_cipher and cipher_explicit and the cipher
97 mode is CBC. The length is controlled by the type of cipher,
98 e.g. DES/3DES 8 octets and AES 16 octets. */
99 unsigned char cipher_iv[CRYPTOCOP_MAX_IV_LENGTH];
100 /* Outdata. */
101 unsigned char *cipher_outdata;
102 size_t cipher_outlen;
104 /* digest configuration. */
105 unsigned char do_digest:1;
106 size_t digest_start;
107 size_t digest_len;
108 /* Outdata. The actual length is determined by the type of the digest. */
109 unsigned char digest[CRYPTOCOP_MAX_DIGEST_LENGTH];
111 /* Checksum configuration. */
112 unsigned char do_csum:1;
113 size_t csum_start;
114 size_t csum_len;
115 /* Outdata. */
116 unsigned char csum[CRYPTOCOP_CSUM_LENGTH];
121 #ifdef __KERNEL__
123 /********** The API to use from inside the kernel. ************/
125 #include <asm/arch/hwregs/dma.h>
127 typedef enum {
128 cryptocop_alg_csum = 0,
129 cryptocop_alg_mem2mem,
130 cryptocop_alg_md5,
131 cryptocop_alg_sha1,
132 cryptocop_alg_des,
133 cryptocop_alg_3des,
134 cryptocop_alg_aes,
135 cryptocop_no_alg,
136 } cryptocop_algorithm;
138 typedef u8 cryptocop_tfrm_id;
141 struct cryptocop_operation;
143 typedef void (cryptocop_callback)(struct cryptocop_operation*, void*);
145 struct cryptocop_transform_init {
146 cryptocop_algorithm alg;
147 /* Keydata for ciphers. */
148 unsigned char key[CRYPTOCOP_MAX_KEY_LENGTH];
149 unsigned int keylen;
150 cryptocop_cipher_mode cipher_mode;
151 cryptocop_3des_mode tdes_mode;
152 cryptocop_csum_type csum_mode; /* cryptocop_csum_none is not allowed when alg==cryptocop_alg_csum */
154 cryptocop_tfrm_id tid; /* Locally unique in session; assigned by user, checked by driver. */
155 struct cryptocop_transform_init *next;
159 typedef enum {
160 cryptocop_source_dma = 0,
161 cryptocop_source_des,
162 cryptocop_source_3des,
163 cryptocop_source_aes,
164 cryptocop_source_md5,
165 cryptocop_source_sha1,
166 cryptocop_source_csum,
167 cryptocop_source_none,
168 } cryptocop_source;
171 struct cryptocop_desc_cfg {
172 cryptocop_tfrm_id tid;
173 cryptocop_source src;
174 unsigned int last:1; /* Last use of this transform in the operation. Will push outdata when encountered. */
175 struct cryptocop_desc_cfg *next;
178 struct cryptocop_desc {
179 size_t length;
180 struct cryptocop_desc_cfg *cfg;
181 struct cryptocop_desc *next;
185 /* Flags for cryptocop_tfrm_cfg */
186 #define CRYPTOCOP_NO_FLAG (0x00)
187 #define CRYPTOCOP_ENCRYPT (0x01)
188 #define CRYPTOCOP_DECRYPT (0x02)
189 #define CRYPTOCOP_EXPLICIT_IV (0x04)
191 struct cryptocop_tfrm_cfg {
192 cryptocop_tfrm_id tid;
194 unsigned int flags; /* DECRYPT, ENCRYPT, EXPLICIT_IV */
196 /* CBC initialisation vector for cihers. */
197 u8 iv[CRYPTOCOP_MAX_IV_LENGTH];
199 /* The position in output where to write the transform output. The order
200 in which the driver writes the output is unspecified, hence if several
201 transforms write on the same positions in the output the result is
202 unspecified. */
203 size_t inject_ix;
205 struct cryptocop_tfrm_cfg *next;
210 struct cryptocop_dma_list_operation{
211 /* The consumer can provide DMA lists to send to the co-processor. 'use_dmalists' in
212 struct cryptocop_operation must be set for the driver to use them. outlist,
213 out_data_buf, inlist and in_data_buf must all be physical addresses since they will
214 be loaded to DMA . */
215 dma_descr_data *outlist; /* Out from memory to the co-processor. */
216 char *out_data_buf;
217 dma_descr_data *inlist; /* In from the co-processor to memory. */
218 char *in_data_buf;
220 cryptocop_3des_mode tdes_mode;
221 cryptocop_csum_type csum_mode;
225 struct cryptocop_tfrm_operation{
226 /* Operation configuration, if not 'use_dmalists' is set. */
227 struct cryptocop_tfrm_cfg *tfrm_cfg;
228 struct cryptocop_desc *desc;
230 struct iovec *indata;
231 size_t incount;
232 size_t inlen; /* Total inlength. */
234 struct iovec *outdata;
235 size_t outcount;
236 size_t outlen; /* Total outlength. */
240 struct cryptocop_operation {
241 cryptocop_callback *cb;
242 void *cb_data;
244 cryptocop_session_id sid;
246 /* The status of the operation when returned to consumer. */
247 int operation_status; /* 0, -EAGAIN */
249 /* Flags */
250 unsigned int use_dmalists:1; /* Use outlist and inlist instead of the desc/tfrm_cfg configuration. */
251 unsigned int in_interrupt:1; /* Set if inserting job from interrupt context. */
252 unsigned int fast_callback:1; /* Set if fast callback wanted, i.e. from interrupt context. */
254 union{
255 struct cryptocop_dma_list_operation list_op;
256 struct cryptocop_tfrm_operation tfrm_op;
261 int cryptocop_new_session(cryptocop_session_id *sid, struct cryptocop_transform_init *tinit, int alloc_flag);
262 int cryptocop_free_session(cryptocop_session_id sid);
264 int cryptocop_job_queue_insert_csum(struct cryptocop_operation *operation);
266 int cryptocop_job_queue_insert_crypto(struct cryptocop_operation *operation);
268 int cryptocop_job_queue_insert_user_job(struct cryptocop_operation *operation);
270 #endif /* __KERNEL__ */
272 #endif /* CRYPTOCOP_H */