7fb9c7dcdae5e38f5a7f6e79d755ba1754b2deca
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 */
8 #include <linux/types.h>
13 /* API extensions for linux */
14 #define CRYPTO_HMAC_MAX_KEY_LEN 512
15 #define CRYPTO_CIPHER_MAX_KEY_LEN 64
17 /* All the supported algorithms
19 enum cryptodev_crypto_op_t
{
24 CRYPTO_SKIPJACK_CBC
= 5,
27 CRYPTO_RIPEMD160_HMAC
= 8,
29 CRYPTO_SHA1_KPDK
= 10,
30 CRYPTO_RIJNDAEL128_CBC
= 11,
31 CRYPTO_AES_CBC
= CRYPTO_RIJNDAEL128_CBC
,
35 CRYPTO_DEFLATE_COMP
= 15,
38 CRYPTO_SHA2_256_HMAC
= 18,
39 CRYPTO_SHA2_384_HMAC
= 19,
40 CRYPTO_SHA2_512_HMAC
= 20,
46 CRYPTO_CAMELLIA_CBC
= 101,
53 CRYPTO_ALGORITHM_ALL
, /* Keep updated - see below */
56 #define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1)
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
68 /* the maximum of the above */
69 #define EALG_MAX_BLOCK_LEN 16
71 /* Values for hashes/MAC */
72 #define AALG_MAX_RESULT_LEN 64
74 /* maximum length of verbose alg names (depends on CRYPTO_MAX_ALG_NAME) */
75 #define CRYPTODEV_MAX_ALG_NAME 64
77 #define HASH_MAX_LEN 64
79 /* input of CIOCGSESSION */
81 /* Specify either cipher or mac
83 __u32 cipher
; /* cryptodev_crypto_op_t */
84 __u32 mac
; /* cryptodev_crypto_op_t */
91 __u32 ses
; /* session identifier */
94 struct session_info_op
{
95 __u32 ses
; /* session identifier */
97 /* verbose names for the requested ciphers */
99 char cra_name
[CRYPTODEV_MAX_ALG_NAME
];
100 char cra_driver_name
[CRYPTODEV_MAX_ALG_NAME
];
101 } cipher_info
, hash_info
;
103 __u16 alignmask
; /* alignment constraints */
104 __u32 flags
; /* SIOP_FLAGS_* */
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).
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.
114 #define SIOP_FLAG_KERNEL_DRIVER_ONLY 1
116 #define COP_ENCRYPT 0
117 #define COP_DECRYPT 1
119 /* input of CIOCCRYPT */
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 */
129 /* initialization vector for encryption operations */
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 */
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 */
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. */
154 /* initialization vector for encryption operations */
159 /* In plain AEAD mode the following are required:
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.
171 * Note tag isn't being used because the Linux AEAD interface
172 * copies the tag just after data.
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.
188 * Note that the padding used is the minimum padding.
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
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.
207 /* struct crypt_op flags */
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 */
223 /* Stuff for bignum arithmetic and public key
224 * cryptography - not supported yet by linux
228 #define CRYPTO_ALG_FLAG_SUPPORTED 1
229 #define CRYPTO_ALG_FLAG_RNG_ENABLE 2
230 #define CRYPTO_ALG_FLAG_DSA_SHA 4
237 #define CRK_MAXPARAM 8
239 /* input of CIOCKEY */
241 __u32 crk_op
; /* cryptodev_crk_op_t */
246 struct crparam crk_param
[CRK_MAXPARAM
];
249 enum cryptodev_crk_op_t
{
254 CRK_DH_COMPUTE_KEY
= 4,
258 #define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1)
260 /* features to be queried with CIOCASYMFEAT ioctl
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)
269 /* ioctl's. Compatible with old linux cryptodev.h
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)
279 /* to indicate that CRIOGET is not required in linux
281 #define CRIOGET_NOT_NEEDED 1
283 /* additional ioctls for AEAD */
284 #define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op)
286 /* additional ioctls for asynchronous operation.
287 * These are conditionally enabled since version 1.6.
289 #define CIOCASYNCCRYPT _IOW('c', 110, struct crypt_op)
290 #define CIOCASYNCFETCH _IOR('c', 111, struct crypt_op)
292 #endif /* L_CRYPTODEV_H */