PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/include/uapi/linux/virtio_crypto.h

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