xref: /qemu/subprojects/libvhost-user/standard-headers/linux/virtio_crypto.h (revision ed2db97e60fdc32441f22526a26bd66a6557674d)
1f43c0076SMichael S. Tsirkin #ifndef _VIRTIO_CRYPTO_H
2f43c0076SMichael S. Tsirkin #define _VIRTIO_CRYPTO_H
35551e3a8SGonglei /* This header is BSD licensed so anyone can use the definitions to implement
45551e3a8SGonglei  * compatible drivers/servers.
55551e3a8SGonglei  *
65551e3a8SGonglei  * Redistribution and use in source and binary forms, with or without
75551e3a8SGonglei  * modification, are permitted provided that the following conditions
85551e3a8SGonglei  * are met:
95551e3a8SGonglei  * 1. Redistributions of source code must retain the above copyright
105551e3a8SGonglei  *    notice, this list of conditions and the following disclaimer.
115551e3a8SGonglei  * 2. Redistributions in binary form must reproduce the above copyright
125551e3a8SGonglei  *    notice, this list of conditions and the following disclaimer in the
135551e3a8SGonglei  *    documentation and/or other materials provided with the distribution.
145551e3a8SGonglei  * 3. Neither the name of IBM nor the names of its contributors
155551e3a8SGonglei  *    may be used to endorse or promote products derived from this software
165551e3a8SGonglei  *    without specific prior written permission.
17f43c0076SMichael S. Tsirkin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18f43c0076SMichael S. Tsirkin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19f43c0076SMichael S. Tsirkin  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20f43c0076SMichael S. Tsirkin  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR
21f43c0076SMichael S. Tsirkin  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22f43c0076SMichael S. Tsirkin  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23f43c0076SMichael S. Tsirkin  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24f43c0076SMichael S. Tsirkin  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25f43c0076SMichael S. Tsirkin  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26f43c0076SMichael S. Tsirkin  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27f43c0076SMichael S. Tsirkin  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28f43c0076SMichael S. Tsirkin  * SUCH DAMAGE.
29f43c0076SMichael S. Tsirkin  */
305551e3a8SGonglei #include "standard-headers/linux/types.h"
315551e3a8SGonglei #include "standard-headers/linux/virtio_types.h"
32f43c0076SMichael S. Tsirkin #include "standard-headers/linux/virtio_ids.h"
33f43c0076SMichael S. Tsirkin #include "standard-headers/linux/virtio_config.h"
345551e3a8SGonglei 
355551e3a8SGonglei 
365551e3a8SGonglei #define VIRTIO_CRYPTO_SERVICE_CIPHER 0
375551e3a8SGonglei #define VIRTIO_CRYPTO_SERVICE_HASH   1
385551e3a8SGonglei #define VIRTIO_CRYPTO_SERVICE_MAC    2
395551e3a8SGonglei #define VIRTIO_CRYPTO_SERVICE_AEAD   3
40e4082063SAlex Williamson #define VIRTIO_CRYPTO_SERVICE_AKCIPHER 4
415551e3a8SGonglei 
425551e3a8SGonglei #define VIRTIO_CRYPTO_OPCODE(service, op)   (((service) << 8) | (op))
435551e3a8SGonglei 
445551e3a8SGonglei struct virtio_crypto_ctrl_header {
455551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \
465551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02)
475551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \
485551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03)
495551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_CREATE_SESSION \
505551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02)
515551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \
525551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03)
535551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CREATE_SESSION \
545551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02)
555551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \
565551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03)
575551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \
585551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02)
595551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \
605551e3a8SGonglei 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03)
61e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \
62e4082063SAlex Williamson 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04)
63e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \
64e4082063SAlex Williamson 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05)
65f43c0076SMichael S. Tsirkin 	uint32_t opcode;
66f43c0076SMichael S. Tsirkin 	uint32_t algo;
67f43c0076SMichael S. Tsirkin 	uint32_t flag;
685551e3a8SGonglei 	/* data virtqueue id */
69f43c0076SMichael S. Tsirkin 	uint32_t queue_id;
705551e3a8SGonglei };
715551e3a8SGonglei 
725551e3a8SGonglei struct virtio_crypto_cipher_session_para {
735551e3a8SGonglei #define VIRTIO_CRYPTO_NO_CIPHER                 0
745551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_ARC4               1
755551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_ECB            2
765551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_CBC            3
775551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_CTR            4
785551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DES_ECB            5
795551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DES_CBC            6
805551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_ECB           7
815551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_CBC           8
825551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_CTR           9
835551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8          10
845551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2        11
855551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_F8             12
865551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_XTS            13
875551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3           14
88f43c0076SMichael S. Tsirkin 	uint32_t algo;
895551e3a8SGonglei 	/* length of key */
90f43c0076SMichael S. Tsirkin 	uint32_t keylen;
915551e3a8SGonglei 
925551e3a8SGonglei #define VIRTIO_CRYPTO_OP_ENCRYPT  1
935551e3a8SGonglei #define VIRTIO_CRYPTO_OP_DECRYPT  2
945551e3a8SGonglei 	/* encrypt or decrypt */
95f43c0076SMichael S. Tsirkin 	uint32_t op;
96f43c0076SMichael S. Tsirkin 	uint32_t padding;
975551e3a8SGonglei };
985551e3a8SGonglei 
995551e3a8SGonglei struct virtio_crypto_session_input {
1005551e3a8SGonglei 	/* Device-writable part */
101f43c0076SMichael S. Tsirkin 	uint64_t session_id;
102f43c0076SMichael S. Tsirkin 	uint32_t status;
103f43c0076SMichael S. Tsirkin 	uint32_t padding;
1045551e3a8SGonglei };
1055551e3a8SGonglei 
1065551e3a8SGonglei struct virtio_crypto_cipher_session_req {
1075551e3a8SGonglei 	struct virtio_crypto_cipher_session_para para;
108f43c0076SMichael S. Tsirkin 	uint8_t padding[32];
1095551e3a8SGonglei };
1105551e3a8SGonglei 
1115551e3a8SGonglei struct virtio_crypto_hash_session_para {
1125551e3a8SGonglei #define VIRTIO_CRYPTO_NO_HASH            0
1135551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_MD5           1
1145551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA1          2
1155551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_224       3
1165551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_256       4
1175551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_384       5
1185551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_512       6
1195551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_224      7
1205551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_256      8
1215551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_384      9
1225551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_512      10
1235551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128      11
1245551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256      12
125f43c0076SMichael S. Tsirkin 	uint32_t algo;
1265551e3a8SGonglei 	/* hash result length */
127f43c0076SMichael S. Tsirkin 	uint32_t hash_result_len;
128f43c0076SMichael S. Tsirkin 	uint8_t padding[8];
1295551e3a8SGonglei };
1305551e3a8SGonglei 
1315551e3a8SGonglei struct virtio_crypto_hash_create_session_req {
1325551e3a8SGonglei 	struct virtio_crypto_hash_session_para para;
133f43c0076SMichael S. Tsirkin 	uint8_t padding[40];
1345551e3a8SGonglei };
1355551e3a8SGonglei 
1365551e3a8SGonglei struct virtio_crypto_mac_session_para {
1375551e3a8SGonglei #define VIRTIO_CRYPTO_NO_MAC                       0
1385551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_MD5                 1
1395551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA1                2
1405551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224             3
1415551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256             4
1425551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384             5
1435551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512             6
1445551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CMAC_3DES                25
1455551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CMAC_AES                 26
1465551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_KASUMI_F9                27
1475551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2              28
1485551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_GMAC_AES                 41
1495551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH             42
1505551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CBCMAC_AES               49
1515551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9         50
1525551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_XCBC_AES                 53
153f43c0076SMichael S. Tsirkin 	uint32_t algo;
1545551e3a8SGonglei 	/* hash result length */
155f43c0076SMichael S. Tsirkin 	uint32_t hash_result_len;
1565551e3a8SGonglei 	/* length of authenticated key */
157f43c0076SMichael S. Tsirkin 	uint32_t auth_key_len;
158f43c0076SMichael S. Tsirkin 	uint32_t padding;
1595551e3a8SGonglei };
1605551e3a8SGonglei 
1615551e3a8SGonglei struct virtio_crypto_mac_create_session_req {
1625551e3a8SGonglei 	struct virtio_crypto_mac_session_para para;
163f43c0076SMichael S. Tsirkin 	uint8_t padding[40];
1645551e3a8SGonglei };
1655551e3a8SGonglei 
1665551e3a8SGonglei struct virtio_crypto_aead_session_para {
1675551e3a8SGonglei #define VIRTIO_CRYPTO_NO_AEAD     0
1685551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_GCM    1
1695551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_CCM    2
1705551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305  3
171f43c0076SMichael S. Tsirkin 	uint32_t algo;
1725551e3a8SGonglei 	/* length of key */
173f43c0076SMichael S. Tsirkin 	uint32_t key_len;
174f43c0076SMichael S. Tsirkin 	/* hash result length */
175f43c0076SMichael S. Tsirkin 	uint32_t hash_result_len;
1765551e3a8SGonglei 	/* length of the additional authenticated data (AAD) in bytes */
177f43c0076SMichael S. Tsirkin 	uint32_t aad_len;
1785551e3a8SGonglei 	/* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */
179f43c0076SMichael S. Tsirkin 	uint32_t op;
180f43c0076SMichael S. Tsirkin 	uint32_t padding;
1815551e3a8SGonglei };
1825551e3a8SGonglei 
1835551e3a8SGonglei struct virtio_crypto_aead_create_session_req {
1845551e3a8SGonglei 	struct virtio_crypto_aead_session_para para;
185f43c0076SMichael S. Tsirkin 	uint8_t padding[32];
1865551e3a8SGonglei };
1875551e3a8SGonglei 
188e4082063SAlex Williamson struct virtio_crypto_rsa_session_para {
189e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_RAW_PADDING   0
190e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1
191e4082063SAlex Williamson 	uint32_t padding_algo;
192e4082063SAlex Williamson 
193e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_NO_HASH   0
194e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_MD2       1
195e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_MD3       2
196e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_MD4       3
197e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_MD5       4
198e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_SHA1      5
199e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_SHA256    6
200e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_SHA384    7
201e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_SHA512    8
202e4082063SAlex Williamson #define VIRTIO_CRYPTO_RSA_SHA224    9
203e4082063SAlex Williamson 	uint32_t hash_algo;
204e4082063SAlex Williamson };
205e4082063SAlex Williamson 
206e4082063SAlex Williamson struct virtio_crypto_ecdsa_session_para {
207e4082063SAlex Williamson #define VIRTIO_CRYPTO_CURVE_UNKNOWN   0
208e4082063SAlex Williamson #define VIRTIO_CRYPTO_CURVE_NIST_P192 1
209e4082063SAlex Williamson #define VIRTIO_CRYPTO_CURVE_NIST_P224 2
210e4082063SAlex Williamson #define VIRTIO_CRYPTO_CURVE_NIST_P256 3
211e4082063SAlex Williamson #define VIRTIO_CRYPTO_CURVE_NIST_P384 4
212e4082063SAlex Williamson #define VIRTIO_CRYPTO_CURVE_NIST_P521 5
213e4082063SAlex Williamson 	uint32_t curve_id;
214e4082063SAlex Williamson 	uint32_t padding;
215e4082063SAlex Williamson };
216e4082063SAlex Williamson 
217e4082063SAlex Williamson struct virtio_crypto_akcipher_session_para {
218e4082063SAlex Williamson #define VIRTIO_CRYPTO_NO_AKCIPHER    0
219e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_RSA   1
220e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_DSA   2
221e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3
222e4082063SAlex Williamson 	uint32_t algo;
223e4082063SAlex Williamson 
224e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC  1
225e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2
226e4082063SAlex Williamson 	uint32_t keytype;
227e4082063SAlex Williamson 	uint32_t keylen;
228e4082063SAlex Williamson 
229e4082063SAlex Williamson 	union {
230e4082063SAlex Williamson 		struct virtio_crypto_rsa_session_para rsa;
231e4082063SAlex Williamson 		struct virtio_crypto_ecdsa_session_para ecdsa;
232e4082063SAlex Williamson 	} u;
233e4082063SAlex Williamson };
234e4082063SAlex Williamson 
235e4082063SAlex Williamson struct virtio_crypto_akcipher_create_session_req {
236e4082063SAlex Williamson 	struct virtio_crypto_akcipher_session_para para;
237e4082063SAlex Williamson 	uint8_t padding[36];
238e4082063SAlex Williamson };
239e4082063SAlex Williamson 
2405551e3a8SGonglei struct virtio_crypto_alg_chain_session_para {
2415551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER  1
2425551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH  2
243f43c0076SMichael S. Tsirkin 	uint32_t alg_chain_order;
2445551e3a8SGonglei /* Plain hash */
2455551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN    1
2465551e3a8SGonglei /* Authenticated hash (mac) */
2475551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH     2
2485551e3a8SGonglei /* Nested hash */
2495551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED   3
250f43c0076SMichael S. Tsirkin 	uint32_t hash_mode;
2515551e3a8SGonglei 	struct virtio_crypto_cipher_session_para cipher_param;
2525551e3a8SGonglei 	union {
2535551e3a8SGonglei 		struct virtio_crypto_hash_session_para hash_param;
2545551e3a8SGonglei 		struct virtio_crypto_mac_session_para mac_param;
255f43c0076SMichael S. Tsirkin 		uint8_t padding[16];
2565551e3a8SGonglei 	} u;
2575551e3a8SGonglei 	/* length of the additional authenticated data (AAD) in bytes */
258f43c0076SMichael S. Tsirkin 	uint32_t aad_len;
259f43c0076SMichael S. Tsirkin 	uint32_t padding;
2605551e3a8SGonglei };
2615551e3a8SGonglei 
2625551e3a8SGonglei struct virtio_crypto_alg_chain_session_req {
2635551e3a8SGonglei 	struct virtio_crypto_alg_chain_session_para para;
2645551e3a8SGonglei };
2655551e3a8SGonglei 
2665551e3a8SGonglei struct virtio_crypto_sym_create_session_req {
2675551e3a8SGonglei 	union {
2685551e3a8SGonglei 		struct virtio_crypto_cipher_session_req cipher;
2695551e3a8SGonglei 		struct virtio_crypto_alg_chain_session_req chain;
270f43c0076SMichael S. Tsirkin 		uint8_t padding[48];
2715551e3a8SGonglei 	} u;
2725551e3a8SGonglei 
2735551e3a8SGonglei 	/* Device-readable part */
2745551e3a8SGonglei 
2755551e3a8SGonglei /* No operation */
2765551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_OP_NONE  0
2775551e3a8SGonglei /* Cipher only operation on the data */
2785551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_OP_CIPHER  1
279f43c0076SMichael S. Tsirkin /*
280f43c0076SMichael S. Tsirkin  * Chain any cipher with any hash or mac operation. The order
281f43c0076SMichael S. Tsirkin  * depends on the value of alg_chain_order param
282f43c0076SMichael S. Tsirkin  */
2835551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING  2
284f43c0076SMichael S. Tsirkin 	uint32_t op_type;
285f43c0076SMichael S. Tsirkin 	uint32_t padding;
2865551e3a8SGonglei };
2875551e3a8SGonglei 
2885551e3a8SGonglei struct virtio_crypto_destroy_session_req {
2895551e3a8SGonglei 	/* Device-readable part */
290f43c0076SMichael S. Tsirkin 	uint64_t  session_id;
291f43c0076SMichael S. Tsirkin 	uint8_t padding[48];
2925551e3a8SGonglei };
2935551e3a8SGonglei 
294f43c0076SMichael S. Tsirkin /* The request of the control virtqueue's packet */
2955551e3a8SGonglei struct virtio_crypto_op_ctrl_req {
2965551e3a8SGonglei 	struct virtio_crypto_ctrl_header header;
2975551e3a8SGonglei 
2985551e3a8SGonglei 	union {
299f43c0076SMichael S. Tsirkin 		struct virtio_crypto_sym_create_session_req
300f43c0076SMichael S. Tsirkin 			sym_create_session;
301f43c0076SMichael S. Tsirkin 		struct virtio_crypto_hash_create_session_req
302f43c0076SMichael S. Tsirkin 			hash_create_session;
303f43c0076SMichael S. Tsirkin 		struct virtio_crypto_mac_create_session_req
304f43c0076SMichael S. Tsirkin 			mac_create_session;
305f43c0076SMichael S. Tsirkin 		struct virtio_crypto_aead_create_session_req
306f43c0076SMichael S. Tsirkin 			aead_create_session;
307e4082063SAlex Williamson 		struct virtio_crypto_akcipher_create_session_req
308e4082063SAlex Williamson 			akcipher_create_session;
309f43c0076SMichael S. Tsirkin 		struct virtio_crypto_destroy_session_req
310f43c0076SMichael S. Tsirkin 			destroy_session;
311f43c0076SMichael S. Tsirkin 		uint8_t padding[56];
3125551e3a8SGonglei 	} u;
3135551e3a8SGonglei };
3145551e3a8SGonglei 
3155551e3a8SGonglei struct virtio_crypto_op_header {
3165551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \
3175551e3a8SGonglei 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00)
3185551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DECRYPT \
3195551e3a8SGonglei 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01)
3205551e3a8SGonglei #define VIRTIO_CRYPTO_HASH \
3215551e3a8SGonglei 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00)
3225551e3a8SGonglei #define VIRTIO_CRYPTO_MAC \
3235551e3a8SGonglei 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00)
3245551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_ENCRYPT \
3255551e3a8SGonglei 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00)
3265551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_DECRYPT \
3275551e3a8SGonglei 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01)
328e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \
329e4082063SAlex Williamson 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00)
330e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \
331e4082063SAlex Williamson 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01)
332*44fe383cSHendrik Brueckner 	/* akcipher sign/verify opcodes are deprecated */
333e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_SIGN \
334e4082063SAlex Williamson 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02)
335e4082063SAlex Williamson #define VIRTIO_CRYPTO_AKCIPHER_VERIFY \
336e4082063SAlex Williamson 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03)
337f43c0076SMichael S. Tsirkin 	uint32_t opcode;
3385551e3a8SGonglei 	/* algo should be service-specific algorithms */
339f43c0076SMichael S. Tsirkin 	uint32_t algo;
3405551e3a8SGonglei 	/* session_id should be service-specific algorithms */
341f43c0076SMichael S. Tsirkin 	uint64_t session_id;
3425551e3a8SGonglei 	/* control flag to control the request */
343f43c0076SMichael S. Tsirkin 	uint32_t flag;
344f43c0076SMichael S. Tsirkin 	uint32_t padding;
3455551e3a8SGonglei };
3465551e3a8SGonglei 
3475551e3a8SGonglei struct virtio_crypto_cipher_para {
3485551e3a8SGonglei 	/*
3495551e3a8SGonglei 	 * Byte Length of valid IV/Counter
3505551e3a8SGonglei 	 *
351f43c0076SMichael S. Tsirkin 	 * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for
3525551e3a8SGonglei 	 *   SNOW3G in UEA2 mode, this is the length of the IV (which
3535551e3a8SGonglei 	 *   must be the same as the block length of the cipher).
354f43c0076SMichael S. Tsirkin 	 * For block ciphers in CTR mode, this is the length of the counter
3555551e3a8SGonglei 	 *   (which must be the same as the block length of the cipher).
356f43c0076SMichael S. Tsirkin 	 * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007.
3575551e3a8SGonglei 	 *
3585551e3a8SGonglei 	 * The IV/Counter will be updated after every partial cryptographic
3595551e3a8SGonglei 	 * operation.
3605551e3a8SGonglei 	 */
361f43c0076SMichael S. Tsirkin 	uint32_t iv_len;
3625551e3a8SGonglei 	/* length of source data */
363f43c0076SMichael S. Tsirkin 	uint32_t src_data_len;
3645551e3a8SGonglei 	/* length of dst data */
365f43c0076SMichael S. Tsirkin 	uint32_t dst_data_len;
366f43c0076SMichael S. Tsirkin 	uint32_t padding;
3675551e3a8SGonglei };
3685551e3a8SGonglei 
3695551e3a8SGonglei struct virtio_crypto_hash_para {
3705551e3a8SGonglei 	/* length of source data */
371f43c0076SMichael S. Tsirkin 	uint32_t src_data_len;
3725551e3a8SGonglei 	/* hash result length */
373f43c0076SMichael S. Tsirkin 	uint32_t hash_result_len;
3745551e3a8SGonglei };
3755551e3a8SGonglei 
3765551e3a8SGonglei struct virtio_crypto_mac_para {
3775551e3a8SGonglei 	struct virtio_crypto_hash_para hash;
3785551e3a8SGonglei };
3795551e3a8SGonglei 
3805551e3a8SGonglei struct virtio_crypto_aead_para {
3815551e3a8SGonglei 	/*
3825551e3a8SGonglei 	 * Byte Length of valid IV data pointed to by the below iv_addr
3835551e3a8SGonglei 	 * parameter.
3845551e3a8SGonglei 	 *
385f43c0076SMichael S. Tsirkin 	 * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which
3865551e3a8SGonglei 	 *   case iv_addr points to J0.
387f43c0076SMichael S. Tsirkin 	 * For CCM mode, this is the length of the nonce, which can be in the
3885551e3a8SGonglei 	 *   range 7 to 13 inclusive.
3895551e3a8SGonglei 	 */
390f43c0076SMichael S. Tsirkin 	uint32_t iv_len;
3915551e3a8SGonglei 	/* length of additional auth data */
392f43c0076SMichael S. Tsirkin 	uint32_t aad_len;
3935551e3a8SGonglei 	/* length of source data */
394f43c0076SMichael S. Tsirkin 	uint32_t src_data_len;
3955551e3a8SGonglei 	/* length of dst data */
396f43c0076SMichael S. Tsirkin 	uint32_t dst_data_len;
3975551e3a8SGonglei };
3985551e3a8SGonglei 
3995551e3a8SGonglei struct virtio_crypto_cipher_data_req {
4005551e3a8SGonglei 	/* Device-readable part */
4015551e3a8SGonglei 	struct virtio_crypto_cipher_para para;
402f43c0076SMichael S. Tsirkin 	uint8_t padding[24];
4035551e3a8SGonglei };
4045551e3a8SGonglei 
4055551e3a8SGonglei struct virtio_crypto_hash_data_req {
4065551e3a8SGonglei 	/* Device-readable part */
4075551e3a8SGonglei 	struct virtio_crypto_hash_para para;
408f43c0076SMichael S. Tsirkin 	uint8_t padding[40];
4095551e3a8SGonglei };
4105551e3a8SGonglei 
4115551e3a8SGonglei struct virtio_crypto_mac_data_req {
4125551e3a8SGonglei 	/* Device-readable part */
4135551e3a8SGonglei 	struct virtio_crypto_mac_para para;
414f43c0076SMichael S. Tsirkin 	uint8_t padding[40];
4155551e3a8SGonglei };
4165551e3a8SGonglei 
4175551e3a8SGonglei struct virtio_crypto_alg_chain_data_para {
418f43c0076SMichael S. Tsirkin 	uint32_t iv_len;
4195551e3a8SGonglei 	/* Length of source data */
420f43c0076SMichael S. Tsirkin 	uint32_t src_data_len;
4215551e3a8SGonglei 	/* Length of destination data */
422f43c0076SMichael S. Tsirkin 	uint32_t dst_data_len;
4235551e3a8SGonglei 	/* Starting point for cipher processing in source data */
424f43c0076SMichael S. Tsirkin 	uint32_t cipher_start_src_offset;
4255551e3a8SGonglei 	/* Length of the source data that the cipher will be computed on */
426f43c0076SMichael S. Tsirkin 	uint32_t len_to_cipher;
4275551e3a8SGonglei 	/* Starting point for hash processing in source data */
428f43c0076SMichael S. Tsirkin 	uint32_t hash_start_src_offset;
4295551e3a8SGonglei 	/* Length of the source data that the hash will be computed on */
430f43c0076SMichael S. Tsirkin 	uint32_t len_to_hash;
4315551e3a8SGonglei 	/* Length of the additional auth data */
432f43c0076SMichael S. Tsirkin 	uint32_t aad_len;
4335551e3a8SGonglei 	/* Length of the hash result */
434f43c0076SMichael S. Tsirkin 	uint32_t hash_result_len;
435f43c0076SMichael S. Tsirkin 	uint32_t reserved;
4365551e3a8SGonglei };
4375551e3a8SGonglei 
4385551e3a8SGonglei struct virtio_crypto_alg_chain_data_req {
4395551e3a8SGonglei 	/* Device-readable part */
4405551e3a8SGonglei 	struct virtio_crypto_alg_chain_data_para para;
4415551e3a8SGonglei };
4425551e3a8SGonglei 
4435551e3a8SGonglei struct virtio_crypto_sym_data_req {
4445551e3a8SGonglei 	union {
4455551e3a8SGonglei 		struct virtio_crypto_cipher_data_req cipher;
4465551e3a8SGonglei 		struct virtio_crypto_alg_chain_data_req chain;
447f43c0076SMichael S. Tsirkin 		uint8_t padding[40];
4485551e3a8SGonglei 	} u;
4495551e3a8SGonglei 
4505551e3a8SGonglei 	/* See above VIRTIO_CRYPTO_SYM_OP_* */
451f43c0076SMichael S. Tsirkin 	uint32_t op_type;
452f43c0076SMichael S. Tsirkin 	uint32_t padding;
4535551e3a8SGonglei };
4545551e3a8SGonglei 
4555551e3a8SGonglei struct virtio_crypto_aead_data_req {
4565551e3a8SGonglei 	/* Device-readable part */
4575551e3a8SGonglei 	struct virtio_crypto_aead_para para;
458f43c0076SMichael S. Tsirkin 	uint8_t padding[32];
4595551e3a8SGonglei };
4605551e3a8SGonglei 
461e4082063SAlex Williamson struct virtio_crypto_akcipher_para {
462e4082063SAlex Williamson 	uint32_t src_data_len;
463e4082063SAlex Williamson 	uint32_t dst_data_len;
464e4082063SAlex Williamson };
465e4082063SAlex Williamson 
466e4082063SAlex Williamson struct virtio_crypto_akcipher_data_req {
467e4082063SAlex Williamson 	struct virtio_crypto_akcipher_para para;
468e4082063SAlex Williamson 	uint8_t padding[40];
469e4082063SAlex Williamson };
470e4082063SAlex Williamson 
471f43c0076SMichael S. Tsirkin /* The request of the data virtqueue's packet */
4725551e3a8SGonglei struct virtio_crypto_op_data_req {
4735551e3a8SGonglei 	struct virtio_crypto_op_header header;
4745551e3a8SGonglei 
4755551e3a8SGonglei 	union {
4765551e3a8SGonglei 		struct virtio_crypto_sym_data_req  sym_req;
4775551e3a8SGonglei 		struct virtio_crypto_hash_data_req hash_req;
4785551e3a8SGonglei 		struct virtio_crypto_mac_data_req mac_req;
4795551e3a8SGonglei 		struct virtio_crypto_aead_data_req aead_req;
480e4082063SAlex Williamson 		struct virtio_crypto_akcipher_data_req akcipher_req;
481f43c0076SMichael S. Tsirkin 		uint8_t padding[48];
4825551e3a8SGonglei 	} u;
4835551e3a8SGonglei };
4845551e3a8SGonglei 
4855551e3a8SGonglei #define VIRTIO_CRYPTO_OK        0
4865551e3a8SGonglei #define VIRTIO_CRYPTO_ERR       1
4875551e3a8SGonglei #define VIRTIO_CRYPTO_BADMSG    2
4885551e3a8SGonglei #define VIRTIO_CRYPTO_NOTSUPP   3
489f43c0076SMichael S. Tsirkin #define VIRTIO_CRYPTO_INVSESS   4 /* Invalid session id */
490e4082063SAlex Williamson #define VIRTIO_CRYPTO_NOSPC     5 /* no free session ID */
491e4082063SAlex Williamson #define VIRTIO_CRYPTO_KEY_REJECTED 6 /* Signature verification failed */
4925551e3a8SGonglei 
4935551e3a8SGonglei /* The accelerator hardware is ready */
4945551e3a8SGonglei #define VIRTIO_CRYPTO_S_HW_READY  (1 << 0)
4955551e3a8SGonglei 
4965551e3a8SGonglei struct virtio_crypto_config {
497f43c0076SMichael S. Tsirkin 	/* See VIRTIO_CRYPTO_OP_* above */
498f43c0076SMichael S. Tsirkin 	uint32_t  status;
4995551e3a8SGonglei 
5005551e3a8SGonglei 	/*
501f43c0076SMichael S. Tsirkin 	 * Maximum number of data queue
5025551e3a8SGonglei 	 */
503f43c0076SMichael S. Tsirkin 	uint32_t  max_dataqueues;
5045551e3a8SGonglei 
505f43c0076SMichael S. Tsirkin 	/*
506f43c0076SMichael S. Tsirkin 	 * Specifies the services mask which the device support,
507f43c0076SMichael S. Tsirkin 	 * see VIRTIO_CRYPTO_SERVICE_* above
508f43c0076SMichael S. Tsirkin 	 */
509f43c0076SMichael S. Tsirkin 	uint32_t crypto_services;
5105551e3a8SGonglei 
5115551e3a8SGonglei 	/* Detailed algorithms mask */
512f43c0076SMichael S. Tsirkin 	uint32_t cipher_algo_l;
513f43c0076SMichael S. Tsirkin 	uint32_t cipher_algo_h;
514f43c0076SMichael S. Tsirkin 	uint32_t hash_algo;
515f43c0076SMichael S. Tsirkin 	uint32_t mac_algo_l;
516f43c0076SMichael S. Tsirkin 	uint32_t mac_algo_h;
517f43c0076SMichael S. Tsirkin 	uint32_t aead_algo;
5185551e3a8SGonglei 	/* Maximum length of cipher key */
5195551e3a8SGonglei 	uint32_t max_cipher_key_len;
5205551e3a8SGonglei 	/* Maximum length of authenticated key */
5215551e3a8SGonglei 	uint32_t max_auth_key_len;
522e4082063SAlex Williamson 	uint32_t akcipher_algo;
523f43c0076SMichael S. Tsirkin 	/* Maximum size of each crypto request's content */
524f43c0076SMichael S. Tsirkin 	uint64_t max_size;
5255551e3a8SGonglei };
5265551e3a8SGonglei 
5275551e3a8SGonglei struct virtio_crypto_inhdr {
5285551e3a8SGonglei 	/* See VIRTIO_CRYPTO_* above */
5295551e3a8SGonglei 	uint8_t status;
5305551e3a8SGonglei };
531f43c0076SMichael S. Tsirkin #endif
532