mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 19:08:57 +09:00
crypto: rockchip: Configure reserve block size based on CRYPTO version
CRYPTO_V2 : rk_hash_reserve_block = 128 CRYPTO_V3/V4 : rk_hash_reserve_block = 64 Signed-off-by: Troy Lin <troy.lin@rock-chips.com> Change-Id: I2a22d6084cb0f111f54c73939180fa7bbed29ef0
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "rk_crypto_core.h"
|
||||
#include "rk_crypto_ahash_utils.h"
|
||||
|
||||
uint32_t rk_hash_reserve_block = RK_HASH_RESERVE_BLOCK;
|
||||
|
||||
static const char * const hash_algo2name[] = {
|
||||
[HASH_ALGO_MD5] = "md5",
|
||||
[HASH_ALGO_SHA1] = "sha1",
|
||||
@@ -35,7 +37,7 @@ static void rk_ahash_ctx_clear(struct rk_ahash_ctx *ctx)
|
||||
{
|
||||
rk_alg_ctx_clear(&ctx->algs_ctx);
|
||||
|
||||
memset(ctx->hash_tmp, 0x00, RK_DMA_ALIGNMENT);
|
||||
memset(ctx->hash_tmp, 0x00, RK_HASH_RESERVE_BLOCK);
|
||||
memset(ctx->lastc, 0x00, sizeof(ctx->lastc));
|
||||
|
||||
ctx->hash_tmp_len = 0;
|
||||
@@ -81,13 +83,13 @@ static u32 rk_calc_lastc_new_len(u32 nbytes, u32 old_len)
|
||||
{
|
||||
u32 total_len = nbytes + old_len;
|
||||
|
||||
if (total_len <= RK_DMA_ALIGNMENT)
|
||||
if (total_len <= rk_hash_reserve_block)
|
||||
return nbytes;
|
||||
|
||||
if (total_len % RK_DMA_ALIGNMENT)
|
||||
return total_len % RK_DMA_ALIGNMENT;
|
||||
if (total_len % rk_hash_reserve_block)
|
||||
return total_len % rk_hash_reserve_block;
|
||||
|
||||
return RK_DMA_ALIGNMENT;
|
||||
return rk_hash_reserve_block;
|
||||
}
|
||||
|
||||
static int rk_ahash_fallback_digest(const char *alg_name, bool is_hmac,
|
||||
@@ -326,7 +328,7 @@ int rk_ahash_start(struct rk_crypto_dev *rk_dev)
|
||||
nbytes = ctx->hash_tmp_len + req->nbytes - ctx->lastc_len;
|
||||
|
||||
/* not enough data */
|
||||
if (nbytes < RK_DMA_ALIGNMENT) {
|
||||
if (nbytes < rk_hash_reserve_block) {
|
||||
CRYPTO_TRACE("nbytes = %u, not enough data", nbytes);
|
||||
memcpy(ctx->hash_tmp + ctx->hash_tmp_len,
|
||||
ctx->lastc, ctx->lastc_len);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "rk_crypto_core.h"
|
||||
#include "rk_crypto_utils.h"
|
||||
|
||||
extern uint32_t rk_hash_reserve_block;
|
||||
|
||||
struct rk_alg_ctx *rk_ahash_alg_ctx(struct rk_crypto_dev *rk_dev);
|
||||
|
||||
struct rk_crypto_algt *rk_ahash_get_algt(struct crypto_ahash *tfm);
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
#define RK_BUFFER_ORDER 3
|
||||
#define RK_BUFFER_SIZE (PAGE_SIZE << RK_BUFFER_ORDER)
|
||||
|
||||
#define RK_DMA_ALIGNMENT 128
|
||||
#define RK_HASH_RESERVE_BLOCK 128
|
||||
|
||||
#define sha384_state sha512_state
|
||||
#define sha224_state sha256_state
|
||||
|
||||
@@ -175,7 +176,7 @@ struct rk_ahash_ctx {
|
||||
bool hash_tmp_mapped;
|
||||
u32 calc_cnt;
|
||||
|
||||
u8 lastc[RK_DMA_ALIGNMENT];
|
||||
u8 lastc[RK_HASH_RESERVE_BLOCK];
|
||||
u32 lastc_len;
|
||||
|
||||
void *priv;
|
||||
|
||||
@@ -220,9 +220,9 @@ static int rk_ahash_dma_start(struct rk_crypto_dev *rk_dev, uint32_t flag)
|
||||
CRYPTO_TRACE("ctx->calc_cnt = %u, count %u Byte, is_final = %d",
|
||||
ctx->calc_cnt, alg_ctx->count, is_final);
|
||||
|
||||
if (alg_ctx->count % RK_DMA_ALIGNMENT && !is_final) {
|
||||
if (alg_ctx->count % rk_hash_reserve_block && !is_final) {
|
||||
dev_err(rk_dev->dev, "count = %u is not aligned with [%u]\n",
|
||||
alg_ctx->count, RK_DMA_ALIGNMENT);
|
||||
alg_ctx->count, rk_hash_reserve_block);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -313,12 +313,14 @@ static int rk_cra_hash_init(struct crypto_tfm *tfm)
|
||||
|
||||
CRYPTO_TRACE();
|
||||
|
||||
rk_hash_reserve_block = RK_HASH_RESERVE_BLOCK;
|
||||
|
||||
memset(ctx, 0x00, sizeof(*ctx));
|
||||
|
||||
if (!rk_dev->request_crypto)
|
||||
return -EFAULT;
|
||||
|
||||
alg_ctx->align_size = RK_DMA_ALIGNMENT;
|
||||
alg_ctx->align_size = 64;
|
||||
|
||||
alg_ctx->ops.start = rk_ahash_start;
|
||||
alg_ctx->ops.update = rk_ahash_crypto_rx;
|
||||
|
||||
@@ -300,9 +300,9 @@ static int rk_ahash_dma_start(struct rk_crypto_dev *rk_dev, uint32_t flag)
|
||||
CRYPTO_TRACE("ctx->calc_cnt = %u, count %u Byte, is_final = %d",
|
||||
ctx->calc_cnt, alg_ctx->count, is_final);
|
||||
|
||||
if (alg_ctx->count % RK_DMA_ALIGNMENT && !is_final) {
|
||||
if (alg_ctx->count % rk_hash_reserve_block && !is_final) {
|
||||
dev_err(rk_dev->dev, "count = %u is not aligned with [%u]\n",
|
||||
alg_ctx->count, RK_DMA_ALIGNMENT);
|
||||
alg_ctx->count, rk_hash_reserve_block);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -400,12 +400,14 @@ static int rk_cra_hash_init(struct crypto_tfm *tfm)
|
||||
|
||||
CRYPTO_TRACE();
|
||||
|
||||
rk_hash_reserve_block = 64;
|
||||
|
||||
memset(ctx, 0x00, sizeof(*ctx));
|
||||
|
||||
if (!rk_dev->request_crypto)
|
||||
return -EFAULT;
|
||||
|
||||
alg_ctx->align_size = RK_DMA_ALIGNMENT;
|
||||
alg_ctx->align_size = 64;
|
||||
|
||||
alg_ctx->ops.start = rk_ahash_start;
|
||||
alg_ctx->ops.update = rk_ahash_crypto_rx;
|
||||
|
||||
Reference in New Issue
Block a user