Skip to content

Commit

Permalink
crypto: chelsio - Recalculate iv only if it is needed
Browse files Browse the repository at this point in the history
Recalculate iv only if it is needed i.e. if the last req to hw
was partial for aes-xts.

Signed-off-by: Ayush Sawal <ayush.sawal@chelsio.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
ayushsawl authored and herbertx committed Mar 6, 2020
1 parent 1b44f93 commit bed44d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/crypto/chelsio/chcr_algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,12 @@ static int chcr_final_cipher_iv(struct skcipher_request *req,
if (subtype == CRYPTO_ALG_SUB_TYPE_CTR)
ctr_add_iv(iv, req->iv, DIV_ROUND_UP(reqctx->processed,
AES_BLOCK_SIZE));
else if (subtype == CRYPTO_ALG_SUB_TYPE_XTS)
ret = chcr_update_tweak(req, iv, 1);
else if (subtype == CRYPTO_ALG_SUB_TYPE_XTS) {
if (!reqctx->partial_req)
memcpy(iv, reqctx->iv, AES_BLOCK_SIZE);
else
ret = chcr_update_tweak(req, iv, 1);
}
else if (subtype == CRYPTO_ALG_SUB_TYPE_CBC) {
/*Already updated for Decrypt*/
if (!reqctx->op)
Expand Down Expand Up @@ -1199,6 +1203,7 @@ static int process_cipher(struct skcipher_request *req,
int bytes, err = -EINVAL;

reqctx->processed = 0;
reqctx->partial_req = 0;
if (!req->iv)
goto error;
if ((ablkctx->enckey_len == 0) || (ivsize > AES_BLOCK_SIZE) ||
Expand Down Expand Up @@ -1289,6 +1294,7 @@ static int process_cipher(struct skcipher_request *req,
}
reqctx->processed = bytes;
reqctx->last_req_len = bytes;
reqctx->partial_req = !!(req->cryptlen - reqctx->processed);

return 0;
unmap:
Expand All @@ -1300,6 +1306,7 @@ static int process_cipher(struct skcipher_request *req,
static int chcr_aes_encrypt(struct skcipher_request *req)
{
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
struct chcr_skcipher_req_ctx *reqctx = skcipher_request_ctx(req);
struct chcr_context *ctx;
struct chcr_dev *dev = c_ctx(tfm)->dev;
struct sk_buff *skb = NULL;
Expand Down Expand Up @@ -1329,6 +1336,7 @@ static int chcr_aes_encrypt(struct skcipher_request *req)
CRYPTO_ALG_SUB_TYPE_CBC && req->base.flags ==
CRYPTO_TFM_REQ_MAY_SLEEP ) {
ctx=c_ctx(tfm);
reqctx->partial_req = 1;
wait_for_completion(&ctx->cbc_aes_aio_done);
}
return isfull ? -EBUSY : -EINPROGRESS;
Expand Down
1 change: 1 addition & 0 deletions drivers/crypto/chelsio/chcr_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ struct chcr_skcipher_req_ctx {
struct scatterlist *dstsg;
unsigned int processed;
unsigned int last_req_len;
unsigned int partial_req;
struct scatterlist *srcsg;
unsigned int src_ofst;
unsigned int dst_ofst;
Expand Down

0 comments on commit bed44d0

Please sign in to comment.