0001 #ifndef _VIRTIO_CRYPTO_H
0002 #define _VIRTIO_CRYPTO_H
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include <linux/types.h>
0031 #include <linux/virtio_types.h>
0032 #include <linux/virtio_ids.h>
0033 #include <linux/virtio_config.h>
0034
0035
0036 #define VIRTIO_CRYPTO_SERVICE_CIPHER 0
0037 #define VIRTIO_CRYPTO_SERVICE_HASH 1
0038 #define VIRTIO_CRYPTO_SERVICE_MAC 2
0039 #define VIRTIO_CRYPTO_SERVICE_AEAD 3
0040 #define VIRTIO_CRYPTO_SERVICE_AKCIPHER 4
0041
0042 #define VIRTIO_CRYPTO_OPCODE(service, op) (((service) << 8) | (op))
0043
0044 struct virtio_crypto_ctrl_header {
0045 #define VIRTIO_CRYPTO_CIPHER_CREATE_SESSION \
0046 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x02)
0047 #define VIRTIO_CRYPTO_CIPHER_DESTROY_SESSION \
0048 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x03)
0049 #define VIRTIO_CRYPTO_HASH_CREATE_SESSION \
0050 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x02)
0051 #define VIRTIO_CRYPTO_HASH_DESTROY_SESSION \
0052 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x03)
0053 #define VIRTIO_CRYPTO_MAC_CREATE_SESSION \
0054 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x02)
0055 #define VIRTIO_CRYPTO_MAC_DESTROY_SESSION \
0056 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x03)
0057 #define VIRTIO_CRYPTO_AEAD_CREATE_SESSION \
0058 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x02)
0059 #define VIRTIO_CRYPTO_AEAD_DESTROY_SESSION \
0060 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x03)
0061 #define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \
0062 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04)
0063 #define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \
0064 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x05)
0065 __le32 opcode;
0066 __le32 algo;
0067 __le32 flag;
0068
0069 __le32 queue_id;
0070 };
0071
0072 struct virtio_crypto_cipher_session_para {
0073 #define VIRTIO_CRYPTO_NO_CIPHER 0
0074 #define VIRTIO_CRYPTO_CIPHER_ARC4 1
0075 #define VIRTIO_CRYPTO_CIPHER_AES_ECB 2
0076 #define VIRTIO_CRYPTO_CIPHER_AES_CBC 3
0077 #define VIRTIO_CRYPTO_CIPHER_AES_CTR 4
0078 #define VIRTIO_CRYPTO_CIPHER_DES_ECB 5
0079 #define VIRTIO_CRYPTO_CIPHER_DES_CBC 6
0080 #define VIRTIO_CRYPTO_CIPHER_3DES_ECB 7
0081 #define VIRTIO_CRYPTO_CIPHER_3DES_CBC 8
0082 #define VIRTIO_CRYPTO_CIPHER_3DES_CTR 9
0083 #define VIRTIO_CRYPTO_CIPHER_KASUMI_F8 10
0084 #define VIRTIO_CRYPTO_CIPHER_SNOW3G_UEA2 11
0085 #define VIRTIO_CRYPTO_CIPHER_AES_F8 12
0086 #define VIRTIO_CRYPTO_CIPHER_AES_XTS 13
0087 #define VIRTIO_CRYPTO_CIPHER_ZUC_EEA3 14
0088 __le32 algo;
0089
0090 __le32 keylen;
0091
0092 #define VIRTIO_CRYPTO_OP_ENCRYPT 1
0093 #define VIRTIO_CRYPTO_OP_DECRYPT 2
0094
0095 __le32 op;
0096 __le32 padding;
0097 };
0098
0099 struct virtio_crypto_session_input {
0100
0101 __le64 session_id;
0102 __le32 status;
0103 __le32 padding;
0104 };
0105
0106 struct virtio_crypto_cipher_session_req {
0107 struct virtio_crypto_cipher_session_para para;
0108 __u8 padding[32];
0109 };
0110
0111 struct virtio_crypto_hash_session_para {
0112 #define VIRTIO_CRYPTO_NO_HASH 0
0113 #define VIRTIO_CRYPTO_HASH_MD5 1
0114 #define VIRTIO_CRYPTO_HASH_SHA1 2
0115 #define VIRTIO_CRYPTO_HASH_SHA_224 3
0116 #define VIRTIO_CRYPTO_HASH_SHA_256 4
0117 #define VIRTIO_CRYPTO_HASH_SHA_384 5
0118 #define VIRTIO_CRYPTO_HASH_SHA_512 6
0119 #define VIRTIO_CRYPTO_HASH_SHA3_224 7
0120 #define VIRTIO_CRYPTO_HASH_SHA3_256 8
0121 #define VIRTIO_CRYPTO_HASH_SHA3_384 9
0122 #define VIRTIO_CRYPTO_HASH_SHA3_512 10
0123 #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE128 11
0124 #define VIRTIO_CRYPTO_HASH_SHA3_SHAKE256 12
0125 __le32 algo;
0126
0127 __le32 hash_result_len;
0128 __u8 padding[8];
0129 };
0130
0131 struct virtio_crypto_hash_create_session_req {
0132 struct virtio_crypto_hash_session_para para;
0133 __u8 padding[40];
0134 };
0135
0136 struct virtio_crypto_mac_session_para {
0137 #define VIRTIO_CRYPTO_NO_MAC 0
0138 #define VIRTIO_CRYPTO_MAC_HMAC_MD5 1
0139 #define VIRTIO_CRYPTO_MAC_HMAC_SHA1 2
0140 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_224 3
0141 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_256 4
0142 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_384 5
0143 #define VIRTIO_CRYPTO_MAC_HMAC_SHA_512 6
0144 #define VIRTIO_CRYPTO_MAC_CMAC_3DES 25
0145 #define VIRTIO_CRYPTO_MAC_CMAC_AES 26
0146 #define VIRTIO_CRYPTO_MAC_KASUMI_F9 27
0147 #define VIRTIO_CRYPTO_MAC_SNOW3G_UIA2 28
0148 #define VIRTIO_CRYPTO_MAC_GMAC_AES 41
0149 #define VIRTIO_CRYPTO_MAC_GMAC_TWOFISH 42
0150 #define VIRTIO_CRYPTO_MAC_CBCMAC_AES 49
0151 #define VIRTIO_CRYPTO_MAC_CBCMAC_KASUMI_F9 50
0152 #define VIRTIO_CRYPTO_MAC_XCBC_AES 53
0153 __le32 algo;
0154
0155 __le32 hash_result_len;
0156
0157 __le32 auth_key_len;
0158 __le32 padding;
0159 };
0160
0161 struct virtio_crypto_mac_create_session_req {
0162 struct virtio_crypto_mac_session_para para;
0163 __u8 padding[40];
0164 };
0165
0166 struct virtio_crypto_aead_session_para {
0167 #define VIRTIO_CRYPTO_NO_AEAD 0
0168 #define VIRTIO_CRYPTO_AEAD_GCM 1
0169 #define VIRTIO_CRYPTO_AEAD_CCM 2
0170 #define VIRTIO_CRYPTO_AEAD_CHACHA20_POLY1305 3
0171 __le32 algo;
0172
0173 __le32 key_len;
0174
0175 __le32 hash_result_len;
0176
0177 __le32 aad_len;
0178
0179 __le32 op;
0180 __le32 padding;
0181 };
0182
0183 struct virtio_crypto_aead_create_session_req {
0184 struct virtio_crypto_aead_session_para para;
0185 __u8 padding[32];
0186 };
0187
0188 struct virtio_crypto_rsa_session_para {
0189 #define VIRTIO_CRYPTO_RSA_RAW_PADDING 0
0190 #define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1
0191 __le32 padding_algo;
0192
0193 #define VIRTIO_CRYPTO_RSA_NO_HASH 0
0194 #define VIRTIO_CRYPTO_RSA_MD2 1
0195 #define VIRTIO_CRYPTO_RSA_MD3 2
0196 #define VIRTIO_CRYPTO_RSA_MD4 3
0197 #define VIRTIO_CRYPTO_RSA_MD5 4
0198 #define VIRTIO_CRYPTO_RSA_SHA1 5
0199 #define VIRTIO_CRYPTO_RSA_SHA256 6
0200 #define VIRTIO_CRYPTO_RSA_SHA384 7
0201 #define VIRTIO_CRYPTO_RSA_SHA512 8
0202 #define VIRTIO_CRYPTO_RSA_SHA224 9
0203 __le32 hash_algo;
0204 };
0205
0206 struct virtio_crypto_ecdsa_session_para {
0207 #define VIRTIO_CRYPTO_CURVE_UNKNOWN 0
0208 #define VIRTIO_CRYPTO_CURVE_NIST_P192 1
0209 #define VIRTIO_CRYPTO_CURVE_NIST_P224 2
0210 #define VIRTIO_CRYPTO_CURVE_NIST_P256 3
0211 #define VIRTIO_CRYPTO_CURVE_NIST_P384 4
0212 #define VIRTIO_CRYPTO_CURVE_NIST_P521 5
0213 __le32 curve_id;
0214 __le32 padding;
0215 };
0216
0217 struct virtio_crypto_akcipher_session_para {
0218 #define VIRTIO_CRYPTO_NO_AKCIPHER 0
0219 #define VIRTIO_CRYPTO_AKCIPHER_RSA 1
0220 #define VIRTIO_CRYPTO_AKCIPHER_DSA 2
0221 #define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3
0222 __le32 algo;
0223
0224 #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC 1
0225 #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2
0226 __le32 keytype;
0227 __le32 keylen;
0228
0229 union {
0230 struct virtio_crypto_rsa_session_para rsa;
0231 struct virtio_crypto_ecdsa_session_para ecdsa;
0232 } u;
0233 };
0234
0235 struct virtio_crypto_akcipher_create_session_req {
0236 struct virtio_crypto_akcipher_session_para para;
0237 __u8 padding[36];
0238 };
0239
0240 struct virtio_crypto_alg_chain_session_para {
0241 #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER 1
0242 #define VIRTIO_CRYPTO_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH 2
0243 __le32 alg_chain_order;
0244
0245 #define VIRTIO_CRYPTO_SYM_HASH_MODE_PLAIN 1
0246
0247 #define VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH 2
0248
0249 #define VIRTIO_CRYPTO_SYM_HASH_MODE_NESTED 3
0250 __le32 hash_mode;
0251 struct virtio_crypto_cipher_session_para cipher_param;
0252 union {
0253 struct virtio_crypto_hash_session_para hash_param;
0254 struct virtio_crypto_mac_session_para mac_param;
0255 __u8 padding[16];
0256 } u;
0257
0258 __le32 aad_len;
0259 __le32 padding;
0260 };
0261
0262 struct virtio_crypto_alg_chain_session_req {
0263 struct virtio_crypto_alg_chain_session_para para;
0264 };
0265
0266 struct virtio_crypto_sym_create_session_req {
0267 union {
0268 struct virtio_crypto_cipher_session_req cipher;
0269 struct virtio_crypto_alg_chain_session_req chain;
0270 __u8 padding[48];
0271 } u;
0272
0273
0274
0275
0276 #define VIRTIO_CRYPTO_SYM_OP_NONE 0
0277
0278 #define VIRTIO_CRYPTO_SYM_OP_CIPHER 1
0279
0280
0281
0282
0283 #define VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING 2
0284 __le32 op_type;
0285 __le32 padding;
0286 };
0287
0288 struct virtio_crypto_destroy_session_req {
0289
0290 __le64 session_id;
0291 __u8 padding[48];
0292 };
0293
0294
0295 struct virtio_crypto_op_ctrl_req {
0296 struct virtio_crypto_ctrl_header header;
0297
0298 union {
0299 struct virtio_crypto_sym_create_session_req
0300 sym_create_session;
0301 struct virtio_crypto_hash_create_session_req
0302 hash_create_session;
0303 struct virtio_crypto_mac_create_session_req
0304 mac_create_session;
0305 struct virtio_crypto_aead_create_session_req
0306 aead_create_session;
0307 struct virtio_crypto_akcipher_create_session_req
0308 akcipher_create_session;
0309 struct virtio_crypto_destroy_session_req
0310 destroy_session;
0311 __u8 padding[56];
0312 } u;
0313 };
0314
0315 struct virtio_crypto_op_header {
0316 #define VIRTIO_CRYPTO_CIPHER_ENCRYPT \
0317 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x00)
0318 #define VIRTIO_CRYPTO_CIPHER_DECRYPT \
0319 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_CIPHER, 0x01)
0320 #define VIRTIO_CRYPTO_HASH \
0321 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_HASH, 0x00)
0322 #define VIRTIO_CRYPTO_MAC \
0323 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_MAC, 0x00)
0324 #define VIRTIO_CRYPTO_AEAD_ENCRYPT \
0325 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x00)
0326 #define VIRTIO_CRYPTO_AEAD_DECRYPT \
0327 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AEAD, 0x01)
0328 #define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \
0329 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00)
0330 #define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \
0331 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01)
0332 #define VIRTIO_CRYPTO_AKCIPHER_SIGN \
0333 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02)
0334 #define VIRTIO_CRYPTO_AKCIPHER_VERIFY \
0335 VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03)
0336 __le32 opcode;
0337
0338 __le32 algo;
0339
0340 __le64 session_id;
0341
0342 __le32 flag;
0343 __le32 padding;
0344 };
0345
0346 struct virtio_crypto_cipher_para {
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360 __le32 iv_len;
0361
0362 __le32 src_data_len;
0363
0364 __le32 dst_data_len;
0365 __le32 padding;
0366 };
0367
0368 struct virtio_crypto_hash_para {
0369
0370 __le32 src_data_len;
0371
0372 __le32 hash_result_len;
0373 };
0374
0375 struct virtio_crypto_mac_para {
0376 struct virtio_crypto_hash_para hash;
0377 };
0378
0379 struct virtio_crypto_aead_para {
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389 __le32 iv_len;
0390
0391 __le32 aad_len;
0392
0393 __le32 src_data_len;
0394
0395 __le32 dst_data_len;
0396 };
0397
0398 struct virtio_crypto_cipher_data_req {
0399
0400 struct virtio_crypto_cipher_para para;
0401 __u8 padding[24];
0402 };
0403
0404 struct virtio_crypto_hash_data_req {
0405
0406 struct virtio_crypto_hash_para para;
0407 __u8 padding[40];
0408 };
0409
0410 struct virtio_crypto_mac_data_req {
0411
0412 struct virtio_crypto_mac_para para;
0413 __u8 padding[40];
0414 };
0415
0416 struct virtio_crypto_alg_chain_data_para {
0417 __le32 iv_len;
0418
0419 __le32 src_data_len;
0420
0421 __le32 dst_data_len;
0422
0423 __le32 cipher_start_src_offset;
0424
0425 __le32 len_to_cipher;
0426
0427 __le32 hash_start_src_offset;
0428
0429 __le32 len_to_hash;
0430
0431 __le32 aad_len;
0432
0433 __le32 hash_result_len;
0434 __le32 reserved;
0435 };
0436
0437 struct virtio_crypto_alg_chain_data_req {
0438
0439 struct virtio_crypto_alg_chain_data_para para;
0440 };
0441
0442 struct virtio_crypto_sym_data_req {
0443 union {
0444 struct virtio_crypto_cipher_data_req cipher;
0445 struct virtio_crypto_alg_chain_data_req chain;
0446 __u8 padding[40];
0447 } u;
0448
0449
0450 __le32 op_type;
0451 __le32 padding;
0452 };
0453
0454 struct virtio_crypto_aead_data_req {
0455
0456 struct virtio_crypto_aead_para para;
0457 __u8 padding[32];
0458 };
0459
0460 struct virtio_crypto_akcipher_para {
0461 __le32 src_data_len;
0462 __le32 dst_data_len;
0463 };
0464
0465 struct virtio_crypto_akcipher_data_req {
0466 struct virtio_crypto_akcipher_para para;
0467 __u8 padding[40];
0468 };
0469
0470
0471 struct virtio_crypto_op_data_req {
0472 struct virtio_crypto_op_header header;
0473
0474 union {
0475 struct virtio_crypto_sym_data_req sym_req;
0476 struct virtio_crypto_hash_data_req hash_req;
0477 struct virtio_crypto_mac_data_req mac_req;
0478 struct virtio_crypto_aead_data_req aead_req;
0479 struct virtio_crypto_akcipher_data_req akcipher_req;
0480 __u8 padding[48];
0481 } u;
0482 };
0483
0484 #define VIRTIO_CRYPTO_OK 0
0485 #define VIRTIO_CRYPTO_ERR 1
0486 #define VIRTIO_CRYPTO_BADMSG 2
0487 #define VIRTIO_CRYPTO_NOTSUPP 3
0488 #define VIRTIO_CRYPTO_INVSESS 4
0489 #define VIRTIO_CRYPTO_NOSPC 5
0490 #define VIRTIO_CRYPTO_KEY_REJECTED 6
0491
0492
0493 #define VIRTIO_CRYPTO_S_HW_READY (1 << 0)
0494
0495 struct virtio_crypto_config {
0496
0497 __le32 status;
0498
0499
0500
0501
0502 __le32 max_dataqueues;
0503
0504
0505
0506
0507
0508 __le32 crypto_services;
0509
0510
0511 __le32 cipher_algo_l;
0512 __le32 cipher_algo_h;
0513 __le32 hash_algo;
0514 __le32 mac_algo_l;
0515 __le32 mac_algo_h;
0516 __le32 aead_algo;
0517
0518 __le32 max_cipher_key_len;
0519
0520 __le32 max_auth_key_len;
0521 __le32 akcipher_algo;
0522
0523 __le64 max_size;
0524 };
0525
0526 struct virtio_crypto_inhdr {
0527
0528 __u8 status;
0529 };
0530 #endif