Commit 676e5081 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Herbert Xu

crypto: arm64/aes-ce - stop using SIMD helper for skciphers

Calls into the skcipher API can only occur from contexts where the SIMD
unit is available, so there is no need for the SIMD helper.
Reviewed-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 96c34e14
...@@ -88,16 +88,12 @@ config CRYPTO_AES_ARM64_CE_BLK ...@@ -88,16 +88,12 @@ config CRYPTO_AES_ARM64_CE_BLK
depends on KERNEL_MODE_NEON depends on KERNEL_MODE_NEON
select CRYPTO_SKCIPHER select CRYPTO_SKCIPHER
select CRYPTO_AES_ARM64_CE select CRYPTO_AES_ARM64_CE
select CRYPTO_AES_ARM64
select CRYPTO_SIMD
config CRYPTO_AES_ARM64_NEON_BLK config CRYPTO_AES_ARM64_NEON_BLK
tristate "AES in ECB/CBC/CTR/XTS modes using NEON instructions" tristate "AES in ECB/CBC/CTR/XTS modes using NEON instructions"
depends on KERNEL_MODE_NEON depends on KERNEL_MODE_NEON
select CRYPTO_SKCIPHER select CRYPTO_SKCIPHER
select CRYPTO_AES_ARM64
select CRYPTO_LIB_AES select CRYPTO_LIB_AES
select CRYPTO_SIMD
config CRYPTO_CHACHA20_NEON config CRYPTO_CHACHA20_NEON
tristate "ChaCha20, XChaCha20, and XChaCha12 stream ciphers using NEON instructions" tristate "ChaCha20, XChaCha20, and XChaCha12 stream ciphers using NEON instructions"
......
...@@ -444,7 +444,7 @@ static int __maybe_unused essiv_cbc_decrypt(struct skcipher_request *req) ...@@ -444,7 +444,7 @@ static int __maybe_unused essiv_cbc_decrypt(struct skcipher_request *req)
return err ?: cbc_decrypt_walk(req, &walk); return err ?: cbc_decrypt_walk(req, &walk);
} }
static int ctr_encrypt(struct skcipher_request *req) static int __maybe_unused ctr_encrypt(struct skcipher_request *req)
{ {
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm); struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
...@@ -485,29 +485,6 @@ static int ctr_encrypt(struct skcipher_request *req) ...@@ -485,29 +485,6 @@ static int ctr_encrypt(struct skcipher_request *req)
return err; return err;
} }
static void ctr_encrypt_one(struct crypto_skcipher *tfm, const u8 *src, u8 *dst)
{
const struct crypto_aes_ctx *ctx = crypto_skcipher_ctx(tfm);
unsigned long flags;
/*
* Temporarily disable interrupts to avoid races where
* cachelines are evicted when the CPU is interrupted
* to do something else.
*/
local_irq_save(flags);
aes_encrypt(ctx, dst, src);
local_irq_restore(flags);
}
static int __maybe_unused ctr_encrypt_sync(struct skcipher_request *req)
{
if (!crypto_simd_usable())
return crypto_ctr_encrypt_walk(req, ctr_encrypt_one);
return ctr_encrypt(req);
}
static int __maybe_unused xts_encrypt(struct skcipher_request *req) static int __maybe_unused xts_encrypt(struct skcipher_request *req)
{ {
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
...@@ -656,10 +633,9 @@ static int __maybe_unused xts_decrypt(struct skcipher_request *req) ...@@ -656,10 +633,9 @@ static int __maybe_unused xts_decrypt(struct skcipher_request *req)
static struct skcipher_alg aes_algs[] = { { static struct skcipher_alg aes_algs[] = { {
#if defined(USE_V8_CRYPTO_EXTENSIONS) || !IS_ENABLED(CONFIG_CRYPTO_AES_ARM64_BS) #if defined(USE_V8_CRYPTO_EXTENSIONS) || !IS_ENABLED(CONFIG_CRYPTO_AES_ARM64_BS)
.base = { .base = {
.cra_name = "__ecb(aes)", .cra_name = "ecb(aes)",
.cra_driver_name = "__ecb-aes-" MODE, .cra_driver_name = "ecb-aes-" MODE,
.cra_priority = PRIO, .cra_priority = PRIO,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = AES_BLOCK_SIZE, .cra_blocksize = AES_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crypto_aes_ctx), .cra_ctxsize = sizeof(struct crypto_aes_ctx),
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
...@@ -671,10 +647,9 @@ static struct skcipher_alg aes_algs[] = { { ...@@ -671,10 +647,9 @@ static struct skcipher_alg aes_algs[] = { {
.decrypt = ecb_decrypt, .decrypt = ecb_decrypt,
}, { }, {
.base = { .base = {
.cra_name = "__cbc(aes)", .cra_name = "cbc(aes)",
.cra_driver_name = "__cbc-aes-" MODE, .cra_driver_name = "cbc-aes-" MODE,
.cra_priority = PRIO, .cra_priority = PRIO,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = AES_BLOCK_SIZE, .cra_blocksize = AES_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crypto_aes_ctx), .cra_ctxsize = sizeof(struct crypto_aes_ctx),
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
...@@ -687,10 +662,9 @@ static struct skcipher_alg aes_algs[] = { { ...@@ -687,10 +662,9 @@ static struct skcipher_alg aes_algs[] = { {
.decrypt = cbc_decrypt, .decrypt = cbc_decrypt,
}, { }, {
.base = { .base = {
.cra_name = "__ctr(aes)", .cra_name = "ctr(aes)",
.cra_driver_name = "__ctr-aes-" MODE, .cra_driver_name = "ctr-aes-" MODE,
.cra_priority = PRIO, .cra_priority = PRIO,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = 1, .cra_blocksize = 1,
.cra_ctxsize = sizeof(struct crypto_aes_ctx), .cra_ctxsize = sizeof(struct crypto_aes_ctx),
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
...@@ -704,26 +678,9 @@ static struct skcipher_alg aes_algs[] = { { ...@@ -704,26 +678,9 @@ static struct skcipher_alg aes_algs[] = { {
.decrypt = ctr_encrypt, .decrypt = ctr_encrypt,
}, { }, {
.base = { .base = {
.cra_name = "ctr(aes)", .cra_name = "xts(aes)",
.cra_driver_name = "ctr-aes-" MODE, .cra_driver_name = "xts-aes-" MODE,
.cra_priority = PRIO - 1,
.cra_blocksize = 1,
.cra_ctxsize = sizeof(struct crypto_aes_ctx),
.cra_module = THIS_MODULE,
},
.min_keysize = AES_MIN_KEY_SIZE,
.max_keysize = AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE,
.chunksize = AES_BLOCK_SIZE,
.setkey = skcipher_aes_setkey,
.encrypt = ctr_encrypt_sync,
.decrypt = ctr_encrypt_sync,
}, {
.base = {
.cra_name = "__xts(aes)",
.cra_driver_name = "__xts-aes-" MODE,
.cra_priority = PRIO, .cra_priority = PRIO,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = AES_BLOCK_SIZE, .cra_blocksize = AES_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crypto_aes_xts_ctx), .cra_ctxsize = sizeof(struct crypto_aes_xts_ctx),
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
...@@ -738,10 +695,9 @@ static struct skcipher_alg aes_algs[] = { { ...@@ -738,10 +695,9 @@ static struct skcipher_alg aes_algs[] = { {
}, { }, {
#endif #endif
.base = { .base = {
.cra_name = "__cts(cbc(aes))", .cra_name = "cts(cbc(aes))",
.cra_driver_name = "__cts-cbc-aes-" MODE, .cra_driver_name = "cts-cbc-aes-" MODE,
.cra_priority = PRIO, .cra_priority = PRIO,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = AES_BLOCK_SIZE, .cra_blocksize = AES_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crypto_aes_ctx), .cra_ctxsize = sizeof(struct crypto_aes_ctx),
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
...@@ -755,10 +711,9 @@ static struct skcipher_alg aes_algs[] = { { ...@@ -755,10 +711,9 @@ static struct skcipher_alg aes_algs[] = { {
.decrypt = cts_cbc_decrypt, .decrypt = cts_cbc_decrypt,
}, { }, {
.base = { .base = {
.cra_name = "__essiv(cbc(aes),sha256)", .cra_name = "essiv(cbc(aes),sha256)",
.cra_driver_name = "__essiv-cbc-aes-sha256-" MODE, .cra_driver_name = "essiv-cbc-aes-sha256-" MODE,
.cra_priority = PRIO + 1, .cra_priority = PRIO + 1,
.cra_flags = CRYPTO_ALG_INTERNAL,
.cra_blocksize = AES_BLOCK_SIZE, .cra_blocksize = AES_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crypto_aes_essiv_cbc_ctx), .cra_ctxsize = sizeof(struct crypto_aes_essiv_cbc_ctx),
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
...@@ -997,28 +952,15 @@ static struct shash_alg mac_algs[] = { { ...@@ -997,28 +952,15 @@ static struct shash_alg mac_algs[] = { {
.descsize = sizeof(struct mac_desc_ctx), .descsize = sizeof(struct mac_desc_ctx),
} }; } };
static struct simd_skcipher_alg *aes_simd_algs[ARRAY_SIZE(aes_algs)];
static void aes_exit(void) static void aes_exit(void)
{ {
int i;
for (i = 0; i < ARRAY_SIZE(aes_simd_algs); i++)
if (aes_simd_algs[i])
simd_skcipher_free(aes_simd_algs[i]);
crypto_unregister_shashes(mac_algs, ARRAY_SIZE(mac_algs)); crypto_unregister_shashes(mac_algs, ARRAY_SIZE(mac_algs));
crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
} }
static int __init aes_init(void) static int __init aes_init(void)
{ {
struct simd_skcipher_alg *simd;
const char *basename;
const char *algname;
const char *drvname;
int err; int err;
int i;
err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); err = crypto_register_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
if (err) if (err)
...@@ -1028,26 +970,8 @@ static int __init aes_init(void) ...@@ -1028,26 +970,8 @@ static int __init aes_init(void)
if (err) if (err)
goto unregister_ciphers; goto unregister_ciphers;
for (i = 0; i < ARRAY_SIZE(aes_algs); i++) {
if (!(aes_algs[i].base.cra_flags & CRYPTO_ALG_INTERNAL))
continue;
algname = aes_algs[i].base.cra_name + 2;
drvname = aes_algs[i].base.cra_driver_name + 2;
basename = aes_algs[i].base.cra_driver_name;
simd = simd_skcipher_create_compat(algname, drvname, basename);
err = PTR_ERR(simd);
if (IS_ERR(simd))
goto unregister_simds;
aes_simd_algs[i] = simd;
}
return 0; return 0;
unregister_simds:
aes_exit();
return err;
unregister_ciphers: unregister_ciphers:
crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs)); crypto_unregister_skciphers(aes_algs, ARRAY_SIZE(aes_algs));
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment