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,
51 CRYPTO_ALGORITHM_ALL
, /* Keep updated - see below */
54 #define CRYPTO_ALGORITHM_MAX (CRYPTO_ALGORITHM_ALL - 1)
56 /* Values for ciphers */
57 #define DES_BLOCK_LEN 8
58 #define DES3_BLOCK_LEN 8
59 #define RIJNDAEL128_BLOCK_LEN 16
60 #define AES_BLOCK_LEN RIJNDAEL128_BLOCK_LEN
61 #define CAMELLIA_BLOCK_LEN 16
62 #define BLOWFISH_BLOCK_LEN 8
63 #define SKIPJACK_BLOCK_LEN 8
64 #define CAST128_BLOCK_LEN 8
66 /* the maximum of the above */
67 #define EALG_MAX_BLOCK_LEN 16
69 /* Values for hashes/MAC */
70 #define AALG_MAX_RESULT_LEN 64
72 /* maximum length of verbose alg names (depends on CRYPTO_MAX_ALG_NAME) */
73 #define CRYPTODEV_MAX_ALG_NAME 64
75 #define HASH_MAX_LEN 64
77 /* input of CIOCGSESSION */
79 /* Specify either cipher or mac
81 __u32 cipher
; /* cryptodev_crypto_op_t */
82 __u32 mac
; /* cryptodev_crypto_op_t */
89 __u32 ses
; /* session identifier */
92 struct session_info_op
{
93 __u32 ses
; /* session identifier */
95 /* verbose names for the requested ciphers */
97 char cra_name
[CRYPTODEV_MAX_ALG_NAME
];
98 char cra_driver_name
[CRYPTODEV_MAX_ALG_NAME
];
99 } cipher_info
, hash_info
;
101 __u16 alignmask
; /* alignment constraints */
104 #define COP_ENCRYPT 0
105 #define COP_DECRYPT 1
107 /* input of CIOCCRYPT */
109 __u32 ses
; /* session identifier */
110 __u16 op
; /* COP_ENCRYPT or COP_DECRYPT */
111 __u16 flags
; /* see COP_FLAG_* */
112 __u32 len
; /* length of source data */
113 __u8 __user
*src
; /* source data */
114 __u8 __user
*dst
; /* pointer to output data */
115 /* pointer to output data for hash/MAC operations */
117 /* initialization vector for encryption operations */
121 /* input of CIOCAUTHCRYPT */
122 struct crypt_auth_op
{
123 __u32 ses
; /* session identifier */
124 __u16 op
; /* COP_ENCRYPT or COP_DECRYPT */
125 __u16 flags
; /* see COP_FLAG_AEAD_* */
126 __u32 len
; /* length of source data */
127 __u32 auth_len
; /* length of auth data */
128 __u8 __user
*auth_src
; /* authenticated-only data */
130 /* The current implementation is more efficient if data are
131 * encrypted in-place (src==dst). */
132 __u8 __user
*src
; /* data to be encrypted and authenticated */
133 __u8 __user
*dst
; /* pointer to output data. Must have
134 * space for tag. For TLS this should be at least
135 * len + tag_size + block_size for padding */
137 __u8 __user
*tag
; /* where the tag will be copied to. TLS mode
138 * doesn't use that as tag is copied to dst.
139 * SRTP mode copies tag there. */
140 __u32 tag_len
; /* the length of the tag. Use zero for digest size or max tag. */
142 /* initialization vector for encryption operations */
147 /* In plain AEAD mode the following are required:
149 * iv : the initialization vector (12 bytes)
150 * auth_len: the length of the data to be authenticated
151 * auth_src: the data to be authenticated
152 * len : length of data to be encrypted
153 * src : the data to be encrypted
154 * dst : space to hold encrypted data. It must have
155 * at least a size of len + tag_size.
156 * tag_size: the size of the desired authentication tag or zero to use
157 * the maximum tag output.
159 * Note tag isn't being used because the Linux AEAD interface
160 * copies the tag just after data.
163 /* In TLS mode (used for CBC ciphers that required padding)
164 * the following are required:
165 * flags : COP_FLAG_AEAD_TLS_TYPE
166 * iv : the initialization vector
167 * auth_len: the length of the data to be authenticated only
168 * len : length of data to be encrypted
169 * auth_src: the data to be authenticated
170 * src : the data to be encrypted
171 * dst : space to hold encrypted data (preferably in-place). It must have
172 * at least a size of len + tag_size + blocksize.
173 * tag_size: the size of the desired authentication tag or zero to use
174 * the default mac output.
176 * Note that the padding used is the minimum padding.
179 /* In SRTP mode the following are required:
180 * flags : COP_FLAG_AEAD_SRTP_TYPE
181 * iv : the initialization vector
182 * auth_len: the length of the data to be authenticated. This must
183 * include the SRTP header + SRTP payload (data to be encrypted) + rest
185 * len : length of data to be encrypted
186 * auth_src: pointer the data to be authenticated. Should point at the same buffer as src.
187 * src : pointer to the data to be encrypted.
188 * dst : This is mandatory to be the same as src (in-place only).
189 * tag_size: the size of the desired authentication tag or zero to use
190 * the default mac output.
191 * tag : Pointer to an address where the authentication tag will be copied.
195 /* struct crypt_op flags */
197 #define COP_FLAG_NONE (0 << 0) /* totally no flag */
198 #define COP_FLAG_UPDATE (1 << 0) /* multi-update hash mode */
199 #define COP_FLAG_FINAL (1 << 1) /* multi-update final hash mode */
200 #define COP_FLAG_WRITE_IV (1 << 2) /* update the IV during operation */
201 #define COP_FLAG_NO_ZC (1 << 3) /* do not zero-copy */
202 #define COP_FLAG_AEAD_TLS_TYPE (1 << 4) /* authenticate and encrypt using the
203 * TLS protocol rules */
204 #define COP_FLAG_AEAD_SRTP_TYPE (1 << 5) /* authenticate and encrypt using the
205 * SRTP protocol rules */
208 /* Stuff for bignum arithmetic and public key
209 * cryptography - not supported yet by linux
213 #define CRYPTO_ALG_FLAG_SUPPORTED 1
214 #define CRYPTO_ALG_FLAG_RNG_ENABLE 2
215 #define CRYPTO_ALG_FLAG_DSA_SHA 4
222 #define CRK_MAXPARAM 8
224 /* input of CIOCKEY */
226 __u32 crk_op
; /* cryptodev_crk_ot_t */
231 struct crparam crk_param
[CRK_MAXPARAM
];
234 enum cryptodev_crk_op_t
{
239 CRK_DH_COMPUTE_KEY
= 4,
243 #define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1)
245 /* features to be queried with CIOCASYMFEAT ioctl
247 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
248 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
249 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
250 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
251 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
254 /* ioctl's. Compatible with old linux cryptodev.h
256 #define CRIOGET _IOWR('c', 101, __u32)
257 #define CIOCGSESSION _IOWR('c', 102, struct session_op)
258 #define CIOCFSESSION _IOW('c', 103, __u32)
259 #define CIOCCRYPT _IOWR('c', 104, struct crypt_op)
260 #define CIOCKEY _IOWR('c', 105, struct crypt_kop)
261 #define CIOCASYMFEAT _IOR('c', 106, __u32)
262 #define CIOCGSESSINFO _IOWR('c', 107, struct session_info_op)
264 /* to indicate that CRIOGET is not required in linux
266 #define CRIOGET_NOT_NEEDED 1
268 /* additional ioctls for asynchronous operation */
269 #define CIOCASYNCCRYPT _IOW('c', 107, struct crypt_op)
270 #define CIOCASYNCFETCH _IOR('c', 108, struct crypt_op)
272 /* additional ioctls for AEAD */
273 #define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op)
275 #endif /* L_CRYPTODEV_H */