blob: 467ac2f768ac2bb423b92eb797dce8bde697f259 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Ard Biesheuvel1abee992017-01-11 16:41:55 +00002/*
3 * Bit sliced AES using NEON instructions
4 *
Ard Biesheuvelec808bb2017-07-24 11:28:15 +01005 * Copyright (C) 2016 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
Ard Biesheuvel1abee992017-01-11 16:41:55 +00006 */
7
8#include <asm/neon.h>
Ard Biesheuvelec808bb2017-07-24 11:28:15 +01009#include <asm/simd.h>
Ard Biesheuvel1abee992017-01-11 16:41:55 +000010#include <crypto/aes.h>
Ard Biesheuvelff6f4112019-07-02 21:41:35 +020011#include <crypto/ctr.h>
Ard Biesheuvel1abee992017-01-11 16:41:55 +000012#include <crypto/internal/simd.h>
13#include <crypto/internal/skcipher.h>
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -070014#include <crypto/scatterwalk.h>
Ard Biesheuvel1abee992017-01-11 16:41:55 +000015#include <crypto/xts.h>
16#include <linux/module.h>
17
18MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
19MODULE_LICENSE("GPL v2");
20
21MODULE_ALIAS_CRYPTO("ecb(aes)");
22MODULE_ALIAS_CRYPTO("cbc(aes)");
23MODULE_ALIAS_CRYPTO("ctr(aes)");
24MODULE_ALIAS_CRYPTO("xts(aes)");
25
26asmlinkage void aesbs_convert_key(u8 out[], u32 const rk[], int rounds);
27
28asmlinkage void aesbs_ecb_encrypt(u8 out[], u8 const in[], u8 const rk[],
29 int rounds, int blocks);
30asmlinkage void aesbs_ecb_decrypt(u8 out[], u8 const in[], u8 const rk[],
31 int rounds, int blocks);
32
33asmlinkage void aesbs_cbc_decrypt(u8 out[], u8 const in[], u8 const rk[],
34 int rounds, int blocks, u8 iv[]);
35
36asmlinkage void aesbs_ctr_encrypt(u8 out[], u8 const in[], u8 const rk[],
Ard Biesheuvelfc074e12022-01-27 12:35:44 +010037 int rounds, int blocks, u8 iv[]);
Ard Biesheuvel1abee992017-01-11 16:41:55 +000038
39asmlinkage void aesbs_xts_encrypt(u8 out[], u8 const in[], u8 const rk[],
40 int rounds, int blocks, u8 iv[]);
41asmlinkage void aesbs_xts_decrypt(u8 out[], u8 const in[], u8 const rk[],
42 int rounds, int blocks, u8 iv[]);
43
Ard Biesheuvel12fcd922017-01-28 23:25:39 +000044/* borrowed from aes-neon-blk.ko */
45asmlinkage void neon_aes_ecb_encrypt(u8 out[], u8 const in[], u32 const rk[],
Ard Biesheuvel68338172018-03-10 15:21:48 +000046 int rounds, int blocks);
Ard Biesheuvel12fcd922017-01-28 23:25:39 +000047asmlinkage void neon_aes_cbc_encrypt(u8 out[], u8 const in[], u32 const rk[],
Ard Biesheuvel68338172018-03-10 15:21:48 +000048 int rounds, int blocks, u8 iv[]);
Ard Biesheuvelfc074e12022-01-27 12:35:44 +010049asmlinkage void neon_aes_ctr_encrypt(u8 out[], u8 const in[], u32 const rk[],
50 int rounds, int bytes, u8 ctr[]);
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -070051asmlinkage void neon_aes_xts_encrypt(u8 out[], u8 const in[],
52 u32 const rk1[], int rounds, int bytes,
53 u32 const rk2[], u8 iv[], int first);
54asmlinkage void neon_aes_xts_decrypt(u8 out[], u8 const in[],
55 u32 const rk1[], int rounds, int bytes,
56 u32 const rk2[], u8 iv[], int first);
Ard Biesheuvel1abee992017-01-11 16:41:55 +000057
58struct aesbs_ctx {
59 u8 rk[13 * (8 * AES_BLOCK_SIZE) + 32];
60 int rounds;
61} __aligned(AES_BLOCK_SIZE);
62
Ard Biesheuvelfc074e12022-01-27 12:35:44 +010063struct aesbs_cbc_ctr_ctx {
Ard Biesheuvel1abee992017-01-11 16:41:55 +000064 struct aesbs_ctx key;
65 u32 enc[AES_MAX_KEYLENGTH_U32];
66};
67
68struct aesbs_xts_ctx {
69 struct aesbs_ctx key;
70 u32 twkey[AES_MAX_KEYLENGTH_U32];
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -070071 struct crypto_aes_ctx cts;
Ard Biesheuvel1abee992017-01-11 16:41:55 +000072};
73
74static int aesbs_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
75 unsigned int key_len)
76{
77 struct aesbs_ctx *ctx = crypto_skcipher_ctx(tfm);
78 struct crypto_aes_ctx rk;
79 int err;
80
Ard Biesheuvelf68df542019-07-02 21:41:31 +020081 err = aes_expandkey(&rk, in_key, key_len);
Ard Biesheuvel1abee992017-01-11 16:41:55 +000082 if (err)
83 return err;
84
85 ctx->rounds = 6 + key_len / 4;
86
87 kernel_neon_begin();
88 aesbs_convert_key(ctx->rk, rk.key_enc, ctx->rounds);
89 kernel_neon_end();
90
91 return 0;
92}
93
94static int __ecb_crypt(struct skcipher_request *req,
95 void (*fn)(u8 out[], u8 const in[], u8 const rk[],
96 int rounds, int blocks))
97{
98 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
99 struct aesbs_ctx *ctx = crypto_skcipher_ctx(tfm);
100 struct skcipher_walk walk;
101 int err;
102
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000103 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000104
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000105 while (walk.nbytes >= AES_BLOCK_SIZE) {
106 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
107
108 if (walk.nbytes < walk.total)
109 blocks = round_down(blocks,
110 walk.stride / AES_BLOCK_SIZE);
111
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000112 kernel_neon_begin();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000113 fn(walk.dst.virt.addr, walk.src.virt.addr, ctx->rk,
114 ctx->rounds, blocks);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000115 kernel_neon_end();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000116 err = skcipher_walk_done(&walk,
117 walk.nbytes - blocks * AES_BLOCK_SIZE);
118 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000119
120 return err;
121}
122
123static int ecb_encrypt(struct skcipher_request *req)
124{
125 return __ecb_crypt(req, aesbs_ecb_encrypt);
126}
127
128static int ecb_decrypt(struct skcipher_request *req)
129{
130 return __ecb_crypt(req, aesbs_ecb_decrypt);
131}
132
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100133static int aesbs_cbc_ctr_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000134 unsigned int key_len)
135{
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100136 struct aesbs_cbc_ctr_ctx *ctx = crypto_skcipher_ctx(tfm);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000137 struct crypto_aes_ctx rk;
138 int err;
139
Ard Biesheuvelf68df542019-07-02 21:41:31 +0200140 err = aes_expandkey(&rk, in_key, key_len);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000141 if (err)
142 return err;
143
144 ctx->key.rounds = 6 + key_len / 4;
145
146 memcpy(ctx->enc, rk.key_enc, sizeof(ctx->enc));
147
148 kernel_neon_begin();
149 aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
150 kernel_neon_end();
Torsten Duwe82ff4932020-03-13 12:02:58 +0100151 memzero_explicit(&rk, sizeof(rk));
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000152
153 return 0;
154}
155
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000156static int cbc_encrypt(struct skcipher_request *req)
157{
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000158 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100159 struct aesbs_cbc_ctr_ctx *ctx = crypto_skcipher_ctx(tfm);
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000160 struct skcipher_walk walk;
Ard Biesheuvel68338172018-03-10 15:21:48 +0000161 int err;
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000162
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000163 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000164
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000165 while (walk.nbytes >= AES_BLOCK_SIZE) {
166 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
167
168 /* fall back to the non-bitsliced NEON implementation */
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000169 kernel_neon_begin();
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000170 neon_aes_cbc_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
Ard Biesheuvel68338172018-03-10 15:21:48 +0000171 ctx->enc, ctx->key.rounds, blocks,
172 walk.iv);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000173 kernel_neon_end();
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000174 err = skcipher_walk_done(&walk, walk.nbytes % AES_BLOCK_SIZE);
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000175 }
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000176 return err;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000177}
178
179static int cbc_decrypt(struct skcipher_request *req)
180{
181 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100182 struct aesbs_cbc_ctr_ctx *ctx = crypto_skcipher_ctx(tfm);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000183 struct skcipher_walk walk;
184 int err;
185
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000186 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000187
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000188 while (walk.nbytes >= AES_BLOCK_SIZE) {
189 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
190
191 if (walk.nbytes < walk.total)
192 blocks = round_down(blocks,
193 walk.stride / AES_BLOCK_SIZE);
194
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000195 kernel_neon_begin();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000196 aesbs_cbc_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
197 ctx->key.rk, ctx->key.rounds, blocks,
198 walk.iv);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000199 kernel_neon_end();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000200 err = skcipher_walk_done(&walk,
201 walk.nbytes - blocks * AES_BLOCK_SIZE);
202 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000203
204 return err;
205}
206
207static int ctr_encrypt(struct skcipher_request *req)
208{
209 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100210 struct aesbs_cbc_ctr_ctx *ctx = crypto_skcipher_ctx(tfm);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000211 struct skcipher_walk walk;
212 int err;
213
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000214 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000215
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000216 while (walk.nbytes > 0) {
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100217 int blocks = (walk.nbytes / AES_BLOCK_SIZE) & ~7;
218 int nbytes = walk.nbytes % (8 * AES_BLOCK_SIZE);
219 const u8 *src = walk.src.virt.addr;
220 u8 *dst = walk.dst.virt.addr;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000221
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000222 kernel_neon_begin();
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100223 if (blocks >= 8) {
224 aesbs_ctr_encrypt(dst, src, ctx->key.rk, ctx->key.rounds,
225 blocks, walk.iv);
226 dst += blocks * AES_BLOCK_SIZE;
227 src += blocks * AES_BLOCK_SIZE;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000228 }
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100229 if (nbytes && walk.nbytes == walk.total) {
Ard Biesheuvel1c0cf6d2024-02-23 14:20:35 +0100230 u8 buf[AES_BLOCK_SIZE];
231 u8 *d = dst;
232
233 if (unlikely(nbytes < AES_BLOCK_SIZE))
234 src = dst = memcpy(buf + sizeof(buf) - nbytes,
235 src, nbytes);
236
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100237 neon_aes_ctr_encrypt(dst, src, ctx->enc, ctx->key.rounds,
238 nbytes, walk.iv);
Ard Biesheuvel1c0cf6d2024-02-23 14:20:35 +0100239
240 if (unlikely(nbytes < AES_BLOCK_SIZE))
241 memcpy(d, dst, nbytes);
242
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100243 nbytes = 0;
244 }
245 kernel_neon_end();
246 err = skcipher_walk_done(&walk, nbytes);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000247 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000248 return err;
249}
250
251static int aesbs_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
252 unsigned int key_len)
253{
254 struct aesbs_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
255 struct crypto_aes_ctx rk;
256 int err;
257
258 err = xts_verify_key(tfm, in_key, key_len);
259 if (err)
260 return err;
261
262 key_len /= 2;
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700263 err = aes_expandkey(&ctx->cts, in_key, key_len);
264 if (err)
265 return err;
266
Ard Biesheuvelf68df542019-07-02 21:41:31 +0200267 err = aes_expandkey(&rk, in_key + key_len, key_len);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000268 if (err)
269 return err;
270
271 memcpy(ctx->twkey, rk.key_enc, sizeof(ctx->twkey));
272
273 return aesbs_setkey(tfm, in_key, key_len);
274}
275
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700276static int __xts_crypt(struct skcipher_request *req, bool encrypt,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000277 void (*fn)(u8 out[], u8 const in[], u8 const rk[],
278 int rounds, int blocks, u8 iv[]))
279{
280 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
281 struct aesbs_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700282 int tail = req->cryptlen % (8 * AES_BLOCK_SIZE);
283 struct scatterlist sg_src[2], sg_dst[2];
284 struct skcipher_request subreq;
285 struct scatterlist *src, *dst;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000286 struct skcipher_walk walk;
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700287 int nbytes, err;
288 int first = 1;
289 u8 *out, *in;
290
291 if (req->cryptlen < AES_BLOCK_SIZE)
292 return -EINVAL;
293
294 /* ensure that the cts tail is covered by a single step */
295 if (unlikely(tail > 0 && tail < AES_BLOCK_SIZE)) {
296 int xts_blocks = DIV_ROUND_UP(req->cryptlen,
297 AES_BLOCK_SIZE) - 2;
298
299 skcipher_request_set_tfm(&subreq, tfm);
300 skcipher_request_set_callback(&subreq,
301 skcipher_request_flags(req),
302 NULL, NULL);
303 skcipher_request_set_crypt(&subreq, req->src, req->dst,
304 xts_blocks * AES_BLOCK_SIZE,
305 req->iv);
306 req = &subreq;
307 } else {
308 tail = 0;
309 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000310
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000311 err = skcipher_walk_virt(&walk, req, false);
Eric Biggers4a8108b2019-04-09 23:46:32 -0700312 if (err)
313 return err;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000314
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000315 while (walk.nbytes >= AES_BLOCK_SIZE) {
Ard Biesheuveldfc60312022-01-27 12:35:45 +0100316 int blocks = (walk.nbytes / AES_BLOCK_SIZE) & ~7;
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700317 out = walk.dst.virt.addr;
318 in = walk.src.virt.addr;
319 nbytes = walk.nbytes;
320
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000321 kernel_neon_begin();
Ard Biesheuveldfc60312022-01-27 12:35:45 +0100322 if (blocks >= 8) {
323 if (first == 1)
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700324 neon_aes_ecb_encrypt(walk.iv, walk.iv,
325 ctx->twkey,
326 ctx->key.rounds, 1);
Ard Biesheuveldfc60312022-01-27 12:35:45 +0100327 first = 2;
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700328
329 fn(out, in, ctx->key.rk, ctx->key.rounds, blocks,
330 walk.iv);
331
332 out += blocks * AES_BLOCK_SIZE;
333 in += blocks * AES_BLOCK_SIZE;
334 nbytes -= blocks * AES_BLOCK_SIZE;
335 }
Ard Biesheuveldfc60312022-01-27 12:35:45 +0100336 if (walk.nbytes == walk.total && nbytes > 0) {
337 if (encrypt)
338 neon_aes_xts_encrypt(out, in, ctx->cts.key_enc,
339 ctx->key.rounds, nbytes,
340 ctx->twkey, walk.iv, first);
341 else
342 neon_aes_xts_decrypt(out, in, ctx->cts.key_dec,
343 ctx->key.rounds, nbytes,
344 ctx->twkey, walk.iv, first);
345 nbytes = first = 0;
346 }
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000347 kernel_neon_end();
Yunfeng Ye9b537992019-10-22 16:11:18 +0800348 err = skcipher_walk_done(&walk, nbytes);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000349 }
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700350
351 if (err || likely(!tail))
352 return err;
353
354 /* handle ciphertext stealing */
355 dst = src = scatterwalk_ffwd(sg_src, req->src, req->cryptlen);
356 if (req->dst != req->src)
357 dst = scatterwalk_ffwd(sg_dst, req->dst, req->cryptlen);
358
359 skcipher_request_set_crypt(req, src, dst, AES_BLOCK_SIZE + tail,
360 req->iv);
361
362 err = skcipher_walk_virt(&walk, req, false);
363 if (err)
364 return err;
365
366 out = walk.dst.virt.addr;
367 in = walk.src.virt.addr;
368 nbytes = walk.nbytes;
369
370 kernel_neon_begin();
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700371 if (encrypt)
372 neon_aes_xts_encrypt(out, in, ctx->cts.key_enc, ctx->key.rounds,
Ard Biesheuveldfc60312022-01-27 12:35:45 +0100373 nbytes, ctx->twkey, walk.iv, first);
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700374 else
375 neon_aes_xts_decrypt(out, in, ctx->cts.key_dec, ctx->key.rounds,
Ard Biesheuveldfc60312022-01-27 12:35:45 +0100376 nbytes, ctx->twkey, walk.iv, first);
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700377 kernel_neon_end();
378
379 return skcipher_walk_done(&walk, 0);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000380}
381
382static int xts_encrypt(struct skcipher_request *req)
383{
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700384 return __xts_crypt(req, true, aesbs_xts_encrypt);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000385}
386
387static int xts_decrypt(struct skcipher_request *req)
388{
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700389 return __xts_crypt(req, false, aesbs_xts_decrypt);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000390}
391
392static struct skcipher_alg aes_algs[] = { {
Ard Biesheuvel96c34e12021-08-27 09:03:37 +0200393 .base.cra_name = "ecb(aes)",
394 .base.cra_driver_name = "ecb-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000395 .base.cra_priority = 250,
396 .base.cra_blocksize = AES_BLOCK_SIZE,
397 .base.cra_ctxsize = sizeof(struct aesbs_ctx),
398 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000399
400 .min_keysize = AES_MIN_KEY_SIZE,
401 .max_keysize = AES_MAX_KEY_SIZE,
402 .walksize = 8 * AES_BLOCK_SIZE,
403 .setkey = aesbs_setkey,
404 .encrypt = ecb_encrypt,
405 .decrypt = ecb_decrypt,
406}, {
Ard Biesheuvel96c34e12021-08-27 09:03:37 +0200407 .base.cra_name = "cbc(aes)",
408 .base.cra_driver_name = "cbc-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000409 .base.cra_priority = 250,
410 .base.cra_blocksize = AES_BLOCK_SIZE,
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100411 .base.cra_ctxsize = sizeof(struct aesbs_cbc_ctr_ctx),
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000412 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000413
414 .min_keysize = AES_MIN_KEY_SIZE,
415 .max_keysize = AES_MAX_KEY_SIZE,
416 .walksize = 8 * AES_BLOCK_SIZE,
417 .ivsize = AES_BLOCK_SIZE,
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100418 .setkey = aesbs_cbc_ctr_setkey,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000419 .encrypt = cbc_encrypt,
420 .decrypt = cbc_decrypt,
421}, {
Ard Biesheuvel96c34e12021-08-27 09:03:37 +0200422 .base.cra_name = "ctr(aes)",
423 .base.cra_driver_name = "ctr-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000424 .base.cra_priority = 250,
425 .base.cra_blocksize = 1,
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100426 .base.cra_ctxsize = sizeof(struct aesbs_cbc_ctr_ctx),
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000427 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000428
429 .min_keysize = AES_MIN_KEY_SIZE,
430 .max_keysize = AES_MAX_KEY_SIZE,
431 .chunksize = AES_BLOCK_SIZE,
432 .walksize = 8 * AES_BLOCK_SIZE,
433 .ivsize = AES_BLOCK_SIZE,
Ard Biesheuvelfc074e12022-01-27 12:35:44 +0100434 .setkey = aesbs_cbc_ctr_setkey,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000435 .encrypt = ctr_encrypt,
436 .decrypt = ctr_encrypt,
437}, {
Ard Biesheuvel96c34e12021-08-27 09:03:37 +0200438 .base.cra_name = "xts(aes)",
439 .base.cra_driver_name = "xts-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000440 .base.cra_priority = 250,
441 .base.cra_blocksize = AES_BLOCK_SIZE,
442 .base.cra_ctxsize = sizeof(struct aesbs_xts_ctx),
443 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000444
445 .min_keysize = 2 * AES_MIN_KEY_SIZE,
446 .max_keysize = 2 * AES_MAX_KEY_SIZE,
447 .walksize = 8 * AES_BLOCK_SIZE,
448 .ivsize = AES_BLOCK_SIZE,
449 .setkey = aesbs_xts_setkey,
450 .encrypt = xts_encrypt,
451 .decrypt = xts_decrypt,
452} };
453
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000454static void aes_exit(void)
455{
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000456 crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
457}
458
459static int __init aes_init(void)
460{
Andrew Murrayaaba0982019-04-09 10:52:40 +0100461 if (!cpu_have_named_feature(ASIMD))
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000462 return -ENODEV;
463
Ard Biesheuvel96c34e12021-08-27 09:03:37 +0200464 return crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000465}
466
467module_init(aes_init);
468module_exit(aes_exit);