1*f43c0076SMichael S. Tsirkin #ifndef _VIRTIO_CRYPTO_H 2*f43c0076SMichael 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. 17*f43c0076SMichael S. Tsirkin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*f43c0076SMichael S. Tsirkin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*f43c0076SMichael S. Tsirkin * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20*f43c0076SMichael S. Tsirkin * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR 21*f43c0076SMichael S. Tsirkin * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*f43c0076SMichael S. Tsirkin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*f43c0076SMichael S. Tsirkin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 24*f43c0076SMichael S. Tsirkin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25*f43c0076SMichael S. Tsirkin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26*f43c0076SMichael S. Tsirkin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 27*f43c0076SMichael S. Tsirkin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28*f43c0076SMichael S. Tsirkin * SUCH DAMAGE. 29*f43c0076SMichael S. Tsirkin */ 305551e3a8SGonglei #include "standard-headers/linux/types.h" 315551e3a8SGonglei #include "standard-headers/linux/virtio_types.h" 32*f43c0076SMichael S. Tsirkin #include "standard-headers/linux/virtio_ids.h" 33*f43c0076SMichael 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 405551e3a8SGonglei 415551e3a8SGonglei #define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op)) 425551e3a8SGonglei 435551e3a8SGonglei struct virtio_crypto_ctrl_header { 445551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \ 455551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02) 465551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \ 475551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03) 485551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_CREATE_SESSION \ 495551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02) 505551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \ 515551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03) 525551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CREATE_SESSION \ 535551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02) 545551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \ 555551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03) 565551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \ 575551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02) 585551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \ 595551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03) 60*f43c0076SMichael S. Tsirkin uint32_t opcode; 61*f43c0076SMichael S. Tsirkin uint32_t algo; 62*f43c0076SMichael S. Tsirkin uint32_t flag; 635551e3a8SGonglei /* data virtqueue id */ 64*f43c0076SMichael S. Tsirkin uint32_t queue_id; 655551e3a8SGonglei }; 665551e3a8SGonglei 675551e3a8SGonglei struct virtio_crypto_cipher_session_para { 685551e3a8SGonglei #define VIRTIO_CRYPTO_NO_CIPHER 0 695551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_ARC4 1 705551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_ECB 2 715551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_CBC 3 725551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_CTR 4 735551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DES_ECB 5 745551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DES_CBC 6 755551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7 765551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8 775551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9 785551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10 795551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11 805551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_F8 12 815551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_XTS 13 825551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14 83*f43c0076SMichael S. Tsirkin uint32_t algo; 845551e3a8SGonglei /* length of key */ 85*f43c0076SMichael S. Tsirkin uint32_t keylen; 865551e3a8SGonglei 875551e3a8SGonglei #define VIRTIO_CRYPTO_OP_ENCRYPT 1 885551e3a8SGonglei #define VIRTIO_CRYPTO_OP_DECRYPT 2 895551e3a8SGonglei /* encrypt or decrypt */ 90*f43c0076SMichael S. Tsirkin uint32_t op; 91*f43c0076SMichael S. Tsirkin uint32_t padding; 925551e3a8SGonglei }; 935551e3a8SGonglei 945551e3a8SGonglei struct virtio_crypto_session_input { 955551e3a8SGonglei /* Device-writable part */ 96*f43c0076SMichael S. Tsirkin uint64_t session_id; 97*f43c0076SMichael S. Tsirkin uint32_t status; 98*f43c0076SMichael S. Tsirkin uint32_t padding; 995551e3a8SGonglei }; 1005551e3a8SGonglei 1015551e3a8SGonglei struct virtio_crypto_cipher_session_req { 1025551e3a8SGonglei struct virtio_crypto_cipher_session_para para; 103*f43c0076SMichael S. Tsirkin uint8_t padding[32]; 1045551e3a8SGonglei }; 1055551e3a8SGonglei 1065551e3a8SGonglei struct virtio_crypto_hash_session_para { 1075551e3a8SGonglei #define VIRTIO_CRYPTO_NO_HASH 0 1085551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_MD5 1 1095551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA1 2 1105551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_224 3 1115551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_256 4 1125551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_384 5 1135551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA_512 6 1145551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_224 7 1155551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_256 8 1165551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_384 9 1175551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_512 10 1185551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11 1195551e3a8SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12 120*f43c0076SMichael S. Tsirkin uint32_t algo; 1215551e3a8SGonglei /* hash result length */ 122*f43c0076SMichael S. Tsirkin uint32_t hash_result_len; 123*f43c0076SMichael S. Tsirkin uint8_t padding[8]; 1245551e3a8SGonglei }; 1255551e3a8SGonglei 1265551e3a8SGonglei struct virtio_crypto_hash_create_session_req { 1275551e3a8SGonglei struct virtio_crypto_hash_session_para para; 128*f43c0076SMichael S. Tsirkin uint8_t padding[40]; 1295551e3a8SGonglei }; 1305551e3a8SGonglei 1315551e3a8SGonglei struct virtio_crypto_mac_session_para { 1325551e3a8SGonglei #define VIRTIO_CRYPTO_NO_MAC 0 1335551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_MD5 1 1345551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2 1355551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3 1365551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4 1375551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5 1385551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6 1395551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CMAC_3DES 25 1405551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CMAC_AES 26 1415551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_KASUMI_F9 27 1425551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28 1435551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_GMAC_AES 41 1445551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42 1455551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49 1465551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50 1475551e3a8SGonglei #define VIRTIO_CRYPTO_MAC_XCBC_AES 53 148*f43c0076SMichael S. Tsirkin uint32_t algo; 1495551e3a8SGonglei /* hash result length */ 150*f43c0076SMichael S. Tsirkin uint32_t hash_result_len; 1515551e3a8SGonglei /* length of authenticated key */ 152*f43c0076SMichael S. Tsirkin uint32_t auth_key_len; 153*f43c0076SMichael S. Tsirkin uint32_t padding; 1545551e3a8SGonglei }; 1555551e3a8SGonglei 1565551e3a8SGonglei struct virtio_crypto_mac_create_session_req { 1575551e3a8SGonglei struct virtio_crypto_mac_session_para para; 158*f43c0076SMichael S. Tsirkin uint8_t padding[40]; 1595551e3a8SGonglei }; 1605551e3a8SGonglei 1615551e3a8SGonglei struct virtio_crypto_aead_session_para { 1625551e3a8SGonglei #define VIRTIO_CRYPTO_NO_AEAD 0 1635551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_GCM 1 1645551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_CCM 2 1655551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3 166*f43c0076SMichael S. Tsirkin uint32_t algo; 1675551e3a8SGonglei /* length of key */ 168*f43c0076SMichael S. Tsirkin uint32_t key_len; 169*f43c0076SMichael S. Tsirkin /* hash result length */ 170*f43c0076SMichael S. Tsirkin uint32_t hash_result_len; 1715551e3a8SGonglei /* length of the additional authenticated data (AAD) in bytes */ 172*f43c0076SMichael S. Tsirkin uint32_t aad_len; 1735551e3a8SGonglei /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ 174*f43c0076SMichael S. Tsirkin uint32_t op; 175*f43c0076SMichael S. Tsirkin uint32_t padding; 1765551e3a8SGonglei }; 1775551e3a8SGonglei 1785551e3a8SGonglei struct virtio_crypto_aead_create_session_req { 1795551e3a8SGonglei struct virtio_crypto_aead_session_para para; 180*f43c0076SMichael S. Tsirkin uint8_t padding[32]; 1815551e3a8SGonglei }; 1825551e3a8SGonglei 1835551e3a8SGonglei struct virtio_crypto_alg_chain_session_para { 1845551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1 1855551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2 186*f43c0076SMichael S. Tsirkin uint32_t alg_chain_order; 1875551e3a8SGonglei /* Plain hash */ 1885551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1 1895551e3a8SGonglei /* Authenticated hash (mac) */ 1905551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2 1915551e3a8SGonglei /* Nested hash */ 1925551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3 193*f43c0076SMichael S. Tsirkin uint32_t hash_mode; 1945551e3a8SGonglei struct virtio_crypto_cipher_session_para cipher_param; 1955551e3a8SGonglei union { 1965551e3a8SGonglei struct virtio_crypto_hash_session_para hash_param; 1975551e3a8SGonglei struct virtio_crypto_mac_session_para mac_param; 198*f43c0076SMichael S. Tsirkin uint8_t padding[16]; 1995551e3a8SGonglei } u; 2005551e3a8SGonglei /* length of the additional authenticated data (AAD) in bytes */ 201*f43c0076SMichael S. Tsirkin uint32_t aad_len; 202*f43c0076SMichael S. Tsirkin uint32_t padding; 2035551e3a8SGonglei }; 2045551e3a8SGonglei 2055551e3a8SGonglei struct virtio_crypto_alg_chain_session_req { 2065551e3a8SGonglei struct virtio_crypto_alg_chain_session_para para; 2075551e3a8SGonglei }; 2085551e3a8SGonglei 2095551e3a8SGonglei struct virtio_crypto_sym_create_session_req { 2105551e3a8SGonglei union { 2115551e3a8SGonglei struct virtio_crypto_cipher_session_req cipher; 2125551e3a8SGonglei struct virtio_crypto_alg_chain_session_req chain; 213*f43c0076SMichael S. Tsirkin uint8_t padding[48]; 2145551e3a8SGonglei } u; 2155551e3a8SGonglei 2165551e3a8SGonglei /* Device-readable part */ 2175551e3a8SGonglei 2185551e3a8SGonglei /* No operation */ 2195551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_OP_NONE 0 2205551e3a8SGonglei /* Cipher only operation on the data */ 2215551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_OP_CIPHER 1 222*f43c0076SMichael S. Tsirkin /* 223*f43c0076SMichael S. Tsirkin * Chain any cipher with any hash or mac operation. The order 224*f43c0076SMichael S. Tsirkin * depends on the value of alg_chain_order param 225*f43c0076SMichael S. Tsirkin */ 2265551e3a8SGonglei #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2 227*f43c0076SMichael S. Tsirkin uint32_t op_type; 228*f43c0076SMichael S. Tsirkin uint32_t padding; 2295551e3a8SGonglei }; 2305551e3a8SGonglei 2315551e3a8SGonglei struct virtio_crypto_destroy_session_req { 2325551e3a8SGonglei /* Device-readable part */ 233*f43c0076SMichael S. Tsirkin uint64_t session_id; 234*f43c0076SMichael S. Tsirkin uint8_t padding[48]; 2355551e3a8SGonglei }; 2365551e3a8SGonglei 237*f43c0076SMichael S. Tsirkin /* The request of the control virtqueue's packet */ 2385551e3a8SGonglei struct virtio_crypto_op_ctrl_req { 2395551e3a8SGonglei struct virtio_crypto_ctrl_header header; 2405551e3a8SGonglei 2415551e3a8SGonglei union { 242*f43c0076SMichael S. Tsirkin struct virtio_crypto_sym_create_session_req 243*f43c0076SMichael S. Tsirkin sym_create_session; 244*f43c0076SMichael S. Tsirkin struct virtio_crypto_hash_create_session_req 245*f43c0076SMichael S. Tsirkin hash_create_session; 246*f43c0076SMichael S. Tsirkin struct virtio_crypto_mac_create_session_req 247*f43c0076SMichael S. Tsirkin mac_create_session; 248*f43c0076SMichael S. Tsirkin struct virtio_crypto_aead_create_session_req 249*f43c0076SMichael S. Tsirkin aead_create_session; 250*f43c0076SMichael S. Tsirkin struct virtio_crypto_destroy_session_req 251*f43c0076SMichael S. Tsirkin destroy_session; 252*f43c0076SMichael S. Tsirkin uint8_t padding[56]; 2535551e3a8SGonglei } u; 2545551e3a8SGonglei }; 2555551e3a8SGonglei 2565551e3a8SGonglei struct virtio_crypto_op_header { 2575551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \ 2585551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00) 2595551e3a8SGonglei #define VIRTIO_CRYPTO_CIPHER_DECRYPT \ 2605551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01) 2615551e3a8SGonglei #define VIRTIO_CRYPTO_HASH \ 2625551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00) 2635551e3a8SGonglei #define VIRTIO_CRYPTO_MAC \ 2645551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00) 2655551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_ENCRYPT \ 2665551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00) 2675551e3a8SGonglei #define VIRTIO_CRYPTO_AEAD_DECRYPT \ 2685551e3a8SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01) 269*f43c0076SMichael S. Tsirkin uint32_t opcode; 2705551e3a8SGonglei /* algo should be service-specific algorithms */ 271*f43c0076SMichael S. Tsirkin uint32_t algo; 2725551e3a8SGonglei /* session_id should be service-specific algorithms */ 273*f43c0076SMichael S. Tsirkin uint64_t session_id; 2745551e3a8SGonglei /* control flag to control the request */ 275*f43c0076SMichael S. Tsirkin uint32_t flag; 276*f43c0076SMichael S. Tsirkin uint32_t padding; 2775551e3a8SGonglei }; 2785551e3a8SGonglei 2795551e3a8SGonglei struct virtio_crypto_cipher_para { 2805551e3a8SGonglei /* 2815551e3a8SGonglei * Byte Length of valid IV/Counter 2825551e3a8SGonglei * 283*f43c0076SMichael S. Tsirkin * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for 2845551e3a8SGonglei * SNOW3G in UEA2 mode, this is the length of the IV (which 2855551e3a8SGonglei * must be the same as the block length of the cipher). 286*f43c0076SMichael S. Tsirkin * For block ciphers in CTR mode, this is the length of the counter 2875551e3a8SGonglei * (which must be the same as the block length of the cipher). 288*f43c0076SMichael S. Tsirkin * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007. 2895551e3a8SGonglei * 2905551e3a8SGonglei * The IV/Counter will be updated after every partial cryptographic 2915551e3a8SGonglei * operation. 2925551e3a8SGonglei */ 293*f43c0076SMichael S. Tsirkin uint32_t iv_len; 2945551e3a8SGonglei /* length of source data */ 295*f43c0076SMichael S. Tsirkin uint32_t src_data_len; 2965551e3a8SGonglei /* length of dst data */ 297*f43c0076SMichael S. Tsirkin uint32_t dst_data_len; 298*f43c0076SMichael S. Tsirkin uint32_t padding; 2995551e3a8SGonglei }; 3005551e3a8SGonglei 3015551e3a8SGonglei struct virtio_crypto_hash_para { 3025551e3a8SGonglei /* length of source data */ 303*f43c0076SMichael S. Tsirkin uint32_t src_data_len; 3045551e3a8SGonglei /* hash result length */ 305*f43c0076SMichael S. Tsirkin uint32_t hash_result_len; 3065551e3a8SGonglei }; 3075551e3a8SGonglei 3085551e3a8SGonglei struct virtio_crypto_mac_para { 3095551e3a8SGonglei struct virtio_crypto_hash_para hash; 3105551e3a8SGonglei }; 3115551e3a8SGonglei 3125551e3a8SGonglei struct virtio_crypto_aead_para { 3135551e3a8SGonglei /* 3145551e3a8SGonglei * Byte Length of valid IV data pointed to by the below iv_addr 3155551e3a8SGonglei * parameter. 3165551e3a8SGonglei * 317*f43c0076SMichael S. Tsirkin * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which 3185551e3a8SGonglei * case iv_addr points to J0. 319*f43c0076SMichael S. Tsirkin * For CCM mode, this is the length of the nonce, which can be in the 3205551e3a8SGonglei * range 7 to 13 inclusive. 3215551e3a8SGonglei */ 322*f43c0076SMichael S. Tsirkin uint32_t iv_len; 3235551e3a8SGonglei /* length of additional auth data */ 324*f43c0076SMichael S. Tsirkin uint32_t aad_len; 3255551e3a8SGonglei /* length of source data */ 326*f43c0076SMichael S. Tsirkin uint32_t src_data_len; 3275551e3a8SGonglei /* length of dst data */ 328*f43c0076SMichael S. Tsirkin uint32_t dst_data_len; 3295551e3a8SGonglei }; 3305551e3a8SGonglei 3315551e3a8SGonglei struct virtio_crypto_cipher_data_req { 3325551e3a8SGonglei /* Device-readable part */ 3335551e3a8SGonglei struct virtio_crypto_cipher_para para; 334*f43c0076SMichael S. Tsirkin uint8_t padding[24]; 3355551e3a8SGonglei }; 3365551e3a8SGonglei 3375551e3a8SGonglei struct virtio_crypto_hash_data_req { 3385551e3a8SGonglei /* Device-readable part */ 3395551e3a8SGonglei struct virtio_crypto_hash_para para; 340*f43c0076SMichael S. Tsirkin uint8_t padding[40]; 3415551e3a8SGonglei }; 3425551e3a8SGonglei 3435551e3a8SGonglei struct virtio_crypto_mac_data_req { 3445551e3a8SGonglei /* Device-readable part */ 3455551e3a8SGonglei struct virtio_crypto_mac_para para; 346*f43c0076SMichael S. Tsirkin uint8_t padding[40]; 3475551e3a8SGonglei }; 3485551e3a8SGonglei 3495551e3a8SGonglei struct virtio_crypto_alg_chain_data_para { 350*f43c0076SMichael S. Tsirkin uint32_t iv_len; 3515551e3a8SGonglei /* Length of source data */ 352*f43c0076SMichael S. Tsirkin uint32_t src_data_len; 3535551e3a8SGonglei /* Length of destination data */ 354*f43c0076SMichael S. Tsirkin uint32_t dst_data_len; 3555551e3a8SGonglei /* Starting point for cipher processing in source data */ 356*f43c0076SMichael S. Tsirkin uint32_t cipher_start_src_offset; 3575551e3a8SGonglei /* Length of the source data that the cipher will be computed on */ 358*f43c0076SMichael S. Tsirkin uint32_t len_to_cipher; 3595551e3a8SGonglei /* Starting point for hash processing in source data */ 360*f43c0076SMichael S. Tsirkin uint32_t hash_start_src_offset; 3615551e3a8SGonglei /* Length of the source data that the hash will be computed on */ 362*f43c0076SMichael S. Tsirkin uint32_t len_to_hash; 3635551e3a8SGonglei /* Length of the additional auth data */ 364*f43c0076SMichael S. Tsirkin uint32_t aad_len; 3655551e3a8SGonglei /* Length of the hash result */ 366*f43c0076SMichael S. Tsirkin uint32_t hash_result_len; 367*f43c0076SMichael S. Tsirkin uint32_t reserved; 3685551e3a8SGonglei }; 3695551e3a8SGonglei 3705551e3a8SGonglei struct virtio_crypto_alg_chain_data_req { 3715551e3a8SGonglei /* Device-readable part */ 3725551e3a8SGonglei struct virtio_crypto_alg_chain_data_para para; 3735551e3a8SGonglei }; 3745551e3a8SGonglei 3755551e3a8SGonglei struct virtio_crypto_sym_data_req { 3765551e3a8SGonglei union { 3775551e3a8SGonglei struct virtio_crypto_cipher_data_req cipher; 3785551e3a8SGonglei struct virtio_crypto_alg_chain_data_req chain; 379*f43c0076SMichael S. Tsirkin uint8_t padding[40]; 3805551e3a8SGonglei } u; 3815551e3a8SGonglei 3825551e3a8SGonglei /* See above VIRTIO_CRYPTO_SYM_OP_* */ 383*f43c0076SMichael S. Tsirkin uint32_t op_type; 384*f43c0076SMichael S. Tsirkin uint32_t padding; 3855551e3a8SGonglei }; 3865551e3a8SGonglei 3875551e3a8SGonglei struct virtio_crypto_aead_data_req { 3885551e3a8SGonglei /* Device-readable part */ 3895551e3a8SGonglei struct virtio_crypto_aead_para para; 390*f43c0076SMichael S. Tsirkin uint8_t padding[32]; 3915551e3a8SGonglei }; 3925551e3a8SGonglei 393*f43c0076SMichael S. Tsirkin /* The request of the data virtqueue's packet */ 3945551e3a8SGonglei struct virtio_crypto_op_data_req { 3955551e3a8SGonglei struct virtio_crypto_op_header header; 3965551e3a8SGonglei 3975551e3a8SGonglei union { 3985551e3a8SGonglei struct virtio_crypto_sym_data_req sym_req; 3995551e3a8SGonglei struct virtio_crypto_hash_data_req hash_req; 4005551e3a8SGonglei struct virtio_crypto_mac_data_req mac_req; 4015551e3a8SGonglei struct virtio_crypto_aead_data_req aead_req; 402*f43c0076SMichael S. Tsirkin uint8_t padding[48]; 4035551e3a8SGonglei } u; 4045551e3a8SGonglei }; 4055551e3a8SGonglei 4065551e3a8SGonglei #define VIRTIO_CRYPTO_OK 0 4075551e3a8SGonglei #define VIRTIO_CRYPTO_ERR 1 4085551e3a8SGonglei #define VIRTIO_CRYPTO_BADMSG 2 4095551e3a8SGonglei #define VIRTIO_CRYPTO_NOTSUPP 3 410*f43c0076SMichael S. Tsirkin #define VIRTIO_CRYPTO_INVSESS 4 /* Invalid session id */ 4115551e3a8SGonglei 4125551e3a8SGonglei /* The accelerator hardware is ready */ 4135551e3a8SGonglei #define VIRTIO_CRYPTO_S_HW_READY (1 << 0) 4145551e3a8SGonglei 4155551e3a8SGonglei struct virtio_crypto_config { 416*f43c0076SMichael S. Tsirkin /* See VIRTIO_CRYPTO_OP_* above */ 417*f43c0076SMichael S. Tsirkin uint32_t status; 4185551e3a8SGonglei 4195551e3a8SGonglei /* 420*f43c0076SMichael S. Tsirkin * Maximum number of data queue 4215551e3a8SGonglei */ 422*f43c0076SMichael S. Tsirkin uint32_t max_dataqueues; 4235551e3a8SGonglei 424*f43c0076SMichael S. Tsirkin /* 425*f43c0076SMichael S. Tsirkin * Specifies the services mask which the device support, 426*f43c0076SMichael S. Tsirkin * see VIRTIO_CRYPTO_SERVICE_* above 427*f43c0076SMichael S. Tsirkin */ 428*f43c0076SMichael S. Tsirkin uint32_t crypto_services; 4295551e3a8SGonglei 4305551e3a8SGonglei /* Detailed algorithms mask */ 431*f43c0076SMichael S. Tsirkin uint32_t cipher_algo_l; 432*f43c0076SMichael S. Tsirkin uint32_t cipher_algo_h; 433*f43c0076SMichael S. Tsirkin uint32_t hash_algo; 434*f43c0076SMichael S. Tsirkin uint32_t mac_algo_l; 435*f43c0076SMichael S. Tsirkin uint32_t mac_algo_h; 436*f43c0076SMichael S. Tsirkin uint32_t aead_algo; 4375551e3a8SGonglei /* Maximum length of cipher key */ 4385551e3a8SGonglei uint32_t max_cipher_key_len; 4395551e3a8SGonglei /* Maximum length of authenticated key */ 4405551e3a8SGonglei uint32_t max_auth_key_len; 441*f43c0076SMichael S. Tsirkin uint32_t reserve; 442*f43c0076SMichael S. Tsirkin /* Maximum size of each crypto request's content */ 443*f43c0076SMichael S. Tsirkin uint64_t max_size; 4445551e3a8SGonglei }; 4455551e3a8SGonglei 4465551e3a8SGonglei struct virtio_crypto_inhdr { 4475551e3a8SGonglei /* See VIRTIO_CRYPTO_* above */ 4485551e3a8SGonglei uint8_t status; 4495551e3a8SGonglei }; 450*f43c0076SMichael S. Tsirkin #endif 451