virtio_crypto.h 16 KB

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