blob: 8df6ad8cb09d6d144d07622395716b22abadacca [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 Biesheuvel88a3f582017-02-02 11:38:55 +000037 int rounds, int blocks, u8 iv[], u8 final[]);
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 Biesheuvel67cfa5d2019-09-03 09:43:34 -070049asmlinkage void neon_aes_xts_encrypt(u8 out[], u8 const in[],
50 u32 const rk1[], int rounds, int bytes,
51 u32 const rk2[], u8 iv[], int first);
52asmlinkage void neon_aes_xts_decrypt(u8 out[], u8 const in[],
53 u32 const rk1[], int rounds, int bytes,
54 u32 const rk2[], u8 iv[], int first);
Ard Biesheuvel1abee992017-01-11 16:41:55 +000055
56struct aesbs_ctx {
57 u8 rk[13 * (8 * AES_BLOCK_SIZE) + 32];
58 int rounds;
59} __aligned(AES_BLOCK_SIZE);
60
61struct aesbs_cbc_ctx {
62 struct aesbs_ctx key;
63 u32 enc[AES_MAX_KEYLENGTH_U32];
64};
65
66struct aesbs_xts_ctx {
67 struct aesbs_ctx key;
68 u32 twkey[AES_MAX_KEYLENGTH_U32];
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -070069 struct crypto_aes_ctx cts;
Ard Biesheuvel1abee992017-01-11 16:41:55 +000070};
71
72static int aesbs_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
73 unsigned int key_len)
74{
75 struct aesbs_ctx *ctx = crypto_skcipher_ctx(tfm);
76 struct crypto_aes_ctx rk;
77 int err;
78
Ard Biesheuvelf68df542019-07-02 21:41:31 +020079 err = aes_expandkey(&rk, in_key, key_len);
Ard Biesheuvel1abee992017-01-11 16:41:55 +000080 if (err)
81 return err;
82
83 ctx->rounds = 6 + key_len / 4;
84
85 kernel_neon_begin();
86 aesbs_convert_key(ctx->rk, rk.key_enc, ctx->rounds);
87 kernel_neon_end();
88
89 return 0;
90}
91
92static int __ecb_crypt(struct skcipher_request *req,
93 void (*fn)(u8 out[], u8 const in[], u8 const rk[],
94 int rounds, int blocks))
95{
96 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
97 struct aesbs_ctx *ctx = crypto_skcipher_ctx(tfm);
98 struct skcipher_walk walk;
99 int err;
100
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000101 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000102
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000103 while (walk.nbytes >= AES_BLOCK_SIZE) {
104 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
105
106 if (walk.nbytes < walk.total)
107 blocks = round_down(blocks,
108 walk.stride / AES_BLOCK_SIZE);
109
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000110 kernel_neon_begin();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000111 fn(walk.dst.virt.addr, walk.src.virt.addr, ctx->rk,
112 ctx->rounds, blocks);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000113 kernel_neon_end();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000114 err = skcipher_walk_done(&walk,
115 walk.nbytes - blocks * AES_BLOCK_SIZE);
116 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000117
118 return err;
119}
120
121static int ecb_encrypt(struct skcipher_request *req)
122{
123 return __ecb_crypt(req, aesbs_ecb_encrypt);
124}
125
126static int ecb_decrypt(struct skcipher_request *req)
127{
128 return __ecb_crypt(req, aesbs_ecb_decrypt);
129}
130
131static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
132 unsigned int key_len)
133{
134 struct aesbs_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
135 struct crypto_aes_ctx rk;
136 int err;
137
Ard Biesheuvelf68df542019-07-02 21:41:31 +0200138 err = aes_expandkey(&rk, in_key, key_len);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000139 if (err)
140 return err;
141
142 ctx->key.rounds = 6 + key_len / 4;
143
144 memcpy(ctx->enc, rk.key_enc, sizeof(ctx->enc));
145
146 kernel_neon_begin();
147 aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
148 kernel_neon_end();
Torsten Duwe82ff4932020-03-13 12:02:58 +0100149 memzero_explicit(&rk, sizeof(rk));
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000150
151 return 0;
152}
153
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000154static int cbc_encrypt(struct skcipher_request *req)
155{
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000156 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
157 struct aesbs_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
158 struct skcipher_walk walk;
Ard Biesheuvel68338172018-03-10 15:21:48 +0000159 int err;
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000160
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000161 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000162
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000163 while (walk.nbytes >= AES_BLOCK_SIZE) {
164 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
165
166 /* fall back to the non-bitsliced NEON implementation */
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000167 kernel_neon_begin();
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000168 neon_aes_cbc_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
Ard Biesheuvel68338172018-03-10 15:21:48 +0000169 ctx->enc, ctx->key.rounds, blocks,
170 walk.iv);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000171 kernel_neon_end();
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000172 err = skcipher_walk_done(&walk, walk.nbytes % AES_BLOCK_SIZE);
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000173 }
Ard Biesheuvel12fcd922017-01-28 23:25:39 +0000174 return err;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000175}
176
177static int cbc_decrypt(struct skcipher_request *req)
178{
179 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
180 struct aesbs_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
181 struct skcipher_walk walk;
182 int err;
183
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000184 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000185
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000186 while (walk.nbytes >= AES_BLOCK_SIZE) {
187 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
188
189 if (walk.nbytes < walk.total)
190 blocks = round_down(blocks,
191 walk.stride / AES_BLOCK_SIZE);
192
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000193 kernel_neon_begin();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000194 aesbs_cbc_decrypt(walk.dst.virt.addr, walk.src.virt.addr,
195 ctx->key.rk, ctx->key.rounds, blocks,
196 walk.iv);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000197 kernel_neon_end();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000198 err = skcipher_walk_done(&walk,
199 walk.nbytes - blocks * AES_BLOCK_SIZE);
200 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000201
202 return err;
203}
204
205static int ctr_encrypt(struct skcipher_request *req)
206{
207 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
208 struct aesbs_ctx *ctx = crypto_skcipher_ctx(tfm);
209 struct skcipher_walk walk;
Ard Biesheuvel88a3f582017-02-02 11:38:55 +0000210 u8 buf[AES_BLOCK_SIZE];
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000211 int err;
212
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000213 err = skcipher_walk_virt(&walk, req, false);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000214
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000215 while (walk.nbytes > 0) {
216 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
Ard Biesheuvel88a3f582017-02-02 11:38:55 +0000217 u8 *final = (walk.total % AES_BLOCK_SIZE) ? buf : NULL;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000218
219 if (walk.nbytes < walk.total) {
220 blocks = round_down(blocks,
221 walk.stride / AES_BLOCK_SIZE);
Ard Biesheuvel88a3f582017-02-02 11:38:55 +0000222 final = NULL;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000223 }
224
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000225 kernel_neon_begin();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000226 aesbs_ctr_encrypt(walk.dst.virt.addr, walk.src.virt.addr,
227 ctx->rk, ctx->rounds, blocks, walk.iv, final);
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000228 kernel_neon_end();
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000229
230 if (final) {
231 u8 *dst = walk.dst.virt.addr + blocks * AES_BLOCK_SIZE;
232 u8 *src = walk.src.virt.addr + blocks * AES_BLOCK_SIZE;
233
Ard Biesheuvel45fe93d2017-07-24 11:28:04 +0100234 crypto_xor_cpy(dst, src, final,
235 walk.total % AES_BLOCK_SIZE);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000236
237 err = skcipher_walk_done(&walk, 0);
238 break;
239 }
240 err = skcipher_walk_done(&walk,
241 walk.nbytes - blocks * AES_BLOCK_SIZE);
242 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000243 return err;
244}
245
246static int aesbs_xts_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
247 unsigned int key_len)
248{
249 struct aesbs_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
250 struct crypto_aes_ctx rk;
251 int err;
252
253 err = xts_verify_key(tfm, in_key, key_len);
254 if (err)
255 return err;
256
257 key_len /= 2;
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700258 err = aes_expandkey(&ctx->cts, in_key, key_len);
259 if (err)
260 return err;
261
Ard Biesheuvelf68df542019-07-02 21:41:31 +0200262 err = aes_expandkey(&rk, in_key + key_len, key_len);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000263 if (err)
264 return err;
265
266 memcpy(ctx->twkey, rk.key_enc, sizeof(ctx->twkey));
267
268 return aesbs_setkey(tfm, in_key, key_len);
269}
270
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700271static int __xts_crypt(struct skcipher_request *req, bool encrypt,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000272 void (*fn)(u8 out[], u8 const in[], u8 const rk[],
273 int rounds, int blocks, u8 iv[]))
274{
275 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
276 struct aesbs_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700277 int tail = req->cryptlen % (8 * AES_BLOCK_SIZE);
278 struct scatterlist sg_src[2], sg_dst[2];
279 struct skcipher_request subreq;
280 struct scatterlist *src, *dst;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000281 struct skcipher_walk walk;
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700282 int nbytes, err;
283 int first = 1;
284 u8 *out, *in;
285
286 if (req->cryptlen < AES_BLOCK_SIZE)
287 return -EINVAL;
288
289 /* ensure that the cts tail is covered by a single step */
290 if (unlikely(tail > 0 && tail < AES_BLOCK_SIZE)) {
291 int xts_blocks = DIV_ROUND_UP(req->cryptlen,
292 AES_BLOCK_SIZE) - 2;
293
294 skcipher_request_set_tfm(&subreq, tfm);
295 skcipher_request_set_callback(&subreq,
296 skcipher_request_flags(req),
297 NULL, NULL);
298 skcipher_request_set_crypt(&subreq, req->src, req->dst,
299 xts_blocks * AES_BLOCK_SIZE,
300 req->iv);
301 req = &subreq;
302 } else {
303 tail = 0;
304 }
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000305
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000306 err = skcipher_walk_virt(&walk, req, false);
Eric Biggers4a8108b2019-04-09 23:46:32 -0700307 if (err)
308 return err;
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000309
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000310 while (walk.nbytes >= AES_BLOCK_SIZE) {
311 unsigned int blocks = walk.nbytes / AES_BLOCK_SIZE;
312
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700313 if (walk.nbytes < walk.total || walk.nbytes % AES_BLOCK_SIZE)
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000314 blocks = round_down(blocks,
315 walk.stride / AES_BLOCK_SIZE);
316
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 Biesheuvel67cfa5d2019-09-03 09:43:34 -0700322 if (likely(blocks > 6)) { /* plain NEON is faster otherwise */
323 if (first)
324 neon_aes_ecb_encrypt(walk.iv, walk.iv,
325 ctx->twkey,
326 ctx->key.rounds, 1);
327 first = 0;
328
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 }
336
337 if (walk.nbytes == walk.total && nbytes > 0)
338 goto xts_tail;
339
Ard Biesheuvel78ad7b02018-03-10 15:21:49 +0000340 kernel_neon_end();
Yunfeng Ye9b537992019-10-22 16:11:18 +0800341 err = skcipher_walk_done(&walk, nbytes);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000342 }
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700343
344 if (err || likely(!tail))
345 return err;
346
347 /* handle ciphertext stealing */
348 dst = src = scatterwalk_ffwd(sg_src, req->src, req->cryptlen);
349 if (req->dst != req->src)
350 dst = scatterwalk_ffwd(sg_dst, req->dst, req->cryptlen);
351
352 skcipher_request_set_crypt(req, src, dst, AES_BLOCK_SIZE + tail,
353 req->iv);
354
355 err = skcipher_walk_virt(&walk, req, false);
356 if (err)
357 return err;
358
359 out = walk.dst.virt.addr;
360 in = walk.src.virt.addr;
361 nbytes = walk.nbytes;
362
363 kernel_neon_begin();
364xts_tail:
365 if (encrypt)
366 neon_aes_xts_encrypt(out, in, ctx->cts.key_enc, ctx->key.rounds,
367 nbytes, ctx->twkey, walk.iv, first ?: 2);
368 else
369 neon_aes_xts_decrypt(out, in, ctx->cts.key_dec, ctx->key.rounds,
370 nbytes, ctx->twkey, walk.iv, first ?: 2);
371 kernel_neon_end();
372
373 return skcipher_walk_done(&walk, 0);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000374}
375
376static int xts_encrypt(struct skcipher_request *req)
377{
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700378 return __xts_crypt(req, true, aesbs_xts_encrypt);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000379}
380
381static int xts_decrypt(struct skcipher_request *req)
382{
Ard Biesheuvel67cfa5d2019-09-03 09:43:34 -0700383 return __xts_crypt(req, false, aesbs_xts_decrypt);
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000384}
385
386static struct skcipher_alg aes_algs[] = { {
Ard Biesheuvel2dabae82021-05-12 20:44:37 +0200387 .base.cra_name = "ecb(aes)",
388 .base.cra_driver_name = "ecb-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000389 .base.cra_priority = 250,
390 .base.cra_blocksize = AES_BLOCK_SIZE,
391 .base.cra_ctxsize = sizeof(struct aesbs_ctx),
392 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000393
394 .min_keysize = AES_MIN_KEY_SIZE,
395 .max_keysize = AES_MAX_KEY_SIZE,
396 .walksize = 8 * AES_BLOCK_SIZE,
397 .setkey = aesbs_setkey,
398 .encrypt = ecb_encrypt,
399 .decrypt = ecb_decrypt,
400}, {
Ard Biesheuvel2dabae82021-05-12 20:44:37 +0200401 .base.cra_name = "cbc(aes)",
402 .base.cra_driver_name = "cbc-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000403 .base.cra_priority = 250,
404 .base.cra_blocksize = AES_BLOCK_SIZE,
405 .base.cra_ctxsize = sizeof(struct aesbs_cbc_ctx),
406 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000407
408 .min_keysize = AES_MIN_KEY_SIZE,
409 .max_keysize = AES_MAX_KEY_SIZE,
410 .walksize = 8 * AES_BLOCK_SIZE,
411 .ivsize = AES_BLOCK_SIZE,
412 .setkey = aesbs_cbc_setkey,
413 .encrypt = cbc_encrypt,
414 .decrypt = cbc_decrypt,
415}, {
Ard Biesheuvel2dabae82021-05-12 20:44:37 +0200416 .base.cra_name = "ctr(aes)",
417 .base.cra_driver_name = "ctr-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000418 .base.cra_priority = 250,
419 .base.cra_blocksize = 1,
420 .base.cra_ctxsize = sizeof(struct aesbs_ctx),
421 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000422
423 .min_keysize = AES_MIN_KEY_SIZE,
424 .max_keysize = AES_MAX_KEY_SIZE,
425 .chunksize = AES_BLOCK_SIZE,
426 .walksize = 8 * AES_BLOCK_SIZE,
427 .ivsize = AES_BLOCK_SIZE,
428 .setkey = aesbs_setkey,
429 .encrypt = ctr_encrypt,
430 .decrypt = ctr_encrypt,
431}, {
Ard Biesheuvel2dabae82021-05-12 20:44:37 +0200432 .base.cra_name = "xts(aes)",
433 .base.cra_driver_name = "xts-aes-neonbs",
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000434 .base.cra_priority = 250,
435 .base.cra_blocksize = AES_BLOCK_SIZE,
436 .base.cra_ctxsize = sizeof(struct aesbs_xts_ctx),
437 .base.cra_module = THIS_MODULE,
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000438
439 .min_keysize = 2 * AES_MIN_KEY_SIZE,
440 .max_keysize = 2 * AES_MAX_KEY_SIZE,
441 .walksize = 8 * AES_BLOCK_SIZE,
442 .ivsize = AES_BLOCK_SIZE,
443 .setkey = aesbs_xts_setkey,
444 .encrypt = xts_encrypt,
445 .decrypt = xts_decrypt,
446} };
447
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000448static void aes_exit(void)
449{
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000450 crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
451}
452
453static int __init aes_init(void)
454{
Andrew Murrayaaba0982019-04-09 10:52:40 +0100455 if (!cpu_have_named_feature(ASIMD))
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000456 return -ENODEV;
457
Ard Biesheuvel2dabae82021-05-12 20:44:37 +0200458 return crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
Ard Biesheuvel1abee992017-01-11 16:41:55 +0000459}
460
461module_init(aes_init);
462module_exit(aes_exit);