blob: 2912006b946b018f13af84322342633cd4284ff7 [file] [log] [blame]
Horia Geantă618b5dc2018-10-10 14:26:48 +03001// SPDX-License-Identifier: GPL-2.0+
Kim Phillips8e8ec592011-03-13 16:54:26 +08002/*
3 * caam - Freescale FSL CAAM support for crypto API
4 *
5 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02006 * Copyright 2016-2019 NXP
Kim Phillips8e8ec592011-03-13 16:54:26 +08007 *
8 * Based on talitos crypto API driver.
9 *
10 * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
11 *
12 * --------------- ---------------
13 * | JobDesc #1 |-------------------->| ShareDesc |
14 * | *(packet 1) | | (PDB) |
15 * --------------- |------------->| (hashKey) |
16 * . | | (cipherKey) |
17 * . | |-------->| (operation) |
18 * --------------- | | ---------------
19 * | JobDesc #2 |------| |
20 * | *(packet 2) | |
21 * --------------- |
22 * . |
23 * . |
24 * --------------- |
25 * | JobDesc #3 |------------
26 * | *(packet 3) |
27 * ---------------
28 *
29 * The SharedDesc never changes for a connection unless rekeyed, but
30 * each packet will likely be in a different place. So all we need
31 * to know to process the packet is where the input is, where the
32 * output goes, and what context we want to process with. Context is
33 * in the SharedDesc, packet references in the JobDesc.
34 *
35 * So, a job desc looks like:
36 *
37 * ---------------------
38 * | Header |
39 * | ShareDesc Pointer |
40 * | SEQ_OUT_PTR |
41 * | (output buffer) |
Yuan Kang6ec47332012-06-22 19:48:43 -050042 * | (output length) |
Kim Phillips8e8ec592011-03-13 16:54:26 +080043 * | SEQ_IN_PTR |
44 * | (input buffer) |
Yuan Kang6ec47332012-06-22 19:48:43 -050045 * | (input length) |
Kim Phillips8e8ec592011-03-13 16:54:26 +080046 * ---------------------
47 */
48
49#include "compat.h"
50
51#include "regs.h"
52#include "intern.h"
53#include "desc_constr.h"
54#include "jr.h"
55#include "error.h"
Yuan Kanga299c832012-06-22 19:48:46 -050056#include "sg_sw_sec4.h"
Yuan Kang4c1ec1f2012-06-22 19:48:45 -050057#include "key_gen.h"
Horia Geantă8cea7b62016-11-22 15:44:09 +020058#include "caamalg_desc.h"
Kim Phillips8e8ec592011-03-13 16:54:26 +080059
60/*
61 * crypto alg
62 */
63#define CAAM_CRA_PRIORITY 3000
64/* max key is sum of AES_MAX_KEY_SIZE, max split key size */
65#define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
Catalin Vasiledaebc462014-10-31 12:45:37 +020066 CTR_RFC3686_NONCE_SIZE + \
Kim Phillips8e8ec592011-03-13 16:54:26 +080067 SHA512_DIGEST_SIZE * 2)
Kim Phillips8e8ec592011-03-13 16:54:26 +080068
Herbert Xuf2147b82015-06-16 13:54:23 +080069#define AEAD_DESC_JOB_IO_LEN (DESC_JOB_IO_LEN + CAAM_CMD_SZ * 2)
70#define GCM_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
71 CAAM_CMD_SZ * 4)
Herbert Xu479bcc72015-07-30 17:53:17 +080072#define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
73 CAAM_CMD_SZ * 5)
Herbert Xuf2147b82015-06-16 13:54:23 +080074
Horia Geantăd6bbd4e2018-11-08 15:36:30 +020075#define CHACHAPOLY_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + CAAM_CMD_SZ * 6)
76
Andrey Smirnov1a3daad2019-08-20 13:23:55 -070077#define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN_MIN)
Herbert Xu87e51b02015-06-18 14:25:55 +080078#define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
Kim Phillips4427b1b2011-05-14 22:08:17 -050079
Herbert Xu479bcc72015-07-30 17:53:17 +080080struct caam_alg_entry {
81 int class1_alg_type;
82 int class2_alg_type;
Herbert Xu479bcc72015-07-30 17:53:17 +080083 bool rfc3686;
84 bool geniv;
Herbert Xu24586b52019-05-06 14:39:44 +080085 bool nodkp;
Herbert Xu479bcc72015-07-30 17:53:17 +080086};
87
88struct caam_aead_alg {
89 struct aead_alg aead;
90 struct caam_alg_entry caam;
91 bool registered;
92};
93
Horia Geantă5ca7bad2018-08-06 15:43:59 +030094struct caam_skcipher_alg {
95 struct skcipher_alg skcipher;
96 struct caam_alg_entry caam;
97 bool registered;
98};
99
Yuan Kangacdca312011-07-15 11:21:42 +0800100/*
Kim Phillips8e8ec592011-03-13 16:54:26 +0800101 * per-session context
102 */
103struct caam_ctx {
Yuan Kang1acebad2011-07-15 11:21:42 +0800104 u32 sh_desc_enc[DESC_MAX_USED_LEN];
105 u32 sh_desc_dec[DESC_MAX_USED_LEN];
Horia Geantăbbf22342017-02-10 14:07:22 +0200106 u8 key[CAAM_MAX_KEY_SIZE];
Yuan Kang1acebad2011-07-15 11:21:42 +0800107 dma_addr_t sh_desc_enc_dma;
108 dma_addr_t sh_desc_dec_dma;
Yuan Kang885e9e22011-07-15 11:21:41 +0800109 dma_addr_t key_dma;
Horia Geantă7e0880b2017-12-19 12:16:07 +0200110 enum dma_data_direction dir;
Horia Geantăbbf22342017-02-10 14:07:22 +0200111 struct device *jrdev;
Horia Geantădb576562016-11-22 15:44:04 +0200112 struct alginfo adata;
113 struct alginfo cdata;
Kim Phillips8e8ec592011-03-13 16:54:26 +0800114 unsigned int authsize;
115};
116
Horia Geantaae4a8252014-03-14 17:46:52 +0200117static int aead_null_set_sh_desc(struct crypto_aead *aead)
118{
Horia Geantaae4a8252014-03-14 17:46:52 +0200119 struct caam_ctx *ctx = crypto_aead_ctx(aead);
120 struct device *jrdev = ctx->jrdev;
Horia Geantă7e0880b2017-12-19 12:16:07 +0200121 struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
Horia Geantaae4a8252014-03-14 17:46:52 +0200122 u32 *desc;
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200123 int rem_bytes = CAAM_DESC_BYTES_MAX - AEAD_DESC_JOB_IO_LEN -
124 ctx->adata.keylen_pad;
Horia Geantaae4a8252014-03-14 17:46:52 +0200125
126 /*
127 * Job Descriptor and Shared Descriptors
128 * must all fit into the 64-word Descriptor h/w Buffer
129 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200130 if (rem_bytes >= DESC_AEAD_NULL_ENC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200131 ctx->adata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100132 ctx->adata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200133 } else {
134 ctx->adata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100135 ctx->adata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200136 }
Horia Geantaae4a8252014-03-14 17:46:52 +0200137
Herbert Xu479bcc72015-07-30 17:53:17 +0800138 /* aead_encrypt shared descriptor */
Horia Geantaae4a8252014-03-14 17:46:52 +0200139 desc = ctx->sh_desc_enc;
Horia Geantă7e0880b2017-12-19 12:16:07 +0200140 cnstr_shdsc_aead_null_encap(desc, &ctx->adata, ctx->authsize,
141 ctrlpriv->era);
Horia Geantăbbf22342017-02-10 14:07:22 +0200142 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200143 desc_bytes(desc), ctx->dir);
Horia Geantaae4a8252014-03-14 17:46:52 +0200144
145 /*
146 * Job Descriptor and Shared Descriptors
147 * must all fit into the 64-word Descriptor h/w Buffer
148 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200149 if (rem_bytes >= DESC_AEAD_NULL_DEC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200150 ctx->adata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100151 ctx->adata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200152 } else {
153 ctx->adata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100154 ctx->adata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200155 }
Horia Geantaae4a8252014-03-14 17:46:52 +0200156
Herbert Xu479bcc72015-07-30 17:53:17 +0800157 /* aead_decrypt shared descriptor */
Horia Geantă8cea7b62016-11-22 15:44:09 +0200158 desc = ctx->sh_desc_dec;
Horia Geantă7e0880b2017-12-19 12:16:07 +0200159 cnstr_shdsc_aead_null_decap(desc, &ctx->adata, ctx->authsize,
160 ctrlpriv->era);
Horia Geantăbbf22342017-02-10 14:07:22 +0200161 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200162 desc_bytes(desc), ctx->dir);
Horia Geantaae4a8252014-03-14 17:46:52 +0200163
164 return 0;
165}
166
Yuan Kang1acebad2011-07-15 11:21:42 +0800167static int aead_set_sh_desc(struct crypto_aead *aead)
168{
Herbert Xu479bcc72015-07-30 17:53:17 +0800169 struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
170 struct caam_aead_alg, aead);
Herbert Xuadd86d52015-05-11 17:47:50 +0800171 unsigned int ivsize = crypto_aead_ivsize(aead);
Yuan Kang1acebad2011-07-15 11:21:42 +0800172 struct caam_ctx *ctx = crypto_aead_ctx(aead);
173 struct device *jrdev = ctx->jrdev;
Horia Geantă7e0880b2017-12-19 12:16:07 +0200174 struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
Catalin Vasiledaebc462014-10-31 12:45:37 +0200175 u32 ctx1_iv_off = 0;
Horia Geantă8cea7b62016-11-22 15:44:09 +0200176 u32 *desc, *nonce = NULL;
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200177 u32 inl_mask;
178 unsigned int data_len[2];
Horia Geantădb576562016-11-22 15:44:04 +0200179 const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
Catalin Vasiledaebc462014-10-31 12:45:37 +0200180 OP_ALG_AAI_CTR_MOD128);
Herbert Xu479bcc72015-07-30 17:53:17 +0800181 const bool is_rfc3686 = alg->caam.rfc3686;
Yuan Kang1acebad2011-07-15 11:21:42 +0800182
Horia Geantă2fdea252016-08-04 20:02:47 +0300183 if (!ctx->authsize)
184 return 0;
185
Horia Geantaae4a8252014-03-14 17:46:52 +0200186 /* NULL encryption / decryption */
Horia Geantădb576562016-11-22 15:44:04 +0200187 if (!ctx->cdata.keylen)
Horia Geantaae4a8252014-03-14 17:46:52 +0200188 return aead_null_set_sh_desc(aead);
189
Yuan Kang1acebad2011-07-15 11:21:42 +0800190 /*
Catalin Vasiledaebc462014-10-31 12:45:37 +0200191 * AES-CTR needs to load IV in CONTEXT1 reg
192 * at an offset of 128bits (16bytes)
193 * CONTEXT1[255:128] = IV
194 */
195 if (ctr_mode)
196 ctx1_iv_off = 16;
197
198 /*
199 * RFC3686 specific:
200 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
201 */
Horia Geantă8cea7b62016-11-22 15:44:09 +0200202 if (is_rfc3686) {
Catalin Vasiledaebc462014-10-31 12:45:37 +0200203 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
Horia Geantă8cea7b62016-11-22 15:44:09 +0200204 nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
205 ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
206 }
Catalin Vasiledaebc462014-10-31 12:45:37 +0200207
Horia Geantăe9b49132019-07-31 16:08:11 +0300208 /*
209 * In case |user key| > |derived key|, using DKP<imm,imm>
210 * would result in invalid opcodes (last bytes of user key) in
211 * the resulting descriptor. Use DKP<ptr,imm> instead => both
212 * virtual and dma key addresses are needed.
213 */
214 ctx->adata.key_virt = ctx->key;
215 ctx->adata.key_dma = ctx->key_dma;
216
217 ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
218 ctx->cdata.key_dma = ctx->key_dma + ctx->adata.keylen_pad;
219
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200220 data_len[0] = ctx->adata.keylen_pad;
221 data_len[1] = ctx->cdata.keylen;
222
Herbert Xu479bcc72015-07-30 17:53:17 +0800223 if (alg->caam.geniv)
224 goto skip_enc;
225
Catalin Vasiledaebc462014-10-31 12:45:37 +0200226 /*
Yuan Kang1acebad2011-07-15 11:21:42 +0800227 * Job Descriptor and Shared Descriptors
228 * must all fit into the 64-word Descriptor h/w Buffer
229 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200230 if (desc_inline_query(DESC_AEAD_ENC_LEN +
231 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
232 AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
233 ARRAY_SIZE(data_len)) < 0)
234 return -EINVAL;
235
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200236 ctx->adata.key_inline = !!(inl_mask & 1);
237 ctx->cdata.key_inline = !!(inl_mask & 2);
Yuan Kang1acebad2011-07-15 11:21:42 +0800238
Herbert Xu479bcc72015-07-30 17:53:17 +0800239 /* aead_encrypt shared descriptor */
Yuan Kang1acebad2011-07-15 11:21:42 +0800240 desc = ctx->sh_desc_enc;
Horia Geantăb1898172017-03-17 12:06:02 +0200241 cnstr_shdsc_aead_encap(desc, &ctx->cdata, &ctx->adata, ivsize,
242 ctx->authsize, is_rfc3686, nonce, ctx1_iv_off,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200243 false, ctrlpriv->era);
Horia Geantăbbf22342017-02-10 14:07:22 +0200244 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200245 desc_bytes(desc), ctx->dir);
Yuan Kang1acebad2011-07-15 11:21:42 +0800246
Herbert Xu479bcc72015-07-30 17:53:17 +0800247skip_enc:
Yuan Kang1acebad2011-07-15 11:21:42 +0800248 /*
249 * Job Descriptor and Shared Descriptors
250 * must all fit into the 64-word Descriptor h/w Buffer
251 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200252 if (desc_inline_query(DESC_AEAD_DEC_LEN +
253 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
254 AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
255 ARRAY_SIZE(data_len)) < 0)
256 return -EINVAL;
257
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200258 ctx->adata.key_inline = !!(inl_mask & 1);
259 ctx->cdata.key_inline = !!(inl_mask & 2);
Yuan Kang1acebad2011-07-15 11:21:42 +0800260
Herbert Xu479bcc72015-07-30 17:53:17 +0800261 /* aead_decrypt shared descriptor */
Yuan Kang1acebad2011-07-15 11:21:42 +0800262 desc = ctx->sh_desc_dec;
Horia Geantă8cea7b62016-11-22 15:44:09 +0200263 cnstr_shdsc_aead_decap(desc, &ctx->cdata, &ctx->adata, ivsize,
264 ctx->authsize, alg->caam.geniv, is_rfc3686,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200265 nonce, ctx1_iv_off, false, ctrlpriv->era);
Horia Geantăbbf22342017-02-10 14:07:22 +0200266 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200267 desc_bytes(desc), ctx->dir);
Yuan Kang1acebad2011-07-15 11:21:42 +0800268
Herbert Xu479bcc72015-07-30 17:53:17 +0800269 if (!alg->caam.geniv)
270 goto skip_givenc;
271
Yuan Kang1acebad2011-07-15 11:21:42 +0800272 /*
273 * Job Descriptor and Shared Descriptors
274 * must all fit into the 64-word Descriptor h/w Buffer
275 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200276 if (desc_inline_query(DESC_AEAD_GIVENC_LEN +
277 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0),
278 AUTHENC_DESC_JOB_IO_LEN, data_len, &inl_mask,
279 ARRAY_SIZE(data_len)) < 0)
280 return -EINVAL;
281
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200282 ctx->adata.key_inline = !!(inl_mask & 1);
283 ctx->cdata.key_inline = !!(inl_mask & 2);
Yuan Kang1acebad2011-07-15 11:21:42 +0800284
285 /* aead_givencrypt shared descriptor */
Horia Geantă1d2d87e2016-08-04 20:02:46 +0300286 desc = ctx->sh_desc_enc;
Horia Geantă8cea7b62016-11-22 15:44:09 +0200287 cnstr_shdsc_aead_givencap(desc, &ctx->cdata, &ctx->adata, ivsize,
288 ctx->authsize, is_rfc3686, nonce,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200289 ctx1_iv_off, false, ctrlpriv->era);
Horia Geantăbbf22342017-02-10 14:07:22 +0200290 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200291 desc_bytes(desc), ctx->dir);
Yuan Kang1acebad2011-07-15 11:21:42 +0800292
Herbert Xu479bcc72015-07-30 17:53:17 +0800293skip_givenc:
Yuan Kang1acebad2011-07-15 11:21:42 +0800294 return 0;
295}
296
Yuan Kang0e479302011-07-15 11:21:41 +0800297static int aead_setauthsize(struct crypto_aead *authenc,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800298 unsigned int authsize)
299{
300 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
301
302 ctx->authsize = authsize;
Yuan Kang1acebad2011-07-15 11:21:42 +0800303 aead_set_sh_desc(authenc);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800304
305 return 0;
306}
307
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300308static int gcm_set_sh_desc(struct crypto_aead *aead)
309{
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300310 struct caam_ctx *ctx = crypto_aead_ctx(aead);
311 struct device *jrdev = ctx->jrdev;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200312 unsigned int ivsize = crypto_aead_ivsize(aead);
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300313 u32 *desc;
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200314 int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
315 ctx->cdata.keylen;
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300316
Horia Geantădb576562016-11-22 15:44:04 +0200317 if (!ctx->cdata.keylen || !ctx->authsize)
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300318 return 0;
319
320 /*
321 * AES GCM encrypt shared descriptor
322 * Job Descriptor and Shared Descriptor
323 * must fit into the 64-word Descriptor h/w Buffer
324 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200325 if (rem_bytes >= DESC_GCM_ENC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200326 ctx->cdata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100327 ctx->cdata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200328 } else {
329 ctx->cdata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100330 ctx->cdata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200331 }
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300332
333 desc = ctx->sh_desc_enc;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200334 cnstr_shdsc_gcm_encap(desc, &ctx->cdata, ivsize, ctx->authsize, false);
Horia Geantăbbf22342017-02-10 14:07:22 +0200335 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200336 desc_bytes(desc), ctx->dir);
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300337
338 /*
339 * Job Descriptor and Shared Descriptors
340 * must all fit into the 64-word Descriptor h/w Buffer
341 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200342 if (rem_bytes >= DESC_GCM_DEC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200343 ctx->cdata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100344 ctx->cdata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200345 } else {
346 ctx->cdata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100347 ctx->cdata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200348 }
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300349
350 desc = ctx->sh_desc_dec;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200351 cnstr_shdsc_gcm_decap(desc, &ctx->cdata, ivsize, ctx->authsize, false);
Horia Geantăbbf22342017-02-10 14:07:22 +0200352 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200353 desc_bytes(desc), ctx->dir);
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300354
355 return 0;
356}
357
358static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
359{
360 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
Iuliana Prodan68a51392019-07-31 16:08:06 +0300361 int err;
362
363 err = crypto_gcm_check_authsize(authsize);
364 if (err)
365 return err;
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300366
367 ctx->authsize = authsize;
368 gcm_set_sh_desc(authenc);
369
370 return 0;
371}
372
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300373static int rfc4106_set_sh_desc(struct crypto_aead *aead)
374{
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300375 struct caam_ctx *ctx = crypto_aead_ctx(aead);
376 struct device *jrdev = ctx->jrdev;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200377 unsigned int ivsize = crypto_aead_ivsize(aead);
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300378 u32 *desc;
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200379 int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
380 ctx->cdata.keylen;
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300381
Horia Geantădb576562016-11-22 15:44:04 +0200382 if (!ctx->cdata.keylen || !ctx->authsize)
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300383 return 0;
384
385 /*
386 * RFC4106 encrypt shared descriptor
387 * Job Descriptor and Shared Descriptor
388 * must fit into the 64-word Descriptor h/w Buffer
389 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200390 if (rem_bytes >= DESC_RFC4106_ENC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200391 ctx->cdata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100392 ctx->cdata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200393 } else {
394 ctx->cdata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100395 ctx->cdata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200396 }
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300397
398 desc = ctx->sh_desc_enc;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200399 cnstr_shdsc_rfc4106_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
400 false);
Horia Geantăbbf22342017-02-10 14:07:22 +0200401 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200402 desc_bytes(desc), ctx->dir);
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300403
404 /*
405 * Job Descriptor and Shared Descriptors
406 * must all fit into the 64-word Descriptor h/w Buffer
407 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200408 if (rem_bytes >= DESC_RFC4106_DEC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200409 ctx->cdata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100410 ctx->cdata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200411 } else {
412 ctx->cdata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100413 ctx->cdata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200414 }
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300415
416 desc = ctx->sh_desc_dec;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200417 cnstr_shdsc_rfc4106_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
418 false);
Horia Geantăbbf22342017-02-10 14:07:22 +0200419 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200420 desc_bytes(desc), ctx->dir);
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300421
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300422 return 0;
423}
424
425static int rfc4106_setauthsize(struct crypto_aead *authenc,
426 unsigned int authsize)
427{
428 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
Iuliana Prodan68a51392019-07-31 16:08:06 +0300429 int err;
430
431 err = crypto_rfc4106_check_authsize(authsize);
432 if (err)
433 return err;
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300434
435 ctx->authsize = authsize;
436 rfc4106_set_sh_desc(authenc);
437
438 return 0;
439}
440
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200441static int rfc4543_set_sh_desc(struct crypto_aead *aead)
442{
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200443 struct caam_ctx *ctx = crypto_aead_ctx(aead);
444 struct device *jrdev = ctx->jrdev;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200445 unsigned int ivsize = crypto_aead_ivsize(aead);
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200446 u32 *desc;
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200447 int rem_bytes = CAAM_DESC_BYTES_MAX - GCM_DESC_JOB_IO_LEN -
448 ctx->cdata.keylen;
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200449
Horia Geantădb576562016-11-22 15:44:04 +0200450 if (!ctx->cdata.keylen || !ctx->authsize)
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200451 return 0;
452
453 /*
454 * RFC4543 encrypt shared descriptor
455 * Job Descriptor and Shared Descriptor
456 * must fit into the 64-word Descriptor h/w Buffer
457 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200458 if (rem_bytes >= DESC_RFC4543_ENC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200459 ctx->cdata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100460 ctx->cdata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200461 } else {
462 ctx->cdata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100463 ctx->cdata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200464 }
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200465
466 desc = ctx->sh_desc_enc;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200467 cnstr_shdsc_rfc4543_encap(desc, &ctx->cdata, ivsize, ctx->authsize,
468 false);
Horia Geantăbbf22342017-02-10 14:07:22 +0200469 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200470 desc_bytes(desc), ctx->dir);
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200471
472 /*
473 * Job Descriptor and Shared Descriptors
474 * must all fit into the 64-word Descriptor h/w Buffer
475 */
Horia Geantă4cbe79c2016-11-22 15:44:06 +0200476 if (rem_bytes >= DESC_RFC4543_DEC_LEN) {
Horia Geantădb576562016-11-22 15:44:04 +0200477 ctx->cdata.key_inline = true;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100478 ctx->cdata.key_virt = ctx->key;
Horia Geantădb576562016-11-22 15:44:04 +0200479 } else {
480 ctx->cdata.key_inline = false;
Arnd Bergmann9c0bc512016-11-30 22:01:59 +0100481 ctx->cdata.key_dma = ctx->key_dma;
Horia Geantădb576562016-11-22 15:44:04 +0200482 }
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200483
484 desc = ctx->sh_desc_dec;
Horia Geantă87ec3a02018-01-29 10:38:36 +0200485 cnstr_shdsc_rfc4543_decap(desc, &ctx->cdata, ivsize, ctx->authsize,
486 false);
Horia Geantăbbf22342017-02-10 14:07:22 +0200487 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200488 desc_bytes(desc), ctx->dir);
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200489
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200490 return 0;
491}
492
493static int rfc4543_setauthsize(struct crypto_aead *authenc,
494 unsigned int authsize)
495{
496 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
497
Iuliana Prodan68a51392019-07-31 16:08:06 +0300498 if (authsize != 16)
499 return -EINVAL;
500
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200501 ctx->authsize = authsize;
502 rfc4543_set_sh_desc(authenc);
503
504 return 0;
505}
506
Horia Geantăd6bbd4e2018-11-08 15:36:30 +0200507static int chachapoly_set_sh_desc(struct crypto_aead *aead)
508{
509 struct caam_ctx *ctx = crypto_aead_ctx(aead);
510 struct device *jrdev = ctx->jrdev;
511 unsigned int ivsize = crypto_aead_ivsize(aead);
512 u32 *desc;
513
514 if (!ctx->cdata.keylen || !ctx->authsize)
515 return 0;
516
517 desc = ctx->sh_desc_enc;
518 cnstr_shdsc_chachapoly(desc, &ctx->cdata, &ctx->adata, ivsize,
Horia Geantăc10a5332018-11-08 15:36:31 +0200519 ctx->authsize, true, false);
Horia Geantăd6bbd4e2018-11-08 15:36:30 +0200520 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
521 desc_bytes(desc), ctx->dir);
522
523 desc = ctx->sh_desc_dec;
524 cnstr_shdsc_chachapoly(desc, &ctx->cdata, &ctx->adata, ivsize,
Horia Geantăc10a5332018-11-08 15:36:31 +0200525 ctx->authsize, false, false);
Horia Geantăd6bbd4e2018-11-08 15:36:30 +0200526 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
527 desc_bytes(desc), ctx->dir);
528
529 return 0;
530}
531
532static int chachapoly_setauthsize(struct crypto_aead *aead,
533 unsigned int authsize)
534{
535 struct caam_ctx *ctx = crypto_aead_ctx(aead);
536
537 if (authsize != POLY1305_DIGEST_SIZE)
538 return -EINVAL;
539
540 ctx->authsize = authsize;
541 return chachapoly_set_sh_desc(aead);
542}
543
544static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key,
545 unsigned int keylen)
546{
547 struct caam_ctx *ctx = crypto_aead_ctx(aead);
548 unsigned int ivsize = crypto_aead_ivsize(aead);
549 unsigned int saltlen = CHACHAPOLY_IV_SIZE - ivsize;
550
Eric Biggers1ca1b912018-11-16 17:26:21 -0800551 if (keylen != CHACHA_KEY_SIZE + saltlen) {
Horia Geantăd6bbd4e2018-11-08 15:36:30 +0200552 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
553 return -EINVAL;
554 }
555
556 ctx->cdata.key_virt = key;
557 ctx->cdata.keylen = keylen - saltlen;
558
559 return chachapoly_set_sh_desc(aead);
560}
561
Yuan Kang0e479302011-07-15 11:21:41 +0800562static int aead_setkey(struct crypto_aead *aead,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800563 const u8 *key, unsigned int keylen)
564{
Kim Phillips8e8ec592011-03-13 16:54:26 +0800565 struct caam_ctx *ctx = crypto_aead_ctx(aead);
566 struct device *jrdev = ctx->jrdev;
Horia Geantă7e0880b2017-12-19 12:16:07 +0200567 struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
Horia Geanta4e6e0b22013-12-19 17:27:35 +0200568 struct crypto_authenc_keys keys;
Kim Phillips8e8ec592011-03-13 16:54:26 +0800569 int ret = 0;
570
Horia Geanta4e6e0b22013-12-19 17:27:35 +0200571 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800572 goto badkey;
573
Sascha Hauer6e005502019-05-23 10:50:29 +0200574 dev_dbg(jrdev, "keylen %d enckeylen %d authkeylen %d\n",
Horia Geanta4e6e0b22013-12-19 17:27:35 +0200575 keys.authkeylen + keys.enckeylen, keys.enckeylen,
576 keys.authkeylen);
Sascha Hauer6e005502019-05-23 10:50:29 +0200577 print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
578 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800579
Horia Geantă7e0880b2017-12-19 12:16:07 +0200580 /*
581 * If DKP is supported, use it in the shared descriptor to generate
582 * the split key.
583 */
584 if (ctrlpriv->era >= 6) {
585 ctx->adata.keylen = keys.authkeylen;
586 ctx->adata.keylen_pad = split_key_len(ctx->adata.algtype &
587 OP_ALG_ALGSEL_MASK);
588
589 if (ctx->adata.keylen_pad + keys.enckeylen > CAAM_MAX_KEY_SIZE)
590 goto badkey;
591
592 memcpy(ctx->key, keys.authkey, keys.authkeylen);
593 memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey,
594 keys.enckeylen);
595 dma_sync_single_for_device(jrdev, ctx->key_dma,
596 ctx->adata.keylen_pad +
597 keys.enckeylen, ctx->dir);
598 goto skip_split_key;
599 }
600
Horia Geantă6655cb82016-11-22 15:44:10 +0200601 ret = gen_split_key(ctx->jrdev, ctx->key, &ctx->adata, keys.authkey,
602 keys.authkeylen, CAAM_MAX_KEY_SIZE -
603 keys.enckeylen);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800604 if (ret) {
Kim Phillips8e8ec592011-03-13 16:54:26 +0800605 goto badkey;
606 }
607
608 /* postpend encryption key to auth split key */
Horia Geantădb576562016-11-22 15:44:04 +0200609 memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
Horia Geantăbbf22342017-02-10 14:07:22 +0200610 dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
Horia Geantă7e0880b2017-12-19 12:16:07 +0200611 keys.enckeylen, ctx->dir);
Sascha Hauer6e005502019-05-23 10:50:29 +0200612
613 print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ",
614 DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
615 ctx->adata.keylen_pad + keys.enckeylen, 1);
Horia Geantă7e0880b2017-12-19 12:16:07 +0200616
617skip_split_key:
Horia Geantădb576562016-11-22 15:44:04 +0200618 ctx->cdata.keylen = keys.enckeylen;
Tudor-Dan Ambarus61dab972018-03-23 12:42:18 +0200619 memzero_explicit(&keys, sizeof(keys));
Horia Geantăbbf22342017-02-10 14:07:22 +0200620 return aead_set_sh_desc(aead);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800621badkey:
622 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
Tudor-Dan Ambarus61dab972018-03-23 12:42:18 +0200623 memzero_explicit(&keys, sizeof(keys));
Kim Phillips8e8ec592011-03-13 16:54:26 +0800624 return -EINVAL;
625}
626
Herbert Xu1b52c402019-04-11 16:51:02 +0800627static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
628 unsigned int keylen)
629{
630 struct crypto_authenc_keys keys;
Herbert Xu1b52c402019-04-11 16:51:02 +0800631 int err;
632
633 err = crypto_authenc_extractkeys(&keys, key, keylen);
634 if (unlikely(err))
Ard Biesheuvela628c5a2019-08-15 12:00:48 +0300635 return err;
Herbert Xu1b52c402019-04-11 16:51:02 +0800636
Ard Biesheuvela628c5a2019-08-15 12:00:48 +0300637 err = verify_aead_des3_key(aead, keys.enckey, keys.enckeylen) ?:
638 aead_setkey(aead, key, keylen);
Herbert Xu1b52c402019-04-11 16:51:02 +0800639
Herbert Xu1b52c402019-04-11 16:51:02 +0800640 memzero_explicit(&keys, sizeof(keys));
641 return err;
Herbert Xu1b52c402019-04-11 16:51:02 +0800642}
643
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300644static int gcm_setkey(struct crypto_aead *aead,
645 const u8 *key, unsigned int keylen)
646{
647 struct caam_ctx *ctx = crypto_aead_ctx(aead);
648 struct device *jrdev = ctx->jrdev;
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300649 int err;
650
651 err = aes_check_keylen(keylen);
652 if (err) {
653 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
654 return err;
655 }
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300656
Sascha Hauer6e005502019-05-23 10:50:29 +0200657 print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
658 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300659
660 memcpy(ctx->key, key, keylen);
Horia Geantă7e0880b2017-12-19 12:16:07 +0200661 dma_sync_single_for_device(jrdev, ctx->key_dma, keylen, ctx->dir);
Horia Geantădb576562016-11-22 15:44:04 +0200662 ctx->cdata.keylen = keylen;
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300663
Horia Geantăbbf22342017-02-10 14:07:22 +0200664 return gcm_set_sh_desc(aead);
Tudor Ambarus3ef8d942014-10-23 16:11:23 +0300665}
666
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300667static int rfc4106_setkey(struct crypto_aead *aead,
668 const u8 *key, unsigned int keylen)
669{
670 struct caam_ctx *ctx = crypto_aead_ctx(aead);
671 struct device *jrdev = ctx->jrdev;
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300672 int err;
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300673
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300674 err = aes_check_keylen(keylen - 4);
675 if (err) {
676 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
677 return err;
678 }
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300679
Sascha Hauer6e005502019-05-23 10:50:29 +0200680 print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
681 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300682
683 memcpy(ctx->key, key, keylen);
684
685 /*
686 * The last four bytes of the key material are used as the salt value
687 * in the nonce. Update the AES key length.
688 */
Horia Geantădb576562016-11-22 15:44:04 +0200689 ctx->cdata.keylen = keylen - 4;
Horia Geantăbbf22342017-02-10 14:07:22 +0200690 dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200691 ctx->dir);
Horia Geantăbbf22342017-02-10 14:07:22 +0200692 return rfc4106_set_sh_desc(aead);
Tudor Ambarusbac68f22014-10-23 16:14:03 +0300693}
694
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200695static int rfc4543_setkey(struct crypto_aead *aead,
696 const u8 *key, unsigned int keylen)
697{
698 struct caam_ctx *ctx = crypto_aead_ctx(aead);
699 struct device *jrdev = ctx->jrdev;
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300700 int err;
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200701
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300702 err = aes_check_keylen(keylen - 4);
703 if (err) {
704 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
705 return err;
706 }
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200707
Sascha Hauer6e005502019-05-23 10:50:29 +0200708 print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
709 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200710
711 memcpy(ctx->key, key, keylen);
712
713 /*
714 * The last four bytes of the key material are used as the salt value
715 * in the nonce. Update the AES key length.
716 */
Horia Geantădb576562016-11-22 15:44:04 +0200717 ctx->cdata.keylen = keylen - 4;
Horia Geantăbbf22342017-02-10 14:07:22 +0200718 dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->cdata.keylen,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200719 ctx->dir);
Horia Geantăbbf22342017-02-10 14:07:22 +0200720 return rfc4543_set_sh_desc(aead);
Tudor Ambarus5d0429a2014-10-30 18:55:07 +0200721}
722
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300723static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300724 unsigned int keylen, const u32 ctx1_iv_off)
Yuan Kangacdca312011-07-15 11:21:42 +0800725{
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300726 struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
727 struct caam_skcipher_alg *alg =
728 container_of(crypto_skcipher_alg(skcipher), typeof(*alg),
729 skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +0800730 struct device *jrdev = ctx->jrdev;
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300731 unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +0800732 u32 *desc;
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300733 const bool is_rfc3686 = alg->caam.rfc3686;
Yuan Kangacdca312011-07-15 11:21:42 +0800734
Sascha Hauer6e005502019-05-23 10:50:29 +0200735 print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
736 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
Catalin Vasilea5f57cf2014-10-31 12:45:36 +0200737
Horia Geantădb576562016-11-22 15:44:04 +0200738 ctx->cdata.keylen = keylen;
Horia Geantă662f70e2017-12-19 12:16:05 +0200739 ctx->cdata.key_virt = key;
Horia Geantădb576562016-11-22 15:44:04 +0200740 ctx->cdata.key_inline = true;
Yuan Kangacdca312011-07-15 11:21:42 +0800741
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300742 /* skcipher_encrypt shared descriptor */
Yuan Kangacdca312011-07-15 11:21:42 +0800743 desc = ctx->sh_desc_enc;
Horia Geantă9dbe3072018-08-06 15:44:00 +0300744 cnstr_shdsc_skcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686,
745 ctx1_iv_off);
Horia Geantăbbf22342017-02-10 14:07:22 +0200746 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200747 desc_bytes(desc), ctx->dir);
Horia Geantă8cea7b62016-11-22 15:44:09 +0200748
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300749 /* skcipher_decrypt shared descriptor */
Yuan Kangacdca312011-07-15 11:21:42 +0800750 desc = ctx->sh_desc_dec;
Horia Geantă9dbe3072018-08-06 15:44:00 +0300751 cnstr_shdsc_skcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686,
752 ctx1_iv_off);
Horia Geantăbbf22342017-02-10 14:07:22 +0200753 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200754 desc_bytes(desc), ctx->dir);
Yuan Kangacdca312011-07-15 11:21:42 +0800755
Horia Geantă8cea7b62016-11-22 15:44:09 +0200756 return 0;
Yuan Kangacdca312011-07-15 11:21:42 +0800757}
758
Iuliana Prodan836d8f42019-07-31 16:08:05 +0300759static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
760 const u8 *key, unsigned int keylen)
761{
762 int err;
763
764 err = aes_check_keylen(keylen);
765 if (err) {
766 crypto_skcipher_set_flags(skcipher,
767 CRYPTO_TFM_RES_BAD_KEY_LEN);
768 return err;
769 }
770
771 return skcipher_setkey(skcipher, key, keylen, 0);
772}
773
774static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher,
775 const u8 *key, unsigned int keylen)
776{
777 u32 ctx1_iv_off;
778 int err;
779
780 /*
781 * RFC3686 specific:
782 * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
783 * | *key = {KEY, NONCE}
784 */
785 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
786 keylen -= CTR_RFC3686_NONCE_SIZE;
787
788 err = aes_check_keylen(keylen);
789 if (err) {
790 crypto_skcipher_set_flags(skcipher,
791 CRYPTO_TFM_RES_BAD_KEY_LEN);
792 return err;
793 }
794
795 return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
796}
797
798static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
799 const u8 *key, unsigned int keylen)
800{
801 u32 ctx1_iv_off;
802 int err;
803
804 /*
805 * AES-CTR needs to load IV in CONTEXT1 reg
806 * at an offset of 128bits (16bytes)
807 * CONTEXT1[255:128] = IV
808 */
809 ctx1_iv_off = 16;
810
811 err = aes_check_keylen(keylen);
812 if (err) {
813 crypto_skcipher_set_flags(skcipher,
814 CRYPTO_TFM_RES_BAD_KEY_LEN);
815 return err;
816 }
817
818 return skcipher_setkey(skcipher, key, keylen, ctx1_iv_off);
819}
820
821static int arc4_skcipher_setkey(struct crypto_skcipher *skcipher,
822 const u8 *key, unsigned int keylen)
823{
824 return skcipher_setkey(skcipher, key, keylen, 0);
825}
826
Iuliana Prodaneaed71a2019-02-08 15:50:09 +0200827static int des_skcipher_setkey(struct crypto_skcipher *skcipher,
828 const u8 *key, unsigned int keylen)
829{
Ard Biesheuvela628c5a2019-08-15 12:00:48 +0300830 return verify_skcipher_des_key(skcipher, key) ?:
831 skcipher_setkey(skcipher, key, keylen, 0);
832}
Iuliana Prodaneaed71a2019-02-08 15:50:09 +0200833
Ard Biesheuvela628c5a2019-08-15 12:00:48 +0300834static int des3_skcipher_setkey(struct crypto_skcipher *skcipher,
835 const u8 *key, unsigned int keylen)
836{
837 return verify_skcipher_des3_key(skcipher, key) ?:
838 skcipher_setkey(skcipher, key, keylen, 0);
Iuliana Prodaneaed71a2019-02-08 15:50:09 +0200839}
840
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300841static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
842 unsigned int keylen)
Catalin Vasilec6415a62015-10-02 13:13:18 +0300843{
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300844 struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
Catalin Vasilec6415a62015-10-02 13:13:18 +0300845 struct device *jrdev = ctx->jrdev;
Horia Geantă8cea7b62016-11-22 15:44:09 +0200846 u32 *desc;
Catalin Vasilec6415a62015-10-02 13:13:18 +0300847
848 if (keylen != 2 * AES_MIN_KEY_SIZE && keylen != 2 * AES_MAX_KEY_SIZE) {
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300849 crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
Catalin Vasilec6415a62015-10-02 13:13:18 +0300850 dev_err(jrdev, "key size mismatch\n");
851 return -EINVAL;
852 }
853
Horia Geantădb576562016-11-22 15:44:04 +0200854 ctx->cdata.keylen = keylen;
Horia Geantă662f70e2017-12-19 12:16:05 +0200855 ctx->cdata.key_virt = key;
Horia Geantădb576562016-11-22 15:44:04 +0200856 ctx->cdata.key_inline = true;
Catalin Vasilec6415a62015-10-02 13:13:18 +0300857
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300858 /* xts_skcipher_encrypt shared descriptor */
Catalin Vasilec6415a62015-10-02 13:13:18 +0300859 desc = ctx->sh_desc_enc;
Horia Geantă9dbe3072018-08-06 15:44:00 +0300860 cnstr_shdsc_xts_skcipher_encap(desc, &ctx->cdata);
Horia Geantăbbf22342017-02-10 14:07:22 +0200861 dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200862 desc_bytes(desc), ctx->dir);
Catalin Vasilec6415a62015-10-02 13:13:18 +0300863
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300864 /* xts_skcipher_decrypt shared descriptor */
Catalin Vasilec6415a62015-10-02 13:13:18 +0300865 desc = ctx->sh_desc_dec;
Horia Geantă9dbe3072018-08-06 15:44:00 +0300866 cnstr_shdsc_xts_skcipher_decap(desc, &ctx->cdata);
Horia Geantăbbf22342017-02-10 14:07:22 +0200867 dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
Horia Geantă7e0880b2017-12-19 12:16:07 +0200868 desc_bytes(desc), ctx->dir);
Catalin Vasilec6415a62015-10-02 13:13:18 +0300869
870 return 0;
871}
872
Kim Phillips8e8ec592011-03-13 16:54:26 +0800873/*
Yuan Kang1acebad2011-07-15 11:21:42 +0800874 * aead_edesc - s/w-extended aead descriptor
Horia Geantăfa0c92d2017-02-10 14:07:19 +0200875 * @src_nents: number of segments in input s/w scatterlist
876 * @dst_nents: number of segments in output s/w scatterlist
Iuliana Prodanba4cf712019-02-08 15:50:07 +0200877 * @mapped_src_nents: number of segments in input h/w link table
878 * @mapped_dst_nents: number of segments in output h/w link table
Yuan Kanga299c832012-06-22 19:48:46 -0500879 * @sec4_sg_bytes: length of dma mapped sec4_sg space
880 * @sec4_sg_dma: bus physical mapped address of h/w link table
Horia Geantă4ca7c7d2016-11-09 10:46:18 +0200881 * @sec4_sg: pointer to h/w link table
Kim Phillips8e8ec592011-03-13 16:54:26 +0800882 * @hw_desc: the h/w job descriptor followed by any referenced link tables
883 */
Yuan Kang0e479302011-07-15 11:21:41 +0800884struct aead_edesc {
Kim Phillips8e8ec592011-03-13 16:54:26 +0800885 int src_nents;
886 int dst_nents;
Iuliana Prodanba4cf712019-02-08 15:50:07 +0200887 int mapped_src_nents;
888 int mapped_dst_nents;
Yuan Kanga299c832012-06-22 19:48:46 -0500889 int sec4_sg_bytes;
890 dma_addr_t sec4_sg_dma;
891 struct sec4_sg_entry *sec4_sg;
Herbert Xuf2147b82015-06-16 13:54:23 +0800892 u32 hw_desc[];
Kim Phillips8e8ec592011-03-13 16:54:26 +0800893};
894
Yuan Kangacdca312011-07-15 11:21:42 +0800895/*
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300896 * skcipher_edesc - s/w-extended skcipher descriptor
Horia Geantăfa0c92d2017-02-10 14:07:19 +0200897 * @src_nents: number of segments in input s/w scatterlist
898 * @dst_nents: number of segments in output s/w scatterlist
Iuliana Prodanba4cf712019-02-08 15:50:07 +0200899 * @mapped_src_nents: number of segments in input h/w link table
900 * @mapped_dst_nents: number of segments in output h/w link table
Yuan Kangacdca312011-07-15 11:21:42 +0800901 * @iv_dma: dma address of iv for checking continuity and link table
Yuan Kanga299c832012-06-22 19:48:46 -0500902 * @sec4_sg_bytes: length of dma mapped sec4_sg space
903 * @sec4_sg_dma: bus physical mapped address of h/w link table
Horia Geantă4ca7c7d2016-11-09 10:46:18 +0200904 * @sec4_sg: pointer to h/w link table
Yuan Kangacdca312011-07-15 11:21:42 +0800905 * @hw_desc: the h/w job descriptor followed by any referenced link tables
Horia Geantă115957b2018-03-28 15:39:18 +0300906 * and IV
Yuan Kangacdca312011-07-15 11:21:42 +0800907 */
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300908struct skcipher_edesc {
Yuan Kangacdca312011-07-15 11:21:42 +0800909 int src_nents;
910 int dst_nents;
Iuliana Prodanba4cf712019-02-08 15:50:07 +0200911 int mapped_src_nents;
912 int mapped_dst_nents;
Yuan Kangacdca312011-07-15 11:21:42 +0800913 dma_addr_t iv_dma;
Yuan Kanga299c832012-06-22 19:48:46 -0500914 int sec4_sg_bytes;
915 dma_addr_t sec4_sg_dma;
916 struct sec4_sg_entry *sec4_sg;
Yuan Kangacdca312011-07-15 11:21:42 +0800917 u32 hw_desc[0];
918};
919
Yuan Kang1acebad2011-07-15 11:21:42 +0800920static void caam_unmap(struct device *dev, struct scatterlist *src,
Yuan Kang643b39b2012-06-22 19:48:49 -0500921 struct scatterlist *dst, int src_nents,
LABBE Corentin13fb8fd2015-09-23 13:55:27 +0200922 int dst_nents,
Horia Geantăcf5448b2018-08-06 15:43:57 +0300923 dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma,
Yuan Kanga299c832012-06-22 19:48:46 -0500924 int sec4_sg_bytes)
Kim Phillips8e8ec592011-03-13 16:54:26 +0800925{
Yuan Kang643b39b2012-06-22 19:48:49 -0500926 if (dst != src) {
Horia Geantăfa0c92d2017-02-10 14:07:19 +0200927 if (src_nents)
928 dma_unmap_sg(dev, src, src_nents, DMA_TO_DEVICE);
Horia Geantă763069b2019-01-22 16:47:01 +0200929 if (dst_nents)
930 dma_unmap_sg(dev, dst, dst_nents, DMA_FROM_DEVICE);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800931 } else {
Horia Geantăfa0c92d2017-02-10 14:07:19 +0200932 dma_unmap_sg(dev, src, src_nents, DMA_BIDIRECTIONAL);
Kim Phillips8e8ec592011-03-13 16:54:26 +0800933 }
934
Yuan Kang1acebad2011-07-15 11:21:42 +0800935 if (iv_dma)
Horia Geantă334d37c2019-06-10 16:30:59 +0300936 dma_unmap_single(dev, iv_dma, ivsize, DMA_BIDIRECTIONAL);
Yuan Kanga299c832012-06-22 19:48:46 -0500937 if (sec4_sg_bytes)
938 dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800939 DMA_TO_DEVICE);
940}
941
Yuan Kang1acebad2011-07-15 11:21:42 +0800942static void aead_unmap(struct device *dev,
943 struct aead_edesc *edesc,
944 struct aead_request *req)
945{
Herbert Xuf2147b82015-06-16 13:54:23 +0800946 caam_unmap(dev, req->src, req->dst,
Horia Geantăcf5448b2018-08-06 15:43:57 +0300947 edesc->src_nents, edesc->dst_nents, 0, 0,
Herbert Xuf2147b82015-06-16 13:54:23 +0800948 edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
949}
950
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300951static void skcipher_unmap(struct device *dev, struct skcipher_edesc *edesc,
952 struct skcipher_request *req)
Yuan Kangacdca312011-07-15 11:21:42 +0800953{
Horia Geantă5ca7bad2018-08-06 15:43:59 +0300954 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
955 int ivsize = crypto_skcipher_ivsize(skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +0800956
957 caam_unmap(dev, req->src, req->dst,
LABBE Corentin13fb8fd2015-09-23 13:55:27 +0200958 edesc->src_nents, edesc->dst_nents,
Horia Geantăcf5448b2018-08-06 15:43:57 +0300959 edesc->iv_dma, ivsize,
Yuan Kang643b39b2012-06-22 19:48:49 -0500960 edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
Yuan Kangacdca312011-07-15 11:21:42 +0800961}
962
Yuan Kang0e479302011-07-15 11:21:41 +0800963static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800964 void *context)
965{
Yuan Kang0e479302011-07-15 11:21:41 +0800966 struct aead_request *req = context;
967 struct aead_edesc *edesc;
Horia Geantă1984aae2019-07-31 16:08:03 +0300968 int ecode = 0;
Herbert Xuf2147b82015-06-16 13:54:23 +0800969
Sascha Hauer6e005502019-05-23 10:50:29 +0200970 dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
Herbert Xuf2147b82015-06-16 13:54:23 +0800971
972 edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
973
974 if (err)
Horia Geantă1984aae2019-07-31 16:08:03 +0300975 ecode = caam_jr_strstatus(jrdev, err);
Herbert Xuf2147b82015-06-16 13:54:23 +0800976
977 aead_unmap(jrdev, edesc, req);
978
979 kfree(edesc);
980
Horia Geantă1984aae2019-07-31 16:08:03 +0300981 aead_request_complete(req, ecode);
Herbert Xuf2147b82015-06-16 13:54:23 +0800982}
983
Yuan Kang0e479302011-07-15 11:21:41 +0800984static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
Kim Phillips8e8ec592011-03-13 16:54:26 +0800985 void *context)
986{
Yuan Kang0e479302011-07-15 11:21:41 +0800987 struct aead_request *req = context;
988 struct aead_edesc *edesc;
Horia Geantă1984aae2019-07-31 16:08:03 +0300989 int ecode = 0;
Herbert Xuf2147b82015-06-16 13:54:23 +0800990
Sascha Hauer6e005502019-05-23 10:50:29 +0200991 dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
Herbert Xuf2147b82015-06-16 13:54:23 +0800992
993 edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
994
995 if (err)
Horia Geantă1984aae2019-07-31 16:08:03 +0300996 ecode = caam_jr_strstatus(jrdev, err);
Herbert Xuf2147b82015-06-16 13:54:23 +0800997
998 aead_unmap(jrdev, edesc, req);
999
Herbert Xuf2147b82015-06-16 13:54:23 +08001000 kfree(edesc);
1001
Horia Geantă1984aae2019-07-31 16:08:03 +03001002 aead_request_complete(req, ecode);
Herbert Xuf2147b82015-06-16 13:54:23 +08001003}
1004
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001005static void skcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1006 void *context)
Yuan Kangacdca312011-07-15 11:21:42 +08001007{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001008 struct skcipher_request *req = context;
1009 struct skcipher_edesc *edesc;
1010 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1011 int ivsize = crypto_skcipher_ivsize(skcipher);
Horia Geantă1984aae2019-07-31 16:08:03 +03001012 int ecode = 0;
Yuan Kangacdca312011-07-15 11:21:42 +08001013
Sascha Hauer6e005502019-05-23 10:50:29 +02001014 dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
Yuan Kangacdca312011-07-15 11:21:42 +08001015
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001016 edesc = container_of(desc, struct skcipher_edesc, hw_desc[0]);
Yuan Kangacdca312011-07-15 11:21:42 +08001017
Marek Vasutfa9659c2014-04-24 20:05:12 +02001018 if (err)
Horia Geantă1984aae2019-07-31 16:08:03 +03001019 ecode = caam_jr_strstatus(jrdev, err);
Yuan Kangacdca312011-07-15 11:21:42 +08001020
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001021 skcipher_unmap(jrdev, edesc, req);
David Gstir854b06f2017-06-28 15:27:10 +02001022
1023 /*
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001024 * The crypto API expects us to set the IV (req->iv) to the last
Horia Geantă334d37c2019-06-10 16:30:59 +03001025 * ciphertext block (CBC mode) or last counter (CTR mode).
1026 * This is used e.g. by the CTS mode.
David Gstir854b06f2017-06-28 15:27:10 +02001027 */
Horia Geantă1ccb39e2019-07-31 16:08:04 +03001028 if (ivsize && !ecode) {
Horia Geantă334d37c2019-06-10 16:30:59 +03001029 memcpy(req->iv, (u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes,
1030 ivsize);
Sascha Hauer6e005502019-05-23 10:50:29 +02001031 print_hex_dump_debug("dstiv @"__stringify(__LINE__)": ",
1032 DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
1033 edesc->src_nents > 1 ? 100 : ivsize, 1);
Horia Geantă334d37c2019-06-10 16:30:59 +03001034 }
Sascha Hauer6e005502019-05-23 10:50:29 +02001035
Sascha Hauer8a824512019-05-23 10:50:30 +02001036 caam_dump_sg("dst @" __stringify(__LINE__)": ",
Sascha Hauerbb992bc2019-05-16 16:24:42 +02001037 DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
1038 edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
1039
Yuan Kangacdca312011-07-15 11:21:42 +08001040 kfree(edesc);
1041
Horia Geantă1984aae2019-07-31 16:08:03 +03001042 skcipher_request_complete(req, ecode);
Yuan Kangacdca312011-07-15 11:21:42 +08001043}
1044
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001045static void skcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
1046 void *context)
Yuan Kangacdca312011-07-15 11:21:42 +08001047{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001048 struct skcipher_request *req = context;
1049 struct skcipher_edesc *edesc;
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001050 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1051 int ivsize = crypto_skcipher_ivsize(skcipher);
Horia Geantă1984aae2019-07-31 16:08:03 +03001052 int ecode = 0;
Yuan Kangacdca312011-07-15 11:21:42 +08001053
Sascha Hauer6e005502019-05-23 10:50:29 +02001054 dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
Yuan Kangacdca312011-07-15 11:21:42 +08001055
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001056 edesc = container_of(desc, struct skcipher_edesc, hw_desc[0]);
Marek Vasutfa9659c2014-04-24 20:05:12 +02001057 if (err)
Horia Geantă1984aae2019-07-31 16:08:03 +03001058 ecode = caam_jr_strstatus(jrdev, err);
Yuan Kangacdca312011-07-15 11:21:42 +08001059
Sascha Hauerbb992bc2019-05-16 16:24:42 +02001060 skcipher_unmap(jrdev, edesc, req);
1061
Horia Geantă334d37c2019-06-10 16:30:59 +03001062 /*
1063 * The crypto API expects us to set the IV (req->iv) to the last
1064 * ciphertext block (CBC mode) or last counter (CTR mode).
1065 * This is used e.g. by the CTS mode.
1066 */
Horia Geantă1ccb39e2019-07-31 16:08:04 +03001067 if (ivsize && !ecode) {
Horia Geantă334d37c2019-06-10 16:30:59 +03001068 memcpy(req->iv, (u8 *)edesc->sec4_sg + edesc->sec4_sg_bytes,
1069 ivsize);
1070
1071 print_hex_dump_debug("dstiv @" __stringify(__LINE__)": ",
1072 DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
1073 ivsize, 1);
1074 }
1075
Sascha Hauer8a824512019-05-23 10:50:30 +02001076 caam_dump_sg("dst @" __stringify(__LINE__)": ",
Horia Geantă972b8122017-07-10 08:40:28 +03001077 DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001078 edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
Yuan Kangacdca312011-07-15 11:21:42 +08001079
Yuan Kangacdca312011-07-15 11:21:42 +08001080 kfree(edesc);
1081
Horia Geantă1984aae2019-07-31 16:08:03 +03001082 skcipher_request_complete(req, ecode);
Yuan Kangacdca312011-07-15 11:21:42 +08001083}
1084
Kim Phillips8e8ec592011-03-13 16:54:26 +08001085/*
Yuan Kang1acebad2011-07-15 11:21:42 +08001086 * Fill in aead job descriptor
Kim Phillips8e8ec592011-03-13 16:54:26 +08001087 */
Herbert Xuf2147b82015-06-16 13:54:23 +08001088static void init_aead_job(struct aead_request *req,
1089 struct aead_edesc *edesc,
1090 bool all_contig, bool encrypt)
1091{
1092 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1093 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1094 int authsize = ctx->authsize;
1095 u32 *desc = edesc->hw_desc;
1096 u32 out_options, in_options;
1097 dma_addr_t dst_dma, src_dma;
1098 int len, sec4_sg_index = 0;
1099 dma_addr_t ptr;
1100 u32 *sh_desc;
1101
1102 sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
1103 ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
1104
1105 len = desc_len(sh_desc);
1106 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
1107
1108 if (all_contig) {
Iuliana Prodanba4cf712019-02-08 15:50:07 +02001109 src_dma = edesc->mapped_src_nents ? sg_dma_address(req->src) :
1110 0;
Herbert Xuf2147b82015-06-16 13:54:23 +08001111 in_options = 0;
1112 } else {
1113 src_dma = edesc->sec4_sg_dma;
Iuliana Prodanba4cf712019-02-08 15:50:07 +02001114 sec4_sg_index += edesc->mapped_src_nents;
Herbert Xuf2147b82015-06-16 13:54:23 +08001115 in_options = LDST_SGF;
1116 }
1117
1118 append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen,
1119 in_options);
1120
1121 dst_dma = src_dma;
1122 out_options = in_options;
1123
1124 if (unlikely(req->src != req->dst)) {
Iuliana Prodanba4cf712019-02-08 15:50:07 +02001125 if (!edesc->mapped_dst_nents) {
Horia Geantă763069b2019-01-22 16:47:01 +02001126 dst_dma = 0;
Horia Geantădcd9c762019-05-03 17:17:37 +03001127 out_options = 0;
Iuliana Prodanba4cf712019-02-08 15:50:07 +02001128 } else if (edesc->mapped_dst_nents == 1) {
Herbert Xuf2147b82015-06-16 13:54:23 +08001129 dst_dma = sg_dma_address(req->dst);
Pankaj Gupta42e95d12019-02-01 07:18:20 +00001130 out_options = 0;
Herbert Xuf2147b82015-06-16 13:54:23 +08001131 } else {
1132 dst_dma = edesc->sec4_sg_dma +
1133 sec4_sg_index *
1134 sizeof(struct sec4_sg_entry);
1135 out_options = LDST_SGF;
1136 }
1137 }
1138
1139 if (encrypt)
1140 append_seq_out_ptr(desc, dst_dma,
1141 req->assoclen + req->cryptlen + authsize,
1142 out_options);
1143 else
1144 append_seq_out_ptr(desc, dst_dma,
1145 req->assoclen + req->cryptlen - authsize,
1146 out_options);
Herbert Xuf2147b82015-06-16 13:54:23 +08001147}
1148
1149static void init_gcm_job(struct aead_request *req,
1150 struct aead_edesc *edesc,
1151 bool all_contig, bool encrypt)
1152{
1153 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1154 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1155 unsigned int ivsize = crypto_aead_ivsize(aead);
1156 u32 *desc = edesc->hw_desc;
Corentin LABBE7545e162017-08-22 10:08:09 +02001157 bool generic_gcm = (ivsize == GCM_AES_IV_SIZE);
Herbert Xuf2147b82015-06-16 13:54:23 +08001158 unsigned int last;
1159
1160 init_aead_job(req, edesc, all_contig, encrypt);
Horia Geantă7e0880b2017-12-19 12:16:07 +02001161 append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
Herbert Xuf2147b82015-06-16 13:54:23 +08001162
1163 /* BUG This should not be specific to generic GCM. */
1164 last = 0;
1165 if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen))
1166 last = FIFOLD_TYPE_LAST1;
1167
1168 /* Read GCM IV */
1169 append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE |
Corentin LABBE7545e162017-08-22 10:08:09 +02001170 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | GCM_AES_IV_SIZE | last);
Herbert Xuf2147b82015-06-16 13:54:23 +08001171 /* Append Salt */
1172 if (!generic_gcm)
Horia Geantădb576562016-11-22 15:44:04 +02001173 append_data(desc, ctx->key + ctx->cdata.keylen, 4);
Herbert Xuf2147b82015-06-16 13:54:23 +08001174 /* Append IV */
1175 append_data(desc, req->iv, ivsize);
1176 /* End of blank commands */
1177}
1178
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02001179static void init_chachapoly_job(struct aead_request *req,
1180 struct aead_edesc *edesc, bool all_contig,
1181 bool encrypt)
1182{
1183 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1184 unsigned int ivsize = crypto_aead_ivsize(aead);
1185 unsigned int assoclen = req->assoclen;
1186 u32 *desc = edesc->hw_desc;
1187 u32 ctx_iv_off = 4;
1188
1189 init_aead_job(req, edesc, all_contig, encrypt);
1190
1191 if (ivsize != CHACHAPOLY_IV_SIZE) {
1192 /* IPsec specific: CONTEXT1[223:128] = {NONCE, IV} */
1193 ctx_iv_off += 4;
1194
1195 /*
1196 * The associated data comes already with the IV but we need
1197 * to skip it when we authenticate or encrypt...
1198 */
1199 assoclen -= ivsize;
1200 }
1201
1202 append_math_add_imm_u32(desc, REG3, ZERO, IMM, assoclen);
1203
1204 /*
1205 * For IPsec load the IV further in the same register.
1206 * For RFC7539 simply load the 12 bytes nonce in a single operation
1207 */
1208 append_load_as_imm(desc, req->iv, ivsize, LDST_CLASS_1_CCB |
1209 LDST_SRCDST_BYTE_CONTEXT |
1210 ctx_iv_off << LDST_OFFSET_SHIFT);
1211}
1212
Herbert Xu479bcc72015-07-30 17:53:17 +08001213static void init_authenc_job(struct aead_request *req,
1214 struct aead_edesc *edesc,
1215 bool all_contig, bool encrypt)
Yuan Kang1acebad2011-07-15 11:21:42 +08001216{
1217 struct crypto_aead *aead = crypto_aead_reqtfm(req);
Herbert Xu479bcc72015-07-30 17:53:17 +08001218 struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
1219 struct caam_aead_alg, aead);
1220 unsigned int ivsize = crypto_aead_ivsize(aead);
Yuan Kang1acebad2011-07-15 11:21:42 +08001221 struct caam_ctx *ctx = crypto_aead_ctx(aead);
Horia Geantă7e0880b2017-12-19 12:16:07 +02001222 struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
Horia Geantădb576562016-11-22 15:44:04 +02001223 const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
Herbert Xu479bcc72015-07-30 17:53:17 +08001224 OP_ALG_AAI_CTR_MOD128);
1225 const bool is_rfc3686 = alg->caam.rfc3686;
Yuan Kang1acebad2011-07-15 11:21:42 +08001226 u32 *desc = edesc->hw_desc;
Herbert Xu479bcc72015-07-30 17:53:17 +08001227 u32 ivoffset = 0;
Kim Phillips8e8ec592011-03-13 16:54:26 +08001228
Herbert Xu479bcc72015-07-30 17:53:17 +08001229 /*
1230 * AES-CTR needs to load IV in CONTEXT1 reg
1231 * at an offset of 128bits (16bytes)
1232 * CONTEXT1[255:128] = IV
1233 */
1234 if (ctr_mode)
1235 ivoffset = 16;
Kim Phillips8e8ec592011-03-13 16:54:26 +08001236
Herbert Xu479bcc72015-07-30 17:53:17 +08001237 /*
1238 * RFC3686 specific:
1239 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
1240 */
1241 if (is_rfc3686)
1242 ivoffset = 16 + CTR_RFC3686_NONCE_SIZE;
Tudor Ambarusbac68f22014-10-23 16:14:03 +03001243
Herbert Xu479bcc72015-07-30 17:53:17 +08001244 init_aead_job(req, edesc, all_contig, encrypt);
Yuan Kang1acebad2011-07-15 11:21:42 +08001245
Horia Geantă7e0880b2017-12-19 12:16:07 +02001246 /*
1247 * {REG3, DPOVRD} = assoclen, depending on whether MATH command supports
1248 * having DPOVRD as destination.
1249 */
1250 if (ctrlpriv->era < 3)
1251 append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
1252 else
1253 append_math_add_imm_u32(desc, DPOVRD, ZERO, IMM, req->assoclen);
1254
Horia Geantă8b18e232016-08-29 14:52:14 +03001255 if (ivsize && ((is_rfc3686 && encrypt) || !alg->caam.geniv))
Herbert Xu479bcc72015-07-30 17:53:17 +08001256 append_load_as_imm(desc, req->iv, ivsize,
1257 LDST_CLASS_1_CCB |
1258 LDST_SRCDST_BYTE_CONTEXT |
1259 (ivoffset << LDST_OFFSET_SHIFT));
Kim Phillips8e8ec592011-03-13 16:54:26 +08001260}
1261
1262/*
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001263 * Fill in skcipher job descriptor
Yuan Kangacdca312011-07-15 11:21:42 +08001264 */
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001265static void init_skcipher_job(struct skcipher_request *req,
1266 struct skcipher_edesc *edesc,
1267 const bool encrypt)
Yuan Kangacdca312011-07-15 11:21:42 +08001268{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001269 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1270 struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
Sascha Hauer6e005502019-05-23 10:50:29 +02001271 struct device *jrdev = ctx->jrdev;
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001272 int ivsize = crypto_skcipher_ivsize(skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +08001273 u32 *desc = edesc->hw_desc;
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001274 u32 *sh_desc;
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001275 u32 in_options = 0, out_options = 0;
1276 dma_addr_t src_dma, dst_dma, ptr;
1277 int len, sec4_sg_index = 0;
Yuan Kangacdca312011-07-15 11:21:42 +08001278
Sascha Hauer6e005502019-05-23 10:50:29 +02001279 print_hex_dump_debug("presciv@"__stringify(__LINE__)": ",
1280 DUMP_PREFIX_ADDRESS, 16, 4, req->iv, ivsize, 1);
1281 dev_dbg(jrdev, "asked=%d, cryptlen%d\n",
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001282 (int)edesc->src_nents > 1 ? 100 : req->cryptlen, req->cryptlen);
Sascha Hauer6e005502019-05-23 10:50:29 +02001283
Sascha Hauer8a824512019-05-23 10:50:30 +02001284 caam_dump_sg("src @" __stringify(__LINE__)": ",
Horia Geantă972b8122017-07-10 08:40:28 +03001285 DUMP_PREFIX_ADDRESS, 16, 4, req->src,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001286 edesc->src_nents > 1 ? 100 : req->cryptlen, 1);
1287
1288 sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
1289 ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
Yuan Kangacdca312011-07-15 11:21:42 +08001290
1291 len = desc_len(sh_desc);
1292 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
1293
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001294 if (ivsize || edesc->mapped_src_nents > 1) {
1295 src_dma = edesc->sec4_sg_dma;
1296 sec4_sg_index = edesc->mapped_src_nents + !!ivsize;
1297 in_options = LDST_SGF;
1298 } else {
1299 src_dma = sg_dma_address(req->src);
1300 }
1301
1302 append_seq_in_ptr(desc, src_dma, req->cryptlen + ivsize, in_options);
Yuan Kangacdca312011-07-15 11:21:42 +08001303
1304 if (likely(req->src == req->dst)) {
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001305 dst_dma = src_dma + !!ivsize * sizeof(struct sec4_sg_entry);
1306 out_options = in_options;
Horia Geantă334d37c2019-06-10 16:30:59 +03001307 } else if (!ivsize && edesc->mapped_dst_nents == 1) {
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001308 dst_dma = sg_dma_address(req->dst);
Yuan Kangacdca312011-07-15 11:21:42 +08001309 } else {
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001310 dst_dma = edesc->sec4_sg_dma + sec4_sg_index *
1311 sizeof(struct sec4_sg_entry);
1312 out_options = LDST_SGF;
Yuan Kangacdca312011-07-15 11:21:42 +08001313 }
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001314
Horia Geantă334d37c2019-06-10 16:30:59 +03001315 append_seq_out_ptr(desc, dst_dma, req->cryptlen + ivsize, out_options);
Yuan Kangacdca312011-07-15 11:21:42 +08001316}
1317
1318/*
Yuan Kang1acebad2011-07-15 11:21:42 +08001319 * allocate and map the aead extended descriptor
Kim Phillips8e8ec592011-03-13 16:54:26 +08001320 */
Herbert Xuf2147b82015-06-16 13:54:23 +08001321static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
1322 int desc_bytes, bool *all_contig_ptr,
1323 bool encrypt)
1324{
1325 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1326 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1327 struct device *jrdev = ctx->jrdev;
Horia Geantă019d62d2017-06-19 11:44:46 +03001328 gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
1329 GFP_KERNEL : GFP_ATOMIC;
Horia Geantă838e0a82017-02-10 14:07:20 +02001330 int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
Horia Geantă059d73e2019-06-10 16:30:58 +03001331 int src_len, dst_len = 0;
Herbert Xuf2147b82015-06-16 13:54:23 +08001332 struct aead_edesc *edesc;
Horia Geantăfa0c92d2017-02-10 14:07:19 +02001333 int sec4_sg_index, sec4_sg_len, sec4_sg_bytes;
Herbert Xuf2147b82015-06-16 13:54:23 +08001334 unsigned int authsize = ctx->authsize;
1335
1336 if (unlikely(req->dst != req->src)) {
Horia Geantă059d73e2019-06-10 16:30:58 +03001337 src_len = req->assoclen + req->cryptlen;
1338 dst_len = src_len + (encrypt ? authsize : (-authsize));
1339
1340 src_nents = sg_nents_for_len(req->src, src_len);
Horia Geantăfd144d82017-02-10 14:07:18 +02001341 if (unlikely(src_nents < 0)) {
1342 dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
Horia Geantă059d73e2019-06-10 16:30:58 +03001343 src_len);
Horia Geantăfd144d82017-02-10 14:07:18 +02001344 return ERR_PTR(src_nents);
1345 }
1346
Horia Geantă059d73e2019-06-10 16:30:58 +03001347 dst_nents = sg_nents_for_len(req->dst, dst_len);
Horia Geantăfd144d82017-02-10 14:07:18 +02001348 if (unlikely(dst_nents < 0)) {
1349 dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
Horia Geantă059d73e2019-06-10 16:30:58 +03001350 dst_len);
Horia Geantăfd144d82017-02-10 14:07:18 +02001351 return ERR_PTR(dst_nents);
1352 }
Herbert Xuf2147b82015-06-16 13:54:23 +08001353 } else {
Horia Geantă059d73e2019-06-10 16:30:58 +03001354 src_len = req->assoclen + req->cryptlen +
1355 (encrypt ? authsize : 0);
1356
1357 src_nents = sg_nents_for_len(req->src, src_len);
Horia Geantăfd144d82017-02-10 14:07:18 +02001358 if (unlikely(src_nents < 0)) {
1359 dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
Horia Geantă059d73e2019-06-10 16:30:58 +03001360 src_len);
Horia Geantăfd144d82017-02-10 14:07:18 +02001361 return ERR_PTR(src_nents);
1362 }
Herbert Xuf2147b82015-06-16 13:54:23 +08001363 }
1364
Horia Geantă838e0a82017-02-10 14:07:20 +02001365 if (likely(req->src == req->dst)) {
1366 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1367 DMA_BIDIRECTIONAL);
1368 if (unlikely(!mapped_src_nents)) {
1369 dev_err(jrdev, "unable to map source\n");
1370 return ERR_PTR(-ENOMEM);
1371 }
1372 } else {
1373 /* Cover also the case of null (zero length) input data */
1374 if (src_nents) {
1375 mapped_src_nents = dma_map_sg(jrdev, req->src,
1376 src_nents, DMA_TO_DEVICE);
1377 if (unlikely(!mapped_src_nents)) {
1378 dev_err(jrdev, "unable to map source\n");
1379 return ERR_PTR(-ENOMEM);
1380 }
1381 } else {
1382 mapped_src_nents = 0;
1383 }
1384
Horia Geantă763069b2019-01-22 16:47:01 +02001385 /* Cover also the case of null (zero length) output data */
1386 if (dst_nents) {
1387 mapped_dst_nents = dma_map_sg(jrdev, req->dst,
1388 dst_nents,
1389 DMA_FROM_DEVICE);
1390 if (unlikely(!mapped_dst_nents)) {
1391 dev_err(jrdev, "unable to map destination\n");
1392 dma_unmap_sg(jrdev, req->src, src_nents,
1393 DMA_TO_DEVICE);
1394 return ERR_PTR(-ENOMEM);
1395 }
1396 } else {
1397 mapped_dst_nents = 0;
Horia Geantă838e0a82017-02-10 14:07:20 +02001398 }
1399 }
1400
Horia Geantăa5e5c132019-05-03 17:17:38 +03001401 /*
1402 * HW reads 4 S/G entries at a time; make sure the reads don't go beyond
1403 * the end of the table by allocating more S/G entries.
1404 */
Horia Geantă838e0a82017-02-10 14:07:20 +02001405 sec4_sg_len = mapped_src_nents > 1 ? mapped_src_nents : 0;
Horia Geantăa5e5c132019-05-03 17:17:38 +03001406 if (mapped_dst_nents > 1)
1407 sec4_sg_len += pad_sg_nents(mapped_dst_nents);
1408 else
1409 sec4_sg_len = pad_sg_nents(sec4_sg_len);
1410
Herbert Xuf2147b82015-06-16 13:54:23 +08001411 sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
1412
1413 /* allocate space for base edesc and hw desc commands, link tables */
Victoria Milhoandde20ae2015-08-05 11:28:39 -07001414 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
1415 GFP_DMA | flags);
Herbert Xuf2147b82015-06-16 13:54:23 +08001416 if (!edesc) {
Horia Geantă838e0a82017-02-10 14:07:20 +02001417 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
Horia Geantăcf5448b2018-08-06 15:43:57 +03001418 0, 0, 0);
Herbert Xuf2147b82015-06-16 13:54:23 +08001419 return ERR_PTR(-ENOMEM);
1420 }
1421
Herbert Xuf2147b82015-06-16 13:54:23 +08001422 edesc->src_nents = src_nents;
Herbert Xuf2147b82015-06-16 13:54:23 +08001423 edesc->dst_nents = dst_nents;
Iuliana Prodanba4cf712019-02-08 15:50:07 +02001424 edesc->mapped_src_nents = mapped_src_nents;
1425 edesc->mapped_dst_nents = mapped_dst_nents;
Herbert Xuf2147b82015-06-16 13:54:23 +08001426 edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
1427 desc_bytes;
Horia Geantă838e0a82017-02-10 14:07:20 +02001428 *all_contig_ptr = !(mapped_src_nents > 1);
Herbert Xuf2147b82015-06-16 13:54:23 +08001429
1430 sec4_sg_index = 0;
Horia Geantă838e0a82017-02-10 14:07:20 +02001431 if (mapped_src_nents > 1) {
Horia Geantă059d73e2019-06-10 16:30:58 +03001432 sg_to_sec4_sg_last(req->src, src_len,
Horia Geantă838e0a82017-02-10 14:07:20 +02001433 edesc->sec4_sg + sec4_sg_index, 0);
1434 sec4_sg_index += mapped_src_nents;
Herbert Xuf2147b82015-06-16 13:54:23 +08001435 }
Horia Geantă838e0a82017-02-10 14:07:20 +02001436 if (mapped_dst_nents > 1) {
Horia Geantă059d73e2019-06-10 16:30:58 +03001437 sg_to_sec4_sg_last(req->dst, dst_len,
Herbert Xuf2147b82015-06-16 13:54:23 +08001438 edesc->sec4_sg + sec4_sg_index, 0);
1439 }
1440
1441 if (!sec4_sg_bytes)
1442 return edesc;
1443
1444 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
1445 sec4_sg_bytes, DMA_TO_DEVICE);
1446 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
1447 dev_err(jrdev, "unable to map S/G table\n");
1448 aead_unmap(jrdev, edesc, req);
1449 kfree(edesc);
1450 return ERR_PTR(-ENOMEM);
1451 }
1452
1453 edesc->sec4_sg_bytes = sec4_sg_bytes;
1454
1455 return edesc;
1456}
1457
1458static int gcm_encrypt(struct aead_request *req)
Kim Phillips8e8ec592011-03-13 16:54:26 +08001459{
Yuan Kang0e479302011-07-15 11:21:41 +08001460 struct aead_edesc *edesc;
Kim Phillips8e8ec592011-03-13 16:54:26 +08001461 struct crypto_aead *aead = crypto_aead_reqtfm(req);
Kim Phillips8e8ec592011-03-13 16:54:26 +08001462 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1463 struct device *jrdev = ctx->jrdev;
Yuan Kang1acebad2011-07-15 11:21:42 +08001464 bool all_contig;
Kim Phillips8e8ec592011-03-13 16:54:26 +08001465 u32 *desc;
Yuan Kang1acebad2011-07-15 11:21:42 +08001466 int ret = 0;
1467
Kim Phillips8e8ec592011-03-13 16:54:26 +08001468 /* allocate extended descriptor */
Herbert Xuf2147b82015-06-16 13:54:23 +08001469 edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, true);
Kim Phillips8e8ec592011-03-13 16:54:26 +08001470 if (IS_ERR(edesc))
1471 return PTR_ERR(edesc);
1472
Yuan Kang1acebad2011-07-15 11:21:42 +08001473 /* Create and submit job descriptor */
Herbert Xuf2147b82015-06-16 13:54:23 +08001474 init_gcm_job(req, edesc, all_contig, true);
Sascha Hauer6e005502019-05-23 10:50:29 +02001475
1476 print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ",
1477 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1478 desc_bytes(edesc->hw_desc), 1);
Yuan Kang1acebad2011-07-15 11:21:42 +08001479
Kim Phillips8e8ec592011-03-13 16:54:26 +08001480 desc = edesc->hw_desc;
Yuan Kang1acebad2011-07-15 11:21:42 +08001481 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
1482 if (!ret) {
1483 ret = -EINPROGRESS;
1484 } else {
1485 aead_unmap(jrdev, edesc, req);
1486 kfree(edesc);
1487 }
Kim Phillips8e8ec592011-03-13 16:54:26 +08001488
Yuan Kang1acebad2011-07-15 11:21:42 +08001489 return ret;
Kim Phillips8e8ec592011-03-13 16:54:26 +08001490}
1491
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02001492static int chachapoly_encrypt(struct aead_request *req)
1493{
1494 struct aead_edesc *edesc;
1495 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1496 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1497 struct device *jrdev = ctx->jrdev;
1498 bool all_contig;
1499 u32 *desc;
1500 int ret;
1501
1502 edesc = aead_edesc_alloc(req, CHACHAPOLY_DESC_JOB_IO_LEN, &all_contig,
1503 true);
1504 if (IS_ERR(edesc))
1505 return PTR_ERR(edesc);
1506
1507 desc = edesc->hw_desc;
1508
1509 init_chachapoly_job(req, edesc, all_contig, true);
1510 print_hex_dump_debug("chachapoly jobdesc@" __stringify(__LINE__)": ",
1511 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1512 1);
1513
1514 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
1515 if (!ret) {
1516 ret = -EINPROGRESS;
1517 } else {
1518 aead_unmap(jrdev, edesc, req);
1519 kfree(edesc);
1520 }
1521
1522 return ret;
1523}
1524
1525static int chachapoly_decrypt(struct aead_request *req)
1526{
1527 struct aead_edesc *edesc;
1528 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1529 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1530 struct device *jrdev = ctx->jrdev;
1531 bool all_contig;
1532 u32 *desc;
1533 int ret;
1534
1535 edesc = aead_edesc_alloc(req, CHACHAPOLY_DESC_JOB_IO_LEN, &all_contig,
1536 false);
1537 if (IS_ERR(edesc))
1538 return PTR_ERR(edesc);
1539
1540 desc = edesc->hw_desc;
1541
1542 init_chachapoly_job(req, edesc, all_contig, false);
1543 print_hex_dump_debug("chachapoly jobdesc@" __stringify(__LINE__)": ",
1544 DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc),
1545 1);
1546
1547 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
1548 if (!ret) {
1549 ret = -EINPROGRESS;
1550 } else {
1551 aead_unmap(jrdev, edesc, req);
1552 kfree(edesc);
1553 }
1554
1555 return ret;
1556}
1557
Herbert Xu46218752015-07-09 07:17:33 +08001558static int ipsec_gcm_encrypt(struct aead_request *req)
1559{
Iuliana Prodanfcd23ed2019-07-31 16:08:07 +03001560 return crypto_ipsec_check_assoclen(req->assoclen) ? : gcm_encrypt(req);
Herbert Xu46218752015-07-09 07:17:33 +08001561}
1562
Herbert Xu479bcc72015-07-30 17:53:17 +08001563static int aead_encrypt(struct aead_request *req)
Kim Phillips8e8ec592011-03-13 16:54:26 +08001564{
Yuan Kang1acebad2011-07-15 11:21:42 +08001565 struct aead_edesc *edesc;
Yuan Kang0e479302011-07-15 11:21:41 +08001566 struct crypto_aead *aead = crypto_aead_reqtfm(req);
Yuan Kang0e479302011-07-15 11:21:41 +08001567 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1568 struct device *jrdev = ctx->jrdev;
Yuan Kang1acebad2011-07-15 11:21:42 +08001569 bool all_contig;
Yuan Kang0e479302011-07-15 11:21:41 +08001570 u32 *desc;
Yuan Kang1acebad2011-07-15 11:21:42 +08001571 int ret = 0;
Yuan Kang0e479302011-07-15 11:21:41 +08001572
1573 /* allocate extended descriptor */
Herbert Xu479bcc72015-07-30 17:53:17 +08001574 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
1575 &all_contig, true);
Yuan Kang0e479302011-07-15 11:21:41 +08001576 if (IS_ERR(edesc))
1577 return PTR_ERR(edesc);
1578
Herbert Xuf2147b82015-06-16 13:54:23 +08001579 /* Create and submit job descriptor */
Herbert Xu479bcc72015-07-30 17:53:17 +08001580 init_authenc_job(req, edesc, all_contig, true);
Sascha Hauer6e005502019-05-23 10:50:29 +02001581
1582 print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ",
1583 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1584 desc_bytes(edesc->hw_desc), 1);
Yuan Kang1acebad2011-07-15 11:21:42 +08001585
Herbert Xuf2147b82015-06-16 13:54:23 +08001586 desc = edesc->hw_desc;
Herbert Xu479bcc72015-07-30 17:53:17 +08001587 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
Herbert Xuf2147b82015-06-16 13:54:23 +08001588 if (!ret) {
1589 ret = -EINPROGRESS;
1590 } else {
Herbert Xu479bcc72015-07-30 17:53:17 +08001591 aead_unmap(jrdev, edesc, req);
Herbert Xuf2147b82015-06-16 13:54:23 +08001592 kfree(edesc);
1593 }
1594
1595 return ret;
1596}
1597
1598static int gcm_decrypt(struct aead_request *req)
1599{
1600 struct aead_edesc *edesc;
1601 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1602 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1603 struct device *jrdev = ctx->jrdev;
1604 bool all_contig;
1605 u32 *desc;
1606 int ret = 0;
1607
1608 /* allocate extended descriptor */
1609 edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, false);
1610 if (IS_ERR(edesc))
1611 return PTR_ERR(edesc);
1612
Yuan Kang1acebad2011-07-15 11:21:42 +08001613 /* Create and submit job descriptor*/
Herbert Xuf2147b82015-06-16 13:54:23 +08001614 init_gcm_job(req, edesc, all_contig, false);
Sascha Hauer6e005502019-05-23 10:50:29 +02001615
1616 print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ",
1617 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1618 desc_bytes(edesc->hw_desc), 1);
Yuan Kang1acebad2011-07-15 11:21:42 +08001619
Yuan Kang0e479302011-07-15 11:21:41 +08001620 desc = edesc->hw_desc;
Yuan Kang1acebad2011-07-15 11:21:42 +08001621 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
1622 if (!ret) {
1623 ret = -EINPROGRESS;
1624 } else {
1625 aead_unmap(jrdev, edesc, req);
1626 kfree(edesc);
1627 }
Yuan Kang0e479302011-07-15 11:21:41 +08001628
Yuan Kang1acebad2011-07-15 11:21:42 +08001629 return ret;
1630}
Yuan Kang0e479302011-07-15 11:21:41 +08001631
Herbert Xu46218752015-07-09 07:17:33 +08001632static int ipsec_gcm_decrypt(struct aead_request *req)
1633{
Iuliana Prodanfcd23ed2019-07-31 16:08:07 +03001634 return crypto_ipsec_check_assoclen(req->assoclen) ? : gcm_decrypt(req);
Herbert Xu46218752015-07-09 07:17:33 +08001635}
1636
Herbert Xu479bcc72015-07-30 17:53:17 +08001637static int aead_decrypt(struct aead_request *req)
Herbert Xuf2147b82015-06-16 13:54:23 +08001638{
1639 struct aead_edesc *edesc;
1640 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1641 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1642 struct device *jrdev = ctx->jrdev;
1643 bool all_contig;
1644 u32 *desc;
1645 int ret = 0;
1646
Sascha Hauer8a824512019-05-23 10:50:30 +02001647 caam_dump_sg("dec src@" __stringify(__LINE__)": ",
Horia Geantă972b8122017-07-10 08:40:28 +03001648 DUMP_PREFIX_ADDRESS, 16, 4, req->src,
1649 req->assoclen + req->cryptlen, 1);
Catalin Vasile5ecf8ef2016-09-22 11:57:58 +03001650
Herbert Xuf2147b82015-06-16 13:54:23 +08001651 /* allocate extended descriptor */
Herbert Xu479bcc72015-07-30 17:53:17 +08001652 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
1653 &all_contig, false);
Herbert Xuf2147b82015-06-16 13:54:23 +08001654 if (IS_ERR(edesc))
1655 return PTR_ERR(edesc);
1656
Herbert Xuf2147b82015-06-16 13:54:23 +08001657 /* Create and submit job descriptor*/
Herbert Xu479bcc72015-07-30 17:53:17 +08001658 init_authenc_job(req, edesc, all_contig, false);
Sascha Hauer6e005502019-05-23 10:50:29 +02001659
1660 print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ",
1661 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1662 desc_bytes(edesc->hw_desc), 1);
Herbert Xuf2147b82015-06-16 13:54:23 +08001663
1664 desc = edesc->hw_desc;
Herbert Xu479bcc72015-07-30 17:53:17 +08001665 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
Herbert Xuf2147b82015-06-16 13:54:23 +08001666 if (!ret) {
1667 ret = -EINPROGRESS;
1668 } else {
Herbert Xu479bcc72015-07-30 17:53:17 +08001669 aead_unmap(jrdev, edesc, req);
Herbert Xuf2147b82015-06-16 13:54:23 +08001670 kfree(edesc);
1671 }
1672
1673 return ret;
1674}
1675
Yuan Kangacdca312011-07-15 11:21:42 +08001676/*
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001677 * allocate and map the skcipher extended descriptor for skcipher
Yuan Kangacdca312011-07-15 11:21:42 +08001678 */
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001679static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req,
1680 int desc_bytes)
Yuan Kangacdca312011-07-15 11:21:42 +08001681{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001682 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1683 struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +08001684 struct device *jrdev = ctx->jrdev;
Horia Geantă42cfcaf2017-06-19 11:44:45 +03001685 gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
Yuan Kangacdca312011-07-15 11:21:42 +08001686 GFP_KERNEL : GFP_ATOMIC;
Horia Geantă838e0a82017-02-10 14:07:20 +02001687 int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001688 struct skcipher_edesc *edesc;
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001689 dma_addr_t iv_dma = 0;
Horia Geantă115957b2018-03-28 15:39:18 +03001690 u8 *iv;
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001691 int ivsize = crypto_skcipher_ivsize(skcipher);
Horia Geantă838e0a82017-02-10 14:07:20 +02001692 int dst_sg_idx, sec4_sg_ents, sec4_sg_bytes;
Yuan Kangacdca312011-07-15 11:21:42 +08001693
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001694 src_nents = sg_nents_for_len(req->src, req->cryptlen);
Horia Geantăfd144d82017-02-10 14:07:18 +02001695 if (unlikely(src_nents < 0)) {
1696 dev_err(jrdev, "Insufficient bytes (%d) in src S/G\n",
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001697 req->cryptlen);
Horia Geantăfd144d82017-02-10 14:07:18 +02001698 return ERR_PTR(src_nents);
1699 }
Yuan Kangacdca312011-07-15 11:21:42 +08001700
Horia Geantăfd144d82017-02-10 14:07:18 +02001701 if (req->dst != req->src) {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001702 dst_nents = sg_nents_for_len(req->dst, req->cryptlen);
Horia Geantăfd144d82017-02-10 14:07:18 +02001703 if (unlikely(dst_nents < 0)) {
1704 dev_err(jrdev, "Insufficient bytes (%d) in dst S/G\n",
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001705 req->cryptlen);
Horia Geantăfd144d82017-02-10 14:07:18 +02001706 return ERR_PTR(dst_nents);
1707 }
1708 }
Yuan Kangacdca312011-07-15 11:21:42 +08001709
1710 if (likely(req->src == req->dst)) {
Horia Geantă838e0a82017-02-10 14:07:20 +02001711 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1712 DMA_BIDIRECTIONAL);
1713 if (unlikely(!mapped_src_nents)) {
Horia Geantăc73e36e2016-11-09 10:46:20 +02001714 dev_err(jrdev, "unable to map source\n");
1715 return ERR_PTR(-ENOMEM);
1716 }
Yuan Kangacdca312011-07-15 11:21:42 +08001717 } else {
Horia Geantă838e0a82017-02-10 14:07:20 +02001718 mapped_src_nents = dma_map_sg(jrdev, req->src, src_nents,
1719 DMA_TO_DEVICE);
1720 if (unlikely(!mapped_src_nents)) {
Horia Geantăc73e36e2016-11-09 10:46:20 +02001721 dev_err(jrdev, "unable to map source\n");
1722 return ERR_PTR(-ENOMEM);
1723 }
Horia Geantă838e0a82017-02-10 14:07:20 +02001724 mapped_dst_nents = dma_map_sg(jrdev, req->dst, dst_nents,
1725 DMA_FROM_DEVICE);
1726 if (unlikely(!mapped_dst_nents)) {
Horia Geantăc73e36e2016-11-09 10:46:20 +02001727 dev_err(jrdev, "unable to map destination\n");
Horia Geantăfa0c92d2017-02-10 14:07:19 +02001728 dma_unmap_sg(jrdev, req->src, src_nents, DMA_TO_DEVICE);
Horia Geantăc73e36e2016-11-09 10:46:20 +02001729 return ERR_PTR(-ENOMEM);
1730 }
Yuan Kangacdca312011-07-15 11:21:42 +08001731 }
1732
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001733 if (!ivsize && mapped_src_nents == 1)
1734 sec4_sg_ents = 0; // no need for an input hw s/g table
1735 else
1736 sec4_sg_ents = mapped_src_nents + !!ivsize;
Horia Geantăfa0c92d2017-02-10 14:07:19 +02001737 dst_sg_idx = sec4_sg_ents;
Horia Geantăa5e5c132019-05-03 17:17:38 +03001738
1739 /*
Horia Geantă334d37c2019-06-10 16:30:59 +03001740 * Input, output HW S/G tables: [IV, src][dst, IV]
1741 * IV entries point to the same buffer
1742 * If src == dst, S/G entries are reused (S/G tables overlap)
1743 *
Horia Geantăa5e5c132019-05-03 17:17:38 +03001744 * HW reads 4 S/G entries at a time; make sure the reads don't go beyond
1745 * the end of the table by allocating more S/G entries. Logic:
Horia Geantă334d37c2019-06-10 16:30:59 +03001746 * if (output S/G)
Horia Geantăa5e5c132019-05-03 17:17:38 +03001747 * pad output S/G, if needed
Horia Geantăa5e5c132019-05-03 17:17:38 +03001748 * else if (input S/G) ...
1749 * pad input S/G, if needed
1750 */
Horia Geantă334d37c2019-06-10 16:30:59 +03001751 if (ivsize || mapped_dst_nents > 1) {
1752 if (req->src == req->dst)
1753 sec4_sg_ents = !!ivsize + pad_sg_nents(sec4_sg_ents);
1754 else
1755 sec4_sg_ents += pad_sg_nents(mapped_dst_nents +
1756 !!ivsize);
1757 } else {
Horia Geantăa5e5c132019-05-03 17:17:38 +03001758 sec4_sg_ents = pad_sg_nents(sec4_sg_ents);
Horia Geantă334d37c2019-06-10 16:30:59 +03001759 }
Horia Geantăa5e5c132019-05-03 17:17:38 +03001760
Horia Geantăfa0c92d2017-02-10 14:07:19 +02001761 sec4_sg_bytes = sec4_sg_ents * sizeof(struct sec4_sg_entry);
Yuan Kangacdca312011-07-15 11:21:42 +08001762
Horia Geantă115957b2018-03-28 15:39:18 +03001763 /*
1764 * allocate space for base edesc and hw desc commands, link tables, IV
1765 */
1766 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes + ivsize,
Victoria Milhoandde20ae2015-08-05 11:28:39 -07001767 GFP_DMA | flags);
Yuan Kangacdca312011-07-15 11:21:42 +08001768 if (!edesc) {
1769 dev_err(jrdev, "could not allocate extended descriptor\n");
Horia Geantă115957b2018-03-28 15:39:18 +03001770 caam_unmap(jrdev, req->src, req->dst, src_nents, dst_nents, 0,
Horia Geantăcf5448b2018-08-06 15:43:57 +03001771 0, 0, 0);
Yuan Kangacdca312011-07-15 11:21:42 +08001772 return ERR_PTR(-ENOMEM);
1773 }
1774
1775 edesc->src_nents = src_nents;
1776 edesc->dst_nents = dst_nents;
Iuliana Prodanba4cf712019-02-08 15:50:07 +02001777 edesc->mapped_src_nents = mapped_src_nents;
1778 edesc->mapped_dst_nents = mapped_dst_nents;
Yuan Kanga299c832012-06-22 19:48:46 -05001779 edesc->sec4_sg_bytes = sec4_sg_bytes;
Horia Geantă13cc6f42018-09-14 18:34:28 +03001780 edesc->sec4_sg = (struct sec4_sg_entry *)((u8 *)edesc->hw_desc +
1781 desc_bytes);
Yuan Kangacdca312011-07-15 11:21:42 +08001782
Horia Geantă115957b2018-03-28 15:39:18 +03001783 /* Make sure IV is located in a DMAable area */
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001784 if (ivsize) {
Horia Geantă334d37c2019-06-10 16:30:59 +03001785 iv = (u8 *)edesc->sec4_sg + sec4_sg_bytes;
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001786 memcpy(iv, req->iv, ivsize);
Horia Geantă115957b2018-03-28 15:39:18 +03001787
Horia Geantă334d37c2019-06-10 16:30:59 +03001788 iv_dma = dma_map_single(jrdev, iv, ivsize, DMA_BIDIRECTIONAL);
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001789 if (dma_mapping_error(jrdev, iv_dma)) {
1790 dev_err(jrdev, "unable to map IV\n");
1791 caam_unmap(jrdev, req->src, req->dst, src_nents,
1792 dst_nents, 0, 0, 0, 0);
1793 kfree(edesc);
1794 return ERR_PTR(-ENOMEM);
1795 }
1796
1797 dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
Yuan Kangacdca312011-07-15 11:21:42 +08001798 }
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001799 if (dst_sg_idx)
Horia Geantă334d37c2019-06-10 16:30:59 +03001800 sg_to_sec4_sg(req->src, req->cryptlen, edesc->sec4_sg +
1801 !!ivsize, 0);
Horia Geantă115957b2018-03-28 15:39:18 +03001802
Horia Geantă334d37c2019-06-10 16:30:59 +03001803 if (req->src != req->dst && (ivsize || mapped_dst_nents > 1))
1804 sg_to_sec4_sg(req->dst, req->cryptlen, edesc->sec4_sg +
1805 dst_sg_idx, 0);
1806
1807 if (ivsize)
1808 dma_to_sec4_sg_one(edesc->sec4_sg + dst_sg_idx +
1809 mapped_dst_nents, iv_dma, ivsize, 0);
1810
1811 if (ivsize || mapped_dst_nents > 1)
1812 sg_to_sec4_set_last(edesc->sec4_sg + dst_sg_idx +
1813 mapped_dst_nents);
Yuan Kangacdca312011-07-15 11:21:42 +08001814
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02001815 if (sec4_sg_bytes) {
1816 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
1817 sec4_sg_bytes,
1818 DMA_TO_DEVICE);
1819 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
1820 dev_err(jrdev, "unable to map S/G table\n");
1821 caam_unmap(jrdev, req->src, req->dst, src_nents,
1822 dst_nents, iv_dma, ivsize, 0, 0);
1823 kfree(edesc);
1824 return ERR_PTR(-ENOMEM);
1825 }
Horia Geantace572082014-07-11 15:34:49 +03001826 }
1827
Yuan Kangacdca312011-07-15 11:21:42 +08001828 edesc->iv_dma = iv_dma;
1829
Sascha Hauer6e005502019-05-23 10:50:29 +02001830 print_hex_dump_debug("skcipher sec4_sg@" __stringify(__LINE__)": ",
1831 DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
1832 sec4_sg_bytes, 1);
Yuan Kangacdca312011-07-15 11:21:42 +08001833
Yuan Kangacdca312011-07-15 11:21:42 +08001834 return edesc;
1835}
1836
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001837static int skcipher_encrypt(struct skcipher_request *req)
Yuan Kangacdca312011-07-15 11:21:42 +08001838{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001839 struct skcipher_edesc *edesc;
1840 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1841 struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +08001842 struct device *jrdev = ctx->jrdev;
Yuan Kangacdca312011-07-15 11:21:42 +08001843 u32 *desc;
1844 int ret = 0;
1845
Iuliana Prodan31bb2f02019-07-31 16:08:08 +03001846 if (!req->cryptlen)
1847 return 0;
1848
Yuan Kangacdca312011-07-15 11:21:42 +08001849 /* allocate extended descriptor */
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001850 edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ);
Yuan Kangacdca312011-07-15 11:21:42 +08001851 if (IS_ERR(edesc))
1852 return PTR_ERR(edesc);
1853
1854 /* Create and submit job descriptor*/
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001855 init_skcipher_job(req, edesc, true);
Sascha Hauer6e005502019-05-23 10:50:29 +02001856
1857 print_hex_dump_debug("skcipher jobdesc@" __stringify(__LINE__)": ",
1858 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1859 desc_bytes(edesc->hw_desc), 1);
1860
Yuan Kangacdca312011-07-15 11:21:42 +08001861 desc = edesc->hw_desc;
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001862 ret = caam_jr_enqueue(jrdev, desc, skcipher_encrypt_done, req);
Yuan Kangacdca312011-07-15 11:21:42 +08001863
1864 if (!ret) {
1865 ret = -EINPROGRESS;
1866 } else {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001867 skcipher_unmap(jrdev, edesc, req);
Yuan Kangacdca312011-07-15 11:21:42 +08001868 kfree(edesc);
1869 }
1870
1871 return ret;
1872}
1873
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001874static int skcipher_decrypt(struct skcipher_request *req)
Yuan Kangacdca312011-07-15 11:21:42 +08001875{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001876 struct skcipher_edesc *edesc;
1877 struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
1878 struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
Yuan Kangacdca312011-07-15 11:21:42 +08001879 struct device *jrdev = ctx->jrdev;
Yuan Kangacdca312011-07-15 11:21:42 +08001880 u32 *desc;
1881 int ret = 0;
1882
Iuliana Prodan31bb2f02019-07-31 16:08:08 +03001883 if (!req->cryptlen)
1884 return 0;
1885
Yuan Kangacdca312011-07-15 11:21:42 +08001886 /* allocate extended descriptor */
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001887 edesc = skcipher_edesc_alloc(req, DESC_JOB_IO_LEN * CAAM_CMD_SZ);
Yuan Kangacdca312011-07-15 11:21:42 +08001888 if (IS_ERR(edesc))
1889 return PTR_ERR(edesc);
1890
1891 /* Create and submit job descriptor*/
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001892 init_skcipher_job(req, edesc, false);
Yuan Kangacdca312011-07-15 11:21:42 +08001893 desc = edesc->hw_desc;
Sascha Hauer6e005502019-05-23 10:50:29 +02001894
1895 print_hex_dump_debug("skcipher jobdesc@" __stringify(__LINE__)": ",
1896 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
1897 desc_bytes(edesc->hw_desc), 1);
Yuan Kangacdca312011-07-15 11:21:42 +08001898
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001899 ret = caam_jr_enqueue(jrdev, desc, skcipher_decrypt_done, req);
Yuan Kangacdca312011-07-15 11:21:42 +08001900 if (!ret) {
1901 ret = -EINPROGRESS;
1902 } else {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001903 skcipher_unmap(jrdev, edesc, req);
Yuan Kangacdca312011-07-15 11:21:42 +08001904 kfree(edesc);
1905 }
1906
1907 return ret;
1908}
1909
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001910static struct caam_skcipher_alg driver_algs[] = {
Yuan Kangacdca312011-07-15 11:21:42 +08001911 {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001912 .skcipher = {
1913 .base = {
1914 .cra_name = "cbc(aes)",
1915 .cra_driver_name = "cbc-aes-caam",
1916 .cra_blocksize = AES_BLOCK_SIZE,
1917 },
Iuliana Prodan836d8f42019-07-31 16:08:05 +03001918 .setkey = aes_skcipher_setkey,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001919 .encrypt = skcipher_encrypt,
1920 .decrypt = skcipher_decrypt,
Yuan Kangacdca312011-07-15 11:21:42 +08001921 .min_keysize = AES_MIN_KEY_SIZE,
1922 .max_keysize = AES_MAX_KEY_SIZE,
1923 .ivsize = AES_BLOCK_SIZE,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001924 },
1925 .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
Yuan Kangacdca312011-07-15 11:21:42 +08001926 },
1927 {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001928 .skcipher = {
1929 .base = {
1930 .cra_name = "cbc(des3_ede)",
1931 .cra_driver_name = "cbc-3des-caam",
1932 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
1933 },
Ard Biesheuvela628c5a2019-08-15 12:00:48 +03001934 .setkey = des3_skcipher_setkey,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001935 .encrypt = skcipher_encrypt,
1936 .decrypt = skcipher_decrypt,
Yuan Kangacdca312011-07-15 11:21:42 +08001937 .min_keysize = DES3_EDE_KEY_SIZE,
1938 .max_keysize = DES3_EDE_KEY_SIZE,
1939 .ivsize = DES3_EDE_BLOCK_SIZE,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001940 },
1941 .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
Yuan Kangacdca312011-07-15 11:21:42 +08001942 },
1943 {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001944 .skcipher = {
1945 .base = {
1946 .cra_name = "cbc(des)",
1947 .cra_driver_name = "cbc-des-caam",
1948 .cra_blocksize = DES_BLOCK_SIZE,
1949 },
Iuliana Prodancf64e492019-02-08 15:50:10 +02001950 .setkey = des_skcipher_setkey,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001951 .encrypt = skcipher_encrypt,
1952 .decrypt = skcipher_decrypt,
Yuan Kangacdca312011-07-15 11:21:42 +08001953 .min_keysize = DES_KEY_SIZE,
1954 .max_keysize = DES_KEY_SIZE,
1955 .ivsize = DES_BLOCK_SIZE,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001956 },
1957 .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
Catalin Vasile2b22f6c2014-10-31 12:45:35 +02001958 },
1959 {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001960 .skcipher = {
1961 .base = {
1962 .cra_name = "ctr(aes)",
1963 .cra_driver_name = "ctr-aes-caam",
1964 .cra_blocksize = 1,
1965 },
Iuliana Prodan836d8f42019-07-31 16:08:05 +03001966 .setkey = ctr_skcipher_setkey,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001967 .encrypt = skcipher_encrypt,
1968 .decrypt = skcipher_decrypt,
Catalin Vasile2b22f6c2014-10-31 12:45:35 +02001969 .min_keysize = AES_MIN_KEY_SIZE,
1970 .max_keysize = AES_MAX_KEY_SIZE,
1971 .ivsize = AES_BLOCK_SIZE,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001972 .chunksize = AES_BLOCK_SIZE,
1973 },
1974 .caam.class1_alg_type = OP_ALG_ALGSEL_AES |
1975 OP_ALG_AAI_CTR_MOD128,
Catalin Vasilea5f57cf2014-10-31 12:45:36 +02001976 },
1977 {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001978 .skcipher = {
1979 .base = {
1980 .cra_name = "rfc3686(ctr(aes))",
1981 .cra_driver_name = "rfc3686-ctr-aes-caam",
1982 .cra_blocksize = 1,
1983 },
Iuliana Prodan836d8f42019-07-31 16:08:05 +03001984 .setkey = rfc3686_skcipher_setkey,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001985 .encrypt = skcipher_encrypt,
1986 .decrypt = skcipher_decrypt,
Catalin Vasilea5f57cf2014-10-31 12:45:36 +02001987 .min_keysize = AES_MIN_KEY_SIZE +
1988 CTR_RFC3686_NONCE_SIZE,
1989 .max_keysize = AES_MAX_KEY_SIZE +
1990 CTR_RFC3686_NONCE_SIZE,
1991 .ivsize = CTR_RFC3686_IV_SIZE,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03001992 .chunksize = AES_BLOCK_SIZE,
1993 },
1994 .caam = {
1995 .class1_alg_type = OP_ALG_ALGSEL_AES |
1996 OP_ALG_AAI_CTR_MOD128,
1997 .rfc3686 = true,
1998 },
Catalin Vasilec6415a62015-10-02 13:13:18 +03001999 },
2000 {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03002001 .skcipher = {
2002 .base = {
2003 .cra_name = "xts(aes)",
2004 .cra_driver_name = "xts-aes-caam",
2005 .cra_blocksize = AES_BLOCK_SIZE,
2006 },
2007 .setkey = xts_skcipher_setkey,
2008 .encrypt = skcipher_encrypt,
2009 .decrypt = skcipher_decrypt,
Catalin Vasilec6415a62015-10-02 13:13:18 +03002010 .min_keysize = 2 * AES_MIN_KEY_SIZE,
2011 .max_keysize = 2 * AES_MAX_KEY_SIZE,
2012 .ivsize = AES_BLOCK_SIZE,
Horia Geantă5ca7bad2018-08-06 15:43:59 +03002013 },
2014 .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
Catalin Vasilec6415a62015-10-02 13:13:18 +03002015 },
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02002016 {
2017 .skcipher = {
2018 .base = {
2019 .cra_name = "ecb(des)",
2020 .cra_driver_name = "ecb-des-caam",
2021 .cra_blocksize = DES_BLOCK_SIZE,
2022 },
2023 .setkey = des_skcipher_setkey,
2024 .encrypt = skcipher_encrypt,
2025 .decrypt = skcipher_decrypt,
2026 .min_keysize = DES_KEY_SIZE,
2027 .max_keysize = DES_KEY_SIZE,
2028 },
2029 .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_ECB,
2030 },
2031 {
2032 .skcipher = {
2033 .base = {
2034 .cra_name = "ecb(aes)",
2035 .cra_driver_name = "ecb-aes-caam",
2036 .cra_blocksize = AES_BLOCK_SIZE,
2037 },
Iuliana Prodan836d8f42019-07-31 16:08:05 +03002038 .setkey = aes_skcipher_setkey,
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02002039 .encrypt = skcipher_encrypt,
2040 .decrypt = skcipher_decrypt,
2041 .min_keysize = AES_MIN_KEY_SIZE,
2042 .max_keysize = AES_MAX_KEY_SIZE,
2043 },
2044 .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_ECB,
2045 },
2046 {
2047 .skcipher = {
2048 .base = {
2049 .cra_name = "ecb(des3_ede)",
2050 .cra_driver_name = "ecb-des3-caam",
2051 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2052 },
Ard Biesheuvela628c5a2019-08-15 12:00:48 +03002053 .setkey = des3_skcipher_setkey,
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02002054 .encrypt = skcipher_encrypt,
2055 .decrypt = skcipher_decrypt,
2056 .min_keysize = DES3_EDE_KEY_SIZE,
2057 .max_keysize = DES3_EDE_KEY_SIZE,
2058 },
2059 .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_ECB,
2060 },
2061 {
2062 .skcipher = {
2063 .base = {
2064 .cra_name = "ecb(arc4)",
2065 .cra_driver_name = "ecb-arc4-caam",
2066 .cra_blocksize = ARC4_BLOCK_SIZE,
2067 },
Iuliana Prodan836d8f42019-07-31 16:08:05 +03002068 .setkey = arc4_skcipher_setkey,
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02002069 .encrypt = skcipher_encrypt,
2070 .decrypt = skcipher_decrypt,
2071 .min_keysize = ARC4_MIN_KEY_SIZE,
2072 .max_keysize = ARC4_MAX_KEY_SIZE,
2073 },
2074 .caam.class1_alg_type = OP_ALG_ALGSEL_ARC4 | OP_ALG_AAI_ECB,
2075 },
Kim Phillips8e8ec592011-03-13 16:54:26 +08002076};
2077
Herbert Xuf2147b82015-06-16 13:54:23 +08002078static struct caam_aead_alg driver_aeads[] = {
2079 {
2080 .aead = {
2081 .base = {
2082 .cra_name = "rfc4106(gcm(aes))",
2083 .cra_driver_name = "rfc4106-gcm-aes-caam",
2084 .cra_blocksize = 1,
2085 },
2086 .setkey = rfc4106_setkey,
2087 .setauthsize = rfc4106_setauthsize,
Herbert Xu46218752015-07-09 07:17:33 +08002088 .encrypt = ipsec_gcm_encrypt,
2089 .decrypt = ipsec_gcm_decrypt,
Corentin LABBE7545e162017-08-22 10:08:09 +02002090 .ivsize = GCM_RFC4106_IV_SIZE,
Herbert Xuf2147b82015-06-16 13:54:23 +08002091 .maxauthsize = AES_BLOCK_SIZE,
2092 },
2093 .caam = {
2094 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
Herbert Xu24586b52019-05-06 14:39:44 +08002095 .nodkp = true,
Herbert Xuf2147b82015-06-16 13:54:23 +08002096 },
2097 },
2098 {
2099 .aead = {
2100 .base = {
2101 .cra_name = "rfc4543(gcm(aes))",
2102 .cra_driver_name = "rfc4543-gcm-aes-caam",
2103 .cra_blocksize = 1,
2104 },
2105 .setkey = rfc4543_setkey,
2106 .setauthsize = rfc4543_setauthsize,
Herbert Xu46218752015-07-09 07:17:33 +08002107 .encrypt = ipsec_gcm_encrypt,
2108 .decrypt = ipsec_gcm_decrypt,
Corentin LABBE7545e162017-08-22 10:08:09 +02002109 .ivsize = GCM_RFC4543_IV_SIZE,
Herbert Xuf2147b82015-06-16 13:54:23 +08002110 .maxauthsize = AES_BLOCK_SIZE,
2111 },
2112 .caam = {
2113 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
Herbert Xu24586b52019-05-06 14:39:44 +08002114 .nodkp = true,
Herbert Xuf2147b82015-06-16 13:54:23 +08002115 },
2116 },
2117 /* Galois Counter Mode */
2118 {
2119 .aead = {
2120 .base = {
2121 .cra_name = "gcm(aes)",
2122 .cra_driver_name = "gcm-aes-caam",
2123 .cra_blocksize = 1,
2124 },
2125 .setkey = gcm_setkey,
2126 .setauthsize = gcm_setauthsize,
2127 .encrypt = gcm_encrypt,
2128 .decrypt = gcm_decrypt,
Corentin LABBE7545e162017-08-22 10:08:09 +02002129 .ivsize = GCM_AES_IV_SIZE,
Herbert Xuf2147b82015-06-16 13:54:23 +08002130 .maxauthsize = AES_BLOCK_SIZE,
2131 },
2132 .caam = {
2133 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
Herbert Xu24586b52019-05-06 14:39:44 +08002134 .nodkp = true,
Herbert Xuf2147b82015-06-16 13:54:23 +08002135 },
2136 },
Herbert Xu479bcc72015-07-30 17:53:17 +08002137 /* single-pass ipsec_esp descriptor */
2138 {
2139 .aead = {
2140 .base = {
2141 .cra_name = "authenc(hmac(md5),"
2142 "ecb(cipher_null))",
2143 .cra_driver_name = "authenc-hmac-md5-"
2144 "ecb-cipher_null-caam",
2145 .cra_blocksize = NULL_BLOCK_SIZE,
2146 },
2147 .setkey = aead_setkey,
2148 .setauthsize = aead_setauthsize,
2149 .encrypt = aead_encrypt,
2150 .decrypt = aead_decrypt,
2151 .ivsize = NULL_IV_SIZE,
2152 .maxauthsize = MD5_DIGEST_SIZE,
2153 },
2154 .caam = {
2155 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2156 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002157 },
2158 },
2159 {
2160 .aead = {
2161 .base = {
2162 .cra_name = "authenc(hmac(sha1),"
2163 "ecb(cipher_null))",
2164 .cra_driver_name = "authenc-hmac-sha1-"
2165 "ecb-cipher_null-caam",
2166 .cra_blocksize = NULL_BLOCK_SIZE,
2167 },
2168 .setkey = aead_setkey,
2169 .setauthsize = aead_setauthsize,
2170 .encrypt = aead_encrypt,
2171 .decrypt = aead_decrypt,
2172 .ivsize = NULL_IV_SIZE,
2173 .maxauthsize = SHA1_DIGEST_SIZE,
2174 },
2175 .caam = {
2176 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2177 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002178 },
2179 },
2180 {
2181 .aead = {
2182 .base = {
2183 .cra_name = "authenc(hmac(sha224),"
2184 "ecb(cipher_null))",
2185 .cra_driver_name = "authenc-hmac-sha224-"
2186 "ecb-cipher_null-caam",
2187 .cra_blocksize = NULL_BLOCK_SIZE,
2188 },
2189 .setkey = aead_setkey,
2190 .setauthsize = aead_setauthsize,
2191 .encrypt = aead_encrypt,
2192 .decrypt = aead_decrypt,
2193 .ivsize = NULL_IV_SIZE,
2194 .maxauthsize = SHA224_DIGEST_SIZE,
2195 },
2196 .caam = {
2197 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2198 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002199 },
2200 },
2201 {
2202 .aead = {
2203 .base = {
2204 .cra_name = "authenc(hmac(sha256),"
2205 "ecb(cipher_null))",
2206 .cra_driver_name = "authenc-hmac-sha256-"
2207 "ecb-cipher_null-caam",
2208 .cra_blocksize = NULL_BLOCK_SIZE,
2209 },
2210 .setkey = aead_setkey,
2211 .setauthsize = aead_setauthsize,
2212 .encrypt = aead_encrypt,
2213 .decrypt = aead_decrypt,
2214 .ivsize = NULL_IV_SIZE,
2215 .maxauthsize = SHA256_DIGEST_SIZE,
2216 },
2217 .caam = {
2218 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2219 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002220 },
2221 },
2222 {
2223 .aead = {
2224 .base = {
2225 .cra_name = "authenc(hmac(sha384),"
2226 "ecb(cipher_null))",
2227 .cra_driver_name = "authenc-hmac-sha384-"
2228 "ecb-cipher_null-caam",
2229 .cra_blocksize = NULL_BLOCK_SIZE,
2230 },
2231 .setkey = aead_setkey,
2232 .setauthsize = aead_setauthsize,
2233 .encrypt = aead_encrypt,
2234 .decrypt = aead_decrypt,
2235 .ivsize = NULL_IV_SIZE,
2236 .maxauthsize = SHA384_DIGEST_SIZE,
2237 },
2238 .caam = {
2239 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2240 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002241 },
2242 },
2243 {
2244 .aead = {
2245 .base = {
2246 .cra_name = "authenc(hmac(sha512),"
2247 "ecb(cipher_null))",
2248 .cra_driver_name = "authenc-hmac-sha512-"
2249 "ecb-cipher_null-caam",
2250 .cra_blocksize = NULL_BLOCK_SIZE,
2251 },
2252 .setkey = aead_setkey,
2253 .setauthsize = aead_setauthsize,
2254 .encrypt = aead_encrypt,
2255 .decrypt = aead_decrypt,
2256 .ivsize = NULL_IV_SIZE,
2257 .maxauthsize = SHA512_DIGEST_SIZE,
2258 },
2259 .caam = {
2260 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2261 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002262 },
2263 },
2264 {
2265 .aead = {
2266 .base = {
2267 .cra_name = "authenc(hmac(md5),cbc(aes))",
2268 .cra_driver_name = "authenc-hmac-md5-"
2269 "cbc-aes-caam",
2270 .cra_blocksize = AES_BLOCK_SIZE,
2271 },
2272 .setkey = aead_setkey,
2273 .setauthsize = aead_setauthsize,
2274 .encrypt = aead_encrypt,
2275 .decrypt = aead_decrypt,
2276 .ivsize = AES_BLOCK_SIZE,
2277 .maxauthsize = MD5_DIGEST_SIZE,
2278 },
2279 .caam = {
2280 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2281 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2282 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002283 },
2284 },
2285 {
2286 .aead = {
2287 .base = {
2288 .cra_name = "echainiv(authenc(hmac(md5),"
2289 "cbc(aes)))",
2290 .cra_driver_name = "echainiv-authenc-hmac-md5-"
2291 "cbc-aes-caam",
2292 .cra_blocksize = AES_BLOCK_SIZE,
2293 },
2294 .setkey = aead_setkey,
2295 .setauthsize = aead_setauthsize,
2296 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002297 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002298 .ivsize = AES_BLOCK_SIZE,
2299 .maxauthsize = MD5_DIGEST_SIZE,
2300 },
2301 .caam = {
2302 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2303 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2304 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002305 .geniv = true,
2306 },
2307 },
2308 {
2309 .aead = {
2310 .base = {
2311 .cra_name = "authenc(hmac(sha1),cbc(aes))",
2312 .cra_driver_name = "authenc-hmac-sha1-"
2313 "cbc-aes-caam",
2314 .cra_blocksize = AES_BLOCK_SIZE,
2315 },
2316 .setkey = aead_setkey,
2317 .setauthsize = aead_setauthsize,
2318 .encrypt = aead_encrypt,
2319 .decrypt = aead_decrypt,
2320 .ivsize = AES_BLOCK_SIZE,
2321 .maxauthsize = SHA1_DIGEST_SIZE,
2322 },
2323 .caam = {
2324 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2325 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2326 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002327 },
2328 },
2329 {
2330 .aead = {
2331 .base = {
2332 .cra_name = "echainiv(authenc(hmac(sha1),"
2333 "cbc(aes)))",
2334 .cra_driver_name = "echainiv-authenc-"
2335 "hmac-sha1-cbc-aes-caam",
2336 .cra_blocksize = AES_BLOCK_SIZE,
2337 },
2338 .setkey = aead_setkey,
2339 .setauthsize = aead_setauthsize,
2340 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002341 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002342 .ivsize = AES_BLOCK_SIZE,
2343 .maxauthsize = SHA1_DIGEST_SIZE,
2344 },
2345 .caam = {
2346 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2347 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2348 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002349 .geniv = true,
2350 },
2351 },
2352 {
2353 .aead = {
2354 .base = {
2355 .cra_name = "authenc(hmac(sha224),cbc(aes))",
2356 .cra_driver_name = "authenc-hmac-sha224-"
2357 "cbc-aes-caam",
2358 .cra_blocksize = AES_BLOCK_SIZE,
2359 },
2360 .setkey = aead_setkey,
2361 .setauthsize = aead_setauthsize,
2362 .encrypt = aead_encrypt,
2363 .decrypt = aead_decrypt,
2364 .ivsize = AES_BLOCK_SIZE,
2365 .maxauthsize = SHA224_DIGEST_SIZE,
2366 },
2367 .caam = {
2368 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2369 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2370 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002371 },
2372 },
2373 {
2374 .aead = {
2375 .base = {
2376 .cra_name = "echainiv(authenc(hmac(sha224),"
2377 "cbc(aes)))",
2378 .cra_driver_name = "echainiv-authenc-"
2379 "hmac-sha224-cbc-aes-caam",
2380 .cra_blocksize = AES_BLOCK_SIZE,
2381 },
2382 .setkey = aead_setkey,
2383 .setauthsize = aead_setauthsize,
2384 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002385 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002386 .ivsize = AES_BLOCK_SIZE,
2387 .maxauthsize = SHA224_DIGEST_SIZE,
2388 },
2389 .caam = {
2390 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2391 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2392 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002393 .geniv = true,
2394 },
2395 },
2396 {
2397 .aead = {
2398 .base = {
2399 .cra_name = "authenc(hmac(sha256),cbc(aes))",
2400 .cra_driver_name = "authenc-hmac-sha256-"
2401 "cbc-aes-caam",
2402 .cra_blocksize = AES_BLOCK_SIZE,
2403 },
2404 .setkey = aead_setkey,
2405 .setauthsize = aead_setauthsize,
2406 .encrypt = aead_encrypt,
2407 .decrypt = aead_decrypt,
2408 .ivsize = AES_BLOCK_SIZE,
2409 .maxauthsize = SHA256_DIGEST_SIZE,
2410 },
2411 .caam = {
2412 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2413 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2414 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002415 },
2416 },
2417 {
2418 .aead = {
2419 .base = {
2420 .cra_name = "echainiv(authenc(hmac(sha256),"
2421 "cbc(aes)))",
2422 .cra_driver_name = "echainiv-authenc-"
2423 "hmac-sha256-cbc-aes-caam",
2424 .cra_blocksize = AES_BLOCK_SIZE,
2425 },
2426 .setkey = aead_setkey,
2427 .setauthsize = aead_setauthsize,
2428 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002429 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002430 .ivsize = AES_BLOCK_SIZE,
2431 .maxauthsize = SHA256_DIGEST_SIZE,
2432 },
2433 .caam = {
2434 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2435 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2436 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002437 .geniv = true,
2438 },
2439 },
2440 {
2441 .aead = {
2442 .base = {
2443 .cra_name = "authenc(hmac(sha384),cbc(aes))",
2444 .cra_driver_name = "authenc-hmac-sha384-"
2445 "cbc-aes-caam",
2446 .cra_blocksize = AES_BLOCK_SIZE,
2447 },
2448 .setkey = aead_setkey,
2449 .setauthsize = aead_setauthsize,
2450 .encrypt = aead_encrypt,
2451 .decrypt = aead_decrypt,
2452 .ivsize = AES_BLOCK_SIZE,
2453 .maxauthsize = SHA384_DIGEST_SIZE,
2454 },
2455 .caam = {
2456 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2457 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2458 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002459 },
2460 },
2461 {
2462 .aead = {
2463 .base = {
2464 .cra_name = "echainiv(authenc(hmac(sha384),"
2465 "cbc(aes)))",
2466 .cra_driver_name = "echainiv-authenc-"
2467 "hmac-sha384-cbc-aes-caam",
2468 .cra_blocksize = AES_BLOCK_SIZE,
2469 },
2470 .setkey = aead_setkey,
2471 .setauthsize = aead_setauthsize,
2472 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002473 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002474 .ivsize = AES_BLOCK_SIZE,
2475 .maxauthsize = SHA384_DIGEST_SIZE,
2476 },
2477 .caam = {
2478 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2479 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2480 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002481 .geniv = true,
2482 },
2483 },
2484 {
2485 .aead = {
2486 .base = {
2487 .cra_name = "authenc(hmac(sha512),cbc(aes))",
2488 .cra_driver_name = "authenc-hmac-sha512-"
2489 "cbc-aes-caam",
2490 .cra_blocksize = AES_BLOCK_SIZE,
2491 },
2492 .setkey = aead_setkey,
2493 .setauthsize = aead_setauthsize,
2494 .encrypt = aead_encrypt,
2495 .decrypt = aead_decrypt,
2496 .ivsize = AES_BLOCK_SIZE,
2497 .maxauthsize = SHA512_DIGEST_SIZE,
2498 },
2499 .caam = {
2500 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2501 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2502 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002503 },
2504 },
2505 {
2506 .aead = {
2507 .base = {
2508 .cra_name = "echainiv(authenc(hmac(sha512),"
2509 "cbc(aes)))",
2510 .cra_driver_name = "echainiv-authenc-"
2511 "hmac-sha512-cbc-aes-caam",
2512 .cra_blocksize = AES_BLOCK_SIZE,
2513 },
2514 .setkey = aead_setkey,
2515 .setauthsize = aead_setauthsize,
2516 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002517 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002518 .ivsize = AES_BLOCK_SIZE,
2519 .maxauthsize = SHA512_DIGEST_SIZE,
2520 },
2521 .caam = {
2522 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2523 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2524 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002525 .geniv = true,
2526 },
2527 },
2528 {
2529 .aead = {
2530 .base = {
2531 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
2532 .cra_driver_name = "authenc-hmac-md5-"
2533 "cbc-des3_ede-caam",
2534 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2535 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002536 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002537 .setauthsize = aead_setauthsize,
2538 .encrypt = aead_encrypt,
2539 .decrypt = aead_decrypt,
2540 .ivsize = DES3_EDE_BLOCK_SIZE,
2541 .maxauthsize = MD5_DIGEST_SIZE,
2542 },
2543 .caam = {
2544 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2545 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2546 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002547 }
2548 },
2549 {
2550 .aead = {
2551 .base = {
2552 .cra_name = "echainiv(authenc(hmac(md5),"
2553 "cbc(des3_ede)))",
2554 .cra_driver_name = "echainiv-authenc-hmac-md5-"
2555 "cbc-des3_ede-caam",
2556 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2557 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002558 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002559 .setauthsize = aead_setauthsize,
2560 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002561 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002562 .ivsize = DES3_EDE_BLOCK_SIZE,
2563 .maxauthsize = MD5_DIGEST_SIZE,
2564 },
2565 .caam = {
2566 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2567 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2568 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002569 .geniv = true,
2570 }
2571 },
2572 {
2573 .aead = {
2574 .base = {
2575 .cra_name = "authenc(hmac(sha1),"
2576 "cbc(des3_ede))",
2577 .cra_driver_name = "authenc-hmac-sha1-"
2578 "cbc-des3_ede-caam",
2579 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2580 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002581 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002582 .setauthsize = aead_setauthsize,
2583 .encrypt = aead_encrypt,
2584 .decrypt = aead_decrypt,
2585 .ivsize = DES3_EDE_BLOCK_SIZE,
2586 .maxauthsize = SHA1_DIGEST_SIZE,
2587 },
2588 .caam = {
2589 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2590 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2591 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002592 },
2593 },
2594 {
2595 .aead = {
2596 .base = {
2597 .cra_name = "echainiv(authenc(hmac(sha1),"
2598 "cbc(des3_ede)))",
2599 .cra_driver_name = "echainiv-authenc-"
2600 "hmac-sha1-"
2601 "cbc-des3_ede-caam",
2602 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2603 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002604 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002605 .setauthsize = aead_setauthsize,
2606 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002607 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002608 .ivsize = DES3_EDE_BLOCK_SIZE,
2609 .maxauthsize = SHA1_DIGEST_SIZE,
2610 },
2611 .caam = {
2612 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2613 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2614 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002615 .geniv = true,
2616 },
2617 },
2618 {
2619 .aead = {
2620 .base = {
2621 .cra_name = "authenc(hmac(sha224),"
2622 "cbc(des3_ede))",
2623 .cra_driver_name = "authenc-hmac-sha224-"
2624 "cbc-des3_ede-caam",
2625 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2626 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002627 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002628 .setauthsize = aead_setauthsize,
2629 .encrypt = aead_encrypt,
2630 .decrypt = aead_decrypt,
2631 .ivsize = DES3_EDE_BLOCK_SIZE,
2632 .maxauthsize = SHA224_DIGEST_SIZE,
2633 },
2634 .caam = {
2635 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2636 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2637 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002638 },
2639 },
2640 {
2641 .aead = {
2642 .base = {
2643 .cra_name = "echainiv(authenc(hmac(sha224),"
2644 "cbc(des3_ede)))",
2645 .cra_driver_name = "echainiv-authenc-"
2646 "hmac-sha224-"
2647 "cbc-des3_ede-caam",
2648 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2649 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002650 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002651 .setauthsize = aead_setauthsize,
2652 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002653 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002654 .ivsize = DES3_EDE_BLOCK_SIZE,
2655 .maxauthsize = SHA224_DIGEST_SIZE,
2656 },
2657 .caam = {
2658 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2659 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2660 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002661 .geniv = true,
2662 },
2663 },
2664 {
2665 .aead = {
2666 .base = {
2667 .cra_name = "authenc(hmac(sha256),"
2668 "cbc(des3_ede))",
2669 .cra_driver_name = "authenc-hmac-sha256-"
2670 "cbc-des3_ede-caam",
2671 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2672 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002673 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002674 .setauthsize = aead_setauthsize,
2675 .encrypt = aead_encrypt,
2676 .decrypt = aead_decrypt,
2677 .ivsize = DES3_EDE_BLOCK_SIZE,
2678 .maxauthsize = SHA256_DIGEST_SIZE,
2679 },
2680 .caam = {
2681 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2682 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2683 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002684 },
2685 },
2686 {
2687 .aead = {
2688 .base = {
2689 .cra_name = "echainiv(authenc(hmac(sha256),"
2690 "cbc(des3_ede)))",
2691 .cra_driver_name = "echainiv-authenc-"
2692 "hmac-sha256-"
2693 "cbc-des3_ede-caam",
2694 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2695 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002696 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002697 .setauthsize = aead_setauthsize,
2698 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002699 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002700 .ivsize = DES3_EDE_BLOCK_SIZE,
2701 .maxauthsize = SHA256_DIGEST_SIZE,
2702 },
2703 .caam = {
2704 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2705 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2706 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002707 .geniv = true,
2708 },
2709 },
2710 {
2711 .aead = {
2712 .base = {
2713 .cra_name = "authenc(hmac(sha384),"
2714 "cbc(des3_ede))",
2715 .cra_driver_name = "authenc-hmac-sha384-"
2716 "cbc-des3_ede-caam",
2717 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2718 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002719 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002720 .setauthsize = aead_setauthsize,
2721 .encrypt = aead_encrypt,
2722 .decrypt = aead_decrypt,
2723 .ivsize = DES3_EDE_BLOCK_SIZE,
2724 .maxauthsize = SHA384_DIGEST_SIZE,
2725 },
2726 .caam = {
2727 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2728 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2729 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002730 },
2731 },
2732 {
2733 .aead = {
2734 .base = {
2735 .cra_name = "echainiv(authenc(hmac(sha384),"
2736 "cbc(des3_ede)))",
2737 .cra_driver_name = "echainiv-authenc-"
2738 "hmac-sha384-"
2739 "cbc-des3_ede-caam",
2740 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2741 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002742 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002743 .setauthsize = aead_setauthsize,
2744 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002745 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002746 .ivsize = DES3_EDE_BLOCK_SIZE,
2747 .maxauthsize = SHA384_DIGEST_SIZE,
2748 },
2749 .caam = {
2750 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2751 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2752 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002753 .geniv = true,
2754 },
2755 },
2756 {
2757 .aead = {
2758 .base = {
2759 .cra_name = "authenc(hmac(sha512),"
2760 "cbc(des3_ede))",
2761 .cra_driver_name = "authenc-hmac-sha512-"
2762 "cbc-des3_ede-caam",
2763 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2764 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002765 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002766 .setauthsize = aead_setauthsize,
2767 .encrypt = aead_encrypt,
2768 .decrypt = aead_decrypt,
2769 .ivsize = DES3_EDE_BLOCK_SIZE,
2770 .maxauthsize = SHA512_DIGEST_SIZE,
2771 },
2772 .caam = {
2773 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2774 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2775 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002776 },
2777 },
2778 {
2779 .aead = {
2780 .base = {
2781 .cra_name = "echainiv(authenc(hmac(sha512),"
2782 "cbc(des3_ede)))",
2783 .cra_driver_name = "echainiv-authenc-"
2784 "hmac-sha512-"
2785 "cbc-des3_ede-caam",
2786 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
2787 },
Herbert Xu1b52c402019-04-11 16:51:02 +08002788 .setkey = des3_aead_setkey,
Herbert Xu479bcc72015-07-30 17:53:17 +08002789 .setauthsize = aead_setauthsize,
2790 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002791 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002792 .ivsize = DES3_EDE_BLOCK_SIZE,
2793 .maxauthsize = SHA512_DIGEST_SIZE,
2794 },
2795 .caam = {
2796 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2797 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
2798 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002799 .geniv = true,
2800 },
2801 },
2802 {
2803 .aead = {
2804 .base = {
2805 .cra_name = "authenc(hmac(md5),cbc(des))",
2806 .cra_driver_name = "authenc-hmac-md5-"
2807 "cbc-des-caam",
2808 .cra_blocksize = DES_BLOCK_SIZE,
2809 },
2810 .setkey = aead_setkey,
2811 .setauthsize = aead_setauthsize,
2812 .encrypt = aead_encrypt,
2813 .decrypt = aead_decrypt,
2814 .ivsize = DES_BLOCK_SIZE,
2815 .maxauthsize = MD5_DIGEST_SIZE,
2816 },
2817 .caam = {
2818 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2819 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2820 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002821 },
2822 },
2823 {
2824 .aead = {
2825 .base = {
2826 .cra_name = "echainiv(authenc(hmac(md5),"
2827 "cbc(des)))",
2828 .cra_driver_name = "echainiv-authenc-hmac-md5-"
2829 "cbc-des-caam",
2830 .cra_blocksize = DES_BLOCK_SIZE,
2831 },
2832 .setkey = aead_setkey,
2833 .setauthsize = aead_setauthsize,
2834 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002835 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002836 .ivsize = DES_BLOCK_SIZE,
2837 .maxauthsize = MD5_DIGEST_SIZE,
2838 },
2839 .caam = {
2840 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2841 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2842 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002843 .geniv = true,
2844 },
2845 },
2846 {
2847 .aead = {
2848 .base = {
2849 .cra_name = "authenc(hmac(sha1),cbc(des))",
2850 .cra_driver_name = "authenc-hmac-sha1-"
2851 "cbc-des-caam",
2852 .cra_blocksize = DES_BLOCK_SIZE,
2853 },
2854 .setkey = aead_setkey,
2855 .setauthsize = aead_setauthsize,
2856 .encrypt = aead_encrypt,
2857 .decrypt = aead_decrypt,
2858 .ivsize = DES_BLOCK_SIZE,
2859 .maxauthsize = SHA1_DIGEST_SIZE,
2860 },
2861 .caam = {
2862 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2863 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2864 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002865 },
2866 },
2867 {
2868 .aead = {
2869 .base = {
2870 .cra_name = "echainiv(authenc(hmac(sha1),"
2871 "cbc(des)))",
2872 .cra_driver_name = "echainiv-authenc-"
2873 "hmac-sha1-cbc-des-caam",
2874 .cra_blocksize = DES_BLOCK_SIZE,
2875 },
2876 .setkey = aead_setkey,
2877 .setauthsize = aead_setauthsize,
2878 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002879 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002880 .ivsize = DES_BLOCK_SIZE,
2881 .maxauthsize = SHA1_DIGEST_SIZE,
2882 },
2883 .caam = {
2884 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2885 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2886 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002887 .geniv = true,
2888 },
2889 },
2890 {
2891 .aead = {
2892 .base = {
2893 .cra_name = "authenc(hmac(sha224),cbc(des))",
2894 .cra_driver_name = "authenc-hmac-sha224-"
2895 "cbc-des-caam",
2896 .cra_blocksize = DES_BLOCK_SIZE,
2897 },
2898 .setkey = aead_setkey,
2899 .setauthsize = aead_setauthsize,
2900 .encrypt = aead_encrypt,
2901 .decrypt = aead_decrypt,
2902 .ivsize = DES_BLOCK_SIZE,
2903 .maxauthsize = SHA224_DIGEST_SIZE,
2904 },
2905 .caam = {
2906 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2907 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2908 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002909 },
2910 },
2911 {
2912 .aead = {
2913 .base = {
2914 .cra_name = "echainiv(authenc(hmac(sha224),"
2915 "cbc(des)))",
2916 .cra_driver_name = "echainiv-authenc-"
2917 "hmac-sha224-cbc-des-caam",
2918 .cra_blocksize = DES_BLOCK_SIZE,
2919 },
2920 .setkey = aead_setkey,
2921 .setauthsize = aead_setauthsize,
2922 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002923 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002924 .ivsize = DES_BLOCK_SIZE,
2925 .maxauthsize = SHA224_DIGEST_SIZE,
2926 },
2927 .caam = {
2928 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2929 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2930 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002931 .geniv = true,
2932 },
2933 },
2934 {
2935 .aead = {
2936 .base = {
2937 .cra_name = "authenc(hmac(sha256),cbc(des))",
2938 .cra_driver_name = "authenc-hmac-sha256-"
2939 "cbc-des-caam",
2940 .cra_blocksize = DES_BLOCK_SIZE,
2941 },
2942 .setkey = aead_setkey,
2943 .setauthsize = aead_setauthsize,
2944 .encrypt = aead_encrypt,
2945 .decrypt = aead_decrypt,
2946 .ivsize = DES_BLOCK_SIZE,
2947 .maxauthsize = SHA256_DIGEST_SIZE,
2948 },
2949 .caam = {
2950 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2951 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2952 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002953 },
2954 },
2955 {
2956 .aead = {
2957 .base = {
2958 .cra_name = "echainiv(authenc(hmac(sha256),"
2959 "cbc(des)))",
2960 .cra_driver_name = "echainiv-authenc-"
2961 "hmac-sha256-cbc-des-caam",
2962 .cra_blocksize = DES_BLOCK_SIZE,
2963 },
2964 .setkey = aead_setkey,
2965 .setauthsize = aead_setauthsize,
2966 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03002967 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08002968 .ivsize = DES_BLOCK_SIZE,
2969 .maxauthsize = SHA256_DIGEST_SIZE,
2970 },
2971 .caam = {
2972 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2973 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
2974 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002975 .geniv = true,
2976 },
2977 },
2978 {
2979 .aead = {
2980 .base = {
2981 .cra_name = "authenc(hmac(sha384),cbc(des))",
2982 .cra_driver_name = "authenc-hmac-sha384-"
2983 "cbc-des-caam",
2984 .cra_blocksize = DES_BLOCK_SIZE,
2985 },
2986 .setkey = aead_setkey,
2987 .setauthsize = aead_setauthsize,
2988 .encrypt = aead_encrypt,
2989 .decrypt = aead_decrypt,
2990 .ivsize = DES_BLOCK_SIZE,
2991 .maxauthsize = SHA384_DIGEST_SIZE,
2992 },
2993 .caam = {
2994 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2995 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
2996 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08002997 },
2998 },
2999 {
3000 .aead = {
3001 .base = {
3002 .cra_name = "echainiv(authenc(hmac(sha384),"
3003 "cbc(des)))",
3004 .cra_driver_name = "echainiv-authenc-"
3005 "hmac-sha384-cbc-des-caam",
3006 .cra_blocksize = DES_BLOCK_SIZE,
3007 },
3008 .setkey = aead_setkey,
3009 .setauthsize = aead_setauthsize,
3010 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003011 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003012 .ivsize = DES_BLOCK_SIZE,
3013 .maxauthsize = SHA384_DIGEST_SIZE,
3014 },
3015 .caam = {
3016 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3017 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3018 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003019 .geniv = true,
3020 },
3021 },
3022 {
3023 .aead = {
3024 .base = {
3025 .cra_name = "authenc(hmac(sha512),cbc(des))",
3026 .cra_driver_name = "authenc-hmac-sha512-"
3027 "cbc-des-caam",
3028 .cra_blocksize = DES_BLOCK_SIZE,
3029 },
3030 .setkey = aead_setkey,
3031 .setauthsize = aead_setauthsize,
3032 .encrypt = aead_encrypt,
3033 .decrypt = aead_decrypt,
3034 .ivsize = DES_BLOCK_SIZE,
3035 .maxauthsize = SHA512_DIGEST_SIZE,
3036 },
3037 .caam = {
3038 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3039 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3040 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003041 },
3042 },
3043 {
3044 .aead = {
3045 .base = {
3046 .cra_name = "echainiv(authenc(hmac(sha512),"
3047 "cbc(des)))",
3048 .cra_driver_name = "echainiv-authenc-"
3049 "hmac-sha512-cbc-des-caam",
3050 .cra_blocksize = DES_BLOCK_SIZE,
3051 },
3052 .setkey = aead_setkey,
3053 .setauthsize = aead_setauthsize,
3054 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003055 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003056 .ivsize = DES_BLOCK_SIZE,
3057 .maxauthsize = SHA512_DIGEST_SIZE,
3058 },
3059 .caam = {
3060 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3061 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3062 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003063 .geniv = true,
3064 },
3065 },
3066 {
3067 .aead = {
3068 .base = {
3069 .cra_name = "authenc(hmac(md5),"
3070 "rfc3686(ctr(aes)))",
3071 .cra_driver_name = "authenc-hmac-md5-"
3072 "rfc3686-ctr-aes-caam",
3073 .cra_blocksize = 1,
3074 },
3075 .setkey = aead_setkey,
3076 .setauthsize = aead_setauthsize,
3077 .encrypt = aead_encrypt,
3078 .decrypt = aead_decrypt,
3079 .ivsize = CTR_RFC3686_IV_SIZE,
3080 .maxauthsize = MD5_DIGEST_SIZE,
3081 },
3082 .caam = {
3083 .class1_alg_type = OP_ALG_ALGSEL_AES |
3084 OP_ALG_AAI_CTR_MOD128,
3085 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3086 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003087 .rfc3686 = true,
3088 },
3089 },
3090 {
3091 .aead = {
3092 .base = {
3093 .cra_name = "seqiv(authenc("
3094 "hmac(md5),rfc3686(ctr(aes))))",
3095 .cra_driver_name = "seqiv-authenc-hmac-md5-"
3096 "rfc3686-ctr-aes-caam",
3097 .cra_blocksize = 1,
3098 },
3099 .setkey = aead_setkey,
3100 .setauthsize = aead_setauthsize,
3101 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003102 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003103 .ivsize = CTR_RFC3686_IV_SIZE,
3104 .maxauthsize = MD5_DIGEST_SIZE,
3105 },
3106 .caam = {
3107 .class1_alg_type = OP_ALG_ALGSEL_AES |
3108 OP_ALG_AAI_CTR_MOD128,
3109 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3110 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003111 .rfc3686 = true,
3112 .geniv = true,
3113 },
3114 },
3115 {
3116 .aead = {
3117 .base = {
3118 .cra_name = "authenc(hmac(sha1),"
3119 "rfc3686(ctr(aes)))",
3120 .cra_driver_name = "authenc-hmac-sha1-"
3121 "rfc3686-ctr-aes-caam",
3122 .cra_blocksize = 1,
3123 },
3124 .setkey = aead_setkey,
3125 .setauthsize = aead_setauthsize,
3126 .encrypt = aead_encrypt,
3127 .decrypt = aead_decrypt,
3128 .ivsize = CTR_RFC3686_IV_SIZE,
3129 .maxauthsize = SHA1_DIGEST_SIZE,
3130 },
3131 .caam = {
3132 .class1_alg_type = OP_ALG_ALGSEL_AES |
3133 OP_ALG_AAI_CTR_MOD128,
3134 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3135 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003136 .rfc3686 = true,
3137 },
3138 },
3139 {
3140 .aead = {
3141 .base = {
3142 .cra_name = "seqiv(authenc("
3143 "hmac(sha1),rfc3686(ctr(aes))))",
3144 .cra_driver_name = "seqiv-authenc-hmac-sha1-"
3145 "rfc3686-ctr-aes-caam",
3146 .cra_blocksize = 1,
3147 },
3148 .setkey = aead_setkey,
3149 .setauthsize = aead_setauthsize,
3150 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003151 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003152 .ivsize = CTR_RFC3686_IV_SIZE,
3153 .maxauthsize = SHA1_DIGEST_SIZE,
3154 },
3155 .caam = {
3156 .class1_alg_type = OP_ALG_ALGSEL_AES |
3157 OP_ALG_AAI_CTR_MOD128,
3158 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3159 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003160 .rfc3686 = true,
3161 .geniv = true,
3162 },
3163 },
3164 {
3165 .aead = {
3166 .base = {
3167 .cra_name = "authenc(hmac(sha224),"
3168 "rfc3686(ctr(aes)))",
3169 .cra_driver_name = "authenc-hmac-sha224-"
3170 "rfc3686-ctr-aes-caam",
3171 .cra_blocksize = 1,
3172 },
3173 .setkey = aead_setkey,
3174 .setauthsize = aead_setauthsize,
3175 .encrypt = aead_encrypt,
3176 .decrypt = aead_decrypt,
3177 .ivsize = CTR_RFC3686_IV_SIZE,
3178 .maxauthsize = SHA224_DIGEST_SIZE,
3179 },
3180 .caam = {
3181 .class1_alg_type = OP_ALG_ALGSEL_AES |
3182 OP_ALG_AAI_CTR_MOD128,
3183 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3184 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003185 .rfc3686 = true,
3186 },
3187 },
3188 {
3189 .aead = {
3190 .base = {
3191 .cra_name = "seqiv(authenc("
3192 "hmac(sha224),rfc3686(ctr(aes))))",
3193 .cra_driver_name = "seqiv-authenc-hmac-sha224-"
3194 "rfc3686-ctr-aes-caam",
3195 .cra_blocksize = 1,
3196 },
3197 .setkey = aead_setkey,
3198 .setauthsize = aead_setauthsize,
3199 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003200 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003201 .ivsize = CTR_RFC3686_IV_SIZE,
3202 .maxauthsize = SHA224_DIGEST_SIZE,
3203 },
3204 .caam = {
3205 .class1_alg_type = OP_ALG_ALGSEL_AES |
3206 OP_ALG_AAI_CTR_MOD128,
3207 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3208 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003209 .rfc3686 = true,
3210 .geniv = true,
3211 },
3212 },
3213 {
3214 .aead = {
3215 .base = {
3216 .cra_name = "authenc(hmac(sha256),"
3217 "rfc3686(ctr(aes)))",
3218 .cra_driver_name = "authenc-hmac-sha256-"
3219 "rfc3686-ctr-aes-caam",
3220 .cra_blocksize = 1,
3221 },
3222 .setkey = aead_setkey,
3223 .setauthsize = aead_setauthsize,
3224 .encrypt = aead_encrypt,
3225 .decrypt = aead_decrypt,
3226 .ivsize = CTR_RFC3686_IV_SIZE,
3227 .maxauthsize = SHA256_DIGEST_SIZE,
3228 },
3229 .caam = {
3230 .class1_alg_type = OP_ALG_ALGSEL_AES |
3231 OP_ALG_AAI_CTR_MOD128,
3232 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3233 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003234 .rfc3686 = true,
3235 },
3236 },
3237 {
3238 .aead = {
3239 .base = {
3240 .cra_name = "seqiv(authenc(hmac(sha256),"
3241 "rfc3686(ctr(aes))))",
3242 .cra_driver_name = "seqiv-authenc-hmac-sha256-"
3243 "rfc3686-ctr-aes-caam",
3244 .cra_blocksize = 1,
3245 },
3246 .setkey = aead_setkey,
3247 .setauthsize = aead_setauthsize,
3248 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003249 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003250 .ivsize = CTR_RFC3686_IV_SIZE,
3251 .maxauthsize = SHA256_DIGEST_SIZE,
3252 },
3253 .caam = {
3254 .class1_alg_type = OP_ALG_ALGSEL_AES |
3255 OP_ALG_AAI_CTR_MOD128,
3256 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3257 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003258 .rfc3686 = true,
3259 .geniv = true,
3260 },
3261 },
3262 {
3263 .aead = {
3264 .base = {
3265 .cra_name = "authenc(hmac(sha384),"
3266 "rfc3686(ctr(aes)))",
3267 .cra_driver_name = "authenc-hmac-sha384-"
3268 "rfc3686-ctr-aes-caam",
3269 .cra_blocksize = 1,
3270 },
3271 .setkey = aead_setkey,
3272 .setauthsize = aead_setauthsize,
3273 .encrypt = aead_encrypt,
3274 .decrypt = aead_decrypt,
3275 .ivsize = CTR_RFC3686_IV_SIZE,
3276 .maxauthsize = SHA384_DIGEST_SIZE,
3277 },
3278 .caam = {
3279 .class1_alg_type = OP_ALG_ALGSEL_AES |
3280 OP_ALG_AAI_CTR_MOD128,
3281 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3282 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003283 .rfc3686 = true,
3284 },
3285 },
3286 {
3287 .aead = {
3288 .base = {
3289 .cra_name = "seqiv(authenc(hmac(sha384),"
3290 "rfc3686(ctr(aes))))",
3291 .cra_driver_name = "seqiv-authenc-hmac-sha384-"
3292 "rfc3686-ctr-aes-caam",
3293 .cra_blocksize = 1,
3294 },
3295 .setkey = aead_setkey,
3296 .setauthsize = aead_setauthsize,
3297 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003298 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003299 .ivsize = CTR_RFC3686_IV_SIZE,
3300 .maxauthsize = SHA384_DIGEST_SIZE,
3301 },
3302 .caam = {
3303 .class1_alg_type = OP_ALG_ALGSEL_AES |
3304 OP_ALG_AAI_CTR_MOD128,
3305 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3306 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003307 .rfc3686 = true,
3308 .geniv = true,
3309 },
3310 },
3311 {
3312 .aead = {
3313 .base = {
3314 .cra_name = "authenc(hmac(sha512),"
3315 "rfc3686(ctr(aes)))",
3316 .cra_driver_name = "authenc-hmac-sha512-"
3317 "rfc3686-ctr-aes-caam",
3318 .cra_blocksize = 1,
3319 },
3320 .setkey = aead_setkey,
3321 .setauthsize = aead_setauthsize,
3322 .encrypt = aead_encrypt,
3323 .decrypt = aead_decrypt,
3324 .ivsize = CTR_RFC3686_IV_SIZE,
3325 .maxauthsize = SHA512_DIGEST_SIZE,
3326 },
3327 .caam = {
3328 .class1_alg_type = OP_ALG_ALGSEL_AES |
3329 OP_ALG_AAI_CTR_MOD128,
3330 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3331 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003332 .rfc3686 = true,
3333 },
3334 },
3335 {
3336 .aead = {
3337 .base = {
3338 .cra_name = "seqiv(authenc(hmac(sha512),"
3339 "rfc3686(ctr(aes))))",
3340 .cra_driver_name = "seqiv-authenc-hmac-sha512-"
3341 "rfc3686-ctr-aes-caam",
3342 .cra_blocksize = 1,
3343 },
3344 .setkey = aead_setkey,
3345 .setauthsize = aead_setauthsize,
3346 .encrypt = aead_encrypt,
Horia Geantă8b18e232016-08-29 14:52:14 +03003347 .decrypt = aead_decrypt,
Herbert Xu479bcc72015-07-30 17:53:17 +08003348 .ivsize = CTR_RFC3686_IV_SIZE,
3349 .maxauthsize = SHA512_DIGEST_SIZE,
3350 },
3351 .caam = {
3352 .class1_alg_type = OP_ALG_ALGSEL_AES |
3353 OP_ALG_AAI_CTR_MOD128,
3354 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3355 OP_ALG_AAI_HMAC_PRECOMP,
Herbert Xu479bcc72015-07-30 17:53:17 +08003356 .rfc3686 = true,
3357 .geniv = true,
3358 },
3359 },
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003360 {
3361 .aead = {
3362 .base = {
3363 .cra_name = "rfc7539(chacha20,poly1305)",
3364 .cra_driver_name = "rfc7539-chacha20-poly1305-"
3365 "caam",
3366 .cra_blocksize = 1,
3367 },
3368 .setkey = chachapoly_setkey,
3369 .setauthsize = chachapoly_setauthsize,
3370 .encrypt = chachapoly_encrypt,
3371 .decrypt = chachapoly_decrypt,
3372 .ivsize = CHACHAPOLY_IV_SIZE,
3373 .maxauthsize = POLY1305_DIGEST_SIZE,
3374 },
3375 .caam = {
3376 .class1_alg_type = OP_ALG_ALGSEL_CHACHA20 |
3377 OP_ALG_AAI_AEAD,
3378 .class2_alg_type = OP_ALG_ALGSEL_POLY1305 |
3379 OP_ALG_AAI_AEAD,
Herbert Xu24586b52019-05-06 14:39:44 +08003380 .nodkp = true,
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003381 },
3382 },
3383 {
3384 .aead = {
3385 .base = {
3386 .cra_name = "rfc7539esp(chacha20,poly1305)",
3387 .cra_driver_name = "rfc7539esp-chacha20-"
3388 "poly1305-caam",
3389 .cra_blocksize = 1,
3390 },
3391 .setkey = chachapoly_setkey,
3392 .setauthsize = chachapoly_setauthsize,
3393 .encrypt = chachapoly_encrypt,
3394 .decrypt = chachapoly_decrypt,
3395 .ivsize = 8,
3396 .maxauthsize = POLY1305_DIGEST_SIZE,
3397 },
3398 .caam = {
3399 .class1_alg_type = OP_ALG_ALGSEL_CHACHA20 |
3400 OP_ALG_AAI_AEAD,
3401 .class2_alg_type = OP_ALG_ALGSEL_POLY1305 |
3402 OP_ALG_AAI_AEAD,
Herbert Xu24586b52019-05-06 14:39:44 +08003403 .nodkp = true,
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003404 },
3405 },
Herbert Xuf2147b82015-06-16 13:54:23 +08003406};
3407
Horia Geantă7e0880b2017-12-19 12:16:07 +02003408static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
3409 bool uses_dkp)
Herbert Xuf2147b82015-06-16 13:54:23 +08003410{
Horia Geantăbbf22342017-02-10 14:07:22 +02003411 dma_addr_t dma_addr;
Horia Geantă7e0880b2017-12-19 12:16:07 +02003412 struct caam_drv_private *priv;
Horia Geantăbbf22342017-02-10 14:07:22 +02003413
Herbert Xuf2147b82015-06-16 13:54:23 +08003414 ctx->jrdev = caam_jr_alloc();
3415 if (IS_ERR(ctx->jrdev)) {
3416 pr_err("Job Ring Device allocation for transform failed\n");
3417 return PTR_ERR(ctx->jrdev);
3418 }
3419
Horia Geantă7e0880b2017-12-19 12:16:07 +02003420 priv = dev_get_drvdata(ctx->jrdev->parent);
3421 if (priv->era >= 6 && uses_dkp)
3422 ctx->dir = DMA_BIDIRECTIONAL;
3423 else
3424 ctx->dir = DMA_TO_DEVICE;
3425
Horia Geantăbbf22342017-02-10 14:07:22 +02003426 dma_addr = dma_map_single_attrs(ctx->jrdev, ctx->sh_desc_enc,
3427 offsetof(struct caam_ctx,
3428 sh_desc_enc_dma),
Horia Geantă7e0880b2017-12-19 12:16:07 +02003429 ctx->dir, DMA_ATTR_SKIP_CPU_SYNC);
Horia Geantăbbf22342017-02-10 14:07:22 +02003430 if (dma_mapping_error(ctx->jrdev, dma_addr)) {
3431 dev_err(ctx->jrdev, "unable to map key, shared descriptors\n");
3432 caam_jr_free(ctx->jrdev);
3433 return -ENOMEM;
3434 }
3435
3436 ctx->sh_desc_enc_dma = dma_addr;
3437 ctx->sh_desc_dec_dma = dma_addr + offsetof(struct caam_ctx,
3438 sh_desc_dec);
Horia Geantăbbf22342017-02-10 14:07:22 +02003439 ctx->key_dma = dma_addr + offsetof(struct caam_ctx, key);
3440
Herbert Xuf2147b82015-06-16 13:54:23 +08003441 /* copy descriptor header template value */
Horia Geantădb576562016-11-22 15:44:04 +02003442 ctx->cdata.algtype = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
3443 ctx->adata.algtype = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
Herbert Xuf2147b82015-06-16 13:54:23 +08003444
3445 return 0;
3446}
3447
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003448static int caam_cra_init(struct crypto_skcipher *tfm)
Kim Phillips8e8ec592011-03-13 16:54:26 +08003449{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003450 struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
3451 struct caam_skcipher_alg *caam_alg =
3452 container_of(alg, typeof(*caam_alg), skcipher);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003453
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003454 return caam_init_common(crypto_skcipher_ctx(tfm), &caam_alg->caam,
3455 false);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003456}
3457
Herbert Xuf2147b82015-06-16 13:54:23 +08003458static int caam_aead_init(struct crypto_aead *tfm)
Kim Phillips8e8ec592011-03-13 16:54:26 +08003459{
Herbert Xuf2147b82015-06-16 13:54:23 +08003460 struct aead_alg *alg = crypto_aead_alg(tfm);
3461 struct caam_aead_alg *caam_alg =
3462 container_of(alg, struct caam_aead_alg, aead);
3463 struct caam_ctx *ctx = crypto_aead_ctx(tfm);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003464
Herbert Xu24586b52019-05-06 14:39:44 +08003465 return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp);
Herbert Xuf2147b82015-06-16 13:54:23 +08003466}
3467
3468static void caam_exit_common(struct caam_ctx *ctx)
3469{
Horia Geantăbbf22342017-02-10 14:07:22 +02003470 dma_unmap_single_attrs(ctx->jrdev, ctx->sh_desc_enc_dma,
3471 offsetof(struct caam_ctx, sh_desc_enc_dma),
Horia Geantă7e0880b2017-12-19 12:16:07 +02003472 ctx->dir, DMA_ATTR_SKIP_CPU_SYNC);
Ruchika Guptacfc6f112013-10-25 12:01:03 +05303473 caam_jr_free(ctx->jrdev);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003474}
3475
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003476static void caam_cra_exit(struct crypto_skcipher *tfm)
Herbert Xuf2147b82015-06-16 13:54:23 +08003477{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003478 caam_exit_common(crypto_skcipher_ctx(tfm));
Herbert Xuf2147b82015-06-16 13:54:23 +08003479}
3480
3481static void caam_aead_exit(struct crypto_aead *tfm)
3482{
3483 caam_exit_common(crypto_aead_ctx(tfm));
3484}
3485
Horia Geantă1b46c902019-05-03 17:17:39 +03003486void caam_algapi_exit(void)
Kim Phillips8e8ec592011-03-13 16:54:26 +08003487{
Herbert Xuf2147b82015-06-16 13:54:23 +08003488 int i;
3489
3490 for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
3491 struct caam_aead_alg *t_alg = driver_aeads + i;
3492
3493 if (t_alg->registered)
3494 crypto_unregister_aead(&t_alg->aead);
3495 }
Kim Phillips8e8ec592011-03-13 16:54:26 +08003496
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003497 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
3498 struct caam_skcipher_alg *t_alg = driver_algs + i;
Kim Phillips8e8ec592011-03-13 16:54:26 +08003499
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003500 if (t_alg->registered)
3501 crypto_unregister_skcipher(&t_alg->skcipher);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003502 }
Kim Phillips8e8ec592011-03-13 16:54:26 +08003503}
3504
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003505static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg)
Kim Phillips8e8ec592011-03-13 16:54:26 +08003506{
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003507 struct skcipher_alg *alg = &t_alg->skcipher;
Kim Phillips8e8ec592011-03-13 16:54:26 +08003508
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003509 alg->base.cra_module = THIS_MODULE;
3510 alg->base.cra_priority = CAAM_CRA_PRIORITY;
3511 alg->base.cra_ctxsize = sizeof(struct caam_ctx);
3512 alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
Kim Phillips8e8ec592011-03-13 16:54:26 +08003513
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003514 alg->init = caam_cra_init;
3515 alg->exit = caam_cra_exit;
Kim Phillips8e8ec592011-03-13 16:54:26 +08003516}
3517
Herbert Xuf2147b82015-06-16 13:54:23 +08003518static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
3519{
3520 struct aead_alg *alg = &t_alg->aead;
3521
3522 alg->base.cra_module = THIS_MODULE;
3523 alg->base.cra_priority = CAAM_CRA_PRIORITY;
3524 alg->base.cra_ctxsize = sizeof(struct caam_ctx);
Herbert Xu5e4b8c12015-08-13 17:29:06 +08003525 alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
Herbert Xuf2147b82015-06-16 13:54:23 +08003526
3527 alg->init = caam_aead_init;
3528 alg->exit = caam_aead_exit;
3529}
3530
Horia Geantă1b46c902019-05-03 17:17:39 +03003531int caam_algapi_init(struct device *ctrldev)
Kim Phillips8e8ec592011-03-13 16:54:26 +08003532{
Horia Geantă1b46c902019-05-03 17:17:39 +03003533 struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003534 int i = 0, err = 0;
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003535 u32 aes_vid, aes_inst, des_inst, md_vid, md_inst, ccha_inst, ptha_inst;
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02003536 u32 arc4_inst;
Victoria Milhoanbf834902015-08-05 11:28:48 -07003537 unsigned int md_limit = SHA512_DIGEST_SIZE;
Horia Geantădf80bfd2019-04-16 19:27:12 +03003538 bool registered = false, gcm_support;
Kim Phillips8e8ec592011-03-13 16:54:26 +08003539
Victoria Milhoanbf834902015-08-05 11:28:48 -07003540 /*
3541 * Register crypto algorithms the device supports.
3542 * First, detect presence and attributes of DES, AES, and MD blocks.
3543 */
Horia Geantăd239b102018-11-08 15:36:27 +02003544 if (priv->era < 10) {
Horia Geantădf80bfd2019-04-16 19:27:12 +03003545 u32 cha_vid, cha_inst, aes_rn;
Horia Geantăd239b102018-11-08 15:36:27 +02003546
3547 cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
3548 aes_vid = cha_vid & CHA_ID_LS_AES_MASK;
3549 md_vid = (cha_vid & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
3550
3551 cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
3552 des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >>
3553 CHA_ID_LS_DES_SHIFT;
3554 aes_inst = cha_inst & CHA_ID_LS_AES_MASK;
3555 md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02003556 arc4_inst = (cha_inst & CHA_ID_LS_ARC4_MASK) >>
3557 CHA_ID_LS_ARC4_SHIFT;
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003558 ccha_inst = 0;
3559 ptha_inst = 0;
Horia Geantădf80bfd2019-04-16 19:27:12 +03003560
3561 aes_rn = rd_reg32(&priv->ctrl->perfmon.cha_rev_ls) &
3562 CHA_ID_LS_AES_MASK;
3563 gcm_support = !(aes_vid == CHA_VER_VID_AES_LP && aes_rn < 8);
Horia Geantăd239b102018-11-08 15:36:27 +02003564 } else {
3565 u32 aesa, mdha;
3566
3567 aesa = rd_reg32(&priv->ctrl->vreg.aesa);
3568 mdha = rd_reg32(&priv->ctrl->vreg.mdha);
3569
3570 aes_vid = (aesa & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
3571 md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
3572
3573 des_inst = rd_reg32(&priv->ctrl->vreg.desa) & CHA_VER_NUM_MASK;
3574 aes_inst = aesa & CHA_VER_NUM_MASK;
3575 md_inst = mdha & CHA_VER_NUM_MASK;
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003576 ccha_inst = rd_reg32(&priv->ctrl->vreg.ccha) & CHA_VER_NUM_MASK;
3577 ptha_inst = rd_reg32(&priv->ctrl->vreg.ptha) & CHA_VER_NUM_MASK;
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02003578 arc4_inst = rd_reg32(&priv->ctrl->vreg.afha) & CHA_VER_NUM_MASK;
Horia Geantădf80bfd2019-04-16 19:27:12 +03003579
3580 gcm_support = aesa & CHA_VER_MISC_AES_GCM;
Horia Geantăd239b102018-11-08 15:36:27 +02003581 }
Kim Phillips8e8ec592011-03-13 16:54:26 +08003582
Victoria Milhoanbf834902015-08-05 11:28:48 -07003583 /* If MD is present, limit digest size based on LP256 */
Horia Geantăd239b102018-11-08 15:36:27 +02003584 if (md_inst && md_vid == CHA_VER_VID_MD_LP256)
Victoria Milhoanbf834902015-08-05 11:28:48 -07003585 md_limit = SHA256_DIGEST_SIZE;
3586
3587 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003588 struct caam_skcipher_alg *t_alg = driver_algs + i;
3589 u32 alg_sel = t_alg->caam.class1_alg_type & OP_ALG_ALGSEL_MASK;
Victoria Milhoanbf834902015-08-05 11:28:48 -07003590
3591 /* Skip DES algorithms if not supported by device */
3592 if (!des_inst &&
3593 ((alg_sel == OP_ALG_ALGSEL_3DES) ||
3594 (alg_sel == OP_ALG_ALGSEL_DES)))
3595 continue;
3596
3597 /* Skip AES algorithms if not supported by device */
3598 if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
3599 continue;
3600
Iuliana Prodaneaed71a2019-02-08 15:50:09 +02003601 /* Skip ARC4 algorithms if not supported by device */
3602 if (!arc4_inst && alg_sel == OP_ALG_ALGSEL_ARC4)
3603 continue;
3604
Sven Ebenfeld83d2c9a2016-11-07 18:51:34 +01003605 /*
3606 * Check support for AES modes not available
3607 * on LP devices.
3608 */
Horia Geantăd239b102018-11-08 15:36:27 +02003609 if (aes_vid == CHA_VER_VID_AES_LP &&
3610 (t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK) ==
3611 OP_ALG_AAI_XTS)
3612 continue;
Sven Ebenfeld83d2c9a2016-11-07 18:51:34 +01003613
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003614 caam_skcipher_alg_init(t_alg);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003615
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003616 err = crypto_register_skcipher(&t_alg->skcipher);
Kim Phillips8e8ec592011-03-13 16:54:26 +08003617 if (err) {
Ruchika Guptacfc6f112013-10-25 12:01:03 +05303618 pr_warn("%s alg registration failed\n",
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003619 t_alg->skcipher.base.cra_driver_name);
Herbert Xuf2147b82015-06-16 13:54:23 +08003620 continue;
3621 }
3622
Horia Geantă5ca7bad2018-08-06 15:43:59 +03003623 t_alg->registered = true;
Herbert Xuf2147b82015-06-16 13:54:23 +08003624 registered = true;
Kim Phillips8e8ec592011-03-13 16:54:26 +08003625 }
Herbert Xuf2147b82015-06-16 13:54:23 +08003626
3627 for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
3628 struct caam_aead_alg *t_alg = driver_aeads + i;
Victoria Milhoanbf834902015-08-05 11:28:48 -07003629 u32 c1_alg_sel = t_alg->caam.class1_alg_type &
3630 OP_ALG_ALGSEL_MASK;
3631 u32 c2_alg_sel = t_alg->caam.class2_alg_type &
3632 OP_ALG_ALGSEL_MASK;
3633 u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
3634
3635 /* Skip DES algorithms if not supported by device */
3636 if (!des_inst &&
3637 ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
3638 (c1_alg_sel == OP_ALG_ALGSEL_DES)))
3639 continue;
3640
3641 /* Skip AES algorithms if not supported by device */
3642 if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES))
3643 continue;
3644
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003645 /* Skip CHACHA20 algorithms if not supported by device */
3646 if (c1_alg_sel == OP_ALG_ALGSEL_CHACHA20 && !ccha_inst)
3647 continue;
3648
3649 /* Skip POLY1305 algorithms if not supported by device */
3650 if (c2_alg_sel == OP_ALG_ALGSEL_POLY1305 && !ptha_inst)
3651 continue;
3652
Horia Geantădf80bfd2019-04-16 19:27:12 +03003653 /* Skip GCM algorithms if not supported by device */
3654 if (c1_alg_sel == OP_ALG_ALGSEL_AES &&
3655 alg_aai == OP_ALG_AAI_GCM && !gcm_support)
Horia Geantăd239b102018-11-08 15:36:27 +02003656 continue;
Victoria Milhoanbf834902015-08-05 11:28:48 -07003657
3658 /*
3659 * Skip algorithms requiring message digests
3660 * if MD or MD size is not supported by device.
3661 */
Horia Geantă2dd3fde2018-12-21 14:47:46 +02003662 if (is_mdha(c2_alg_sel) &&
Horia Geantăd6bbd4e2018-11-08 15:36:30 +02003663 (!md_inst || t_alg->aead.maxauthsize > md_limit))
3664 continue;
Herbert Xuf2147b82015-06-16 13:54:23 +08003665
3666 caam_aead_alg_init(t_alg);
3667
3668 err = crypto_register_aead(&t_alg->aead);
3669 if (err) {
3670 pr_warn("%s alg registration failed\n",
3671 t_alg->aead.base.cra_driver_name);
3672 continue;
3673 }
3674
3675 t_alg->registered = true;
3676 registered = true;
3677 }
3678
3679 if (registered)
Ruchika Guptacfc6f112013-10-25 12:01:03 +05303680 pr_info("caam algorithms registered in /proc/crypto\n");
Kim Phillips8e8ec592011-03-13 16:54:26 +08003681
Kim Phillips8e8ec592011-03-13 16:54:26 +08003682 return err;
3683}