Skip to content

Commit 69b6f2e

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: arm64/aes-neon - limit exposed routines if faster driver is enabled
The pure NEON AES implementation predates the bit-slicing one, and is generally slower, unless the algorithm in question can only execute sequentially. So advertising the skciphers that the bit-slicing driver implements as well serves no real purpose, and we can just disable them. Note that the bit-slicing driver also has a link time dependency on the pure NEON driver, for CBC encryption and for XTS tweak calculation, so we still need both drivers on systems that do not implement the Crypto Extensions. At the same time, expose those modaliases for the AES instruction based driver. This is necessary since otherwise, we may end up loading the wrong driver when any of the skciphers are instantiated before the CPU capability based module loading has completed. Finally, add the missing modalias for cts(cbc(aes)) so requests for this algorithm will autoload the correct module. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7a3b1c6 commit 69b6f2e

1 file changed

Lines changed: 59 additions & 53 deletions

File tree

‎arch/arm64/crypto/aes-glue.c‎

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,18 @@ MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 Crypto Extensions");
5454
#define aes_xts_decrypt neon_aes_xts_decrypt
5555
#define aes_mac_update neon_aes_mac_update
5656
MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 NEON");
57+
#endif
58+
#if defined(USE_V8_CRYPTO_EXTENSIONS) || !defined(CONFIG_CRYPTO_AES_ARM64_BS)
5759
MODULE_ALIAS_CRYPTO("ecb(aes)");
5860
MODULE_ALIAS_CRYPTO("cbc(aes)");
59-
MODULE_ALIAS_CRYPTO("essiv(cbc(aes),sha256)");
6061
MODULE_ALIAS_CRYPTO("ctr(aes)");
6162
MODULE_ALIAS_CRYPTO("xts(aes)");
63+
#endif
64+
MODULE_ALIAS_CRYPTO("cts(cbc(aes))");
65+
MODULE_ALIAS_CRYPTO("essiv(cbc(aes),sha256)");
6266
MODULE_ALIAS_CRYPTO("cmac(aes)");
6367
MODULE_ALIAS_CRYPTO("xcbc(aes)");
6468
MODULE_ALIAS_CRYPTO("cbcmac(aes)");
65-
#endif
6669

6770
MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
6871
MODULE_LICENSE("GPL v2");
@@ -144,8 +147,8 @@ static int skcipher_aes_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
144147
return ret;
145148
}
146149

147-
static int xts_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
148-
unsigned int key_len)
150+
static int __maybe_unused xts_set_key(struct crypto_skcipher *tfm,
151+
const u8 *in_key, unsigned int key_len)
149152
{
150153
struct crypto_aes_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
151154
int ret;
@@ -165,8 +168,9 @@ static int xts_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
165168
return -EINVAL;
166169
}
167170

168-
static int essiv_cbc_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
169-
unsigned int key_len)
171+
static int __maybe_unused essiv_cbc_set_key(struct crypto_skcipher *tfm,
172+
const u8 *in_key,
173+
unsigned int key_len)
170174
{
171175
struct crypto_aes_essiv_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
172176
SHASH_DESC_ON_STACK(desc, ctx->hash);
@@ -190,7 +194,7 @@ static int essiv_cbc_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
190194
return -EINVAL;
191195
}
192196

193-
static int ecb_encrypt(struct skcipher_request *req)
197+
static int __maybe_unused ecb_encrypt(struct skcipher_request *req)
194198
{
195199
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
196200
struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -210,7 +214,7 @@ static int ecb_encrypt(struct skcipher_request *req)
210214
return err;
211215
}
212216

