xref: /linux/include/uapi/linux/virtio_crypto.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
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
40*24e19590Szhenwei 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)
61*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION \
62*24e19590Szhenwei pi 	   VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x04)
63*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_DESTROY_SESSION \
64*24e19590Szhenwei 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 
188*24e19590Szhenwei pi struct virtio_crypto_rsa_session_para {
189*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_RAW_PADDING   0
190*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_PKCS1_PADDING 1
191*24e19590Szhenwei pi 	__le32 padding_algo;
192*24e19590Szhenwei pi 
193*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_NO_HASH   0
194*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD2       1
195*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD3       2
196*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD4       3
197*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_MD5       4
198*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA1      5
199*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA256    6
200*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA384    7
201*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA512    8
202*24e19590Szhenwei pi #define VIRTIO_CRYPTO_RSA_SHA224    9
203*24e19590Szhenwei pi 	__le32 hash_algo;
204*24e19590Szhenwei pi };
205*24e19590Szhenwei pi 
206*24e19590Szhenwei pi struct virtio_crypto_ecdsa_session_para {
207*24e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_UNKNOWN   0
208*24e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P192 1
209*24e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P224 2
210*24e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P256 3
211*24e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P384 4
212*24e19590Szhenwei pi #define VIRTIO_CRYPTO_CURVE_NIST_P521 5
213*24e19590Szhenwei pi 	__le32 curve_id;
214*24e19590Szhenwei pi 	__le32 padding;
215*24e19590Szhenwei pi };
216*24e19590Szhenwei pi 
217*24e19590Szhenwei pi struct virtio_crypto_akcipher_session_para {
218*24e19590Szhenwei pi #define VIRTIO_CRYPTO_NO_AKCIPHER    0
219*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_RSA   1
220*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_DSA   2
221*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_ECDSA 3
222*24e19590Szhenwei pi 	__le32 algo;
223*24e19590Szhenwei pi 
224*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC  1
225*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE 2
226*24e19590Szhenwei pi 	__le32 keytype;
227*24e19590Szhenwei pi 	__le32 keylen;
228*24e19590Szhenwei pi 
229*24e19590Szhenwei pi 	union {
230*24e19590Szhenwei pi 		struct virtio_crypto_rsa_session_para rsa;
231*24e19590Szhenwei pi 		struct virtio_crypto_ecdsa_session_para ecdsa;
232*24e19590Szhenwei pi 	} u;
233*24e19590Szhenwei pi };
234*24e19590Szhenwei pi 
235*24e19590Szhenwei pi struct virtio_crypto_akcipher_create_session_req {
236*24e19590Szhenwei pi 	struct virtio_crypto_akcipher_session_para para;
237*24e19590Szhenwei pi 	__u8 padding[36];
238*24e19590Szhenwei pi };
239*24e19590Szhenwei 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;
307*24e19590Szhenwei pi 		struct virtio_crypto_akcipher_create_session_req
308*24e19590Szhenwei 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)
328*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_ENCRYPT \
329*24e19590Szhenwei pi 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x00)
330*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_DECRYPT \
331*24e19590Szhenwei pi 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x01)
332*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_SIGN \
333*24e19590Szhenwei pi 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x02)
334*24e19590Szhenwei pi #define VIRTIO_CRYPTO_AKCIPHER_VERIFY \
335*24e19590Szhenwei pi 	VIRTIO_CRYPTO_OPCODE(VIRTIO_CRYPTO_SERVICE_AKCIPHER, 0x03)
336dbaf0624SGonglei 	__le32 opcode;
337dbaf0624SGonglei 	/* algo should be service-specific algorithms */
338dbaf0624SGonglei 	__le32 algo;
339dbaf0624SGonglei 	/* session_id should be service-specific algorithms */
340dbaf0624SGonglei 	__le64 session_id;
341dbaf0624SGonglei 	/* control flag to control the request */
342dbaf0624SGonglei 	__le32 flag;
343dbaf0624SGonglei 	__le32 padding;
344dbaf0624SGonglei };
345dbaf0624SGonglei 
346dbaf0624SGonglei struct virtio_crypto_cipher_para {
347dbaf0624SGonglei 	/*
348dbaf0624SGonglei 	 * Byte Length of valid IV/Counter
349dbaf0624SGonglei 	 *
350dbaf0624SGonglei 	 * For block ciphers in CBC or F8 mode, or for Kasumi in F8 mode, or for
351dbaf0624SGonglei 	 *   SNOW3G in UEA2 mode, this is the length of the IV (which
352dbaf0624SGonglei 	 *   must be the same as the block length of the cipher).
353dbaf0624SGonglei 	 * For block ciphers in CTR mode, this is the length of the counter
354dbaf0624SGonglei 	 *   (which must be the same as the block length of the cipher).
355dbaf0624SGonglei 	 * For AES-XTS, this is the 128bit tweak, i, from IEEE Std 1619-2007.
356dbaf0624SGonglei 	 *
357dbaf0624SGonglei 	 * The IV/Counter will be updated after every partial cryptographic
358dbaf0624SGonglei 	 * operation.
359dbaf0624SGonglei 	 */
360dbaf0624SGonglei 	__le32 iv_len;
361dbaf0624SGonglei 	/* length of source data */
362dbaf0624SGonglei 	__le32 src_data_len;
363dbaf0624SGonglei 	/* length of dst data */
364dbaf0624SGonglei 	__le32 dst_data_len;
365dbaf0624SGonglei 	__le32 padding;
366dbaf0624SGonglei };
367dbaf0624SGonglei 
368dbaf0624SGonglei struct virtio_crypto_hash_para {
369dbaf0624SGonglei 	/* length of source data */
370dbaf0624SGonglei 	__le32 src_data_len;
371dbaf0624SGonglei 	/* hash result length */
372dbaf0624SGonglei 	__le32 hash_result_len;
373dbaf0624SGonglei };
374dbaf0624SGonglei 
375dbaf0624SGonglei struct virtio_crypto_mac_para {
376dbaf0624SGonglei 	struct virtio_crypto_hash_para hash;
377dbaf0624SGonglei };
378dbaf0624SGonglei 
379dbaf0624SGonglei struct virtio_crypto_aead_para {
380dbaf0624SGonglei 	/*
381dbaf0624SGonglei 	 * Byte Length of valid IV data pointed to by the below iv_addr
382dbaf0624SGonglei 	 * parameter.
383dbaf0624SGonglei 	 *
384dbaf0624SGonglei 	 * For GCM mode, this is either 12 (for 96-bit IVs) or 16, in which
385dbaf0624SGonglei 	 *   case iv_addr points to J0.
386dbaf0624SGonglei 	 * For CCM mode, this is the length of the nonce, which can be in the
387dbaf0624SGonglei 	 *   range 7 to 13 inclusive.
388dbaf0624SGonglei 	 */
389dbaf0624SGonglei 	__le32 iv_len;
390dbaf0624SGonglei 	/* length of additional auth data */
391dbaf0624SGonglei 	__le32 aad_len;
392dbaf0624SGonglei 	/* length of source data */
393dbaf0624SGonglei 	__le32 src_data_len;
394dbaf0624SGonglei 	/* length of dst data */
395dbaf0624SGonglei 	__le32 dst_data_len;
396dbaf0624SGonglei };
397dbaf0624SGonglei 
398dbaf0624SGonglei struct virtio_crypto_cipher_data_req {
399dbaf0624SGonglei 	/* Device-readable part */
400dbaf0624SGonglei 	struct virtio_crypto_cipher_para para;
401dbaf0624SGonglei 	__u8 padding[24];
402dbaf0624SGonglei };
403dbaf0624SGonglei 
404dbaf0624SGonglei struct virtio_crypto_hash_data_req {
405dbaf0624SGonglei 	/* Device-readable part */
406dbaf0624SGonglei 	struct virtio_crypto_hash_para para;
407dbaf0624SGonglei 	__u8 padding[40];
408dbaf0624SGonglei };
409dbaf0624SGonglei 
410dbaf0624SGonglei struct virtio_crypto_mac_data_req {
411dbaf0624SGonglei 	/* Device-readable part */
412dbaf0624SGonglei 	struct virtio_crypto_mac_para para;
413dbaf0624SGonglei 	__u8 padding[40];
414dbaf0624SGonglei };
415dbaf0624SGonglei 
416dbaf0624SGonglei struct virtio_crypto_alg_chain_data_para {
417dbaf0624SGonglei 	__le32 iv_len;
418dbaf0624SGonglei 	/* Length of source data */
419dbaf0624SGonglei 	__le32 src_data_len;
420dbaf0624SGonglei 	/* Length of destination data */
421dbaf0624SGonglei 	__le32 dst_data_len;
422dbaf0624SGonglei 	/* Starting point for cipher processing in source data */
423dbaf0624SGonglei 	__le32 cipher_start_src_offset;
424dbaf0624SGonglei 	/* Length of the source data that the cipher will be computed on */
425dbaf0624SGonglei 	__le32 len_to_cipher;
426dbaf0624SGonglei 	/* Starting point for hash processing in source data */
427dbaf0624SGonglei 	__le32 hash_start_src_offset;
428dbaf0624SGonglei 	/* Length of the source data that the hash will be computed on */
429dbaf0624SGonglei 	__le32 len_to_hash;
430dbaf0624SGonglei 	/* Length of the additional auth data */
431dbaf0624SGonglei 	__le32 aad_len;
432dbaf0624SGonglei 	/* Length of the hash result */
433dbaf0624SGonglei 	__le32 hash_result_len;
434dbaf0624SGonglei 	__le32 reserved;
435dbaf0624SGonglei };
436dbaf0624SGonglei 
437dbaf0624SGonglei struct virtio_crypto_alg_chain_data_req {
438dbaf0624SGonglei 	/* Device-readable part */
439dbaf0624SGonglei 	struct virtio_crypto_alg_chain_data_para para;
440dbaf0624SGonglei };
441dbaf0624SGonglei 
442dbaf0624SGonglei struct virtio_crypto_sym_data_req {
443dbaf0624SGonglei 	union {
444dbaf0624SGonglei 		struct virtio_crypto_cipher_data_req cipher;
445dbaf0624SGonglei 		struct virtio_crypto_alg_chain_data_req chain;
446dbaf0624SGonglei 		__u8 padding[40];
447dbaf0624SGonglei 	} u;
448dbaf0624SGonglei 
449dbaf0624SGonglei 	/* See above VIRTIO_CRYPTO_SYM_OP_* */
450dbaf0624SGonglei 	__le32 op_type;
451dbaf0624SGonglei 	__le32 padding;
452dbaf0624SGonglei };
453dbaf0624SGonglei 
454dbaf0624SGonglei struct virtio_crypto_aead_data_req {
455dbaf0624SGonglei 	/* Device-readable part */
456dbaf0624SGonglei 	struct virtio_crypto_aead_para para;
457dbaf0624SGonglei 	__u8 padding[32];
458dbaf0624SGonglei };
459dbaf0624SGonglei 
460*24e19590Szhenwei pi struct virtio_crypto_akcipher_para {
461*24e19590Szhenwei pi 	__le32 src_data_len;
462*24e19590Szhenwei pi 	__le32 dst_data_len;
463*24e19590Szhenwei pi };
464*24e19590Szhenwei pi 
465*24e19590Szhenwei pi struct virtio_crypto_akcipher_data_req {
466*24e19590Szhenwei pi 	struct virtio_crypto_akcipher_para para;
467*24e19590Szhenwei pi 	__u8 padding[40];
468*24e19590Szhenwei pi };
469*24e19590Szhenwei pi 
470dbaf0624SGonglei /* The request of the data virtqueue's packet */
471dbaf0624SGonglei struct virtio_crypto_op_data_req {
472dbaf0624SGonglei 	struct virtio_crypto_op_header header;
473dbaf0624SGonglei 
474dbaf0624SGonglei 	union {
475dbaf0624SGonglei 		struct virtio_crypto_sym_data_req  sym_req;
476dbaf0624SGonglei 		struct virtio_crypto_hash_data_req hash_req;
477dbaf0624SGonglei 		struct virtio_crypto_mac_data_req mac_req;
478dbaf0624SGonglei 		struct virtio_crypto_aead_data_req aead_req;
479*24e19590Szhenwei pi 		struct virtio_crypto_akcipher_data_req akcipher_req;
480dbaf0624SGonglei 		__u8 padding[48];
481dbaf0624SGonglei 	} u;
482dbaf0624SGonglei };
483dbaf0624SGonglei 
484dbaf0624SGonglei #define VIRTIO_CRYPTO_OK        0
485dbaf0624SGonglei #define VIRTIO_CRYPTO_ERR       1
486dbaf0624SGonglei #define VIRTIO_CRYPTO_BADMSG    2
487dbaf0624SGonglei #define VIRTIO_CRYPTO_NOTSUPP   3
488dbaf0624SGonglei #define VIRTIO_CRYPTO_INVSESS   4 /* Invalid session id */
48913d640a3Szhenwei pi #define VIRTIO_CRYPTO_NOSPC     5 /* no free session ID */
490*24e19590Szhenwei pi #define VIRTIO_CRYPTO_KEY_REJECTED 6 /* Signature verification failed */
491dbaf0624SGonglei 
492dbaf0624SGonglei /* The accelerator hardware is ready */
493dbaf0624SGonglei #define VIRTIO_CRYPTO_S_HW_READY  (1 << 0)
494dbaf0624SGonglei 
495dbaf0624SGonglei struct virtio_crypto_config {
496dbaf0624SGonglei 	/* See VIRTIO_CRYPTO_OP_* above */
49724bcf35bSMichael S. Tsirkin 	__le32  status;
498dbaf0624SGonglei 
499dbaf0624SGonglei 	/*
500dbaf0624SGonglei 	 * Maximum number of data queue
501dbaf0624SGonglei 	 */
50224bcf35bSMichael S. Tsirkin 	__le32  max_dataqueues;
503dbaf0624SGonglei 
504dbaf0624SGonglei 	/*
505dbaf0624SGonglei 	 * Specifies the services mask which the device support,
506dbaf0624SGonglei 	 * see VIRTIO_CRYPTO_SERVICE_* above
507dbaf0624SGonglei 	 */
50824bcf35bSMichael S. Tsirkin 	__le32 crypto_services;
509dbaf0624SGonglei 
510dbaf0624SGonglei 	/* Detailed algorithms mask */
51124bcf35bSMichael S. Tsirkin 	__le32 cipher_algo_l;
51224bcf35bSMichael S. Tsirkin 	__le32 cipher_algo_h;
51324bcf35bSMichael S. Tsirkin 	__le32 hash_algo;
51424bcf35bSMichael S. Tsirkin 	__le32 mac_algo_l;
51524bcf35bSMichael S. Tsirkin 	__le32 mac_algo_h;
51624bcf35bSMichael S. Tsirkin 	__le32 aead_algo;
517dbaf0624SGonglei 	/* Maximum length of cipher key */
51824bcf35bSMichael S. Tsirkin 	__le32 max_cipher_key_len;
519dbaf0624SGonglei 	/* Maximum length of authenticated key */
52024bcf35bSMichael S. Tsirkin 	__le32 max_auth_key_len;
521*24e19590Szhenwei pi 	__le32 akcipher_algo;
522dbaf0624SGonglei 	/* Maximum size of each crypto request's content */
52324bcf35bSMichael S. Tsirkin 	__le64 max_size;
524dbaf0624SGonglei };
525dbaf0624SGonglei 
526dbaf0624SGonglei struct virtio_crypto_inhdr {
527dbaf0624SGonglei 	/* See VIRTIO_CRYPTO_* above */
528dbaf0624SGonglei 	__u8 status;
529dbaf0624SGonglei };
530dbaf0624SGonglei #endif
531