162306a36Sopenharmony_ci#ifndef _VIRTIO_CRYPTO_H 262306a36Sopenharmony_ci#define _VIRTIO_CRYPTO_H 362306a36Sopenharmony_ci/* This header is BSD licensed so anyone can use the definitions to implement 462306a36Sopenharmony_ci * compatible drivers/servers. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 762306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 862306a36Sopenharmony_ci * are met: 962306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 1062306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 1162306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 1262306a36Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 1362306a36Sopenharmony_ci * documentation and/or other materials provided with the distribution. 1462306a36Sopenharmony_ci * 3. Neither the name of IBM nor the names of its contributors 1562306a36Sopenharmony_ci * may be used to endorse or promote products derived from this software 1662306a36Sopenharmony_ci * without specific prior written permission. 1762306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1862306a36Sopenharmony_ci * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1962306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 2062306a36Sopenharmony_ci * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR 2162306a36Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2262306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2362306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2462306a36Sopenharmony_ci * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 2562306a36Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2662306a36Sopenharmony_ci * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2762306a36Sopenharmony_ci * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2862306a36Sopenharmony_ci * SUCH DAMAGE. 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ci#include <linux/types.h> 3162306a36Sopenharmony_ci#include <linux/virtio_types.h> 3262306a36Sopenharmony_ci#include <linux/virtio_ids.h> 3362306a36Sopenharmony_ci#include <linux/virtio_config.h> 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_CIPHER 0 3762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_HASH 1 3862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_MAC 2 3962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_AEAD 3 4062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SERVICE_AKCIPHER 4 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op)) 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_cistruct virtio_crypto_ctrl_header { 4562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \ 4662306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02) 4762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \ 4862306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03) 4962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_CREATE_SESSION \ 5062306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02) 5162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \ 5262306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03) 5362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CREATE_SESSION \ 5462306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02) 5562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \ 5662306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03) 5762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \ 5862306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02) 5962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \ 6062306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03) 6162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \ 6262306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04) 6362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \ 6462306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05) 6562306a36Sopenharmony_ci __le32 opcode; 6662306a36Sopenharmony_ci __le32 algo; 6762306a36Sopenharmony_ci __le32 flag; 6862306a36Sopenharmony_ci /* data virtqueue id */ 6962306a36Sopenharmony_ci __le32 queue_id; 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_cistruct virtio_crypto_cipher_session_para { 7362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NO_CIPHER 0 7462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_ARC4 1 7562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_ECB 2 7662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_CBC 3 7762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_CTR 4 7862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DES_ECB 5 7962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DES_CBC 6 8062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7 8162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8 8262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9 8362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10 8462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11 8562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_F8 12 8662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_AES_XTS 13 8762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14 8862306a36Sopenharmony_ci __le32 algo; 8962306a36Sopenharmony_ci /* length of key */ 9062306a36Sopenharmony_ci __le32 keylen; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_OP_ENCRYPT 1 9362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_OP_DECRYPT 2 9462306a36Sopenharmony_ci /* encrypt or decrypt */ 9562306a36Sopenharmony_ci __le32 op; 9662306a36Sopenharmony_ci __le32 padding; 9762306a36Sopenharmony_ci}; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_cistruct virtio_crypto_session_input { 10062306a36Sopenharmony_ci /* Device-writable part */ 10162306a36Sopenharmony_ci __le64 session_id; 10262306a36Sopenharmony_ci __le32 status; 10362306a36Sopenharmony_ci __le32 padding; 10462306a36Sopenharmony_ci}; 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_cistruct virtio_crypto_cipher_session_req { 10762306a36Sopenharmony_ci struct virtio_crypto_cipher_session_para para; 10862306a36Sopenharmony_ci __u8 padding[32]; 10962306a36Sopenharmony_ci}; 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistruct virtio_crypto_hash_session_para { 11262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NO_HASH 0 11362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_MD5 1 11462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA1 2 11562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_224 3 11662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_256 4 11762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_384 5 11862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA_512 6 11962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_224 7 12062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_256 8 12162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_384 9 12262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_512 10 12362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11 12462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12 12562306a36Sopenharmony_ci __le32 algo; 12662306a36Sopenharmony_ci /* hash result length */ 12762306a36Sopenharmony_ci __le32 hash_result_len; 12862306a36Sopenharmony_ci __u8 padding[8]; 12962306a36Sopenharmony_ci}; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cistruct virtio_crypto_hash_create_session_req { 13262306a36Sopenharmony_ci struct virtio_crypto_hash_session_para para; 13362306a36Sopenharmony_ci __u8 padding[40]; 13462306a36Sopenharmony_ci}; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_cistruct virtio_crypto_mac_session_para { 13762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NO_MAC 0 13862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_MD5 1 13962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2 14062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3 14162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4 14262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5 14362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6 14462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CMAC_3DES 25 14562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CMAC_AES 26 14662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_KASUMI_F9 27 14762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28 14862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_GMAC_AES 41 14962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42 15062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49 15162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50 15262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC_XCBC_AES 53 15362306a36Sopenharmony_ci __le32 algo; 15462306a36Sopenharmony_ci /* hash result length */ 15562306a36Sopenharmony_ci __le32 hash_result_len; 15662306a36Sopenharmony_ci /* length of authenticated key */ 15762306a36Sopenharmony_ci __le32 auth_key_len; 15862306a36Sopenharmony_ci __le32 padding; 15962306a36Sopenharmony_ci}; 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_cistruct virtio_crypto_mac_create_session_req { 16262306a36Sopenharmony_ci struct virtio_crypto_mac_session_para para; 16362306a36Sopenharmony_ci __u8 padding[40]; 16462306a36Sopenharmony_ci}; 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_cistruct virtio_crypto_aead_session_para { 16762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NO_AEAD 0 16862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_GCM 1 16962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_CCM 2 17062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3 17162306a36Sopenharmony_ci __le32 algo; 17262306a36Sopenharmony_ci /* length of key */ 17362306a36Sopenharmony_ci __le32 key_len; 17462306a36Sopenharmony_ci /* hash result length */ 17562306a36Sopenharmony_ci __le32 hash_result_len; 17662306a36Sopenharmony_ci /* length of the additional authenticated data (AAD) in bytes */ 17762306a36Sopenharmony_ci __le32 aad_len; 17862306a36Sopenharmony_ci /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ 17962306a36Sopenharmony_ci __le32 op; 18062306a36Sopenharmony_ci __le32 padding; 18162306a36Sopenharmony_ci}; 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_cistruct virtio_crypto_aead_create_session_req { 18462306a36Sopenharmony_ci struct virtio_crypto_aead_session_para para; 18562306a36Sopenharmony_ci __u8 padding[32]; 18662306a36Sopenharmony_ci}; 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_cistruct virtio_crypto_rsa_session_para { 18962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_RAW_PADDING 0 19062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1 19162306a36Sopenharmony_ci __le32 padding_algo; 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_NO_HASH 0 19462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD2 1 19562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD3 2 19662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD4 3 19762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_MD5 4 19862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA1 5 19962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA256 6 20062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA384 7 20162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA512 8 20262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_RSA_SHA224 9 20362306a36Sopenharmony_ci __le32 hash_algo; 20462306a36Sopenharmony_ci}; 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_cistruct virtio_crypto_ecdsa_session_para { 20762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_UNKNOWN 0 20862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P192 1 20962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P224 2 21062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P256 3 21162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P384 4 21262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CURVE_NIST_P521 5 21362306a36Sopenharmony_ci __le32 curve_id; 21462306a36Sopenharmony_ci __le32 padding; 21562306a36Sopenharmony_ci}; 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_cistruct virtio_crypto_akcipher_session_para { 21862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NO_AKCIPHER 0 21962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_RSA 1 22062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_DSA 2 22162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3 22262306a36Sopenharmony_ci __le32 algo; 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC 1 22562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2 22662306a36Sopenharmony_ci __le32 keytype; 22762306a36Sopenharmony_ci __le32 keylen; 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci union { 23062306a36Sopenharmony_ci struct virtio_crypto_rsa_session_para rsa; 23162306a36Sopenharmony_ci struct virtio_crypto_ecdsa_session_para ecdsa; 23262306a36Sopenharmony_ci } u; 23362306a36Sopenharmony_ci}; 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_cistruct virtio_crypto_akcipher_create_session_req { 23662306a36Sopenharmony_ci struct virtio_crypto_akcipher_session_para para; 23762306a36Sopenharmony_ci __u8 padding[36]; 23862306a36Sopenharmony_ci}; 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_cistruct virtio_crypto_alg_chain_session_para { 24162306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1 24262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2 24362306a36Sopenharmony_ci __le32 alg_chain_order; 24462306a36Sopenharmony_ci/* Plain hash */ 24562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1 24662306a36Sopenharmony_ci/* Authenticated hash (mac) */ 24762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2 24862306a36Sopenharmony_ci/* Nested hash */ 24962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3 25062306a36Sopenharmony_ci __le32 hash_mode; 25162306a36Sopenharmony_ci struct virtio_crypto_cipher_session_para cipher_param; 25262306a36Sopenharmony_ci union { 25362306a36Sopenharmony_ci struct virtio_crypto_hash_session_para hash_param; 25462306a36Sopenharmony_ci struct virtio_crypto_mac_session_para mac_param; 25562306a36Sopenharmony_ci __u8 padding[16]; 25662306a36Sopenharmony_ci } u; 25762306a36Sopenharmony_ci /* length of the additional authenticated data (AAD) in bytes */ 25862306a36Sopenharmony_ci __le32 aad_len; 25962306a36Sopenharmony_ci __le32 padding; 26062306a36Sopenharmony_ci}; 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_cistruct virtio_crypto_alg_chain_session_req { 26362306a36Sopenharmony_ci struct virtio_crypto_alg_chain_session_para para; 26462306a36Sopenharmony_ci}; 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_cistruct virtio_crypto_sym_create_session_req { 26762306a36Sopenharmony_ci union { 26862306a36Sopenharmony_ci struct virtio_crypto_cipher_session_req cipher; 26962306a36Sopenharmony_ci struct virtio_crypto_alg_chain_session_req chain; 27062306a36Sopenharmony_ci __u8 padding[48]; 27162306a36Sopenharmony_ci } u; 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci /* Device-readable part */ 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci/* No operation */ 27662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_OP_NONE 0 27762306a36Sopenharmony_ci/* Cipher only operation on the data */ 27862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_OP_CIPHER 1 27962306a36Sopenharmony_ci/* 28062306a36Sopenharmony_ci * Chain any cipher with any hash or mac operation. The order 28162306a36Sopenharmony_ci * depends on the value of alg_chain_order param 28262306a36Sopenharmony_ci */ 28362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2 28462306a36Sopenharmony_ci __le32 op_type; 28562306a36Sopenharmony_ci __le32 padding; 28662306a36Sopenharmony_ci}; 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_cistruct virtio_crypto_destroy_session_req { 28962306a36Sopenharmony_ci /* Device-readable part */ 29062306a36Sopenharmony_ci __le64 session_id; 29162306a36Sopenharmony_ci __u8 padding[48]; 29262306a36Sopenharmony_ci}; 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci/* The request of the control virtqueue's packet */ 29562306a36Sopenharmony_cistruct virtio_crypto_op_ctrl_req { 29662306a36Sopenharmony_ci struct virtio_crypto_ctrl_header header; 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci union { 29962306a36Sopenharmony_ci struct virtio_crypto_sym_create_session_req 30062306a36Sopenharmony_ci sym_create_session; 30162306a36Sopenharmony_ci struct virtio_crypto_hash_create_session_req 30262306a36Sopenharmony_ci hash_create_session; 30362306a36Sopenharmony_ci struct virtio_crypto_mac_create_session_req 30462306a36Sopenharmony_ci mac_create_session; 30562306a36Sopenharmony_ci struct virtio_crypto_aead_create_session_req 30662306a36Sopenharmony_ci aead_create_session; 30762306a36Sopenharmony_ci struct virtio_crypto_akcipher_create_session_req 30862306a36Sopenharmony_ci akcipher_create_session; 30962306a36Sopenharmony_ci struct virtio_crypto_destroy_session_req 31062306a36Sopenharmony_ci destroy_session; 31162306a36Sopenharmony_ci __u8 padding[56]; 31262306a36Sopenharmony_ci } u; 31362306a36Sopenharmony_ci}; 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_cistruct virtio_crypto_op_header { 31662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_ENCRYPT \ 31762306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00) 31862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_CIPHER_DECRYPT \ 31962306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01) 32062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_HASH \ 32162306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00) 32262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_MAC \ 32362306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00) 32462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_ENCRYPT \ 32562306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00) 32662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AEAD_DECRYPT \ 32762306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01) 32862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \ 32962306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00) 33062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \ 33162306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01) 33262306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_SIGN \ 33362306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02) 33462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_AKCIPHER_VERIFY \ 33562306a36Sopenharmony_ci VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03) 33662306a36Sopenharmony_ci __le32 opcode; 33762306a36Sopenharmony_ci /* algo should be service-specific algorithms */ 33862306a36Sopenharmony_ci __le32 algo; 33962306a36Sopenharmony_ci /* session_id should be service-specific algorithms */ 34062306a36Sopenharmony_ci __le64 session_id; 34162306a36Sopenharmony_ci /* control flag to control the request */ 34262306a36Sopenharmony_ci __le32 flag; 34362306a36Sopenharmony_ci __le32 padding; 34462306a36Sopenharmony_ci}; 34562306a36Sopenharmony_ci 34662306a36Sopenharmony_cistruct virtio_crypto_cipher_para { 34762306a36Sopenharmony_ci /* 34862306a36Sopenharmony_ci * Byte Length of valid IV/Counter 34962306a36Sopenharmony_ci * 35062306a36Sopenharmony_ci * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for 35162306a36Sopenharmony_ci * SNOW3G in UEA2 mode, this is the length of the IV (which 35262306a36Sopenharmony_ci * must be the same as the block length of the cipher). 35362306a36Sopenharmony_ci * For block ciphers in CTR mode, this is the length of the counter 35462306a36Sopenharmony_ci * (which must be the same as the block length of the cipher). 35562306a36Sopenharmony_ci * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007. 35662306a36Sopenharmony_ci * 35762306a36Sopenharmony_ci * The IV/Counter will be updated after every partial cryptographic 35862306a36Sopenharmony_ci * operation. 35962306a36Sopenharmony_ci */ 36062306a36Sopenharmony_ci __le32 iv_len; 36162306a36Sopenharmony_ci /* length of source data */ 36262306a36Sopenharmony_ci __le32 src_data_len; 36362306a36Sopenharmony_ci /* length of dst data */ 36462306a36Sopenharmony_ci __le32 dst_data_len; 36562306a36Sopenharmony_ci __le32 padding; 36662306a36Sopenharmony_ci}; 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_cistruct virtio_crypto_hash_para { 36962306a36Sopenharmony_ci /* length of source data */ 37062306a36Sopenharmony_ci __le32 src_data_len; 37162306a36Sopenharmony_ci /* hash result length */ 37262306a36Sopenharmony_ci __le32 hash_result_len; 37362306a36Sopenharmony_ci}; 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_cistruct virtio_crypto_mac_para { 37662306a36Sopenharmony_ci struct virtio_crypto_hash_para hash; 37762306a36Sopenharmony_ci}; 37862306a36Sopenharmony_ci 37962306a36Sopenharmony_cistruct virtio_crypto_aead_para { 38062306a36Sopenharmony_ci /* 38162306a36Sopenharmony_ci * Byte Length of valid IV data pointed to by the below iv_addr 38262306a36Sopenharmony_ci * parameter. 38362306a36Sopenharmony_ci * 38462306a36Sopenharmony_ci * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which 38562306a36Sopenharmony_ci * case iv_addr points to J0. 38662306a36Sopenharmony_ci * For CCM mode, this is the length of the nonce, which can be in the 38762306a36Sopenharmony_ci * range 7 to 13 inclusive. 38862306a36Sopenharmony_ci */ 38962306a36Sopenharmony_ci __le32 iv_len; 39062306a36Sopenharmony_ci /* length of additional auth data */ 39162306a36Sopenharmony_ci __le32 aad_len; 39262306a36Sopenharmony_ci /* length of source data */ 39362306a36Sopenharmony_ci __le32 src_data_len; 39462306a36Sopenharmony_ci /* length of dst data */ 39562306a36Sopenharmony_ci __le32 dst_data_len; 39662306a36Sopenharmony_ci}; 39762306a36Sopenharmony_ci 39862306a36Sopenharmony_cistruct virtio_crypto_cipher_data_req { 39962306a36Sopenharmony_ci /* Device-readable part */ 40062306a36Sopenharmony_ci struct virtio_crypto_cipher_para para; 40162306a36Sopenharmony_ci __u8 padding[24]; 40262306a36Sopenharmony_ci}; 40362306a36Sopenharmony_ci 40462306a36Sopenharmony_cistruct virtio_crypto_hash_data_req { 40562306a36Sopenharmony_ci /* Device-readable part */ 40662306a36Sopenharmony_ci struct virtio_crypto_hash_para para; 40762306a36Sopenharmony_ci __u8 padding[40]; 40862306a36Sopenharmony_ci}; 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_cistruct virtio_crypto_mac_data_req { 41162306a36Sopenharmony_ci /* Device-readable part */ 41262306a36Sopenharmony_ci struct virtio_crypto_mac_para para; 41362306a36Sopenharmony_ci __u8 padding[40]; 41462306a36Sopenharmony_ci}; 41562306a36Sopenharmony_ci 41662306a36Sopenharmony_cistruct virtio_crypto_alg_chain_data_para { 41762306a36Sopenharmony_ci __le32 iv_len; 41862306a36Sopenharmony_ci /* Length of source data */ 41962306a36Sopenharmony_ci __le32 src_data_len; 42062306a36Sopenharmony_ci /* Length of destination data */ 42162306a36Sopenharmony_ci __le32 dst_data_len; 42262306a36Sopenharmony_ci /* Starting point for cipher processing in source data */ 42362306a36Sopenharmony_ci __le32 cipher_start_src_offset; 42462306a36Sopenharmony_ci /* Length of the source data that the cipher will be computed on */ 42562306a36Sopenharmony_ci __le32 len_to_cipher; 42662306a36Sopenharmony_ci /* Starting point for hash processing in source data */ 42762306a36Sopenharmony_ci __le32 hash_start_src_offset; 42862306a36Sopenharmony_ci /* Length of the source data that the hash will be computed on */ 42962306a36Sopenharmony_ci __le32 len_to_hash; 43062306a36Sopenharmony_ci /* Length of the additional auth data */ 43162306a36Sopenharmony_ci __le32 aad_len; 43262306a36Sopenharmony_ci /* Length of the hash result */ 43362306a36Sopenharmony_ci __le32 hash_result_len; 43462306a36Sopenharmony_ci __le32 reserved; 43562306a36Sopenharmony_ci}; 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_cistruct virtio_crypto_alg_chain_data_req { 43862306a36Sopenharmony_ci /* Device-readable part */ 43962306a36Sopenharmony_ci struct virtio_crypto_alg_chain_data_para para; 44062306a36Sopenharmony_ci}; 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_cistruct virtio_crypto_sym_data_req { 44362306a36Sopenharmony_ci union { 44462306a36Sopenharmony_ci struct virtio_crypto_cipher_data_req cipher; 44562306a36Sopenharmony_ci struct virtio_crypto_alg_chain_data_req chain; 44662306a36Sopenharmony_ci __u8 padding[40]; 44762306a36Sopenharmony_ci } u; 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci /* See above VIRTIO_CRYPTO_SYM_OP_* */ 45062306a36Sopenharmony_ci __le32 op_type; 45162306a36Sopenharmony_ci __le32 padding; 45262306a36Sopenharmony_ci}; 45362306a36Sopenharmony_ci 45462306a36Sopenharmony_cistruct virtio_crypto_aead_data_req { 45562306a36Sopenharmony_ci /* Device-readable part */ 45662306a36Sopenharmony_ci struct virtio_crypto_aead_para para; 45762306a36Sopenharmony_ci __u8 padding[32]; 45862306a36Sopenharmony_ci}; 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_cistruct virtio_crypto_akcipher_para { 46162306a36Sopenharmony_ci __le32 src_data_len; 46262306a36Sopenharmony_ci __le32 dst_data_len; 46362306a36Sopenharmony_ci}; 46462306a36Sopenharmony_ci 46562306a36Sopenharmony_cistruct virtio_crypto_akcipher_data_req { 46662306a36Sopenharmony_ci struct virtio_crypto_akcipher_para para; 46762306a36Sopenharmony_ci __u8 padding[40]; 46862306a36Sopenharmony_ci}; 46962306a36Sopenharmony_ci 47062306a36Sopenharmony_ci/* The request of the data virtqueue's packet */ 47162306a36Sopenharmony_cistruct virtio_crypto_op_data_req { 47262306a36Sopenharmony_ci struct virtio_crypto_op_header header; 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci union { 47562306a36Sopenharmony_ci struct virtio_crypto_sym_data_req sym_req; 47662306a36Sopenharmony_ci struct virtio_crypto_hash_data_req hash_req; 47762306a36Sopenharmony_ci struct virtio_crypto_mac_data_req mac_req; 47862306a36Sopenharmony_ci struct virtio_crypto_aead_data_req aead_req; 47962306a36Sopenharmony_ci struct virtio_crypto_akcipher_data_req akcipher_req; 48062306a36Sopenharmony_ci __u8 padding[48]; 48162306a36Sopenharmony_ci } u; 48262306a36Sopenharmony_ci}; 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ci#define VIRTIO_CRYPTO_OK 0 48562306a36Sopenharmony_ci#define VIRTIO_CRYPTO_ERR 1 48662306a36Sopenharmony_ci#define VIRTIO_CRYPTO_BADMSG 2 48762306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NOTSUPP 3 48862306a36Sopenharmony_ci#define VIRTIO_CRYPTO_INVSESS 4 /* Invalid session id */ 48962306a36Sopenharmony_ci#define VIRTIO_CRYPTO_NOSPC 5 /* no free session ID */ 49062306a36Sopenharmony_ci#define VIRTIO_CRYPTO_KEY_REJECTED 6 /* Signature verification failed */ 49162306a36Sopenharmony_ci 49262306a36Sopenharmony_ci/* The accelerator hardware is ready */ 49362306a36Sopenharmony_ci#define VIRTIO_CRYPTO_S_HW_READY (1 << 0) 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_cistruct virtio_crypto_config { 49662306a36Sopenharmony_ci /* See VIRTIO_CRYPTO_OP_* above */ 49762306a36Sopenharmony_ci __le32 status; 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci /* 50062306a36Sopenharmony_ci * Maximum number of data queue 50162306a36Sopenharmony_ci */ 50262306a36Sopenharmony_ci __le32 max_dataqueues; 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci /* 50562306a36Sopenharmony_ci * Specifies the services mask which the device support, 50662306a36Sopenharmony_ci * see VIRTIO_CRYPTO_SERVICE_* above 50762306a36Sopenharmony_ci */ 50862306a36Sopenharmony_ci __le32 crypto_services; 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_ci /* Detailed algorithms mask */ 51162306a36Sopenharmony_ci __le32 cipher_algo_l; 51262306a36Sopenharmony_ci __le32 cipher_algo_h; 51362306a36Sopenharmony_ci __le32 hash_algo; 51462306a36Sopenharmony_ci __le32 mac_algo_l; 51562306a36Sopenharmony_ci __le32 mac_algo_h; 51662306a36Sopenharmony_ci __le32 aead_algo; 51762306a36Sopenharmony_ci /* Maximum length of cipher key */ 51862306a36Sopenharmony_ci __le32 max_cipher_key_len; 51962306a36Sopenharmony_ci /* Maximum length of authenticated key */ 52062306a36Sopenharmony_ci __le32 max_auth_key_len; 52162306a36Sopenharmony_ci __le32 akcipher_algo; 52262306a36Sopenharmony_ci /* Maximum size of each crypto request's content */ 52362306a36Sopenharmony_ci __le64 max_size; 52462306a36Sopenharmony_ci}; 52562306a36Sopenharmony_ci 52662306a36Sopenharmony_cistruct virtio_crypto_inhdr { 52762306a36Sopenharmony_ci /* See VIRTIO_CRYPTO_* above */ 52862306a36Sopenharmony_ci __u8 status; 52962306a36Sopenharmony_ci}; 53062306a36Sopenharmony_ci#endif 531