1 /**************************************************************************** 2 **************************************************************************** 3 *** 4 *** This header was automatically generated from a Linux kernel header 5 *** of the same name, to make information necessary for userspace to 6 *** call into the kernel available to libc. It contains only constants, 7 *** structures, and macros generated from the original header, and thus, 8 *** contains no copyrightable information. 9 *** 10 *** To edit the content of this header, modify the corresponding 11 *** source file (e.g. under external/kernel-headers/original/) then 12 *** run bionic/libc/kernel/tools/update_all.py 13 *** 14 *** Any manual change here will be lost the next time this script will 15 *** be run. You've been warned! 16 *** 17 **************************************************************************** 18 ****************************************************************************/ 19 #ifndef _VIRTIO_CRYPTO_H 20 #define _VIRTIO_CRYPTO_H 21 #include <linux/types.h> 22 #include <linux/virtio_types.h> 23 #include <linux/virtio_ids.h> 24 #include <linux/virtio_config.h> 25 #define VIRTIO_CRYPTO_SERVICE_CIPHER 0 26 #define VIRTIO_CRYPTO_SERVICE_HASH 1 27 #define VIRTIO_CRYPTO_SERVICE_MAC 2 28 #define VIRTIO_CRYPTO_SERVICE_AEAD 3 29 #define VIRTIO_CRYPTO_OPCODE(service,op) (((service) << 8) | (op)) 30 struct virtio_crypto_ctrl_header { 31 #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02) 32 #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03) 33 #define VIRTIO_CRYPTO_HASH_CREATE_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02) 34 #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03) 35 #define VIRTIO_CRYPTO_MAC_CREATE_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02) 36 #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03) 37 #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02) 38 #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03) 39 __le32 opcode; 40 __le32 algo; 41 __le32 flag; 42 __le32 queue_id; 43 }; 44 struct virtio_crypto_cipher_session_para { 45 #define VIRTIO_CRYPTO_NO_CIPHER 0 46 #define VIRTIO_CRYPTO_CIPHER_ARC4 1 47 #define VIRTIO_CRYPTO_CIPHER_AES_ECB 2 48 #define VIRTIO_CRYPTO_CIPHER_AES_CBC 3 49 #define VIRTIO_CRYPTO_CIPHER_AES_CTR 4 50 #define VIRTIO_CRYPTO_CIPHER_DES_ECB 5 51 #define VIRTIO_CRYPTO_CIPHER_DES_CBC 6 52 #define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7 53 #define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8 54 #define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9 55 #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10 56 #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11 57 #define VIRTIO_CRYPTO_CIPHER_AES_F8 12 58 #define VIRTIO_CRYPTO_CIPHER_AES_XTS 13 59 #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14 60 __le32 algo; 61 __le32 keylen; 62 #define VIRTIO_CRYPTO_OP_ENCRYPT 1 63 #define VIRTIO_CRYPTO_OP_DECRYPT 2 64 __le32 op; 65 __le32 padding; 66 }; 67 struct virtio_crypto_session_input { 68 __le64 session_id; 69 __le32 status; 70 __le32 padding; 71 }; 72 struct virtio_crypto_cipher_session_req { 73 struct virtio_crypto_cipher_session_para para; 74 __u8 padding[32]; 75 }; 76 struct virtio_crypto_hash_session_para { 77 #define VIRTIO_CRYPTO_NO_HASH 0 78 #define VIRTIO_CRYPTO_HASH_MD5 1 79 #define VIRTIO_CRYPTO_HASH_SHA1 2 80 #define VIRTIO_CRYPTO_HASH_SHA_224 3 81 #define VIRTIO_CRYPTO_HASH_SHA_256 4 82 #define VIRTIO_CRYPTO_HASH_SHA_384 5 83 #define VIRTIO_CRYPTO_HASH_SHA_512 6 84 #define VIRTIO_CRYPTO_HASH_SHA3_224 7 85 #define VIRTIO_CRYPTO_HASH_SHA3_256 8 86 #define VIRTIO_CRYPTO_HASH_SHA3_384 9 87 #define VIRTIO_CRYPTO_HASH_SHA3_512 10 88 #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11 89 #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12 90 __le32 algo; 91 __le32 hash_result_len; 92 __u8 padding[8]; 93 }; 94 struct virtio_crypto_hash_create_session_req { 95 struct virtio_crypto_hash_session_para para; 96 __u8 padding[40]; 97 }; 98 struct virtio_crypto_mac_session_para { 99 #define VIRTIO_CRYPTO_NO_MAC 0 100 #define VIRTIO_CRYPTO_MAC_HMAC_MD5 1 101 #define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2 102 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3 103 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4 104 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5 105 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6 106 #define VIRTIO_CRYPTO_MAC_CMAC_3DES 25 107 #define VIRTIO_CRYPTO_MAC_CMAC_AES 26 108 #define VIRTIO_CRYPTO_MAC_KASUMI_F9 27 109 #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28 110 #define VIRTIO_CRYPTO_MAC_GMAC_AES 41 111 #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42 112 #define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49 113 #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50 114 #define VIRTIO_CRYPTO_MAC_XCBC_AES 53 115 __le32 algo; 116 __le32 hash_result_len; 117 __le32 auth_key_len; 118 __le32 padding; 119 }; 120 struct virtio_crypto_mac_create_session_req { 121 struct virtio_crypto_mac_session_para para; 122 __u8 padding[40]; 123 }; 124 struct virtio_crypto_aead_session_para { 125 #define VIRTIO_CRYPTO_NO_AEAD 0 126 #define VIRTIO_CRYPTO_AEAD_GCM 1 127 #define VIRTIO_CRYPTO_AEAD_CCM 2 128 #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3 129 __le32 algo; 130 __le32 key_len; 131 __le32 hash_result_len; 132 __le32 aad_len; 133 __le32 op; 134 __le32 padding; 135 }; 136 struct virtio_crypto_aead_create_session_req { 137 struct virtio_crypto_aead_session_para para; 138 __u8 padding[32]; 139 }; 140 struct virtio_crypto_alg_chain_session_para { 141 #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1 142 #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2 143 __le32 alg_chain_order; 144 #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1 145 #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2 146 #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3 147 __le32 hash_mode; 148 struct virtio_crypto_cipher_session_para cipher_param; 149 union { 150 struct virtio_crypto_hash_session_para hash_param; 151 struct virtio_crypto_mac_session_para mac_param; 152 __u8 padding[16]; 153 } u; 154 __le32 aad_len; 155 __le32 padding; 156 }; 157 struct virtio_crypto_alg_chain_session_req { 158 struct virtio_crypto_alg_chain_session_para para; 159 }; 160 struct virtio_crypto_sym_create_session_req { 161 union { 162 struct virtio_crypto_cipher_session_req cipher; 163 struct virtio_crypto_alg_chain_session_req chain; 164 __u8 padding[48]; 165 } u; 166 #define VIRTIO_CRYPTO_SYM_OP_NONE 0 167 #define VIRTIO_CRYPTO_SYM_OP_CIPHER 1 168 #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2 169 __le32 op_type; 170 __le32 padding; 171 }; 172 struct virtio_crypto_destroy_session_req { 173 __le64 session_id; 174 __u8 padding[48]; 175 }; 176 struct virtio_crypto_op_ctrl_req { 177 struct virtio_crypto_ctrl_header header; 178 union { 179 struct virtio_crypto_sym_create_session_req sym_create_session; 180 struct virtio_crypto_hash_create_session_req hash_create_session; 181 struct virtio_crypto_mac_create_session_req mac_create_session; 182 struct virtio_crypto_aead_create_session_req aead_create_session; 183 struct virtio_crypto_destroy_session_req destroy_session; 184 __u8 padding[56]; 185 } u; 186 }; 187 struct virtio_crypto_op_header { 188 #define VIRTIO_CRYPTO_CIPHER_ENCRYPT VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00) 189 #define VIRTIO_CRYPTO_CIPHER_DECRYPT VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01) 190 #define VIRTIO_CRYPTO_HASH VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00) 191 #define VIRTIO_CRYPTO_MAC VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00) 192 #define VIRTIO_CRYPTO_AEAD_ENCRYPT VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00) 193 #define VIRTIO_CRYPTO_AEAD_DECRYPT VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01) 194 __le32 opcode; 195 __le32 algo; 196 __le64 session_id; 197 __le32 flag; 198 __le32 padding; 199 }; 200 struct virtio_crypto_cipher_para { 201 __le32 iv_len; 202 __le32 src_data_len; 203 __le32 dst_data_len; 204 __le32 padding; 205 }; 206 struct virtio_crypto_hash_para { 207 __le32 src_data_len; 208 __le32 hash_result_len; 209 }; 210 struct virtio_crypto_mac_para { 211 struct virtio_crypto_hash_para hash; 212 }; 213 struct virtio_crypto_aead_para { 214 __le32 iv_len; 215 __le32 aad_len; 216 __le32 src_data_len; 217 __le32 dst_data_len; 218 }; 219 struct virtio_crypto_cipher_data_req { 220 struct virtio_crypto_cipher_para para; 221 __u8 padding[24]; 222 }; 223 struct virtio_crypto_hash_data_req { 224 struct virtio_crypto_hash_para para; 225 __u8 padding[40]; 226 }; 227 struct virtio_crypto_mac_data_req { 228 struct virtio_crypto_mac_para para; 229 __u8 padding[40]; 230 }; 231 struct virtio_crypto_alg_chain_data_para { 232 __le32 iv_len; 233 __le32 src_data_len; 234 __le32 dst_data_len; 235 __le32 cipher_start_src_offset; 236 __le32 len_to_cipher; 237 __le32 hash_start_src_offset; 238 __le32 len_to_hash; 239 __le32 aad_len; 240 __le32 hash_result_len; 241 __le32 reserved; 242 }; 243 struct virtio_crypto_alg_chain_data_req { 244 struct virtio_crypto_alg_chain_data_para para; 245 }; 246 struct virtio_crypto_sym_data_req { 247 union { 248 struct virtio_crypto_cipher_data_req cipher; 249 struct virtio_crypto_alg_chain_data_req chain; 250 __u8 padding[40]; 251 } u; 252 __le32 op_type; 253 __le32 padding; 254 }; 255 struct virtio_crypto_aead_data_req { 256 struct virtio_crypto_aead_para para; 257 __u8 padding[32]; 258 }; 259 struct virtio_crypto_op_data_req { 260 struct virtio_crypto_op_header header; 261 union { 262 struct virtio_crypto_sym_data_req sym_req; 263 struct virtio_crypto_hash_data_req hash_req; 264 struct virtio_crypto_mac_data_req mac_req; 265 struct virtio_crypto_aead_data_req aead_req; 266 __u8 padding[48]; 267 } u; 268 }; 269 #define VIRTIO_CRYPTO_OK 0 270 #define VIRTIO_CRYPTO_ERR 1 271 #define VIRTIO_CRYPTO_BADMSG 2 272 #define VIRTIO_CRYPTO_NOTSUPP 3 273 #define VIRTIO_CRYPTO_INVSESS 4 274 #define VIRTIO_CRYPTO_S_HW_READY (1 << 0) 275 struct virtio_crypto_config { 276 __u32 status; 277 __u32 max_dataqueues; 278 __u32 crypto_services; 279 __u32 cipher_algo_l; 280 __u32 cipher_algo_h; 281 __u32 hash_algo; 282 __u32 mac_algo_l; 283 __u32 mac_algo_h; 284 __u32 aead_algo; 285 __u32 max_cipher_key_len; 286 __u32 max_auth_key_len; 287 __u32 reserve; 288 __u64 max_size; 289 }; 290 struct virtio_crypto_inhdr { 291 __u8 status; 292 }; 293 #endif 294