Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / standard-headers / linux / virtio_crypto.h
blob68066dafb6dd73d4220b41b65260176898812d82
1 #ifndef _VIRTIO_CRYPTO_H
2 #define _VIRTIO_CRYPTO_H
3 /* This header is BSD licensed so anyone can use the definitions to implement
4 * compatible drivers/servers.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of IBM nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
30 #include "standard-headers/linux/types.h"
31 #include "standard-headers/linux/virtio_types.h"
32 #include "standard-headers/linux/virtio_ids.h"
33 #include "standard-headers/linux/virtio_config.h"
36 #define VIRTIO_CRYPTO_SERVICE_CIPHER 0
37 #define VIRTIO_CRYPTO_SERVICE_HASH 1
38 #define VIRTIO_CRYPTO_SERVICE_MAC 2
39 #define VIRTIO_CRYPTO_SERVICE_AEAD 3
40 #define VIRTIO_CRYPTO_SERVICE_AKCIPHER 4
42 #define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op))
44 struct virtio_crypto_ctrl_header {
45 #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \
46 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02)
47 #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \
48 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03)
49 #define VIRTIO_CRYPTO_HASH_CREATE_SESSION \
50 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02)
51 #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \
52 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03)
53 #define VIRTIO_CRYPTO_MAC_CREATE_SESSION \
54 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02)
55 #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \
56 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03)
57 #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \
58 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02)
59 #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \
60 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03)
61 #define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \
62 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04)
63 #define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \
64 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05)
65 uint32_t opcode;
66 uint32_t algo;
67 uint32_t flag;
68 /* data virtqueue id */
69 uint32_t queue_id;
72 struct virtio_crypto_cipher_session_para {
73 #define VIRTIO_CRYPTO_NO_CIPHER 0
74 #define VIRTIO_CRYPTO_CIPHER_ARC4 1
75 #define VIRTIO_CRYPTO_CIPHER_AES_ECB 2
76 #define VIRTIO_CRYPTO_CIPHER_AES_CBC 3
77 #define VIRTIO_CRYPTO_CIPHER_AES_CTR 4
78 #define VIRTIO_CRYPTO_CIPHER_DES_ECB 5
79 #define VIRTIO_CRYPTO_CIPHER_DES_CBC 6
80 #define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7
81 #define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8
82 #define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9
83 #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10
84 #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11
85 #define VIRTIO_CRYPTO_CIPHER_AES_F8 12
86 #define VIRTIO_CRYPTO_CIPHER_AES_XTS 13
87 #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14
88 uint32_t algo;
89 /* length of key */
90 uint32_t keylen;
92 #define VIRTIO_CRYPTO_OP_ENCRYPT 1
93 #define VIRTIO_CRYPTO_OP_DECRYPT 2
94 /* encrypt or decrypt */
95 uint32_t op;
96 uint32_t padding;
99 struct virtio_crypto_session_input {
100 /* Device-writable part */
101 uint64_t session_id;
102 uint32_t status;
103 uint32_t padding;
106 struct virtio_crypto_cipher_session_req {
107 struct virtio_crypto_cipher_session_para para;
108 uint8_t padding[32];
111 struct virtio_crypto_hash_session_para {
112 #define VIRTIO_CRYPTO_NO_HASH 0
113 #define VIRTIO_CRYPTO_HASH_MD5 1
114 #define VIRTIO_CRYPTO_HASH_SHA1 2
115 #define VIRTIO_CRYPTO_HASH_SHA_224 3
116 #define VIRTIO_CRYPTO_HASH_SHA_256 4
117 #define VIRTIO_CRYPTO_HASH_SHA_384 5
118 #define VIRTIO_CRYPTO_HASH_SHA_512 6
119 #define VIRTIO_CRYPTO_HASH_SHA3_224 7
120 #define VIRTIO_CRYPTO_HASH_SHA3_256 8
121 #define VIRTIO_CRYPTO_HASH_SHA3_384 9
122 #define VIRTIO_CRYPTO_HASH_SHA3_512 10
123 #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11
124 #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12
125 uint32_t algo;
126 /* hash result length */
127 uint32_t hash_result_len;
128 uint8_t padding[8];
131 struct virtio_crypto_hash_create_session_req {
132 struct virtio_crypto_hash_session_para para;
133 uint8_t padding[40];
136 struct virtio_crypto_mac_session_para {
137 #define VIRTIO_CRYPTO_NO_MAC 0
138 #define VIRTIO_CRYPTO_MAC_HMAC_MD5 1
139 #define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2
140 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3
141 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4
142 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5
143 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6
144 #define VIRTIO_CRYPTO_MAC_CMAC_3DES 25
145 #define VIRTIO_CRYPTO_MAC_CMAC_AES 26
146 #define VIRTIO_CRYPTO_MAC_KASUMI_F9 27
147 #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28
148 #define VIRTIO_CRYPTO_MAC_GMAC_AES 41
149 #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42
150 #define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49
151 #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50
152 #define VIRTIO_CRYPTO_MAC_XCBC_AES 53
153 uint32_t algo;
154 /* hash result length */
155 uint32_t hash_result_len;
156 /* length of authenticated key */
157 uint32_t auth_key_len;
158 uint32_t padding;
161 struct virtio_crypto_mac_create_session_req {
162 struct virtio_crypto_mac_session_para para;
163 uint8_t padding[40];
166 struct virtio_crypto_aead_session_para {
167 #define VIRTIO_CRYPTO_NO_AEAD 0
168 #define VIRTIO_CRYPTO_AEAD_GCM 1
169 #define VIRTIO_CRYPTO_AEAD_CCM 2
170 #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3
171 uint32_t algo;
172 /* length of key */
173 uint32_t key_len;
174 /* hash result length */
175 uint32_t hash_result_len;
176 /* length of the additional authenticated data (AAD) in bytes */
177 uint32_t aad_len;
178 /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */
179 uint32_t op;
180 uint32_t padding;
183 struct virtio_crypto_aead_create_session_req {
184 struct virtio_crypto_aead_session_para para;
185 uint8_t padding[32];
188 struct virtio_crypto_rsa_session_para {
189 #define VIRTIO_CRYPTO_RSA_RAW_PADDING 0
190 #define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1
191 uint32_t padding_algo;
193 #define VIRTIO_CRYPTO_RSA_NO_HASH 0
194 #define VIRTIO_CRYPTO_RSA_MD2 1
195 #define VIRTIO_CRYPTO_RSA_MD3 2
196 #define VIRTIO_CRYPTO_RSA_MD4 3
197 #define VIRTIO_CRYPTO_RSA_MD5 4
198 #define VIRTIO_CRYPTO_RSA_SHA1 5
199 #define VIRTIO_CRYPTO_RSA_SHA256 6
200 #define VIRTIO_CRYPTO_RSA_SHA384 7
201 #define VIRTIO_CRYPTO_RSA_SHA512 8
202 #define VIRTIO_CRYPTO_RSA_SHA224 9
203 uint32_t hash_algo;
206 struct virtio_crypto_ecdsa_session_para {
207 #define VIRTIO_CRYPTO_CURVE_UNKNOWN 0
208 #define VIRTIO_CRYPTO_CURVE_NIST_P192 1
209 #define VIRTIO_CRYPTO_CURVE_NIST_P224 2
210 #define VIRTIO_CRYPTO_CURVE_NIST_P256 3
211 #define VIRTIO_CRYPTO_CURVE_NIST_P384 4
212 #define VIRTIO_CRYPTO_CURVE_NIST_P521 5
213 uint32_t curve_id;
214 uint32_t padding;
217 struct virtio_crypto_akcipher_session_para {
218 #define VIRTIO_CRYPTO_NO_AKCIPHER 0
219 #define VIRTIO_CRYPTO_AKCIPHER_RSA 1
220 #define VIRTIO_CRYPTO_AKCIPHER_DSA 2
221 #define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3
222 uint32_t algo;
224 #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC 1
225 #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2
226 uint32_t keytype;
227 uint32_t keylen;
229 union {
230 struct virtio_crypto_rsa_session_para rsa;
231 struct virtio_crypto_ecdsa_session_para ecdsa;
232 } u;
235 struct virtio_crypto_akcipher_create_session_req {
236 struct virtio_crypto_akcipher_session_para para;
237 uint8_t padding[36];
240 struct virtio_crypto_alg_chain_session_para {
241 #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1
242 #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2
243 uint32_t alg_chain_order;
244 /* Plain hash */
245 #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1
246 /* Authenticated hash (mac) */
247 #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2
248 /* Nested hash */
249 #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3
250 uint32_t hash_mode;
251 struct virtio_crypto_cipher_session_para cipher_param;
252 union {
253 struct virtio_crypto_hash_session_para hash_param;
254 struct virtio_crypto_mac_session_para mac_param;
255 uint8_t padding[16];
256 } u;
257 /* length of the additional authenticated data (AAD) in bytes */
258 uint32_t aad_len;
259 uint32_t padding;
262 struct virtio_crypto_alg_chain_session_req {
263 struct virtio_crypto_alg_chain_session_para para;
266 struct virtio_crypto_sym_create_session_req {
267 union {
268 struct virtio_crypto_cipher_session_req cipher;
269 struct virtio_crypto_alg_chain_session_req chain;
270 uint8_t padding[48];
271 } u;
273 /* Device-readable part */
275 /* No operation */
276 #define VIRTIO_CRYPTO_SYM_OP_NONE 0
277 /* Cipher only operation on the data */
278 #define VIRTIO_CRYPTO_SYM_OP_CIPHER 1
280 * Chain any cipher with any hash or mac operation. The order
281 * depends on the value of alg_chain_order param
283 #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2
284 uint32_t op_type;
285 uint32_t padding;
288 struct virtio_crypto_destroy_session_req {
289 /* Device-readable part */
290 uint64_t session_id;
291 uint8_t padding[48];
294 /* The request of the control virtqueue's packet */
295 struct virtio_crypto_op_ctrl_req {
296 struct virtio_crypto_ctrl_header header;
298 union {
299 struct virtio_crypto_sym_create_session_req
300 sym_create_session;
301 struct virtio_crypto_hash_create_session_req
302 hash_create_session;
303 struct virtio_crypto_mac_create_session_req
304 mac_create_session;
305 struct virtio_crypto_aead_create_session_req
306 aead_create_session;
307 struct virtio_crypto_akcipher_create_session_req
308 akcipher_create_session;
309 struct virtio_crypto_destroy_session_req
310 destroy_session;
311 uint8_t padding[56];
312 } u;
315 struct virtio_crypto_op_header {
316 #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \
317 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00)
318 #define VIRTIO_CRYPTO_CIPHER_DECRYPT \
319 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01)
320 #define VIRTIO_CRYPTO_HASH \
321 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00)
322 #define VIRTIO_CRYPTO_MAC \
323 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00)
324 #define VIRTIO_CRYPTO_AEAD_ENCRYPT \
325 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00)
326 #define VIRTIO_CRYPTO_AEAD_DECRYPT \
327 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01)
328 #define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \
329 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00)
330 #define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \
331 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01)
332 #define VIRTIO_CRYPTO_AKCIPHER_SIGN \
333 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02)
334 #define VIRTIO_CRYPTO_AKCIPHER_VERIFY \
335 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03)
336 uint32_t opcode;
337 /* algo should be service-specific algorithms */
338 uint32_t algo;
339 /* session_id should be service-specific algorithms */
340 uint64_t session_id;
341 /* control flag to control the request */
342 uint32_t flag;
343 uint32_t padding;
346 struct virtio_crypto_cipher_para {
348 * Byte Length of valid IV/Counter
350 * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for
351 * SNOW3G in UEA2 mode, this is the length of the IV (which
352 * must be the same as the block length of the cipher).
353 * For block ciphers in CTR mode, this is the length of the counter
354 * (which must be the same as the block length of the cipher).
355 * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007.
357 * The IV/Counter will be updated after every partial cryptographic
358 * operation.
360 uint32_t iv_len;
361 /* length of source data */
362 uint32_t src_data_len;
363 /* length of dst data */
364 uint32_t dst_data_len;
365 uint32_t padding;
368 struct virtio_crypto_hash_para {
369 /* length of source data */
370 uint32_t src_data_len;
371 /* hash result length */
372 uint32_t hash_result_len;
375 struct virtio_crypto_mac_para {
376 struct virtio_crypto_hash_para hash;
379 struct virtio_crypto_aead_para {
381 * Byte Length of valid IV data pointed to by the below iv_addr
382 * parameter.
384 * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which
385 * case iv_addr points to J0.
386 * For CCM mode, this is the length of the nonce, which can be in the
387 * range 7 to 13 inclusive.
389 uint32_t iv_len;
390 /* length of additional auth data */
391 uint32_t aad_len;
392 /* length of source data */
393 uint32_t src_data_len;
394 /* length of dst data */
395 uint32_t dst_data_len;
398 struct virtio_crypto_cipher_data_req {
399 /* Device-readable part */
400 struct virtio_crypto_cipher_para para;
401 uint8_t padding[24];
404 struct virtio_crypto_hash_data_req {
405 /* Device-readable part */
406 struct virtio_crypto_hash_para para;
407 uint8_t padding[40];
410 struct virtio_crypto_mac_data_req {
411 /* Device-readable part */
412 struct virtio_crypto_mac_para para;
413 uint8_t padding[40];
416 struct virtio_crypto_alg_chain_data_para {
417 uint32_t iv_len;
418 /* Length of source data */
419 uint32_t src_data_len;
420 /* Length of destination data */
421 uint32_t dst_data_len;
422 /* Starting point for cipher processing in source data */
423 uint32_t cipher_start_src_offset;
424 /* Length of the source data that the cipher will be computed on */
425 uint32_t len_to_cipher;
426 /* Starting point for hash processing in source data */
427 uint32_t hash_start_src_offset;
428 /* Length of the source data that the hash will be computed on */
429 uint32_t len_to_hash;
430 /* Length of the additional auth data */
431 uint32_t aad_len;
432 /* Length of the hash result */
433 uint32_t hash_result_len;
434 uint32_t reserved;
437 struct virtio_crypto_alg_chain_data_req {
438 /* Device-readable part */
439 struct virtio_crypto_alg_chain_data_para para;
442 struct virtio_crypto_sym_data_req {
443 union {
444 struct virtio_crypto_cipher_data_req cipher;
445 struct virtio_crypto_alg_chain_data_req chain;
446 uint8_t padding[40];
447 } u;
449 /* See above VIRTIO_CRYPTO_SYM_OP_* */
450 uint32_t op_type;
451 uint32_t padding;
454 struct virtio_crypto_aead_data_req {
455 /* Device-readable part */
456 struct virtio_crypto_aead_para para;
457 uint8_t padding[32];
460 struct virtio_crypto_akcipher_para {
461 uint32_t src_data_len;
462 uint32_t dst_data_len;
465 struct virtio_crypto_akcipher_data_req {
466 struct virtio_crypto_akcipher_para para;
467 uint8_t padding[40];
470 /* The request of the data virtqueue's packet */
471 struct virtio_crypto_op_data_req {
472 struct virtio_crypto_op_header header;
474 union {
475 struct virtio_crypto_sym_data_req sym_req;
476 struct virtio_crypto_hash_data_req hash_req;
477 struct virtio_crypto_mac_data_req mac_req;
478 struct virtio_crypto_aead_data_req aead_req;
479 struct virtio_crypto_akcipher_data_req akcipher_req;
480 uint8_t padding[48];
481 } u;
484 #define VIRTIO_CRYPTO_OK 0
485 #define VIRTIO_CRYPTO_ERR 1
486 #define VIRTIO_CRYPTO_BADMSG 2
487 #define VIRTIO_CRYPTO_NOTSUPP 3
488 #define VIRTIO_CRYPTO_INVSESS 4 /* Invalid session id */
489 #define VIRTIO_CRYPTO_NOSPC 5 /* no free session ID */
490 #define VIRTIO_CRYPTO_KEY_REJECTED 6 /* Signature verification failed */
492 /* The accelerator hardware is ready */
493 #define VIRTIO_CRYPTO_S_HW_READY (1 << 0)
495 struct virtio_crypto_config {
496 /* See VIRTIO_CRYPTO_OP_* above */
497 uint32_t status;
500 * Maximum number of data queue
502 uint32_t max_dataqueues;
505 * Specifies the services mask which the device support,
506 * see VIRTIO_CRYPTO_SERVICE_* above
508 uint32_t crypto_services;
510 /* Detailed algorithms mask */
511 uint32_t cipher_algo_l;
512 uint32_t cipher_algo_h;
513 uint32_t hash_algo;
514 uint32_t mac_algo_l;
515 uint32_t mac_algo_h;
516 uint32_t aead_algo;
517 /* Maximum length of cipher key */
518 uint32_t max_cipher_key_len;
519 /* Maximum length of authenticated key */
520 uint32_t max_auth_key_len;
521 uint32_t akcipher_algo;
522 /* Maximum size of each crypto request's content */
523 uint64_t max_size;
526 struct virtio_crypto_inhdr {
527 /* See VIRTIO_CRYPTO_* above */
528 uint8_t status;
530 #endif