Corrected copyright statements and other minir fixes.
[cryptodev-linux.git] / cryptodev.h
blobfcdd00628843fd38688c89f7896acc8a9404ea2a
1 /*
2 * Driver for /dev/crypto device (aka CryptoDev)
4 * Copyright (c) 2004 Michal Ludvig <mludvig@logix.net.nz>, SuSE Labs
6 * Structures and ioctl command names were taken from
7 * OpenBSD to preserve compatibility with their API.
9 */
11 #ifndef _CRYPTODEV_H
12 #define _CRYPTODEV_H
14 #ifndef __KERNEL__
15 #include <inttypes.h>
16 #endif
18 #define CRYPTODEV_MINOR MISC_DYNAMIC_MINOR
21 #define CRYPTO_FLAG_HMAC 0x0010
22 #define CRYPTO_FLAG_MASK 0x00FF
24 enum {
25 CRYPTO_DES_CBC=1,
26 CRYPTO_3DES_CBC,
27 CRYPTO_BLF_CBC,
28 CRYPTO_AES_CBC,
29 CRYPTO_RIJNDAEL128_CBC=CRYPTO_AES_CBC,
30 CRYPTO_CAMELLIA_CBC,
31 /* unsupported from here */
32 CRYPTO_CAST_CBC,
33 CRYPTO_SKIPJACK_CBC,
35 CRYPTO_MD5_KPDK=200,
36 CRYPTO_SHA1_KPDK,
37 CRYPTO_MD5,
38 CRYPTO_RIPEMD160,
39 CRYPTO_SHA1,
40 CRYPTO_SHA2_256,
41 CRYPTO_SHA2_384,
42 CRYPTO_SHA2_512,
43 CRYPTO_MD5_HMAC,
44 CRYPTO_RIPEMD160_HMAC,
45 CRYPTO_SHA1_HMAC,
46 CRYPTO_SHA2_256_HMAC,
47 CRYPTO_SHA2_384_HMAC,
48 CRYPTO_SHA2_512_HMAC,
49 CRYPTO_ALGORITHM_MAX
52 #define CRYPTO_CIPHER_MAX_KEY_LEN 64
53 #define CRYPTO_HMAC_MAX_KEY_LEN 512
55 #define HASH_MAX_LEN 64
57 struct crparam;
58 struct crypt_kop;
60 /* ioctl parameter to create a session */
61 struct session_op {
62 uint16_t cipher; /* e.g. CRYPTO_DES_CBC */
63 uint16_t mac; /* e.g. CRYPTO_MD5_HMAC */
64 uint8_t *key;
65 size_t keylen; /* cipher key */
66 size_t mackeylen; /* mac key */
67 uint8_t *mackey;
69 /* Return values */
70 uint32_t ses; /* session ID */
73 /* ioctl parameter to request a crypt/decrypt operation against a session */
74 struct crypt_op {
75 uint32_t ses; /* from session_op->ses */
76 #define COP_DECRYPT 0
77 #define COP_ENCRYPT 1
78 uint32_t op; /* ie. COP_ENCRYPT */
79 uint32_t flags; /* unused */
81 size_t len;
82 void *src, *dst;
83 void *mac;
84 void *iv;
87 /* clone original filedescriptor */
88 #define CRIOGET _IOWR('c', 101, uint32_t)
90 /* create crypto session */
91 #define CIOCGSESSION _IOWR('c', 102, struct session_op)
93 /* finish crypto session */
94 #define CIOCFSESSION _IOW('c', 103, uint32_t)
96 /* request encryption/decryptions of a given buffer */
97 #define CIOCCRYPT _IOWR('c', 104, struct crypt_op)
99 /* ioctl()s for asym-crypto. Not yet supported. */
100 #define CIOCKEY _IOWR('c', 105, void *)
101 #define CIOCASYMFEAT _IOR('c', 106, uint32_t)
103 #endif /* _CRYPTODEV_H */
105 /* unused structures */
106 struct crparam {
107 caddr_t crp_p;
108 uint32_t crp_nbits;
111 #define CRK_MAXPARAM 8
113 struct crypt_kop {
114 uint32_t crk_op; /* ie. CRK_MOD_EXP or other */
115 uint32_t crk_status; /* return status */
116 uint16_t crk_iparams; /* # of input parameters */
117 uint16_t crk_oparams; /* # of output parameters */
118 uint32_t crk_crid; /* NB: only used by CIOCKEY2 (rw) */
119 struct crparam crk_param[CRK_MAXPARAM];
122 /* Definitions from openbsd's cryptodev */
124 #define DES_BLOCK_LEN 8
125 #define DES3_BLOCK_LEN 8
126 #define BLOWFISH_BLOCK_LEN 8
127 #define SKIPJACK_BLOCK_LEN 8
128 #define CAST128_BLOCK_LEN 8
129 #define RIJNDAEL128_BLOCK_LEN 16
130 #define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN
131 #define EALG_MAX_BLOCK_LEN AES_BLOCK_LEN /* Keep this updated */
133 #define NULL_HASH_LEN 16
134 #define MD5_HASH_LEN 16
135 #define SHA1_HASH_LEN 20
136 #define RIPEMD160_HASH_LEN 20
137 #define SHA2_256_HASH_LEN 32
138 #define SHA2_384_HASH_LEN 48
139 #define SHA2_512_HASH_LEN 64
140 #define MD5_KPDK_HASH_LEN 16
141 #define SHA1_KPDK_HASH_LEN 20
143 #define CRK_ALGORITM_MIN 0
144 #define CRK_MOD_EXP 0
145 #define CRK_MOD_EXP_CRT 1
146 #define CRK_DSA_SIGN 2
147 #define CRK_DSA_VERIFY 3
148 #define CRK_DH_COMPUTE_KEY 4
149 #define CRK_ALGORITHM_MAX 4 /* Keep updated - see below */
151 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
152 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
153 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
154 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
155 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)