213-
static int ecb_decrypt(struct skcipher_request *req)
217+
static int __maybe_unused ecb_decrypt(struct skcipher_request *req)
214218
{
215219
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
216220
struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -248,7 +252,7 @@ static int cbc_encrypt_walk(struct skcipher_request *req,
248252
return err;
249253
}
250254

251-
static int cbc_encrypt(struct skcipher_request *req)
255+
static int __maybe_unused cbc_encrypt(struct skcipher_request *req)
252256
{
253257
struct skcipher_walk walk;
254258
int err;
@@ -277,7 +281,7 @@ static int cbc_decrypt_walk(struct skcipher_request *req,
277281
return err;
278282
}
279283

280-
static int cbc_decrypt(struct skcipher_request *req)
284+
static int __maybe_unused cbc_decrypt(struct skcipher_request *req)
281285
{
282286
struct skcipher_walk walk;
283287
int err;
@@ -404,7 +408,7 @@ static int cts_cbc_decrypt(struct skcipher_request *req)
404408
return skcipher_walk_done(&walk, 0);
405409
}
406410

407-
static int essiv_cbc_init_tfm(struct crypto_skcipher *tfm)
411+
static int __maybe_unused essiv_cbc_init_tfm(struct crypto_skcipher *tfm)
408412
{
409413
struct crypto_aes_essiv_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
410414

@@ -413,14 +417,14 @@ static int essiv_cbc_init_tfm(struct crypto_skcipher *tfm)
413417
return PTR_ERR_OR_ZERO(ctx->hash);
414418
}
415419

416-
static void essiv_cbc_exit_tfm(struct crypto_skcipher *tfm)
420+
static void __maybe_unused essiv_cbc_exit_tfm(struct crypto_skcipher *tfm)
417421
{
418422
struct crypto_aes_essiv_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
419423

420424
crypto_free_shash(ctx->hash);
421425
}
422426

423-
static int essiv_cbc_encrypt(struct skcipher_request *req)
427+
static int __maybe_unused essiv_cbc_encrypt(struct skcipher_request *req)
424428
{
425429
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
426430
struct crypto_aes_essiv_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -442,7 +446,7 @@ static int essiv_cbc_encrypt(struct skcipher_request *req)
442446
return err ?: cbc_encrypt_walk(req, &walk);
443447
}
444448

445-
static int essiv_cbc_decrypt(struct skcipher_request *req)
449+
static int __maybe_unused essiv_cbc_decrypt(struct skcipher_request *req)
446450
{
447451
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
448452
struct crypto_aes_essiv_cbc_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -518,15 +522,15 @@ static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst)
518522
local_irq_restore(flags);
519523
}
520524

521-
static int ctr_encrypt_sync(struct skcipher_request *req)
525+
static int __maybe_unused ctr_encrypt_sync(struct skcipher_request *req)
522526
{
523527
if (!crypto_simd_usable())
524528
return crypto_ctr_encrypt_walk(req, ctr_encrypt_one);
525529

526530
return ctr_encrypt(req);
527531
}
528532

529-
static int xts_encrypt(struct skcipher_request *req)
533+
static int __maybe_unused xts_encrypt(struct skcipher_request *req)
530534
{
531535
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
532536
struct crypto_aes_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -548,7 +552,7 @@ static int xts_encrypt(struct skcipher_request *req)
548552
return err;
549553
}
550554

551-
static int xts_decrypt(struct skcipher_request *req)
555+
static int __maybe_unused xts_decrypt(struct skcipher_request *req)
552556
{
553557
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
554558
struct crypto_aes_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
@@ -571,6 +575,7 @@ static int xts_decrypt(struct skcipher_request *req)
571575
}
572576

573577
static struct skcipher_alg aes_algs[] = { {
578+
#if defined(USE_V8_CRYPTO_EXTENSIONS) || !defined(CONFIG_CRYPTO_AES_ARM64_BS)
574579
.base = {
575580
.cra_name = "__ecb(aes)",
576581
.cra_driver_name = "__ecb-aes-" MODE,
@@ -601,42 +606,6 @@ static struct skcipher_alg aes_algs[] = { {
601606
.setkey = skcipher_aes_setkey,
602607
.encrypt = cbc_encrypt,
603608
.decrypt = cbc_decrypt,
604-
}, {
605-
.base = {
606-
.cra_name = "__cts(cbc(aes))",
607-
.cra_driver_name = "__cts-cbc-aes-" MODE,
608-
.cra_priority = PRIO,
609-
.cra_flags = CRYPTO_ALG_INTERNAL,
610-
.cra_blocksize = AES_BLOCK_SIZE,
611-
.cra_ctxsize = sizeof(struct crypto_aes_ctx),
612-
.cra_module = THIS_MODULE,
613-
},
614-
.min_keysize = AES_MIN_KEY_SIZE,
615-
.max_keysize = AES_MAX_KEY_SIZE,
616-
.ivsize = AES_BLOCK_SIZE,
617-
.walksize = 2 * AES_BLOCK_SIZE,
618-
.setkey = skcipher_aes_setkey,
619-
.encrypt = cts_cbc_encrypt,
620-
.decrypt = cts_cbc_decrypt,
621-
.init = cts_cbc_init_tfm,
622-
}, {
623-
.base = {
624-
.cra_name = "__essiv(cbc(aes),sha256)",
625-
.cra_driver_name = "__essiv-cbc-aes-sha256-" MODE,
626-
.cra_priority = PRIO + 1,
627-
.cra_flags = CRYPTO_ALG_INTERNAL,
628-
.cra_blocksize = AES_BLOCK_SIZE,
629-
.cra_ctxsize = sizeof(struct crypto_aes_essiv_cbc_ctx),
630-
.cra_module = THIS_MODULE,
631-
},
632-
.min_keysize = AES_MIN_KEY_SIZE,
633-
.max_keysize = AES_MAX_KEY_SIZE,
634-
.ivsize = AES_BLOCK_SIZE,
635-
.setkey = essiv_cbc_set_key,
636-
.encrypt = essiv_cbc_encrypt,
637-
.decrypt = essiv_cbc_decrypt,
638-
.init = essiv_cbc_init_tfm,
639-
.exit = essiv_cbc_exit_tfm,
640609
}, {
641610
.base = {
642611
.cra_name = "__ctr(aes)",
@@ -686,6 +655,43 @@ static struct skcipher_alg aes_algs[] = { {
686655
.setkey = xts_set_key,
687656
.encrypt = xts_encrypt,
688657
.decrypt = xts_decrypt,
658+
}, {
659+
#endif
660+
.base = {
661+
.cra_name = "__cts(cbc(aes))",
662+
.cra_driver_name = "__cts-cbc-aes-" MODE,
663+
.cra_priority = PRIO,
664+
.cra_flags = CRYPTO_ALG_INTERNAL,
665+
.cra_blocksize = AES_BLOCK_SIZE,
666+
.cra_ctxsize = sizeof(struct crypto_aes_ctx),
667+
.cra_module = THIS_MODULE,
668+
},
669+
.min_keysize = AES_MIN_KEY_SIZE,
670+
.max_keysize = AES_MAX_KEY_SIZE,
671+
.ivsize = AES_BLOCK_SIZE,
672+
.walksize = 2 * AES_BLOCK_SIZE,
673+
.setkey = skcipher_aes_setkey,
674+
.encrypt = cts_cbc_encrypt,
675+
.decrypt = cts_cbc_decrypt,
676+
.init = cts_cbc_init_tfm,
677+
}, {
678+
.base = {
679+
.cra_name = "__essiv(cbc(aes),sha256)",
680+
.cra_driver_name = "__essiv-cbc-aes-sha256-" MODE,
681+
.cra_priority = PRIO + 1,
682+
.cra_flags = CRYPTO_ALG_INTERNAL,
683+
.cra_blocksize = AES_BLOCK_SIZE,
684+
.cra_ctxsize = sizeof(struct crypto_aes_essiv_cbc_ctx),
685+
.cra_module = THIS_MODULE,
686+
},
687+
.min_keysize = AES_MIN_KEY_SIZE,
688+
.max_keysize = AES_MAX_KEY_SIZE,
689+
.ivsize = AES_BLOCK_SIZE,
690+
.setkey = essiv_cbc_set_key,
691+
.encrypt = essiv_cbc_encrypt,
692+
.decrypt = essiv_cbc_decrypt,
693+
.init = essiv_cbc_init_tfm,
694+
.exit = essiv_cbc_exit_tfm,
689695
} };
690696

691697
static int cbcmac_setkey(struct crypto_shash *tfm, const u8 *in_key,

0 commit comments

Comments
 (0)