1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#ifndef __CHCR_CRYPTO_H__
37#define __CHCR_CRYPTO_H__
38
39#define GHASH_BLOCK_SIZE 16
40#define GHASH_DIGEST_SIZE 16
41
42#define CCM_B0_SIZE 16
43#define CCM_AAD_FIELD_SIZE 2
44#define T6_MAX_AAD_SIZE 511
45
46
47
48
49
50
51#define CHCR_CRA_PRIORITY 500
52#define CHCR_AEAD_PRIORITY 6000
53#define CHCR_AES_MAX_KEY_LEN (2 * (AES_MAX_KEY_SIZE))
54#define CHCR_MAX_CRYPTO_IV_LEN 16
55
56#define CHCR_MAX_AUTHENC_AES_KEY_LEN 32
57#define CHCR_MAX_AUTHENC_SHA_KEY_LEN 128
58
59#define CHCR_GIVENCRYPT_OP 2
60
61
62#define CHCR_ENCRYPT_OP 0
63#define CHCR_DECRYPT_OP 1
64
65#define CHCR_SCMD_SEQ_NO_CTRL_32BIT 1
66#define CHCR_SCMD_SEQ_NO_CTRL_48BIT 2
67#define CHCR_SCMD_SEQ_NO_CTRL_64BIT 3
68
69#define CHCR_SCMD_PROTO_VERSION_GENERIC 4
70
71#define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0
72#define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1
73
74#define CHCR_SCMD_CIPHER_MODE_NOP 0
75#define CHCR_SCMD_CIPHER_MODE_AES_CBC 1
76#define CHCR_SCMD_CIPHER_MODE_AES_GCM 2
77#define CHCR_SCMD_CIPHER_MODE_AES_CTR 3
78#define CHCR_SCMD_CIPHER_MODE_GENERIC_AES 4
79#define CHCR_SCMD_CIPHER_MODE_AES_XTS 6
80#define CHCR_SCMD_CIPHER_MODE_AES_CCM 7
81
82#define CHCR_SCMD_AUTH_MODE_NOP 0
83#define CHCR_SCMD_AUTH_MODE_SHA1 1
84#define CHCR_SCMD_AUTH_MODE_SHA224 2
85#define CHCR_SCMD_AUTH_MODE_SHA256 3
86#define CHCR_SCMD_AUTH_MODE_GHASH 4
87#define CHCR_SCMD_AUTH_MODE_SHA512_224 5
88#define CHCR_SCMD_AUTH_MODE_SHA512_256 6
89#define CHCR_SCMD_AUTH_MODE_SHA512_384 7
90#define CHCR_SCMD_AUTH_MODE_SHA512_512 8
91#define CHCR_SCMD_AUTH_MODE_CBCMAC 9
92#define CHCR_SCMD_AUTH_MODE_CMAC 10
93
94#define CHCR_SCMD_HMAC_CTRL_NOP 0
95#define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1
96#define CHCR_SCMD_HMAC_CTRL_TRUNC_RFC4366 2
97#define CHCR_SCMD_HMAC_CTRL_IPSEC_96BIT 3
98#define CHCR_SCMD_HMAC_CTRL_PL1 4
99#define CHCR_SCMD_HMAC_CTRL_PL2 5
100#define CHCR_SCMD_HMAC_CTRL_PL3 6
101#define CHCR_SCMD_HMAC_CTRL_DIV2 7
102#define VERIFY_HW 0
103#define VERIFY_SW 1
104
105#define CHCR_SCMD_IVGEN_CTRL_HW 0
106#define CHCR_SCMD_IVGEN_CTRL_SW 1
107
108
109
110#define CHCR_KEYCTX_MAC_KEY_SIZE_128 0
111#define CHCR_KEYCTX_MAC_KEY_SIZE_160 1
112#define CHCR_KEYCTX_MAC_KEY_SIZE_192 2
113#define CHCR_KEYCTX_MAC_KEY_SIZE_256 3
114#define CHCR_KEYCTX_MAC_KEY_SIZE_512 4
115#define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0
116#define CHCR_KEYCTX_CIPHER_KEY_SIZE_192 1
117#define CHCR_KEYCTX_CIPHER_KEY_SIZE_256 2
118#define CHCR_KEYCTX_NO_KEY 15
119
120#define CHCR_CPL_FW4_PLD_IV_OFFSET (5 * 64)
121#define CHCR_CPL_FW4_PLD_HASH_RESULT_OFFSET (7 * 64)
122#define CHCR_CPL_FW4_PLD_DATA_SIZE (4 * 64)
123
124#define KEY_CONTEXT_HDR_SALT_AND_PAD 16
125#define flits_to_bytes(x) (x * 8)
126
127#define IV_NOP 0
128#define IV_IMMEDIATE 1
129#define IV_DSGL 2
130
131#define AEAD_H_SIZE 16
132
133#define CRYPTO_ALG_SUB_TYPE_MASK 0x0f000000
134#define CRYPTO_ALG_SUB_TYPE_HASH_HMAC 0x01000000
135#define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106 0x02000000
136#define CRYPTO_ALG_SUB_TYPE_AEAD_GCM 0x03000000
137#define CRYPTO_ALG_SUB_TYPE_AEAD_AUTHENC 0x04000000
138#define CRYPTO_ALG_SUB_TYPE_AEAD_CCM 0x05000000
139#define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4309 0x06000000
140#define CRYPTO_ALG_SUB_TYPE_AEAD_NULL 0x07000000
141#define CRYPTO_ALG_SUB_TYPE_CTR 0x08000000
142#define CRYPTO_ALG_SUB_TYPE_CTR_RFC3686 0x09000000
143#define CRYPTO_ALG_SUB_TYPE_XTS 0x0a000000
144#define CRYPTO_ALG_SUB_TYPE_CBC 0x0b000000
145#define CRYPTO_ALG_TYPE_HMAC (CRYPTO_ALG_TYPE_AHASH |\
146 CRYPTO_ALG_SUB_TYPE_HASH_HMAC)
147
148#define MAX_SCRATCH_PAD_SIZE 32
149
150#define CHCR_HASH_MAX_BLOCK_SIZE_64 64
151#define CHCR_HASH_MAX_BLOCK_SIZE_128 128
152#define CHCR_SG_SIZE 2048
153
154
155
156struct ablk_ctx {
157 struct crypto_skcipher *sw_cipher;
158 struct crypto_cipher *aes_generic;
159 __be32 key_ctx_hdr;
160 unsigned int enckey_len;
161 unsigned char ciph_mode;
162 u8 key[CHCR_AES_MAX_KEY_LEN];
163 u8 nonce[4];
164 u8 rrkey[AES_MAX_KEY_SIZE];
165};
166struct chcr_aead_reqctx {
167 struct sk_buff *skb;
168 struct scatterlist *dst;
169 struct scatterlist *newdstsg;
170 struct scatterlist srcffwd[2];
171 struct scatterlist dstffwd[2];
172 short int dst_nents;
173 u16 verify;
174 u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
175 unsigned char scratch_pad[MAX_SCRATCH_PAD_SIZE];
176};
177
178struct chcr_gcm_ctx {
179 u8 ghash_h[AEAD_H_SIZE];
180};
181
182struct chcr_authenc_ctx {
183 u8 dec_rrkey[AES_MAX_KEY_SIZE];
184 u8 h_iopad[2 * CHCR_HASH_MAX_DIGEST_SIZE];
185 unsigned char auth_mode;
186};
187
188struct __aead_ctx {
189 struct chcr_gcm_ctx gcm[0];
190 struct chcr_authenc_ctx authenc[0];
191};
192
193
194
195struct chcr_aead_ctx {
196 __be32 key_ctx_hdr;
197 unsigned int enckey_len;
198 struct crypto_skcipher *null;
199 struct crypto_aead *sw_cipher;
200 u8 salt[MAX_SALT];
201 u8 key[CHCR_AES_MAX_KEY_LEN];
202 u16 hmac_ctrl;
203 u16 mayverify;
204 struct __aead_ctx ctx[0];
205};
206
207
208
209struct hmac_ctx {
210 struct crypto_shash *base_hash;
211 u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128];
212 u8 opad[CHCR_HASH_MAX_BLOCK_SIZE_128];
213};
214
215struct __crypto_ctx {
216 struct hmac_ctx hmacctx[0];
217 struct ablk_ctx ablkctx[0];
218 struct chcr_aead_ctx aeadctx[0];
219};
220
221struct chcr_context {
222 struct chcr_dev *dev;
223 unsigned char tx_qidx;
224 unsigned char rx_qidx;
225 struct __crypto_ctx crypto_ctx[0];
226};
227
228struct chcr_ahash_req_ctx {
229 u32 result;
230 u8 bfr1[CHCR_HASH_MAX_BLOCK_SIZE_128];
231 u8 bfr2[CHCR_HASH_MAX_BLOCK_SIZE_128];
232 u8 *reqbfr;
233 u8 *skbfr;
234 u8 reqlen;
235
236 u8 partial_hash[CHCR_HASH_MAX_DIGEST_SIZE];
237 u64 data_len;
238
239 struct sk_buff *skb;
240};
241
242struct chcr_blkcipher_req_ctx {
243 struct sk_buff *skb;
244 struct scatterlist srcffwd[2];
245 struct scatterlist dstffwd[2];
246 struct scatterlist *dstsg;
247 struct scatterlist *dst;
248 struct scatterlist *newdstsg;
249 unsigned int processed;
250 unsigned int op;
251 short int dst_nents;
252 u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
253};
254
255struct chcr_alg_template {
256 u32 type;
257 u32 is_registered;
258 union {
259 struct crypto_alg crypto;
260 struct ahash_alg hash;
261 struct aead_alg aead;
262 } alg;
263};
264
265struct chcr_req_ctx {
266 union {
267 struct ahash_request *ahash_req;
268 struct aead_request *aead_req;
269 struct ablkcipher_request *ablk_req;
270 } req;
271 union {
272 struct chcr_ahash_req_ctx *ahash_ctx;
273 struct chcr_aead_reqctx *reqctx;
274 struct chcr_blkcipher_req_ctx *ablk_ctx;
275 } ctx;
276};
277
278struct sge_opaque_hdr {
279 void *dev;
280 dma_addr_t addr[MAX_SKB_FRAGS + 1];
281};
282
283typedef struct sk_buff *(*create_wr_t)(struct aead_request *req,
284 unsigned short qid,
285 int size,
286 unsigned short op_type);
287
288static int chcr_aead_op(struct aead_request *req_base,
289 unsigned short op_type,
290 int size,
291 create_wr_t create_wr_fn);
292static inline int get_aead_subtype(struct crypto_aead *aead);
293static int is_newsg(struct scatterlist *sgl, unsigned int *newents);
294static struct scatterlist *alloc_new_sg(struct scatterlist *sgl,
295 unsigned int nents);
296static inline void free_new_sg(struct scatterlist *sgl);
297static int chcr_handle_cipher_resp(struct ablkcipher_request *req,
298 unsigned char *input, int err);
299#endif
300