libwd/0053-uadk_tool-fix-hpre-test-code-issues.patch
2023-11-23 10:41:04 +08:00

453 lines
14 KiB
Diff

From 9a0b4eba99f8390bcfe6d594afb159dac4c53355 Mon Sep 17 00:00:00 2001
From: Weili Qian <qianweili@huawei.com>
Date: Fri, 10 Nov 2023 11:52:22 +0800
Subject: [PATCH 53/85] uadk_tool: fix hpre test code issues
1.Change the ECC_CURVE_ID to 2 for secp256k1 test.
2.Increase the block size for the nosva test.
3.Modify the sample data of ecdsa 256 verify.
4.Queues on multiple devices can be obtained.
Signed-off-by: Weili Qian <qianweili@huawei.com>
---
uadk_tool/benchmark/hpre_protocol_data.h | 77 ++++++++++++++--
uadk_tool/benchmark/hpre_uadk_benchmark.c | 107 ++++++++++++++++++----
uadk_tool/benchmark/hpre_wd_benchmark.c | 80 ++++++++++------
3 files changed, 210 insertions(+), 54 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_protocol_data.h b/uadk_tool/benchmark/hpre_protocol_data.h
index 9c92138..7bdb942 100644
--- a/uadk_tool/benchmark/hpre_protocol_data.h
+++ b/uadk_tool/benchmark/hpre_protocol_data.h
@@ -1292,8 +1292,9 @@ static unsigned char ecc_except_kinv_secp256k1[] = {
};
static unsigned char ecc_except_e_secp256k1[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04
+ 0x3a, 0x10, 0x3a, 0x4e, 0x57, 0x29, 0xad, 0x68, 0xc0, 0x2a, 0x67, 0x8a,
+ 0xe3, 0x9a, 0xcc, 0xfb, 0xc0, 0xae, 0x20, 0x80, 0x96, 0x43, 0x74, 0x01,
+ 0xb7, 0xce, 0xab, 0x63, 0xcc, 0xa0, 0x62, 0x2f
};
static unsigned char ecc_cp_sign_secp256k1[] = {
@@ -1649,19 +1650,75 @@ static unsigned char sm2_ciphertext_l[609] = {
static unsigned char sm2_pubkey[] = {
0x04,
- 0x09, 0xf9, 0xdf, 0x31, 0x1e, 0x54, 0x21, 0xa1, 0x50, 0xdd, 0x7d, 0x16, 0x1e, 0x4b, 0xc5, 0xc6,
- 0x72, 0x17, 0x9f, 0xad, 0x18, 0x33, 0xfc, 0x07, 0x6b, 0xb0, 0x8f, 0xf3, 0x56, 0xf3, 0x50, 0x20,
- 0xcc, 0xea, 0x49, 0x0c, 0xe2, 0x67, 0x75, 0xa5, 0x2d, 0xc6, 0xea, 0x71, 0x8c, 0xc1, 0xaa, 0x60,
- 0x0a, 0xed, 0x05, 0xfb, 0xf3, 0x5e, 0x08, 0x4a, 0x66, 0x32, 0xf6, 0x07, 0x2d, 0xa9, 0xad, 0x13
+ 0x09, 0xf9, 0xdf, 0x31, 0x1e, 0x54, 0x21, 0xa1, 0x50, 0xdd, 0x7d, 0x16,
+ 0x1e, 0x4b, 0xc5, 0xc6, 0x72, 0x17, 0x9f, 0xad, 0x18, 0x33, 0xfc, 0x07,
+ 0x6b, 0xb0, 0x8f, 0xf3, 0x56, 0xf3, 0x50, 0x20,
+ 0xcc, 0xea, 0x49, 0x0c, 0xe2, 0x67, 0x75, 0xa5, 0x2d, 0xc6, 0xea, 0x71,
+ 0x8c, 0xc1, 0xaa, 0x60, 0x0a, 0xed, 0x05, 0xfb, 0xf3, 0x5e, 0x08, 0x4a,
+ 0x66, 0x32, 0xf6, 0x07, 0x2d, 0xa9, 0xad, 0x13
};
static unsigned char sm2_priv[] = {
- 0x39, 0x45, 0x20, 0x8f, 0x7b, 0x21, 0x44, 0xb1, 0x3f, 0x36, 0xe3, 0x8a, 0xc6, 0xd3, 0x9f, 0x95,
- 0x88, 0x93, 0x93, 0x69, 0x28, 0x60, 0xb5, 0x1a, 0x42, 0xfb, 0x81, 0xef, 0x4d, 0xf7, 0xc5, 0xb8
+ 0x39, 0x45, 0x20, 0x8f, 0x7b, 0x21, 0x44, 0xb1, 0x3f, 0x36, 0xe3, 0x8a,
+ 0xc6, 0xd3, 0x9f, 0x95, 0x88, 0x93, 0x93, 0x69, 0x28, 0x60, 0xb5, 0x1a,
+ 0x42, 0xfb, 0x81, 0xef, 0x4d, 0xf7, 0xc5, 0xb8
};
static unsigned char sm2_digest[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
+ 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74
+};
+
+static char ecdsa_verf_p_secp256k1[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+};
+
+static char ecdsa_verf_a_secp256k1[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC
+};
+
+static char ecdsa_verf_b_secp256k1[] = {
+ 0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7, 0xB3, 0xEB, 0xBD, 0x55,
+ 0x76, 0x98, 0x86, 0xBC, 0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6,
+ 0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B
+};
+
+static char ecdsa_verf_g_secp256k1[] = {
+ 0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47, 0xF8, 0xBC, 0xE6, 0xE5,
+ 0x63, 0xA4, 0x40, 0xF2, 0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
+ 0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96,
+ 0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B, 0x8E, 0xE7, 0xEB, 0x4A,
+ 0x7C, 0x0F, 0x9E, 0x16, 0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE,
+ 0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5
+};
+
+static char ecdsa_verf_n_secp256k1[] = {
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF, 0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
+ 0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
+};
+
+static char ecdsa_verf_sign_secp256k1[] = {
+ 0x31, 0x28, 0x18, 0x0d, 0x19, 0x7c, 0xd1, 0xa5, 0xcb, 0x32, 0x95, 0x98,
+ 0xb6, 0x5f, 0x8c, 0xb8, 0xdf, 0x0b, 0x4e, 0xf3, 0xef, 0x5e, 0x22, 0x79,
+ 0x7f, 0xe0, 0xdb, 0xf0, 0x33, 0x59, 0x67, 0x01,
+ 0xeb, 0xd1, 0xca, 0x09, 0x55, 0x6a, 0xbe, 0xd5, 0x32, 0x34, 0xfb, 0xb2,
+ 0x4f, 0xfc, 0x7d, 0xa3, 0xd1, 0x6d, 0xc9, 0x65, 0x30, 0xca, 0x76, 0x3b,
+ 0x09, 0xd5, 0xef, 0x6a, 0x65, 0x05, 0x0d, 0x23
+};
+
+static char ecdh_verf_pubkey_secp256k1[] = {
+ 0x04,
+ 0xab, 0xd2, 0xd9, 0xec, 0x43, 0x60, 0xcc, 0x5b, 0x23, 0x5a, 0x80, 0x74,
+ 0x2e, 0xbc, 0xb8, 0x36, 0x27, 0xe7, 0xb5, 0x4f, 0x72, 0xc3, 0x4a, 0x05,
+ 0xe9, 0x70, 0x5a, 0x12, 0x8f, 0xab, 0x95, 0x7c,
+ 0x6b, 0xf1, 0x84, 0x92, 0x46, 0x7b, 0x81, 0x4e, 0x28, 0x83, 0x25, 0xfb,
+ 0x1f, 0x60, 0xe9, 0x98, 0xb6, 0x9f, 0xa0, 0xf4, 0x50, 0x3f, 0xa4, 0x1d,
+ 0x4a, 0x4d, 0x87, 0xb8, 0xe6, 0xe4, 0x81, 0xd4
};
#endif
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c
index e3372fb..ffa1a85 100644
--- a/uadk_tool/benchmark/hpre_uadk_benchmark.c
+++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c
@@ -346,30 +346,40 @@ static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options
static int init_hpre_ctx_config(char *alg, int subtype, int mode)
{
- struct uacce_dev_list *list;
struct sched_params param;
- int i, max_node;
+ struct uacce_dev *dev;
+ int max_node;
int ret = 0;
+ int i = 0;
max_node = numa_max_node() + 1;
if (max_node <= 0)
return -EINVAL;
- list = wd_get_accel_list(alg);
- if (!list) {
- HPRE_TST_PRT("failed to get %s device\n", alg);
- return -ENODEV;
- }
memset(&g_ctx_cfg, 0, sizeof(struct wd_ctx_config));
g_ctx_cfg.ctx_num = g_ctxnum;
g_ctx_cfg.ctxs = calloc(g_ctxnum, sizeof(struct wd_ctx));
if (!g_ctx_cfg.ctxs)
return -ENOMEM;
- for (i = 0; i < g_ctxnum; i++) {
- g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(list->dev);
- g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
- g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ while (i < g_ctxnum) {
+ dev = wd_get_accel_dev(alg);
+ if (!dev) {
+ HPRE_TST_PRT("failed to get %s device\n", alg);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ for (; i < g_ctxnum; i++) {
+ g_ctx_cfg.ctxs[i].ctx = wd_request_ctx(dev);
+ if (!g_ctx_cfg.ctxs[i].ctx)
+ break;
+
+ g_ctx_cfg.ctxs[i].op_type = 0; // default op_type
+ g_ctx_cfg.ctxs[i].ctx_mode = (__u8)mode;
+ }
+
+ free(dev);
}
switch(subtype) {
@@ -395,12 +405,8 @@ static int init_hpre_ctx_config(char *alg, int subtype, int mode)
goto out;
}
- /* If there is no numa, we defualt config to zero */
- if (list->dev->numa_id < 0)
- list->dev->numa_id = 0;
-
g_sched->name = SCHED_SINGLE;
- param.numa_id = list->dev->numa_id;
+ param.numa_id = 0;
param.type = 0;
param.mode = mode;
param.begin = 0;
@@ -434,10 +440,11 @@ static int init_hpre_ctx_config(char *alg, int subtype, int mode)
goto out;
}
- wd_free_list_accels(list);
-
return 0;
out:
+ for (i = i - 1; i >= 0; i--)
+ wd_release_ctx(g_ctx_cfg.ctxs[i].ctx);
+
free(g_ctx_cfg.ctxs);
wd_sched_rr_release(g_sched);
@@ -1964,6 +1971,38 @@ del_ecc_out:
return ret;
}
+static void fill_ecc_param_data(struct wd_ecc_curve *ecc_pa,
+ struct hpre_ecc_setup *ecc_set,
+ u32 key_bits)
+{
+ u32 key_size = (key_bits + 7) / 8;
+
+ ecc_pa->a.data = ecdsa_verf_a_secp256k1;
+ ecc_pa->b.data = ecdsa_verf_b_secp256k1;
+ ecc_pa->p.data = ecdsa_verf_p_secp256k1;
+ ecc_pa->n.data = ecdsa_verf_n_secp256k1;
+ ecc_pa->g.x.data = ecdsa_verf_g_secp256k1;
+ ecc_pa->g.y.data = ecdsa_verf_g_secp256k1 + key_size;
+
+ ecc_set->sign = ecdsa_verf_sign_secp256k1;
+ ecc_set->sign_size = sizeof(ecdsa_verf_sign_secp256k1);
+ ecc_set->pub_key = ecdh_verf_pubkey_secp256k1;
+ ecc_set->pub_key_size = sizeof(ecdh_verf_pubkey_secp256k1);
+
+ ecc_pa->a.bsize = key_size;
+ ecc_pa->a.dsize = key_size;
+ ecc_pa->b.bsize = key_size;
+ ecc_pa->b.dsize = key_size;
+ ecc_pa->p.bsize = key_size;
+ ecc_pa->p.dsize = key_size;
+ ecc_pa->n.bsize = key_size;
+ ecc_pa->n.dsize = key_size;
+ ecc_pa->g.x.bsize = key_size;
+ ecc_pa->g.x.dsize = key_size;
+ ecc_pa->g.y.bsize = key_size;
+ ecc_pa->g.y.dsize = key_size;
+}
+
static void *ecc_uadk_sync_run(void *arg)
{
thread_data *pdata = (thread_data *)arg;
@@ -1971,6 +2010,8 @@ static void *ecc_uadk_sync_run(void *arg)
u32 subtype = pdata->subtype;
struct wd_ecc_sess_setup sess_setup;
struct hpre_ecc_setup setup;
+ struct wd_ecc_curve_cfg cfg;
+ struct wd_ecc_curve cv;
struct wd_ecc_curve param;
struct wd_ecc_key *ecc_key;
struct wd_ecc_point pbk;
@@ -2015,6 +2056,12 @@ static void *ecc_uadk_sync_run(void *arg)
case ECDSA_TYPE:
sess_setup.alg = "ecdsa";
break;
+ case X448_TYPE:
+ sess_setup.alg = "x448";
+ break;
+ case X25519_TYPE:
+ sess_setup.alg = "x25519";
+ break;
}
// set def setting;
@@ -2025,6 +2072,14 @@ static void *ecc_uadk_sync_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_param_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WD_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ sess_setup.cv = cfg;
+ }
+
h_sess = wd_ecc_alloc_sess(&sess_setup);
if (!h_sess)
goto msg_release;
@@ -2113,6 +2168,8 @@ static void *ecc_uadk_async_run(void *arg)
struct wd_ecc_sess_setup sess_setup;
struct rsa_async_tag *tag;
struct hpre_ecc_setup setup;
+ struct wd_ecc_curve_cfg cfg;
+ struct wd_ecc_curve cv;
struct wd_ecc_curve param;
struct wd_ecc_key *ecc_key;
struct wd_ecc_point pbk;
@@ -2158,6 +2215,12 @@ static void *ecc_uadk_async_run(void *arg)
case ECDSA_TYPE:
sess_setup.alg = "ecdsa";
break;
+ case X448_TYPE:
+ sess_setup.alg = "x448";
+ break;
+ case X25519_TYPE:
+ sess_setup.alg = "x25519";
+ break;
}
// set def setting;
@@ -2168,6 +2231,14 @@ static void *ecc_uadk_async_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_param_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WD_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ sess_setup.cv = cfg;
+ }
+
h_sess = wd_ecc_alloc_sess(&sess_setup);
if (!h_sess)
goto msg_release;
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c
index 2e23c95..67d57c6 100644
--- a/uadk_tool/benchmark/hpre_wd_benchmark.c
+++ b/uadk_tool/benchmark/hpre_wd_benchmark.c
@@ -12,7 +12,7 @@
#include "v1/wd_bmm.h"
#include "v1/wd_util.h"
-#define ECC_CURVE_ID 0x3 /* def set secp256k1 */
+#define ECC_CURVE_ID 0x2 /* def set secp256k1 */
#define HPRE_TST_PRT printf
#define ERR_OPTYPE 0xFF
#define SM2_DG_SZ 1024
@@ -403,33 +403,9 @@ static int hpre_wd_get_block(u32 algtype)
case DH_4096:
block_size = 8192;
break;
- case ECDH_256:
- block_size = 256;
- break;
- case ECDH_384:
- block_size = 384;
- break;
- case ECDH_521:
- block_size = 576;
- break;
- case ECDSA_256:
- block_size = 256;
- break;
- case ECDSA_384:
- block_size = 384;
- break;
- case ECDSA_521:
+ default:
block_size = 576;
break;
- case SM2_ALG:
- block_size = 4352;
- break;
- case X25519_ALG:
- block_size = 256;
- break;
- case X448_ALG:
- block_size = 384;
- break;
}
return block_size;
@@ -1759,6 +1735,38 @@ static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup,
return 0;
}
+static void fill_ecc_cv_data(struct wcrypto_ecc_curve *cv,
+ struct hpre_ecc_setup *ecc_setup,
+ u32 key_bits)
+{
+ u32 key_size = (key_bits + 7) / 8;
+
+ cv->a.data = ecdsa_verf_a_secp256k1;
+ cv->b.data = ecdsa_verf_b_secp256k1;
+ cv->p.data = ecdsa_verf_p_secp256k1;
+ cv->n.data = ecdsa_verf_n_secp256k1;
+ cv->g.x.data = ecdsa_verf_g_secp256k1;
+ cv->g.y.data = ecdsa_verf_g_secp256k1 + key_size;
+
+ ecc_setup->sign = ecdsa_verf_sign_secp256k1;
+ ecc_setup->sign_size = sizeof(ecdsa_verf_sign_secp256k1);
+ ecc_setup->pub_key = ecdh_verf_pubkey_secp256k1;
+ ecc_setup->pub_key_size = sizeof(ecdh_verf_pubkey_secp256k1);
+
+ cv->a.bsize = key_size;
+ cv->a.dsize = key_size;
+ cv->b.bsize = key_size;
+ cv->b.dsize = key_size;
+ cv->p.bsize = key_size;
+ cv->p.dsize = key_size;
+ cv->n.bsize = key_size;
+ cv->n.dsize = key_size;
+ cv->g.x.bsize = key_size;
+ cv->g.x.dsize = key_size;
+ cv->g.y.bsize = key_size;
+ cv->g.y.dsize = key_size;
+}
+
static int ecdsa_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata,
struct wcrypto_ecc_key *ecc_key, struct hpre_ecc_setup *setup,
thread_data *pdata)
@@ -2060,6 +2068,8 @@ static void *ecc_wd_sync_run(void *arg)
struct wcrypto_ecc_ctx_setup ctx_setup;
struct wcrypto_ecc_op_data opdata;
struct wcrypto_ecc_curve param;
+ struct wcrypto_ecc_curve_cfg cfg;
+ struct wcrypto_ecc_curve cv;
struct hpre_ecc_setup setup;
struct wcrypto_ecc_key *ecc_key;
struct wcrypto_ecc_point pbk;
@@ -2114,6 +2124,14 @@ static void *ecc_wd_sync_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_cv_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WCRYPTO_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ ctx_setup.cv = cfg;
+ }
+
ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup);
if (!ctx)
goto msg_release;
@@ -2208,6 +2226,8 @@ static void *ecc_wd_async_run(void *arg)
struct wcrypto_ecc_ctx_setup ctx_setup;
struct wcrypto_ecc_op_data opdata;
struct wcrypto_ecc_curve param;
+ struct wcrypto_ecc_curve_cfg cfg;
+ struct wcrypto_ecc_curve cv;
struct hpre_ecc_setup setup;
struct wcrypto_ecc_key *ecc_key;
struct wcrypto_ecc_point pbk;
@@ -2263,6 +2283,14 @@ static void *ecc_wd_async_run(void *arg)
if (ret)
return NULL;
+ if (subtype == ECDSA_TYPE && key_size == 32) {
+ fill_ecc_cv_data(&cv, &setup, pdata->keybits);
+
+ cfg.type = WCRYPTO_CV_CFG_PARAM;
+ cfg.cfg.pparam = &cv;
+ ctx_setup.cv = cfg;
+ }
+
ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup);
if (!ctx)
goto msg_release;
--
2.25.1