1/*
2 * The device /dev/cryptocop is accessible using this driver using
3 * CRYPTOCOP_MAJOR (254) and minor number 0.
4 */
5
6#ifndef _UAPICRYPTOCOP_H
7#define _UAPICRYPTOCOP_H
8
9#include <linux/uio.h>
10
11
12#define CRYPTOCOP_SESSION_ID_NONE (0)
13
14typedef unsigned long long int cryptocop_session_id;
15
16/* cryptocop ioctls */
17#define ETRAXCRYPTOCOP_IOCTYPE         (250)
18
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)
23
24typedef 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;
31
32typedef enum {
33	cryptocop_digest_sha1 = 0,
34	cryptocop_digest_md5 = 1,
35	cryptocop_digest_none
36} cryptocop_digest_type;
37
38typedef enum {
39	cryptocop_csum_le = 0,
40	cryptocop_csum_be = 1,
41	cryptocop_csum_none
42} cryptocop_csum_type;
43
44typedef enum {
45	cryptocop_cipher_mode_ecb = 0,
46	cryptocop_cipher_mode_cbc,
47	cryptocop_cipher_mode_none
48} cryptocop_cipher_mode;
49
50typedef 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;
60
61/* Usermode accessible (ioctl) operations. */
62struct strcop_session_op{
63	cryptocop_session_id    ses_id;
64
65	cryptocop_cipher_type   cipher; /* AES, DES, 3DES, m2m, none */
66
67	cryptocop_cipher_mode   cmode; /* ECB, CBC, none */
68	cryptocop_3des_mode     des3_mode;
69
70	cryptocop_digest_type   digest; /* MD5, SHA1, none */
71
72	cryptocop_csum_type     csum;   /* BE, LE, none */
73
74	unsigned char           *key;
75	size_t                  keylen;
76};
77
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)
82
83struct strcop_crypto_op{
84	cryptocop_session_id ses_id;
85
86	/* Indata. */
87	unsigned char            *indata;
88	size_t                   inlen; /* Total indata length. */
89
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;
103
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];
110
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];
117};
118
119
120
121
122#endif /* _UAPICRYPTOCOP_H */
123