crypto/ccp: support session related ops
[dpdk.git] / drivers / crypto / ccp / ccp_crypto.h
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
3  */
4
5 #ifndef _CCP_CRYPTO_H_
6 #define _CCP_CRYPTO_H_
7
8 #include <limits.h>
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <string.h>
12
13 #include <rte_atomic.h>
14 #include <rte_byteorder.h>
15 #include <rte_io.h>
16 #include <rte_pci.h>
17 #include <rte_spinlock.h>
18 #include <rte_crypto_sym.h>
19 #include <rte_cryptodev.h>
20
21 #include "ccp_dev.h"
22
23 #define CCP_SHA3_CTX_SIZE 200
24 /**
25  * CCP supported AES modes
26  */
27 enum ccp_aes_mode {
28         CCP_AES_MODE_ECB = 0,
29         CCP_AES_MODE_CBC,
30         CCP_AES_MODE_OFB,
31         CCP_AES_MODE_CFB,
32         CCP_AES_MODE_CTR,
33         CCP_AES_MODE_CMAC,
34         CCP_AES_MODE_GHASH,
35         CCP_AES_MODE_GCTR,
36         CCP_AES_MODE__LAST,
37 };
38
39 /**
40  * CCP AES GHASH mode
41  */
42 enum ccp_aes_ghash_mode {
43         CCP_AES_MODE_GHASH_AAD = 0,
44         CCP_AES_MODE_GHASH_FINAL
45 };
46
47 /**
48  * CCP supported AES types
49  */
50 enum ccp_aes_type {
51         CCP_AES_TYPE_128 = 0,
52         CCP_AES_TYPE_192,
53         CCP_AES_TYPE_256,
54         CCP_AES_TYPE__LAST,
55 };
56
57 /***** 3DES engine *****/
58
59 /**
60  * CCP supported DES/3DES modes
61  */
62 enum ccp_des_mode {
63         CCP_DES_MODE_ECB = 0, /* Not supported */
64         CCP_DES_MODE_CBC,
65         CCP_DES_MODE_CFB,
66 };
67
68 /**
69  * CCP supported DES types
70  */
71 enum ccp_des_type {
72         CCP_DES_TYPE_128 = 0,   /* 112 + 16 parity */
73         CCP_DES_TYPE_192,       /* 168 + 24 parity */
74         CCP_DES_TYPE__LAST,
75 };
76
77 /***** SHA engine *****/
78
79 /**
80  * ccp_sha_type - type of SHA operation
81  *
82  * @CCP_SHA_TYPE_1: SHA-1 operation
83  * @CCP_SHA_TYPE_224: SHA-224 operation
84  * @CCP_SHA_TYPE_256: SHA-256 operation
85  */
86 enum ccp_sha_type {
87         CCP_SHA_TYPE_1 = 1,
88         CCP_SHA_TYPE_224,
89         CCP_SHA_TYPE_256,
90         CCP_SHA_TYPE_384,
91         CCP_SHA_TYPE_512,
92         CCP_SHA_TYPE_RSVD1,
93         CCP_SHA_TYPE_RSVD2,
94         CCP_SHA3_TYPE_224,
95         CCP_SHA3_TYPE_256,
96         CCP_SHA3_TYPE_384,
97         CCP_SHA3_TYPE_512,
98         CCP_SHA_TYPE__LAST,
99 };
100
101 /**
102  * CCP supported cipher algorithms
103  */
104 enum ccp_cipher_algo {
105         CCP_CIPHER_ALGO_AES_CBC = 0,
106         CCP_CIPHER_ALGO_AES_ECB,
107         CCP_CIPHER_ALGO_AES_CTR,
108         CCP_CIPHER_ALGO_AES_GCM,
109         CCP_CIPHER_ALGO_3DES_CBC,
110 };
111
112 /**
113  * CCP cipher operation type
114  */
115 enum ccp_cipher_dir {
116         CCP_CIPHER_DIR_DECRYPT = 0,
117         CCP_CIPHER_DIR_ENCRYPT = 1,
118 };
119
120 /**
121  * CCP supported hash algorithms
122  */
123 enum ccp_hash_algo {
124         CCP_AUTH_ALGO_SHA1 = 0,
125         CCP_AUTH_ALGO_SHA1_HMAC,
126         CCP_AUTH_ALGO_SHA224,
127         CCP_AUTH_ALGO_SHA224_HMAC,
128         CCP_AUTH_ALGO_SHA3_224,
129         CCP_AUTH_ALGO_SHA3_224_HMAC,
130         CCP_AUTH_ALGO_SHA256,
131         CCP_AUTH_ALGO_SHA256_HMAC,
132         CCP_AUTH_ALGO_SHA3_256,
133         CCP_AUTH_ALGO_SHA3_256_HMAC,
134         CCP_AUTH_ALGO_SHA384,
135         CCP_AUTH_ALGO_SHA384_HMAC,
136         CCP_AUTH_ALGO_SHA3_384,
137         CCP_AUTH_ALGO_SHA3_384_HMAC,
138         CCP_AUTH_ALGO_SHA512,
139         CCP_AUTH_ALGO_SHA512_HMAC,
140         CCP_AUTH_ALGO_SHA3_512,
141         CCP_AUTH_ALGO_SHA3_512_HMAC,
142         CCP_AUTH_ALGO_AES_CMAC,
143         CCP_AUTH_ALGO_AES_GCM,
144 #ifdef RTE_LIBRTE_PMD_CCP_CPU_AUTH
145         CCP_AUTH_ALGO_MD5_HMAC,
146 #endif
147 };
148
149 /**
150  * CCP hash operation type
151  */
152 enum ccp_hash_op {
153         CCP_AUTH_OP_GENERATE = 0,
154         CCP_AUTH_OP_VERIFY = 1,
155 };
156
157 /* CCP crypto private session structure */
158 struct ccp_session {
159         enum ccp_cmd_order cmd_id;
160         /**< chain order mode */
161         struct {
162                 uint16_t length;
163                 uint16_t offset;
164         } iv;
165         /**< IV parameters */
166         struct {
167                 enum ccp_cipher_algo  algo;
168                 enum ccp_engine  engine;
169                 union {
170                         enum ccp_aes_mode aes_mode;
171                         enum ccp_des_mode des_mode;
172                 } um;
173                 union {
174                         enum ccp_aes_type aes_type;
175                         enum ccp_des_type des_type;
176                 } ut;
177                 enum ccp_cipher_dir dir;
178                 uint64_t key_length;
179                 /**< max cipher key size 256 bits */
180                 uint8_t key[32];
181                 /**ccp key format*/
182                 uint8_t key_ccp[32];
183                 phys_addr_t key_phys;
184                 /**AES-ctr nonce(4) iv(8) ctr*/
185                 uint8_t nonce[32];
186                 phys_addr_t nonce_phys;
187         } cipher;
188         /**< Cipher Parameters */
189
190         struct {
191                 enum ccp_hash_algo algo;
192                 enum ccp_engine  engine;
193                 union {
194                         enum ccp_aes_mode aes_mode;
195                 } um;
196                 union {
197                         enum ccp_sha_type sha_type;
198                         enum ccp_aes_type aes_type;
199                 } ut;
200                 enum ccp_hash_op op;
201                 uint64_t key_length;
202                 /**< max hash key size 144 bytes (struct capabilties) */
203                 uint8_t key[144];
204                 /**< max be key size of AES is 32*/
205                 uint8_t key_ccp[32];
206                 phys_addr_t key_phys;
207                 uint64_t digest_length;
208                 void *ctx;
209                 int ctx_len;
210                 int offset;
211                 int block_size;
212                 /**< Buffer to store  Software generated precomute values*/
213                 /**< For HMAC H(ipad ^ key) and H(opad ^ key) */
214                 /**< For CMAC K1 IV and K2 IV*/
215                 uint8_t pre_compute[2 * CCP_SHA3_CTX_SIZE];
216                 /**< SHA3 initial ctx all zeros*/
217                 uint8_t sha3_ctx[200];
218                 int aad_length;
219         } auth;
220         /**< Authentication Parameters */
221         enum rte_crypto_aead_algorithm aead_algo;
222         /**< AEAD Algorithm */
223
224         uint32_t reserved;
225 } __rte_cache_aligned;
226
227 extern uint8_t ccp_cryptodev_driver_id;
228
229 struct ccp_qp;
230
231 /**
232  * Set and validate CCP crypto session parameters
233  *
234  * @param sess ccp private session
235  * @param xform crypto xform for this session
236  * @return 0 on success otherwise -1
237  */
238 int ccp_set_session_parameters(struct ccp_session *sess,
239                                const struct rte_crypto_sym_xform *xform);
240
241 #endif /* _CCP_CRYPTO_H_ */