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