Commit d3f1d2f7 authored by Harsh Jain's avatar Harsh Jain Committed by Herbert Xu

crypto: chcr - Avoid algo allocation in softirq.

Thsi patch fixes calling "crypto_alloc_cipher" call in bottom halves.
Pre allocate aes cipher required to update Tweak value for XTS.
Signed-off-by: default avatarHarsh Jain <harsh@chelsio.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 854b06f7
...@@ -899,26 +899,20 @@ static int chcr_update_tweak(struct ablkcipher_request *req, u8 *iv) ...@@ -899,26 +899,20 @@ static int chcr_update_tweak(struct ablkcipher_request *req, u8 *iv)
u8 *key; u8 *key;
unsigned int keylen; unsigned int keylen;
cipher = crypto_alloc_cipher("aes-generic", 0, 0); cipher = ablkctx->aes_generic;
memcpy(iv, req->info, AES_BLOCK_SIZE); memcpy(iv, req->info, AES_BLOCK_SIZE);
if (IS_ERR(cipher)) {
ret = -ENOMEM;
goto out;
}
keylen = ablkctx->enckey_len / 2; keylen = ablkctx->enckey_len / 2;
key = ablkctx->key + keylen; key = ablkctx->key + keylen;
ret = crypto_cipher_setkey(cipher, key, keylen); ret = crypto_cipher_setkey(cipher, key, keylen);
if (ret) if (ret)
goto out1; goto out;
crypto_cipher_encrypt_one(cipher, iv, iv); crypto_cipher_encrypt_one(cipher, iv, iv);
for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++) for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++)
gf128mul_x_ble((le128 *)iv, (le128 *)iv); gf128mul_x_ble((le128 *)iv, (le128 *)iv);
crypto_cipher_decrypt_one(cipher, iv, iv); crypto_cipher_decrypt_one(cipher, iv, iv);
out1:
crypto_free_cipher(cipher);
out: out:
return ret; return ret;
} }
...@@ -1262,6 +1256,17 @@ static int chcr_cra_init(struct crypto_tfm *tfm) ...@@ -1262,6 +1256,17 @@ static int chcr_cra_init(struct crypto_tfm *tfm)
pr_err("failed to allocate fallback for %s\n", alg->cra_name); pr_err("failed to allocate fallback for %s\n", alg->cra_name);
return PTR_ERR(ablkctx->sw_cipher); return PTR_ERR(ablkctx->sw_cipher);
} }
if (get_cryptoalg_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_XTS) {
/* To update tweak*/
ablkctx->aes_generic = crypto_alloc_cipher("aes-generic", 0, 0);
if (IS_ERR(ablkctx->aes_generic)) {
pr_err("failed to allocate aes cipher for tweak\n");
return PTR_ERR(ablkctx->aes_generic);
}
} else
ablkctx->aes_generic = NULL;
tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx); tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx);
return chcr_device_init(crypto_tfm_ctx(tfm)); return chcr_device_init(crypto_tfm_ctx(tfm));
} }
...@@ -1292,6 +1297,8 @@ static void chcr_cra_exit(struct crypto_tfm *tfm) ...@@ -1292,6 +1297,8 @@ static void chcr_cra_exit(struct crypto_tfm *tfm)
struct ablk_ctx *ablkctx = ABLK_CTX(ctx); struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
crypto_free_skcipher(ablkctx->sw_cipher); crypto_free_skcipher(ablkctx->sw_cipher);
if (ablkctx->aes_generic)
crypto_free_cipher(ablkctx->aes_generic);
} }
static int get_alg_config(struct algo_param *params, static int get_alg_config(struct algo_param *params,
......
...@@ -155,6 +155,7 @@ ...@@ -155,6 +155,7 @@
struct ablk_ctx { struct ablk_ctx {
struct crypto_skcipher *sw_cipher; struct crypto_skcipher *sw_cipher;
struct crypto_cipher *aes_generic;
__be32 key_ctx_hdr; __be32 key_ctx_hdr;
unsigned int enckey_len; unsigned int enckey_len;
unsigned char ciph_mode; unsigned char ciph_mode;
......
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