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 __u32 tag_len
; /* the length of the tag. Use zero for digest size. */
129 __u8 __user
*auth_src
; /* authenticated-only data */
131 /* The current implementation is more efficient if data are
132 * encrypted in-place (src==dst). */
133 __u8 __user
*src
; /* data to be encrypted and authenticated */
134 __u8 __user
*dst
; /* pointer to output data. Must have
135 * space for tag. For TLS this should be at least
136 * len + tag_size + block_size for padding */
138 __u8 __user
*tag
; /* where the tag will be copied to. TLS mode
139 * doesn't use that as tag is copied to dst.
140 * SRTP mode copies tag there. */
142 /* initialization vector for encryption operations */
147 /* In TLS mode the following are required:
148 * flags : COP_FLAG_AEAD_TLS_TYPE
149 * iv : the initialization vector
150 * auth_len: the length of the data to be authenticated only
151 * len : length of data to be encrypted
152 * auth_src: the data to be authenticated
153 * src : the data to be encrypted
154 * dst : space to hold encrypted data (preferably in-place). It must have
155 * at least a size of len + tag_size + blocksize.
156 * tag_size: the size of the desired authentication tag or zero to use
157 * the default mac output.
160 /* In SRTP mode the following are required:
161 * flags : COP_FLAG_AEAD_SRTP_TYPE
162 * iv : the initialization vector
163 * auth_len: the length of the data to be authenticated. This must
164 * include the SRTP header + SRTP payload (data to be encrypted) + rest
166 * len : length of data to be encrypted
167 * auth_src: pointer the data to be authenticated. Should point at the same buffer as src.
168 * src : pointer to the data to be encrypted.
169 * dst : This is mandatory to be the same as src (in-place only).
170 * tag_size: the size of the desired authentication tag or zero to use
171 * the default mac output.
172 * tag : Pointer to an address where the authentication tag will be copied.
176 /* struct crypt_op flags */
178 #define COP_FLAG_NONE (0 << 0) /* totally no flag */
179 #define COP_FLAG_UPDATE (1 << 0) /* multi-update hash mode */
180 #define COP_FLAG_FINAL (1 << 1) /* multi-update final hash mode */
181 #define COP_FLAG_WRITE_IV (1 << 2) /* update the IV during operation */
182 #define COP_FLAG_NO_ZC (1 << 3) /* do not zero-copy */
183 #define COP_FLAG_AEAD_TLS_TYPE (1 << 4) /* authenticate and encrypt using the
184 * TLS protocol rules */
185 #define COP_FLAG_AEAD_SRTP_TYPE (1 << 5) /* authenticate and encrypt using the
186 * SRTP protocol rules */
189 /* Stuff for bignum arithmetic and public key
190 * cryptography - not supported yet by linux
194 #define CRYPTO_ALG_FLAG_SUPPORTED 1
195 #define CRYPTO_ALG_FLAG_RNG_ENABLE 2
196 #define CRYPTO_ALG_FLAG_DSA_SHA 4
203 #define CRK_MAXPARAM 8
205 /* input of CIOCKEY */
207 __u32 crk_op
; /* cryptodev_crk_ot_t */
212 struct crparam crk_param
[CRK_MAXPARAM
];
215 enum cryptodev_crk_op_t
{
220 CRK_DH_COMPUTE_KEY
= 4,
224 #define CRK_ALGORITHM_MAX (CRK_ALGORITHM_ALL-1)
226 /* features to be queried with CIOCASYMFEAT ioctl
228 #define CRF_MOD_EXP (1 << CRK_MOD_EXP)
229 #define CRF_MOD_EXP_CRT (1 << CRK_MOD_EXP_CRT)
230 #define CRF_DSA_SIGN (1 << CRK_DSA_SIGN)
231 #define CRF_DSA_VERIFY (1 << CRK_DSA_VERIFY)
232 #define CRF_DH_COMPUTE_KEY (1 << CRK_DH_COMPUTE_KEY)
235 /* ioctl's. Compatible with old linux cryptodev.h
237 #define CRIOGET _IOWR('c', 101, __u32)
238 #define CIOCGSESSION _IOWR('c', 102, struct session_op)
239 #define CIOCFSESSION _IOW('c', 103, __u32)
240 #define CIOCCRYPT _IOWR('c', 104, struct crypt_op)
241 #define CIOCKEY _IOWR('c', 105, struct crypt_kop)
242 #define CIOCASYMFEAT _IOR('c', 106, __u32)
243 #define CIOCGSESSINFO _IOWR('c', 107, struct session_info_op)
245 /* to indicate that CRIOGET is not required in linux
247 #define CRIOGET_NOT_NEEDED 1
249 /* additional ioctls for asynchronous operation */
250 #define CIOCASYNCCRYPT _IOW('c', 107, struct crypt_op)
251 #define CIOCASYNCFETCH _IOR('c', 108, struct crypt_op)
253 /* additional ioctls for AEAD */
254 #define CIOCAUTHCRYPT _IOWR('c', 109, struct crypt_auth_op)
256 #endif /* L_CRYPTODEV_H */