*** BLURB HERE ***
Junchong Pan (1): uadk_tool: print help when empty parameters
Qi Tao (1): uadk: support appending tag for digest stream model
Wenkai Lin (7): uadk: fix for aead authsize check uadk: fix for aead auth key length uadk: fix for digest auth key length uadk: fix for ce key_len check uadk: fix for key address check uadk: fix for v1 aead authsize check uadk: fix for aead cbc mode authsize
drv/hisi_sec.c | 40 +++++++++++++------------- drv/isa_ce_sm3.c | 5 ---- uadk_tool/benchmark/uadk_benchmark.c | 6 ++-- uadk_tool/benchmark/uadk_benchmark.h | 1 + uadk_tool/uadk_tool.c | 10 ++++++- v1/drv/hisi_sec_udrv.c | 18 ++---------- v1/wd_aead.c | 41 ++++++++++++++++++++------- v1/wd_cipher.c | 2 +- v1/wd_digest.c | 42 ++++++++++++++++++++++------ v1/wd_digest.h | 19 +++++++++++-- wd_aead.c | 11 +++----- wd_digest.c | 12 ++++---- 12 files changed, 127 insertions(+), 80 deletions(-)
From: Wenkai Lin linwenkai6@hisilicon.com
When a combined algorithm is used, the authsize should not be 0, so add check for it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- wd_aead.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_aead.c b/wd_aead.c index 11fee5a6..c6c40374 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -263,7 +263,7 @@ int wd_aead_set_authsize(handle_t h_sess, __u16 authsize) return -WD_EINVAL; } } else { - if (sess->dalg >= WD_DIGEST_TYPE_MAX || + if (sess->dalg >= WD_DIGEST_TYPE_MAX || !authsize || authsize & (WD_AEAD_CCM_GCM_MAX - 1) || authsize > g_aead_mac_len[sess->dalg]) { WD_ERR("failed to check aead mac authsize, size = %u\n",
From: Wenkai Lin linwenkai6@hisilicon.com
According to the HMAC rfc, the auth key could be 0 bytes, so remove the wrong judgment.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_aead.c | 12 ++++++------ wd_aead.c | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c index 3ebe1899..f79c9d9c 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -387,14 +387,11 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len) { struct wcrypto_aead_ctx *ctxt = ctx;
- if (!ctx || !key) { - WD_ERR("input param is NULL!\n"); + if (!ctx || (key_len && !key)) { + WD_ERR("failed to check authenticate key param!\n"); return -WD_EINVAL; }
- if (key_len == 0) - goto err_key_len; - if (ctxt->setup.dalg > WCRYPTO_SHA256) { if (key_len > MAX_HMAC_KEY_SIZE) goto err_key_len; @@ -405,6 +402,9 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len)
ctxt->akey_bytes = key_len;
+ if (!key_len) + return WD_SUCCESS; + if (ctxt->setup.data_fmt == WD_SGL_BUF) wd_sgl_cp_from_pbuf(ctxt->akey, 0, key, key_len); else @@ -413,7 +413,7 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len) return WD_SUCCESS;
err_key_len: - WD_ERR("fail to check key length!\n"); + WD_ERR("failed to check authenticate key length, size = %u\n", key_len); return -WD_EINVAL; }
diff --git a/wd_aead.c b/wd_aead.c index c6c40374..9cf85d13 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -208,14 +208,11 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len) { struct wd_aead_sess *sess = (struct wd_aead_sess *)h_sess;
- if (unlikely(!key || !sess)) { + if (!sess || (key_len && !key)) { WD_ERR("failed to check authenticate key param!\n"); return -WD_EINVAL; }
- if (key_len == 0) - goto err_key_len; - /* * Here dalg only supports sha1, sha256, sha512, * and should check key length with different max length. @@ -229,7 +226,8 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len) }
sess->akey_bytes = key_len; - memcpy(sess->akey, key, key_len); + if (key_len) + memcpy(sess->akey, key, key_len);
return 0;
From: Wenkai Lin linwenkai6@hisilicon.com
According to the HMAC rfc, the auth key could be 0 bytes, so remove the wrong judgment.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_digest.c | 13 +++++++------ wd_digest.c | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/v1/wd_digest.c b/v1/wd_digest.c index 3d05688d..e26909d3 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -274,6 +274,10 @@ static int digest_hmac_key_check(enum wcrypto_digest_alg alg, __u16 key_len) } break; case WCRYPTO_SHA384 ... WCRYPTO_SHA512_256: + if (key_len > MAX_HMAC_KEY_SIZE) { + WD_ERR("failed to check alg %u key bytes, key_len = %u\n", alg, key_len); + return -WD_EINVAL; + } break; case WCRYPTO_AES_XCBC_MAC_96: case WCRYPTO_AES_XCBC_PRF_128: @@ -304,21 +308,18 @@ int wcrypto_set_digest_key(void *ctx, __u8 *key, __u16 key_len) struct wcrypto_digest_ctx *ctxt = ctx; int ret;
- if (!ctx || !key) { + if (!ctx || (key_len && !key)) { WD_ERR("%s(): input param err!\n", __func__); return -WD_EINVAL; }
- if (key_len == 0 || key_len > MAX_HMAC_KEY_SIZE) { - WD_ERR("%s: input key length err, key_len = %u!\n", __func__, key_len); - return -WD_EINVAL; - } - ret = digest_hmac_key_check(ctxt->setup.alg, key_len); if (ret) return ret;
ctxt->key_bytes = key_len; + if (!key_len) + return WD_SUCCESS;
if (ctxt->setup.data_fmt == WD_SGL_BUF) wd_sgl_cp_from_pbuf(ctxt->key, 0, key, key_len); diff --git a/wd_digest.c b/wd_digest.c index 4709a1c9..1851203c 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -158,14 +158,13 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) struct wd_digest_sess *sess = (struct wd_digest_sess *)h_sess; int ret;
- if (!key || !sess) { - WD_ERR("invalid: failed to check input param, sess or key is NULL!\n"); + if (!sess || (key_len && !key)) { + WD_ERR("invalid: digest session or key is NULL!\n"); return -WD_EINVAL; }
- if ((sess->alg <= WD_DIGEST_SHA224 && key_len > - MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 || - key_len > MAX_HMAC_KEY_SIZE) { + if ((sess->alg <= WD_DIGEST_SHA224 && key_len > MAX_HMAC_KEY_SIZE >> 1) || + key_len > MAX_HMAC_KEY_SIZE) { WD_ERR("failed to check digest key length, size = %u\n", key_len); return -WD_EINVAL; @@ -181,7 +180,8 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) }
sess->key_bytes = key_len; - memcpy(sess->key, key, key_len); + if (key_len) + memcpy(sess->key, key, key_len);
return 0; }
From: Wenkai Lin linwenkai6@hisilicon.com
The auth key could be 0 bytes, remove the wrong judgment.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/isa_ce_sm3.c | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index 54c2a9e7..4ad21705 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -293,11 +293,6 @@ static int do_hmac_sm3_ce(struct wd_digest_msg *msg, __u8 *out_hmac) /* Use last output as the iv in current cycle */ iv = msg->out;
- if (!key_len) { - WD_ERR("invalid hmac key_len is 0!\n"); - return -WD_EINVAL; - } - block_type = get_hash_block_type(msg); switch(block_type) { case HASH_SINGLE_BLOCK:
From: Wenkai Lin linwenkai6@hisilicon.com
The ctx key may be null if the user use the normal mode, it should return an error before copy data to the key.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_aead.c | 4 ++-- v1/wd_cipher.c | 2 +- v1/wd_digest.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c index f79c9d9c..87bd6acb 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -362,7 +362,7 @@ int wcrypto_set_aead_ckey(void *ctx, __u8 *key, __u16 key_len) struct wcrypto_aead_ctx *ctxt = ctx; int ret;
- if (!ctx || !key) { + if (!ctx || !ctxt->ckey || !key) { WD_ERR("input param is NULL!\n"); return -WD_EINVAL; } @@ -387,7 +387,7 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len) { struct wcrypto_aead_ctx *ctxt = ctx;
- if (!ctx || (key_len && !key)) { + if (!ctx || !ctxt->akey || (key_len && !key)) { WD_ERR("failed to check authenticate key param!\n"); return -WD_EINVAL; } diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index 57f10091..6dbdebc3 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -309,7 +309,7 @@ int wcrypto_set_cipher_key(void *ctx, __u8 *key, __u16 key_len) struct wcrypto_cipher_ctx *ctxt = ctx; int ret;
- if (!ctx || !key) { + if (!ctx || !ctxt->key || !key) { WD_ERR("%s: input param err!\n", __func__); return -WD_EINVAL; } diff --git a/v1/wd_digest.c b/v1/wd_digest.c index e26909d3..c02b3b30 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -308,7 +308,7 @@ int wcrypto_set_digest_key(void *ctx, __u8 *key, __u16 key_len) struct wcrypto_digest_ctx *ctxt = ctx; int ret;
- if (!ctx || (key_len && !key)) { + if (!ctx || !ctxt->key || (key_len && !key)) { WD_ERR("%s(): input param err!\n", __func__); return -WD_EINVAL; }
From: Wenkai Lin linwenkai6@hisilicon.com
First, move the algorithm check to the right level, then we modified the alignment to 4 bytes from 16 bytes according to the hardware specification.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/drv/hisi_sec_udrv.c | 18 ++---------------- v1/wd_aead.c | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index b8ba55b4..f1be25fb 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -2732,26 +2732,13 @@ static int aead_comb_param_check(struct wcrypto_aead_msg *msg) }
if (msg->cmode == WCRYPTO_CIPHER_CCM) { - if (unlikely(msg->auth_bytes < WORD_BYTES || - msg->auth_bytes > AES_BLOCK_SIZE || - msg->auth_bytes % (WORD_BYTES >> 1))) { - WD_ERR("Invalid aead ccm mode auth_bytes!\n"); - return -WD_EINVAL; - } if (unlikely(msg->assoc_bytes > MAX_CCM_AAD_LEN)) { WD_ERR("aead ccm mode aasoc_bytes is too long!\n"); return -WD_EINVAL; } return WD_SUCCESS; - } - if (msg->cmode == WCRYPTO_CIPHER_GCM) { - if (unlikely(msg->auth_bytes < U64_DATA_BYTES || - msg->auth_bytes > AES_BLOCK_SIZE)) { - WD_ERR("Invalid aead gcm mode auth_bytes!\n"); - return -WD_EINVAL; - } + } else if (msg->cmode == WCRYPTO_CIPHER_GCM) return WD_SUCCESS; - }
/* CCM/GCM support 0 in_bytes, but others not support */ if (unlikely(msg->in_bytes == 0)) { @@ -2759,8 +2746,7 @@ static int aead_comb_param_check(struct wcrypto_aead_msg *msg) return -WD_EINVAL; }
- if (unlikely(msg->auth_bytes != AES_BLOCK_SIZE && - msg->auth_bytes != AES_BLOCK_SIZE << 1)) { + if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) { WD_ERR("Invalid aead auth_bytes!\n"); return -WD_EINVAL; } diff --git a/v1/wd_aead.c b/v1/wd_aead.c index 87bd6acb..2b98547f 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -28,6 +28,8 @@
#define MAX_AEAD_AUTH_SIZE 64 #define MAX_AEAD_RETRY_CNT 20000000 +#define AEAD_CCM_GCM_MIN 4U +#define AEAD_CCM_GCM_MAX 16
static int g_aead_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = { WCRYPTO_SM3_LEN, WCRYPTO_MD5_LEN, WCRYPTO_SHA1_LEN, @@ -283,9 +285,28 @@ int wcrypto_aead_setauthsize(void *ctx, __u16 authsize) return -WD_EINVAL; }
- if (authsize > MAX_AEAD_AUTH_SIZE) { - WD_ERR("fail to check authsize!\n"); - return -WD_EINVAL; + if (ctxt->setup.cmode == WCRYPTO_CIPHER_CCM) { + if (authsize < AEAD_CCM_GCM_MIN || + authsize > AEAD_CCM_GCM_MAX || + authsize % (AEAD_CCM_GCM_MIN >> 1)) { + WD_ERR("failed to check aead CCM authsize, size = %u\n", + authsize); + return -WD_EINVAL; + } + } else if (ctxt->setup.cmode == WCRYPTO_CIPHER_GCM) { + if (authsize < AEAD_CCM_GCM_MIN << 1 || + authsize > AEAD_CCM_GCM_MAX) { + WD_ERR("failed to check aead GCM authsize, size = %u\n", + authsize); + return -WD_EINVAL; + } + } else { + if (ctxt->setup.dalg >= WCRYPTO_MAX_DIGEST_TYPE || !authsize || + authsize > g_aead_mac_len[ctxt->setup.dalg]) { + WD_ERR("failed to check aead mac authsize, size = %u\n", + authsize); + return -WD_EINVAL; + } }
ctxt->auth_size = authsize;
From: Wenkai Lin linwenkai6@hisilicon.com
The alignment of authsize should be 4 bytes not 16 bytes according to the hardware specification.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_sec.c | 40 +++++++++++++++++++--------------------- wd_aead.c | 1 - 2 files changed, 19 insertions(+), 22 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 473d4b1a..7f4ae109 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -15,7 +15,7 @@ #define SEC_DIGEST_ALG_OFFSET 11 #define WORD_ALIGNMENT_MASK 0x3 #define CTR_MODE_LEN_SHIFT 4 -#define WORD_BYTES 4 +#define BYTES_TO_WORDS(bcount) ((bcount) >> 2) #define BYTE_BITS 8 #define SQE_BYTES_NUMS 128 #define SEC_FLAG_OFFSET 7 @@ -34,7 +34,6 @@ #define SEC_CMODE_OFFSET 12 #define SEC_CKEY_OFFSET 9 #define SEC_CIPHER_OFFSET 4 -#define XTS_MODE_KEY_DIVISOR 2 #define SEC_CTR_CNT_OFFSET 25 #define SEC_CTR_CNT_ROLLOVER 2
@@ -834,7 +833,7 @@ static int get_aes_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len)
len = msg->key_bytes; if (msg->mode == WD_CIPHER_XTS) - len = len / XTS_MODE_KEY_DIVISOR; + len = len >> 1;
switch (len) { case AES_KEYSIZE_128: @@ -1489,7 +1488,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, * the output full length. */ if (!msg->has_next) - sqe->type2.mac_key_alg = msg->out_bytes / WORD_BYTES; + sqe->type2.mac_key_alg = BYTES_TO_WORDS(msg->out_bytes);
/* SM3 can't config 0 in normal mode */ if (msg->has_next && msg->mode == WD_DIGEST_NORMAL && @@ -1508,8 +1507,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, msg->key_bytes); return -WD_EINVAL; } - sqe->type2.mac_key_alg |= (__u32)(msg->key_bytes / - WORD_BYTES) << MAC_LEN_OFFSET; + sqe->type2.mac_key_alg |= (__u32)BYTES_TO_WORDS(msg->key_bytes) << MAC_LEN_OFFSET; sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->key;
sqe->type2.mac_key_alg |= @@ -1836,8 +1834,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, * the output full length. */ if (!msg->has_next) - sqe->auth_mac_key |= (msg->out_bytes / WORD_BYTES) << - SEC_MAC_OFFSET_V3; + sqe->auth_mac_key |= BYTES_TO_WORDS(msg->out_bytes) << SEC_MAC_OFFSET_V3;
/* SM3 can't config 0 in normal mode */ if (msg->has_next && msg->mode == WD_DIGEST_NORMAL && @@ -1857,8 +1854,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, if (ret) return ret;
- sqe->auth_mac_key |= (__u32)(msg->key_bytes / - WORD_BYTES) << SEC_AKEY_OFFSET_V3; + sqe->auth_mac_key |= (__u32)BYTES_TO_WORDS(msg->key_bytes) << SEC_AKEY_OFFSET_V3; sqe->a_key_addr = (__u64)(uintptr_t)msg->key; sqe->auth_mac_key |= g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; @@ -2094,7 +2090,7 @@ static int aead_get_aes_key_len(struct wd_aead_msg *msg, __u8 *key_len) return 0; }
-static int aead_akey_len_check(struct wd_aead_msg *msg) +static int aead_auth_spec_check(struct wd_aead_msg *msg) { if (unlikely(msg->akey_bytes & WORD_ALIGNMENT_MASK)) { WD_ERR("failed to check aead auth key bytes, size = %u\n", @@ -2102,6 +2098,12 @@ static int aead_akey_len_check(struct wd_aead_msg *msg) return -WD_EINVAL; }
+ if (unlikely(msg->auth_bytes & WORD_ALIGNMENT_MASK)) { + WD_ERR("failed to check aead auth bytes, size = %u\n", + msg->auth_bytes); + return -WD_EINVAL; + } + return 0; }
@@ -2130,14 +2132,12 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg, if (msg->cmode == WD_CIPHER_CCM || msg->cmode == WD_CIPHER_GCM) return ret;
- sqe->type2.mac_key_alg = msg->auth_bytes / WORD_BYTES; - - ret = aead_akey_len_check(msg); + ret = aead_auth_spec_check(msg); if (ret) return ret;
- sqe->type2.mac_key_alg |= (__u32)(msg->akey_bytes / - WORD_BYTES) << MAC_LEN_OFFSET; + sqe->type2.mac_key_alg = BYTES_TO_WORDS(msg->auth_bytes); + sqe->type2.mac_key_alg |= (__u32)BYTES_TO_WORDS(msg->akey_bytes) << MAC_LEN_OFFSET;
switch (msg->dalg) { case WD_DIGEST_SHA1: @@ -2736,15 +2736,13 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg, if (msg->cmode == WD_CIPHER_CCM || msg->cmode == WD_CIPHER_GCM) return ret;
- ret = aead_akey_len_check(msg); + ret = aead_auth_spec_check(msg); if (ret) return ret;
- sqe->auth_mac_key |= (msg->auth_bytes / - WORD_BYTES) << SEC_MAC_OFFSET_V3; + sqe->auth_mac_key |= BYTES_TO_WORDS(msg->auth_bytes) << SEC_MAC_OFFSET_V3;
- sqe->auth_mac_key |= (msg->akey_bytes / - WORD_BYTES) << SEC_AKEY_OFFSET_V3; + sqe->auth_mac_key |= (__u32)BYTES_TO_WORDS(msg->akey_bytes) << SEC_AKEY_OFFSET_V3;
switch (msg->dalg) { case WD_DIGEST_SHA1: diff --git a/wd_aead.c b/wd_aead.c index 9cf85d13..2715e910 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -262,7 +262,6 @@ int wd_aead_set_authsize(handle_t h_sess, __u16 authsize) } } else { if (sess->dalg >= WD_DIGEST_TYPE_MAX || !authsize || - authsize & (WD_AEAD_CCM_GCM_MAX - 1) || authsize > g_aead_mac_len[sess->dalg]) { WD_ERR("failed to check aead mac authsize, size = %u\n", authsize);
From: Junchong Pan panjunchong@h-partners.com
Add print help when dfx/benchmark/test input empty parameters.
Signed-off-by: Junchong Pan panjunchong@h-partners.com --- uadk_tool/benchmark/uadk_benchmark.c | 6 +++--- uadk_tool/benchmark/uadk_benchmark.h | 1 + uadk_tool/uadk_tool.c | 10 +++++++++- 3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index dd2b22da..16980616 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -635,7 +635,7 @@ int acc_default_case(struct acc_option *option) return acc_benchmark_run(option); }
-static void print_help(void) +void print_benchmark_help(void) { ACC_TST_PRT("NAME\n"); ACC_TST_PRT(" benchmark: test UADK acc performance,etc\n"); @@ -728,7 +728,7 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option)
switch (c) { case 0: - print_help(); + print_benchmark_help(); goto to_exit; case 1: option->algtype = get_alg_type(optarg); @@ -791,7 +791,7 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) break; default: ACC_TST_PRT("invalid: bad input parameter!\n"); - print_help(); + print_benchmark_help(); goto to_exit; } } diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 0def4b9f..c4042355 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -225,5 +225,6 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option); int acc_default_case(struct acc_option *option); int acc_option_convert(struct acc_option *option); int acc_benchmark_run(struct acc_option *option); +void print_benchmark_help(void);
#endif /* UADK_BENCHMARK_H */ diff --git a/uadk_tool/uadk_tool.c b/uadk_tool/uadk_tool.c index 63e6d0f4..64d41630 100644 --- a/uadk_tool/uadk_tool.c +++ b/uadk_tool/uadk_tool.c @@ -22,11 +22,16 @@ int main(int argc, char **argv)
if (argc > index) { if (!strcmp("dfx", argv[index])) { + if (!argv[++index]) + print_dfx_help(); + dfx_cmd_parse(argc, argv); } else if (!strcmp("benchmark", argv[index])) { printf("start UADK benchmark test.\n"); - if (!argv[++index]) + if (!argv[++index]) { + print_benchmark_help(); acc_default_case(&option); + }
ret = acc_cmd_parse(argc, argv, &option); if (ret) @@ -37,6 +42,9 @@ int main(int argc, char **argv) return ret; (void)acc_benchmark_run(&option); } else if (!strcmp("test", argv[index])) { + if (!argv[++index]) + print_test_help(); + printf("start UADK acc algorithm test.\n"); acc_test_run(argc, argv); } else {
In common digest stream mode, io_bytes and iv_bytes need to be set to 0 when the final bd is calculated. Therefore, in the appending tag scenario, need to restore the values of io_bytes and iv_bytes to the values before they are set to 0.
Therefore, the hardware can compute the overall hash value of the appending packet and the previously calculated packet, and reduce the repeated calculation.
Signed-off-by: Qi Tao taoqi10@huawei.com --- v1/wd_digest.c | 29 +++++++++++++++++++++++++++-- v1/wd_digest.h | 19 +++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/v1/wd_digest.c b/v1/wd_digest.c index c02b3b30..1b665a34 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -445,7 +445,7 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, return -WD_EINVAL; }
- if (d_opdata[i]->has_next) + if (d_opdata[i]->has_next == WCRYPTO_DIGEST_DOING) ret = stream_mode_param_check(d_ctx, d_opdata[i], num); else ret = block_mode_param_check(d_ctx, d_opdata[i]); @@ -466,6 +466,24 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, return WD_SUCCESS; }
+static int append_tag_restore_status(struct wcrypto_digest_ctx *ctxt, + struct wcrypto_digest_op_data **opdata, + struct wcrypto_digest_msg **req, __u32 ind) +{ + if (opdata[ind]->has_next == WCRYPTO_DIGEST_STREAM_END) + opdata[ind]->has_next = WCRYPTO_DIGEST_END; + else if (opdata[ind]->has_next == WCRYPTO_DIGEST_STREAM_DOING) + opdata[ind]->has_next = WCRYPTO_DIGEST_DOING; + else + return -WD_EINVAL; + + ctxt->io_bytes = *(__u64 *)opdata[ind]->priv; + req[ind]->iv_bytes = opdata[ind]->out_bytes; + opdata[ind]->priv = NULL; + + return WD_SUCCESS; +} + int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata, void **tag, __u32 num) { @@ -483,8 +501,15 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata, return ret;
for (i = 0; i < num; i++) { - cookies[i]->tag.priv = opdata[i]->priv; req[i] = &cookies[i]->msg; + + if (opdata[i]->has_next > WCRYPTO_DIGEST_DOING) { + ret = append_tag_restore_status(ctxt, opdata, req, i); + if (unlikely(ret)) + goto fail_with_cookies; + } + + cookies[i]->tag.priv = opdata[i]->priv; if (tag) cookies[i]->tag.wcrypto_tag.tag = tag[i]; } diff --git a/v1/wd_digest.h b/v1/wd_digest.h index 9667a663..e325bffc 100644 --- a/v1/wd_digest.h +++ b/v1/wd_digest.h @@ -76,6 +76,21 @@ enum wcrypto_digest_mode { WCRYPTO_DIGEST_HMAC, };
+/** + * wcrypto_digest_msg_state - Message state of digest + * @WCRYPTO_DIGEST_END: Final message or single block message + * @WCRYPTO_DIGEST_DOING: First message or middle message + * @WCRYPTO_DIGEST_STREAM_END: Final message for appending tag mode + * @WCRYPTO_DIGEST_STREAM_DOING: Middle message for appending tag mode + */ +enum wcrypto_digest_msg_state { + WCRYPTO_DIGEST_END = 0x0, + WCRYPTO_DIGEST_DOING, + WCRYPTO_DIGEST_STREAM_END, + WCRYPTO_DIGEST_STREAM_DOING, + WCRYPTO_DIGEST_MSG_STATE_MAX, +}; + /** * different contexts for different users/threads * @cb: call back functions of user @@ -100,7 +115,7 @@ struct wcrypto_digest_ctx_setup { * @out_bytes:output data size * @priv:reserved data field segment * @status:I/O operation return status - * @has_next: is there next data block + * @has_next: message state, all types are defined in enum wcrypto_digest_msg_state * @iv: initialization verctor data address * @iv_bytes:initialization verctor data size */ @@ -111,7 +126,7 @@ struct wcrypto_digest_op_data { __u32 out_bytes; void *priv; int status; - bool has_next; + int has_next; void *iv; __u32 iv_bytes; };