From: Zhiqi Song songzhiqi1@huawei.com
Support performance and function test for sm3-ce.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/Makefile.am | 1 + uadk_tool/benchmark/sec_uadk_benchmark.c | 22 +++++++++++++-- uadk_tool/benchmark/uadk_benchmark.c | 29 ++++++++++++-------- uadk_tool/benchmark/uadk_benchmark.h | 1 + uadk_tool/test/test_sec.c | 35 +++++++++++++++++++++--- 5 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am index 7f00087..6fa0d9d 100644 --- a/uadk_tool/Makefile.am +++ b/uadk_tool/Makefile.am @@ -29,6 +29,7 @@ uadk_tool_LDADD=$(libwd_la_OBJECTS) \ ../.libs/libhisi_sec.a \ ../.libs/libhisi_hpre.a \ ../.libs/libhisi_zip.a \ + ../.libs/libisa_ce.a \ -ldl -lnuma else uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \ diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 105fb1a..c3da616 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -679,6 +679,7 @@ static void uninit_ctx_config2(int subtype) wd_aead_uninit2(); break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: wd_digest_uninit2(); break; default: @@ -703,12 +704,23 @@ static int init_ctx_config2(struct acc_option *options) switch(subtype) { case CIPHER_TYPE: ret = wd_cipher_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + if (ret) + SEC_TST_PRT("failed to do cipher init2!\n"); break; case AEAD_TYPE: ret = wd_aead_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + if (ret) + SEC_TST_PRT("failed to do aead init2!\n"); break; case DIGEST_TYPE: ret = wd_digest_init2(alg_name, SCHED_POLICY_RR, TASK_HW); + if (ret) + SEC_TST_PRT("failed to do digest init2!\n"); + break; + case DIGEST_INSTR_TYPE: + ret = wd_digest_init2(alg_name, SCHED_POLICY_NONE, TASK_INSTR); + if (ret) + SEC_TST_PRT("failed to do digest intruction init2!\n"); break; } if (ret) { @@ -716,7 +728,7 @@ static int init_ctx_config2(struct acc_option *options) return ret; }
- return 0; + return ret; }
static void get_aead_data(u8 *addr, u32 size) @@ -1489,8 +1501,8 @@ static void *sec_uadk_digest_sync(void *arg) } } dreq.in_bytes = g_pktlen; - dreq.out_bytes = 16; - dreq.out_buf_bytes = 16; + dreq.out_bytes = 32; + dreq.out_buf_bytes = 32; dreq.data_fmt = 0; dreq.state = 0; dreq.has_next = 0; @@ -1536,8 +1548,12 @@ int sec_uadk_sync_threads(struct acc_option *options) uadk_sec_sync_run = sec_uadk_aead_sync; break; case DIGEST_TYPE: + case DIGEST_INSTR_TYPE: uadk_sec_sync_run = sec_uadk_digest_sync; break; + default: + SEC_TST_PRT("Invalid subtype!\n"); + return -EINVAL; }
for (i = 0; i < g_thread_num; i++) { diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 5dbe26a..9c025cf 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -37,6 +37,7 @@ enum test_type { SOFT_MODE = 0x4, SVA_SOFT = 0x5, NOSVA_SOFT = 0x6, + INSTR_MODE = 0x7, INVALID_MODE = 0x8, };
@@ -51,6 +52,7 @@ static struct acc_sva_item sys_name_item[] = { {"soft", SOFT_MODE}, {"sva-soft", SVA_SOFT}, {"nosva-soft", NOSVA_SOFT}, + {"instr", INSTR_MODE}, };
struct acc_alg_item { @@ -286,7 +288,7 @@ static int get_alg_type(const char *alg_name)
for (i = 0; i < ALG_MAX; i++) { if (strcmp(alg_name, alg_options[i].name) == 0) { - alg = alg_options[i].alg; + alg = alg_options[i].alg; break; } } @@ -482,8 +484,11 @@ static void parse_alg_param(struct acc_option *option) option->subtype = AEAD_TYPE; } else if (option->algtype <= SHA512_256) { snprintf(option->algclass, MAX_ALG_NAME, "%s", "digest"); + if (option->modetype == INSTR_MODE) + option->subtype = DIGEST_INSTR_TYPE; + else + option->subtype = DIGEST_TYPE; option->acctype = SEC_TYPE; - option->subtype = DIGEST_TYPE; } } } @@ -545,35 +550,35 @@ static int benchmark_run(struct acc_option *option)
switch(option->acctype) { case SEC_TYPE: - if (option->modetype & SVA_MODE) { + if ((option->modetype == SVA_MODE) || (option->modetype == INSTR_MODE)) { ret = sec_uadk_benchmark(option); - } else if (option->modetype & NOSVA_MODE) { + } else if (option->modetype == NOSVA_MODE) { ret = sec_wd_benchmark(option); } usleep(20000); #ifdef HAVE_CRYPTO - if (option->modetype & SOFT_MODE) { + if (option->modetype == SOFT_MODE) { ret = sec_soft_benchmark(option); } #endif break; case HPRE_TYPE: - if (option->modetype & SVA_MODE) { + if (option->modetype == SVA_MODE) { ret = hpre_uadk_benchmark(option); - } else if (option->modetype & NOSVA_MODE) { + } else if (option->modetype == NOSVA_MODE) { ret = hpre_wd_benchmark(option); } break; case ZIP_TYPE: - if (option->modetype & SVA_MODE) { + if (option->modetype == SVA_MODE) { ret = zip_uadk_benchmark(option); - } else if (option->modetype & NOSVA_MODE) { + } else if (option->modetype == NOSVA_MODE) { ret = zip_wd_benchmark(option); } case TRNG_TYPE: - if (option->modetype & SVA_MODE) + if (option->modetype == SVA_MODE) ACC_TST_PRT("TRNG not support sva mode..\n"); - else if (option->modetype & NOSVA_MODE) + else if (option->modetype == NOSVA_MODE) ret = trng_wd_benchmark(option);
break; @@ -698,7 +703,7 @@ static void print_help(void) ACC_TST_PRT("DESCRIPTION\n"); ACC_TST_PRT(" [--alg aes-128-cbc ]:\n"); ACC_TST_PRT(" The name of the algorithm for benchmarking\n"); - ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft]: start UADK or Warpdrive or Openssl mode test\n"); + ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft/instr]: start UADK or Warpdrive or Openssl or Instruction mode test\n"); ACC_TST_PRT(" [--sync/--async]: start asynchronous/synchronous mode test\n"); ACC_TST_PRT(" [--opt 0,1,2,3,4,5]:\n"); ACC_TST_PRT(" SEC/ZIP: 0/1:encryption/decryption or compression/decompression\n"); diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index fd3ebe5..e370d3e 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -104,6 +104,7 @@ enum alg_type { SM2_TYPE, X25519_TYPE, X448_TYPE, + DIGEST_INSTR_TYPE, };
enum sync_type { diff --git a/uadk_tool/test/test_sec.c b/uadk_tool/test/test_sec.c index 16feaf0..87fc718 100644 --- a/uadk_tool/test/test_sec.c +++ b/uadk_tool/test/test_sec.c @@ -32,7 +32,7 @@ #define SCHED_SINGLE "sched_single" #define SCHED_NULL_CTX_SIZE 4 #define TEST_WORD_LEN 4096 -#define MAX_ALGO_PER_TYPE 16 +#define MAX_ALGO_PER_TYPE 17 #define MIN_SVA_BD_NUM 1 #define AES_KEYSIZE_128 16 #define AES_KEYSIZE_192 24 @@ -83,6 +83,8 @@ enum digest_type { LOCAL_AES_GMAC_192, LOCAL_AES_GMAC_256, LOCAL_AES_XCBC_MAC_96, + LOCAL_AES_XCBC_PRF_128, + LOCAL_AES_CCM, };
char *digest_names[MAX_ALGO_PER_TYPE] = { @@ -102,6 +104,7 @@ char *digest_names[MAX_ALGO_PER_TYPE] = { "xcbc-mac-96(aes)", "xcbc-prf-128(aes)", "ccm(aes)", /* --digest 15: for error alg test */ + "sm3-ce", };
char *aead_names[MAX_ALGO_PER_TYPE] = { @@ -1464,11 +1467,14 @@ static int digest_init2(int type, int mode) { struct wd_ctx_params cparams = {0}; struct wd_ctx_nums *ctx_set_num; + char *alg_name; int ret;
if (g_testalg >= MAX_ALGO_PER_TYPE) return -WD_EINVAL;
+ alg_name = digest_names[g_testalg]; + ctx_set_num = calloc(1, sizeof(*ctx_set_num)); if (!ctx_set_num) { WD_ERR("failed to alloc ctx_set_size!\n"); @@ -1492,7 +1498,10 @@ static int digest_init2(int type, int mode) if (mode == CTX_MODE_ASYNC) ctx_set_num->async_ctx_num = g_ctxnum;
- ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams); + if (!strcmp(alg_name, "sm3-ce")) + ret = wd_digest_init2("sm3", SCHED_POLICY_NONE, TASK_INSTR); + else + ret = wd_digest_init2_(digest_names[g_testalg], 0, 0, &cparams); if (ret) goto out_freebmp;
@@ -1780,7 +1789,22 @@ int get_digest_resource(struct hash_testvec **alg_tv, int* alg, int* mode) tv->dsize = 16; alg_type = WD_DIGEST_AES_XCBC_PRF_128; break; - + case 16: /* SM3-CE */ + switch (g_alg_op_type) { + case 0: + mode_type = WD_DIGEST_NORMAL; + SEC_TST_PRT("test alg: %s\n", "normal(sm3-ce)"); + tv = &sm3_tv_template[0]; + break; + case 1: + mode_type = WD_DIGEST_HMAC; + SEC_TST_PRT("test alg: %s\n", "hmac(sm3-ce)"); + tv = &hmac_sm3_tv_template[0]; + break; + } + tv->dsize = 32; + alg_type = WD_DIGEST_SM3; + break; default: SEC_TST_PRT("keylenth error, default test alg: %s\n", "normal(sm3)"); return -EINVAL; @@ -4229,7 +4253,7 @@ static void print_help(void) SEC_TST_PRT(" 4 : SHA224; 5 : SHA384; 6 : SHA512; 7 : SHA512_224\n"); SEC_TST_PRT(" 8 : SHA512_256; 9 : AES_CMAC; 10 : AES_GMAC_128\n"); SEC_TST_PRT(" 11 : AES_GMAC_192; 12 : AES_GMAC_256; 13 : AES_XCBC_MAC_96\n"); - SEC_TST_PRT(" 14 : AES_XCBC_PRF_128\n"); + SEC_TST_PRT(" 14 : AES_XCBC_PRF_128; 15 : SM3-CE\n"); SEC_TST_PRT(" [--aead ]:\n"); SEC_TST_PRT(" specify symmetric aead algorithm\n"); SEC_TST_PRT(" 0 : AES-CCM; 1 : AES-GCM; 2 : Hmac(sha256),cbc(aes)\n"); @@ -4257,6 +4281,9 @@ static void print_help(void) SEC_TST_PRT(" set the steam mode for digest\n"); SEC_TST_PRT(" [--sglnum]:\n"); SEC_TST_PRT(" the number of scatterlist number used by the entire test task\n"); + SEC_TST_PRT(" [--init]:\n"); + SEC_TST_PRT(" 1: use init API of uadk\n"); + SEC_TST_PRT(" 2: use init2 API of uadk\n"); SEC_TST_PRT(" [--help] = usage\n"); SEC_TST_PRT("Example\n"); SEC_TST_PRT(" ./uadk_tool test --m sec --cipher 0 --sync --optype 0\n");