mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-12-18 08:26:08 +01:00
LF-14933: drivers: tee: crypto: remove limitation in buf sz
Removes the limitation for input buffer size greater than 4096. For the input buffer is divided in to chunks of 4096 bytes, the performance with buffer size greater than 4096, tends to remain flat or lower. Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
This commit is contained in:
parent
d415b45bdc
commit
051c87ef3c
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "tee_skcipher.h"
|
||||
|
||||
#define TEE_CRYPT_INIT_MAX_BUF_SZ SZ_4K
|
||||
|
||||
static DEFINE_MUTEX(algs_lock);
|
||||
static unsigned int active_devs;
|
||||
static atomic_long_t key_counter;
|
||||
|
|
@ -291,6 +293,8 @@ static int aes_crypt(struct skcipher_request *req, u8 ta_cmd_id)
|
|||
u32 out_len = req->cryptlen + pad_len;
|
||||
u32 in_len = req->cryptlen + pad_len;
|
||||
u32 iv_len = ctx->iv_size;
|
||||
u32 skip_in_len = 0;
|
||||
u32 pend_in_len = in_len;
|
||||
u8 *out_buf = NULL;
|
||||
u8 *in_buf = NULL;
|
||||
u8 *iv_buf = NULL;
|
||||
|
|
@ -298,30 +302,37 @@ static int aes_crypt(struct skcipher_request *req, u8 ta_cmd_id)
|
|||
u32 dst_nents;
|
||||
|
||||
src_nents = sg_nents_for_len(req->src, req->cryptlen);
|
||||
|
||||
dst_nents = sg_nents_for_len(req->dst, req->cryptlen);
|
||||
mutex_lock(&tc_prv_lock);
|
||||
tc_prv_ctx = tc_prv;
|
||||
|
||||
in_buf = tc_prv_ctx->shm_pool;
|
||||
out_buf = in_buf + in_len;
|
||||
iv_buf = out_buf + out_len;
|
||||
do {
|
||||
if (pend_in_len > TEE_CRYPT_INIT_MAX_BUF_SZ)
|
||||
in_len = TEE_CRYPT_INIT_MAX_BUF_SZ;
|
||||
|
||||
memcpy(iv_buf, req->iv, iv_len);
|
||||
out_len = in_len;
|
||||
|
||||
sg_copy_to_buffer(req->src, src_nents, in_buf, in_len);
|
||||
in_buf = tc_prv_ctx->shm_pool;
|
||||
out_buf = in_buf + in_len;
|
||||
iv_buf = out_buf + out_len;
|
||||
|
||||
ret = tc_sk_crypt(ctx, tc_prv_ctx,
|
||||
out_len, in_len, iv_len,
|
||||
ta_cmd_id);
|
||||
memcpy(iv_buf, req->iv, iv_len);
|
||||
|
||||
if (ret) {
|
||||
pr_err("TEE-Crypt: SK-Cipher Ops Failed[0x%x].", ret);
|
||||
goto out;
|
||||
}
|
||||
sg_copy_buffer(req->src, src_nents, in_buf, in_len, skip_in_len, true);
|
||||
|
||||
dst_nents = sg_nents_for_len(req->dst, req->cryptlen);
|
||||
ret = tc_sk_crypt(ctx, tc_prv_ctx,
|
||||
out_len, in_len, iv_len,
|
||||
ta_cmd_id);
|
||||
|
||||
sg_copy_from_buffer(req->dst, dst_nents, out_buf, out_len);
|
||||
if (ret) {
|
||||
pr_err("TEE-Crypt: SK-Cipher Ops Failed[0x%x].", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_copy_buffer(req->dst, dst_nents, out_buf, out_len, skip_in_len, false);
|
||||
pend_in_len = pend_in_len - in_len;
|
||||
skip_in_len += in_len;
|
||||
} while (pend_in_len);
|
||||
|
||||
out:
|
||||
mutex_unlock(&tc_prv_lock);
|
||||
|
|
@ -576,20 +587,20 @@ static int tee_crypt_open_session(struct tee_crypt_priv_data *tc_prv_ctx)
|
|||
if ((ret < 0) || (sess_arg.ret != 0)) {
|
||||
pr_err("tee_client_open_session failed, err: %x\n",
|
||||
sess_arg.ret);
|
||||
ret = -EINVAL;
|
||||
goto out_ctx;
|
||||
}
|
||||
tc_prv_ctx->session_id = sess_arg.session;
|
||||
|
||||
ret = skcipher_alloc_shm(tc_prv_ctx,
|
||||
AES_BLOCK_SIZE + 2 * SZ_4K,
|
||||
AES_BLOCK_SIZE + 2 * TEE_CRYPT_INIT_MAX_BUF_SZ,
|
||||
&tc_prv_ctx->shm_pool_paddr);
|
||||
if (ret) {
|
||||
ret = -ENOMEM;
|
||||
goto out_ctx;
|
||||
}
|
||||
tc_prv_ctx->shm_pool = memremap(tc_prv_ctx->shm_pool_paddr,
|
||||
AES_BLOCK_SIZE + 2 * SZ_4K, MEMREMAP_WB);
|
||||
AES_BLOCK_SIZE + 2 * TEE_CRYPT_INIT_MAX_BUF_SZ,
|
||||
MEMREMAP_WB);
|
||||
if (!tc_prv_ctx->shm_pool) {
|
||||
ret = -EINVAL;
|
||||
goto out_ctx;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user