1dbaf0624SGonglei #ifndef _VIRTIO_CRYPTO_H 2dbaf0624SGonglei #define _VIRTIO_CRYPTO_H 3dbaf0624SGonglei /* This header is BSD licensed so anyone can use the definitions to implement 4dbaf0624SGonglei * compatible drivers/servers. 5dbaf0624SGonglei * 6dbaf0624SGonglei * Redistribution and use in source and binary forms, with or without 7dbaf0624SGonglei * modification, are permitted provided that the following conditions 8dbaf0624SGonglei * are met: 9dbaf0624SGonglei * 1. Redistributions of source code must retain the above copyright 10dbaf0624SGonglei * notice, this list of conditions and the following disclaimer. 11dbaf0624SGonglei * 2. Redistributions in binary form must reproduce the above copyright 12dbaf0624SGonglei * notice, this list of conditions and the following disclaimer in the 13dbaf0624SGonglei * documentation and/or other materials provided with the distribution. 14dbaf0624SGonglei * 3. Neither the name of IBM nor the names of its contributors 15dbaf0624SGonglei * may be used to endorse or promote products derived from this software 16dbaf0624SGonglei * without specific prior written permission. 17dbaf0624SGonglei * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18dbaf0624SGonglei * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19dbaf0624SGonglei * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20dbaf0624SGonglei * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR 21dbaf0624SGonglei * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22dbaf0624SGonglei * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23dbaf0624SGonglei * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 24dbaf0624SGonglei * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25dbaf0624SGonglei * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26dbaf0624SGonglei * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 27dbaf0624SGonglei * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28dbaf0624SGonglei * SUCH DAMAGE. 29dbaf0624SGonglei */ 30dbaf0624SGonglei #include <linux/types.h> 31dbaf0624SGonglei #include <linux/virtio_types.h> 32dbaf0624SGonglei #include <linux/virtio_ids.h> 33dbaf0624SGonglei #include <linux/virtio_config.h> 34dbaf0624SGonglei 35dbaf0624SGonglei 36dbaf0624SGonglei #define VIRTIO_CRYPTO_SERVICE_CIPHER 0 37dbaf0624SGonglei #define VIRTIO_CRYPTO_SERVICE_HASH 1 38dbaf0624SGonglei #define VIRTIO_CRYPTO_SERVICE_MAC 2 39dbaf0624SGonglei #define VIRTIO_CRYPTO_SERVICE_AEAD 3 4024e19590Szhenwei pi #define VIRTIO_CRYPTO_SERVICE_AKCIPHER 4 41dbaf0624SGonglei 42dbaf0624SGonglei #define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op)) 43dbaf0624SGonglei 44dbaf0624SGonglei struct virtio_crypto_ctrl_header { 45dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \ 46dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02) 47dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \ 48dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03) 49dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_CREATE_SESSION \ 50dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02) 51dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \ 52dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03) 53dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_CREATE_SESSION \ 54dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02) 55dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \ 56dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03) 57dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \ 58dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02) 59dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \ 60dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03) 6124e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \ 6224e19590Szhenwei pi VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04) 6324e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \ 6424e19590Szhenwei pi VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05) 65dbaf0624SGonglei __le32 opcode; 66dbaf0624SGonglei __le32 algo; 67dbaf0624SGonglei __le32 flag; 68dbaf0624SGonglei /* data virtqueue id */ 69dbaf0624SGonglei __le32 queue_id; 70dbaf0624SGonglei }; 71dbaf0624SGonglei 72dbaf0624SGonglei struct virtio_crypto_cipher_session_para { 73dbaf0624SGonglei #define VIRTIO_CRYPTO_NO_CIPHER 0 74dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_ARC4 1 75dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_ECB 2 76dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_CBC 3 77dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_CTR 4 78dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_DES_ECB 5 79dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_DES_CBC 6 80dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7 81dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8 82dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9 83dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10 84dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11 85dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_F8 12 86dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_AES_XTS 13 87dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14 88dbaf0624SGonglei __le32 algo; 89dbaf0624SGonglei /* length of key */ 90dbaf0624SGonglei __le32 keylen; 91dbaf0624SGonglei 92dbaf0624SGonglei #define VIRTIO_CRYPTO_OP_ENCRYPT 1 93dbaf0624SGonglei #define VIRTIO_CRYPTO_OP_DECRYPT 2 94dbaf0624SGonglei /* encrypt or decrypt */ 95dbaf0624SGonglei __le32 op; 96dbaf0624SGonglei __le32 padding; 97dbaf0624SGonglei }; 98dbaf0624SGonglei 99dbaf0624SGonglei struct virtio_crypto_session_input { 100dbaf0624SGonglei /* Device-writable part */ 101dbaf0624SGonglei __le64 session_id; 102dbaf0624SGonglei __le32 status; 103dbaf0624SGonglei __le32 padding; 104dbaf0624SGonglei }; 105dbaf0624SGonglei 106dbaf0624SGonglei struct virtio_crypto_cipher_session_req { 107dbaf0624SGonglei struct virtio_crypto_cipher_session_para para; 108dbaf0624SGonglei __u8 padding[32]; 109dbaf0624SGonglei }; 110dbaf0624SGonglei 111dbaf0624SGonglei struct virtio_crypto_hash_session_para { 112dbaf0624SGonglei #define VIRTIO_CRYPTO_NO_HASH 0 113dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_MD5 1 114dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA1 2 115dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA_224 3 116dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA_256 4 117dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA_384 5 118dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA_512 6 119dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_224 7 120dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_256 8 121dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_384 9 122dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_512 10 123dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11 124dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12 125dbaf0624SGonglei __le32 algo; 126dbaf0624SGonglei /* hash result length */ 127dbaf0624SGonglei __le32 hash_result_len; 128dbaf0624SGonglei __u8 padding[8]; 129dbaf0624SGonglei }; 130dbaf0624SGonglei 131dbaf0624SGonglei struct virtio_crypto_hash_create_session_req { 132dbaf0624SGonglei struct virtio_crypto_hash_session_para para; 133dbaf0624SGonglei __u8 padding[40]; 134dbaf0624SGonglei }; 135dbaf0624SGonglei 136dbaf0624SGonglei struct virtio_crypto_mac_session_para { 137dbaf0624SGonglei #define VIRTIO_CRYPTO_NO_MAC 0 138dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_MD5 1 139dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2 140dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3 141dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4 142dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5 143dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6 144dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_CMAC_3DES 25 145dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_CMAC_AES 26 146dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_KASUMI_F9 27 147dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28 148dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_GMAC_AES 41 149dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42 150dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49 151dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50 152dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC_XCBC_AES 53 153dbaf0624SGonglei __le32 algo; 154dbaf0624SGonglei /* hash result length */ 155dbaf0624SGonglei __le32 hash_result_len; 156dbaf0624SGonglei /* length of authenticated key */ 157dbaf0624SGonglei __le32 auth_key_len; 158dbaf0624SGonglei __le32 padding; 159dbaf0624SGonglei }; 160dbaf0624SGonglei 161dbaf0624SGonglei struct virtio_crypto_mac_create_session_req { 162dbaf0624SGonglei struct virtio_crypto_mac_session_para para; 163dbaf0624SGonglei __u8 padding[40]; 164dbaf0624SGonglei }; 165dbaf0624SGonglei 166dbaf0624SGonglei struct virtio_crypto_aead_session_para { 167dbaf0624SGonglei #define VIRTIO_CRYPTO_NO_AEAD 0 168dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_GCM 1 169dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_CCM 2 170dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3 171dbaf0624SGonglei __le32 algo; 172dbaf0624SGonglei /* length of key */ 173dbaf0624SGonglei __le32 key_len; 174dbaf0624SGonglei /* hash result length */ 175dbaf0624SGonglei __le32 hash_result_len; 176dbaf0624SGonglei /* length of the additional authenticated data (AAD) in bytes */ 177dbaf0624SGonglei __le32 aad_len; 178dbaf0624SGonglei /* encrypt or decrypt, See above VIRTIO_CRYPTO_OP_* */ 179dbaf0624SGonglei __le32 op; 180dbaf0624SGonglei __le32 padding; 181dbaf0624SGonglei }; 182dbaf0624SGonglei 183dbaf0624SGonglei struct virtio_crypto_aead_create_session_req { 184dbaf0624SGonglei struct virtio_crypto_aead_session_para para; 185dbaf0624SGonglei __u8 padding[32]; 186dbaf0624SGonglei }; 187dbaf0624SGonglei 18824e19590Szhenwei pi struct virtio_crypto_rsa_session_para { 18924e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_RAW_PADDING 0 19024e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1 19124e19590Szhenwei pi __le32 padding_algo; 19224e19590Szhenwei pi 19324e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_NO_HASH 0 19424e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD2 1 19524e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD3 2 19624e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD4 3 19724e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD5 4 19824e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA1 5 19924e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA256 6 20024e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA384 7 20124e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA512 8 20224e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA224 9 20324e19590Szhenwei pi __le32 hash_algo; 20424e19590Szhenwei pi }; 20524e19590Szhenwei pi 20624e19590Szhenwei pi struct virtio_crypto_ecdsa_session_para { 20724e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_UNKNOWN 0 20824e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P192 1 20924e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P224 2 21024e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P256 3 21124e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P384 4 21224e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P521 5 21324e19590Szhenwei pi __le32 curve_id; 21424e19590Szhenwei pi __le32 padding; 21524e19590Szhenwei pi }; 21624e19590Szhenwei pi 21724e19590Szhenwei pi struct virtio_crypto_akcipher_session_para { 21824e19590Szhenwei pi #define VIRTIO_CRYPTO_NO_AKCIPHER 0 21924e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_RSA 1 22024e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_DSA 2 22124e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3 22224e19590Szhenwei pi __le32 algo; 22324e19590Szhenwei pi 22424e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC 1 22524e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2 22624e19590Szhenwei pi __le32 keytype; 22724e19590Szhenwei pi __le32 keylen; 22824e19590Szhenwei pi 22924e19590Szhenwei pi union { 23024e19590Szhenwei pi struct virtio_crypto_rsa_session_para rsa; 23124e19590Szhenwei pi struct virtio_crypto_ecdsa_session_para ecdsa; 23224e19590Szhenwei pi } u; 23324e19590Szhenwei pi }; 23424e19590Szhenwei pi 23524e19590Szhenwei pi struct virtio_crypto_akcipher_create_session_req { 23624e19590Szhenwei pi struct virtio_crypto_akcipher_session_para para; 23724e19590Szhenwei pi __u8 padding[36]; 23824e19590Szhenwei pi }; 23924e19590Szhenwei pi 240dbaf0624SGonglei struct virtio_crypto_alg_chain_session_para { 241dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1 242dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2 243dbaf0624SGonglei __le32 alg_chain_order; 244dbaf0624SGonglei /* Plain hash */ 245dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1 246dbaf0624SGonglei /* Authenticated hash (mac) */ 247dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2 248dbaf0624SGonglei /* Nested hash */ 249dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3 250dbaf0624SGonglei __le32 hash_mode; 251dbaf0624SGonglei struct virtio_crypto_cipher_session_para cipher_param; 252dbaf0624SGonglei union { 253dbaf0624SGonglei struct virtio_crypto_hash_session_para hash_param; 254dbaf0624SGonglei struct virtio_crypto_mac_session_para mac_param; 255dbaf0624SGonglei __u8 padding[16]; 256dbaf0624SGonglei } u; 257dbaf0624SGonglei /* length of the additional authenticated data (AAD) in bytes */ 258dbaf0624SGonglei __le32 aad_len; 259dbaf0624SGonglei __le32 padding; 260dbaf0624SGonglei }; 261dbaf0624SGonglei 262dbaf0624SGonglei struct virtio_crypto_alg_chain_session_req { 263dbaf0624SGonglei struct virtio_crypto_alg_chain_session_para para; 264dbaf0624SGonglei }; 265dbaf0624SGonglei 266dbaf0624SGonglei struct virtio_crypto_sym_create_session_req { 267dbaf0624SGonglei union { 268dbaf0624SGonglei struct virtio_crypto_cipher_session_req cipher; 269dbaf0624SGonglei struct virtio_crypto_alg_chain_session_req chain; 270dbaf0624SGonglei __u8 padding[48]; 271dbaf0624SGonglei } u; 272dbaf0624SGonglei 273dbaf0624SGonglei /* Device-readable part */ 274dbaf0624SGonglei 275dbaf0624SGonglei /* No operation */ 276dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_OP_NONE 0 277dbaf0624SGonglei /* Cipher only operation on the data */ 278dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_OP_CIPHER 1 279dbaf0624SGonglei /* 280dbaf0624SGonglei * Chain any cipher with any hash or mac operation. The order 281dbaf0624SGonglei * depends on the value of alg_chain_order param 282dbaf0624SGonglei */ 283dbaf0624SGonglei #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2 284dbaf0624SGonglei __le32 op_type; 285dbaf0624SGonglei __le32 padding; 286dbaf0624SGonglei }; 287dbaf0624SGonglei 288dbaf0624SGonglei struct virtio_crypto_destroy_session_req { 289dbaf0624SGonglei /* Device-readable part */ 290dbaf0624SGonglei __le64 session_id; 291dbaf0624SGonglei __u8 padding[48]; 292dbaf0624SGonglei }; 293dbaf0624SGonglei 294dbaf0624SGonglei /* The request of the control virtqueue's packet */ 295dbaf0624SGonglei struct virtio_crypto_op_ctrl_req { 296dbaf0624SGonglei struct virtio_crypto_ctrl_header header; 297dbaf0624SGonglei 298dbaf0624SGonglei union { 299dbaf0624SGonglei struct virtio_crypto_sym_create_session_req 300dbaf0624SGonglei sym_create_session; 301dbaf0624SGonglei struct virtio_crypto_hash_create_session_req 302dbaf0624SGonglei hash_create_session; 303dbaf0624SGonglei struct virtio_crypto_mac_create_session_req 304dbaf0624SGonglei mac_create_session; 305dbaf0624SGonglei struct virtio_crypto_aead_create_session_req 306dbaf0624SGonglei aead_create_session; 30724e19590Szhenwei pi struct virtio_crypto_akcipher_create_session_req 30824e19590Szhenwei pi akcipher_create_session; 309dbaf0624SGonglei struct virtio_crypto_destroy_session_req 310dbaf0624SGonglei destroy_session; 311dbaf0624SGonglei __u8 padding[56]; 312dbaf0624SGonglei } u; 313dbaf0624SGonglei }; 314dbaf0624SGonglei 315dbaf0624SGonglei struct virtio_crypto_op_header { 316dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \ 317dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00) 318dbaf0624SGonglei #define VIRTIO_CRYPTO_CIPHER_DECRYPT \ 319dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01) 320dbaf0624SGonglei #define VIRTIO_CRYPTO_HASH \ 321dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00) 322dbaf0624SGonglei #define VIRTIO_CRYPTO_MAC \ 323dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00) 324dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_ENCRYPT \ 325dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00) 326dbaf0624SGonglei #define VIRTIO_CRYPTO_AEAD_DECRYPT \ 327dbaf0624SGonglei VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01) 32824e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \ 32924e19590Szhenwei pi VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00) 33024e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \ 33124e19590Szhenwei pi VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01) 332*5b553e06SLukas Wunner /* akcipher sign/verify opcodes are deprecated */ 33324e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_SIGN \ 33424e19590Szhenwei pi VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02) 33524e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_VERIFY \ 33624e19590Szhenwei pi VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03) 337dbaf0624SGonglei __le32 opcode; 338dbaf0624SGonglei /* algo should be service-specific algorithms */ 339dbaf0624SGonglei __le32 algo; 340dbaf0624SGonglei /* session_id should be service-specific algorithms */ 341dbaf0624SGonglei __le64 session_id; 342dbaf0624SGonglei /* control flag to control the request */ 343dbaf0624SGonglei __le32 flag; 344dbaf0624SGonglei __le32 padding; 345dbaf0624SGonglei }; 346dbaf0624SGonglei 347dbaf0624SGonglei struct virtio_crypto_cipher_para { 348dbaf0624SGonglei /* 349dbaf0624SGonglei * Byte Length of valid IV/Counter 350dbaf0624SGonglei * 351dbaf0624SGonglei * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for 352dbaf0624SGonglei * SNOW3G in UEA2 mode, this is the length of the IV (which 353dbaf0624SGonglei * must be the same as the block length of the cipher). 354dbaf0624SGonglei * For block ciphers in CTR mode, this is the length of the counter 355dbaf0624SGonglei * (which must be the same as the block length of the cipher). 356dbaf0624SGonglei * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007. 357dbaf0624SGonglei * 358dbaf0624SGonglei * The IV/Counter will be updated after every partial cryptographic 359dbaf0624SGonglei * operation. 360dbaf0624SGonglei */ 361dbaf0624SGonglei __le32 iv_len; 362dbaf0624SGonglei /* length of source data */ 363dbaf0624SGonglei __le32 src_data_len; 364dbaf0624SGonglei /* length of dst data */ 365dbaf0624SGonglei __le32 dst_data_len; 366dbaf0624SGonglei __le32 padding; 367dbaf0624SGonglei }; 368dbaf0624SGonglei 369dbaf0624SGonglei struct virtio_crypto_hash_para { 370dbaf0624SGonglei /* length of source data */ 371dbaf0624SGonglei __le32 src_data_len; 372dbaf0624SGonglei /* hash result length */ 373dbaf0624SGonglei __le32 hash_result_len; 374dbaf0624SGonglei }; 375dbaf0624SGonglei 376dbaf0624SGonglei struct virtio_crypto_mac_para { 377dbaf0624SGonglei struct virtio_crypto_hash_para hash; 378dbaf0624SGonglei }; 379dbaf0624SGonglei 380dbaf0624SGonglei struct virtio_crypto_aead_para { 381dbaf0624SGonglei /* 382dbaf0624SGonglei * Byte Length of valid IV data pointed to by the below iv_addr 383dbaf0624SGonglei * parameter. 384dbaf0624SGonglei * 385dbaf0624SGonglei * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which 386dbaf0624SGonglei * case iv_addr points to J0. 387dbaf0624SGonglei * For CCM mode, this is the length of the nonce, which can be in the 388dbaf0624SGonglei * range 7 to 13 inclusive. 389dbaf0624SGonglei */ 390dbaf0624SGonglei __le32 iv_len; 391dbaf0624SGonglei /* length of additional auth data */ 392dbaf0624SGonglei __le32 aad_len; 393dbaf0624SGonglei /* length of source data */ 394dbaf0624SGonglei __le32 src_data_len; 395dbaf0624SGonglei /* length of dst data */ 396dbaf0624SGonglei __le32 dst_data_len; 397dbaf0624SGonglei }; 398dbaf0624SGonglei 399dbaf0624SGonglei struct virtio_crypto_cipher_data_req { 400dbaf0624SGonglei /* Device-readable part */ 401dbaf0624SGonglei struct virtio_crypto_cipher_para para; 402dbaf0624SGonglei __u8 padding[24]; 403dbaf0624SGonglei }; 404dbaf0624SGonglei 405dbaf0624SGonglei struct virtio_crypto_hash_data_req { 406dbaf0624SGonglei /* Device-readable part */ 407dbaf0624SGonglei struct virtio_crypto_hash_para para; 408dbaf0624SGonglei __u8 padding[40]; 409dbaf0624SGonglei }; 410dbaf0624SGonglei 411dbaf0624SGonglei struct virtio_crypto_mac_data_req { 412dbaf0624SGonglei /* Device-readable part */ 413dbaf0624SGonglei struct virtio_crypto_mac_para para; 414dbaf0624SGonglei __u8 padding[40]; 415dbaf0624SGonglei }; 416dbaf0624SGonglei 417dbaf0624SGonglei struct virtio_crypto_alg_chain_data_para { 418dbaf0624SGonglei __le32 iv_len; 419dbaf0624SGonglei /* Length of source data */ 420dbaf0624SGonglei __le32 src_data_len; 421dbaf0624SGonglei /* Length of destination data */ 422dbaf0624SGonglei __le32 dst_data_len; 423dbaf0624SGonglei /* Starting point for cipher processing in source data */ 424dbaf0624SGonglei __le32 cipher_start_src_offset; 425dbaf0624SGonglei /* Length of the source data that the cipher will be computed on */ 426dbaf0624SGonglei __le32 len_to_cipher; 427dbaf0624SGonglei /* Starting point for hash processing in source data */ 428dbaf0624SGonglei __le32 hash_start_src_offset; 429dbaf0624SGonglei /* Length of the source data that the hash will be computed on */ 430dbaf0624SGonglei __le32 len_to_hash; 431dbaf0624SGonglei /* Length of the additional auth data */ 432dbaf0624SGonglei __le32 aad_len; 433dbaf0624SGonglei /* Length of the hash result */ 434dbaf0624SGonglei __le32 hash_result_len; 435dbaf0624SGonglei __le32 reserved; 436dbaf0624SGonglei }; 437dbaf0624SGonglei 438dbaf0624SGonglei struct virtio_crypto_alg_chain_data_req { 439dbaf0624SGonglei /* Device-readable part */ 440dbaf0624SGonglei struct virtio_crypto_alg_chain_data_para para; 441dbaf0624SGonglei }; 442dbaf0624SGonglei 443dbaf0624SGonglei struct virtio_crypto_sym_data_req { 444dbaf0624SGonglei union { 445dbaf0624SGonglei struct virtio_crypto_cipher_data_req cipher; 446dbaf0624SGonglei struct virtio_crypto_alg_chain_data_req chain; 447dbaf0624SGonglei __u8 padding[40]; 448dbaf0624SGonglei } u; 449dbaf0624SGonglei 450dbaf0624SGonglei /* See above VIRTIO_CRYPTO_SYM_OP_* */ 451dbaf0624SGonglei __le32 op_type; 452dbaf0624SGonglei __le32 padding; 453dbaf0624SGonglei }; 454dbaf0624SGonglei 455dbaf0624SGonglei struct virtio_crypto_aead_data_req { 456dbaf0624SGonglei /* Device-readable part */ 457dbaf0624SGonglei struct virtio_crypto_aead_para para; 458dbaf0624SGonglei __u8 padding[32]; 459dbaf0624SGonglei }; 460dbaf0624SGonglei 46124e19590Szhenwei pi struct virtio_crypto_akcipher_para { 46224e19590Szhenwei pi __le32 src_data_len; 46324e19590Szhenwei pi __le32 dst_data_len; 46424e19590Szhenwei pi }; 46524e19590Szhenwei pi 46624e19590Szhenwei pi struct virtio_crypto_akcipher_data_req { 46724e19590Szhenwei pi struct virtio_crypto_akcipher_para para; 46824e19590Szhenwei pi __u8 padding[40]; 46924e19590Szhenwei pi }; 47024e19590Szhenwei pi 471dbaf0624SGonglei /* The request of the data virtqueue's packet */ 472dbaf0624SGonglei struct virtio_crypto_op_data_req { 473dbaf0624SGonglei struct virtio_crypto_op_header header; 474dbaf0624SGonglei 475dbaf0624SGonglei union { 476dbaf0624SGonglei struct virtio_crypto_sym_data_req sym_req; 477dbaf0624SGonglei struct virtio_crypto_hash_data_req hash_req; 478dbaf0624SGonglei struct virtio_crypto_mac_data_req mac_req; 479dbaf0624SGonglei struct virtio_crypto_aead_data_req aead_req; 48024e19590Szhenwei pi struct virtio_crypto_akcipher_data_req akcipher_req; 481dbaf0624SGonglei __u8 padding[48]; 482dbaf0624SGonglei } u; 483dbaf0624SGonglei }; 484dbaf0624SGonglei 485dbaf0624SGonglei #define VIRTIO_CRYPTO_OK 0 486dbaf0624SGonglei #define VIRTIO_CRYPTO_ERR 1 487dbaf0624SGonglei #define VIRTIO_CRYPTO_BADMSG 2 488dbaf0624SGonglei #define VIRTIO_CRYPTO_NOTSUPP 3 489dbaf0624SGonglei #define VIRTIO_CRYPTO_INVSESS 4 /* Invalid session id */ 49013d640a3Szhenwei pi #define VIRTIO_CRYPTO_NOSPC 5 /* no free session ID */ 49124e19590Szhenwei pi #define VIRTIO_CRYPTO_KEY_REJECTED 6 /* Signature verification failed */ 492dbaf0624SGonglei 493dbaf0624SGonglei /* The accelerator hardware is ready */ 494dbaf0624SGonglei #define VIRTIO_CRYPTO_S_HW_READY (1 << 0) 495dbaf0624SGonglei 496dbaf0624SGonglei struct virtio_crypto_config { 497dbaf0624SGonglei /* See VIRTIO_CRYPTO_OP_* above */ 49824bcf35bSMichael S. Tsirkin __le32 status; 499dbaf0624SGonglei 500dbaf0624SGonglei /* 501dbaf0624SGonglei * Maximum number of data queue 502dbaf0624SGonglei */ 50324bcf35bSMichael S. Tsirkin __le32 max_dataqueues; 504dbaf0624SGonglei 505dbaf0624SGonglei /* 506dbaf0624SGonglei * Specifies the services mask which the device support, 507dbaf0624SGonglei * see VIRTIO_CRYPTO_SERVICE_* above 508dbaf0624SGonglei */ 50924bcf35bSMichael S. Tsirkin __le32 crypto_services; 510dbaf0624SGonglei 511dbaf0624SGonglei /* Detailed algorithms mask */ 51224bcf35bSMichael S. Tsirkin __le32 cipher_algo_l; 51324bcf35bSMichael S. Tsirkin __le32 cipher_algo_h; 51424bcf35bSMichael S. Tsirkin __le32 hash_algo; 51524bcf35bSMichael S. Tsirkin __le32 mac_algo_l; 51624bcf35bSMichael S. Tsirkin __le32 mac_algo_h; 51724bcf35bSMichael S. Tsirkin __le32 aead_algo; 518dbaf0624SGonglei /* Maximum length of cipher key */ 51924bcf35bSMichael S. Tsirkin __le32 max_cipher_key_len; 520dbaf0624SGonglei /* Maximum length of authenticated key */ 52124bcf35bSMichael S. Tsirkin __le32 max_auth_key_len; 52224e19590Szhenwei pi __le32 akcipher_algo; 523dbaf0624SGonglei /* Maximum size of each crypto request's content */ 52424bcf35bSMichael S. Tsirkin __le64 max_size; 525dbaf0624SGonglei }; 526dbaf0624SGonglei 527dbaf0624SGonglei struct virtio_crypto_inhdr { 528dbaf0624SGonglei /* See VIRTIO_CRYPTO_* above */ 529dbaf0624SGonglei __u8 status; 530dbaf0624SGonglei }; 531dbaf0624SGonglei #endif 532