1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2*99a2dd95SBruce Richardson * Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. 3*99a2dd95SBruce Richardson */ 4*99a2dd95SBruce Richardson 5*99a2dd95SBruce Richardson #ifndef _VIRTIO_CRYPTO_H 6*99a2dd95SBruce Richardson #define _VIRTIO_CRYPTO_H 7*99a2dd95SBruce Richardson 8*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SERVICE_CIPHER 0 9*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SERVICE_HASH 1 10*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SERVICE_MAC 2 11*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SERVICE_AEAD 3 12*99a2dd95SBruce Richardson 13*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op)) 14*99a2dd95SBruce Richardson 15*99a2dd95SBruce Richardson struct virtio_crypto_ctrl_header { 16*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \ 17*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02) 18*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \ 19*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03) 20*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_CREATE_SESSION \ 21*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02) 22*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \ 23*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03) 24*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_CREATE_SESSION \ 25*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02) 26*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \ 27*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03) 28*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \ 29*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02) 30*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \ 31*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03) 32*99a2dd95SBruce Richardson uint32_t opcode; 33*99a2dd95SBruce Richardson uint32_t algo; 34*99a2dd95SBruce Richardson uint32_t flag; 35*99a2dd95SBruce Richardson /* data virtqueue id */ 36*99a2dd95SBruce Richardson uint32_t queue_id; 37*99a2dd95SBruce Richardson }; 38*99a2dd95SBruce Richardson 39*99a2dd95SBruce Richardson struct virtio_crypto_cipher_session_para { 40*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_NO_CIPHER 0 41*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_ARC4 1 42*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_AES_ECB 2 43*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_AES_CBC 3 44*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_AES_CTR 4 45*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_DES_ECB 5 46*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_DES_CBC 6 47*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7 48*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8 49*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9 50*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10 51*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11 52*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_AES_F8 12 53*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_AES_XTS 13 54*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14 55*99a2dd95SBruce Richardson uint32_t algo; 56*99a2dd95SBruce Richardson /* length of key */ 57*99a2dd95SBruce Richardson uint32_t keylen; 58*99a2dd95SBruce Richardson 59*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_OP_ENCRYPT 1 60*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_OP_DECRYPT 2 61*99a2dd95SBruce Richardson /* encrypt or decrypt */ 62*99a2dd95SBruce Richardson uint32_t op; 63*99a2dd95SBruce Richardson uint32_t padding; 64*99a2dd95SBruce Richardson }; 65*99a2dd95SBruce Richardson 66*99a2dd95SBruce Richardson struct virtio_crypto_session_input { 67*99a2dd95SBruce Richardson /* Device-writable part */ 68*99a2dd95SBruce Richardson uint64_t session_id; 69*99a2dd95SBruce Richardson uint32_t status; 70*99a2dd95SBruce Richardson uint32_t padding; 71*99a2dd95SBruce Richardson }; 72*99a2dd95SBruce Richardson 73*99a2dd95SBruce Richardson struct virtio_crypto_cipher_session_req { 74*99a2dd95SBruce Richardson struct virtio_crypto_cipher_session_para para; 75*99a2dd95SBruce Richardson uint8_t padding[32]; 76*99a2dd95SBruce Richardson }; 77*99a2dd95SBruce Richardson 78*99a2dd95SBruce Richardson struct virtio_crypto_hash_session_para { 79*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_NO_HASH 0 80*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_MD5 1 81*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA1 2 82*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA_224 3 83*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA_256 4 84*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA_384 5 85*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA_512 6 86*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA3_224 7 87*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA3_256 8 88*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA3_384 9 89*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA3_512 10 90*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11 91*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12 92*99a2dd95SBruce Richardson uint32_t algo; 93*99a2dd95SBruce Richardson /* hash result length */ 94*99a2dd95SBruce Richardson uint32_t hash_result_len; 95*99a2dd95SBruce Richardson uint8_t padding[8]; 96*99a2dd95SBruce Richardson }; 97*99a2dd95SBruce Richardson 98*99a2dd95SBruce Richardson struct virtio_crypto_hash_create_session_req { 99*99a2dd95SBruce Richardson struct virtio_crypto_hash_session_para para; 100*99a2dd95SBruce Richardson uint8_t padding[40]; 101*99a2dd95SBruce Richardson }; 102*99a2dd95SBruce Richardson 103*99a2dd95SBruce Richardson struct virtio_crypto_mac_session_para { 104*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_NO_MAC 0 105*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_HMAC_MD5 1 106*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2 107*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3 108*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4 109*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5 110*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6 111*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_CMAC_3DES 25 112*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_CMAC_AES 26 113*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_KASUMI_F9 27 114*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28 115*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_GMAC_AES 41 116*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42 117*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49 118*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50 119*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC_XCBC_AES 53 120*99a2dd95SBruce Richardson uint32_t algo; 121*99a2dd95SBruce Richardson /* hash result length */ 122*99a2dd95SBruce Richardson uint32_t hash_result_len; 123*99a2dd95SBruce Richardson /* length of authenticated key */ 124*99a2dd95SBruce Richardson uint32_t auth_key_len; 125*99a2dd95SBruce Richardson uint32_t padding; 126*99a2dd95SBruce Richardson }; 127*99a2dd95SBruce Richardson 128*99a2dd95SBruce Richardson struct virtio_crypto_mac_create_session_req { 129*99a2dd95SBruce Richardson struct virtio_crypto_mac_session_para para; 130*99a2dd95SBruce Richardson uint8_t padding[40]; 131*99a2dd95SBruce Richardson }; 132*99a2dd95SBruce Richardson 133*99a2dd95SBruce Richardson struct virtio_crypto_aead_session_para { 134*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_NO_AEAD 0 135*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_GCM 1 136*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_CCM 2 137*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3 138*99a2dd95SBruce Richardson uint32_t algo; 139*99a2dd95SBruce Richardson /* length of key */ 140*99a2dd95SBruce Richardson uint32_t key_len; 141*99a2dd95SBruce Richardson /* hash result length */ 142*99a2dd95SBruce Richardson uint32_t hash_result_len; 143*99a2dd95SBruce Richardson /* length of the additional authenticated data (AAD) in bytes */ 144*99a2dd95SBruce Richardson uint32_t aad_len; 145*99a2dd95SBruce Richardson /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ 146*99a2dd95SBruce Richardson uint32_t op; 147*99a2dd95SBruce Richardson uint32_t padding; 148*99a2dd95SBruce Richardson }; 149*99a2dd95SBruce Richardson 150*99a2dd95SBruce Richardson struct virtio_crypto_aead_create_session_req { 151*99a2dd95SBruce Richardson struct virtio_crypto_aead_session_para para; 152*99a2dd95SBruce Richardson uint8_t padding[32]; 153*99a2dd95SBruce Richardson }; 154*99a2dd95SBruce Richardson 155*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_session_para { 156*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1 157*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2 158*99a2dd95SBruce Richardson uint32_t alg_chain_order; 159*99a2dd95SBruce Richardson /* Plain hash */ 160*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1 161*99a2dd95SBruce Richardson /* Authenticated hash (mac) */ 162*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2 163*99a2dd95SBruce Richardson /* Nested hash */ 164*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3 165*99a2dd95SBruce Richardson uint32_t hash_mode; 166*99a2dd95SBruce Richardson struct virtio_crypto_cipher_session_para cipher_param; 167*99a2dd95SBruce Richardson union { 168*99a2dd95SBruce Richardson struct virtio_crypto_hash_session_para hash_param; 169*99a2dd95SBruce Richardson struct virtio_crypto_mac_session_para mac_param; 170*99a2dd95SBruce Richardson uint8_t padding[16]; 171*99a2dd95SBruce Richardson } u; 172*99a2dd95SBruce Richardson /* length of the additional authenticated data (AAD) in bytes */ 173*99a2dd95SBruce Richardson uint32_t aad_len; 174*99a2dd95SBruce Richardson uint32_t padding; 175*99a2dd95SBruce Richardson }; 176*99a2dd95SBruce Richardson 177*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_session_req { 178*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_session_para para; 179*99a2dd95SBruce Richardson }; 180*99a2dd95SBruce Richardson 181*99a2dd95SBruce Richardson struct virtio_crypto_sym_create_session_req { 182*99a2dd95SBruce Richardson union { 183*99a2dd95SBruce Richardson struct virtio_crypto_cipher_session_req cipher; 184*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_session_req chain; 185*99a2dd95SBruce Richardson uint8_t padding[48]; 186*99a2dd95SBruce Richardson } u; 187*99a2dd95SBruce Richardson 188*99a2dd95SBruce Richardson /* Device-readable part */ 189*99a2dd95SBruce Richardson 190*99a2dd95SBruce Richardson /* No operation */ 191*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_OP_NONE 0 192*99a2dd95SBruce Richardson /* Cipher only operation on the data */ 193*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_OP_CIPHER 1 194*99a2dd95SBruce Richardson /* 195*99a2dd95SBruce Richardson * Chain any cipher with any hash or mac operation. The order 196*99a2dd95SBruce Richardson * depends on the value of alg_chain_order param 197*99a2dd95SBruce Richardson */ 198*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2 199*99a2dd95SBruce Richardson uint32_t op_type; 200*99a2dd95SBruce Richardson uint32_t padding; 201*99a2dd95SBruce Richardson }; 202*99a2dd95SBruce Richardson 203*99a2dd95SBruce Richardson struct virtio_crypto_destroy_session_req { 204*99a2dd95SBruce Richardson /* Device-readable part */ 205*99a2dd95SBruce Richardson uint64_t session_id; 206*99a2dd95SBruce Richardson uint8_t padding[48]; 207*99a2dd95SBruce Richardson }; 208*99a2dd95SBruce Richardson 209*99a2dd95SBruce Richardson /* The request of the control virtqueue's packet */ 210*99a2dd95SBruce Richardson struct virtio_crypto_op_ctrl_req { 211*99a2dd95SBruce Richardson struct virtio_crypto_ctrl_header header; 212*99a2dd95SBruce Richardson 213*99a2dd95SBruce Richardson union { 214*99a2dd95SBruce Richardson struct virtio_crypto_sym_create_session_req 215*99a2dd95SBruce Richardson sym_create_session; 216*99a2dd95SBruce Richardson struct virtio_crypto_hash_create_session_req 217*99a2dd95SBruce Richardson hash_create_session; 218*99a2dd95SBruce Richardson struct virtio_crypto_mac_create_session_req 219*99a2dd95SBruce Richardson mac_create_session; 220*99a2dd95SBruce Richardson struct virtio_crypto_aead_create_session_req 221*99a2dd95SBruce Richardson aead_create_session; 222*99a2dd95SBruce Richardson struct virtio_crypto_destroy_session_req 223*99a2dd95SBruce Richardson destroy_session; 224*99a2dd95SBruce Richardson uint8_t padding[56]; 225*99a2dd95SBruce Richardson } u; 226*99a2dd95SBruce Richardson }; 227*99a2dd95SBruce Richardson 228*99a2dd95SBruce Richardson struct virtio_crypto_op_header { 229*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \ 230*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00) 231*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_CIPHER_DECRYPT \ 232*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01) 233*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_HASH \ 234*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00) 235*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_MAC \ 236*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00) 237*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_ENCRYPT \ 238*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00) 239*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_AEAD_DECRYPT \ 240*99a2dd95SBruce Richardson VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01) 241*99a2dd95SBruce Richardson uint32_t opcode; 242*99a2dd95SBruce Richardson /* algo should be service-specific algorithms */ 243*99a2dd95SBruce Richardson uint32_t algo; 244*99a2dd95SBruce Richardson /* session_id should be service-specific algorithms */ 245*99a2dd95SBruce Richardson uint64_t session_id; 246*99a2dd95SBruce Richardson /* control flag to control the request */ 247*99a2dd95SBruce Richardson uint32_t flag; 248*99a2dd95SBruce Richardson uint32_t padding; 249*99a2dd95SBruce Richardson }; 250*99a2dd95SBruce Richardson 251*99a2dd95SBruce Richardson struct virtio_crypto_cipher_para { 252*99a2dd95SBruce Richardson /* 253*99a2dd95SBruce Richardson * Byte Length of valid IV/Counter 254*99a2dd95SBruce Richardson * 255*99a2dd95SBruce Richardson * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for 256*99a2dd95SBruce Richardson * SNOW3G in UEA2 mode, this is the length of the IV (which 257*99a2dd95SBruce Richardson * must be the same as the block length of the cipher). 258*99a2dd95SBruce Richardson * For block ciphers in CTR mode, this is the length of the counter 259*99a2dd95SBruce Richardson * (which must be the same as the block length of the cipher). 260*99a2dd95SBruce Richardson * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007. 261*99a2dd95SBruce Richardson * 262*99a2dd95SBruce Richardson * The IV/Counter will be updated after every partial cryptographic 263*99a2dd95SBruce Richardson * operation. 264*99a2dd95SBruce Richardson */ 265*99a2dd95SBruce Richardson uint32_t iv_len; 266*99a2dd95SBruce Richardson /* length of source data */ 267*99a2dd95SBruce Richardson uint32_t src_data_len; 268*99a2dd95SBruce Richardson /* length of dst data */ 269*99a2dd95SBruce Richardson uint32_t dst_data_len; 270*99a2dd95SBruce Richardson uint32_t padding; 271*99a2dd95SBruce Richardson }; 272*99a2dd95SBruce Richardson 273*99a2dd95SBruce Richardson struct virtio_crypto_hash_para { 274*99a2dd95SBruce Richardson /* length of source data */ 275*99a2dd95SBruce Richardson uint32_t src_data_len; 276*99a2dd95SBruce Richardson /* hash result length */ 277*99a2dd95SBruce Richardson uint32_t hash_result_len; 278*99a2dd95SBruce Richardson }; 279*99a2dd95SBruce Richardson 280*99a2dd95SBruce Richardson struct virtio_crypto_mac_para { 281*99a2dd95SBruce Richardson struct virtio_crypto_hash_para hash; 282*99a2dd95SBruce Richardson }; 283*99a2dd95SBruce Richardson 284*99a2dd95SBruce Richardson struct virtio_crypto_aead_para { 285*99a2dd95SBruce Richardson /* 286*99a2dd95SBruce Richardson * Byte Length of valid IV data pointed to by the below iv_addr 287*99a2dd95SBruce Richardson * parameter. 288*99a2dd95SBruce Richardson * 289*99a2dd95SBruce Richardson * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which 290*99a2dd95SBruce Richardson * case iv_addr points to J0. 291*99a2dd95SBruce Richardson * For CCM mode, this is the length of the nonce, which can be in the 292*99a2dd95SBruce Richardson * range 7 to 13 inclusive. 293*99a2dd95SBruce Richardson */ 294*99a2dd95SBruce Richardson uint32_t iv_len; 295*99a2dd95SBruce Richardson /* length of additional auth data */ 296*99a2dd95SBruce Richardson uint32_t aad_len; 297*99a2dd95SBruce Richardson /* length of source data */ 298*99a2dd95SBruce Richardson uint32_t src_data_len; 299*99a2dd95SBruce Richardson /* length of dst data */ 300*99a2dd95SBruce Richardson uint32_t dst_data_len; 301*99a2dd95SBruce Richardson }; 302*99a2dd95SBruce Richardson 303*99a2dd95SBruce Richardson struct virtio_crypto_cipher_data_req { 304*99a2dd95SBruce Richardson /* Device-readable part */ 305*99a2dd95SBruce Richardson struct virtio_crypto_cipher_para para; 306*99a2dd95SBruce Richardson uint8_t padding[24]; 307*99a2dd95SBruce Richardson }; 308*99a2dd95SBruce Richardson 309*99a2dd95SBruce Richardson struct virtio_crypto_hash_data_req { 310*99a2dd95SBruce Richardson /* Device-readable part */ 311*99a2dd95SBruce Richardson struct virtio_crypto_hash_para para; 312*99a2dd95SBruce Richardson uint8_t padding[40]; 313*99a2dd95SBruce Richardson }; 314*99a2dd95SBruce Richardson 315*99a2dd95SBruce Richardson struct virtio_crypto_mac_data_req { 316*99a2dd95SBruce Richardson /* Device-readable part */ 317*99a2dd95SBruce Richardson struct virtio_crypto_mac_para para; 318*99a2dd95SBruce Richardson uint8_t padding[40]; 319*99a2dd95SBruce Richardson }; 320*99a2dd95SBruce Richardson 321*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_data_para { 322*99a2dd95SBruce Richardson uint32_t iv_len; 323*99a2dd95SBruce Richardson /* Length of source data */ 324*99a2dd95SBruce Richardson uint32_t src_data_len; 325*99a2dd95SBruce Richardson /* Length of destination data */ 326*99a2dd95SBruce Richardson uint32_t dst_data_len; 327*99a2dd95SBruce Richardson /* Starting point for cipher processing in source data */ 328*99a2dd95SBruce Richardson uint32_t cipher_start_src_offset; 329*99a2dd95SBruce Richardson /* Length of the source data that the cipher will be computed on */ 330*99a2dd95SBruce Richardson uint32_t len_to_cipher; 331*99a2dd95SBruce Richardson /* Starting point for hash processing in source data */ 332*99a2dd95SBruce Richardson uint32_t hash_start_src_offset; 333*99a2dd95SBruce Richardson /* Length of the source data that the hash will be computed on */ 334*99a2dd95SBruce Richardson uint32_t len_to_hash; 335*99a2dd95SBruce Richardson /* Length of the additional auth data */ 336*99a2dd95SBruce Richardson uint32_t aad_len; 337*99a2dd95SBruce Richardson /* Length of the hash result */ 338*99a2dd95SBruce Richardson uint32_t hash_result_len; 339*99a2dd95SBruce Richardson uint32_t reserved; 340*99a2dd95SBruce Richardson }; 341*99a2dd95SBruce Richardson 342*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_data_req { 343*99a2dd95SBruce Richardson /* Device-readable part */ 344*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_data_para para; 345*99a2dd95SBruce Richardson }; 346*99a2dd95SBruce Richardson 347*99a2dd95SBruce Richardson struct virtio_crypto_sym_data_req { 348*99a2dd95SBruce Richardson union { 349*99a2dd95SBruce Richardson struct virtio_crypto_cipher_data_req cipher; 350*99a2dd95SBruce Richardson struct virtio_crypto_alg_chain_data_req chain; 351*99a2dd95SBruce Richardson uint8_t padding[40]; 352*99a2dd95SBruce Richardson } u; 353*99a2dd95SBruce Richardson 354*99a2dd95SBruce Richardson /* See above VIRTIO_CRYPTO_SYM_OP_* */ 355*99a2dd95SBruce Richardson uint32_t op_type; 356*99a2dd95SBruce Richardson uint32_t padding; 357*99a2dd95SBruce Richardson }; 358*99a2dd95SBruce Richardson 359*99a2dd95SBruce Richardson struct virtio_crypto_aead_data_req { 360*99a2dd95SBruce Richardson /* Device-readable part */ 361*99a2dd95SBruce Richardson struct virtio_crypto_aead_para para; 362*99a2dd95SBruce Richardson uint8_t padding[32]; 363*99a2dd95SBruce Richardson }; 364*99a2dd95SBruce Richardson 365*99a2dd95SBruce Richardson /* The request of the data virtqueue's packet */ 366*99a2dd95SBruce Richardson struct virtio_crypto_op_data_req { 367*99a2dd95SBruce Richardson struct virtio_crypto_op_header header; 368*99a2dd95SBruce Richardson 369*99a2dd95SBruce Richardson union { 370*99a2dd95SBruce Richardson struct virtio_crypto_sym_data_req sym_req; 371*99a2dd95SBruce Richardson struct virtio_crypto_hash_data_req hash_req; 372*99a2dd95SBruce Richardson struct virtio_crypto_mac_data_req mac_req; 373*99a2dd95SBruce Richardson struct virtio_crypto_aead_data_req aead_req; 374*99a2dd95SBruce Richardson uint8_t padding[48]; 375*99a2dd95SBruce Richardson } u; 376*99a2dd95SBruce Richardson }; 377*99a2dd95SBruce Richardson 378*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_OK 0 379*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_ERR 1 380*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_BADMSG 2 381*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_NOTSUPP 3 382*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_INVSESS 4 /* Invalid session id */ 383*99a2dd95SBruce Richardson 384*99a2dd95SBruce Richardson /* The accelerator hardware is ready */ 385*99a2dd95SBruce Richardson #define VIRTIO_CRYPTO_S_HW_READY (1 << 0) 386*99a2dd95SBruce Richardson 387*99a2dd95SBruce Richardson struct virtio_crypto_config { 388*99a2dd95SBruce Richardson /* See VIRTIO_CRYPTO_OP_* above */ 389*99a2dd95SBruce Richardson uint32_t status; 390*99a2dd95SBruce Richardson 391*99a2dd95SBruce Richardson /* 392*99a2dd95SBruce Richardson * Maximum number of data queue 393*99a2dd95SBruce Richardson */ 394*99a2dd95SBruce Richardson uint32_t max_dataqueues; 395*99a2dd95SBruce Richardson 396*99a2dd95SBruce Richardson /* 397*99a2dd95SBruce Richardson * Specifies the services mask which the device support, 398*99a2dd95SBruce Richardson * see VIRTIO_CRYPTO_SERVICE_* above 399*99a2dd95SBruce Richardson */ 400*99a2dd95SBruce Richardson uint32_t crypto_services; 401*99a2dd95SBruce Richardson 402*99a2dd95SBruce Richardson /* Detailed algorithms mask */ 403*99a2dd95SBruce Richardson uint32_t cipher_algo_l; 404*99a2dd95SBruce Richardson uint32_t cipher_algo_h; 405*99a2dd95SBruce Richardson uint32_t hash_algo; 406*99a2dd95SBruce Richardson uint32_t mac_algo_l; 407*99a2dd95SBruce Richardson uint32_t mac_algo_h; 408*99a2dd95SBruce Richardson uint32_t aead_algo; 409*99a2dd95SBruce Richardson /* Maximum length of cipher key */ 410*99a2dd95SBruce Richardson uint32_t max_cipher_key_len; 411*99a2dd95SBruce Richardson /* Maximum length of authenticated key */ 412*99a2dd95SBruce Richardson uint32_t max_auth_key_len; 413*99a2dd95SBruce Richardson uint32_t reserve; 414*99a2dd95SBruce Richardson /* Maximum size of each crypto request's content */ 415*99a2dd95SBruce Richardson uint64_t max_size; 416*99a2dd95SBruce Richardson }; 417*99a2dd95SBruce Richardson 418*99a2dd95SBruce Richardson struct virtio_crypto_inhdr { 419*99a2dd95SBruce Richardson /* See VIRTIO_CRYPTO_* above */ 420*99a2dd95SBruce Richardson uint8_t status; 421*99a2dd95SBruce Richardson }; 422*99a2dd95SBruce Richardson #endif /* _VIRTIO_CRYPTO_H */ 423