
From: lizhi <lizhi206@huawei.com> Upstream: Yes Bugfix or Feature: Bugfix DTS: DTS2024111417327 1. Add ecdh benchmark with secp256r1 curve 2. To diff with original mode, the new mode is named ecdh-256r1, adding 'r1' as suffix. Signed-off-by: lizhi <lizhi206@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 35 +++++++++++++++++++---- uadk_tool/benchmark/uadk_benchmark.c | 3 +- uadk_tool/benchmark/uadk_benchmark.h | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index bc0687da..44d513da 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -11,10 +11,12 @@ #include "include/wd_ecc.h" #include "include/wd_sched.h" -#define ECC_CURVE_ID 0x3 /* def set secp256k1 */ +#define ECC_CURVE_SECP256K1 0x3 /* def set with secp256k1 */ +#define ECC_CURVE_SECP256R1 0x7 /* optional set with secp256r1 */ #define HPRE_TST_PRT printf #define ERR_OPTYPE 0xFF #define SM2_DG_SZ 1024 +#define WD_SECP256R1 0x18 /* consistent with wd_ecc.c */ struct hpre_rsa_key_in { void *e; @@ -92,6 +94,7 @@ typedef struct uadk_thread_res { u32 kmode; u32 optype; u32 td_id; + u32 algtype; } thread_data; static struct wd_ctx_config g_ctx_cfg; @@ -217,6 +220,9 @@ static void get_ecc_param(u32 algtype, u32 *keysize) case ECDH_256: *keysize = 256; break; + case ECDH_256R1: + *keysize = 256; + break; case ECDH_384: *keysize = 384; break; @@ -337,6 +343,7 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options tddata->keybits = keysize; tddata->kmode = mode; tddata->optype = optype; + tddata->algtype = algtype; HPRE_TST_PRT("%s to run %s task!\n", options->algclass, alg_operations[options->optype]); @@ -1038,6 +1045,10 @@ static int get_ecc_curve(struct hpre_ecc_setup *setup, u32 cid) setup->nid = 716; setup->curve_id = WD_SECP521R1; break; + case 7: // secp256R1 + setup->nid = 415; + setup->curve_id = WD_SECP256R1; + break; default: HPRE_TST_PRT("failed to get ecc curve id!\n"); return -EINVAL; @@ -2253,7 +2264,7 @@ static void *ecc_uadk_sync_run(void *arg) struct wd_ecc_point pbk; struct wd_dtb prk; struct wd_ecc_req req; - u32 cid = ECC_CURVE_ID; + u32 cid; handle_t h_sess; u32 count = 0; int ret; @@ -2263,6 +2274,12 @@ static void *ecc_uadk_sync_run(void *arg) memset(&req, 0, sizeof(req)); memset(&setup, 0, sizeof(setup)); + + if (pdata->algtype == ECDH_256R1) + cid = ECC_CURVE_SECP256R1; + else + cid = ECC_CURVE_SECP256K1; + if (subtype != X448_TYPE && subtype != X25519_TYPE) { ret = get_ecc_curve(&setup, cid); if (ret) @@ -2271,7 +2288,7 @@ static void *ecc_uadk_sync_run(void *arg) sess_setup.key_bits = pdata->keybits; if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { - if (cid > ECC_CURVE_ID) { + if (cid > ECC_CURVE_SECP256R1) { sess_setup.cv.type = WD_CV_CFG_PARAM; get_ecc_key_param(¶m, pdata->keybits); sess_setup.cv.cfg.pparam = ¶m; @@ -2411,7 +2428,7 @@ static void *ecc_uadk_async_run(void *arg) struct wd_ecc_point pbk; struct wd_ecc_req req; struct wd_dtb prk; - u32 cid = ECC_CURVE_ID; + u32 cid; handle_t h_sess; int try_cnt = 0; u32 count = 0; @@ -2422,6 +2439,12 @@ static void *ecc_uadk_async_run(void *arg) memset(&req, 0, sizeof(req)); memset(&setup, 0, sizeof(setup)); + + if (pdata->algtype == ECDH_256R1) + cid = ECC_CURVE_SECP256R1; + else + cid = ECC_CURVE_SECP256K1; + if (subtype != X448_TYPE && subtype != X25519_TYPE) { ret = get_ecc_curve(&setup, cid); if (ret) @@ -2430,7 +2453,7 @@ static void *ecc_uadk_async_run(void *arg) sess_setup.key_bits = pdata->keybits; if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { - if (cid > ECC_CURVE_ID) { + if (cid > ECC_CURVE_SECP256R1) { sess_setup.cv.type = WD_CV_CFG_PARAM; get_ecc_key_param(¶m, pdata->keybits); sess_setup.cv.cfg.pparam = ¶m; @@ -2627,6 +2650,7 @@ static int hpre_uadk_sync_threads(struct acc_option *options) threads_args[i].keybits = threads_option.keybits; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; + threads_args[i].algtype = threads_option.algtype; ret = pthread_create(&tdid[i], NULL, uadk_hpre_sync_run, &threads_args[i]); if (ret) { HPRE_TST_PRT("Create sync thread fail!\n"); @@ -2703,6 +2727,7 @@ static int hpre_uadk_async_threads(struct acc_option *options) threads_args[i].keybits = threads_option.keybits; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; + threads_args[i].algtype = threads_option.algtype; ret = pthread_create(&tdid[i], NULL, uadk_hpre_async_run, &threads_args[i]); if (ret) { HPRE_TST_PRT("Create async thread fail!\n"); diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index e6cc2ddf..d8f9e7af 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -83,6 +83,7 @@ static struct acc_alg_item alg_options[] = { {"dh", "dh-3072", DH_3072}, {"dh", "dh-4096", DH_4096}, {"ecdh", "ecdh-256", ECDH_256}, + {"ecdh", "ecdh-256r1", ECDH_256R1}, {"ecdh", "ecdh-384", ECDH_384}, {"ecdh", "ecdh-521", ECDH_521}, {"ecdsa", "ecdsa-256", ECDSA_256}, @@ -632,7 +633,7 @@ void print_benchmark_help(void) ACC_TST_PRT(" specify numa nodes for cpu and memory\n"); 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(" The name of the algorithm for benchmarking, note that alg ecdh-256r1 means ecdh with secp256r1\n"); ACC_TST_PRT(" [--mode sva/nosva/soft/sva-soft/nosva-soft/instr/multibuff]: 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"); diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 39725724..81ab2cf3 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -135,6 +135,7 @@ enum test_alg { DH_3072, DH_4096, ECDH_256, // ecdh + ECDH_256R1, // ecdh with secp256r1 curve ECDH_384, ECDH_521, ECDSA_256, // ecdsa -- 2.33.0