18c2ecf20Sopenharmony_ci#ifndef _VIRTIO_CRYPTO_H
28c2ecf20Sopenharmony_ci#define _VIRTIO_CRYPTO_H
38c2ecf20Sopenharmony_ci/* This header is BSD licensed so anyone can use the definitions to implement
48c2ecf20Sopenharmony_ci * compatible drivers/servers.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
78c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
88c2ecf20Sopenharmony_ci * are met:
98c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
108c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
118c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
128c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
138c2ecf20Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
148c2ecf20Sopenharmony_ci * 3. Neither the name of IBM nor the names of its contributors
158c2ecf20Sopenharmony_ci *    may be used to endorse or promote products derived from this software
168c2ecf20Sopenharmony_ci *    without specific prior written permission.
178c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
188c2ecf20Sopenharmony_ci * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
198c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
208c2ecf20Sopenharmony_ci * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR
218c2ecf20Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
228c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
238c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
248c2ecf20Sopenharmony_ci * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
258c2ecf20Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
268c2ecf20Sopenharmony_ci * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
278c2ecf20Sopenharmony_ci * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288c2ecf20Sopenharmony_ci * SUCH DAMAGE.
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci#include <linux/types.h>
318c2ecf20Sopenharmony_ci#include <linux/virtio_types.h>
328c2ecf20Sopenharmony_ci#include <linux/virtio_ids.h>
338c2ecf20Sopenharmony_ci#include <linux/virtio_config.h>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_CIPHER 0
378c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_HASH   1
388c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_MAC    2
398c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_AEAD   3
408c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_AKCIPHER 4
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_OPCODE(service, op)   (((service) << 8) | (op))
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct virtio_crypto_ctrl_header {
458c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \
468c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02)
478c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \
488c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03)
498c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_CREATE_SESSION \
508c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02)
518c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \
528c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03)
538c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CREATE_SESSION \
548c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02)
558c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \
568c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03)
578c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \
588c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02)
598c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \
608c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03)
618c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \
628c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04)
638c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \
648c2ecf20Sopenharmony_ci	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05)
658c2ecf20Sopenharmony_ci	__le32 opcode;
668c2ecf20Sopenharmony_ci	__le32 algo;
678c2ecf20Sopenharmony_ci	__le32 flag;
688c2ecf20Sopenharmony_ci	/* data virtqueue id */
698c2ecf20Sopenharmony_ci	__le32 queue_id;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct virtio_crypto_cipher_session_para {
738c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NO_CIPHER                 0
748c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_ARC4               1
758c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_ECB            2
768c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_CBC            3
778c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_CTR            4
788c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DES_ECB            5
798c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DES_CBC            6
808c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_3DES_ECB           7
818c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_3DES_CBC           8
828c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_3DES_CTR           9
838c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_KASUMI_F8          10
848c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2        11
858c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_F8             12
868c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_XTS            13
878c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3           14
888c2ecf20Sopenharmony_ci	__le32 algo;
898c2ecf20Sopenharmony_ci	/* length of key */
908c2ecf20Sopenharmony_ci	__le32 keylen;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_OP_ENCRYPT  1
938c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_OP_DECRYPT  2
948c2ecf20Sopenharmony_ci	/* encrypt or decrypt */
958c2ecf20Sopenharmony_ci	__le32 op;
968c2ecf20Sopenharmony_ci	__le32 padding;
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistruct virtio_crypto_session_input {
1008c2ecf20Sopenharmony_ci	/* Device-writable part */
1018c2ecf20Sopenharmony_ci	__le64 session_id;
1028c2ecf20Sopenharmony_ci	__le32 status;
1038c2ecf20Sopenharmony_ci	__le32 padding;
1048c2ecf20Sopenharmony_ci};
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistruct virtio_crypto_cipher_session_req {
1078c2ecf20Sopenharmony_ci	struct virtio_crypto_cipher_session_para para;
1088c2ecf20Sopenharmony_ci	__u8 padding[32];
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct virtio_crypto_hash_session_para {
1128c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NO_HASH            0
1138c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_MD5           1
1148c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA1          2
1158c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_224       3
1168c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_256       4
1178c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_384       5
1188c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_512       6
1198c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_224      7
1208c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_256      8
1218c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_384      9
1228c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_512      10
1238c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128      11
1248c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256      12
1258c2ecf20Sopenharmony_ci	__le32 algo;
1268c2ecf20Sopenharmony_ci	/* hash result length */
1278c2ecf20Sopenharmony_ci	__le32 hash_result_len;
1288c2ecf20Sopenharmony_ci	__u8 padding[8];
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct virtio_crypto_hash_create_session_req {
1328c2ecf20Sopenharmony_ci	struct virtio_crypto_hash_session_para para;
1338c2ecf20Sopenharmony_ci	__u8 padding[40];
1348c2ecf20Sopenharmony_ci};
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_cistruct virtio_crypto_mac_session_para {
1378c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NO_MAC                       0
1388c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_MD5                 1
1398c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA1                2
1408c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_224             3
1418c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_256             4
1428c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_384             5
1438c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_512             6
1448c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CMAC_3DES                25
1458c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CMAC_AES                 26
1468c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_KASUMI_F9                27
1478c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2              28
1488c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_GMAC_AES                 41
1498c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH             42
1508c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CBCMAC_AES               49
1518c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9         50
1528c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_XCBC_AES                 53
1538c2ecf20Sopenharmony_ci	__le32 algo;
1548c2ecf20Sopenharmony_ci	/* hash result length */
1558c2ecf20Sopenharmony_ci	__le32 hash_result_len;
1568c2ecf20Sopenharmony_ci	/* length of authenticated key */
1578c2ecf20Sopenharmony_ci	__le32 auth_key_len;
1588c2ecf20Sopenharmony_ci	__le32 padding;
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistruct virtio_crypto_mac_create_session_req {
1628c2ecf20Sopenharmony_ci	struct virtio_crypto_mac_session_para para;
1638c2ecf20Sopenharmony_ci	__u8 padding[40];
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_cistruct virtio_crypto_aead_session_para {
1678c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NO_AEAD     0
1688c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_GCM    1
1698c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_CCM    2
1708c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305  3
1718c2ecf20Sopenharmony_ci	__le32 algo;
1728c2ecf20Sopenharmony_ci	/* length of key */
1738c2ecf20Sopenharmony_ci	__le32 key_len;
1748c2ecf20Sopenharmony_ci	/* hash result length */
1758c2ecf20Sopenharmony_ci	__le32 hash_result_len;
1768c2ecf20Sopenharmony_ci	/* length of the additional authenticated data (AAD) in bytes */
1778c2ecf20Sopenharmony_ci	__le32 aad_len;
1788c2ecf20Sopenharmony_ci	/* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */
1798c2ecf20Sopenharmony_ci	__le32 op;
1808c2ecf20Sopenharmony_ci	__le32 padding;
1818c2ecf20Sopenharmony_ci};
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_cistruct virtio_crypto_aead_create_session_req {
1848c2ecf20Sopenharmony_ci	struct virtio_crypto_aead_session_para para;
1858c2ecf20Sopenharmony_ci	__u8 padding[32];
1868c2ecf20Sopenharmony_ci};
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistruct virtio_crypto_rsa_session_para {
1898c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_RAW_PADDING   0
1908c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1
1918c2ecf20Sopenharmony_ci	__le32 padding_algo;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_NO_HASH   0
1948c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD2       1
1958c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD3       2
1968c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD4       3
1978c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD5       4
1988c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA1      5
1998c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA256    6
2008c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA384    7
2018c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA512    8
2028c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA224    9
2038c2ecf20Sopenharmony_ci	__le32 hash_algo;
2048c2ecf20Sopenharmony_ci};
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistruct virtio_crypto_ecdsa_session_para {
2078c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_UNKNOWN   0
2088c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P192 1
2098c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P224 2
2108c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P256 3
2118c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P384 4
2128c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P521 5
2138c2ecf20Sopenharmony_ci	__le32 curve_id;
2148c2ecf20Sopenharmony_ci	__le32 padding;
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistruct virtio_crypto_akcipher_session_para {
2188c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NO_AKCIPHER    0
2198c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_RSA   1
2208c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_DSA   2
2218c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3
2228c2ecf20Sopenharmony_ci	__le32 algo;
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC  1
2258c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2
2268c2ecf20Sopenharmony_ci	__le32 keytype;
2278c2ecf20Sopenharmony_ci	__le32 keylen;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	union {
2308c2ecf20Sopenharmony_ci		struct virtio_crypto_rsa_session_para rsa;
2318c2ecf20Sopenharmony_ci		struct virtio_crypto_ecdsa_session_para ecdsa;
2328c2ecf20Sopenharmony_ci	} u;
2338c2ecf20Sopenharmony_ci};
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_cistruct virtio_crypto_akcipher_create_session_req {
2368c2ecf20Sopenharmony_ci	struct virtio_crypto_akcipher_session_para para;
2378c2ecf20Sopenharmony_ci	__u8 padding[36];
2388c2ecf20Sopenharmony_ci};
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistruct virtio_crypto_alg_chain_session_para {
2418c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER  1
2428c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH  2
2438c2ecf20Sopenharmony_ci	__le32 alg_chain_order;
2448c2ecf20Sopenharmony_ci/* Plain hash */
2458c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN    1
2468c2ecf20Sopenharmony_ci/* Authenticated hash (mac) */
2478c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH     2
2488c2ecf20Sopenharmony_ci/* Nested hash */
2498c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED   3
2508c2ecf20Sopenharmony_ci	__le32 hash_mode;
2518c2ecf20Sopenharmony_ci	struct virtio_crypto_cipher_session_para cipher_param;
2528c2ecf20Sopenharmony_ci	union {
2538c2ecf20Sopenharmony_ci		struct virtio_crypto_hash_session_para hash_param;
2548c2ecf20Sopenharmony_ci		struct virtio_crypto_mac_session_para mac_param;
2558c2ecf20Sopenharmony_ci		__u8 padding[16];
2568c2ecf20Sopenharmony_ci	} u;
2578c2ecf20Sopenharmony_ci	/* length of the additional authenticated data (AAD) in bytes */
2588c2ecf20Sopenharmony_ci	__le32 aad_len;
2598c2ecf20Sopenharmony_ci	__le32 padding;
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistruct virtio_crypto_alg_chain_session_req {
2638c2ecf20Sopenharmony_ci	struct virtio_crypto_alg_chain_session_para para;
2648c2ecf20Sopenharmony_ci};
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistruct virtio_crypto_sym_create_session_req {
2678c2ecf20Sopenharmony_ci	union {
2688c2ecf20Sopenharmony_ci		struct virtio_crypto_cipher_session_req cipher;
2698c2ecf20Sopenharmony_ci		struct virtio_crypto_alg_chain_session_req chain;
2708c2ecf20Sopenharmony_ci		__u8 padding[48];
2718c2ecf20Sopenharmony_ci	} u;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	/* Device-readable part */
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci/* No operation */
2768c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_OP_NONE  0
2778c2ecf20Sopenharmony_ci/* Cipher only operation on the data */
2788c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_OP_CIPHER  1
2798c2ecf20Sopenharmony_ci/*
2808c2ecf20Sopenharmony_ci * Chain any cipher with any hash or mac operation. The order
2818c2ecf20Sopenharmony_ci * depends on the value of alg_chain_order param
2828c2ecf20Sopenharmony_ci */
2838c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING  2
2848c2ecf20Sopenharmony_ci	__le32 op_type;
2858c2ecf20Sopenharmony_ci	__le32 padding;
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistruct virtio_crypto_destroy_session_req {
2898c2ecf20Sopenharmony_ci	/* Device-readable part */
2908c2ecf20Sopenharmony_ci	__le64  session_id;
2918c2ecf20Sopenharmony_ci	__u8 padding[48];
2928c2ecf20Sopenharmony_ci};
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/* The request of the control virtqueue's packet */
2958c2ecf20Sopenharmony_cistruct virtio_crypto_op_ctrl_req {
2968c2ecf20Sopenharmony_ci	struct virtio_crypto_ctrl_header header;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	union {
2998c2ecf20Sopenharmony_ci		struct virtio_crypto_sym_create_session_req
3008c2ecf20Sopenharmony_ci			sym_create_session;
3018c2ecf20Sopenharmony_ci		struct virtio_crypto_hash_create_session_req
3028c2ecf20Sopenharmony_ci			hash_create_session;
3038c2ecf20Sopenharmony_ci		struct virtio_crypto_mac_create_session_req
3048c2ecf20Sopenharmony_ci			mac_create_session;
3058c2ecf20Sopenharmony_ci		struct virtio_crypto_aead_create_session_req
3068c2ecf20Sopenharmony_ci			aead_create_session;
3078c2ecf20Sopenharmony_ci		struct virtio_crypto_akcipher_create_session_req
3088c2ecf20Sopenharmony_ci			akcipher_create_session;
3098c2ecf20Sopenharmony_ci		struct virtio_crypto_destroy_session_req
3108c2ecf20Sopenharmony_ci			destroy_session;
3118c2ecf20Sopenharmony_ci		__u8 padding[56];
3128c2ecf20Sopenharmony_ci	} u;
3138c2ecf20Sopenharmony_ci};
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistruct virtio_crypto_op_header {
3168c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_ENCRYPT \
3178c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00)
3188c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DECRYPT \
3198c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01)
3208c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_HASH \
3218c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00)
3228c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_MAC \
3238c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00)
3248c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_ENCRYPT \
3258c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00)
3268c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_DECRYPT \
3278c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01)
3288c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \
3298c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00)
3308c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \
3318c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01)
3328c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_SIGN \
3338c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02)
3348c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_VERIFY \
3358c2ecf20Sopenharmony_ci	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03)
3368c2ecf20Sopenharmony_ci	__le32 opcode;
3378c2ecf20Sopenharmony_ci	/* algo should be service-specific algorithms */
3388c2ecf20Sopenharmony_ci	__le32 algo;
3398c2ecf20Sopenharmony_ci	/* session_id should be service-specific algorithms */
3408c2ecf20Sopenharmony_ci	__le64 session_id;
3418c2ecf20Sopenharmony_ci	/* control flag to control the request */
3428c2ecf20Sopenharmony_ci	__le32 flag;
3438c2ecf20Sopenharmony_ci	__le32 padding;
3448c2ecf20Sopenharmony_ci};
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_cistruct virtio_crypto_cipher_para {
3478c2ecf20Sopenharmony_ci	/*
3488c2ecf20Sopenharmony_ci	 * Byte Length of valid IV/Counter
3498c2ecf20Sopenharmony_ci	 *
3508c2ecf20Sopenharmony_ci	 * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for
3518c2ecf20Sopenharmony_ci	 *   SNOW3G in UEA2 mode, this is the length of the IV (which
3528c2ecf20Sopenharmony_ci	 *   must be the same as the block length of the cipher).
3538c2ecf20Sopenharmony_ci	 * For block ciphers in CTR mode, this is the length of the counter
3548c2ecf20Sopenharmony_ci	 *   (which must be the same as the block length of the cipher).
3558c2ecf20Sopenharmony_ci	 * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007.
3568c2ecf20Sopenharmony_ci	 *
3578c2ecf20Sopenharmony_ci	 * The IV/Counter will be updated after every partial cryptographic
3588c2ecf20Sopenharmony_ci	 * operation.
3598c2ecf20Sopenharmony_ci	 */
3608c2ecf20Sopenharmony_ci	__le32 iv_len;
3618c2ecf20Sopenharmony_ci	/* length of source data */
3628c2ecf20Sopenharmony_ci	__le32 src_data_len;
3638c2ecf20Sopenharmony_ci	/* length of dst data */
3648c2ecf20Sopenharmony_ci	__le32 dst_data_len;
3658c2ecf20Sopenharmony_ci	__le32 padding;
3668c2ecf20Sopenharmony_ci};
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistruct virtio_crypto_hash_para {
3698c2ecf20Sopenharmony_ci	/* length of source data */
3708c2ecf20Sopenharmony_ci	__le32 src_data_len;
3718c2ecf20Sopenharmony_ci	/* hash result length */
3728c2ecf20Sopenharmony_ci	__le32 hash_result_len;
3738c2ecf20Sopenharmony_ci};
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cistruct virtio_crypto_mac_para {
3768c2ecf20Sopenharmony_ci	struct virtio_crypto_hash_para hash;
3778c2ecf20Sopenharmony_ci};
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistruct virtio_crypto_aead_para {
3808c2ecf20Sopenharmony_ci	/*
3818c2ecf20Sopenharmony_ci	 * Byte Length of valid IV data pointed to by the below iv_addr
3828c2ecf20Sopenharmony_ci	 * parameter.
3838c2ecf20Sopenharmony_ci	 *
3848c2ecf20Sopenharmony_ci	 * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which
3858c2ecf20Sopenharmony_ci	 *   case iv_addr points to J0.
3868c2ecf20Sopenharmony_ci	 * For CCM mode, this is the length of the nonce, which can be in the
3878c2ecf20Sopenharmony_ci	 *   range 7 to 13 inclusive.
3888c2ecf20Sopenharmony_ci	 */
3898c2ecf20Sopenharmony_ci	__le32 iv_len;
3908c2ecf20Sopenharmony_ci	/* length of additional auth data */
3918c2ecf20Sopenharmony_ci	__le32 aad_len;
3928c2ecf20Sopenharmony_ci	/* length of source data */
3938c2ecf20Sopenharmony_ci	__le32 src_data_len;
3948c2ecf20Sopenharmony_ci	/* length of dst data */
3958c2ecf20Sopenharmony_ci	__le32 dst_data_len;
3968c2ecf20Sopenharmony_ci};
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_cistruct virtio_crypto_cipher_data_req {
3998c2ecf20Sopenharmony_ci	/* Device-readable part */
4008c2ecf20Sopenharmony_ci	struct virtio_crypto_cipher_para para;
4018c2ecf20Sopenharmony_ci	__u8 padding[24];
4028c2ecf20Sopenharmony_ci};
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_cistruct virtio_crypto_hash_data_req {
4058c2ecf20Sopenharmony_ci	/* Device-readable part */
4068c2ecf20Sopenharmony_ci	struct virtio_crypto_hash_para para;
4078c2ecf20Sopenharmony_ci	__u8 padding[40];
4088c2ecf20Sopenharmony_ci};
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_cistruct virtio_crypto_mac_data_req {
4118c2ecf20Sopenharmony_ci	/* Device-readable part */
4128c2ecf20Sopenharmony_ci	struct virtio_crypto_mac_para para;
4138c2ecf20Sopenharmony_ci	__u8 padding[40];
4148c2ecf20Sopenharmony_ci};
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_cistruct virtio_crypto_alg_chain_data_para {
4178c2ecf20Sopenharmony_ci	__le32 iv_len;
4188c2ecf20Sopenharmony_ci	/* Length of source data */
4198c2ecf20Sopenharmony_ci	__le32 src_data_len;
4208c2ecf20Sopenharmony_ci	/* Length of destination data */
4218c2ecf20Sopenharmony_ci	__le32 dst_data_len;
4228c2ecf20Sopenharmony_ci	/* Starting point for cipher processing in source data */
4238c2ecf20Sopenharmony_ci	__le32 cipher_start_src_offset;
4248c2ecf20Sopenharmony_ci	/* Length of the source data that the cipher will be computed on */
4258c2ecf20Sopenharmony_ci	__le32 len_to_cipher;
4268c2ecf20Sopenharmony_ci	/* Starting point for hash processing in source data */
4278c2ecf20Sopenharmony_ci	__le32 hash_start_src_offset;
4288c2ecf20Sopenharmony_ci	/* Length of the source data that the hash will be computed on */
4298c2ecf20Sopenharmony_ci	__le32 len_to_hash;
4308c2ecf20Sopenharmony_ci	/* Length of the additional auth data */
4318c2ecf20Sopenharmony_ci	__le32 aad_len;
4328c2ecf20Sopenharmony_ci	/* Length of the hash result */
4338c2ecf20Sopenharmony_ci	__le32 hash_result_len;
4348c2ecf20Sopenharmony_ci	__le32 reserved;
4358c2ecf20Sopenharmony_ci};
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cistruct virtio_crypto_alg_chain_data_req {
4388c2ecf20Sopenharmony_ci	/* Device-readable part */
4398c2ecf20Sopenharmony_ci	struct virtio_crypto_alg_chain_data_para para;
4408c2ecf20Sopenharmony_ci};
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cistruct virtio_crypto_sym_data_req {
4438c2ecf20Sopenharmony_ci	union {
4448c2ecf20Sopenharmony_ci		struct virtio_crypto_cipher_data_req cipher;
4458c2ecf20Sopenharmony_ci		struct virtio_crypto_alg_chain_data_req chain;
4468c2ecf20Sopenharmony_ci		__u8 padding[40];
4478c2ecf20Sopenharmony_ci	} u;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* See above VIRTIO_CRYPTO_SYM_OP_* */
4508c2ecf20Sopenharmony_ci	__le32 op_type;
4518c2ecf20Sopenharmony_ci	__le32 padding;
4528c2ecf20Sopenharmony_ci};
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cistruct virtio_crypto_aead_data_req {
4558c2ecf20Sopenharmony_ci	/* Device-readable part */
4568c2ecf20Sopenharmony_ci	struct virtio_crypto_aead_para para;
4578c2ecf20Sopenharmony_ci	__u8 padding[32];
4588c2ecf20Sopenharmony_ci};
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_cistruct virtio_crypto_akcipher_para {
4618c2ecf20Sopenharmony_ci	__le32 src_data_len;
4628c2ecf20Sopenharmony_ci	__le32 dst_data_len;
4638c2ecf20Sopenharmony_ci};
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistruct virtio_crypto_akcipher_data_req {
4668c2ecf20Sopenharmony_ci	struct virtio_crypto_akcipher_para para;
4678c2ecf20Sopenharmony_ci	__u8 padding[40];
4688c2ecf20Sopenharmony_ci};
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci/* The request of the data virtqueue's packet */
4718c2ecf20Sopenharmony_cistruct virtio_crypto_op_data_req {
4728c2ecf20Sopenharmony_ci	struct virtio_crypto_op_header header;
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	union {
4758c2ecf20Sopenharmony_ci		struct virtio_crypto_sym_data_req  sym_req;
4768c2ecf20Sopenharmony_ci		struct virtio_crypto_hash_data_req hash_req;
4778c2ecf20Sopenharmony_ci		struct virtio_crypto_mac_data_req mac_req;
4788c2ecf20Sopenharmony_ci		struct virtio_crypto_aead_data_req aead_req;
4798c2ecf20Sopenharmony_ci		struct virtio_crypto_akcipher_data_req akcipher_req;
4808c2ecf20Sopenharmony_ci		__u8 padding[48];
4818c2ecf20Sopenharmony_ci	} u;
4828c2ecf20Sopenharmony_ci};
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_OK        0
4858c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_ERR       1
4868c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_BADMSG    2
4878c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NOTSUPP   3
4888c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_INVSESS   4 /* Invalid session id */
4898c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_NOSPC     5 /* no free session ID */
4908c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_KEY_REJECTED 6 /* Signature verification failed */
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci/* The accelerator hardware is ready */
4938c2ecf20Sopenharmony_ci#define VIRTIO_CRYPTO_S_HW_READY  (1 << 0)
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_cistruct virtio_crypto_config {
4968c2ecf20Sopenharmony_ci	/* See VIRTIO_CRYPTO_OP_* above */
4978c2ecf20Sopenharmony_ci	__le32  status;
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci	/*
5008c2ecf20Sopenharmony_ci	 * Maximum number of data queue
5018c2ecf20Sopenharmony_ci	 */
5028c2ecf20Sopenharmony_ci	__le32  max_dataqueues;
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci	/*
5058c2ecf20Sopenharmony_ci	 * Specifies the services mask which the device support,
5068c2ecf20Sopenharmony_ci	 * see VIRTIO_CRYPTO_SERVICE_* above
5078c2ecf20Sopenharmony_ci	 */
5088c2ecf20Sopenharmony_ci	__le32 crypto_services;
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ci	/* Detailed algorithms mask */
5118c2ecf20Sopenharmony_ci	__le32 cipher_algo_l;
5128c2ecf20Sopenharmony_ci	__le32 cipher_algo_h;
5138c2ecf20Sopenharmony_ci	__le32 hash_algo;
5148c2ecf20Sopenharmony_ci	__le32 mac_algo_l;
5158c2ecf20Sopenharmony_ci	__le32 mac_algo_h;
5168c2ecf20Sopenharmony_ci	__le32 aead_algo;
5178c2ecf20Sopenharmony_ci	/* Maximum length of cipher key */
5188c2ecf20Sopenharmony_ci	__le32 max_cipher_key_len;
5198c2ecf20Sopenharmony_ci	/* Maximum length of authenticated key */
5208c2ecf20Sopenharmony_ci	__le32 max_auth_key_len;
5218c2ecf20Sopenharmony_ci	__le32 akcipher_algo;
5228c2ecf20Sopenharmony_ci	/* Maximum size of each crypto request's content */
5238c2ecf20Sopenharmony_ci	__le64 max_size;
5248c2ecf20Sopenharmony_ci};
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_cistruct virtio_crypto_inhdr {
5278c2ecf20Sopenharmony_ci	/* See VIRTIO_CRYPTO_* above */
5288c2ecf20Sopenharmony_ci	__u8 status;
5298c2ecf20Sopenharmony_ci};
5308c2ecf20Sopenharmony_ci#endif
531