1. Modify part of the repeated code macro. 2. Add new random number generation method. 3. Add new test parameters, support test algorithm query and address pre-step function.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/benchmark/sec_soft_benchmark.c | 7 +- uadk_tool/benchmark/sec_soft_benchmark.h | 1 - uadk_tool/benchmark/sec_uadk_benchmark.c | 65 ++++---- uadk_tool/benchmark/sec_wd_benchmark.c | 192 +++++++---------------- uadk_tool/benchmark/uadk_benchmark.c | 115 ++++++++------ uadk_tool/benchmark/uadk_benchmark.h | 20 ++- 6 files changed, 167 insertions(+), 233 deletions(-)
diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c index 2f6bccb..a622329 100644 --- a/uadk_tool/benchmark/sec_soft_benchmark.c +++ b/uadk_tool/benchmark/sec_soft_benchmark.c @@ -56,11 +56,8 @@ typedef struct soft_jobs_res { u32 use_engine; } jobs_data;
-#define MAX_POOL_LENTH 4096 #define MAX_IVK_LENTH 64 #define DEF_IVK_DATA 0xAA -#define MAX_TRY_CNT 5000 -#define SEND_USLEEP 100
static unsigned int g_thread_num; static unsigned int g_ctxnum; @@ -613,7 +610,7 @@ static void *sec_soft_async_run(void *arg) exit_pause: ASYNC_WAIT_CTX_free(waitctx);
- add_recv_data(count); + add_recv_data(count, g_pktlen);
return NULL; } @@ -802,7 +799,7 @@ static void *sec_soft_sync_run(void *arg) break; }
- add_recv_data(count); + add_recv_data(count, g_pktlen);
return NULL; } diff --git a/uadk_tool/benchmark/sec_soft_benchmark.h b/uadk_tool/benchmark/sec_soft_benchmark.h index 8331eb5..c1374d6 100644 --- a/uadk_tool/benchmark/sec_soft_benchmark.h +++ b/uadk_tool/benchmark/sec_soft_benchmark.h @@ -4,6 +4,5 @@
#include "uadk_benchmark.h"
- extern int sec_soft_benchmark(struct acc_option *options); #endif /* SEC_SOFT_BENCHMARK_H */ diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 6eeee12..09cd8f4 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -10,6 +10,8 @@ #include "include/wd_sched.h"
#define SEC_TST_PRT printf +#define MAX_IVK_LENTH 64 +#define DEF_IVK_DATA 0xAA
struct uadk_bd { u8 *src; @@ -37,18 +39,12 @@ typedef struct uadk_thread_res { u32 td_id; } thread_data;
-#define MAX_POOL_LENTH 4096 -#define MAX_IVK_LENTH 64 -#define DEF_IVK_DATA 0xAA -#define MAX_TRY_CNT 5000 -#define SEND_USLEEP 100 - static struct wd_ctx_config g_ctx_cfg; static struct wd_sched *g_sched; static unsigned int g_thread_num; static unsigned int g_ctxnum; +static unsigned int g_prefetch; static unsigned int g_pktlen; -static struct sched_params g_param;
static void *cipher_async_cb(struct wd_cipher_req *req, void *data) { @@ -349,6 +345,7 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) static int init_ctx_config(char *alg, int subtype, int mode) { struct uacce_dev_list *list; + struct sched_params param; int i, max_node; int ret = 0;
@@ -385,7 +382,7 @@ static int init_ctx_config(char *alg, int subtype, int mode) break; default: SEC_TST_PRT("Fail to parse alg subtype!\n"); - return -EINVAL; + goto out; } if (!g_sched) { SEC_TST_PRT("Fail to alloc sched!\n"); @@ -397,12 +394,12 @@ static int init_ctx_config(char *alg, int subtype, int mode) list->dev->numa_id = 0;
g_sched->name = SCHED_SINGLE; - g_param.numa_id = list->dev->numa_id; - g_param.type = 0; - g_param.mode = mode; - g_param.begin = 0; - g_param.end = g_ctxnum - 1; - ret = wd_sched_rr_instance(g_sched, &g_param); + param.numa_id = list->dev->numa_id; + param.type = 0; + param.mode = mode; + param.begin = 0; + param.end = g_ctxnum - 1; + ret = wd_sched_rr_instance(g_sched, ¶m); if (ret) { SEC_TST_PRT("Fail to fill sched data!\n"); goto out; @@ -419,6 +416,8 @@ static int init_ctx_config(char *alg, int subtype, int mode) case DIGEST_TYPE: ret = wd_digest_init(&g_ctx_cfg, g_sched); break; + default: + goto out; } if (ret) { SEC_TST_PRT("Fail to cipher ctx!\n"); @@ -461,18 +460,13 @@ static void uninit_ctx_config(int subtype) wd_sched_rr_release(g_sched); }
-int init_uadk_bd_pool(void) +static int init_uadk_bd_pool(void) { unsigned long step; - int fill_size; int i, j;
// make the block not align to 4K step = sizeof(char) * g_pktlen * 2; - if (g_pktlen > MAX_IVK_LENTH) - fill_size = MAX_IVK_LENTH; - else - fill_size = g_pktlen;
g_uadk_pool.iv = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char)); g_uadk_pool.key = malloc(g_thread_num * MAX_IVK_LENTH * sizeof(char)); @@ -498,7 +492,9 @@ int init_uadk_bd_pool(void) if (!g_uadk_pool.pool[i].bds[j].dst) goto malloc_error3;
- get_rand_data(g_uadk_pool.pool[i].bds[j].src, fill_size); + get_rand_data(g_uadk_pool.pool[i].bds[j].src, g_pktlen); + if (g_prefetch) + get_rand_data(g_uadk_pool.pool[i].bds[j].dst, g_pktlen); } } } @@ -526,12 +522,13 @@ malloc_error1:
free(g_uadk_pool.iv); free(g_uadk_pool.key); + free(g_uadk_pool.mac);
SEC_TST_PRT("init uadk bd pool alloc failed!\n"); return -ENOMEM; }
-void free_uadk_bd_pool(void) +static void free_uadk_bd_pool(void) { int i, j;
@@ -550,21 +547,22 @@ void free_uadk_bd_pool(void)
free(g_uadk_pool.iv); free(g_uadk_pool.key); + free(g_uadk_pool.mac); }
/*-------------------------------uadk benchmark main code-------------------------------------*/
-void *sec_uadk_poll(void *data) +static void *sec_uadk_poll(void *data) { typedef int (*poll_ctx)(__u32 idx, __u32 expt, __u32 *count); poll_ctx uadk_poll_ctx = NULL; thread_data *pdata = (thread_data *)data; u32 expt = ACC_QUEUE_SIZE * g_thread_num; u32 id = pdata->td_id; - u32 last_time = 2; /* poll need one more recv time */ + u32 last_time = 2; // poll need one more recv time u32 count = 0; u32 recv = 0; - int ret; + int ret;
if (id > g_ctxnum) return NULL; @@ -586,7 +584,6 @@ void *sec_uadk_poll(void *data)
while (last_time) { ret = uadk_poll_ctx(id, expt, &recv); - // SEC_TST_PRT("expt %u, poll %d recv: %u!\n", expt, i, recv); count += recv; recv = 0; if (unlikely(ret != -WD_EAGAIN && ret < 0)) { @@ -599,7 +596,7 @@ void *sec_uadk_poll(void *data) }
recv_error: - add_recv_data(count); + add_recv_data(count, g_pktlen);
return NULL; } @@ -636,7 +633,6 @@ static void *sec_uadk_async_run(void *arg) case CIPHER_TYPE: cipher_setup.alg = pdata->alg; cipher_setup.mode = pdata->mode; - cipher_setup.sched_param = (void *)&g_param; h_sess = wd_cipher_alloc_sess(&cipher_setup); if (!h_sess) return NULL; @@ -682,7 +678,6 @@ static void *sec_uadk_async_run(void *arg) case AEAD_TYPE: // just ccm and gcm aead_setup.calg = pdata->alg; aead_setup.cmode = pdata->mode; - aead_setup.sched_param = (void *)&g_param; h_sess = wd_aead_alloc_sess(&aead_setup); if (!h_sess) return NULL; @@ -740,7 +735,6 @@ static void *sec_uadk_async_run(void *arg) case DIGEST_TYPE: digest_setup.alg = pdata->alg; digest_setup.mode = pdata->mode; // digest mode is optype - digest_setup.sched_param = (void *)&g_param; h_sess = wd_digest_alloc_sess(&digest_setup); if (!h_sess) return NULL; @@ -820,7 +814,6 @@ static void *sec_uadk_sync_run(void *arg) case CIPHER_TYPE: cipher_setup.alg = pdata->alg; cipher_setup.mode = pdata->mode; - cipher_setup.sched_param = (void *)&g_param; h_sess = wd_cipher_alloc_sess(&cipher_setup); if (!h_sess) return NULL; @@ -845,7 +838,7 @@ static void *sec_uadk_sync_run(void *arg) creq.src = uadk_pool->bds[i].src; creq.dst = uadk_pool->bds[i].dst; ret = wd_do_cipher_sync(h_sess, &creq); - if (ret || creq.state) + if ((ret < 0 && ret != -WD_EBUSY) || creq.state) break; count++; if (get_run_state() == 0) @@ -856,7 +849,6 @@ static void *sec_uadk_sync_run(void *arg) case AEAD_TYPE: // just ccm and gcm aead_setup.calg = pdata->alg; aead_setup.cmode = pdata->mode; - aead_setup.sched_param = (void *)&g_param; h_sess = wd_aead_alloc_sess(&aead_setup); if (!h_sess) return NULL; @@ -905,7 +897,6 @@ static void *sec_uadk_sync_run(void *arg) case DIGEST_TYPE: digest_setup.alg = pdata->alg; digest_setup.mode = pdata->mode; // digest mode is optype - digest_setup.sched_param = (void *)&g_param; h_sess = wd_digest_alloc_sess(&digest_setup); if (!h_sess) return NULL; @@ -939,7 +930,7 @@ static void *sec_uadk_sync_run(void *arg) break; }
- add_recv_data(count); + add_recv_data(count, g_pktlen);
return NULL; } @@ -982,7 +973,6 @@ int sec_uadk_sync_threads(struct acc_option *options)
sync_error: return ret; - }
int sec_uadk_async_threads(struct acc_option *options) @@ -998,10 +988,10 @@ int sec_uadk_async_threads(struct acc_option *options) if (ret) return ret;
- /* poll thread */ for (i = 0; i < g_ctxnum; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].td_id = i; + /* poll thread */ ret = pthread_create(&pollid[i], NULL, sec_uadk_poll, &threads_args[i]); if (ret) { SEC_TST_PRT("Create poll thread fail!\n"); @@ -1053,6 +1043,7 @@ int sec_uadk_benchmark(struct acc_option *options) g_thread_num = options->threads; g_pktlen = options->pktlen; g_ctxnum = options->ctxnums; + g_prefetch = options->prefetch; if (options->optype > WD_CIPHER_DECRYPTION) { SEC_TST_PRT("SEC optype error: %u\n", options->optype); return -EINVAL; diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index 2e9c55d..d7cfe75 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -11,6 +11,9 @@ #include "v1/wd_util.h"
#define SEC_TST_PRT printf +#define MAX_IVK_LENTH 64 +#define DEF_IVK_DATA 0xAA +#define SQE_SIZE 128
typedef struct wd_thread_res { u32 subtype; @@ -32,57 +35,31 @@ struct thread_bd_res {
struct thread_queue_res { struct thread_bd_res *bd_res; -} g_thread_queue; +};
struct wcrypto_async_tag { void *ctx; - char *out_buf; int thread_id; int cnt; };
-#define MAX_IVK_LENTH 64 -#define DEF_IVK_DATA 0xAA -#define MAX_TRY_CNT 5000 -#define SEND_USLEEP 100 -#define TEST_MAX_THRD 128 -#define SQE_SIZE 128 -#define MAX_BLOCK_NM 4096 - +static struct thread_queue_res g_thread_queue; static unsigned int g_thread_num; -static unsigned int g_ctxnum; static unsigned int g_pktlen;
static void *cipher_async_cb(void *message, void *cipher_tag) { - struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)cipher_tag; - struct wcrypto_cipher_msg *req = (struct wcrypto_cipher_msg *)message; - - // no-sva data copy from uadk to user - memcpy(async_tag->out_buf, req->out, g_pktlen); - return NULL; }
-static void *aead_async_cb(void *message, void *aead_tag) +static void *aead_async_cb(void *message, void *cipher_tag) { - struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)aead_tag; - struct wcrypto_aead_msg *req = (struct wcrypto_aead_msg *)message; - - // no-sva data copy from uadk to user - memcpy(async_tag->out_buf, req->out, g_pktlen); - return NULL; }
static void *digest_async_cb(void *message, void *digest_tag) { - struct wcrypto_async_tag *async_tag = (struct wcrypto_async_tag *)digest_tag; - struct wcrypto_digest_msg *req = (struct wcrypto_digest_msg *)message; - - // no-sva data copy from uadk to user - memcpy(async_tag->out_buf, req->out, 16); - + // struct WCRYPTO_req *req = (struct WCRYPTO_req *)data; return NULL; }
@@ -396,9 +373,9 @@ static int init_wd_queue(struct acc_option *options) // use no-sva pbuffer memset(&blksetup, 0, sizeof(blksetup)); blksetup.block_size = g_pktlen + SQE_SIZE; //aead need mac and aad out - blksetup.block_num = MAX_BLOCK_NM * 4; //set pool inv + key + in + out + blksetup.block_num = MAX_BLOCK_NM; //set pool inv + key + in + out blksetup.align_size = SQE_SIZE; - SEC_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); + // SEC_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10);
for (j = 0; j < g_thread_num; j++) { g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup); @@ -411,8 +388,8 @@ static int init_wd_queue(struct acc_option *options)
// alloc in pbuffer res for (m = 0; m < g_thread_num; m++) { - g_thread_queue.bd_res[m].in = malloc(MAX_BLOCK_NM * sizeof(void *)); - for (idx = 0; idx < MAX_BLOCK_NM; idx++) { + g_thread_queue.bd_res[m].in = malloc(MAX_POOL_LENTH * sizeof(void *)); + for (idx = 0; idx < MAX_POOL_LENTH; idx++) { g_thread_queue.bd_res[m].in[idx] = wd_alloc_blk(g_thread_queue.bd_res[m].pool); if (!g_thread_queue.bd_res[m].in[idx]) { SEC_TST_PRT("create pool %dth in memory fail!\n", m); @@ -427,8 +404,8 @@ static int init_wd_queue(struct acc_option *options)
// alloc out pbuffer res for (n = 0; n < g_thread_num; n++) { - g_thread_queue.bd_res[n].out = malloc(MAX_BLOCK_NM * sizeof(void *)); - for (idx = 0; idx < MAX_BLOCK_NM; idx++) { + g_thread_queue.bd_res[n].out = malloc(MAX_POOL_LENTH * sizeof(void *)); + for (idx = 0; idx < MAX_POOL_LENTH; idx++) { g_thread_queue.bd_res[n].out[idx] = wd_alloc_blk(g_thread_queue.bd_res[n].pool); if (!g_thread_queue.bd_res[n].out[idx]) { SEC_TST_PRT("create pool %dth out memory fail!\n", n); @@ -443,8 +420,8 @@ static int init_wd_queue(struct acc_option *options)
// alloc iv pbuffer res for (k = 0; k < g_thread_num; k++) { - g_thread_queue.bd_res[k].iv = malloc(MAX_BLOCK_NM * sizeof(void *)); - for (idx = 0; idx < MAX_BLOCK_NM; idx++) { + g_thread_queue.bd_res[k].iv = malloc(MAX_POOL_LENTH * sizeof(void *)); + for (idx = 0; idx < MAX_POOL_LENTH; idx++) { g_thread_queue.bd_res[k].iv[idx] = wd_alloc_blk(g_thread_queue.bd_res[k].pool); if (!g_thread_queue.bd_res[k].iv[idx]) { SEC_TST_PRT("create pool %dth iv memory fail!\n", k); @@ -462,21 +439,21 @@ static int init_wd_queue(struct acc_option *options)
iv_err: for (k--; k >= 0; k--) { - for (idx = 0; idx < MAX_BLOCK_NM; idx++) + for (idx = 0; idx < MAX_POOL_LENTH; idx++) wd_free_blk(g_thread_queue.bd_res[k].pool, g_thread_queue.bd_res[k].iv[idx]); free(g_thread_queue.bd_res[k].iv); } out_err: for (n--; n >= 0; n--) { - for (idx = 0; idx < MAX_BLOCK_NM; idx++) + for (idx = 0; idx < MAX_POOL_LENTH; idx++) wd_free_blk(g_thread_queue.bd_res[n].pool, g_thread_queue.bd_res[n].out[idx]); free(g_thread_queue.bd_res[n].out); } in_err: for (m--; m >= 0; m--) { - for (idx = 0; idx < MAX_BLOCK_NM; idx++) + for (idx = 0; idx < MAX_POOL_LENTH; idx++) wd_free_blk(g_thread_queue.bd_res[m].pool, g_thread_queue.bd_res[m].in[idx]); free(g_thread_queue.bd_res[m].in); @@ -498,7 +475,7 @@ static void uninit_wd_queue(void) int i, j, idx;
for (i = 0; i < g_thread_num; i++) { - for (idx = 0; idx < MAX_BLOCK_NM; idx++) { + for (idx = 0; idx < MAX_POOL_LENTH; idx++) { wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].iv[idx]); wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].in[idx]); wd_free_blk(g_thread_queue.bd_res[i].pool, g_thread_queue.bd_res[i].out[idx]); @@ -522,22 +499,22 @@ void *sec_wd_poll(void *data) { typedef int (*poll_ctx)(struct wd_queue *q, unsigned int num); thread_data *pdata = (thread_data *)data; - poll_ctx uadk_poll_ctx = NULL; + poll_ctx wd_poll_ctx = NULL; u32 expt = ACC_QUEUE_SIZE * g_thread_num; - u32 last_time = 2; /* poll need one more recv time */ + u32 last_time = 2; // poll need one more recv time u32 id = pdata->td_id; u32 count = 0; - u32 recv = 0; + int recv = 0;
switch(pdata->subtype) { case CIPHER_TYPE: - uadk_poll_ctx = wcrypto_cipher_poll; + wd_poll_ctx = wcrypto_cipher_poll; break; case AEAD_TYPE: - uadk_poll_ctx = wcrypto_aead_poll; + wd_poll_ctx = wcrypto_aead_poll; break; case DIGEST_TYPE: - uadk_poll_ctx = wcrypto_digest_poll; + wd_poll_ctx = wcrypto_digest_poll; break; default: SEC_TST_PRT("<<<<<<async poll interface is NULL!\n"); @@ -548,7 +525,7 @@ void *sec_wd_poll(void *data) return NULL;
while (last_time) { - recv = uadk_poll_ctx(g_thread_queue.bd_res[id].queue, expt); + recv = wd_poll_ctx(g_thread_queue.bd_res[id].queue, expt); /* * warpdrive async mode poll easy to 100% with small package. * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv); @@ -565,7 +542,7 @@ void *sec_wd_poll(void *data) }
recv_error: - add_recv_data(count); + add_recv_data(count, g_pktlen);
return NULL; } @@ -582,8 +559,6 @@ static void *sec_wd_async_run(void *arg) struct wcrypto_async_tag *tag = NULL; char priv_key[MAX_IVK_LENTH]; struct thread_bd_res *bd_res; - char *src_data_buf = NULL; - char *out_data_buf = NULL; struct wd_queue *queue; void *ctx = NULL; void **res_in; @@ -605,27 +580,13 @@ static void *sec_wd_async_run(void *arg) res_out = bd_res->out; res_iv = bd_res->iv;
- /* create user data buffer */ - src_data_buf = malloc(g_pktlen * sizeof(char)); - if (!src_data_buf) - return NULL; - - get_rand_data((u8 *)src_data_buf, g_pktlen); - out_data_buf = malloc(g_pktlen * sizeof(char)); - if (!out_data_buf) { - free(src_data_buf); - return NULL; - } - memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); tag = malloc(sizeof(struct wcrypto_async_tag)); // set the user tag if (!tag) { SEC_TST_PRT("wcrypto async alloc tag fail!\n"); - free(src_data_buf); - free(out_data_buf); return NULL; } - tag->out_buf = out_data_buf; + tag->thread_id = pdata->td_id;
switch(pdata->subtype) { case CIPHER_TYPE: @@ -642,7 +603,7 @@ static void *sec_wd_async_run(void *arg) ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); if (!ctx) { SEC_TST_PRT("wd create cipher ctx fail!\n"); - goto async_err; + return NULL; } tag->ctx = ctx;
@@ -650,7 +611,7 @@ static void *sec_wd_async_run(void *arg) if (ret) { SEC_TST_PRT("wd cipher set key fail!\n"); wcrypto_del_cipher_ctx(ctx); - goto async_err; + return NULL; }
if (queue->capa.priv.direction == 0) @@ -672,9 +633,6 @@ static void *sec_wd_async_run(void *arg) if (get_run_state() == 0) break;
- // no-sva data copy to uadk - memcpy(copdata.in, src_data_buf, g_pktlen); - ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag); if (ret == -WD_EBUSY) { usleep(SEND_USLEEP * try_cnt); @@ -687,7 +645,7 @@ static void *sec_wd_async_run(void *arg) }
count++; - i = count % MAX_BLOCK_NM; + i = count % MAX_POOL_LENTH; tag->cnt = i; try_cnt = 0; copdata.in = res_in[i]; @@ -710,7 +668,7 @@ static void *sec_wd_async_run(void *arg) ctx = wcrypto_create_aead_ctx(queue, &aead_setup); if (!ctx) { SEC_TST_PRT("wd create aead ctx fail!\n"); - goto async_err; + return NULL; } tag->ctx = ctx;
@@ -718,7 +676,7 @@ static void *sec_wd_async_run(void *arg) if (ret) { SEC_TST_PRT("wd aead set key fail!\n"); wcrypto_del_aead_ctx(ctx); - goto async_err; + return NULL; }
authsize = 16; //set defaut size @@ -726,7 +684,7 @@ static void *sec_wd_async_run(void *arg) if (ret) { SEC_TST_PRT("set authsize fail!\n"); wcrypto_del_aead_ctx(ctx); - goto async_err; + return NULL; }
if (queue->capa.priv.direction == 0) { @@ -753,9 +711,6 @@ static void *sec_wd_async_run(void *arg) if (get_run_state() == 0) break;
- // no-sva data copy to uadk - memcpy(aopdata.in, src_data_buf, g_pktlen); - ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag); if (ret == -WD_EBUSY) { usleep(SEND_USLEEP * try_cnt); @@ -768,7 +723,7 @@ static void *sec_wd_async_run(void *arg) }
count++; - i = count % MAX_BLOCK_NM; + i = count % MAX_POOL_LENTH; tag->cnt = i; try_cnt = 0; aopdata.in = res_in[i]; @@ -791,7 +746,7 @@ static void *sec_wd_async_run(void *arg) ctx = wcrypto_create_digest_ctx(queue, &digest_setup); if (!ctx) { SEC_TST_PRT("wd create digest ctx fail!\n"); - goto async_err; + return NULL; } tag->ctx = ctx;
@@ -801,7 +756,7 @@ static void *sec_wd_async_run(void *arg) if (ret) { SEC_TST_PRT("wd digest set key fail!\n"); wcrypto_del_digest_ctx(ctx); - goto async_err; + return NULL; } }
@@ -818,9 +773,6 @@ static void *sec_wd_async_run(void *arg) if (get_run_state() == 0) break;
- // no-sva data copy to uadk - memcpy(dopdata.in, src_data_buf, g_pktlen); - ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); if (ret == -WD_EBUSY) { usleep(SEND_USLEEP * try_cnt); @@ -833,7 +785,7 @@ static void *sec_wd_async_run(void *arg) }
count++; - i = count % MAX_BLOCK_NM; + i = count % MAX_POOL_LENTH; tag->cnt = i; try_cnt = 0; dopdata.in = res_in[i]; @@ -846,7 +798,7 @@ static void *sec_wd_async_run(void *arg) add_send_complete();
while (1) { - if (get_recv_time() == g_thread_num) // wait Async mode finish recv + if (get_recv_time() > 0) // wait Async mode finish recv break; usleep(SEND_USLEEP); } @@ -863,10 +815,6 @@ static void *sec_wd_async_run(void *arg) break; }
-async_err: - free(tag); - free(src_data_buf); - free(out_data_buf); return NULL; }
@@ -882,8 +830,6 @@ static void *sec_wd_sync_run(void *arg) char priv_key[MAX_IVK_LENTH]; struct thread_bd_res *bd_res; struct wd_queue *queue; - char *src_data_buf = NULL; - char *out_data_buf = NULL; void *ctx = NULL; void *tag = NULL; void **res_in; @@ -905,18 +851,6 @@ static void *sec_wd_sync_run(void *arg) res_out = bd_res->out; res_iv = bd_res->iv;
- /* create user data buffer */ - src_data_buf = malloc(g_pktlen * sizeof(char)); - if (!src_data_buf) - return NULL; - - get_rand_data((u8 *)src_data_buf, g_pktlen); - out_data_buf = malloc(g_pktlen * sizeof(char)); - if (!out_data_buf) { - free(src_data_buf); - return NULL; - } - memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
switch(pdata->subtype) { @@ -933,14 +867,14 @@ static void *sec_wd_sync_run(void *arg) ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); if (!ctx) { SEC_TST_PRT("wd create cipher ctx fail!\n"); - goto sync_err; + return NULL; }
ret = wcrypto_set_cipher_key(ctx, (__u8*)priv_key, (__u16)pdata->keysize); if (ret) { SEC_TST_PRT("wd cipher set key fail!\n"); wcrypto_del_cipher_ctx(ctx); - goto sync_err; + return NULL; }
if (queue->capa.priv.direction == 0) @@ -961,9 +895,6 @@ static void *sec_wd_sync_run(void *arg) if (get_run_state() == 0) break;
- // no-sva data copy to uadk - memcpy(copdata.in, src_data_buf, g_pktlen); - ret = wcrypto_do_cipher(ctx, &copdata, tag); if (ret == -WD_EBUSY) { usleep(SEND_USLEEP * try_cnt); @@ -977,13 +908,10 @@ static void *sec_wd_sync_run(void *arg)
count++; try_cnt = 0; - i = count % MAX_BLOCK_NM; + i = count % MAX_POOL_LENTH; copdata.in = res_in[i]; copdata.out = res_out[i]; copdata.iv = res_iv[i]; - - // no-sva data copy from uadk to user - memcpy(out_data_buf, copdata.out, g_pktlen); } wcrypto_del_cipher_ctx(ctx);
@@ -1001,14 +929,14 @@ static void *sec_wd_sync_run(void *arg) ctx = wcrypto_create_aead_ctx(queue, &aead_setup); if (!ctx) { SEC_TST_PRT("wd create aead ctx fail!\n"); - goto sync_err; + return NULL; }
ret = wcrypto_set_aead_ckey(ctx, (__u8*)priv_key, (__u16)pdata->keysize); if (ret) { SEC_TST_PRT("wd aead set key fail!\n"); wcrypto_del_aead_ctx(ctx); - goto sync_err; + return NULL; }
authsize = 16; //set defaut size @@ -1016,7 +944,7 @@ static void *sec_wd_sync_run(void *arg) if (ret) { SEC_TST_PRT("set authsize fail!\n"); wcrypto_del_aead_ctx(ctx); - goto sync_err; + return NULL; }
if (queue->capa.priv.direction == 0) { @@ -1042,9 +970,6 @@ static void *sec_wd_sync_run(void *arg) if (get_run_state() == 0) break;
- // no-sva data copy to uadk - memcpy(aopdata.in, src_data_buf, g_pktlen); - ret = wcrypto_do_aead(ctx, &aopdata, tag); if (ret == -WD_EBUSY) { usleep(SEND_USLEEP * try_cnt); @@ -1058,13 +983,10 @@ static void *sec_wd_sync_run(void *arg)
count++; try_cnt = 0; - i = count % MAX_BLOCK_NM; + i = count % MAX_POOL_LENTH; aopdata.in = res_in[i]; aopdata.out = res_out[i]; aopdata.iv = res_iv[i]; - - // no-sva data copy from uadk to user - memcpy(out_data_buf, aopdata.out, g_pktlen); } wcrypto_del_aead_ctx(ctx);
@@ -1082,7 +1004,7 @@ static void *sec_wd_sync_run(void *arg) ctx = wcrypto_create_digest_ctx(queue, &digest_setup); if (!ctx) { SEC_TST_PRT("wd create digest ctx fail!\n"); - goto sync_err; + return NULL; }
if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { @@ -1091,7 +1013,7 @@ static void *sec_wd_sync_run(void *arg) if (ret) { SEC_TST_PRT("wd digest set key fail!\n"); wcrypto_del_digest_ctx(ctx); - goto sync_err; + return NULL; } }
@@ -1107,9 +1029,6 @@ static void *sec_wd_sync_run(void *arg) if (get_run_state() == 0) break;
- // no-sva data copy to uadk - memcpy(dopdata.in, src_data_buf, g_pktlen); - ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); if (ret == -WD_EBUSY) { usleep(SEND_USLEEP * try_cnt); @@ -1123,22 +1042,16 @@ static void *sec_wd_sync_run(void *arg)
count++; try_cnt = 0; - i = count % MAX_BLOCK_NM; + i = count % MAX_POOL_LENTH; dopdata.in = res_in[i]; - dopdata.out = res_out[i]; - - // no-sva data copy from uadk to user - memcpy(out_data_buf, dopdata.out, 16); + dopdata.out = res_out[i]; } wcrypto_del_digest_ctx(ctx); break; }
- add_recv_data(count); + add_recv_data(count, g_pktlen);
-sync_err: - free(src_data_buf); - free(out_data_buf); return NULL; }
@@ -1180,6 +1093,7 @@ int sec_wd_sync_threads(struct acc_option *options)
sync_error: return ret; + }
int sec_wd_async_threads(struct acc_option *options) @@ -1249,7 +1163,6 @@ int sec_wd_benchmark(struct acc_option *options)
g_thread_num = options->threads; g_pktlen = options->pktlen; - g_ctxnum = options->ctxnums; if (options->optype > WCRYPTO_CIPHER_DECRYPTION) { SEC_TST_PRT("SEC optype error: %u\n", options->optype); return -EINVAL; @@ -1273,3 +1186,4 @@ int sec_wd_benchmark(struct acc_option *options)
return 0; } + diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 84941d5..2904cba 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -10,19 +10,19 @@
#define BYTES_TO_KB 10 #define TABLE_SPACE_SIZE 8 -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/*----------------------------------------head struct--------------------------------------------------------*/ static unsigned int g_run_state = 1; static pthread_mutex_t acc_mutex = PTHREAD_MUTEX_INITIALIZER; static struct _recv_data { + double pkg_len; u64 send_cnt; u64 recv_cnt; u32 send_times; u32 recv_times; } g_recv_data;
-/* SVA mode and NOSVA mode change need re_insmode driver ko */ +/* SVA mode and NOSVA mode change need re_insmod driver ko */ enum test_type { SVA_MODE = 0x1, NOSVA_MODE = 0x2, @@ -63,7 +63,7 @@ static struct acc_alg_item alg_options[] = { {"rsa-2048-crt", RSA_2048_CRT}, {"rsa-3072-crt", RSA_3072_CRT}, {"rsa-4096-crt", RSA_4096_CRT}, - {"dh-768 ", DH_768}, + {"dh-768", DH_768}, {"dh-1024", DH_1024}, {"dh-1536", DH_1536}, {"dh-2048", DH_2048}, @@ -131,10 +131,14 @@ void add_send_complete(void) __atomic_add_fetch(&g_recv_data.send_times, 1, __ATOMIC_RELAXED); }
-void add_recv_data(u32 cnt) +void add_recv_data(u32 cnt, u32 pkglen) { pthread_mutex_lock(&acc_mutex); g_recv_data.recv_cnt += cnt; + if (g_recv_data.pkg_len == 0) + g_recv_data.pkg_len = pkglen; + else + g_recv_data.pkg_len = ((double)pkglen + g_recv_data.pkg_len) / 2; g_recv_data.recv_times++; pthread_mutex_unlock(&acc_mutex); } @@ -148,6 +152,7 @@ void init_recv_data(void) { g_recv_data.send_cnt = 0; g_recv_data.recv_cnt = 0; + g_recv_data.pkg_len = 0.0; g_recv_data.send_times = 0; g_recv_data.recv_times = 0; } @@ -263,28 +268,21 @@ void time_start(u32 seconds) alarm(seconds); }
-int get_rand_int(int range) -{ - int randnum; - - if (range <= 0) { - ACC_TST_PRT("rand range error!\n"); - return 1; - } - srand((unsigned)time(NULL) * getpid()); - randnum = rand() % range; - - return randnum; -} - -void get_rand_data(u8 *addr, int size) +void get_rand_data(u8 *addr, u32 size) { + unsigned short rand_state[3] = { + (0xae >> 16) & 0xffff, 0xae & 0xffff, 0x330e}; int i;
- srand((unsigned)time(NULL) * getpid()); - for (i = 0; i < size; i++) { - addr[i] = rand() % 0xFF; - } +#if 1 + // only 32bit valid, other 32bit is zero + for (i = 0; i < size >> 3; i++) + *((u64 *)addr + i) = nrand48(rand_state); +#else + // full 64bit valid + for (i = 0; i < size >> 2; i++) + *((u32 *)addr + i) = nrand48(rand_state); +#endif }
/*-------------------------------------main code------------------------------------------------------*/ @@ -320,7 +318,7 @@ static void parse_alg_param(struct acc_option *option) case X25519_ALG: snprintf(option->algclass, MAX_ALG_NAME, "%s", "x25519"); option->acctype = HPRE_TYPE; - option->subtype = X22519_TYPE; + option->subtype = X25519_TYPE; break; case X448_ALG: snprintf(option->algclass, MAX_ALG_NAME, "%s", "x448"); @@ -366,8 +364,8 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime) double perfermance; double cpu_rate; u32 ttime = 1000; - u32 perfdata; - u32 perfops; + double perfdata; + double perfops; double ops; u32 ptime; int i, len; @@ -397,13 +395,13 @@ void cal_perfermance_data(struct acc_option *option, u32 sttime) palgname[i] = '\0';
ptime = ptime - sttime; - perfdata = (g_recv_data.recv_cnt * option->pktlen) >> BYTES_TO_KB; - perfops = (g_recv_data.recv_cnt) >> BYTES_TO_KB; - perfermance = (double)perfdata / option->times; - ops = (double)perfops / option->times; + perfdata = g_recv_data.pkg_len * g_recv_data.recv_cnt / 1024.0; + perfops = (double)(g_recv_data.recv_cnt) / 1000.0; + perfermance = perfdata / option->times; + ops = perfops / option->times; cpu_rate = (double)ptime / option->times; ACC_TST_PRT("algname: length: perf: iops: CPU_rate:\n" - "%s %uBytes %.1fKB/s %.1fKops %.2f%%\n", + "%s %-2uBytes %.1fKB/s %.1fKops %.2f%%\n", palgname, option->pktlen, perfermance, ops, cpu_rate); }
@@ -419,11 +417,11 @@ static int benchmark_run(struct acc_option *option) ret = sec_wd_benchmark(option); } usleep(20000); - #ifdef WITH_OPENSSL_DIR +#ifdef WITH_OPENSSL_DIR if (option->modetype & SOFT_MODE) { ret = sec_soft_benchmark(option); } - #endif +#endif break; case HPRE_TYPE: break; @@ -447,6 +445,7 @@ static void dump_param(struct acc_option *option) ACC_TST_PRT(" [--ctxnum]: %u\n", option->ctxnums); ACC_TST_PRT(" [--algclass]:%s\n", option->algclass); ACC_TST_PRT(" [--acctype]: %u\n", option->acctype); + ACC_TST_PRT(" [--prefetch]:%u\n", option->prefetch); ACC_TST_PRT(" [--engine]: %s\n", option->engine); }
@@ -457,6 +456,7 @@ int acc_benchmark_run(struct acc_option *option) int i, ret = 0; int status;
+ ACC_TST_PRT("start UADK benchmark test.\n"); parse_alg_param(option); dump_param(option);
@@ -558,13 +558,27 @@ static void print_help(void) ACC_TST_PRT(" set the number of threads\n"); ACC_TST_PRT(" [--ctxnum]:\n"); ACC_TST_PRT(" the number of QP queues used by the entire test task\n"); + ACC_TST_PRT(" [--prefetch]:\n"); + ACC_TST_PRT(" in SVA mode, Enable prefetch can reduce page faults and improve performance\n"); ACC_TST_PRT(" [--engine]:\n"); ACC_TST_PRT(" set the test openssl engine\n"); + ACC_TST_PRT(" [--alglist]:\n"); + ACC_TST_PRT(" list the all support alg\n"); ACC_TST_PRT(" [--help] = usage\n"); ACC_TST_PRT("Example\n"); ACC_TST_PRT(" ./uadk_tool benchmark --alg aes-128-cbc --mode sva --opt 0 --sync\n"); ACC_TST_PRT(" --pktlen 1024 --seconds 1 --multi 1 --thread 1 --ctxnum 4\n"); - ACC_TST_PRT("UPDATE:2021-7-28\n"); + ACC_TST_PRT("UPDATE:2022-7-18\n"); +} + +static void print_support_alg(void) +{ + int i; + + ACC_TST_PRT("UADK benchmark supported ALG:\n"); + for (i = 0; i < ALG_MAX; i++) { + ACC_TST_PRT("%s\n", alg_options[i].name); + } }
int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) @@ -583,8 +597,10 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) {"thread", required_argument, 0, 9}, {"multi", required_argument, 0, 10}, {"ctxnum", required_argument, 0, 11}, - {"engine", required_argument, 0, 12}, - {"help", no_argument, 0, 13}, + {"prefetch", no_argument, 0, 12}, + {"engine", required_argument, 0, 13}, + {"alglist", no_argument, 0, 14}, + {"help", no_argument, 0, 15}, {0, 0, 0, 0} };
@@ -593,7 +609,6 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) if (c == -1) break;
- // ACC_TST_PRT("index:%d , optarg name:%s\n", c, optarg); switch (c) { case 2: option->algtype = get_alg_type(optarg); @@ -627,26 +642,36 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) option->ctxnums = strtol(optarg, NULL, 0); break; case 12: - strcpy(option->engine, optarg); + option->prefetch = 1; break; case 13: - print_help(); + strcpy(option->engine, optarg); break; + case 14: + print_support_alg(); + goto to_exit; + case 15: + print_help(); + goto to_exit; default: ACC_TST_PRT("bad input test parameter!\n"); print_help(); - exit(-1); + goto to_exit; } } + return 0; + +to_exit: + return -EINVAL; }
int acc_option_convert(struct acc_option *option) { - if (option->algtype >= ALG_MAX) + if (option->algtype >= ALG_MAX) { + ACC_TST_PRT("invalid: input algname is wrong!\n"); goto param_err; - else if (option->algtype < 0) - option->algtype = AES_128_CBC; + }
if (option->modetype >= INVALID_MODE) goto param_err; @@ -657,8 +682,8 @@ int acc_option_convert(struct acc_option *option) /* Min test package size is 64Bytes */ if (option->pktlen > MAX_DATA_SIZE) goto param_err; - else if (option->pktlen < 64) - option->pktlen = 64; + else if (option->pktlen < 16) + option->pktlen = 16;
if (option->times > MAX_TIME_SECONDS) { ACC_TST_PRT("uadk benchmark max test times to 128 seconds\n"); diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 2cb3dc0..a344fac 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -15,7 +15,6 @@ #include <signal.h> #include <linux/random.h> #include <sys/syscall.h> -#include <sys/mman.h> #include <sys/time.h>
#define ACC_TST_PRT printf @@ -24,21 +23,30 @@ #define MAX_CTX_NUM 64 #define MAX_TIME_SECONDS 128 #define BYTES_TO_MB 20 -#define MAX_OPT_TYPE 5 +#define MAX_OPT_TYPE 6 #define MAX_DATA_SIZE (15 * 1024 * 1024) #define MAX_ALG_NAME 64 #define ACC_QUEUE_SIZE 1024
+#define MAX_BLOCK_NM 16384 /* BLOCK_NUM must 4 times of POOL_LENTH */ +#define MAX_POOL_LENTH 4096 +#define MAX_TRY_CNT 5000 +#define SEND_USLEEP 100 + typedef unsigned char u8; typedef unsigned int u32; typedef unsigned long long u64; #define SCHED_SINGLE "sched_single" +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/** * struct acc_option - Define the test acc app option list. * @algclass: 0:cipher 1:digest * @acctype: The sub alg type, reference func get_cipher_resource. * @syncmode: 0:sync mode 1:async mode + * @modetype: sva, no-sva, soft mode + * @optype: enc/dec, comp/decomp + * @prefetch: write allocated memory to prevent page faults */ struct acc_option { char algname[64]; @@ -56,6 +64,7 @@ struct acc_option { u32 subtype; char engine[64]; u32 engine_flag; + u32 prefetch; };
enum acc_type { @@ -74,7 +83,7 @@ enum alg_type { ECDH_TYPE, ECDSA_TYPE, SM2_TYPE, - X22519_TYPE, + X25519_TYPE, X448_TYPE, };
@@ -164,9 +173,8 @@ extern void cal_perfermance_data(struct acc_option *option, u32 sttime); extern void time_start(u32 seconds); extern int get_run_state(void); extern void set_run_state(int state); -extern int get_rand_int(int range); -extern void get_rand_data(u8 *addr, int size); -extern void add_recv_data(u32 cnt); +extern void get_rand_data(u8 *addr, u32 size); +extern void add_recv_data(u32 cnt, u32 pkglen); extern void add_send_complete(void); extern u32 get_recv_time(void);
Add the performance test function of SVA mode of RSA, DH, ECC algorithms for HPRE module.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/benchmark/hpre_protocol_data.h | 1667 ++++++++++++++ uadk_tool/benchmark/hpre_uadk_benchmark.c | 2433 +++++++++++++++++++++ uadk_tool/benchmark/hpre_uadk_benchmark.h | 6 + 3 files changed, 4106 insertions(+) create mode 100644 uadk_tool/benchmark/hpre_protocol_data.h create mode 100644 uadk_tool/benchmark/hpre_uadk_benchmark.c create mode 100644 uadk_tool/benchmark/hpre_uadk_benchmark.h
diff --git a/uadk_tool/benchmark/hpre_protocol_data.h b/uadk_tool/benchmark/hpre_protocol_data.h new file mode 100644 index 0000000..2678a08 --- /dev/null +++ b/uadk_tool/benchmark/hpre_protocol_data.h @@ -0,0 +1,1667 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#ifndef HPRE_PROTOCOL_DATA_H +#define HPRE_PROTOCOL_DATA_H + +static unsigned char rsa_e_1024[] = { + 0x01, 0x00, 0x01, +}; + +static unsigned char rsa_p_1024[] = { + 0xf6, 0x49, 0xf2, 0xec, 0x89, 0xc8, 0xc2, 0x9b, 0x38, 0xd8, 0x74, 0x9b, 0x77, 0xed, 0x96, 0xc7, + 0x6d, 0xed, 0x15, 0x51, 0x2d, 0xfe, 0x67, 0x10, 0xa5, 0xdf, 0xd0, 0x59, 0x79, 0x75, 0x00, 0x60, + 0x3d, 0xd0, 0xf6, 0xe4, 0xda, 0x16, 0x5a, 0x24, 0x14, 0x01, 0xfa, 0x19, 0x07, 0x75, 0x21, 0x70, + 0x88, 0x40, 0xd9, 0x2f, 0xec, 0x83, 0x9e, 0x5f, 0xaa, 0xc0, 0xa3, 0x70, 0x18, 0xf5, 0x78, 0xdf, +}; + +static unsigned char rsa_q_1024[] = { + 0xcf, 0x53, 0x52, 0x09, 0x0d, 0xd7, 0x84, 0xdb, 0xa4, 0x4c, 0x79, 0x74, 0x0d, 0x94, 0xa0, 0x19, + 0x94, 0x33, 0xbf, 0x39, 0xe5, 0xef, 0xf5, 0xe9, 0x6c, 0xef, 0xd0, 0x9a, 0x4c, 0x00, 0x14, 0x68, + 0x66, 0xa7, 0x80, 0x32, 0x14, 0x84, 0xc9, 0x6f, 0x9a, 0x7d, 0x43, 0x0e, 0x9f, 0x85, 0x27, 0x6c, + 0x65, 0x50, 0x9b, 0x88, 0x54, 0x22, 0x72, 0x95, 0x90, 0x26, 0xc4, 0xa8, 0x19, 0x1c, 0x47, 0x03, +}; + +static unsigned char rsa_dp_1024[] = { + 0xd0, 0xb6, 0x66, 0x28, 0xd1, 0xb2, 0xd2, 0x48, 0x1c, 0x6a, 0x42, 0x97, 0x25, 0x90, 0xb0, 0x40, + 0x1d, 0x05, 0xd7, 0x14, 0xce, 0x77, 0x52, 0xfc, 0x26, 0xb5, 0x7e, 0xa8, 0xf4, 0x66, 0x94, 0x84, + 0xfa, 0x9d, 0xc5, 0x3c, 0xb7, 0x1c, 0x4e, 0x13, 0x58, 0xe9, 0x3b, 0xfa, 0x4d, 0xf9, 0x92, 0xf6, + 0xfc, 0x60, 0x88, 0x2d, 0x36, 0xaf, 0x6b, 0x5d, 0x03, 0x24, 0xf0, 0xdc, 0x24, 0x2a, 0x91, 0xdd, +}; + +static unsigned char rsa_dq_1024[] = { + 0x09, 0x4a, 0x89, 0x9d, 0xa0, 0x42, 0x2d, 0x51, 0x0e, 0x8e, 0xe2, 0xce, 0x81, 0xa1, 0x4c, 0x7f, + 0x78, 0xf5, 0xcc, 0xb7, 0x12, 0x87, 0xeb, 0x74, 0x57, 0x8e, 0x73, 0xc1, 0xc6, 0x70, 0x26, 0x79, + 0xfb, 0x47, 0xbc, 0x66, 0x02, 0x27, 0x65, 0x43, 0x9c, 0x1f, 0xca, 0xf6, 0x87, 0xcd, 0x96, 0xd3, + 0xb3, 0xc2, 0xa6, 0x05, 0xb9, 0x07, 0x86, 0x2d, 0x0f, 0xb5, 0xbd, 0x10, 0x6f, 0x77, 0xa5, 0xf3, +}; + +static unsigned char rsa_qinv_1024[] = { + 0x59, 0xf3, 0xaf, 0x75, 0xde, 0xdd, 0xcc, 0xc7, 0x62, 0xd7, 0xed, 0x4e, 0x81, 0x18, 0xca, 0x42, + 0xab, 0x36, 0x3b, 0x83, 0x5c, 0xd0, 0x55, 0x3f, 0x37, 0x3a, 0xa9, 0x64, 0x25, 0x65, 0x05, 0xde, + 0x87, 0xca, 0x54, 0xdb, 0x24, 0xdc, 0xe8, 0xf7, 0x4a, 0xfe, 0x2c, 0x59, 0xbf, 0x3d, 0x45, 0x43, + 0x91, 0x9e, 0x6b, 0x9c, 0xf6, 0xce, 0xb2, 0xf8, 0xc5, 0x2e, 0xef, 0x85, 0x58, 0xed, 0x4a, 0x0e, +}; + +static unsigned char rsa_d_1024[] = { + 0x13, 0xbe, 0x3a, 0x33, 0xf3, 0xad, 0x6f, 0xc7, 0x3a, 0x8c, 0x77, 0xe3, 0x73, 0xb8, 0x13, 0xf0, + 0x66, 0x50, 0xd7, 0x04, 0xe5, 0xeb, 0x11, 0x31, 0x97, 0x9b, 0xac, 0xd5, 0x72, 0x9f, 0xe4, 0xeb, + 0xd7, 0x27, 0x9b, 0x2d, 0xef, 0xca, 0xa3, 0x7c, 0xe7, 0x2f, 0x5e, 0xd7, 0xe9, 0x85, 0xbd, 0x88, + 0xce, 0xb6, 0x32, 0xe2, 0xf3, 0xe4, 0x28, 0x0f, 0xc7, 0x8e, 0xa5, 0xbb, 0xc4, 0xd4, 0xe8, 0xd9, + 0x23, 0x81, 0x4c, 0x71, 0x37, 0xc9, 0x78, 0xe2, 0xd8, 0x54, 0x01, 0x05, 0xb9, 0x5e, 0x48, 0xab, + 0x65, 0x76, 0x63, 0xe3, 0x90, 0xaf, 0x25, 0x00, 0xde, 0xe3, 0xb7, 0x6f, 0x91, 0xa1, 0x5e, 0x7a, + 0x84, 0xbf, 0x62, 0x08, 0x63, 0xe7, 0x0a, 0x23, 0x42, 0x50, 0xc8, 0x33, 0x29, 0xb9, 0x27, 0x27, + 0xe6, 0x34, 0x73, 0x69, 0x08, 0x76, 0xaf, 0x65, 0x1e, 0x3b, 0x51, 0xa5, 0x16, 0xad, 0x20, 0xe5, +}; + +static unsigned char rsa_n_1024[] = { + 0xc7, 0x75, 0xf4, 0x53, 0x6b, 0xd4, 0x69, 0x28, 0x39, 0xeb, 0xa7, 0x70, 0xcf, 0x8f, 0x47, 0x54, + 0x57, 0xf9, 0x43, 0xd3, 0xd6, 0x7b, 0xa4, 0xc9, 0x4b, 0xb3, 0x9d, 0xb3, 0x7f, 0x8f, 0x46, 0x31, + 0xf6, 0xbe, 0x62, 0xa4, 0x0c, 0x7e, 0x41, 0x41, 0x2e, 0x4d, 0x31, 0x1a, 0x92, 0xca, 0x69, 0x27, + 0x0a, 0x06, 0x23, 0xf5, 0x0f, 0x50, 0xf0, 0x17, 0xfa, 0x92, 0x25, 0x1c, 0xb6, 0x59, 0x2c, 0xcc, + 0xc9, 0x4d, 0x3c, 0x38, 0x04, 0xbb, 0x05, 0xc5, 0x20, 0xe5, 0xaf, 0x06, 0xd0, 0xc4, 0x14, 0x9c, + 0xa9, 0xa4, 0x7e, 0x97, 0x04, 0xb9, 0xe7, 0x60, 0x47, 0xa2, 0xed, 0xea, 0xda, 0xec, 0x4e, 0x0a, + 0x7a, 0x01, 0x00, 0x19, 0x19, 0x99, 0x49, 0x28, 0x70, 0x07, 0x21, 0xd8, 0x0d, 0x1f, 0x2d, 0xa2, + 0x9d, 0x78, 0x94, 0x26, 0xdd, 0x26, 0x65, 0x66, 0xf3, 0x04, 0xc3, 0x3b, 0x5e, 0xca, 0x43, 0x9d, +}; + +static unsigned char rsa_e_2048[] = { + 0x01, 0x00, 0x01, +}; + +static unsigned char rsa_p_2048[] = { + 0x01, 0xf8, 0x33, 0x75, 0x8c, 0x8d, 0x6b, 0xed, 0x4b, 0xf7, 0x0a, 0x3a, 0x67, 0xd5, 0x91, + 0x27, 0xe6, 0x62, 0x90, 0x67, 0xd2, 0xe3, 0x33, 0xdc, 0xba, 0x96, 0x81, 0xb7, 0xc9, 0xc8, + 0xa6, 0x64, 0x8b, 0xe9, 0x2f, 0x1d, 0x87, 0x3c, 0x9a, 0x95, 0x19, 0x8b, 0x04, 0x8c, 0x1a, + 0xc1, 0x6b, 0x76, 0x8d, 0xe3, 0x2a, 0x50, 0xec, 0xb8, 0xf7, 0x02, 0x38, 0x5d, 0xd0, 0xe6, + 0xc0, 0x9f, 0xb5, 0xc6, 0xf7, 0xd0, 0x34, 0xec, 0xd5, 0x4d, 0xf5, 0x26, 0x32, 0x8a, 0xe8, + 0x5f, 0xd5, 0x1d, 0x0e, 0xd8, 0xcd, 0x84, 0xe0, 0xd6, 0x09, 0x3a, 0xcd, 0x8b, 0x5c, 0x96, + 0x89, 0xf0, 0x2e, 0xb7, 0x87, 0x9c, 0x12, 0xeb, 0xd6, 0x84, 0x00, 0x3d, 0x1c, 0xff, 0xa0, + 0xaa, 0x82, 0x0a, 0x4d, 0x53, 0x06, 0xde, 0x5a, 0x0c, 0x4a, 0xd4, 0x94, 0x5b, 0x01, 0xac, + 0x9f, 0x9e, 0x7e, 0x90, 0xb0, 0xd7, 0x19 +}; + +static unsigned char rsa_q_2048[] = { + 0x01, 0xe1, 0xf1, 0x9b, 0xd6, 0xcf, 0x15, 0x49, 0x4c, 0xfa, 0x90, 0xf1, 0x27, 0xb1, 0xe2, + 0xc9, 0xf8, 0xec, 0x97, 0xc5, 0x10, 0x6c, 0xad, 0x62, 0xba, 0x1b, 0x23, 0x1e, 0x95, 0xb3, + 0x30, 0x89, 0x15, 0xc2, 0x19, 0x9e, 0xa8, 0x06, 0x30, 0xe1, 0xf0, 0x14, 0xfa, 0x99, 0x10, + 0x22, 0x13, 0x43, 0xb1, 0x97, 0xa4, 0x7d, 0x5d, 0x92, 0xa4, 0xf1, 0x28, 0x33, 0xbc, 0x9b, + 0x20, 0xba, 0x73, 0x66, 0x32, 0x96, 0x63, 0xb2, 0x1d, 0x49, 0xe8, 0xbc, 0x2e, 0x88, 0x2b, + 0x9f, 0x89, 0x14, 0xb6, 0x5e, 0xe1, 0xe9, 0x0f, 0x1c, 0xa8, 0xd5, 0xa4, 0xda, 0x61, 0xde, + 0x0c, 0x36, 0xce, 0xf2, 0x89, 0xeb, 0x59, 0xd5, 0xd0, 0xdf, 0x77, 0xb5, 0x14, 0xa6, 0xcf, + 0x35, 0x86, 0xf1, 0x78, 0x1a, 0x8a, 0x52, 0x6f, 0x06, 0x20, 0x17, 0xca, 0xa8, 0xae, 0x4a, + 0x60, 0xf9, 0x89, 0x05, 0xc6, 0x0d, 0x87 +}; + +static unsigned char rsa_dp_2048[] = { + 0x54, 0xd7, 0xb3, 0xec, 0x16, 0xd0, 0x16, 0x7a, 0x35, 0xf3, 0xce, 0xa8, 0x32, 0x53, 0xde, + 0xb6, 0xf1, 0xd7, 0x02, 0xe1, 0x85, 0xc1, 0xf0, 0x5e, 0xa5, 0x7c, 0xe6, 0x84, 0x59, 0xf3, + 0x45, 0xf0, 0x15, 0x29, 0x0c, 0x7a, 0xf9, 0x43, 0xb9, 0xdb, 0x36, 0x7d, 0x69, 0x66, 0x07, + 0x2e, 0x22, 0x20, 0xf6, 0x1c, 0xe4, 0xc9, 0x30, 0xc6, 0xbf, 0xe4, 0xe4, 0x44, 0x86, 0xcf, + 0xdb, 0x10, 0x27, 0x8f, 0x03, 0xc6, 0x24, 0x24, 0x30, 0x9e, 0x13, 0xf3, 0x65, 0x54, 0x7c, + 0xeb, 0xcb, 0x9b, 0xf7, 0xf7, 0x7d, 0x68, 0xa8, 0x1b, 0x9d, 0x7d, 0x80, 0xf9, 0xef, 0x8a, + 0xfe, 0x93, 0x9d, 0xe6, 0x7f, 0xe8, 0xdf, 0x2e, 0x95, 0xbf, 0xc4, 0x88, 0xe0, 0xab, 0x14, + 0x86, 0x15, 0x5d, 0xb5, 0x9e, 0xee, 0x43, 0x90, 0xd5, 0xf6, 0xb7, 0x90, 0x28, 0xd3, 0xf7, + 0x78, 0x20, 0x2c, 0x10, 0xd5, 0xe1 +}; + +static unsigned char rsa_dq_2048[] = { + 0x38, 0x83, 0x81, 0x77, 0xb5, 0xfe, 0xd4, 0x02, 0x9f, 0xdb, 0x41, 0x3c, 0x1b, 0x62, 0xf1, + 0xb6, 0x2b, 0xe0, 0x3c, 0x2e, 0x89, 0xdf, 0xe7, 0x14, 0xd5, 0xbb, 0xcf, 0x89, 0x54, 0x62, + 0xdb, 0xa0, 0x5e, 0x8b, 0x6c, 0x8c, 0x5d, 0x75, 0x7b, 0xf9, 0x10, 0x2c, 0xb6, 0xa8, 0x2a, + 0xa6, 0xc1, 0xa8, 0x60, 0x94, 0xdc, 0x52, 0x8d, 0xb0, 0xa3, 0xca, 0xc8, 0x0e, 0x54, 0xce, + 0x88, 0xae, 0xa1, 0x8c, 0x4b, 0x10, 0x53, 0xc1, 0x95, 0x7a, 0x22, 0x1e, 0xfe, 0xbe, 0xc6, + 0xcd, 0x67, 0x4d, 0x5f, 0x60, 0xf4, 0x58, 0x5e, 0x4e, 0xfa, 0x06, 0x83, 0xc9, 0x38, 0x25, + 0x8c, 0x83, 0xc5, 0xf3, 0x20, 0x52, 0xff, 0x7c, 0xa7, 0xc7, 0xbc, 0xc7, 0x38, 0x2c, 0x52, + 0x25, 0x89, 0xc9, 0x40, 0xab, 0x79, 0xb1, 0x25, 0x31, 0xbc, 0x38, 0x7a, 0x81, 0x3d, 0x9d, + 0x93, 0x85, 0x5a, 0xd4, 0xf7, 0x9f +}; + +static unsigned char rsa_qinv_2048[] = { + 0x01, 0x3d, 0x2b, 0xcc, 0x55, 0x34, 0x6f, 0x0b, 0x2d, 0x84, 0x57, 0x16, 0x50, 0x06, 0x38, + 0x3f, 0xcf, 0x61, 0x25, 0x6d, 0x16, 0xc4, 0x91, 0x0e, 0x28, 0xa4, 0xbe, 0x2e, 0x0a, 0x12, + 0x6a, 0x0b, 0xe7, 0xda, 0x94, 0x12, 0x36, 0x99, 0xbe, 0x3c, 0x51, 0x01, 0x98, 0x84, 0x77, + 0xc8, 0xed, 0xd9, 0xaa, 0xbc, 0x3d, 0x7a, 0x48, 0x69, 0xf4, 0xac, 0x68, 0x78, 0xfa, 0x81, + 0xba, 0x57, 0xbd, 0xaa, 0x9d, 0xcc, 0x39, 0x57, 0x87, 0x77, 0xe9, 0x2a, 0xcd, 0xde, 0xfc, + 0x4d, 0xf5, 0xb6, 0x4f, 0xc3, 0x53, 0x00, 0x5a, 0xf6, 0x14, 0x96, 0x7b, 0x37, 0x7e, 0x9f, + 0x89, 0xa0, 0x7e, 0xa4, 0xc8, 0xe5, 0xb1, 0x7b, 0x29, 0x82, 0x95, 0x7b, 0x08, 0x68, 0xb6, + 0x76, 0x4b, 0xf9, 0x5f, 0x31, 0xe7, 0x3f, 0xf2, 0x2a, 0xbe, 0xe4, 0x28, 0xf3, 0x83, 0x0f, + 0x17, 0xe9, 0x8f, 0xbb, 0x4f, 0x1e, 0x26 +}; + +static unsigned char rsa_d_2048[] = { + 0x03, 0xb5, 0x34, 0x8b, 0x3c, 0xfa, 0x14, 0xd1, 0x38, 0x44, 0xc0, 0xb5, 0xee, 0x6f, 0xa6, + 0x8b, 0x46, 0x4a, 0x46, 0x77, 0x7f, 0x49, 0x4f, 0x0a, 0x00, 0x5d, 0xed, 0x36, 0xe2, 0x22, + 0x0b, 0xc6, 0x6c, 0xd6, 0x25, 0x15, 0xa2, 0x51, 0xa1, 0xc8, 0xb7, 0x22, 0xd8, 0xad, 0xb7, + 0xf8, 0x59, 0xa9, 0x69, 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C0, 0xD0, 0x98, 0x94, 0x7A, 0x81, 0x02, 0xC1, + 0xCE, 0x0B, 0xED, 0x6E, 0xF1, 0x5D, 0xB7, 0xB3, 0x9C, 0xA9, 0x88, 0x52, 0xF9, 0xF9, 0xCF, 0xFD, + 0x74, 0x6A, 0xA3, 0x3B, 0x0C, 0xA0, 0x32, 0xD2, 0xB6, 0x31, 0x8B, 0x93, 0x3B, 0x8A, 0x04, 0x2E, + 0xDD, 0x14, 0x60, 0x35, 0xA0, 0xD4, 0xCA, 0xDC, 0x9E, 0x96, 0x23, 0xAC, 0x64, 0xD5, 0x29, 0xB2, + 0x0D, 0x46, 0x01, 0xE6, 0xF7, 0xA0, 0xE0, 0x9C, 0xFB, 0xDE, 0x21, 0xFF, 0xFF, 0x4F, 0xC0, 0x04, + 0x3E, 0xC4, 0x4B, 0xAF, 0x20, 0x1C, 0x41, 0xCE, 0x07, 0x3C, 0x79, 0xFC, 0x6D, 0x7C, 0xEF, 0x1E, + 0x37, 0x14, 0x78, 0x9D, 0x26, 0x85, 0x2A, 0xCC, 0x72, 0x22, 0x83, 0xB3, 0x2F +}; + +static unsigned char rsa_e_3072[] = { + 0x01, 0x00, 0x01 +}; + +static unsigned char rsa_p_3072[] = { + 0xfe, 0x2d, 0x13, 0xf6, 0x82, 0xbd, 0xc9, 0x3f, 0xf2, 0x44, 0x87, 0xb0, 0x9c, 0xda, 0xca, 0xb5, + 0xfa, 0x01, 0x6f, 0xf0, 0x3d, 0xd0, 0xd2, 0x1c, 0x40, 0xef, 0xc6, 0x69, 0xe0, 0xe9, 0x66, 0x06, + 0x29, 0x00, 0x7e, 0xe6, 0x0b, 0x1a, 0x02, 0x50, 0x5e, 0x0e, 0x19, 0x5f, 0x6a, 0xf3, 0x0c, 0xa5, + 0x3f, 0xe9, 0xc4, 0x5d, 0x36, 0xc5, 0xbe, 0xc7, 0x77, 0xfc, 0x15, 0x05, 0xb3, 0xa4, 0xc7, 0xd1, + 0xab, 0x3f, 0xfc, 0x42, 0xc3, 0x9a, 0x0e, 0x5a, 0xd8, 0x51, 0xeb, 0x36, 0x2c, 0xf2, 0x07, 0xe3, + 0x5c, 0xcb, 0xe1, 0xf3, 0xd7, 0x67, 0x42, 0x2f, 0x3a, 0x31, 0x21, 0x0f, 0x4e, 0x4d, 0x03, 0x30, + 0xaf, 0xd9, 0x05, 0x03, 0x64, 0x79, 0x7d, 0x7b, 0x96, 0x48, 0xe5, 0x6f, 0x84, 0x44, 0x03, 0x36, + 0x08, 0xf6, 0xe8, 0xb4, 0xa8, 0x7d, 0xb4, 0x63, 0x73, 0x6f, 0x2b, 0x14, 0xb0, 0x6e, 0x0c, 0x96, + 0x3d, 0xe2, 0xda, 0x7f, 0x4f, 0x07, 0xc3, 0xb0, 0x89, 0x53, 0x9d, 0x14, 0x61, 0x17, 0xe6, 0xa4, + 0x52, 0x1a, 0xfb, 0xd4, 0xdd, 0xe0, 0x54, 0x2a, 0xf2, 0x86, 0x30, 0x8c, 0x1c, 0x68, 0x30, 0x72, + 0xcc, 0xa0, 0x3f, 0xe0, 0x14, 0x3d, 0xfc, 0xf2, 0xd9, 0x91, 0xea, 0xe8, 0xe8, 0x9a, 0x78, 0xfb, + 0xa8, 0x16, 0x50, 0x24, 0xfe, 0x54, 0xd4, 0x57, 0xf1, 0xd9, 0x8f, 0xcb, 0x6d, 0x38, 0x63, 0x21 +}; + +static unsigned char rsa_q_3072[] = { + 0xd4, 0x12, 0x12, 0xd1, 0x4e, 0x9e, 0xa8, 0xb4, 0xf3, 0x94, 0x4d, 0x03, 0x70, 0x83, 0x4f, 0x1c, + 0x16, 0x85, 0xd8, 0xa8, 0x8d, 0xcc, 0xfe, 0xde, 0x5d, 0x08, 0xc3, 0xdf, 0xc4, 0xd8, 0xf9, 0x60, + 0x50, 0x9a, 0x58, 0xd5, 0xf5, 0x96, 0xec, 0x95, 0x09, 0x7b, 0x5f, 0x96, 0xaf, 0xf5, 0xee, 0x79, + 0x46, 0x8b, 0x38, 0x2c, 0x9b, 0x17, 0x69, 0x07, 0x91, 0x74, 0x57, 0x73, 0x99, 0xd9, 0x89, 0xa4, + 0x20, 0x0b, 0xb5, 0x7f, 0x30, 0xd7, 0x13, 0xda, 0x0d, 0xc0, 0x3a, 0x96, 0x76, 0xf7, 0xac, 0x86, + 0x5e, 0x1f, 0x5d, 0xd4, 0x54, 0xa0, 0x30, 0xca, 0x36, 0x00, 0x7c, 0xc1, 0xd8, 0x05, 0x73, 0xde, + 0x75, 0x6c, 0xd0, 0x69, 0xe5, 0xfa, 0xd8, 0x24, 0xca, 0xb0, 0xee, 0x8a, 0x63, 0x83, 0x1b, 0x90, + 0xb8, 0x0d, 0x6d, 0xd5, 0x75, 0xe4, 0x5c, 0x73, 0xc7, 0xff, 0xe4, 0x57, 0x6a, 0x59, 0xc3, 0x17, + 0x05, 0xc4, 0xc4, 0x87, 0xc2, 0x11, 0x7a, 0x34, 0xbd, 0xb4, 0x7c, 0x7f, 0x3a, 0x60, 0xd7, 0x57, + 0xcb, 0x48, 0xb1, 0x14, 0xa6, 0x4f, 0x57, 0x35, 0xc7, 0x64, 0xf9, 0xb8, 0x11, 0xe8, 0x22, 0xfd, + 0x6c, 0x53, 0xdd, 0xef, 0x6a, 0x88, 0x56, 0xf7, 0x6d, 0x51, 0xa1, 0x5b, 0x26, 0x81, 0xa0, 0xd4, + 0x78, 0x10, 0x9f, 0x2d, 0x88, 0xdc, 0xa1, 0x09, 0xd0, 0x84, 0x7a, 0x3b, 0x38, 0x7c, 0x5f, 0x75 +}; + +static unsigned char rsa_dp_3072[] = { + 0xfd, 0x8d, 0x3a, 0x3c, 0xce, 0x6f, 0x44, 0x32, 0xe6, 0x1a, 0x36, 0xc1, 0x97, 0xb7, 0x2a, 0x40, + 0x1e, 0x05, 0x11, 0x05, 0x36, 0xa4, 0xf8, 0xf3, 0xf6, 0x53, 0x3a, 0x3a, 0xa4, 0x82, 0x2f, 0xa4, + 0x35, 0x82, 0xa9, 0x14, 0x12, 0x3e, 0xff, 0xcf, 0xec, 0x03, 0x64, 0x8c, 0x2a, 0xc4, 0x09, 0xf9, + 0x4e, 0xa8, 0x83, 0x99, 0xf8, 0xe9, 0x8a, 0x46, 0xb1, 0x0a, 0x66, 0x6e, 0x29, 0xa6, 0x57, 0x2e, + 0x71, 0x06, 0x83, 0x3e, 0x96, 0xa1, 0x37, 0x70, 0xa8, 0x1a, 0x0f, 0xe9, 0x1b, 0x2c, 0xd5, 0x71, + 0x99, 0x40, 0x49, 0x46, 0x55, 0xba, 0x4b, 0xeb, 0x90, 0xc1, 0x31, 0x99, 0x73, 0x22, 0x9f, 0xec, + 0x11, 0x7f, 0x0b, 0xe1, 0x36, 0x79, 0x7b, 0x13, 0xad, 0xf7, 0x49, 0xe8, 0xd4, 0xa8, 0x84, 0x0b, + 0x83, 0x25, 0xcb, 0x3d, 0x6c, 0x56, 0xf9, 0x7b, 0xbb, 0xcb, 0x49, 0xce, 0x79, 0xb1, 0x4e, 0x1d, + 0x11, 0xdf, 0x1a, 0xd7, 0xa4, 0x9e, 0xba, 0x37, 0x80, 0xc6, 0x48, 0x0b, 0xec, 0x4f, 0x4b, 0x64, + 0xe0, 0x02, 0xca, 0xf4, 0xad, 0xe0, 0xfa, 0x15, 0x5d, 0x99, 0x3f, 0x14, 0x85, 0xc1, 0xe9, 0x92, + 0x9b, 0x4d, 0xc0, 0x6a, 0x67, 0xc6, 0xee, 0x6d, 0xd3, 0x5c, 0x1c, 0x59, 0xfa, 0xaf, 0x1d, 0xc0, + 0xed, 0x0c, 0x55, 0x26, 0x92, 0x0f, 0x4d, 0x43, 0xed, 0x9e, 0x7a, 0x33, 0x13, 0xe1, 0x0c, 0x01 +}; + +static unsigned char rsa_dq_3072[] = { + 0x51, 0xfc, 0xde, 0xcb, 0x8e, 0xe2, 0xa6, 0x04, 0xb7, 0x3a, 0xf9, 0x7f, 0x3f, 0xeb, 0x74, 0x15, + 0x3e, 0xdb, 0xe6, 0x44, 0x5b, 0xf6, 0x09, 0xfe, 0xfb, 0xe6, 0xdc, 0x9b, 0x51, 0x66, 0x35, 0x1b, + 0x38, 0x6e, 0x43, 0xb4, 0x0c, 0x6b, 0x99, 0xf1, 0x90, 0xa5, 0xe2, 0xf1, 0xc5, 0xfb, 0x85, 0x83, + 0xdb, 0x73, 0x0d, 0x77, 0xa9, 0x4a, 0x26, 0xaf, 0xe7, 0x5b, 0x1c, 0x48, 0x34, 0x0d, 0xb7, 0x39, + 0xfd, 0xad, 0xa9, 0x30, 0x90, 0x38, 0x46, 0x93, 0x81, 0xc7, 0x74, 0x9f, 0x21, 0x45, 0x65, 0xac, + 0xd9, 0x0c, 0xb5, 0x60, 0xd6, 0x8a, 0xcb, 0xf2, 0x11, 0x68, 0xa4, 0xd2, 0xe8, 0x6a, 0x4b, 0x3e, + 0x91, 0x15, 0x4d, 0x89, 0xf3, 0x80, 0xc4, 0x39, 0x8d, 0x27, 0x54, 0x41, 0xaa, 0x71, 0x50, 0xa1, + 0xe5, 0x96, 0x43, 0x85, 0x48, 0x3b, 0xce, 0x46, 0x70, 0xe7, 0x0c, 0x67, 0x83, 0x55, 0x4a, 0xa8, + 0x46, 0xf1, 0xa8, 0xad, 0x77, 0xa8, 0xfc, 0x1f, 0x11, 0xcc, 0x8a, 0x69, 0x41, 0xaf, 0x98, 0xf1, + 0x77, 0x45, 0x16, 0x39, 0x0e, 0x87, 0x14, 0x07, 0x55, 0x9c, 0x43, 0x33, 0x17, 0xb1, 0x30, 0x7d, + 0xdb, 0x78, 0x9d, 0x0f, 0xe7, 0x96, 0xe8, 0x50, 0x66, 0x32, 0x2d, 0xf8, 0xa8, 0x6d, 0x6b, 0x39, + 0x59, 0x65, 0xcb, 0xb4, 0x75, 0xfa, 0x1e, 0x44, 0x46, 0x1a, 0x41, 0x8b, 0x4d, 0xae, 0x3f, 0xd5 +}; + +static unsigned char rsa_qinv_3072[] = { + 0xb2, 0xa1, 0x52, 0x54, 0xee, 0xcd, 0xb9, 0x07, 0xde, 0x26, 0x8a, 0x1b, 0x93, 0x91, 0xf7, 0x08, + 0xbe, 0x81, 0x23, 0x0c, 0xba, 0x24, 0x7a, 0x66, 0x57, 0x41, 0x09, 0xc6, 0x3a, 0x25, 0xa8, 0x56, + 0x03, 0x34, 0xcd, 0xcb, 0x97, 0xe8, 0x48, 0xdf, 0x64, 0xc8, 0xd3, 0xe2, 0xfd, 0xaa, 0xcb, 0xdc, + 0x9c, 0xfc, 0xab, 0x0d, 0x00, 0x57, 0x06, 0xb3, 0x71, 0x53, 0xe9, 0x2d, 0x7c, 0xcc, 0x68, 0xca, + 0x24, 0x94, 0x11, 0x48, 0x21, 0xb0, 0x55, 0xcb, 0xa9, 0x2b, 0x09, 0x99, 0x90, 0x9a, 0xaa, 0xea, + 0xa3, 0xbd, 0x4d, 0xf3, 0xba, 0x67, 0x55, 0x3c, 0x5c, 0xbf, 0xfa, 0x23, 0xbf, 0xfc, 0xcd, 0x7e, + 0x99, 0x60, 0xf1, 0x71, 0x78, 0x03, 0x15, 0xbb, 0xda, 0x54, 0xd9, 0x3d, 0x0d, 0x19, 0xad, 0xbf, + 0x3e, 0x35, 0xa9, 0x5d, 0xf7, 0xb1, 0x88, 0x78, 0x96, 0x59, 0xda, 0x0b, 0x54, 0xd9, 0x8a, 0x64, + 0x89, 0xf8, 0xea, 0x27, 0x78, 0x73, 0x58, 0x40, 0x1f, 0xec, 0xa3, 0xdd, 0xe3, 0xdb, 0x88, 0xdb, + 0x3f, 0x00, 0xc1, 0xdb, 0x95, 0x24, 0x7d, 0x55, 0x2f, 0xe1, 0xa1, 0xa5, 0x70, 0x13, 0xd5, 0xc7, + 0x26, 0x41, 0x9f, 0x79, 0xc7, 0x5b, 0x30, 0x58, 0x65, 0x16, 0xa0, 0x0d, 0xac, 0x1d, 0xc8, 0x8d, + 0xe1, 0xce, 0xc2, 0x61, 0x0f, 0xb0, 0x02, 0xc9, 0x80, 0x1e, 0xbd, 0x25, 0x83, 0xbc, 0x9d, 0xdc +}; + +static unsigned char rsa_d_3072[] = { + 0x33, 0x49, 0x58, 0xb0, 0x89, 0x3d, 0x96, 0x78, 0xb7, 0x2a, 0x99, 0x5e, 0x0c, 0x56, 0xae, 0x08, + 0x32, 0xe1, 0xb9, 0x1c, 0x17, 0xd7, 0x71, 0xaa, 0x57, 0x37, 0x58, 0xbf, 0x94, 0xf8, 0xa0, 0xdf, + 0xdb, 0x0a, 0xfd, 0x2f, 0xce, 0x8a, 0x82, 0x43, 0x11, 0x48, 0x6b, 0xec, 0x61, 0x72, 0x77, 0x98, + 0x53, 0x00, 0x32, 0x5e, 0xbe, 0x3d, 0x37, 0xaf, 0x53, 0x55, 0x13, 0xc7, 0x61, 0x03, 0x6a, 0x28, + 0xc8, 0xe6, 0xa8, 0xac, 0x5f, 0xcf, 0x15, 0x54, 0x36, 0xc4, 0x74, 0x60, 0x3b, 0xcc, 0xbc, 0x4f, + 0x05, 0x27, 0x0d, 0x9e, 0x3c, 0x0c, 0x74, 0x1d, 0x59, 0xb7, 0x28, 0x05, 0x94, 0x2d, 0x0d, 0x02, + 0x60, 0xaa, 0x82, 0x14, 0x29, 0xf9, 0x38, 0x6a, 0xcb, 0x3a, 0xc4, 0x14, 0x70, 0xa4, 0x6b, 0x34, + 0xb6, 0xad, 0x11, 0xca, 0x4b, 0x76, 0x59, 0xd7, 0x29, 0xf1, 0x2e, 0xef, 0xf9, 0xa9, 0xf4, 0xd5, + 0x50, 0x13, 0x60, 0xc9, 0xac, 0x96, 0x14, 0x23, 0xdd, 0x3a, 0x2d, 0x9a, 0x9f, 0x58, 0xa8, 0xcb, + 0x70, 0xe4, 0x19, 0x45, 0x5c, 0xec, 0x7c, 0x64, 0xab, 0x76, 0x63, 0x07, 0xe0, 0x98, 0x5a, 0xbc, + 0x91, 0xc0, 0xbc, 0x84, 0xd5, 0x06, 0xef, 0xc4, 0xa2, 0xe0, 0x8f, 0x5a, 0xc9, 0x0e, 0x74, 0x3a, + 0x64, 0x80, 0x72, 0x8f, 0x62, 0xe4, 0x23, 0xe2, 0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8, 0x7d, + 0x9c, 0xa3, 0x00, 0xd0, 0x1d, 0xe1, 0x52, 0xc4, 0x71, 0x12, 0x5c, 0x53, 0xd6, 0x88, 0xfb, 0x81 +}; + +static unsigned char rsa_n_3072[] = { + 0xd2, 0x8f, 0x46, 0x62, 0x87, 0xde, 0x40, 0xdb, 0xdc, 0xd5, 0xf1, 0x7b, 0x14, 0x75, 0x7e, 0x5e, + 0xcb, 0x38, 0x7f, 0x9e, 0xc4, 0x30, 0xb6, 0x77, 0x6d, 0x20, 0x9a, 0x52, 0xe0, 0x0a, 0x9d, 0x34, + 0x09, 0xfd, 0x15, 0xbe, 0x36, 0x25, 0x71, 0x85, 0x0d, 0x6a, 0x33, 0x6d, 0x81, 0xd5, 0x74, 0x4c, + 0x2f, 0x8a, 0xd2, 0xad, 0xa0, 0x94, 0x26, 0x3d, 0xba, 0x1d, 0xe9, 0x33, 0xdc, 0x50, 0x6d, 0xc2, + 0xd1, 0xc9, 0xc9, 0xae, 0xd3, 0xf8, 0x31, 0x30, 0xc5, 0x33, 0xe5, 0xf7, 0x80, 0xcf, 0x33, 0x6d, + 0x50, 0xf0, 0xba, 0xa0, 0xd0, 0x86, 0x75, 0x21, 0xb9, 0x28, 0x02, 0x20, 0xf1, 0x7f, 0x1c, 0xe7, + 0xdb, 0xe6, 0x10, 0x5e, 0x5c, 0xf0, 0xea, 0x55, 0x89, 0x41, 0x1d, 0x93, 0x60, 0x59, 0x3a, 0x58, + 0x54, 0x93, 0x7c, 0x09, 0x62, 0xc0, 0x2d, 0x60, 0x8e, 0x49, 0x5e, 0x23, 0xe6, 0x90, 0x67, 0xe8, + 0x99, 0xb5, 0xe3, 0xf3, 0xb4, 0x9f, 0x29, 0xe7, 0x6b, 0xc9, 0x32, 0xd5, 0x98, 0xde, 0xb9, 0xad, + 0xd2, 0x28, 0x9b, 0xc6, 0x8e, 0xeb, 0x8a, 0xb0, 0xf3, 0x6d, 0x86, 0x71, 0x70, 0xba, 0x77, 0xf0, + 0xad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x6b, 0x81, 0x19, 0x07, 0xdd, 0x05, 0x91, 0xc2, 0x78, 0x32, + 0x72, 0x09, 0x62, 0x30, 0xf0, 0x73, 0x7b, 0xbc, 0x5e, 0x7d, 0x3d, 0xfe, 0x0d, 0x8b, 0xef, 0x31, + 0xdb, 0x8e, 0x28, 0x20, 0xae, 0x0e, 0xe0, 0x7d, 0x63, 0x79, 0x05, 0x1b, 0x13, 0x8a, 0x8d, 0x15 +}; + +static unsigned char rsa_e_4096[] = { + 0x01, 0x00, 0x01 +}; + +static unsigned char rsa_p_4096[] = { + 0xff, 0x0f, 0x4f, 0x6c, 0xdd, 0x59, 0xd8, 0x48, 0x87, 0xc3, 0x24, 0x04, 0x87, 0x63, 0xbe, 0xcd, + 0xa6, 0x51, 0xb6, 0xb8, 0xda, 0x31, 0x8f, 0xb0, 0xf7, 0x29, 0x08, 0x28, 0x60, 0xb0, 0xb1, 0x52, + 0xe4, 0x73, 0xf1, 0xdb, 0x10, 0xe3, 0xbc, 0xfc, 0x2d, 0x88, 0x43, 0xab, 0x2a, 0x2e, 0x41, 0x80, + 0x0f, 0x25, 0x62, 0x53, 0x8f, 0x09, 0x82, 0xd1, 0xe4, 0x12, 0xe3, 0x9f, 0xae, 0xe9, 0x5b, 0xe4, + 0x89, 0x97, 0xf7, 0x40, 0x0c, 0x78, 0x86, 0xd1, 0x23, 0xe7, 0xd3, 0x45, 0xc9, 0x15, 0xf8, 0xbf, + 0xe9, 0x3d, 0x44, 0x57, 0x21, 0x61, 0x62, 0xe1, 0xad, 0x9d, 0x28, 0x5c, 0x99, 0xfc, 0xec, 0xe1, + 0xcb, 0x93, 0x70, 0x28, 0x8d, 0xc2, 0x97, 0xc4, 0xc4, 0xaa, 0xb1, 0xe3, 0xb6, 0x61, 0x84, 0x0c, + 0x03, 0xc9, 0xf7, 0x96, 0xdf, 0x04, 0xdc, 0x15, 0x94, 0x35, 0x60, 0xfa, 0xe7, 0xc4, 0xc1, 0xc7, + 0x80, 0xfb, 0xa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x46, 0xa0, 0x01, 0xff, 0x52, 0xb7, 0xe7, 0x57, 0xe1, 0xe4, + 0xfc, 0xd0, 0x8e, 0xba, 0x87, 0x4c, 0xb9, 0x93, 0xca, 0xc9, 0x62, 0x2f, 0x6f, 0xde, 0x6b, 0xc7, + 0x2b, 0xf7, 0x5e, 0x24, 0x6f, 0xb3, 0x88, 0x9a, 0xb3, 0x89, 0x81, 0xae, 0x8e, 0x32, 0x99, 0xab, + 0xa5, 0xb5, 0xce, 0x6d, 0x60, 0xa9, 0x3a, 0xb2, 0xc3, 0x15, 0xfe, 0x97, 0xcd, 0x92, 0x56, 0x9d, + 0x63, 0x97, 0xad, 0x3e, 0x48, 0xcd, 0x05, 0x15, 0x31, 0x71, 0xfd, 0x8d, 0xb4, 0x5f, 0x32, 0x08, + 0xc3, 0x33, 0xf3, 0x69, 0x9e, 0xb7, 0xf6, 0x3a, 0x24, 0x4b, 0x34, 0xf3, 0x52, 0xac, 0xed, 0xdf, + 0x18, 0x79, 0xbb, 0x2f, 0x8f, 0xd6, 0xf4, 0xae, 0xe3, 0xae, 0x61, 0x9e, 0x32, 0x16, 0x08, 0x61 +}; + +static unsigned char rsa_dq_4096[] = { + 0xb8, 0x1a, 0x74, 0xe6, 0x96, 0x0a, 0x4e, 0x1f, 0xf0, 0x84, 0xf5, 0x52, 0xe4, 0xd4, 0x66, 0xe0, + 0x78, 0x0e, 0xc7, 0x45, 0xa7, 0xdc, 0x89, 0x8d, 0x06, 0x60, 0x5f, 0x54, 0xf7, 0x36, 0x4f, 0x27, + 0x70, 0xd3, 0x71, 0x4e, 0xf9, 0x79, 0x34, 0x39, 0xf7, 0xe1, 0xaf, 0xf0, 0x8d, 0xd3, 0x27, 0x94, + 0xca, 0x61, 0x66, 0x0d, 0x89, 0x0e, 0xc0, 0x12, 0x35, 0xc4, 0xff, 0x12, 0x1e, 0xba, 0xfb, 0x72, + 0x19, 0x68, 0xa7, 0x47, 0x7a, 0x96, 0x62, 0x37, 0x1b, 0x24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x9d +}; + +static unsigned char rsa_qinv_4096[] = { + 0x11, 0xc1, 0x35, 0xf3, 0xe0, 0x74, 0x80, 0x68, 0x32, 0xdd, 0x15, 0xdb, 0x92, 0x72, 0xad, 0xd8, + 0xfd, 0xfe, 0x78, 0xee, 0xfd, 0x8a, 0xaa, 0xd4, 0x47, 0x07, 0xc3, 0xcf, 0x35, 0xbd, 0x23, 0x3d, + 0x2b, 0x09, 0xed, 0xbe, 0xb6, 0x3d, 0xc1, 0xb7, 0x25, 0x79, 0x5e, 0x0c, 0x7c, 0x25, 0x2c, 0x8f, + 0x98, 0x34, 0x19, 0xc7, 0xdf, 0x74, 0x67, 0x6a, 0x2e, 0x3b, 0x99, 0x3d, 0x41, 0xee, 0x44, 0xe8, + 0xc5, 0x75, 0xc2, 0x05, 0xdc, 0x85, 0x04, 0x59, 0x45, 0x14, 0x70, 0xc2, 0x9c, 0xa8, 0xa9, 0x2b, + 0x04, 0x65, 0xe1, 0xba, 0x83, 0x5e, 0x03, 0x04, 0x78, 0xe4, 0x16, 0x2d, 0x14, 0xfa, 0x10, 0xeb, + 0xe4, 0x3e, 0x6d, 0x75, 0xb1, 0xe5, 0xc5, 0xe7, 0x98, 0x69, 0x9a, 0x1b, 0xab, 0x87, 0x05, 0x51, + 0x84, 0x73, 0x31, 0xd5, 0x61, 0x67, 0xdc, 0x70, 0xce, 0x12, 0xdc, 0x53, 0xa5, 0xe6, 0x12, 0xb2, + 0x85, 0x00, 0x14, 0x6f, 0x56, 0x5c, 0x35, 0xc7, 0xd0, 0xea, 0x51, 0xf7, 0xba, 0xe4, 0x6b, 0x13, + 0x0c, 0x4d, 0x3d, 0x82, 0xe0, 0x7b, 0xac, 0x4b, 0x7e, 0xfb, 0x95, 0x47, 0xa3, 0x90, 0x84, 0xdc, + 0x9b, 0xf1, 0x4a, 0x36, 0x85, 0x7a, 0x5e, 0x9e, 0x74, 0x59, 0x1c, 0x59, 0xaa, 0x7e, 0x30, 0x5b, + 0x0c, 0x03, 0x3a, 0xb3, 0x80, 0xc5, 0x0b, 0xf4, 0x04, 0x41, 0x21, 0x77, 0xdc, 0x89, 0x10, 0x09, + 0x32, 0xa2, 0xd3, 0xa8, 0xb2, 0x3f, 0x9e, 0xc8, 0x62, 0x68, 0x59, 0x83, 0x68, 0xf3, 0xe4, 0x1f, + 0x20, 0x64, 0x0e, 0x2c, 0x18, 0x5a, 0xd1, 0x16, 0x02, 0x1c, 0x73, 0x4e, 0xc4, 0x92, 0x79, 0x56, + 0x9f, 0x66, 0x7c, 0xa6, 0xf2, 0x5e, 0xb5, 0x04, 0xf6, 0xa2, 0xf6, 0x59, 0xe2, 0x8c, 0x85, 0x95, + 0x62, 0xd6, 0x20, 0x8d, 0x3d, 0x87, 0x88, 0xa1, 0xa2, 0xea, 0x68, 0xe1, 0x29, 0x99, 0xd3, 0x7e +}; + +static unsigned char rsa_d_4096[] = { + 0x15, 0x49, 0x6c, 0x18, 0x59, 0x19, 0x8d, 0x47, 0xa9, 0xf4, 0x83, 0xd9, 0x13, 0xa8, 0x60, 0xb7, + 0xcf, 0x53, 0x9d, 0xe1, 0xe8, 0xb2, 0x90, 0x3b, 0x2e, 0x9a, 0xd4, 0xed, 0x7f, 0xce, 0x16, 0x92, + 0xcb, 0xa4, 0x89, 0x38, 0xe8, 0x88, 0x1d, 0x7c, 0x7f, 0x8a, 0xdf, 0xa2, 0x7f, 0xf5, 0xcd, 0x18, + 0xd4, 0x51, 0xf7, 0x31, 0x8b, 0x54, 0x19, 0x0d, 0xfc, 0xfe, 0x87, 0x8b, 0x62, 0x94, 0x0c, 0xe2, + 0x50, 0x23, 0xbe, 0x22, 0xda, 0x5c, 0xbf, 0x00, 0xc7, 0xce, 0x0b, 0x1d, 0x0d, 0x9b, 0x74, 0x2e, + 0xad, 0xcd, 0x80, 0x2b, 0x69, 0x1b, 0x92, 0x86, 0xe9, 0x5b, 0x9e, 0x3a, 0xf2, 0x66, 0xd1, 0x64, + 0x93, 0xcb, 0x72, 0xb7, 0x86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0x49, 0x4a, 0xf3, 0xe3, 0x86, 0x5e, 0xc4, 0x16, 0x61, 0x5c, 0x80, 0x7a, 0x4d, 0x81, + 0x95, 0x8e, 0xa8, 0x15, 0x32, 0x2f, 0x46, 0x8c, 0x89, 0xe6, 0x2c, 0x75, 0x11, 0x16, 0xd5, 0xea, + 0xbf, 0x0c, 0x21, 0x75, 0x3a, 0xad, 0x9a, 0xd1, 0x3e, 0xd8, 0x4d, 0xee, 0x89, 0xe3, 0x6b, 0x51 +}; + +static unsigned char rsa_n_4096[] = { + 0xe7, 0xbd, 0x61, 0x33, 0xc2, 0xd8, 0x4c, 0x41, 0xa0, 0x3d, 0xd2, 0xa6, 0xad, 0x39, 0x2b, 0x62, + 0x26, 0x3f, 0x7f, 0xa3, 0xbe, 0xdf, 0x35, 0xd3, 0x62, 0x67, 0x3b, 0x09, 0xe5, 0x9d, 0xf4, 0x21, + 0x6f, 0x0b, 0xf1, 0x9a, 0x5a, 0xe0, 0x72, 0x80, 0xcf, 0x27, 0x99, 0x25, 0xea, 0x3d, 0x73, 0x70, + 0x7f, 0x03, 0x61, 0x9d, 0xca, 0x25, 0xf2, 0xd2, 0x29, 0x04, 0x1a, 0xf5, 0x08, 0xa6, 0xac, 0xc0, + 0x6d, 0x1f, 0x0e, 0x0e, 0xfd, 0x6e, 0x73, 0xe7, 0x1d, 0x60, 0x92, 0x13, 0xc3, 0x20, 0x39, 0x95, + 0x9a, 0x1e, 0x31, 0x07, 0x07, 0x45, 0x62, 0x97, 0xe4, 0xe4, 0x41, 0x98, 0xf2, 0x4c, 0x06, 0x9b, + 0xb1, 0x13, 0x28, 0x70, 0xa8, 0x2c, 0x99, 0x59, 0x8a, 0x85, 0x0b, 0x92, 0xde, 0x35, 0x9a, 0x68, + 0x9b, 0x9f, 0x8f, 0x70, 0x1e, 0x68, 0x22, 0x25, 0x32, 0xdf, 0x78, 0xac, 0xc3, 0x0b, 0x2f, 0x4e, + 0x26, 0x1c, 0x6a, 0xb9, 0x2d,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 0x03, 0xfd, 0xd3, 0x14, 0xbc, 0xc5, 0x64, 0x4c, 0x29, 0xd4, 0x27, 0x08, 0xe3, 0x69 +}; + +static unsigned char dh_g_5[] = {0x05}; +static unsigned char dh_g_2[] = {0x02}; + +static unsigned char dh_p_768[] = { + 0xdd, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, + 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, + 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x01, 0xf5, 0x1a, 0x4f, + 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, + 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_xa_768[] = { + 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, + 0xa2, 0x47, 0xd2, 0x0d, 0xee, 0xfe, 0xdc, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, + 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, + 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, + 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, + 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f +}; + +static unsigned char dh_except_a_pubkey_768[] = { + 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, + 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, + 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, + 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, + 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, + 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b +}; + +static unsigned char dh_except_b_pubkey_768[] = { + 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, + 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, + 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x1, 0xf5, 0x1a, 0x4f, + 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, + 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_share_key_768[] = { + 0x55, 0x9, 0x6b, 0x9c, 0xc6, 0x37, 0xa9, 0x9b, 0xdf, 0x67, 0x73, 0x7b, 0x46, 0xf9, 0x63, 0x47, + 0xcb, 0xa0, 0x57, 0x2a, 0xed, 0x97, 0x2f, 0xfe, 0x92, 0xf2, 0x20, 0x2c, 0x7e, 0xee, 0x7d, 0x11, + 0x78, 0xe6, 0xb9, 0x9, 0xd1, 0x94, 0xce, 0xd1, 0x5b, 0xf4, 0x44, 0xa9, 0xcb, 0x26, 0x2, 0x36, + 0x57, 0x2c, 0xa2, 0xbe, 0x37, 0xde, 0x86, 0x46, 0x20, 0x27, 0x9d, 0xa0, 0x2f, 0x4, 0xc1, 0xcd, + 0xff, 0x81, 0xe5, 0xe6, 0x2c, 0x9e, 0x39, 0x82, 0x31, 0x54, 0x33, 0xf8, 0xe7, 0xa0, 0xe5, 0x96, + 0xa4, 0x40, 0xc4, 0x44, 0xfe, 0x93, 0x66, 0xe2, 0xda, 0xaa, 0xb8, 0xfb, 0x2f, 0x3b, 0x8c, 0xce, +}; + +static unsigned char dh_p_1024[] = { + 0x6a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0x40, 0x18, 0x71, 0x07, 0x96, 0xa9, 0x56, 0x6e, + 0x45, 0x58, 0x24, 0xce, 0x75, 0x80, 0x3, 0x68, 0x36, 0x96, 0x03, 0xb2, 0x9c, 0x25, 0xbc, 0x55, + 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, + 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, + 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x01, 0xf5, 0x1a, 0x4f, + 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, + 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_xa_1024[] = { + 0x0f, 0x2a, 0x77, 0x25, 0x4b, 0xb3, 0xd3, 0x2d, 0xfd, 0x94, 0x8b, 0x53, 0x02, 0x21, 0x40, 0xd7, + 0x36, 0x76, 0xf3, 0xc8, 0xc0, 0x36, 0x3d, 0x23, 0xc9, 0xbd, 0x92, 0x51, 0xf2, 0x4b, 0x83, 0x15, + 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, + 0xa2, 0x47, 0xd2, 0x0d, 0xee, 0xfe, 0xdc, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, + 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, + 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, + 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, + 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f +}; + +static unsigned char dh_except_a_pubkey_1024[] = { + 0x5d, 0xa6, 0x7, 0x56, 0x93, 0x89, 0xe5, 0x0f, 0x2a, 0xb5, 0x67, 0x3a, 0xcf, 0xc3, 0x82, 0x83, + 0xf6, 0x88, 0x52, 0x0b, 0xfc, 0x6a, 0x5b, 0x1a, 0x57, 0x87, 0x86, 0xef, 0xda, 0x47, 0xdb, 0x4d, + 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, + 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, + 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, + 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, + 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, + 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b +}; + +static unsigned char dh_except_b_pubkey_1024[] = { + 0x4a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0x40, 0x18, 0x71, 0x7, 0x96, 0xa9, 0x56, 0x6e, + 0x45, 0x58, 0x24, 0xce, 0x75, 0x80, 0x3, 0x68, 0x36, 0x96, 0x3, 0xb2, 0x9c, 0x25, 0xbc, 0x55, + 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, + 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, + 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x1, 0xf5, 0x1a, 0x4f, + 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, + 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_share_key_1024[] = { + 0xcc, 0x48, 0x97, 0xe4, 0x21, 0x65, 0xa6, 0x55, 0xb8, 0xf3, 0xb2, 0x7b, 0x91, 0xd7, 0xca, 0xb9, + 0x17, 0x58, 0x31, 0x71, 0xc0, 0xc9, 0x69, 0x1e, 0xf0, 0x9e, 0x3f, 0xe2, 0x37, 0x4, 0x2d, 0xa8, + 0x55, 0x9, 0x6b, 0x9c, 0xc6, 0x37, 0xa9, 0x9b, 0xdf, 0x67, 0x73, 0x7b, 0x46, 0xf9, 0x63, 0x47, + 0xcb, 0xa0, 0x57, 0x2a, 0xed, 0x97, 0x2f, 0xfe, 0x92, 0xf2, 0x20, 0x2c, 0x7e, 0xee, 0x7d, 0x11, + 0x78, 0xe6, 0xb9, 0x9, 0xd1, 0x94, 0xce, 0xd1, 0x5b, 0xf4, 0x44, 0xa9, 0xcb, 0x26, 0x2, 0x36, + 0x57, 0x2c, 0xa2, 0xbe, 0x37, 0xde, 0x86, 0x46, 0x20, 0x27, 0x9d, 0xa0, 0x2f, 0x4, 0xc1, 0xcd, + 0xff, 0x81, 0xe5, 0xe6, 0x2c, 0x9e, 0x39, 0x82, 0x31, 0x54, 0x33, 0xf8, 0xe7, 0xa0, 0xe5, 0x96, + 0xa4, 0x40, 0xc4, 0x44, 0xfe, 0x93, 0x66, 0xe2, 0xda, 0xaa, 0xb8, 0xfb, 0x2f, 0x3b, 0x8c, 0xce, +}; + +static unsigned char dh_p_1536[] = { + 0xe3,0x7d,0xa7,0x4a,0xcc,0xef,0xce,0xa6,0xde,0x1d,0x3d,0xc5,0x2b,0xaa,0x6b,0x83, + 0xec,0x87,0x60,0xcd,0xc6,0xe4,0x16,0x0d,0xe7,0xb9,0x20,0x0e,0x10,0x50,0x35,0x22, + 0xd6,0xdb,0xbf,0x6,0xcc,0x7b,0x8e,0xe1,0x68,0x38,0x76,0x5f,0x0a,0x68,0xa8,0xfd, + 0x3f,0x40,0x51,0x46,0x45,0x64,0x53,0x22,0xcf,0x8,0xe2,0xef,0xd2,0x6f,0x28,0x84, + 0x14,0xb3,0xa6,0x24,0x49,0x6f,0x49,0x6c,0x0a,0x13,0xb6,0x78,0x4f,0xa4,0xd0,0xc4, + 0x20,0x6c,0x7,0x4c,0x6b,0xf7,0x8c,0x72,0x16,0x6c,0x99,0xd2,0x44,0x9e,0x63,0x5, + 0xfc,0x3a,0xa9,0x33,0x16,0x0b,0xc4,0x1a,0xf0,0xc7,0x25,0xcd,0xc6,0x3a,0x8e,0x66, + 0xa2,0xeb,0x70,0xb9,0x59,0xd9,0xb7,0xdd,0x68,0x45,0x26,0x20,0xfa,0x58,0x6f,0xd6, + 0x3f,0xd8,0xf2,0x52,0xd5,0x3a,0x16,0x7,0xdd,0xb4,0x63,0x0c,0xfe,0x8,0x67,0xd0, + 0x9f,0x8a,0xe0,0xe9,0x25,0xa0,0x0e,0x5,0x8e,0xe5,0x56,0xa6,0xc3,0x5b,0x0b,0xb5, + 0x41,0x33,0xd0,0xdb,0x89,0xbd,0x3b,0xaf,0x33,0x7e,0xae,0xff,0x20,0xef,0xa9,0x3c, + 0xd7,0xb5,0x45,0x61,0x50,0x76,0x60,0x89,0x6a,0xbb,0x9c,0x3e,0xcb,0xcb,0xdb,0x0b, +}; + +static unsigned char dh_xa_1536[] = { + 0x56,0x68,0x23,0x22,0x49,0x24,0xf2,0x21,0xee,0x5f,0x12,0x46,0xe2,0xea,0x69,0x93, + 0x0,0xf5,0x10,0x1d,0x4d,0x96,0x7b,0xa4,0x9d,0xab,0xbe,0xdf,0x8e,0xcc,0xa5,0x0e, + 0x84,0x12,0x4e,0x77,0xc0,0x46,0x6b,0x51,0x11,0x46,0x4f,0x73,0x1e,0x1c,0x1c,0xd1, + 0x3,0xea,0x0e,0x11,0xdb,0xa3,0xa6,0x14,0xdb,0xdc,0x3e,0xc5,0x7f,0x7d,0x7a,0x69, + 0xa1,0x38,0x70,0x95,0xa5,0x2d,0x47,0xa3,0x0f,0xcf,0xf9,0x7c,0x2,0x4e,0x52,0x4c, + 0xd6,0x5b,0x9e,0xf3,0x7f,0x64,0x70,0x13,0x59,0x8e,0x44,0x31,0x92,0x1b,0xb4,0xaa, + 0xf9,0x64,0xfd,0xb7,0x3c,0x81,0xc0,0xf9,0x66,0x5d,0xff,0x9,0x3e,0x26,0xaf,0x1a, + 0xc0,0xd2,0xd9,0x7c,0x0e,0x6f,0x81,0x12,0x82,0x90,0x1b,0x37,0xb7,0x1a,0x7e,0x36, + 0x79,0x15,0xb1,0xe1,0xd5,0x2d,0x72,0xd4,0x47,0xf7,0x30,0x3c,0x17,0xe1,0x76,0x15, + 0xbc,0x17,0xdc,0x9d,0xd9,0xfc,0xfd,0xb6,0xe6,0xbd,0x8e,0x47,0x8d,0xbb,0xa8,0x8a, + 0xe7,0xe7,0x57,0xf2,0xd8,0x80,0x4c,0xdd,0xe7,0xaf,0x29,0xee,0x40,0x4e,0x2,0xad, + 0xec,0xb3,0x18,0x8e,0x4b,0x2d,0xd2,0x28,0x4e,0x58,0x85,0x29,0xe3,0x93,0x1b,0xa7, +}; + +static unsigned char dh_except_a_pubkey_1536[] = { + 0x97,0x1e,0x6d,0xf7,0xb1,0x2f,0xa7,0x82,0x9e,0x99,0x22,0xfb,0xf3,0x4e,0x2a,0x73, + 0xcc,0xd9,0x2b,0x10,0x1,0xfb,0xac,0xf1,0x81,0xfe,0x78,0x3d,0x23,0xb0,0xcf,0x5c, + 0x95,0x69,0x36,0xc0,0x99,0x6a,0xd2,0x9c,0xf0,0x85,0x8d,0xda,0x5d,0xba,0x8e,0x0f, + 0xa3,0xce,0xbe,0x9b,0xe8,0x3b,0xad,0x71,0xfd,0xfd,0x53,0x25,0xee,0x61,0x26,0x15, + 0x0a,0x46,0x9e,0xce,0x85,0xb1,0x5c,0xf1,0xa0,0x8f,0xe7,0x89,0xe3,0x4f,0x7c,0xea, + 0x18,0xd3,0xa9,0x44,0xce,0x35,0x9,0x86,0x80,0x8c,0x30,0x1,0xbc,0x6d,0xf6,0x6a, + 0x3a,0xa6,0xad,0xbe,0xfa,0x73,0x6b,0xb0,0x35,0x8c,0x63,0x80,0xb6,0x58,0x51,0x6e, + 0x4c,0x5d,0x4a,0xe9,0xa9,0x72,0x6,0x9f,0xa2,0x3e,0x64,0xaf,0x70,0x63,0xee,0x2a, + 0x5d,0x73,0xf3,0xdc,0xa3,0x32,0x0f,0x8,0x48,0xcf,0x13,0x80,0x0d,0xdb,0x91,0xdf, + 0x87,0x99,0xa4,0x8a,0x50,0xe9,0x75,0x43,0xfb,0x56,0xd7,0x89,0xc3,0x10,0x7e,0xd0, + 0xb7,0x46,0xd8,0x41,0x91,0xdf,0xb1,0x91,0x8e,0xc1,0x58,0xd7,0x7c,0x33,0x1e,0xb3, + 0xa3,0xda,0xcb,0xf5,0x0,0x76,0xe4,0xee,0x20,0xd6,0x9d,0x8a,0x28,0xa4,0xdb,0xf9, +}; + +static unsigned char dh_except_b_pubkey_1536[] = { + 0x44, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x9, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, + 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd2, 0x12, 0x59, 0x35, 0xcc, 0x39, + 0x99, 0x4, 0xe8, 0x9a, 0xd2, 0x0, 0x7a, 0xce, 0x3c, 0x78, 0xfe, 0xea, 0x4b, 0x13, 0x53, 0xcd, + 0xc3, 0x60, 0x73, 0xa4, 0x3f, 0xbc, 0x8a, 0x8d, 0x61, 0x1c, 0xfa, 0xaf, 0xb7, 0xf8, 0x37, 0xa5, + 0xe2, 0x3a, 0xd2, 0x7a, 0xb6, 0x0, 0xf3, 0xd8, 0x3a, 0xa2, 0x46, 0xd2, 0x5c, 0x91, 0xc1, 0x5, + 0x6a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0x40, 0x18, 0x71, 0x7, 0x96, 0xa9, 0x56, 0x6e, + 0x45, 0x58, 0x24, 0xce, 0x75, 0x80, 0x3, 0x68, 0x36, 0x96, 0x3, 0xb2, 0x9c, 0x25, 0xbc, 0x55, + 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, +}; + +static unsigned char dh_share_key_1536[] = { + 0xaf, 0xd4, 0xf6, 0x45, 0x63, 0x21, 0x8d, 0x98, 0xc4, 0xab, 0x18, 0xd7, 0x2b, 0x3c, 0x1d, 0xde, + 0xe7, 0x1f, 0xe1, 0xc5, 0x79, 0x57, 0x60, 0x20, 0xfa, 0x99, 0xbd, 0x7b, 0xa2, 0x94, 0x0b, 0xa3, + 0xb4, 0xb3, 0x33, 0x4a, 0x2f, 0xd0, 0x17, 0x7, 0x2e, 0x70, 0x19, 0x84, 0x1f, 0x8e, 0xe9, 0x61, + 0xe5, 0x52, 0x3, 0x96, 0xea, 0xd8, 0xb6, 0x3, 0x9f, 0xc4, 0x3e, 0x23, 0x77, 0x17, 0x54, 0xfb, + 0x13, 0xf0, 0x3e, 0x9a, 0x27, 0x5d, 0x12, 0x99, 0x58, 0x8d, 0x41, 0x46, 0xd9, 0xc9, 0x29, 0xbd, + 0x40, 0xd1, 0x4f, 0xef, 0x63, 0x7b, 0x54, 0xe6, 0x59, 0x6d, 0xe2, 0x30, 0xe8, 0x2c, 0x2f, 0xf9, + 0x66, 0xa2, 0x12, 0xf5, 0x58, 0x61, 0xac, 0x43, 0xec, 0x7e, 0xf9, 0x2e, 0x27, 0x70, 0x35, 0x75, + 0xb4, 0x10, 0x29, 0xac, 0x0a, 0xab, 0x59, 0xb6, 0x68, 0x4c, 0x16, 0xaf, 0xf0, 0x4f, 0x21, 0xcd, + 0xcc, 0x48, 0x97, 0xe4, 0x21, 0x65, 0xa6, 0x55, 0xb8, 0xf3, 0xb2, 0x7b, 0x91, 0xd7, 0xca, 0xb9, + 0x17, 0x58, 0x31, 0x71, 0xc0, 0xc9, 0x69, 0x1e, 0xf0, 0x9e, 0x3f, 0xe2, 0x37, 0x4, 0x2d, 0xa8, + 0x55, 0x9, 0x6b, 0x9c, 0xc6, 0x37, 0xa9, 0x9b, 0xdf, 0x67, 0x73, 0x7b, 0x46, 0xf9, 0x63, 0x47, + 0xcb, 0xa0, 0x57, 0x2a, 0xed, 0x97, 0x2f, 0xfe, 0x92, 0xf2, 0x20, 0x2c, 0x7e, 0xee, 0x7d, 0x11, +}; + +static unsigned char dh_p_2048[] = { + 0xce, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x09, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, + 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd2, 0x12, 0x59, 0x35, 0xcc, 0x39, + 0x99, 0x04, 0xe8, 0x9a, 0xd2, 0x00, 0x7a, 0xce, 0x3c, 0x78, 0xfe, 0xea, 0x4b, 0x13, 0x53, 0xcd, + 0xc3, 0x60, 0x73, 0xa4, 0x3f, 0xbc, 0x8a, 0x8d, 0x61, 0x1c, 0xfa, 0xaf, 0xb7, 0xf8, 0x37, 0xa5, + 0xe2, 0x3a, 0xd2, 0x7a, 0xb6, 0x00, 0xf3, 0xd8, 0x3a, 0xa2, 0x46, 0xd2, 0x5c, 0x91, 0xc1, 0x05, + 0x6a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0x40, 0x18, 0x71, 0x07, 0x96, 0xa9, 0x56, 0x6e, + 0x45, 0x58, 0x24, 0xce, 0x75, 0x80, 0x3, 0x68, 0x36, 0x96, 0x03, 0xb2, 0x9c, 0x25, 0xbc, 0x55, + 0x0d, 0xe8, 0xa1, 0x7d, 0xdd, 0x39, 0x87, 0x3c, 0xa1, 0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, + 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, + 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x01, 0xf5, 0x1a, 0x4f, + 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, + 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_xa_2048[] = { + 0x6b, 0x1f, 0xc4, 0x85, 0x98, 0xc3, 0x01, 0xda, 0x39, 0xf0, 0x1b, 0x76, 0x5d, 0x81, 0x1d, 0x1f, + 0xc9, 0x93, 0x95, 0xc1, 0xf8, 0xd1, 0x67, 0x2c, 0xd4, 0x0a, 0x67, 0xf0, 0x40, 0x86, 0x82, 0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, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, + 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, + 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f +}; + +static unsigned char dh_except_a_pubkey_2048[] = { + 0xa5, 0x24, 0x63, 0x20, 0xb2, 0x56, 0x9a, 0x94, 0x97, 0xf7, 0x88, 0x41, 0x35, 0xeb, 0x52, 0x37, + 0xa4, 0xf2, 0x74, 0x1b, 0x38, 0xe4, 0x4c, 0x8b, 0x4b, 0xd2, 0xa5, 0xad, 0xb8, 0x2f, 0x7b, 0x5a, + 0xfd, 0xbc, 0x9c, 0xe0, 0xea, 0x9e, 0x82, 0x3, 0x62, 0xe2, 0xdc, 0x6c, 0x56, 0x9, 0x2, 0x28, + 0xb8, 0x2d, 0xb8, 0x46, 0xaf, 0x3a, 0xf4, 0x51, 0xf7, 0x4d, 0xc4, 0xd9, 0xa9, 0x1d, 0x67, 0x9d, + 0x2b, 0x18, 0x56, 0x86, 0x2a, 0x3, 0x19, 0xe9, 0x6, 0xeb, 0x4a, 0x6f, 0x2a, 0x40, 0x28, 0xbb, + 0x3e, 0x87, 0xc1, 0xce, 0x39, 0x6e, 0x3b, 0x1f, 0xb0, 0x9, 0x33, 0x67, 0x19, 0x0e, 0x1a, 0xb2, + 0xb3, 0x7d, 0xd3, 0xe6, 0x33, 0xf4, 0x7c, 0x82, 0x73, 0x7b, 0xb6, 0x16, 0x55, 0xff, 0x76, 0xaf, + 0x7f, 0xc2, 0x42, 0x51, 0xa9, 0xad, 0x1e, 0x72, 0xc9, 0x63, 0xab, 0x41, 0x5a, 0x26, 0x32, 0x39, + 0x5d, 0xa6, 0x7, 0x56, 0x93, 0x89, 0xe5, 0x0f, 0x2a, 0xb5, 0x67, 0x3a, 0xcf, 0xc3, 0x82, 0x83, + 0xf6, 0x88, 0x52, 0x0b, 0xfc, 0x6a, 0x5b, 0x1a, 0x57, 0x87, 0x86, 0xef, 0xda, 0x47, 0xdb, 0x4d, + 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, + 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, + 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, + 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, + 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, + 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b +}; + +static unsigned char dh_except_b_pubkey_2048[] = { + 0x44, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x9, 0x84, 0x32, 0x34, 0xf7, 0x46, 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d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_share_key_2048[] = { + 0xaf, 0xd4, 0xf6, 0x45, 0x63, 0x21, 0x8d, 0x98, 0xc4, 0xab, 0x18, 0xd7, 0x2b, 0x3c, 0x1d, 0xde, + 0xe7, 0x1f, 0xe1, 0xc5, 0x79, 0x57, 0x60, 0x20, 0xfa, 0x99, 0xbd, 0x7b, 0xa2, 0x94, 0x0b, 0xa3, + 0xb4, 0xb3, 0x33, 0x4a, 0x2f, 0xd0, 0x17, 0x7, 0x2e, 0x70, 0x19, 0x84, 0x1f, 0x8e, 0xe9, 0x61, + 0xe5, 0x52, 0x3, 0x96, 0xea, 0xd8, 0xb6, 0x3, 0x9f, 0xc4, 0x3e, 0x23, 0x77, 0x17, 0x54, 0xfb, + 0x13, 0xf0, 0x3e, 0x9a, 0x27, 0x5d, 0x12, 0x99, 0x58, 0x8d, 0x41, 0x46, 0xd9, 0xc9, 0x29, 0xbd, + 0x40, 0xd1, 0x4f, 0xef, 0x63, 0x7b, 0x54, 0xe6, 0x59, 0x6d, 0xe2, 0x30, 0xe8, 0x2c, 0x2f, 0xf9, + 0x66, 0xa2, 0x12, 0xf5, 0x58, 0x61, 0xac, 0x43, 0xec, 0x7e, 0xf9, 0x2e, 0x27, 0x70, 0x35, 0x75, + 0xb4, 0x10, 0x29, 0xac, 0x0a, 0xab, 0x59, 0xb6, 0x68, 0x4c, 0x16, 0xaf, 0xf0, 0x4f, 0x21, 0xcd, + 0xcc, 0x48, 0x97, 0xe4, 0x21, 0x65, 0xa6, 0x55, 0xb8, 0xf3, 0xb2, 0x7b, 0x91, 0xd7, 0xca, 0xb9, + 0x17, 0x58, 0x31, 0x71, 0xc0, 0xc9, 0x69, 0x1e, 0xf0, 0x9e, 0x3f, 0xe2, 0x37, 0x4, 0x2d, 0xa8, + 0x55, 0x9, 0x6b, 0x9c, 0xc6, 0x37, 0xa9, 0x9b, 0xdf, 0x67, 0x73, 0x7b, 0x46, 0xf9, 0x63, 0x47, + 0xcb, 0xa0, 0x57, 0x2a, 0xed, 0x97, 0x2f, 0xfe, 0x92, 0xf2, 0x20, 0x2c, 0x7e, 0xee, 0x7d, 0x11, + 0x78, 0xe6, 0xb9, 0x9, 0xd1, 0x94, 0xce, 0xd1, 0x5b, 0xf4, 0x44, 0xa9, 0xcb, 0x26, 0x2, 0x36, + 0x57, 0x2c, 0xa2, 0xbe, 0x37, 0xde, 0x86, 0x46, 0x20, 0x27, 0x9d, 0xa0, 0x2f, 0x4, 0xc1, 0xcd, + 0xff, 0x81, 0xe5, 0xe6, 0x2c, 0x9e, 0x39, 0x82, 0x31, 0x54, 0x33, 0xf8, 0xe7, 0xa0, 0xe5, 0x96, + 0xa4, 0x40, 0xc4, 0x44, 0xfe, 0x93, 0x66, 0xe2, 0xda, 0xaa, 0xb8, 0xfb, 0x2f, 0x3b, 0x8c, 0xce, +}; + +static unsigned char dh_p_3072[] = { + 0xce, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x09, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, + 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd2, 0x12, 0x59, 0x35, 0xcc, 0x39, + 0x99, 0x04, 0xe8, 0x9a, 0xd2, 0x00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, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x09, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, + 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd2, 0x12, 0x59, 0x35, 0xcc, 0x39, + 0x99, 0x04, 0xe8, 0x9a, 0xd2, 0x00, 0x7a, 0xce, 0x3c, 0x78, 0xfe, 0xea, 0x4b, 0x13, 0x53, 0xcd, + 0xc3, 0x60, 0x73, 0xa4, 0x3f, 0xbc, 0x8a, 0x8d, 0x61, 0x1c, 0xfa, 0xaf, 0xb7, 0xf8, 0x37, 0xa5, + 0xe2, 0x3a, 0xd2, 0x7a, 0xb6, 0x00, 0xf3, 0xd8, 0x3a, 0xa2, 0x46, 0xd2, 0x5c, 0x91, 0xc1, 0x05, +}; + +static unsigned char dh_xa_3072[] = { + 0x6b, 0x1f, 0xc4, 0x85, 0x98, 0xc3, 0x01, 0xda, 0x39, 0xf0, 0x1b, 0x76, 0x5d, 0x81, 0x1d, 0x1f, + 0xc9, 0x93, 0x95, 0xc1, 0xf8, 0xd1, 0x67, 0x2c, 0xd4, 0x0a, 0x67, 0xf0, 0x40, 0x86, 0x82, 0x7f, + 0x8f, 0x9d, 0x79, 0x04, 0xee, 0x4a, 0x54, 0xc9, 0x9c, 0x7f, 0xda, 0x15, 0x13, 0xc6, 0x95, 0xfb, + 0xfc, 0x7b, 0xe7, 0xd8, 0xde, 0x2a, 0xd8, 0xfd, 0xff, 0xdb, 0xa4, 0x7f, 0x4b, 0x37, 0x5d, 0x42, + 0xb6, 0x46, 0x4c, 0xbc, 0x34, 0x23, 0x99, 0x74, 0xf8, 0x80, 0x1b, 0xc1, 0x97, 0x34, 0xdf, 0x23, + 0x15, 0xa2, 0x8b, 0xec, 0xf3, 0x3e, 0x20, 0x93, 0x63, 0x88, 0x17, 0x70, 0x75, 0xbb, 0x9d, 0xb8, + 0x32, 0xb0, 0xae, 0xb5, 0x24, 0x6a, 0x86, 0xf6, 0xc1, 0x60, 0x41, 0xc4, 0xf4, 0x95, 0x6e, 0x10, + 0x2f, 0xd8, 0x58, 0x56, 0x42, 0x82, 0x71, 0x85, 0x19, 0xde, 0x91, 0xf0, 0x2f, 0x30, 0x0c, 0x63, + 0x0f, 0x2a, 0x77, 0x25, 0x4b, 0xb3, 0xd3, 0x2d, 0xfd, 0x94, 0x8b, 0x53, 0x02, 0x21, 0x40, 0xd7, + 0x36, 0x76, 0xf3, 0xc8, 0xc0, 0x36, 0x3d, 0x23, 0xc9, 0xbd, 0x92, 0x51, 0xf2, 0x4b, 0x83, 0x15, + 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, + 0xa2, 0x47, 0xd2, 0x0d, 0xee, 0xfe, 0xdc, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, + 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, + 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, + 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, + 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f, + 0x6b, 0x1f, 0xc4, 0x85, 0x98, 0xc3, 0x01, 0xda, 0x39, 0xf0, 0x1b, 0x76, 0x5d, 0x81, 0x1d, 0x1f, + 0xc9, 0x93, 0x95, 0xc1, 0xf8, 0xd1, 0x67, 0x2c, 0xd4, 0x0a, 0x67, 0xf0, 0x40, 0x86, 0x82, 0x7f, + 0x8f, 0x9d, 0x79, 0x04, 0xee, 0x4a, 0x54, 0xc9, 0x9c, 0x7f, 0xda, 0x15, 0x13, 0xc6, 0x95, 0xfb, + 0xfc, 0x7b, 0xe7, 0xd8, 0xde, 0x2a, 0xd8, 0xfd, 0xff, 0xdb, 0xa4, 0x7f, 0x4b, 0x37, 0x5d, 0x42, + 0xb6, 0x46, 0x4c, 0xbc, 0x34, 0x23, 0x99, 0x74, 0xf8, 0x80, 0x1b, 0xc1, 0x97, 0x34, 0xdf, 0x23, + 0x15, 0xa2, 0x8b, 0xec, 0xf3, 0x3e, 0x20, 0x93, 0x63, 0x88, 0x17, 0x70, 0x75, 0xbb, 0x9d, 0xb8, + 0x32, 0xb0, 0xae, 0xb5, 0x24, 0x6a, 0x86, 0xf6, 0xc1, 0x60, 0x41, 0xc4, 0xf4, 0x95, 0x6e, 0x10, + 0x2f, 0xd8, 0x58, 0x56, 0x42, 0x82, 0x71, 0x85, 0x19, 0xde, 0x91, 0xf0, 0x2f, 0x30, 0x0c, 0x63, +}; + +static unsigned char dh_except_a_pubkey_3072[] = { + 0xa5, 0x24, 0x63, 0x20, 0xb2, 0x56, 0x9a, 0x94, 0x97, 0xf7, 0x88, 0x41, 0x35, 0xeb, 0x52, 0x37, + 0xa4, 0xf2, 0x74, 0x1b, 0x38, 0xe4, 0x4c, 0x8b, 0x4b, 0xd2, 0xa5, 0xad, 0xb8, 0x2f, 0x7b, 0x5a, + 0xfd, 0xbc, 0x9c, 0xe0, 0xea, 0x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27, 0x13, 0xab, + 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, + 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b, + 0xa5, 0x24, 0x63, 0x20, 0xb2, 0x56, 0x9a, 0x94, 0x97, 0xf7, 0x88, 0x41, 0x35, 0xeb, 0x52, 0x37, + 0xa4, 0xf2, 0x74, 0x1b, 0x38, 0xe4, 0x4c, 0x8b, 0x4b, 0xd2, 0xa5, 0xad, 0xb8, 0x2f, 0x7b, 0x5a, + 0xfd, 0xbc, 0x9c, 0xe0, 0xea, 0x9e, 0x82, 0x3, 0x62, 0xe2, 0xdc, 0x6c, 0x56, 0x9, 0x2, 0x28, + 0xb8, 0x2d, 0xb8, 0x46, 0xaf, 0x3a, 0xf4, 0x51, 0xf7, 0x4d, 0xc4, 0xd9, 0xa9, 0x1d, 0x67, 0x9d, + 0x2b, 0x18, 0x56, 0x86, 0x2a, 0x3, 0x19, 0xe9, 0x6, 0xeb, 0x4a, 0x6f, 0x2a, 0x40, 0x28, 0xbb, + 0x3e, 0x87, 0xc1, 0xce, 0x39, 0x6e, 0x3b, 0x1f, 0xb0, 0x9, 0x33, 0x67, 0x19, 0x0e, 0x1a, 0xb2, + 0xb3, 0x7d, 0xd3, 0xe6, 0x33, 0xf4, 0x7c, 0x82, 0x73, 0x7b, 0xb6, 0x16, 0x55, 0xff, 0x76, 0xaf, + 0x7f, 0xc2, 0x42, 0x51, 0xa9, 0xad, 0x1e, 0x72, 0xc9, 0x63, 0xab, 0x41, 0x5a, 0x26, 0x32, 0x39, +}; + +static unsigned char dh_except_b_pubkey_3072[] = { + 0x44, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42,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xa2, 0x46, 0xd2, 0x5c, 0x91, 0xc1, 0x5, +}; + +static unsigned char dh_share_key_3072[] = { + 0xaf, 0xd4, 0xf6, 0x45, 0x63, 0x21, 0x8d, 0x98, 0xc4, 0xab, 0x18, 0xd7, 0x2b, 0x3c, 0x1d, 0xde, + 0xe7, 0x1f, 0xe1, 0xc5, 0x79, 0x57, 0x60, 0x20, 0xfa, 0x99, 0xbd, 0x7b, 0xa2, 0x94, 0x0b, 0xa3, + 0xb4, 0xb3, 0x33, 0x4a, 0x2f, 0xd0, 0x17, 0x7, 0x2e, 0x70, 0x19, 0x84, 0x1f, 0x8e, 0xe9, 0x61, + 0xe5, 0x52, 0x3, 0x96, 0xea, 0xd8, 0xb6, 0x3, 0x9f, 0xc4, 0x3e, 0x23, 0x77, 0x17, 0x54, 0xfb, + 0x13, 0xf0, 0x3e, 0x9a, 0x27, 0x5d, 0x12, 0x99, 0x58, 0x8d, 0x41, 0x46, 0xd9, 0xc9, 0x29, 0xbd, + 0x40, 0xd1, 0x4f, 0xef, 0x63, 0x7b, 0x54, 0xe6, 0x59, 0x6d, 0xe2, 0x30, 0xe8, 0x2c, 0x2f, 0xf9, + 0x66, 0xa2, 0x12, 0xf5, 0x58, 0x61, 0xac, 0x43, 0xec, 0x7e, 0xf9, 0x2e, 0x27, 0x70, 0x35, 0x75, + 0xb4, 0x10, 0x29, 0xac, 0x0a, 0xab, 0x59, 0xb6, 0x68, 0x4c, 0x16, 0xaf, 0xf0, 0x4f, 0x21, 0xcd, + 0xcc, 0x48, 0x97, 0xe4, 0x21, 0x65, 0xa6, 0x55, 0xb8, 0xf3, 0xb2, 0x7b, 0x91, 0xd7, 0xca, 0xb9, + 0x17, 0x58, 0x31, 0x71, 0xc0, 0xc9, 0x69, 0x1e, 0xf0, 0x9e, 0x3f, 0xe2, 0x37, 0x4, 0x2d, 0xa8, + 0x55, 0x9, 0x6b, 0x9c, 0xc6, 0x37, 0xa9, 0x9b, 0xdf, 0x67, 0x73, 0x7b, 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 0xf5, 0x58, 0x61, 0xac, 0x43, 0xec, 0x7e, 0xf9, 0x2e, 0x27, 0x70, 0x35, 0x75, + 0xb4, 0x10, 0x29, 0xac, 0x0a, 0xab, 0x59, 0xb6, 0x68, 0x4c, 0x16, 0xaf, 0xf0, 0x4f, 0x21, 0xcd, +}; + +static unsigned char dh_p_4096[] = { + 0xce, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x09, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9, 0xb5, 0x97, + 0xc2, 0x4a, 0x6f, 0x41, 0x40, 0xc9, 0x9e, 0x63, 0xe1, 0x0f, 0xd2, 0x12, 0x59, 0x35, 0xcc, 0x39, + 0x99, 0x04, 0xe8, 0x9a, 0xd2, 0x00, 0x7a, 0xce, 0x3c, 0x78, 0xfe, 0xea, 0x4b, 0x13, 0x53, 0xcd, + 0xc3, 0x60, 0x73, 0xa4, 0x3f, 0xbc, 0x8a, 0x8d, 0x61, 0x1c, 0xfa, 0xaf, 0xb7, 0xf8, 0x37, 0xa5, + 0xe2, 0x3a, 0xd2, 0x7a, 0xb6, 0x00, 0xf3, 0xd8, 0x3a, 0xa2, 0x46, 0xd2, 0x5c, 0x91, 0xc1, 0x05, + 0x6a, 0xf3, 0x2c, 0xd2, 0x2d, 0x55, 0xc1, 0x54, 0x40, 0x18, 0x71, 0x07, 0x96, 0xa9, 0x56, 0x6e, + 0x45, 0x58, 0x24, 0xce, 0x75, 0x80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; + +static unsigned char dh_xa_4096[] = { + 0x6b, 0x1f, 0xc4, 0x85, 0x98, 0xc3, 0x01, 0xda, 0x39, 0xf0, 0x1b, 0x76, 0x5d, 0x81, 0x1d, 0x1f, + 0xc9, 0x93, 0x95, 0xc1, 0xf8, 0xd1, 0x67, 0x2c, 0xd4, 0x0a, 0x67, 0xf0, 0x40, 0x86, 0x82, 0x7f, + 0x8f, 0x9d, 0x79, 0x04, 0xee, 0x4a, 0x54, 0xc9, 0x9c, 0x7f, 0xda, 0x15, 0x13, 0xc6, 0x95, 0xfb, + 0xfc, 0x7b, 0xe7, 0xd8, 0xde, 0x2a, 0xd8, 0xfd, 0xff, 0xdb, 0xa4, 0x7f, 0x4b, 0x37, 0x5d, 0x42, + 0xb6, 0x46, 0x4c, 0xbc, 0x34, 0x23, 0x99, 0x74, 0xf8, 0x80, 0x1b, 0xc1, 0x97, 0x34, 0xdf, 0x23, + 0x15, 0xa2, 0x8b, 0xec, 0xf3, 0x3e, 0x20, 0x93, 0x63, 0x88, 0x17, 0x70, 0x75, 0xbb, 0x9d, 0xb8, + 0x32, 0xb0, 0xae, 0xb5, 0x24, 0x6a, 0x86, 0xf6, 0xc1, 0x60, 0x41, 0xc4, 0xf4, 0x95, 0x6e, 0x10, + 0x2f, 0xd8, 0x58, 0x56, 0x42, 0x82, 0x71, 0x85, 0x19, 0xde, 0x91, 0xf0, 0x2f, 0x30, 0x0c, 0x63, + 0x0f, 0x2a, 0x77, 0x25, 0x4b, 0xb3, 0xd3, 0x2d, 0xfd, 0x94, 0x8b, 0x53, 0x02, 0x21, 0x40, 0xd7, + 0x36, 0x76, 0xf3, 0xc8, 0xc0, 0x36, 0x3d, 0x23, 0xc9, 0xbd, 0x92, 0x51, 0xf2, 0x4b, 0x83, 0x15, + 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, + 0xa2, 0x47, 0xd2, 0x0d, 0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x41, 0xc4, 0xf4, 0x95, 0x6e, 0x10, + 0x2f, 0xd8, 0x58, 0x56, 0x42, 0x82, 0x71, 0x85, 0x19, 0xde, 0x91, 0xf0, 0x2f, 0x30, 0x0c, 0x63, + 0x0f, 0x2a, 0x77, 0x25, 0x4b, 0xb3, 0xd3, 0x2d, 0xfd, 0x94, 0x8b, 0x53, 0x02, 0x21, 0x40, 0xd7, + 0x36, 0x76, 0xf3, 0xc8, 0xc0, 0x36, 0x3d, 0x23, 0xc9, 0xbd, 0x92, 0x51, 0xf2, 0x4b, 0x83, 0x15, + 0xe0, 0x80, 0x86, 0x24, 0xe2, 0x20, 0x35, 0x97, 0xda, 0x0e, 0x68, 0x39, 0x01, 0xdd, 0x01, 0x87, + 0xa2, 0x47, 0xd2, 0x0d, 0xee, 0xfe, 0xdc, 0x5a, 0x37, 0x23, 0xeb, 0x3d, 0xe8, 0x1e, 0x39, 0x2d, + 0xbf, 0xa6, 0xe9, 0x17, 0x48, 0xe2, 0xea, 0xef, 0x1d, 0x2f, 0xe2, 0xaf, 0x3c, 0xbc, 0xae, 0xa7, + 0x42, 0x9b, 0xa5, 0x7d, 0x47, 0x8a, 0x20, 0xc5, 0xae, 0xa1, 0xe4, 0xe8, 0x1c, 0x05, 0xc0, 0x0a, + 0x05, 0xdc, 0x01, 0x74, 0xde, 0xad, 0xad, 0x07, 0xec, 0x6e, 0x6a, 0xc7, 0xee, 0x0f, 0xb8, 0xbe, + 0xaa, 0x46, 0x61, 0x8c, 0x12, 0x5a, 0xaf, 0x05, 0xff, 0x1b, 0x35, 0x6b, 0xe2, 0x3d, 0x48, 0x4f +}; + +static unsigned char dh_except_a_pubkey_4096[] = { + 0xa5, 0x24, 0x63, 0x20, 0xb2, 0x56, 0x9a, 0x94, 0x97, 0xf7, 0x88, 0x41, 0x35, 0xeb, 0x52, 0x37, + 0xa4, 0xf2, 0x74, 0x1b, 0x38, 0xe4, 0x4c, 0x8b, 0x4b, 0xd2, 0xa5, 0xad, 0xb8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 0x3a, 0xcf, 0xc3, 0x82, 0x83, + 0xf6, 0x88, 0x52, 0x0b, 0xfc, 0x6a, 0x5b, 0x1a, 0x57, 0x87, 0x86, 0xef, 0xda, 0x47, 0xdb, 0x4d, + 0xba, 0xe7, 0x3, 0x5b, 0xe4, 0x70, 0x8b, 0xe0, 0xe1, 0x92, 0x13, 0x86, 0x74, 0x4, 0xdc, 0x6a, + 0x0a, 0x2a, 0x20, 0xec, 0x6d, 0xbf, 0xf0, 0x46, 0xf7, 0x9, 0x2, 0xdb, 0x2f, 0x70, 0x11, 0xdd, + 0xb0, 0x13, 0xa2, 0xc1, 0x58, 0x74, 0x29, 0x19, 0x8d, 0x4a, 0x94, 0x80, 0x0b, 0xd7, 0x25, 0x85, + 0x10, 0x35, 0x97, 0x48, 0x6e, 0x70, 0x28, 0xae, 0x58, 0x97, 0x7d, 0xf2, 0x19, 0x27, 0x13, 0xab, + 0x47, 0x9b, 0x54, 0xdf, 0xc3, 0x5b, 0x5f, 0x5e, 0xb4, 0x64, 0x47, 0xce, 0x40, 0x3b, 0x0c, 0x4a, + 0x62, 0x52, 0xba, 0xc7, 0xf0, 0x36, 0x87, 0x9c, 0x79, 0x9a, 0x83, 0x11, 0x61, 0x0c, 0x1b, 0x6b +}; + +static unsigned char dh_except_b_pubkey_4096[] = { + 0x44, 0x58, 0xe8, 0x62, 0xc8, 0xd2, 0xb5, 0x45, 0x1f, 0xa5, 0xc3, 0xdb, 0x8e, 0x69, 0x42, 0xd2, + 0x21, 0x7e, 0x6b, 0x26, 0x69, 0x45, 0xf1, 0x33, 0xcf, 0xd7, 0xe6, 0x6e, 0x64, 0xc3, 0x29, 0xa5, + 0x68, 0x49, 0x3d, 0x13, 0x0b, 0x42, 0x36, 0xa6, 0xf4, 0xb1, 0xab, 0xa3, 0x8f, 0xe6, 0xcf, 0x46, + 0xe8, 0x85, 0xf3, 0xaa, 0xcb, 0x9, 0x84, 0x32, 0x34, 0xf7, 0x46, 0x0a, 0x65, 0xf9,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0x6a, 0xeb, 0x1b, 0x4f, 0x14, 0x72, 0x88, + 0x6c, 0x14, 0x6d, 0x24, 0xb7, 0xda, 0xf8, 0x97, 0xaa, 0xba, 0xb4, 0xdd, 0xc9, 0x5b, 0x28, 0x10, + 0x49, 0xfa, 0x93, 0xcc, 0x62, 0xc0, 0x70, 0xf8, 0xd6, 0xdc, 0xb2, 0x80, 0x35, 0x20, 0x84, 0xa4, + 0x99, 0xfc, 0x10, 0x7c, 0x9d, 0xc0, 0xc6, 0xd4, 0x8b, 0x0c, 0x57, 0xf1, 0x1, 0xf5, 0x1a, 0x4f, + 0x20, 0xfa, 0x8d, 0x66, 0x8b, 0x22, 0x3c, 0x96, 0xef, 0xd0, 0xde, 0xe5, 0x7e, 0x7f, 0x23, 0xdc, + 0x6d, 0x71, 0xdf, 0xc3, 0xe5, 0x1b, 0x39, 0xfe, 0xb7, 0x77, 0xe5, 0x72, 0x0d, 0x1c, 0x8d, 0xb7 +}; + +static unsigned char dh_share_key_4096[] = { + 0xaf, 0xd4, 0xf6, 0x45, 0x63, 0x21, 0x8d, 0x98, 0xc4, 0xab, 0x18, 0xd7, 0x2b, 0x3c, 0x1d, 0xde, + 0xe7, 0x1f, 0xe1, 0xc5, 0x79, 0x57, 0x60, 0x20, 0xfa, 0x99, 0xbd, 0x7b, 0xa2, 0x94, 0x0b, 0xa3, + 0xb4, 0xb3, 0x33, 0x4a, 0x2f, 0xd0, 0x17, 0x7, 0x2e, 0x70, 0x19, 0x84, 0x1f, 0x8e, 0xe9, 0x61, + 0xe5, 0x52, 0x3, 0x96, 0xea, 0xd8, 0xb6, 0x3, 0x9f, 0xc4, 0x3e, 0x23, 0x77, 0x17, 0x54, 0xfb, + 0x13, 0xf0, 0x3e, 0x9a, 0x27, 0x5d, 0x12, 0x99, 0x58, 0x8d, 0x41, 0x46, 0xd9, 0xc9, 0x29, 0xbd, + 0x40, 0xd1, 0x4f, 0xef, 0x63, 0x7b, 0x54, 0xe6, 0x59, 0x6d, 0x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 0xf4, 0x44, 0xa9, 0xcb, 0x26, 0x2, 0x36, + 0x57, 0x2c, 0xa2, 0xbe, 0x37, 0xde, 0x86, 0x46, 0x20, 0x27, 0x9d, 0xa0, 0x2f, 0x4, 0xc1, 0xcd, + 0xff, 0x81, 0xe5, 0xe6, 0x2c, 0x9e, 0x39, 0x82, 0x31, 0x54, 0x33, 0xf8, 0xe7, 0xa0, 0xe5, 0x96, + 0xa4, 0x40, 0xc4, 0x44, 0xfe, 0x93, 0x66, 0xe2, 0xda, 0xaa, 0xb8, 0xfb, 0x2f, 0x3b, 0x8c, 0xce, +}; + +/******************************************* ECDH ********************************************/ +static char ecdh_a_secp128r1[] = { + 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc +}; + +static char ecdh_b_secp128r1[] = { + 0xe8, 0x75, 0x79, 0xc1, 0x10, 0x79, 0xf4, 0x3d, 0xd8, 0x24, 0x99, 0x3c, 0x2c, 0xee, 0x5e, 0xd3 +}; + +static char ecdh_p_secp128r1[] = { + 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff +}; + +static char ecdh_n_secp128r1[] = { + 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x75, 0xa3, 0x0d, 0x1b, 0x90, 0x38, 0xa1, 0x15 +}; + +static char ecdh_g_secp128r1[] = { + 0x16, 0x1f, 0xf7, 0x52, 0x8b, 0x89, 0x9b, 0x2d, 0x0c, 0x28, 0x60, 0x7c, 0xa5, 0x2c, 0x5b, 0x86, + 0xcf, 0x5a, 0xc8, 0x39, 0x5b, 0xaf, 0xeb, 0x13, 0xc0, 0x2d, 0xa2, 0x92, 0xdd, 0xed, 0x7a, 0x83 +}; + +static char ecdh_da_secp128r1[] = { + 0xfe, 0x4e, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x78, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static char ecdh_cp_pubkey_secp128r1[] = { + 0x04, + 0xcc, 0x40, 0x99, 0x3b, 0xcd, 0x0b, 0xcf, 0xcb, 0x9a, 0x96, 0x08, 0x56, 0xc2, 0x96, 0x2c, 0xe1, + 0xdf, 0x69, 0x2a, 0x71, 0xaf, 0x96, 0xe2, 0xeb, 0x5a, 0x26, 0x7f, 0xd3, 0x7a, 0xe8, 0x70, 0xf3 +}; + +static char ecdh_except_b_pubkey_secp128r1[] = { + 0x04, + 0xcc, 0x40, 0x99, 0x3b, 0xcd, 0x0b, 0xcf, 0xcb, 0x9a, 0x96, 0x08, 0x56, 0xc2, 0x96, 0x2c, 0xe1, + 0xdf, 0x69, 0x2a, 0x71, 0xaf, 0x96, 0xe2, 0xeb, 0x5a, 0x26, 0x7f, 0xd3, 0x7a, 0xe8, 0x70, 0xf3 +}; + +static char ecdh_cp_sharekey_secp128r1[] = { + 0x68, 0x55, 0x71, 0xa4, 0xd7, 0x51, 0x49, 0xa8, 0x78, 0xa8, 0x3a, 0xc1, 0x3f, 0xb3, 0x8c, 0xcb +}; + +/* ecc sign or verf*/ +static char ecc_except_kinv_secp128r1[] = { + 0xfe, 0x4e, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x4d, 0x78, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static char ecc_except_e_secp128r1[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x4 +}; + +static char ecc_cp_sign_secp128r1[] = { + 0x2e, 0x69, 0xad, 0x4f, 0xd5, 0xd4, 0x62, 0xec, 0xf2, 0xde, 0x21, 0x4f, 0xbc, 0x1f, 0xe8, 0x19, + 0x7b, 0x98, 0x8d, 0xaf, 0xe4, 0x6c, 0x60, 0x73, 0x00, 0xb0, 0x8b, 0xef, 0x89, 0x65, 0x35, 0x84 +}; + +static char ecdh_a_secp192k1[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static char ecdh_b_secp192k1[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 +}; + +static char ecdh_p_secp192k1[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xee, 0x37 +}; + +static char ecdh_n_secp192k1[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x26, 0xf2, 0xfc, 0x17, + 0x0f, 0x69, 0x46, 0x6a, 0x74, 0xde, 0xfd, 0x8d +}; + +static char ecdh_g_secp192k1[] = { + 0xdb, 0x4f, 0xf1, 0x0e, 0xc0, 0x57, 0xe9, 0xae, 0x26, 0xb0, 0x7d, 0x02, 0x80, 0xb7, 0xf4, 0x34, + 0x1d, 0xa5, 0xd1, 0xb1, 0xea, 0xe0, 0x6c, 0x7d, + 0x9b, 0x2f, 0x2f, 0x6d, 0x9c, 0x56, 0x28, 0xa7, 0x84, 0x41, 0x63, 0xd0, 0x15, 0xbe, 0x86, 0x34, + 0x40, 0x82, 0xaa, 0x88, 0xd9, 0x5e, 0x2f, 0x9d +}; + +static char ecdh_da_secp192k1[] = { + 0x2b, 0x58, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x58, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, + 0x67, 0x6a, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static char ecdh_cp_pubkey_secp192k1[] = { + 0x04, + 0xec, 0x0e, 0x64, 0xac, 0x04, 0x2a, 0x88, 0x86, 0xed, 0xc1, 0xf2, 0x50, 0x0f, 0xe1, 0x27, 0x63, + 0x86, 0x63, 0x9e, 0xb2, 0x82, 0x21, 0x6e, 0x3f, 0x48, 0x59, 0x76, 0xb9, 0x4e, 0xd9, 0xe2, 0x02, + 0xb4, 0xdb, 0xfc, 0x8f, 0x49, 0xe7, 0x24, 0x9b, 0xbe, 0x33, 0xee, 0xc8, 0xcc, 0x9e, 0x00, 0x9a +}; + +static char ecdh_cp_sharekey_secp192k1[] = { + 0x79, 0xd3, 0x1c, 0x98, 0xfb, 0xd2, 0xb6, 0x7c, 0x60, 0x4b, 0x6e, 0x4c, 0xa9, 0x95, 0xcb, 0xac, + 0xb0, 0xf9, 0x05, 0xed, 0x9a, 0xcb, 0x2e, 0x5b +}; + +static char ecdh_except_b_pubkey_secp192k1[] = { + 0x04, + 0xec, 0x0e, 0x64, 0xac, 0x04, 0x2a, 0x88, 0x86, 0xed, 0xc1, 0xf2, 0x50, 0x0f, 0xe1, 0x27, 0x63, + 0x86, 0x63, 0x9e, 0xb2, 0x82, 0x21, 0x6e, 0x3f, 0x48, 0x59, 0x76, 0xb9, 0x4e, 0xd9, 0xe2, 0x02, + 0xb4, 0xdb, 0xfc, 0x8f, 0x49, 0xe7, 0x24, 0x9b, 0xbe, 0x33, 0xee, 0xc8, 0xcc, 0x9e, 0x00, 0x9a +}; + +/* ecc sign or verf*/ +static unsigned char ecc_except_kinv_secp192k1[] = { + 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, + 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54 +}; + +static unsigned char ecc_except_e_secp192k1[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04 +}; + +/* 224 */ +static char ecdh_a_secp224r1[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE +}; + +static char ecdh_b_secp224r1[] = { + 0xB4, 0x05, 0x0A, 0x85, 0x0C, 0x04, 0xB3, 0xAB, 0xF5, 0x41, 0x32, 0x56, 0x50, 0x44, + 0xB0, 0xB7, 0xD7, 0xBF, 0xD8, 0xBA, 0x27, 0x0B, 0x39, 0x43, 0x23, 0x55, 0xFF, 0xB4 +}; + +static char ecdh_p_secp224r1[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 +}; + +static char ecdh_n_secp224r1[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x16, 0xA2, 0xE0, 0xB8, 0xF0, 0x3E, 0x13, 0xDD, 0x29, 0x45, 0x5C, 0x5C, 0x2A, 0x3D +}; + +static char ecdh_g_secp224r1[] = { + 0xB7, 0x0E, 0x0C, 0xBD, 0x6B, 0xB4, 0xBF, 0x7F, 0x32, 0x13, 0x90, 0xB9, 0x4A, 0x03, + 0xC1, 0xD3, 0x56, 0xC2, 0x11, 0x22, 0x34, 0x32, 0x80, 0xD6, 0x11, 0x5C, 0x1D, 0x21, + 0xBD, 0x37, 0x63, 0x88, 0xB5, 0xF7, 0x23, 0xFB, 0x4C, 0x22, 0xDF, 0xE6, 0xCD, 0x43, + 0x75, 0xA0, 0x5A, 0x07, 0x47, 0x64, 0x44, 0xD5, 0x81, 0x99, 0x85, 0x00, 0x7E, 0x34 +}; + +static char ecdh_da_secp224r1[] = { + 0x41, 0x5c, 0x8c, 0x34, 0xfd, 0x70, 0x76, 0x3c, 0x6a, 0x81, 0x8e, 0x33, 0x7c, 0xa5, + 0x59, 0x6b, 0xfb, 0x58, 0x8e, 0x74, 0xb8, 0xc7, 0x3c, 0xcf, 0xde, 0xe3, 0x81, 0x60 +}; + +static char ecdh_cp_pubkey_secp224r1[] = { + 0x04, + 0x5b, 0x46, 0x50, 0x7c, 0x7a, 0x37, 0x82, 0x05, 0x5a, 0xc7, 0xd0, 0x29, 0xf8, 0xdd, + 0xe6, 0x3e, 0xb4, 0xc2, 0x31, 0x59, 0xfd, 0xa4, 0xb7, 0xee, 0x61, 0x83, 0x7c, 0x80, + 0xf1, 0x51, 0xf0, 0x5b, 0xfb, 0xc6, 0x63, 0x23, 0x9a, 0x13, 0xfa, 0x47, 0x68, 0x7b, + 0x3e, 0x47, 0xb3, 0x88, 0xca, 0x3e, 0x4b, 0x71, 0x24, 0x17, 0xc7, 0x4c, 0xd0, 0x06 +}; + +static char ecdh_except_b_pubkey_secp224r1[] = { + 0x04, + 0x5b, 0x46, 0x50, 0x7c, 0x7a, 0x37, 0x82, 0x05, 0x5a, 0xc7, 0xd0, 0x29, 0xf8, 0xdd, + 0xe6, 0x3e, 0xb4, 0xc2, 0x31, 0x59, 0xfd, 0xa4, 0xb7, 0xee, 0x61, 0x83, 0x7c, 0x80, + 0xf1, 0x51, 0xf0, 0x5b, 0xfb, 0xc6, 0x63, 0x23, 0x9a, 0x13, 0xfa, 0x47, 0x68, 0x7b, + 0x3e, 0x47, 0xb3, 0x88, 0xca, 0x3e, 0x4b, 0x71, 0x24, 0x17, 0xc7, 0x4c, 0xd0, 0x06 +}; + +static char ecdh_cp_sharekey_secp224r1[] = { + 0x2f, 0xc0, 0x04, 0x34, 0x0e, 0x03, 0xb0, 0xd2, 0x84, 0xe1, 0x4f, 0x4f, 0x7b, 0xac, + 0x53, 0xaa, 0x32, 0x5c, 0xbd, 0xe5, 0xbc, 0x2a, 0xe3, 0xda, 0x48, 0x38, 0x67, 0x16 +}; + + +/* 256 */ +static char ecdh_a_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, 0x00, 0x00, 0x00, 0x00 +}; + +static char ecdh_b_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, 0x00, 0x00, 0x00, 0x07 +}; + +static char ecdh_p_secp256k1[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xfc, 0x2f +}; + +static char ecdh_n_secp256k1[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, + 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41 +}; + +static char ecdh_g_secp256k1[] = { + 0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC, 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07, + 0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9, 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98, + 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, + 0xfd, 0x17, 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8 +}; + +static char ecdh_da_secp256k1[] = { + 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, + 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 +}; + +#if 0 +static char ecdh_db_secp256k1[] = { + 0xe2, 0x74, 0x69, 0xc8, 0x17, 0x6c, 0x0d, 0xca, 0xdd, 0x9e, 0xf6, 0x2f, 0x30, 0x9f, 0xad, 0xf3, + 0xdd, 0x16, 0xcc, 0x0c, 0xb1, 0xd0, 0x7b, 0xf4, 0xde, 0x9d, 0xf2, 0x5d, 0x22, 0x03, 0xce, 0x41 +}; +#endif + +static char ecdh_cp_pubkey_secp256k1[] = { + 0x04, + 0x68, 0xae, 0x87, 0x7c, 0x45, 0xb3, 0x8b, 0xa8, 0xa8, 0x8e, 0x4b, 0xe5, 0x1f, 0x4e, 0xe6, 0x89, + 0x67, 0x73, 0x71, 0x96, 0x92, 0x2e, 0x57, 0x07, 0xc4, 0x30, 0xa5, 0xcf, 0x9f, 0x58, 0xb0, 0x6f, + 0x26, 0xd3, 0x58, 0xa4, 0xb6, 0xfc, 0xb6, 0x4b, 0x0f, 0x63, 0xd9, 0xa6, 0xa0, 0x1b, 0xba, 0x10, + 0x10, 0xa4, 0xab, 0x28, 0x6e, 0xab, 0x51, 0x34, 0xac, 0x3d, 0x2b, 0x39, 0xf1, 0xd7, 0x21, 0x48 +}; + +static char ecdh_except_b_pubkey_secp256k1[] = { + 0x04, + 0x90, 0x34, 0x99, 0xc8, 0x9e, 0x32, 0xdb, 0xcd, 0x24, 0x4e, 0x31, 0x51, 0x1c, 0x83, 0x4b, 0xf7, + 0x68, 0xf0, 0xbb, 0xa3, 0x91, 0x38, 0xa8, 0xf1, 0xab, 0x76, 0x36, 0xcd, 0x23, 0x3f, 0x57, 0x3b, + 0x22, 0x1a, 0x3f, 0x2e, 0x40, 0x8b, 0xe2, 0x7b, 0xd4, 0x91, 0xe4, 0xf2, 0x36, 0x00, 0xbe, 0xae, + 0x9c, 0xf2, 0xfc, 0xb4, 0xb9, 0x8b, 0x5b, 0xa7, 0x39, 0x88, 0xf2, 0x3b, 0xe2, 0xe5, 0xab, 0x1b +}; + +static char ecdh_cp_sharekey_secp256k1[] = { + 0xd8, 0x9d, 0x1e, 0x25, 0xa2, 0x5, 0xd8, 0xad, 0x0f, 0x1c, 0x7a, 0x44, 0xd4, 0xe6, 0x96, 0xc2, + 0xd3, 0xbc, 0x05, 0xa1, 0x8d, 0x4a, 0x2, 0x11, 0x0e, 0x93, 0xcd, 0xb9, 0x56, 0xd6, 0x44, 0x1c, +}; + +/* ecc sign or verf*/ +static unsigned char ecc_except_kinv_secp256k1[] = { + 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, + 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 +}; + +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 +}; + +static unsigned char ecc_cp_sign_secp256k1[] = { + 0x30,0x45,0x02,0x20,0x68,0xae,0x87,0x7c,0x45,0xb3,0x8b,0xa8,0xa8,0x8e,0x4b,0xe5, + 0x1f,0x4e,0xe6,0x89,0x67,0x73,0x71,0x96,0x92,0x2e,0x57,0x07,0xc4,0x30,0xa5,0xcf, + 0x9f,0x58,0xb0,0x6f,0x02,0x21,0x00,0xdb,0x14,0xac,0x48,0x0d,0x0a,0xe9,0xe4,0x1d, + 0x8d,0xca,0x47,0xb6,0x0e,0x44,0xf6,0xfb,0xde,0x86,0x9b,0x38,0x76,0x98,0x67,0x12, + 0x7f,0x1d,0x09,0x97,0xab,0xc2,0xcb +}; + +static char ecdh_a_secp320k1[] = { + 0x3e, 0xe3, 0x0b, 0x56, 0x8f, 0xba, 0xb0, 0xf8, 0x83, 0xcc, 0xeb, 0xd4, 0x6d, 0x3f, 0x3b, 0xb8, + 0xa2, 0xa7, 0x35, 0x13, 0xf5, 0xeb, 0x79, 0xda, 0x66, 0x19, 0x0e, 0xb0, 0x85, 0xff, 0xa9, 0xf4, + 0x92, 0xf3, 0x75, 0xa9, 0x7d, 0x86, 0x0e, 0xb4 +}; + +static char ecdh_b_secp320k1[] = { + 0x52, 0x08, 0x83, 0x94, 0x9d, 0xfd, 0xbc, 0x42, 0xd3, 0xad, 0x19, 0x86, 0x40, 0x68, 0x8a, 0x6f, + 0xe1, 0x3f, 0x41, 0x34, 0x95, 0x54, 0xb4, 0x9a, 0xcc, 0x31, 0xdc, 0xcd, 0x88, 0x45, 0x39, 0x81, + 0x6f, 0x5e, 0xb4, 0xac, 0x8f, 0xb1, 0xf1, 0xa6 +}; + +static char ecdh_p_secp320k1[] = { + 0xd3, 0x5e, 0x47, 0x20, 0x36, 0xbc, 0x4f, 0xb7, 0xe1, 0x3c, 0x78, 0x5e, 0xd2, 0x01, 0xe0, 0x65, + 0xf9, 0x8f, 0xcf, 0xa6, 0xf6, 0xf4, 0x0d, 0xef, 0x4f, 0x92, 0xb9, 0xec, 0x78, 0x93, 0xec, 0x28, + 0xfc, 0xd4, 0x12, 0xb1, 0xf1, 0xb3, 0x2e, 0x27 +}; + +static char ecdh_n_secp320k1[] = { + 0xd3, 0x5e, 0x47, 0x20, 0x36, 0xbc, 0x4f, 0xb7, 0xe1, 0x3c, 0x78, 0x5e, 0xd2, 0x01, 0xe0, 0x65, + 0xf9, 0x8f, 0xcf, 0xa5, 0xb6, 0x8f, 0x12, 0xa3, 0x2d, 0x48, 0x2e, 0xc7, 0xee, 0x86, 0x58, 0xe9, + 0x86, 0x91, 0x55, 0x5b, 0x44, 0xc5, 0x93, 0x11 +}; + +static char ecdh_g_secp320k1[] = { + 0x43, 0xbd, 0x7e, 0x9a, 0xfb, 0x53, 0xd8, 0xb8, 0x52, 0x89, 0xbc, 0xc4, 0x8e, 0xe5, 0xbf, 0xe6, + 0xf2, 0x01, 0x37, 0xd1, 0x0a, 0x08, 0x7e, 0xb6, 0xe7, 0x87, 0x1e, 0x2a, 0x10, 0xa5, 0x99, 0xc7, + 0x10, 0xaf, 0x8d, 0x0d, 0x39, 0xe2, 0x06, 0x11, + 0x14, 0xfd, 0xd0, 0x55, 0x45, 0xec, 0x1c, 0xc8, 0xab, 0x40, 0x93, 0x24, 0x7f, 0x77, 0x27, 0x5e, + 0x07, 0x43, 0xff, 0xed, 0x11, 0x71, 0x82, 0xea, 0xa9, 0xc7, 0x78, 0x77, 0xaa, 0xac, 0x6a, 0xc7, + 0xd3, 0x52, 0x45, 0xd1, 0x69, 0x2e, 0x8e, 0xe1, +}; + +static char ecdh_da_secp320k1[] = { + 0x6a, 0x5b, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x21, 0x8e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x31, 0x00, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x6a, 0x5b, 0xc2, 0x5e, 0x00, 0x00, 0x00, 0x00, + 0x21, 0x8e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static char ecdh_cp_pubkey_secp320k1[] = { + 0x04, + 0x5f, 0x25, 0x77, 0xa9, 0xb5, 0x0a, 0x6f, 0xd3, 0xcb, 0x43, 0x93, 0xe0, 0xb7, 0x41, 0x3b, 0x56, + 0xc3, 0xfe, 0x1e, 0x5c, 0xb9, 0x32, 0x3a, 0x74, 0x68, 0xf8, 0x69, 0xea, 0xcf, 0x5b, 0x82, 0xd2, + 0x38, 0x8c, 0x96, 0x87, 0x97, 0xc3, 0x89, 0x9d, 0x13, 0x02, 0x40, 0xba, 0x88, 0xfa, 0x0c, 0x5a, + 0x64, 0x52, 0x7c, 0x36, 0xbd, 0xa6, 0x92, 0xb7, 0x6f, 0xb1, 0xd5, 0x81, 0xdb, 0xd5, 0x78, 0x96, + 0x50, 0x6a, 0x48, 0xec, 0x75, 0x04, 0x01, 0x3e, 0x86, 0x07, 0x74, 0x5b, 0xa7, 0x72, 0x44, 0x27 +}; + +static char ecdh_except_b_pubkey_secp320k1[] = { + 0x04, + 0x5f, 0x25, 0x77, 0xa9, 0xb5, 0x0a, 0x6f, 0xd3, 0xcb, 0x43, 0x93, 0xe0, 0xb7, 0x41, 0x3b, 0x56, + 0xc3, 0xfe, 0x1e, 0x5c, 0xb9, 0x32, 0x3a, 0x74, 0x68, 0xf8, 0x69, 0xea, 0xcf, 0x5b, 0x82, 0xd2, + 0x38, 0x8c, 0x96, 0x87, 0x97, 0xc3, 0x89, 0x9d, 0x13, 0x02, 0x40, 0xba, 0x88, 0xfa, 0x0c, 0x5a, + 0x64, 0x52, 0x7c, 0x36, 0xbd, 0xa6, 0x92, 0xb7, 0x6f, 0xb1, 0xd5, 0x81, 0xdb, 0xd5, 0x78, 0x96, + 0x50, 0x6a, 0x48, 0xec, 0x75, 0x04, 0x01, 0x3e, 0x86, 0x07, 0x74, 0x5b, 0xa7, 0x72, 0x44, 0x27 +}; + +static char ecdh_cp_sharekey_secp320k1[] = { + 0x69, 0x8a, 0x70, 0x4e, 0xf8, 0x4a, 0x9a, 0x80, 0xe8, 0x48, 0xc9, 0xb9, 0xac, 0x2a, 0x74, 0xf0, + 0xe5, 0x29, 0x60, 0x6d, 0xf3, 0x4e, 0x01, 0xa6, 0x20, 0x37, 0xc2, 0x0f, 0xba, 0x98, 0x91, 0x3b, + 0xc2, 0x75, 0xa3, 0xc6, 0x75, 0x90, 0x79, 0xb4 +}; + +/* ecc sign or verf*/ +static unsigned char ecc_except_kinv_secp320k1[] = { + 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, + 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 +}; + +static unsigned char ecc_except_e_secp320k1[] = { + 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 +}; + +/* 384 */ +static char ecdh_a_secp384r1[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFC +}; + +static char ecdh_b_secp384r1[] = { + 0xB3, 0x31, 0x2F, 0xA7, 0xE2, 0x3E, 0xE7, 0xE4, 0x98, 0x8E, 0x05, 0x6B, + 0xE3, 0xF8, 0x2D, 0x19, 0x18, 0x1D, 0x9C, 0x6E, 0xFE, 0x81, 0x41, 0x12, + 0x03, 0x14, 0x08, 0x8F, 0x50, 0x13, 0x87, 0x5A, 0xC6, 0x56, 0x39, 0x8D, + 0x8A, 0x2E, 0xD1, 0x9D, 0x2A, 0x85, 0xC8, 0xED, 0xD3, 0xEC, 0x2A, 0xEF +}; + +static char ecdh_p_secp384r1[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF +}; + +static char ecdh_n_secp384r1[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xC7, 0x63, 0x4D, 0x81, 0xF4, 0x37, 0x2D, 0xDF, 0x58, 0x1A, 0x0D, 0xB2, + 0x48, 0xB0, 0xA7, 0x7A, 0xEC, 0xEC, 0x19, 0x6A, 0xCC, 0xC5, 0x29, 0x73 +}; + +static char ecdh_g_secp384r1[] = { + 0xAA, 0x87, 0xCA, 0x22, 0xBE, 0x8B, 0x05, 0x37, 0x8E, 0xB1, 0xC7, 0x1E, + 0xF3, 0x20, 0xAD, 0x74, 0x6E, 0x1D, 0x3B, 0x62, 0x8B, 0xA7, 0x9B, 0x98, + 0x59, 0xF7, 0x41, 0xE0, 0x82, 0x54, 0x2A, 0x38, 0x55, 0x02, 0xF2, 0x5D, + 0xBF, 0x55, 0x29, 0x6C, 0x3A, 0x54, 0x5E, 0x38, 0x72, 0x76, 0x0A, 0xB7, + 0x36, 0x17, 0xDE, 0x4A, 0x96, 0x26, 0x2C, 0x6F, 0x5D, 0x9E, 0x98, 0xBF, + 0x92, 0x92, 0xDC, 0x29, 0xF8, 0xF4, 0x1D, 0xBD, 0x28, 0x9A, 0x14, 0x7C, + 0xE9, 0xDA, 0x31, 0x13, 0xB5, 0xF0, 0xB8, 0xC0, 0x0A, 0x60, 0xB1, 0xCE, + 0x1D, 0x7E, 0x81, 0x9D, 0x7A, 0x43, 0x1D, 0x7C, 0x90, 0xEA, 0x0E, 0x5F +}; + +static char ecdh_da_secp384r1[] = { + 0xee, 0x57, 0xd7, 0xad, 0xbc, 0x8c, 0x5d, 0x82, 0x65, 0x7f, 0x03, 0xcb, 0x12, 0xc1, 0x38, 0x0d, + 0x02, 0x5c, 0xb7, 0x8f, 0xa4, 0x36, 0x56, 0x27, 0x25, 0x85, 0xaa, 0x3e, 0xdf, 0x22, 0x88, 0x7b, + 0xe3, 0xe7, 0xc5, 0xf1, 0xd7, 0x37, 0x8c, 0xc7, 0x56, 0xca, 0xa7, 0x93, 0x37, 0xbd, 0xf9, 0x37 +}; + +static char ecdh_cp_pubkey_secp384r1[] = { + 0x04, + 0x7d, 0x54, 0xd0, 0x72, 0x45, 0x4b, 0x5a, 0x48, 0xed, 0xc6, 0x19, 0xde, 0x8f, 0x1b, 0xa6, 0xfd, + 0xe5, 0x00, 0xbc, 0x74, 0xbb, 0xee, 0xdc, 0x6b, 0x1c, 0x6d, 0x36, 0xf1, 0x2a, 0x6a, 0x3c, 0xcd, + 0xd5, 0xb9, 0xf8, 0x3c, 0x57, 0xe8, 0xc2, 0xb2, 0xe6, 0x60, 0x58, 0x03, 0x3e, 0x48, 0xf4, 0xc4, + 0x4b, 0x80, 0x58, 0x8c, 0xc7, 0x65, 0x2e, 0xdd, 0x23, 0x31, 0xd2, 0xae, 0x62, 0x62, 0xc3, 0xb4, + 0x57, 0x88, 0xc6, 0x84, 0x51, 0xaf, 0x8c, 0x7b, 0x94, 0x2a, 0x43, 0x68, 0x31, 0xbd, 0x3d, 0x4f, + 0x43, 0xae, 0x79, 0x50, 0x80, 0x60, 0x09, 0xfa, 0x42, 0xfe, 0x9d, 0x18, 0xce, 0xbe, 0xfd, 0x64 +}; + +static char ecdh_except_b_pubkey_secp384r1[] = { + 0x04, + 0x7d, 0x54, 0xd0, 0x72, 0x45, 0x4b, 0x5a, 0x48, 0xed, 0xc6, 0x19, 0xde, 0x8f, 0x1b, 0xa6, 0xfd, + 0xe5, 0x00, 0xbc, 0x74, 0xbb, 0xee, 0xdc, 0x6b, 0x1c, 0x6d, 0x36, 0xf1, 0x2a, 0x6a, 0x3c, 0xcd, + 0xd5, 0xb9, 0xf8, 0x3c, 0x57, 0xe8, 0xc2, 0xb2, 0xe6, 0x60, 0x58, 0x03, 0x3e, 0x48, 0xf4, 0xc4, + 0x4b, 0x80, 0x58, 0x8c, 0xc7, 0x65, 0x2e, 0xdd, 0x23, 0x31, 0xd2, 0xae, 0x62, 0x62, 0xc3, 0xb4, + 0x57, 0x88, 0xc6, 0x84, 0x51, 0xaf, 0x8c, 0x7b, 0x94, 0x2a, 0x43, 0x68, 0x31, 0xbd, 0x3d, 0x4f, + 0x43, 0xae, 0x79, 0x50, 0x80, 0x60, 0x09, 0xfa, 0x42, 0xfe, 0x9d, 0x18, 0xce, 0xbe, 0xfd, 0x64 +}; + +static char ecdh_cp_sharekey_secp384r1[] = { + 0x82, 0x80, 0x4b, 0x00, 0x8c, 0x3c, 0x29, 0x51, 0xc8, 0x77, 0x1f, 0x72, 0xe2, 0x8c, 0x9d, 0x2a, + 0x3c, 0xf3, 0xe3, 0x7c, 0xc0, 0xc9, 0x80, 0x20, 0xe2, 0x1a, 0x45, 0xb6, 0x20, 0x13, 0x18, 0x91, + 0x61, 0xfa, 0xf1, 0x9d, 0x9f, 0xf2, 0x95, 0x78, 0xdd, 0xfe, 0x73, 0x9f, 0x09, 0x24, 0xa1, 0x4b +}; + +/* ecc sign or verf*/ +static unsigned char ecc_except_kinv_secp384r1[] = { + /* + 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, + 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3*/ +}; + +static unsigned char ecc_except_e_secp384r1[] = { + /* + 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*/ +}; + +/* 521 */ +static char ecdh_a_secp521r1[] = { + 0x01, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc +}; + +static char ecdh_b_secp521r1[] = { + 0x00, 0xe6, 0x15, 0x1c, 0x79, 0x17, 0x8d, 0x1b, 0x5c, 0xfa, + 0xbc, 0x7e, 0x53, 0x82, 0xb9, 0x33, 0xbc, 0x16, 0x2c, 0x9f, 0x27, 0xed, 0x6d, 0x79, 0x34, 0xf2, + 0xba, 0x07, 0x92, 0x9e, 0x96, 0xea, 0xe9, 0xdd, 0xb5, 0xae, 0x57, 0x7a, 0x54, 0xe1, 0x3c, 0x71, + 0xa9, 0x6e, 0x3e, 0x3d, 0x88, 0xaf, 0x92, 0x77, 0xe8, 0xe6, 0x61, 0xfe, 0xed, 0x39, 0xbd, 0x11, + 0x19, 0x25, 0x3f, 0x09, 0x4e, 0x71, 0x25, 0xcc +}; + +static char ecdh_p_secp521r1[] = { + 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff +}; + +static char ecdh_n_secp521r1[] = { + 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 0x51, 0x86, 0x87, 0x83, 0xbf, 0x2f, 0x96, 0x6b, + 0x7f, 0xcc, 0x01, 0x48, 0xf7, 0x09, 0xa5, 0xd0, 0x3b, 0xb5, 0xc9, 0xb8, 0x89, 0x9c, 0x47, 0xae, + 0xbb, 0x6f, 0xb7, 0x1e, 0x91, 0x38, 0x64, 0x09 +}; + +static char ecdh_g_secp521r1[] = { + 0x00, 0xc6, + 0x85, 0x8e, 0x06, 0xb7, 0x04, 0x04, 0xe9, 0xcd, 0x9e, 0x3e, 0xcb, 0x66, 0x23, 0x95, 0xb4, 0x42, + 0x9c, 0x64, 0x81, 0x39, 0x05, 0x3f, 0xb5, 0x21, 0xf8, 0x28, 0xaf, 0x60, 0x6b, 0x4d, 0x3d, 0xba, + 0xa1, 0x4b, 0x5e, 0x77, 0xef, 0xe7, 0x59, 0x28, 0xfe, 0x1d, 0xc1, 0x27, 0xa2, 0xff, 0xa8, 0xde, + 0x33, 0x48, 0xb3, 0xc1, 0x85, 0x6a, 0x42, 0x9b, 0xf9, 0x7e, 0x7e, 0x31, 0xc2, 0xe5, 0xbd, 0x66, + + 0x01, 0x18, 0x39, 0x29, 0x6a, 0x78, 0x9a, 0x3b, 0xc0, 0x04, + 0x5c, 0x8a, 0x5f, 0xb4, 0x2c, 0x7d, 0x1b, 0xd9, 0x98, 0xf5, 0x44, 0x49, 0x57, 0x9b, 0x44, 0x68, + 0x17, 0xaf, 0xbd, 0x17, 0x27, 0x3e, 0x66, 0x2c, 0x97, 0xee, 0x72, 0x99, 0x5e, 0xf4, 0x26, 0x40, + 0xc5, 0x50, 0xb9, 0x01, 0x3f, 0xad, 0x07, 0x61, 0x35, 0x3c, 0x70, 0x86, 0xa2, 0x72, 0xc2, 0x40, + 0x88, 0xbe, 0x94, 0x76, 0x9f, 0xd1, 0x66, 0x50 +}; + +static char ecdh_da_secp521r1[] = { + 0x00, 0xe6, 0x15, 0x1c, 0x79, 0x17, 0x8d, 0x1b, 0x5c, 0xfa, + 0xbc, 0x7e, 0x53, 0x82, 0xb9, 0x33, 0xbc, 0x16, 0x2c, 0x9f, 0x27, 0xed, 0x6d, 0x79, 0x34, 0xf2, + 0xba, 0x07, 0x92, 0x9e, 0x96, 0xea, 0xe9, 0xdd, 0xb5, 0xae, 0x57, 0x7a, 0x54, 0xe1, 0x3c, 0x71, + 0xa9, 0x6e, 0x3e, 0x3d, 0x88, 0xaf, 0x92, 0x77, 0xe8, 0xe6, 0x61, 0xfe, 0xed, 0x39, 0xbd, 0x11, + 0x19, 0x25, 0x3f, 0x09, 0x4e, 0x71, 0x25, 0xcc +}; + +static char ecdh_except_b_pubkey_secp521r1[] = { + 0x04, + 0x01, 0x16, 0x0a, 0x52, 0xaa, 0x18, 0x96, 0x56, 0xf6, 0x27, 0xd1, 0x59, 0xbd, 0x7d, 0x0f, 0x57, + 0xfd, 0x34, 0xfa, 0x52, 0x1b, 0x04, 0xbd, 0x9a, 0x90, 0xd5, 0x8d, 0xad, 0x41, 0x32, 0x80, 0x14, + 0x6e, 0x73, 0x58, 0x83, 0x98, 0xeb, 0xb0, 0x6b, 0xb5, 0x63, 0x8e, 0xa1, 0x06, 0x04, 0x86, 0x94, + 0x9e, 0x34, 0x53, 0xf4, 0x93, 0x37, 0x1c, 0xbc, 0xbb, 0x7b, 0x4c, 0x97, 0x87, 0x32, 0x92, 0xf2, + 0x36, 0xdd, 0x01, 0x30, 0xa1, 0xa7, 0x68, 0x5a, 0x3e, 0x40, 0xe9, 0xbf, 0x3d, 0x2a, 0x1b, 0xbf, + 0x09, 0xa0, 0x51, 0xe8, 0x1d, 0x23, 0x27, 0x9c, 0x70, 0xb2, 0x18, 0x42, 0x02, 0x09, 0x02, 0x66, + 0xc7, 0xdb, 0x1a, 0xec, 0xe5, 0x20, 0x68, 0x31, 0x31, 0x6e, 0x70, 0xbe, 0x09, 0x72, 0x79, 0x42, + 0xe2, 0x3b, 0x3b, 0xd3, 0x0a, 0xe4, 0x9c, 0x34, 0x4c, 0x61, 0x74, 0x7c, 0xed, 0xe1, 0x84, 0x89, + 0x4b, 0xf4, 0xd5, 0xc3 +}; + +static char ecdh_cp_pubkey_secp521r1[] = { + 0x04, + 0x01, 0x16, 0x0a, 0x52, 0xaa, 0x18, 0x96, 0x56, 0xf6, 0x27, 0xd1, 0x59, 0xbd, 0x7d, 0x0f, 0x57, + 0xfd, 0x34, 0xfa, 0x52, 0x1b, 0x04, 0xbd, 0x9a, 0x90, 0xd5, 0x8d, 0xad, 0x41, 0x32, 0x80, 0x14, + 0x6e, 0x73, 0x58, 0x83, 0x98, 0xeb, 0xb0, 0x6b, 0xb5, 0x63, 0x8e, 0xa1, 0x06, 0x04, 0x86, 0x94, + 0x9e, 0x34, 0x53, 0xf4, 0x93, 0x37, 0x1c, 0xbc, 0xbb, 0x7b, 0x4c, 0x97, 0x87, 0x32, 0x92, 0xf2, + 0x36, 0xdd, 0x01, 0x30, 0xa1, 0xa7, 0x68, 0x5a, 0x3e, 0x40, 0xe9, 0xbf, 0x3d, 0x2a, 0x1b, 0xbf, + 0x09, 0xa0, 0x51, 0xe8, 0x1d, 0x23, 0x27, 0x9c, 0x70, 0xb2, 0x18, 0x42, 0x02, 0x09, 0x02, 0x66, + 0xc7, 0xdb, 0x1a, 0xec, 0xe5, 0x20, 0x68, 0x31, 0x31, 0x6e, 0x70, 0xbe, 0x09, 0x72, 0x79, 0x42, + 0xe2, 0x3b, 0x3b, 0xd3, 0x0a, 0xe4, 0x9c, 0x34, 0x4c, 0x61, 0x74, 0x7c, 0xed, 0xe1, 0x84, 0x89, + 0x4b, 0xf4, 0xd5, 0xc3 +}; + +static char ecdh_cp_sharekey_secp521r1[] = { + 0x01, 0xaf, 0x53, 0x84, 0x60, 0x59, 0x79, 0x64, 0x09, 0x5f, 0x2b, 0x4e, 0x82, 0xc4, 0x79, 0x21, + 0x55, 0x9c, 0xb0, 0x2f, 0x7d, 0xd4, 0x2f, 0x5d, 0xca, 0xfc, 0x4f, 0x70, 0x28, 0x6e, 0x2b, 0x13, + 0x2e, 0x5f, 0xf0, 0x1f, 0x50, 0x87, 0xf5, 0x82, 0x2f, 0xa7, 0x31, 0x5b, 0xfd, 0x5c, 0x0e, 0xef, + 0xaf, 0x5c, 0x80, 0x53, 0x48, 0xed, 0xcf, 0x14, 0xdc, 0x91, 0xc5, 0xc9, 0x1b, 0xff, 0xa8, 0x16, + 0x42, 0xa8 +}; + +/* ecc sign or verf*/ +static unsigned char ecc_except_kinv_secp521r1[] = { + 0x71, 0x71, 0xb4, 0x5b, 0x79, 0x51, 0x94, 0x70, 0x53, 0xf9, 0x77, 0x02, 0x64, 0xef, 0xc4, 0xdb, + 0x64, 0xfc, 0xbe, 0x4e, 0x44, 0x4a, 0xc6, 0x54, 0x71, 0x69, 0x2e, 0x4a, 0x46, 0xa7, 0x2d, 0xa3 +}; + +static unsigned char ecc_except_e_secp521r1[] = { + 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 +}; + +static unsigned char sm2_k[] = { + 0x7c, 0x47, 0x81, 0x10, 0x54, 0xc6, 0xf9, 0x96, 0x13, 0xa5, 0x78, 0xeb, 0x84, 0x53, 0x70, 0x6c, + 0xcb, 0x96, 0x38, 0x4f, 0xe7, 0xdf, 0x5c, 0x17, 0x16, 0x71, 0xe7, 0x60, 0xbf, 0xa8, 0xbe, 0x3a +}; + +static unsigned char sm2_id[] = { + 0x41, 0x4c, 0x49, 0x43, 0x45, 0x31, 0x32, 0x33, 0x40, 0x59, 0x41, 0x48, 0x4f, 0x4f, 0x2e, 0x43, + 0x4f, 0x4d +}; + +static unsigned char sm2_plaintext[] = { + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74 +}; + +static unsigned char sm2_plaintext_l[513] = { + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20, 0x64, 0x69, 0x67, 0x65, 0x73, 0x74 +}; + +static unsigned char sm2_sign_data[] = { + /* r */ + 0xe6, 0xcd, 0x2d, 0xf9, 0x4f, 0x57, 0x40, 0x9e, 0x6b, 0xec, 0x8c, 0x0e, 0xf0, 0x44, 0x5c, 0xa4, + 0xfa, 0xea, 0x24, 0xe3, 0xf2, 0x28, 0x0e, 0xad, 0xc1, 0xa4, 0x1c, 0xf6, 0x24, 0x88, 0xaf, 0xd2, + + /* s */ + 0x98, 0x0e, 0x4f, 0xda, 0xbd, 0xe9, 0x9e, 0xc1, 0x6d, 0x59, 0x87, 0xd0, 0x23, 0x19, 0x84, 0xd1, + 0x94, 0x07, 0x7b, 0xb5, 0x43, 0xa8, 0x93, 0x00, 0xd4, 0xbb, 0xc7, 0xf8, 0x83, 0xb3, 0xf0, 0xc3, +}; + +static unsigned char sm2_ciphertext[] = { + /* c1 x */ + 0xe6, 0xcd, 0x2d, 0xf9, 0x4f, 0x57, 0x40, 0x9e, 0x6b, 0xec, 0x8c, 0x0e, 0xf0, 0x44, 0x5c, 0xa4, + 0xfa, 0xe9, 0xb7, 0x7e, 0x7e, 0xb4, 0xad, 0x46, 0x5c, 0x83, 0xb8, 0x8c, 0xbd, 0x23, 0x3c, 0x5e, + /* c1 y */ + 0x80, 0x89, 0xf0, 0xea, 0x2c, 0x84, 0x63, 0x45, 0xd8, 0x99, 0x7b, 0x5c, 0x2c, 0x75, 0x7d, 0x8e, + 0x5c, 0x99, 0x6e, 0x46, 0x85, 0x9f, 0x19, 0xd3, 0x7e, 0xb0, 0x3b, 0x24, 0xde, 0xab, 0xae, 0x30, + /* c3 */ + 0xfb, 0xcf, 0x24, 0x19, 0xf8, 0x61, 0x1c, 0xba, 0xb1, 0xd0, 0x6f, 0x4f, 0x84, 0xda, 0x9a, 0xe6, + 0x2d, 0x42, 0x27, 0xa1, 0x2b, 0x27, 0x26, 0x32, 0xc2, 0x6d, 0xda, 0x35, 0x54, 0xf9, 0xfc, 0xf8, + /* c2 */ + 0xdf, 0xe8, 0x59, 0xe8, 0x35, 0xb3, 0x98, 0x18, 0xca, 0x56, 0xaa, 0x29, 0x7b, 0x01, +}; + +static unsigned char sm2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xcd, 0x86, 0xa7, 0xb9, 0xb1, 0x74, 0xd0, 0x51, 0x3d, 0x1e, 0x8d, 0xb3, 0x4f, 0x46, 0x9f, 0xfb, + 0x36, 0x43, 0x3d, 0xff, 0xaf, 0x19, 0x29, 0xb5, 0x41, 0x4c, 0x75, 0x4d, 0x75, 0x41, 0x5e, 0xe1, + 0x86, 0x5b, 0xbb, 0x94, 0x13, 0xd3, 0xa7, 0x23, 0xb4, 0xfb, 0x6f, 0x7f, 0x36, 0xfe, 0x9f, 0xec, + 0x80, 0x56, 0x5c, 0x79, 0x78, 0x9d, 0xed, 0xe0, 0x0a, 0x68, 0xd9, 0xc1, 0x19, 0x93, 0x94, 0x2c, + 0x3d, +}; + +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 +}; + +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 +}; + +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 +}; +#endif diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c new file mode 100644 index 0000000..e722c36 --- /dev/null +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -0,0 +1,2433 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include <numa.h> +#include "uadk_benchmark.h" + +#include "hpre_uadk_benchmark.h" +#include "hpre_protocol_data.h" +#include "include/wd.h" +#include "include/wd_rsa.h" +#include "include/wd_dh.h" +#include "include/wd_ecc.h" +#include "include/wd_sched.h" + +#define ECC_CURVE_ID 0x3 /* def set secp256k1 */ +#define HPRE_TST_PRT printf +#define ERR_OPTYPE 0xFF +#define SM2_DG_SZ 1024 + +struct hpre_rsa_key_in { + void *e; + void *p; + void *q; + u32 e_size; + u32 p_size; + u32 q_size; + void *data[]; +}; + +static __thread struct hpre_rsa_key_in *rsa_key_in = NULL; +static const char rsa_m[8] = {0x54, 0x85, 0x9b, 0x34, 0x2c, 0x49, 0xea, 0x2a}; + +struct rsa_async_tag { + handle_t sess; +}; + +//----------------------------------RSA param--------------------------------------// +struct hpre_dh_param { + const void *x; + const void *p; + const void *g; + const void *except_pub_key; + const void *pub_key; + const void *share_key; + u32 x_size; + u32 p_size; + u32 g_size; + u32 pub_key_size; + u32 share_key_size; + u32 except_pub_key_size; + u32 key_bits; + u32 optype; +}; + +//----------------------------------DH param-------------------------------------// +struct hpre_ecc_setup { + void *except_pub_key; // use in ecdh phase 2 + const void *pub_key; // use in ecdh phase 1 + const void *share_key; // use in ecdh phase 2 + const void *digest; //use in ecdsa sign + const void *k; // ecdsa sign in + const void *rp; // x coordinate of k*generator used in ecdsa + const void *sign; // ecdsa sign out or verf in + const void *priv_key; // use in ecdsa sign + void *msg; // sm2 plaintext,ciphertext or digest input + const void *userid; // sm2 user id + const void *ciphertext; // sm2 ciphertext + const void *plaintext; // sm2 plaintext + u32 key_size; + u32 share_key_size; + u32 except_pub_key_size; + u32 digest_size; + u32 k_size; + u32 rp_size; + u32 sign_size; + u32 priv_key_size; + u32 pub_key_size; + u32 msg_size; + u32 userid_size; + u32 ciphertext_size; + u32 plaintext_size; + u32 op_type; + u32 key_bits; + u32 nid; + u32 curve_id; // WD ecc curve_id +}; + +//----------------------------------ECC param-------------------------------------// + +typedef struct uadk_thread_res { + u32 subtype; + u32 keybits; + u32 kmode; + u32 optype; + u32 td_id; +} thread_data; + +static struct wd_ctx_config g_ctx_cfg; +static struct wd_sched *g_sched; +static unsigned int g_thread_num; +static unsigned int g_ctxnum; + +static const char* const alg_operations[] = { + "GenKey", "ShareKey", "Encrypt", "Decrypt", "Sign", "Verify", +}; + +static void get_dh_param(u32 algtype, u32 *keysize) +{ + switch(algtype) { + case DH_768: + *keysize = 768; + break; + case DH_1024: + *keysize = 1024; + break; + case DH_1536: + *keysize = 1536; + break; + case DH_2048: + *keysize = 2048; + break; + case DH_3072: + *keysize = 3072; + break; + case DH_4096: + *keysize = 4096; + break; + } +} + +static u32 get_dh_optype(u32 optype) +{ + u32 op_type = 0; + + switch(optype) { + case 0: //GENKEY1 + op_type = WD_DH_PHASE1; + break; + case 1: //GENKEY12 + op_type = WD_DH_PHASE2; + break; + default: + HPRE_TST_PRT("failed to set dh op_type\n"); + HPRE_TST_PRT("DH Gen1: 0\n"); + HPRE_TST_PRT("DH Gen2: 1\n"); + return ERR_OPTYPE; + } + + return op_type; +} + +static void get_rsa_param(u32 algtype, u32 *keysize, u32 *mode) +{ + switch(algtype) { + case RSA_1024: + *keysize = 1024; + *mode = 0; + break; + case RSA_2048: + *keysize = 2048; + *mode = 0; + break; + case RSA_3072: + *keysize = 3072; + *mode = 0; + break; + case RSA_4096: + *keysize = 4096; + *mode = 0; + break; + case RSA_1024_CRT: + *keysize = 1024; + *mode = 1; + break; + case RSA_2048_CRT: + *keysize = 2048; + *mode = 1; + break; + case RSA_3072_CRT: + *keysize = 3072; + *mode = 1; + break; + case RSA_4096_CRT: + *keysize = 4096; + *mode = 1; + break; + } +} + +static u32 get_rsa_optype(u32 optype) +{ + u32 op_type = 0; + + switch(optype) { + case 0: //GENKEY1 + op_type = WD_RSA_GENKEY; + break; + case 4: //Sign + op_type = WD_RSA_SIGN; + break; + case 5: //Verf + op_type = WD_RSA_VERIFY; + break; + default: + HPRE_TST_PRT("failed to set rsa op_type\n"); + HPRE_TST_PRT("RSA Gen: 0\n"); + HPRE_TST_PRT("RSA Sign: 4\n"); + HPRE_TST_PRT("RSA Verf: 5\n"); + return ERR_OPTYPE; + } + + return op_type; +} + +static void get_ecc_param(u32 algtype, u32 *keysize) +{ + switch(algtype) { + case ECDH_256: + *keysize = 256; + break; + case ECDH_384: + *keysize = 384; + break; + case ECDH_521: + *keysize = 521; + break; + case ECDSA_256: + *keysize = 256; + break; + case ECDSA_384: + *keysize = 384; + break; + case ECDSA_521: + *keysize = 521; + break; + case SM2_ALG: + *keysize = 256; + break; + case X25519_ALG: + *keysize = 256; + break; + case X448_ALG: + *keysize = 448; + break; + } +} + +static u32 get_ecc_optype(u32 subtype, u32 optype) +{ + u32 op_type = 0; + + if (subtype == SM2_TYPE) { + switch (optype) { + case 0: + op_type = WD_SM2_KG; + break; + case 2: + op_type = WD_SM2_ENCRYPT; + break; + case 3: + op_type = WD_SM2_DECRYPT; + break; + case 4: + op_type = WD_SM2_SIGN; + break; + case 5: + op_type = WD_SM2_VERIFY; + break; + default: + HPRE_TST_PRT("failed to set SM2 op_type\n"); + HPRE_TST_PRT("SM2 KeyGen: 0\n"); + HPRE_TST_PRT("SM2 Encrypt: 2\n"); + HPRE_TST_PRT("SM2 Decrypt: 3\n"); + HPRE_TST_PRT("SM2 Sign: 4\n"); + HPRE_TST_PRT("SM2 Verify: 5\n"); + return ERR_OPTYPE; + } + } else if (subtype == ECDH_TYPE || + subtype == X25519_TYPE || subtype == X448_TYPE) { + switch(optype) { + case 0: //GENKEY + op_type = WD_ECXDH_GEN_KEY; + break; + case 1: //COMPUTEKEY + op_type = WD_ECXDH_COMPUTE_KEY; + break; + default: + HPRE_TST_PRT("failed to set ECDH op_type\n"); + HPRE_TST_PRT("ECDH GenKey: 0\n"); + HPRE_TST_PRT("ECDH ShareKey: 1\n"); + return ERR_OPTYPE; + } + } else if (subtype == ECDSA_TYPE) { + switch(optype) { + case 4: //Sign + op_type = WD_ECDSA_SIGN; + break; + case 5: //Verf + op_type = WD_ECDSA_VERIFY; + break; + default: + HPRE_TST_PRT("failed to set ECDSA op_type\n"); + HPRE_TST_PRT("ECDSA Sign: 4\n"); + HPRE_TST_PRT("ECDSA Verf: 5\n"); + return ERR_OPTYPE; + } + } + + return op_type; +} + +static int hpre_uadk_param_parse(thread_data *tddata, struct acc_option *options) +{ + u32 algtype = options->algtype; + u32 optype = 0; + u32 keysize = 0; + u32 mode = 0; + + if (algtype >= RSA_1024 && algtype <= RSA_4096_CRT) { + get_rsa_param(algtype, &keysize, &mode); + optype = get_rsa_optype(options->optype); + } else if (algtype <= DH_4096) { + get_dh_param(algtype, &keysize); + optype = get_dh_optype(options->optype); + } else if (algtype <= X448_ALG) { + get_ecc_param(algtype, &keysize); + optype = get_ecc_optype(options->subtype, options->optype); + } else { + HPRE_TST_PRT("failed to set hpre alg!\n"); + return -EINVAL; + } + + if (optype == ERR_OPTYPE) + return -EINVAL; + + /* HPRE package length is keybits */ + options->pktlen = keysize >> 3; + tddata->keybits = keysize; + tddata->kmode = mode; + tddata->optype = optype; + + HPRE_TST_PRT("%s to run %s task!\n", options->algclass, + alg_operations[options->optype]); + + return 0; +} + +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; + int ret = 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; + } + + switch(subtype) { + case RSA_TYPE: + g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_rsa_poll_ctx); + break; + case DH_TYPE: + g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_dh_poll_ctx); + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 1, max_node, wd_ecc_poll_ctx); + break; + default: + HPRE_TST_PRT("failed to parse alg subtype!\n"); + g_sched = NULL; + } + if (!g_sched) { + HPRE_TST_PRT("failed to alloc sched!\n"); + 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.type = 0; + param.mode = mode; + param.begin = 0; + param.end = g_ctxnum - 1; + ret = wd_sched_rr_instance(g_sched, ¶m); + if (ret) { + HPRE_TST_PRT("failed to fill hpre sched data!\n"); + goto out; + } + + /* init */ + switch(subtype) { + case RSA_TYPE: + ret = wd_rsa_init(&g_ctx_cfg, g_sched); + break; + case DH_TYPE: + ret = wd_dh_init(&g_ctx_cfg, g_sched); + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + ret = wd_ecc_init(&g_ctx_cfg, g_sched); + break; + default: + ret = -EINVAL; + } + if (ret) { + HPRE_TST_PRT("failed to get hpre ctx!\n"); + goto out; + } + + wd_free_list_accels(list); + + return 0; +out: + free(g_ctx_cfg.ctxs); + wd_sched_rr_release(g_sched); + + return ret; +} + +static void uninit_hpre_ctx_config(int subtype) +{ + int i; + + /* uninit */ + switch(subtype) { + case RSA_TYPE: + wd_rsa_uninit(); + break; + case DH_TYPE: + wd_dh_uninit(); + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + wd_ecc_uninit(); + break; + default: + HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); + return; + } + + for (i = 0; i < g_ctx_cfg.ctx_num; i++) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + free(g_ctx_cfg.ctxs); + wd_sched_rr_release(g_sched); +} + +/*-------------------------------uadk benchmark main code-------------------------------------*/ + +void *hpre_uadk_poll(void *data) +{ + typedef int (*poll_ctx)(__u32 idx, __u32 expt, __u32 *count); + poll_ctx uadk_poll_ctx = NULL; + thread_data *pdata = (thread_data *)data; + u32 expt = ACC_QUEUE_SIZE * g_thread_num; + u32 id = pdata->td_id; + u32 last_time = 2; // poll need one more recv time + u32 count = 0; + u32 recv = 0; + int ret; + + if (id > g_ctxnum) + return NULL; + + switch(pdata->subtype) { + case RSA_TYPE: + uadk_poll_ctx = wd_rsa_poll_ctx; + break; + case DH_TYPE: + uadk_poll_ctx = wd_dh_poll_ctx; + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + uadk_poll_ctx = wd_ecc_poll_ctx; + break; + default: + HPRE_TST_PRT("<<<<<<async poll interface is NULL!\n"); + return NULL; + } + + while (last_time) { + ret = uadk_poll_ctx(id, expt, &recv); + count += recv; + recv = 0; + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + HPRE_TST_PRT("poll ret: %u!\n", ret); + goto recv_error; + } + + if (get_run_state() == 0) + last_time--; + } + +recv_error: + add_recv_data(count, pdata->keybits >> 3); + + return NULL; +} + +static int get_rsa_key_from_sample(handle_t sess, char *privkey_file, + char *crt_privkey_file, u32 key_bits, u32 is_crt) +{ + struct wd_dtb wd_e, wd_d, wd_n, wd_dq, wd_dp, wd_qinv, wd_q, wd_p; + int e_bytes, d_bytes, n_bytes, q_bytes, p_bytes, qinv_bytes; + u8 *p, *q, *n, *e, *d, *dmp1, *dmq1, *iqmp; + int dq_bytes, dp_bytes, bits, wd_lenth; + u32 key_size = key_bits >> 3; + char *wd_mem; + int ret = 0; + + memset(&wd_e, 0, sizeof(wd_e)); + memset(&wd_d, 0, sizeof(wd_d)); + memset(&wd_n, 0, sizeof(wd_n)); + memset(&wd_dq, 0, sizeof(wd_dq)); + memset(&wd_dp, 0, sizeof(wd_dp)); + memset(&wd_qinv, 0, sizeof(wd_qinv)); + memset(&wd_q, 0, sizeof(wd_q)); + memset(&wd_p, 0, sizeof(wd_p)); + + bits = wd_rsa_get_key_bits(sess); + switch (bits) { + case 1024: + e = rsa_e_1024; + n = rsa_n_1024; + p = rsa_p_1024; + q = rsa_q_1024; + dmp1 = rsa_dp_1024; + dmq1 = rsa_dq_1024; + iqmp = rsa_qinv_1024; + d = rsa_d_1024; + e_bytes = ARRAY_SIZE(rsa_e_1024); + n_bytes = ARRAY_SIZE(rsa_n_1024); + q_bytes = ARRAY_SIZE(rsa_q_1024); + p_bytes = ARRAY_SIZE(rsa_p_1024); + dq_bytes = ARRAY_SIZE(rsa_dq_1024); + dp_bytes = ARRAY_SIZE(rsa_dp_1024); + qinv_bytes = ARRAY_SIZE(rsa_qinv_1024); + d_bytes = ARRAY_SIZE(rsa_d_1024); + break; + case 2048: + e = rsa_e_2048; + n = rsa_n_2048; + p = rsa_p_2048; + q = rsa_q_2048; + dmp1 = rsa_dp_2048; + dmq1 = rsa_dq_2048; + iqmp = rsa_qinv_2048; + d = rsa_d_2048; + e_bytes = ARRAY_SIZE(rsa_e_2048); + n_bytes = ARRAY_SIZE(rsa_n_2048); + q_bytes = ARRAY_SIZE(rsa_q_2048); + p_bytes = ARRAY_SIZE(rsa_p_2048); + dq_bytes = ARRAY_SIZE(rsa_dq_2048); + dp_bytes = ARRAY_SIZE(rsa_dp_2048); + qinv_bytes = ARRAY_SIZE(rsa_qinv_2048); + d_bytes = ARRAY_SIZE(rsa_d_2048); + break; + case 3072: + e = rsa_e_3072; + n = rsa_n_3072; + p = rsa_p_3072; + q = rsa_q_3072; + dmp1 = rsa_dp_3072; + dmq1 = rsa_dq_3072; + iqmp = rsa_qinv_3072; + d = rsa_d_3072; + e_bytes = ARRAY_SIZE(rsa_e_3072); + n_bytes = ARRAY_SIZE(rsa_n_3072); + q_bytes = ARRAY_SIZE(rsa_q_3072); + p_bytes = ARRAY_SIZE(rsa_p_3072); + dq_bytes = ARRAY_SIZE(rsa_dq_3072); + dp_bytes = ARRAY_SIZE(rsa_dp_3072); + qinv_bytes = ARRAY_SIZE(rsa_qinv_3072); + d_bytes = ARRAY_SIZE(rsa_d_3072); + break; + case 4096: + e = rsa_e_4096; + n = rsa_n_4096; + p = rsa_p_4096; + q = rsa_q_4096; + dmp1 = rsa_dp_4096; + dmq1 = rsa_dq_4096; + iqmp = rsa_qinv_4096; + d = rsa_d_4096; + e_bytes = ARRAY_SIZE(rsa_e_4096); + n_bytes = ARRAY_SIZE(rsa_n_4096); + q_bytes = ARRAY_SIZE(rsa_q_4096); + p_bytes = ARRAY_SIZE(rsa_p_4096); + dq_bytes = ARRAY_SIZE(rsa_dq_4096); + dp_bytes = ARRAY_SIZE(rsa_dp_4096); + qinv_bytes = ARRAY_SIZE(rsa_qinv_4096); + d_bytes = ARRAY_SIZE(rsa_d_4096); + break; + default: + HPRE_TST_PRT("invalid key bits = %d!\n", bits); + return -EINVAL; + } + + wd_lenth = e_bytes + n_bytes + q_bytes + p_bytes + dq_bytes + + dp_bytes + qinv_bytes + d_bytes; + wd_mem = malloc(wd_lenth); + if (!wd_mem) { + HPRE_TST_PRT("failed to alloc rsa key memory!\n"); + return -EINVAL; + } + + wd_e.data = wd_mem; + wd_n.data = wd_e.data + e_bytes; + + memcpy(wd_e.data, e, e_bytes); + wd_e.dsize = e_bytes; + memcpy(wd_n.data, n, n_bytes); + wd_n.dsize = n_bytes; + if (wd_rsa_set_pubkey_params(sess, &wd_e, &wd_n)) { + HPRE_TST_PRT("failed to set rsa pubkey!\n"); + ret = -EINVAL; + goto gen_fail; + } + + if (rsa_key_in) { + memcpy(rsa_key_in->e, e, e_bytes); + memcpy(rsa_key_in->p, p, p_bytes); + memcpy(rsa_key_in->q, q, q_bytes); + rsa_key_in->e_size = e_bytes; + rsa_key_in->p_size = p_bytes; + rsa_key_in->q_size = q_bytes; + } + + if (is_crt) { + wd_q.data = wd_n.data + n_bytes; + wd_p.data = wd_q.data + q_bytes; + wd_dq.data = wd_p.data + p_bytes; + wd_dp.data = wd_dq.data + dq_bytes; + wd_qinv.data = wd_dp.data + dp_bytes; + + /* CRT mode private key */ + wd_dq.dsize = dq_bytes; + memcpy(wd_dq.data, dmq1, dq_bytes); + + wd_dp.dsize = dp_bytes; + memcpy(wd_dp.data, dmp1, dp_bytes); + + wd_q.dsize = q_bytes; + memcpy(wd_q.data, q, q_bytes); + + wd_p.dsize = p_bytes; + memcpy(wd_p.data, p, p_bytes); + + wd_qinv.dsize = qinv_bytes; + memcpy(wd_qinv.data, iqmp, qinv_bytes); + + if (wd_rsa_set_crt_prikey_params(sess, &wd_dq, + &wd_dp, &wd_qinv, + &wd_q, &wd_p)) { + HPRE_TST_PRT("failed to set rsa crt prikey!\n"); + ret = -EINVAL; + goto gen_fail; + } + + if (crt_privkey_file) { + memcpy(crt_privkey_file, wd_dq.data, (key_bits >> 4) * 5); + memcpy(crt_privkey_file + (key_bits >> 4) * 5, + wd_e.data, (key_bits >> 2)); + } + + } else { + //wd_rsa_get_prikey_params(prikey, &wd_d, &wd_n); + wd_d.data = wd_mem + (wd_lenth - d_bytes); + + /* common mode private key */ + wd_d.dsize = d_bytes; + memcpy(wd_d.data, d, d_bytes); + + if (wd_rsa_set_prikey_params(sess, &wd_d, &wd_n)) { + HPRE_TST_PRT("failed to set rsa prikey!\n"); + ret = -EINVAL; + goto gen_fail; + } + + + if (privkey_file) { + memcpy(privkey_file, wd_d.data, key_size); + memcpy(privkey_file + key_size, wd_n.data, key_size); + memcpy(privkey_file + 2 * key_size, wd_e.data, key_size); + memcpy(privkey_file + 3 * key_size, wd_n.data, key_size); + } + } + +gen_fail: + free(wd_mem); + + return ret; +} + +static int get_hpre_keygen_opdata(handle_t sess, struct wd_rsa_req *req) +{ + struct wd_rsa_pubkey *pubkey; + struct wd_rsa_prikey *prikey; + struct wd_dtb t_e, t_p, t_q; + struct wd_dtb *e, *p, *q; + + wd_rsa_get_pubkey(sess, &pubkey); + wd_rsa_get_pubkey_params(pubkey, &e, NULL); + wd_rsa_get_prikey(sess, &prikey); + + if (wd_rsa_is_crt(sess)) { + wd_rsa_get_crt_prikey_params(prikey, NULL , NULL, NULL, &q, &p); + } else { + e = &t_e; + p = &t_p; + q = &t_q; + e->data = rsa_key_in->e; + e->dsize = rsa_key_in->e_size; + p->data = rsa_key_in->p; + p->dsize = rsa_key_in->p_size; + q->data = rsa_key_in->q; + q->dsize = rsa_key_in->q_size; + } + + req->src = wd_rsa_new_kg_in(sess, e, p, q); + if (!req->src) { + HPRE_TST_PRT("failed to create rsa kgen in!\n"); + return -ENOMEM; + } + req->dst = wd_rsa_new_kg_out(sess); + if (!req->dst) { + HPRE_TST_PRT("failed to create rsa kgen out!\n"); + wd_rsa_del_kg_in(sess, req->src); + return -ENOMEM; + } + + return 0; +} + +static int get_ecc_curve(struct hpre_ecc_setup *setup, u32 cid) +{ + switch (cid) { + case 0: // secp128R1 + setup->nid = 706; + setup->curve_id = WD_SECP128R1; + break; + case 1: // secp192K1 + setup->nid = 711; + setup->curve_id = WD_SECP192K1; + break; + case 2: // secp224R1 + setup->nid = 712; + setup->curve_id = WD_SECP224R1; + break; + case 3: // secp256K1 + setup->nid = 714; + setup->curve_id = WD_SECP256K1; + break; + case 4: // brainpoolP320R1 + setup->nid = 929; + setup->curve_id = WD_BRAINPOOLP320R1; + break; + case 5: // secp384R1 + setup->nid = 715; + setup->curve_id = WD_SECP384R1; + break; + case 6: // secp521R1 + setup->nid = 716; + setup->curve_id = WD_SECP521R1; + break; + default: + HPRE_TST_PRT("failed to get ecc curve id!\n"); + return -EINVAL; + } + + return 0; +} + +static int get_ecc_key_param(struct wd_ecc_curve *param, u32 key_bits) +{ + u32 key_size = (key_bits + 7) / 8; + + switch (key_bits) { + case 128: + param->a.data = ecdh_a_secp128r1; + param->b.data = ecdh_b_secp128r1; + param->p.data = ecdh_p_secp128r1; + param->n.data = ecdh_n_secp128r1; + param->g.x.data = ecdh_g_secp128r1; + param->g.y.data = ecdh_g_secp128r1 + key_size; + case 192: + param->a.data = ecdh_a_secp192k1; + param->b.data = ecdh_b_secp192k1; + param->p.data = ecdh_p_secp192k1; + param->n.data = ecdh_n_secp192k1; + param->g.x.data = ecdh_g_secp192k1; + param->g.y.data = ecdh_g_secp192k1 + key_size; + case 224: + param->a.data = ecdh_a_secp224r1; + param->b.data = ecdh_b_secp224r1; + param->p.data = ecdh_p_secp224r1; + param->n.data = ecdh_n_secp224r1; + param->g.x.data = ecdh_g_secp224r1; + param->g.y.data = ecdh_g_secp224r1 + key_size; + case 256: + param->a.data = ecdh_a_secp256k1; + param->b.data = ecdh_b_secp256k1; + param->p.data = ecdh_p_secp256k1; + param->n.data = ecdh_n_secp256k1; + param->g.x.data = ecdh_g_secp256k1; + param->g.y.data = ecdh_g_secp256k1 + key_size; + case 320: + param->a.data = ecdh_a_secp320k1; + param->b.data = ecdh_b_secp320k1; + param->p.data = ecdh_p_secp320k1; + param->n.data = ecdh_n_secp320k1; + param->g.x.data = ecdh_g_secp320k1; + param->g.y.data = ecdh_g_secp320k1 + key_size; + case 384: + param->a.data = ecdh_a_secp384r1; + param->b.data = ecdh_b_secp384r1; + param->p.data = ecdh_p_secp384r1; + param->n.data = ecdh_n_secp384r1; + param->g.x.data = ecdh_g_secp384r1; + param->g.y.data = ecdh_g_secp384r1 + key_size; + case 521: + param->a.data = ecdh_a_secp521r1; + param->b.data = ecdh_b_secp521r1; + param->p.data = ecdh_p_secp521r1; + param->n.data = ecdh_n_secp521r1; + param->g.x.data = ecdh_g_secp521r1; + param->g.y.data = ecdh_g_secp521r1 + key_size; + default: + HPRE_TST_PRT("key_bits %d not find\n", key_bits); + return -EINVAL; + } + + param->a.bsize = key_size; + param->a.dsize = key_size; + param->b.bsize = key_size; + param->b.dsize = key_size; + param->p.bsize = key_size; + param->p.dsize = key_size; + param->n.bsize = key_size; + param->n.dsize = key_size; + param->g.x.bsize = key_size; + param->g.x.dsize = key_size; + param->g.y.bsize = key_size; + param->g.y.dsize = key_size; + + return 0; +} + +static int ecc_get_rand(char *out, size_t out_len, void *usr) +{ + //int ret; + + get_rand_data((u8 *)out, out_len); + //ret = RAND_priv_bytes((void *)out, out_len); + //if (ret != 1) { + // HPRE_TST_PRT("failed to get ecc rand data:%d\n", ret); + // return -EINVAL; + //} + + return 0; +} + +static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup, + u32 subtype, u32 key_bits) +{ + int key_size = (key_bits + 7) / 8; + u32 len; + + setup->key_bits = key_bits; + + if (setup->nid == 714 || key_bits == 256) { // NID_secp256k1 + /* sm2 */ + if (subtype == SM2_TYPE) { + setup->priv_key = sm2_priv; + setup->priv_key_size = sizeof(sm2_priv); + setup->pub_key = sm2_pubkey; + setup->pub_key_size = sizeof(sm2_pubkey); + + len = SM2_DG_SZ; + setup->msg = malloc(len); + if (!setup->msg) + return -1; + memset(setup->msg, 0xFF, len); + + if (true) { // for msg_sigest mode + memcpy(setup->msg, sm2_digest, sizeof(sm2_digest)); + setup->msg_size = sizeof(sm2_digest); + } else { + memcpy(setup->msg, sm2_plaintext, sizeof(sm2_plaintext)); + setup->msg_size = sizeof(sm2_plaintext); + } + + if (setup->msg_size > 512) { + setup->ciphertext = sm2_ciphertext_l; + setup->ciphertext_size = sizeof(sm2_ciphertext_l); + setup->plaintext = sm2_plaintext_l; + setup->plaintext_size = sizeof(sm2_plaintext_l); + } else { + setup->ciphertext = sm2_ciphertext; + setup->ciphertext_size = sizeof(sm2_ciphertext); + setup->plaintext = sm2_plaintext; + setup->plaintext_size = sizeof(sm2_plaintext); + } + + setup->k = sm2_k; + setup->k_size = sizeof(sm2_k); + setup->userid = sm2_id; + setup->userid_size = sizeof(sm2_id); + setup->sign = sm2_sign_data; + setup->sign_size = sizeof(sm2_sign_data); + + } else { + setup->priv_key = ecdh_da_secp256k1; + setup->except_pub_key = ecdh_except_b_pubkey_secp256k1; + setup->pub_key = ecdh_cp_pubkey_secp256k1; + setup->share_key = ecdh_cp_sharekey_secp256k1; + setup->priv_key_size = sizeof(ecdh_da_secp256k1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp256k1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp256k1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp256k1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp256k1; + setup->msg_size = sizeof(ecc_except_e_secp256k1); + setup->k = ecc_except_kinv_secp256k1; + setup->k_size = sizeof(ecc_except_kinv_secp256k1); + setup->rp = ecdh_cp_pubkey_secp256k1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + } + } else if (setup->nid == 706 || key_bits == 128) { + setup->priv_key = ecdh_da_secp128r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp128r1; + setup->pub_key = ecdh_cp_pubkey_secp128r1; + setup->share_key = ecdh_cp_sharekey_secp128r1; + setup->priv_key_size = sizeof(ecdh_da_secp128r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp128r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp128r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp128r1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp128r1; + setup->msg_size = sizeof(ecc_except_e_secp128r1); + setup->k = ecc_except_kinv_secp128r1; + setup->k_size = sizeof(ecc_except_kinv_secp128r1); + setup->rp = ecdh_cp_pubkey_secp128r1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp128r1; + setup->sign_size = sizeof(ecc_cp_sign_secp128r1); + + } else if (setup->nid == 711 || key_bits == 192) { + setup->priv_key = ecdh_da_secp192k1; + setup->except_pub_key = ecdh_except_b_pubkey_secp192k1; + setup->pub_key = ecdh_cp_pubkey_secp192k1; + setup->share_key = ecdh_cp_sharekey_secp192k1; + setup->priv_key_size = sizeof(ecdh_da_secp192k1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp192k1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp192k1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp192k1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp192k1; + setup->msg_size = sizeof(ecc_except_e_secp192k1); + setup->k = ecc_except_kinv_secp192k1; + setup->k_size = sizeof(ecc_except_kinv_secp192k1); + setup->rp = ecdh_cp_pubkey_secp192k1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + } else if (setup->nid == 712 || key_bits == 224) { + setup->priv_key = ecdh_da_secp224r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp224r1; + setup->pub_key = ecdh_cp_pubkey_secp224r1; + setup->share_key = ecdh_cp_sharekey_secp224r1; + setup->priv_key_size = sizeof(ecdh_da_secp224r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp224r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp224r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp224r1); + } else if (setup->nid == 929 || key_bits == 320) { + setup->priv_key = ecdh_da_secp320k1; + setup->except_pub_key = ecdh_except_b_pubkey_secp320k1; + setup->pub_key = ecdh_cp_pubkey_secp320k1; + setup->share_key = ecdh_cp_sharekey_secp320k1; + setup->priv_key_size = sizeof(ecdh_da_secp320k1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp320k1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp320k1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp320k1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp320k1; + setup->msg_size = sizeof(ecc_except_e_secp320k1); + setup->k = ecc_except_kinv_secp320k1; + setup->k_size = sizeof(ecc_except_kinv_secp320k1); + setup->rp = ecdh_cp_pubkey_secp192k1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + + } else if (setup->nid == 931 || key_bits == 384) { + setup->priv_key = ecdh_da_secp384r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp384r1; + setup->pub_key = ecdh_cp_pubkey_secp384r1; + setup->share_key = ecdh_cp_sharekey_secp384r1; + setup->priv_key_size = sizeof(ecdh_da_secp384r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp384r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp384r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp384r1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp384r1; + setup->msg_size = sizeof(ecc_except_e_secp384r1); + setup->k = ecc_except_kinv_secp384r1; + setup->k_size = sizeof(ecc_except_kinv_secp384r1); + setup->rp = ecdh_cp_pubkey_secp384r1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + } else if (setup->nid == 716 || key_bits == 521) { + setup->priv_key = ecdh_da_secp521r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp521r1; + setup->pub_key = ecdh_cp_pubkey_secp521r1; + setup->share_key = ecdh_cp_sharekey_secp521r1; + setup->priv_key_size = sizeof(ecdh_da_secp521r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp521r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp521r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp521r1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp521r1; + setup->msg_size = sizeof(ecc_except_e_secp521r1); + setup->k = ecc_except_kinv_secp521r1; + setup->k_size = sizeof(ecc_except_kinv_secp521r1); + setup->rp = ecdh_cp_pubkey_secp521r1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + + } else { + HPRE_TST_PRT("init test sess setup not find this bits %d or nid %d\n", + key_bits, setup->nid); + return -EINVAL; + } + + return 0; +} + +static void *rsa_uadk_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wd_rsa_sess_setup setup; + struct wd_rsa_req req; + void *key_info = NULL; + handle_t h_sess; + u32 count = 0; + int ret; + + memset(&setup, 0, sizeof(setup)); + memset(&req, 0, sizeof(req)); + setup.key_bits = pdata->keybits; + setup.is_crt = pdata->kmode; + + h_sess = wd_rsa_alloc_sess(&setup); + if (!h_sess) + return NULL; + + key_info = malloc(key_size * 16); + if (!key_info) { + HPRE_TST_PRT("failed to alloc RSA key info!\n"); + return NULL; + } + memset(key_info, 0, key_size * 16); + + rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); + if (!rsa_key_in) { + HPRE_TST_PRT("failed to alloc RSA key input param!\n"); + goto key_release; + } + rsa_key_in->e = rsa_key_in + 1; + rsa_key_in->p = rsa_key_in->e + key_size; + rsa_key_in->q = rsa_key_in->p + (key_size >> 1); + + ret = get_rsa_key_from_sample(h_sess, key_info, key_info, + pdata->keybits, pdata->kmode); + if (ret) { + HPRE_TST_PRT("failed to get sample key data!\n"); + goto sample_release; + } + + req.src_bytes = key_size; + req.dst_bytes = key_size; + req.op_type = pdata->optype; + if (req.op_type == WD_RSA_GENKEY) { + ret = get_hpre_keygen_opdata(h_sess, &req); + if (ret){ + HPRE_TST_PRT("failed to fill rsa key gen req!\n"); + goto sample_release; + } + } else { + req.src = malloc(key_size); + if (!req.src) { + HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); + goto sample_release; + } + memset(req.src, 0, req.src_bytes); + memcpy(req.src + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); + req.dst = malloc(key_size); + if (!req.dst) { + HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); + goto src_release; + } + } + + do { + ret = wd_do_rsa_sync(h_sess, &req); + if (ret || req.status) { + HPRE_TST_PRT("failed to do rsa task, status: %d\n", req.status); + goto dst_release; + } + + count++; + if (get_run_state() == 0) + break; + } while(true); + + /* clean output buffer remainings in the last time operation */ + if (req.op_type == WD_RSA_GENKEY) { + char *data; + int len; + + len = wd_rsa_kg_out_data((void *)req.dst, &data); + if (len < 0) { + HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); + goto sample_release; + } + memset(data, 0, len); + + wd_rsa_del_kg_in(h_sess, req.src); + req.src = NULL; + wd_rsa_del_kg_out(h_sess, req.dst); + req.dst = NULL; + } + +dst_release: + if (req.dst) + free(req.dst); +src_release: + if (req.src) + free(req.src); +sample_release: + free(rsa_key_in); +key_release: + free(key_info); + + wd_rsa_free_sess(h_sess); + add_recv_data(count, key_size); + + return NULL; +} + +static void rsa_async_cb(void *req_t) +{ + //struct wd_rsa_req *req = req_t; + //struct rsa_async_tag *tag = req->cb_param; + //enum wd_rsa_op_type op_type = req->op_type; + //handle_t h_sess = tag->sess; + + return; +} + +static void *rsa_uadk_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct rsa_async_tag *tag; + struct wd_rsa_sess_setup setup; + struct wd_rsa_req req; + void *key_info = NULL; + int try_cnt = 0; + handle_t h_sess; + u32 count = 0; + int i, ret; + + memset(&setup, 0, sizeof(setup)); + memset(&req, 0, sizeof(req)); + setup.key_bits = pdata->keybits; + setup.is_crt = pdata->kmode; + + h_sess = wd_rsa_alloc_sess(&setup); + if (!h_sess) + return NULL; + + key_info = malloc(key_size * 16); + if (!key_info) { + HPRE_TST_PRT("failed to alloc RSA key info!\n"); + return NULL; + } + memset(key_info, 0, key_size * 16); + + rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); + if (!rsa_key_in) { + HPRE_TST_PRT("failed to alloc RSA key input param!\n"); + goto key_release; + } + rsa_key_in->e = rsa_key_in + 1; + rsa_key_in->p = rsa_key_in->e + key_size; + rsa_key_in->q = rsa_key_in->p + (key_size >> 1); + + ret = get_rsa_key_from_sample(h_sess, key_info, key_info, + pdata->keybits, pdata->kmode); + if (ret) { + HPRE_TST_PRT("failed to get sample key data!\n"); + goto sample_release; + } + + req.src_bytes = key_size; + req.dst_bytes = key_size; + req.op_type = pdata->optype; + if (req.op_type == WD_RSA_GENKEY) { + ret = get_hpre_keygen_opdata(h_sess, &req); + if (ret){ + HPRE_TST_PRT("failed to fill rsa key gen req!\n"); + goto sample_release; + } + } else { + req.src = malloc(key_size); + if (!req.src) { + HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); + goto sample_release; + } + memset(req.src, 0, req.src_bytes); + memcpy(req.src + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); + req.dst = malloc(key_size); + if (!req.dst) { + HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); + goto src_release; + } + } + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + HPRE_TST_PRT("failed to malloc rsa tag!\n"); + goto dst_release; + } + req.cb = rsa_async_cb; + + do { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + tag[i].sess = h_sess; + req.cb_param = &tag[i]; + + ret = wd_do_rsa_async(h_sess, &req); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + HPRE_TST_PRT("Test RSA send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret) { + HPRE_TST_PRT("failed to do rsa async task!\n"); + goto tag_release; + } + count++; + } while(true); + + /* clean output buffer remainings in the last time operation */ + if (req.op_type == WD_RSA_GENKEY) { + char *data; + int len; + + len = wd_rsa_kg_out_data((void *)req.dst, &data); + if (len < 0) { + HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); + goto tag_release; + } + memset(data, 0, len); + + wd_rsa_del_kg_in(h_sess, req.src); + req.src = NULL; + wd_rsa_del_kg_out(h_sess, req.dst); + req.dst = NULL; + } + +tag_release: + free(tag); +dst_release: + if (req.dst) + free(req.dst); +src_release: + if (req.src) + free(req.src); +sample_release: + free(rsa_key_in); +key_release: + free(key_info); + + wd_rsa_free_sess(h_sess); + add_send_complete(); + + return NULL; +} + +static int get_dh_param_from_sample(struct hpre_dh_param *setup, + u32 key_bits, u8 is_g2) +{ + setup->key_bits = key_bits; + + switch (key_bits) { + case 768: + setup->x = dh_xa_768; + setup->p = dh_p_768; + setup->except_pub_key = dh_except_b_pubkey_768; + setup->pub_key = dh_except_a_pubkey_768; + setup->share_key = dh_share_key_768; + setup->x_size = sizeof(dh_xa_768); + setup->p_size = sizeof(dh_p_768); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_768); + setup->pub_key_size = sizeof(dh_except_a_pubkey_768); + setup->share_key_size = sizeof(dh_share_key_768); + break; + case 1024: + setup->x = dh_xa_1024; + setup->p = dh_p_1024; + setup->except_pub_key = dh_except_b_pubkey_1024; + setup->pub_key = dh_except_a_pubkey_1024; + setup->share_key = dh_share_key_1024; + setup->x_size = sizeof(dh_xa_1024); + setup->p_size = sizeof(dh_p_1024); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1024); + setup->pub_key_size = sizeof(dh_except_a_pubkey_1024); + setup->share_key_size = sizeof(dh_share_key_1024); + break; + case 1536: + setup->x = dh_xa_1536; + setup->p = dh_p_1536; + setup->except_pub_key = dh_except_b_pubkey_1536; + setup->pub_key = dh_except_a_pubkey_1536; + setup->share_key = dh_share_key_1536; + setup->x_size = sizeof(dh_xa_1536); + setup->p_size = sizeof(dh_p_1536); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1536); + setup->pub_key_size = sizeof(dh_except_a_pubkey_1536); + setup->share_key_size = sizeof(dh_share_key_1536); + break; + case 2048: + setup->x = dh_xa_2048; + setup->p = dh_p_2048; + setup->except_pub_key = dh_except_b_pubkey_2048; + setup->pub_key = dh_except_a_pubkey_2048; + setup->share_key = dh_share_key_2048; + setup->x_size = sizeof(dh_xa_2048); + setup->p_size = sizeof(dh_p_2048); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_2048); + setup->pub_key_size = sizeof(dh_except_a_pubkey_2048); + setup->share_key_size = sizeof(dh_share_key_2048); + break; + case 3072: + setup->x = dh_xa_3072; + setup->p = dh_p_3072; + setup->except_pub_key = dh_except_b_pubkey_3072; + setup->pub_key = dh_except_a_pubkey_3072; + setup->share_key = dh_share_key_3072; + setup->x_size = sizeof(dh_xa_3072); + setup->p_size = sizeof(dh_p_3072); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_3072); + setup->pub_key_size = sizeof(dh_except_a_pubkey_3072); + setup->share_key_size = sizeof(dh_share_key_3072); + break; + case 4096: + setup->x = dh_xa_4096; + setup->p = dh_p_4096; + setup->except_pub_key = dh_except_b_pubkey_4096; + setup->pub_key = dh_except_a_pubkey_4096; + setup->share_key = dh_share_key_4096; + setup->x_size = sizeof(dh_xa_4096); + setup->p_size = sizeof(dh_p_4096); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_4096); + setup->pub_key_size = sizeof(dh_except_a_pubkey_4096); + setup->share_key_size = sizeof(dh_share_key_4096); + break; + default: + HPRE_TST_PRT("failed to find dh keybits %u\n", key_bits); + return -EINVAL; + } + + if (is_g2) { + setup->g = dh_g_2; + } else { + setup->g = dh_g_5; + } + setup->g_size = 1; + + return 0; +} + +static int get_dh_opdata_param(handle_t h_sess, struct wd_dh_req *req, + struct hpre_dh_param *setup, int key_size) +{ + unsigned char *ag_bin = NULL; + struct wd_dtb ctx_g; + int ret; + + ag_bin = malloc(2 * key_size); + if (!ag_bin) + return -ENOMEM; + + memset(ag_bin, 0, 2 * key_size); + req->pv = ag_bin; + + req->x_p = malloc(2 * key_size); + if (!req->x_p) + goto ag_error; + + memset(req->x_p, 0, 2 * key_size); + + req->pri = malloc(2 * key_size); + if (!req->pri) + goto xp_error; + + memset(req->pri, 0, 2 * key_size); + req->pri_bytes = 2 * key_size; + + ctx_g.data = malloc(key_size); + if (!ctx_g.data) + goto ctx_release; + + if (setup->optype == WD_DH_PHASE1) { // GEN1 + memcpy(req->x_p, setup->x, setup->x_size); + memcpy(req->x_p + key_size, setup->p, setup->p_size); + memcpy(ctx_g.data, setup->g, setup->g_size); + req->pbytes = setup->p_size; + req->xbytes = setup->x_size; + ctx_g.dsize = setup->g_size; + ctx_g.bsize = key_size; + + ret = wd_dh_set_g(h_sess, &ctx_g); + if (ret) + HPRE_TST_PRT("wd_dh_set_g run failed\n"); + } else { // GEN1 + memcpy(req->x_p, setup->x, setup->x_size); + memcpy(req->x_p + key_size, setup->p, setup->p_size); + memcpy(req->pv, setup->except_pub_key, setup->except_pub_key_size); + req->pbytes = setup->p_size; + req->xbytes = setup->x_size; + req->pvbytes = setup->except_pub_key_size; + } + + free(ctx_g.data); + + return 0; + +ctx_release: + free(req->pri); +xp_error: + free(req->x_p); +ag_error: + free(req->pv); + + return -ENOMEM; +} + +static void dh_async_cb(void *req_t) +{ + //struct wd_dh_req *req = req_t; + //struct rsa_async_tag *tag = req->cb_param; + //enum wd_rsa_op_type op_type = req->op_type; + //handle_t h_sess = tag->sess; + + return; +} + +static void *dh_uadk_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wd_dh_sess_setup dh_setup; + struct rsa_async_tag *tag; + struct hpre_dh_param param; + struct wd_dh_req req; + handle_t h_sess; + int try_cnt = 0; + u32 count = 0; + int i, ret; + + memset(&dh_setup, 0, sizeof(dh_setup)); + memset(&req, 0, sizeof(req)); + dh_setup.key_bits = pdata->keybits; + if (pdata->optype == WD_DH_PHASE2) + dh_setup.is_g2 = true; // G1 is 0; G2 is 1; + + h_sess = wd_dh_alloc_sess(&dh_setup); + if (!h_sess) + return NULL; + + ret = get_dh_param_from_sample(¶m, pdata->keybits, pdata->kmode); + if (ret) + goto sess_release; + + param.optype = pdata->optype; + req.op_type = pdata->optype; + ret = get_dh_opdata_param(h_sess, &req, ¶m, key_size); + if (ret){ + HPRE_TST_PRT("failed to fill dh key gen req!\n"); + goto param_release; + } + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + HPRE_TST_PRT("failed to malloc rsa tag!\n"); + goto param_release; + } + req.cb = dh_async_cb; + + do { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + tag[i].sess = h_sess; + req.cb_param = &tag[i]; + + ret = wd_do_dh_async(h_sess, &req); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + HPRE_TST_PRT("Test DH send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret) { + HPRE_TST_PRT("failed to do DH async task!\n"); + goto tag_release; + } + count++; + } while(true); + +tag_release: + free(tag); +param_release: + free(req.x_p); + free(req.pv); + free(req.pri); +sess_release: + wd_dh_free_sess(h_sess); + add_send_complete(); + + return NULL; +} + +static void *dh_uadk_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wd_dh_sess_setup dh_setup; + struct hpre_dh_param setup; + struct wd_dh_req req; + handle_t h_sess; + u32 count = 0; + int ret; + + memset(&dh_setup, 0, sizeof(dh_setup)); + memset(&req, 0, sizeof(req)); + dh_setup.key_bits = pdata->keybits; + if (pdata->optype == WD_DH_PHASE2) + dh_setup.is_g2 = true; // G1 is 0; G2 is 1; + + h_sess = wd_dh_alloc_sess(&dh_setup); + if (!h_sess) + return NULL; + + ret = get_dh_param_from_sample(&setup, pdata->keybits, pdata->kmode); + if (ret) + goto sess_release; + + setup.optype = pdata->optype; + req.op_type = pdata->optype; + ret = get_dh_opdata_param(h_sess, &req, &setup, key_size); + if (ret){ + HPRE_TST_PRT("failed to fill dh key gen req!\n"); + goto param_release; + } + + do { + ret = wd_do_dh_sync(h_sess, &req); + if (ret || req.status) { + HPRE_TST_PRT("failed to do dh task, status: %d\n", req.status); + goto param_release; + } + + count++; + if (get_run_state() == 0) + break; + } while(true); + +param_release: + free(req.x_p); + free(req.pv); + free(req.pri); +sess_release: + wd_dh_free_sess(h_sess); + add_recv_data(count, key_size); + + return NULL; +} + +static int hpre_compute_hash(const char *in, size_t in_len, + char *out, size_t out_len, void *usr) +{ + /* perf test for none hash check */ + return 0; +} + +static int ecdsa_param_fill(handle_t h_sess, struct wd_ecc_req *req, + struct wd_ecc_key *ecc_key, struct hpre_ecc_setup *setup, + thread_data *pdata) +{ + int key_insize = (pdata->keybits + 7) / 8; + u32 optype = pdata->optype; + struct wd_ecc_out *ecc_out = NULL; + struct wd_ecc_in *ecc_in = NULL; + struct wd_ecc_point pub; + struct wd_dtb d, e, k; + int ret = 0; + + if (optype == WD_ECDSA_SIGN) {// Sign + ecc_out = wd_ecdsa_new_sign_out(h_sess); + if (!ecc_out) { + HPRE_TST_PRT("failed to get ecdsa out!\n"); + return -ENOMEM; + } + + d.data = (void *)setup->priv_key; + d.dsize = setup->priv_key_size; + d.bsize = setup->priv_key_size; + ret = wd_ecc_set_prikey(ecc_key, &d); + if (ret) { + HPRE_TST_PRT("failed to set ecdsa prikey!\n"); + goto del_ecc_out; + } + + pub.x.data = (void *)setup->pub_key + 1; + pub.x.dsize = key_insize; + pub.x.bsize = key_insize; + pub.y.data = pub.x.data + key_insize; + pub.y.dsize = key_insize; + pub.y.bsize = key_insize; + ret = wd_ecc_set_pubkey(ecc_key, &pub); + if (ret) { + HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); + goto del_ecc_out; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = key_insize; + + k.data = (void *)setup->k; + k.dsize = setup->k_size; + k.bsize = key_insize; + ecc_in = wd_ecdsa_new_sign_in(h_sess, &e, &k); + if (!ecc_in) { + HPRE_TST_PRT("failed to get ecdsa sign in!\n"); + ret = -ENOMEM; + goto del_ecc_out; + } + + req->src = ecc_in; + req->dst = ecc_out; + } else { // Verf + pub.x.data = (void *)setup->pub_key + 1; + pub.x.dsize = key_insize; + pub.x.bsize = key_insize; + pub.y.data = pub.x.data + key_insize; + pub.y.dsize = key_insize; + pub.y.bsize = key_insize; + ret = wd_ecc_set_pubkey(ecc_key, &pub); + if (ret) { + HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = key_insize; + + d.data = (void *)setup->sign; + d.dsize = key_insize; + d.bsize = key_insize; + k.data = d.data + key_insize; + k.dsize = key_insize; + k.bsize = key_insize; + ecc_in = wd_ecdsa_new_verf_in(h_sess, &e, &d, &k); + if (!ecc_in) { + HPRE_TST_PRT("failed to get ecdsa verf ecc in!\n"); + return -ENOMEM; + } + + req->src = ecc_in; + } + + return 0; +del_ecc_out: + if (ecc_out) + (void)wd_ecc_del_out(h_sess, ecc_out); + return ret; +} + +static int sm2_param_fill(handle_t h_sess, struct wd_ecc_req *req, + struct hpre_ecc_setup *setup, thread_data *pdata) +{ + int key_insize = (pdata->keybits + 7) / 8; + u32 optype = pdata->optype; + struct wd_ecc_out *ecc_out = NULL; + struct wd_ecc_in *ecc_in = NULL; + struct wd_ecc_point tmp; + struct wd_dtb d, e, k; + + switch (optype) { + case WD_SM2_SIGN:// Sign + ecc_out = wd_sm2_new_sign_out(h_sess); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = setup->msg_size; + k.data = (void *)setup->k; + k.dsize = setup->k_size; + k.bsize = key_insize; + ecc_in = wd_sm2_new_sign_in(h_sess, &e, &k, NULL, 1); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + goto del_ecc_out; + } + req->src = ecc_in; + req->dst = ecc_out; + break; + case WD_SM2_VERIFY: // Verf + ecc_out = wd_sm2_new_sign_out(h_sess); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = key_insize; + d.data = (void *)setup->sign; + d.dsize = key_insize; + d.bsize = key_insize; + k.data = d.data + key_insize; + k.dsize = key_insize; + k.bsize = key_insize; + ecc_in = wd_sm2_new_verf_in(h_sess, &e, &d, &k, NULL, 1); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + goto del_ecc_out; + } + + req->src = ecc_in; + req->dst = ecc_out; + break; + case WD_SM2_ENCRYPT: // Enc + ecc_out = wd_sm2_new_enc_out(h_sess, setup->msg_size); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->plaintext; + e.dsize = setup->plaintext_size; + e.bsize = setup->plaintext_size; + k.data = (void *)setup->k; + k.dsize = setup->k_size; + k.bsize = key_insize; + ecc_in = wd_sm2_new_enc_in(h_sess, &e, &k); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + goto del_ecc_out; + } + req->src = ecc_in; + req->dst = ecc_out; + break; + case WD_SM2_DECRYPT: // Dec + tmp.x.data = (void *)setup->ciphertext; + tmp.x.dsize = 32; + tmp.y.data = tmp.x.data + 32; + tmp.y.dsize = 32; + e.data = tmp.y.data + 32; + e.dsize = 32; + d.data = e.data + 32; + d.dsize = setup->ciphertext_size - 32 * 3; + ecc_in = wd_sm2_new_dec_in(h_sess, &tmp, &d, &e); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + return -ENOMEM; + } + + ecc_out = wd_sm2_new_dec_out(h_sess, d.dsize); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + goto del_ecc_in; + } + + req->src = ecc_in; + req->dst = ecc_out; + break; + case WD_SM2_KG: // KG + ecc_out = wd_sm2_new_kg_out(h_sess); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + req->dst = ecc_out; + break; + default: + HPRE_TST_PRT("failed to match sm2 optype!\n"); + return -ENOMEM; + } + + return 0; + +del_ecc_in: + if (ecc_in) + (void)wd_ecc_del_in(h_sess, ecc_in); +del_ecc_out: + if (ecc_out) + (void)wd_ecc_del_out(h_sess, ecc_out); + + return -ENOMEM; +} + +static int ecc_param_fill(handle_t h_sess, struct wd_ecc_req *req, + struct wd_ecc_key *ecc_key, struct hpre_ecc_setup *setup, + thread_data *pdata) +{ + int key_insize = (pdata->keybits + 7) / 8; + u32 subtype = pdata->subtype; + u32 optype = pdata->optype; + struct wd_ecc_out *ecc_out = NULL; + struct wd_ecc_in *ecc_in = NULL; + struct wd_ecc_point tmp; + struct wd_dtb d; + int ret = 0; + + ecc_out = wd_ecxdh_new_out(h_sess); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc ecc out!\n"); + return -ENOMEM; + } + if (optype == WD_ECXDH_GEN_KEY) { // gen + d.data = (void *)setup->priv_key; + d.dsize = setup->priv_key_size; + d.bsize = setup->priv_key_size; + ret = wd_ecc_set_prikey(ecc_key, &d); + if (ret) { + HPRE_TST_PRT("failed to set ecxdh prikey!\n"); + goto del_ecc_out; + } + + req->dst = ecc_out; + } else { // compute + if (subtype == ECDH_TYPE) + tmp.x.data = setup->except_pub_key; + else + tmp.x.data = setup->except_pub_key + 1; + tmp.x.bsize = key_insize; + tmp.x.dsize = key_insize; + tmp.y.data = tmp.x.data + key_insize; + tmp.y.bsize = key_insize; + tmp.y.dsize = key_insize; + ecc_in = wd_ecxdh_new_in(h_sess, &tmp); + if (!ecc_in) { + HPRE_TST_PRT("failed to get ecxdh sign in!\n"); + goto del_ecc_out; + } + + d.data = (void *)setup->priv_key; + d.dsize = setup->priv_key_size; + d.bsize = setup->priv_key_size; + ret = wd_ecc_set_prikey(ecc_key, &d); + if (ret) { + HPRE_TST_PRT("failed to set ecc prikey!\n"); + goto del_ecc_out; + } + + req->src = ecc_in; + req->dst = ecc_out; + } + + return 0; + +del_ecc_out: + if (ecc_out) + (void)wd_ecc_del_out(h_sess, ecc_out); + + return ret; +} + +static void *ecc_uadk_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + u32 subtype = pdata->subtype; + struct wd_ecc_sess_setup sess_setup; + struct hpre_ecc_setup setup; + struct wd_ecc_curve param; + struct wd_ecc_key *ecc_key; + struct wd_ecc_point pbk; + struct wd_dtb prk; + struct wd_ecc_req req; + u32 cid = ECC_CURVE_ID; + handle_t h_sess; + u32 count = 0; + int ret; + + memset(&sess_setup, 0, sizeof(sess_setup)); + memset(¶m, 0, sizeof(param)); + memset(&req, 0, sizeof(req)); + + memset(&setup, 0, sizeof(setup)); + if (subtype != X448_TYPE || subtype != X25519_TYPE) { + ret = get_ecc_curve(&setup, cid); + if (ret) + return NULL; + } + + sess_setup.key_bits = pdata->keybits; + if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { + if (cid > ECC_CURVE_ID) { + sess_setup.cv.type = WD_CV_CFG_PARAM; + get_ecc_key_param(¶m, pdata->keybits); + sess_setup.cv.cfg.pparam = ¶m; + } else { + sess_setup.cv.type = WD_CV_CFG_ID; + sess_setup.cv.cfg.id = setup.curve_id; + } + } + + sess_setup.rand.cb = ecc_get_rand; + switch (subtype) { + case SM2_TYPE: + sess_setup.alg = "sm2"; + break; + case ECDH_TYPE: + sess_setup.alg = "ecdh"; + break; + case ECDSA_TYPE: + sess_setup.alg = "ecdsa"; + break; + } + + // set def setting; + sess_setup.hash.cb = hpre_compute_hash; + sess_setup.hash.type = WD_HASH_SHA256; + + ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); + if (ret) + return NULL; + + h_sess = wd_ecc_alloc_sess(&sess_setup); + if (!h_sess) + goto msg_release; + + prk.data = (void *)setup.priv_key; + prk.dsize = setup.priv_key_size; + prk.bsize = setup.priv_key_size; + pbk.x.data = (char *)setup.pub_key + 1; + pbk.x.dsize = key_size; + pbk.x.bsize = key_size; + pbk.y.data = pbk.x.data + key_size; + pbk.y.dsize = key_size; + pbk.y.bsize = key_size; + + ecc_key = wd_ecc_get_key(h_sess); + ret = wd_ecc_set_prikey(ecc_key, &prk); + if (ret) { + HPRE_TST_PRT("failed to pre set ecc prikey!\n"); + goto sess_release; + } + + ret = wd_ecc_set_pubkey(ecc_key, &pbk); + if (ret) { + HPRE_TST_PRT("failed to pre set ecc pubkey!\n"); + goto sess_release; + } + + req.op_type = pdata->optype; + switch (subtype) { + case ECDSA_TYPE: // ECC alg + ret = ecdsa_param_fill(h_sess, &req, ecc_key, &setup, pdata); + if (ret) + goto src_release; + break; + case SM2_TYPE: // SM2 alg + ret = sm2_param_fill(h_sess, &req, &setup, pdata); + if (ret) + goto src_release; + break; + default: // ECDH, X25519, X448 alg + ret = ecc_param_fill(h_sess, &req, ecc_key, &setup, pdata); + if (ret) + goto src_release; + break; + } + + do { + ret = wd_do_ecc_sync(h_sess, &req); + if (ret || req.status) { + HPRE_TST_PRT("failed to do ecc task, status: %d\n", req.status); + goto src_release; + } + + count++; + if (get_run_state() == 0) + break; + } while(true); + +src_release: + if (req.src) + (void)wd_ecc_del_in(h_sess, req.src); + if (req.dst) + (void)wd_ecc_del_out(h_sess, req.dst); +sess_release: + wd_ecc_free_sess(h_sess); +msg_release: + if (subtype == SM2_TYPE) + free(setup.msg); + + add_recv_data(count, key_size); + + return NULL; +} + +static void ecc_async_cb(void *req_t) +{ + //struct wd_ecc_req *req = req_t; + //struct rsa_async_tag *tag = req->cb_param; + //enum wd_rsa_op_type op_type = req->op_type; + //handle_t h_sess = tag->sess; + + return; +} + +static void *ecc_uadk_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + u32 subtype = pdata->subtype; + struct wd_ecc_sess_setup sess_setup; + struct rsa_async_tag *tag; + struct hpre_ecc_setup setup; + struct wd_ecc_curve param; + struct wd_ecc_key *ecc_key; + struct wd_ecc_point pbk; + struct wd_ecc_req req; + struct wd_dtb prk; + u32 cid = ECC_CURVE_ID; + handle_t h_sess; + int try_cnt = 0; + u32 count = 0; + int i, ret; + + memset(&sess_setup, 0, sizeof(sess_setup)); + memset(¶m, 0, sizeof(param)); + memset(&req, 0, sizeof(req)); + + memset(&setup, 0, sizeof(setup)); + if (subtype != X448_TYPE || subtype != X25519_TYPE) { + ret = get_ecc_curve(&setup, cid); + if (ret) + return NULL; + } + + sess_setup.key_bits = pdata->keybits; + if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { + if (cid > ECC_CURVE_ID) { + sess_setup.cv.type = WD_CV_CFG_PARAM; + get_ecc_key_param(¶m, pdata->keybits); + sess_setup.cv.cfg.pparam = ¶m; + } else { + sess_setup.cv.type = WD_CV_CFG_ID; + sess_setup.cv.cfg.id = setup.curve_id; + } + } + + sess_setup.rand.cb = ecc_get_rand; + switch (subtype) { + case SM2_TYPE: + sess_setup.alg = "sm2"; + break; + case ECDH_TYPE: + sess_setup.alg = "ecdh"; + break; + case ECDSA_TYPE: + sess_setup.alg = "ecdsa"; + break; + } + + // set def setting; + sess_setup.hash.cb = hpre_compute_hash; + sess_setup.hash.type = WD_HASH_SHA256; + + ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); + if (ret) + return NULL; + + h_sess = wd_ecc_alloc_sess(&sess_setup); + if (!h_sess) + goto msg_release; + + prk.data = (void *)setup.priv_key; + prk.dsize = setup.priv_key_size; + prk.bsize = setup.priv_key_size; + pbk.x.data = (char *)setup.pub_key + 1; + pbk.x.dsize = key_size; + pbk.x.bsize = key_size; + pbk.y.data = pbk.x.data + key_size; + pbk.y.dsize = key_size; + pbk.y.bsize = key_size; + + ecc_key = wd_ecc_get_key(h_sess); + ret = wd_ecc_set_prikey(ecc_key, &prk); + if (ret) { + HPRE_TST_PRT("failed to pre set ecc prikey!\n"); + goto sess_release; + } + + ret = wd_ecc_set_pubkey(ecc_key, &pbk); + if (ret) { + HPRE_TST_PRT("failed to pre set ecc pubkey!\n"); + goto sess_release; + } + + req.op_type = pdata->optype; + switch (subtype) { + case ECDSA_TYPE: // ECC alg + ret = ecdsa_param_fill(h_sess, &req, ecc_key, &setup, pdata); + if (ret) + goto src_release; + break; + case SM2_TYPE: // SM2 alg + ret = sm2_param_fill(h_sess, &req, &setup, pdata); + if (ret) + goto src_release; + break; + default: // ECDH, X25519, X448 alg + ret = ecc_param_fill(h_sess, &req, ecc_key, &setup, pdata); + if (ret) + goto src_release; + break; + } + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + HPRE_TST_PRT("failed to malloc rsa tag!\n"); + goto src_release; + } + req.cb = ecc_async_cb; + + do { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + tag[i].sess = h_sess; + req.cb_param = &tag[i]; + + ret = wd_do_ecc_sync(h_sess, &req); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + HPRE_TST_PRT("Test ECC send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret) { + HPRE_TST_PRT("failed to do ECC async task!\n"); + goto tag_release; + } + count++; + } while(true); + +tag_release: + free(tag); +src_release: + if (req.src) + (void)wd_ecc_del_in(h_sess, req.src); + if (req.dst) + (void)wd_ecc_del_out(h_sess, req.dst); +sess_release: + wd_ecc_free_sess(h_sess); +msg_release: + if (subtype == SM2_TYPE) + free(setup.msg); + + add_send_complete(); + + return NULL; +} + +static int hpre_uadk_sync_threads(struct acc_option *options) +{ + typedef void *(*hpre_sync_run)(void *arg); + hpre_sync_run uadk_hpre_sync_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + threads_option.subtype = options->subtype; + threads_option.td_id = 0; + ret = hpre_uadk_param_parse(&threads_option, options); + if (ret) + return ret; + + switch (options->subtype) { + case RSA_TYPE: + uadk_hpre_sync_run = rsa_uadk_sync_run; + break; + case DH_TYPE: + uadk_hpre_sync_run = dh_uadk_sync_run; + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + uadk_hpre_sync_run = ecc_uadk_sync_run; + break; + default: + HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); + return -EINVAL; + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].kmode = threads_option.kmode; + threads_args[i].keybits = threads_option.keybits; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, uadk_hpre_sync_run, &threads_args[i]); + if (ret) { + HPRE_TST_PRT("Create sync thread fail!\n"); + goto sync_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + HPRE_TST_PRT("Join sync thread fail!\n"); + goto sync_error; + } + } + +sync_error: + return ret; +} + +static int hpre_uadk_async_threads(struct acc_option *options) +{ + typedef void *(*hpre_async_run)(void *arg); + hpre_async_run uadk_hpre_async_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + pthread_t pollid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + threads_option.subtype = options->subtype; + threads_option.td_id = 0; + ret = hpre_uadk_param_parse(&threads_option, options); + if (ret) + return ret; + + switch (options->subtype) { + case RSA_TYPE: + uadk_hpre_async_run = rsa_uadk_async_run; + break; + case DH_TYPE: + uadk_hpre_async_run = dh_uadk_async_run; + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + uadk_hpre_async_run = ecc_uadk_async_run; + break; + default: + HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); + return -EINVAL; + } + + for (i = 0; i < g_ctxnum; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].td_id = i; + /* poll thread */ + ret = pthread_create(&pollid[i], NULL, hpre_uadk_poll, &threads_args[i]); + if (ret) { + HPRE_TST_PRT("Create poll thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].kmode = threads_option.kmode; + threads_args[i].keybits = threads_option.keybits; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, uadk_hpre_async_run, &threads_args[i]); + if (ret) { + HPRE_TST_PRT("Create async thread fail!\n"); + goto async_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + HPRE_TST_PRT("Join async thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_ctxnum; i++) { + ret = pthread_join(pollid[i], NULL); + if (ret) { + HPRE_TST_PRT("Join poll thread fail!\n"); + goto async_error; + } + } + +async_error: + return ret; +} + +int hpre_uadk_benchmark(struct acc_option *options) +{ + u32 ptime; + int ret; + + g_thread_num = options->threads; + g_ctxnum = options->ctxnums; + + if (options->optype >= (WD_EC_OP_MAX - WD_ECDSA_VERIFY)) { + HPRE_TST_PRT("HPRE optype error: %u\n", options->optype); + return -EINVAL; + } + + ret = init_hpre_ctx_config(options->algclass, options->subtype, + options->syncmode); + if (ret) + return ret; + + get_pid_cpu_time(&ptime); + time_start(options->times); + if (options->syncmode) + ret = hpre_uadk_async_threads(options); + else + ret = hpre_uadk_sync_threads(options); + cal_perfermance_data(options, ptime); + if (ret) + return ret; + + uninit_hpre_ctx_config(options->subtype); + + return 0; +} diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.h b/uadk_tool/benchmark/hpre_uadk_benchmark.h new file mode 100644 index 0000000..7e3966d --- /dev/null +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#ifndef HPRE_UADK_BENCHMARK_H +#define HPRE_UADK_BENCHMARK_H + +extern int hpre_uadk_benchmark(struct acc_option *options); +#endif /* HPRE_UADK_BENCHMARK_H */
Added No-SVA mode performance test function for HPRE's RSA, DH, ECC algorithms.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/benchmark/hpre_wd_benchmark.c | 2553 +++++++++++++++++++++++ uadk_tool/benchmark/hpre_wd_benchmark.h | 6 + 2 files changed, 2559 insertions(+) create mode 100644 uadk_tool/benchmark/hpre_wd_benchmark.c create mode 100644 uadk_tool/benchmark/hpre_wd_benchmark.h
diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c new file mode 100644 index 0000000..c9b0c18 --- /dev/null +++ b/uadk_tool/benchmark/hpre_wd_benchmark.c @@ -0,0 +1,2553 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include <numa.h> +#include "uadk_benchmark.h" + +#include "hpre_wd_benchmark.h" +#include "hpre_protocol_data.h" +#include "v1/wd.h" +#include "v1/wd_ecc.h" +#include "v1/wd_rsa.h" +#include "v1/wd_dh.h" +#include "v1/wd_bmm.h" +#include "v1/wd_util.h" + +#define ECC_CURVE_ID 0x3 /* def set secp256k1 */ +#define HPRE_TST_PRT printf +#define ERR_OPTYPE 0xFF +#define SM2_DG_SZ 1024 +#define SEND_USLEEP 100 +#define ALIGN_SIZE 128 + +static char rsa_m[8] = {0x54, 0x85, 0x9b, 0x34, 0x2c, 0x49, 0xea, 0x2a}; + +struct hpre_rsa_key_in { + void *e; + void *p; + void *q; + u32 e_size; + u32 p_size; + u32 q_size; + void *data[]; +}; +static __thread struct hpre_rsa_key_in *rsa_key_in = NULL; + +struct rsa_async_tag { + void *ctx; + int cnt; + int optype; +}; + +//----------------------------------RSA param--------------------------------------// +struct hpre_dh_param { + const void *x; + const void *p; + const void *g; + const void *except_pub_key; + const void *pub_key; + const void *share_key; + void *pool; + u32 x_size; + u32 p_size; + u32 g_size; + u32 pub_key_size; + u32 share_key_size; + u32 except_pub_key_size; + u32 key_bits; + u32 optype; +}; + +//----------------------------------DH param-------------------------------------// +struct hpre_ecc_setup { + void *except_pub_key; // use in ecdh phase 2 + const void *pub_key; // use in ecdh phase 1 + const void *share_key; // use in ecdh phase 2 + const void *degist; //ecdsa sign in + const void *k; //ecdsa sign in + const void *rp; //ecdsa sign in + const void *sign; // ecdsa sign out or verf in + const void *priv_key; // use in ecdsa sign + void *msg; // sm2 plaintext,ciphertext or digest input + const void *userid; // sm2 user id + const void *ciphertext; // sm2 ciphertext + const void *plaintext; // sm2 plaintext + u32 key_size; + u32 share_key_size; + u32 except_pub_key_size; + u32 degist_size; + u32 k_size; + u32 rp_size; + u32 sign_size; + u32 priv_key_size; + u32 pub_key_size; + u32 msg_size; + u32 userid_size; + u32 ciphertext_size; + u32 plaintext_size; + u32 op_type; + u32 key_bits; + u32 nid; + u32 curve_id; // WD ecc curve_id +}; + +//----------------------------------ECC param-------------------------------------// +struct thread_bd_res { + struct wd_queue *queue; + void *pool; +}; + +struct thread_queue_res { + struct thread_bd_res *bd_res; +}; + +typedef struct uadk_thread_res { + u32 subtype; + u32 keybits; + u32 kmode; + u32 optype; + u32 td_id; +} thread_data; + +static unsigned int g_thread_num; +static struct thread_queue_res g_thread_queue; + +static const char* const alg_operations[] = { + "GenKey", "ShareKey", "Encrypt", "Decrypt", "Sign", "Verify", +}; + +static void get_rsa_param(u32 algtype, u32 *keysize, u32 *mode) +{ + switch(algtype) { + case RSA_1024: + *keysize = 1024; + *mode = 0; + break; + case RSA_2048: + *keysize = 2048; + *mode = 0; + break; + case RSA_3072: + *keysize = 3072; + *mode = 0; + break; + case RSA_4096: + *keysize = 4096; + *mode = 0; + break; + case RSA_1024_CRT: + *keysize = 1024; + *mode = 1; + break; + case RSA_2048_CRT: + *keysize = 2048; + *mode = 1; + break; + case RSA_3072_CRT: + *keysize = 3072; + *mode = 1; + break; + case RSA_4096_CRT: + *keysize = 4096; + *mode = 1; + break; + } +} + +static u32 get_rsa_optype(u32 optype) +{ + u32 op_type = 0; + + switch(optype) { + case 0: //GENKEY1 + op_type = WCRYPTO_RSA_GENKEY; + break; + case 4: //Sign + op_type = WCRYPTO_RSA_SIGN; + break; + case 5: //Verf + op_type = WCRYPTO_RSA_VERIFY; + break; + default: + HPRE_TST_PRT("failed to set rsa op_type\n"); + HPRE_TST_PRT("RSA Gen: 0\n"); + HPRE_TST_PRT("RSA Sign: 4\n"); + HPRE_TST_PRT("RSA Verf: 5\n"); + return ERR_OPTYPE; + } + + return op_type; +} + +static void get_dh_param(u32 algtype, u32 *keysize) +{ + switch(algtype) { + case DH_768: + *keysize = 768; + break; + case DH_1024: + *keysize = 1024; + break; + case DH_1536: + *keysize = 1536; + break; + case DH_2048: + *keysize = 2048; + break; + case DH_3072: + *keysize = 3072; + break; + case DH_4096: + *keysize = 4096; + break; + } +} + +static u32 get_dh_optype(u32 optype) +{ + u32 op_type = 0; + + switch(optype) { + case 0: //GENKEY1 + op_type = WCRYPTO_DH_PHASE1; + break; + case 1: //GENKEY12 + op_type = WCRYPTO_DH_PHASE2; + break; + default: + HPRE_TST_PRT("failed to set dh op_type\n"); + HPRE_TST_PRT("DH Gen1: 0\n"); + HPRE_TST_PRT("DH Gen2: 1\n"); + return ERR_OPTYPE; + } + + return op_type; +} + +static void get_ecc_param(u32 algtype, u32 *keysize) +{ + switch(algtype) { + case ECDH_256: + *keysize = 256; + break; + case ECDH_384: + *keysize = 384; + break; + case ECDH_521: + *keysize = 521; + break; + case ECDSA_256: + *keysize = 256; + break; + case ECDSA_384: + *keysize = 384; + break; + case ECDSA_521: + *keysize = 521; + break; + case SM2_ALG: + *keysize = 256; + break; + case X25519_ALG: + *keysize = 256; + break; + case X448_ALG: + *keysize = 448; + break; + } +} + +static u32 get_ecc_optype(u32 subtype, u32 optype) +{ + u32 op_type = 0; + + if (subtype == SM2_TYPE) { + switch (optype) { + case 0: + op_type = WCRYPTO_SM2_KG; + break; + case 2: + op_type = WCRYPTO_SM2_ENCRYPT; + break; + case 3: + op_type = WCRYPTO_SM2_DECRYPT; + break; + case 4: + op_type = WCRYPTO_SM2_SIGN; + break; + case 5: + op_type = WCRYPTO_SM2_VERIFY; + break; + default: + HPRE_TST_PRT("failed to set SM2 op_type\n"); + HPRE_TST_PRT("SM2 KeyGen: 0\n"); + HPRE_TST_PRT("SM2 Encrypt: 2\n"); + HPRE_TST_PRT("SM2 Decrypt: 3\n"); + HPRE_TST_PRT("SM2 Sign: 4\n"); + HPRE_TST_PRT("SM2 Verify: 5\n"); + return ERR_OPTYPE; + } + } else if (subtype == ECDH_TYPE || + subtype == X25519_TYPE || subtype == X448_TYPE) { + switch(optype) { + case 0: //GENKEY + op_type = WCRYPTO_ECXDH_GEN_KEY; + break; + case 1: //COMPUTEKEY + op_type = WCRYPTO_ECXDH_COMPUTE_KEY; + break; + default: + HPRE_TST_PRT("failed to set ECDH op_type\n"); + HPRE_TST_PRT("ECDH GenKey: 0\n"); + HPRE_TST_PRT("ECDH ShareKey: 1\n"); + return ERR_OPTYPE; + } + } else if (subtype == ECDSA_TYPE) { + switch(optype) { + case 4: //Sign + op_type = WCRYPTO_ECDSA_SIGN; + break; + case 5: //Verf + op_type = WCRYPTO_ECDSA_VERIFY; + break; + default: + HPRE_TST_PRT("failed to set ECDSA op_type\n"); + HPRE_TST_PRT("ECDSA Sign: 4\n"); + HPRE_TST_PRT("ECDSA Verf: 5\n"); + return ERR_OPTYPE; + } + } + + return op_type; +} + +static int hpre_wd_param_parse(thread_data *tddata, struct acc_option *options) +{ + u32 algtype = options->algtype; + u32 optype = 0; + u32 keysize = 0; + u32 mode = 0; + + if (algtype >= RSA_1024 && algtype <= RSA_4096_CRT) { + get_rsa_param(algtype, &keysize, &mode); + optype = get_rsa_optype(options->optype); + } else if (algtype <= DH_4096) { + get_dh_param(algtype, &keysize); + optype = get_dh_optype(options->optype); + } else if (algtype <= X448_ALG) { + get_ecc_param(algtype, &keysize); + optype = get_ecc_optype(options->subtype, options->optype); + } else { + HPRE_TST_PRT("failed to set hpre alg!\n"); + return -EINVAL; + } + + if (optype == ERR_OPTYPE) + return -EINVAL; + + /* HPRE package length is keybits */ + options->pktlen = keysize >> 3; + tddata->keybits = keysize; + tddata->kmode = mode; + tddata->optype = optype; + + HPRE_TST_PRT("%s to run %s task!\n", options->algclass, + alg_operations[options->optype]); + + return 0; +} + +static int hpre_wd_get_block(u32 algtype) +{ + int block_size = 512; + + switch(algtype) { + case RSA_1024: + block_size = 1280; + break; + case RSA_2048: + block_size = 2560; + break; + case RSA_3072: + block_size = 3840; + break; + case RSA_4096: + block_size = 5120; + break; + case RSA_1024_CRT: + block_size = 1280; + break; + case RSA_2048_CRT: + block_size = 2560; + break; + case RSA_3072_CRT: + block_size = 3840; + break; + case RSA_4096_CRT: + block_size = 5120; + break; + case DH_768: + block_size = 1536; + break; + case DH_1024: + block_size = 2048; + break; + case DH_1536: + block_size = 3072; + break; + case DH_2048: + block_size = 4096; + break; + case DH_3072: + block_size = 6144; + break; + 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: + 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; +} + +static int init_hpre_wd_queue(struct acc_option *options) +{ + u32 blocksize = hpre_wd_get_block(options->algtype); + struct wd_blkpool_setup blksetup; + int i, j, ret; + + g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res)); + if (!g_thread_queue.bd_res) { + HPRE_TST_PRT("malloc thread res memory fail!\n"); + return -ENOMEM; + } + + for (i = 0; i < g_thread_num; i++) { + g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue)); + g_thread_queue.bd_res[i].queue->capa.alg = options->algclass; + // 0 is ENC, 1 is DEC + g_thread_queue.bd_res[i].queue->capa.priv.direction = options->optype; + /* nodemask need to be clean */ + g_thread_queue.bd_res[i].queue->node_mask = 0x0; + memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); + + ret = wd_request_queue(g_thread_queue.bd_res[i].queue); + if (ret) { + HPRE_TST_PRT("request queue %d fail!\n", i); + goto queue_out; + } + } + + // use no-sva pbuffer, MAX_BLOCK_NM at least 4 times of thread inside alloc + memset(&blksetup, 0, sizeof(blksetup)); + blksetup.block_size = blocksize; + blksetup.block_num = MAX_BLOCK_NM; + blksetup.align_size = ALIGN_SIZE; + // HPRE_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); + + for (j = 0; j < g_thread_num; j++) { + g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup); + if (!g_thread_queue.bd_res[j].pool) { + HPRE_TST_PRT("create %dth pool fail!\n", j); + ret = -ENOMEM; + goto pool_err; + } + } + + return 0; + +pool_err: + for (j--; j >= 0; j--) + wd_blkpool_destroy(g_thread_queue.bd_res[j].pool); +queue_out: + for (i--; i >= 0; i--) { + wd_release_queue(g_thread_queue.bd_res[i].queue); + free(g_thread_queue.bd_res[i].queue); + } + free(g_thread_queue.bd_res); + return ret; +} + +static void uninit_hpre_wd_queue(void) +{ + int j; + + for (j = 0; j < g_thread_num; j++) { + wd_blkpool_destroy(g_thread_queue.bd_res[j].pool); + wd_release_queue(g_thread_queue.bd_res[j].queue); + } + + free(g_thread_queue.bd_res); +} + +/*-------------------------------uadk benchmark main code-------------------------------------*/ + +void *hpre_wd_poll(void *data) +{ + typedef int (*poll_ctx)(struct wd_queue *q, unsigned int num); + thread_data *pdata = (thread_data *)data; + u32 expt = ACC_QUEUE_SIZE * g_thread_num; + poll_ctx wd_poll_ctx = NULL; + struct wd_queue *queue; + u32 id = pdata->td_id; + u32 last_time = 2; // poll need one more recv time + u32 count = 0; + int recv = 0; + + if (id > g_thread_num) + return NULL; + + queue = g_thread_queue.bd_res[id].queue; + switch(pdata->subtype) { + case RSA_TYPE: + wd_poll_ctx = wcrypto_rsa_poll; + break; + case DH_TYPE: + wd_poll_ctx = wcrypto_dh_poll; + break; + case ECDH_TYPE: + case X25519_TYPE: + case X448_TYPE: + wd_poll_ctx = wcrypto_ecxdh_poll; + break; + case ECDSA_TYPE: + wd_poll_ctx = wcrypto_ecdsa_poll; + break; + case SM2_TYPE: + wd_poll_ctx = wcrypto_sm2_poll; + break; + default: + HPRE_TST_PRT("wd async poll interface is NULL!\n"); + return NULL; + } + + while (last_time) { + recv = wd_poll_ctx(queue, expt); + /* + * warpdrive async mode poll easy to 100% with small package. + * SEC_TST_PRT("warpdrive poll %d recv: %u!\n", i, recv); + */ + + if (unlikely(recv < 0)) { + HPRE_TST_PRT("poll ret: %u!\n", recv); + goto recv_error; + } + count += recv; + recv = 0; + + if (get_run_state() == 0) + last_time--; + } + +recv_error: + add_recv_data(count, pdata->keybits >> 3); + + return NULL; +} + +static int get_rsa_key_from_sample(void *ctx, char *privkey_file, + char *crt_privkey_file, u32 key_bits, u32 is_crt) +{ + struct wd_dtb wd_e, wd_d, wd_n, wd_dq, wd_dp, wd_qinv, wd_q, wd_p; + int e_bytes, d_bytes, n_bytes, q_bytes, p_bytes, qinv_bytes; + u8 *p, *q, *n, *e, *d, *dmp1, *dmq1, *iqmp; + int dq_bytes, dp_bytes, bits, wd_lenth; + u32 key_size = key_bits >> 3; + char *wd_mem; + int ret = 0; + + memset(&wd_e, 0, sizeof(wd_e)); + memset(&wd_d, 0, sizeof(wd_d)); + memset(&wd_n, 0, sizeof(wd_n)); + memset(&wd_dq, 0, sizeof(wd_dq)); + memset(&wd_dp, 0, sizeof(wd_dp)); + memset(&wd_qinv, 0, sizeof(wd_qinv)); + memset(&wd_q, 0, sizeof(wd_q)); + memset(&wd_p, 0, sizeof(wd_p)); + + bits = wcrypto_rsa_key_bits(ctx); + switch (bits) { + case 1024: + e = rsa_e_1024; + n = rsa_n_1024; + p = rsa_p_1024; + q = rsa_q_1024; + dmp1 = rsa_dp_1024; + dmq1 = rsa_dq_1024; + iqmp = rsa_qinv_1024; + d = rsa_d_1024; + e_bytes = ARRAY_SIZE(rsa_e_1024); + n_bytes = ARRAY_SIZE(rsa_n_1024); + q_bytes = ARRAY_SIZE(rsa_q_1024); + p_bytes = ARRAY_SIZE(rsa_p_1024); + dq_bytes = ARRAY_SIZE(rsa_dq_1024); + dp_bytes = ARRAY_SIZE(rsa_dp_1024); + qinv_bytes = ARRAY_SIZE(rsa_qinv_1024); + d_bytes = ARRAY_SIZE(rsa_d_1024); + break; + case 2048: + e = rsa_e_2048; + n = rsa_n_2048; + p = rsa_p_2048; + q = rsa_q_2048; + dmp1 = rsa_dp_2048; + dmq1 = rsa_dq_2048; + iqmp = rsa_qinv_2048; + d = rsa_d_2048; + e_bytes = ARRAY_SIZE(rsa_e_2048); + n_bytes = ARRAY_SIZE(rsa_n_2048); + q_bytes = ARRAY_SIZE(rsa_q_2048); + p_bytes = ARRAY_SIZE(rsa_p_2048); + dq_bytes = ARRAY_SIZE(rsa_dq_2048); + dp_bytes = ARRAY_SIZE(rsa_dp_2048); + qinv_bytes = ARRAY_SIZE(rsa_qinv_2048); + d_bytes = ARRAY_SIZE(rsa_d_2048); + break; + case 3072: + e = rsa_e_3072; + n = rsa_n_3072; + p = rsa_p_3072; + q = rsa_q_3072; + dmp1 = rsa_dp_3072; + dmq1 = rsa_dq_3072; + iqmp = rsa_qinv_3072; + d = rsa_d_3072; + e_bytes = ARRAY_SIZE(rsa_e_3072); + n_bytes = ARRAY_SIZE(rsa_n_3072); + q_bytes = ARRAY_SIZE(rsa_q_3072); + p_bytes = ARRAY_SIZE(rsa_p_3072); + dq_bytes = ARRAY_SIZE(rsa_dq_3072); + dp_bytes = ARRAY_SIZE(rsa_dp_3072); + qinv_bytes = ARRAY_SIZE(rsa_qinv_3072); + d_bytes = ARRAY_SIZE(rsa_d_3072); + break; + case 4096: + e = rsa_e_4096; + n = rsa_n_4096; + p = rsa_p_4096; + q = rsa_q_4096; + dmp1 = rsa_dp_4096; + dmq1 = rsa_dq_4096; + iqmp = rsa_qinv_4096; + d = rsa_d_4096; + e_bytes = ARRAY_SIZE(rsa_e_4096); + n_bytes = ARRAY_SIZE(rsa_n_4096); + q_bytes = ARRAY_SIZE(rsa_q_4096); + p_bytes = ARRAY_SIZE(rsa_p_4096); + dq_bytes = ARRAY_SIZE(rsa_dq_4096); + dp_bytes = ARRAY_SIZE(rsa_dp_4096); + qinv_bytes = ARRAY_SIZE(rsa_qinv_4096); + d_bytes = ARRAY_SIZE(rsa_d_4096); + break; + default: + HPRE_TST_PRT("invalid key bits = %d!\n", bits); + return -EINVAL; + } + + wd_lenth = e_bytes + n_bytes + q_bytes + p_bytes + dq_bytes + + dp_bytes + qinv_bytes + d_bytes; + wd_mem = malloc(wd_lenth); + if (!wd_mem) { + HPRE_TST_PRT("failed to alloc rsa key memory!\n"); + return -EINVAL; + } + + wd_e.data = wd_mem; + wd_n.data = wd_e.data + e_bytes; + + memcpy(wd_e.data, e, e_bytes); + wd_e.dsize = e_bytes; + memcpy(wd_n.data, n, n_bytes); + wd_n.dsize = n_bytes; + if (wcrypto_set_rsa_pubkey_params(ctx, &wd_e, &wd_n)) { + HPRE_TST_PRT("failed to set rsa pubkey!\n"); + ret = -EINVAL; + goto gen_fail; + } + + if (rsa_key_in) { + memcpy(rsa_key_in->e, e, e_bytes); + memcpy(rsa_key_in->p, p, p_bytes); + memcpy(rsa_key_in->q, q, q_bytes); + rsa_key_in->e_size = e_bytes; + rsa_key_in->p_size = p_bytes; + rsa_key_in->q_size = q_bytes; + } + + if (is_crt) { + wd_q.data = wd_n.data + n_bytes; + wd_p.data = wd_q.data + q_bytes; + wd_dq.data = wd_p.data + p_bytes; + wd_dp.data = wd_dq.data + dq_bytes; + wd_qinv.data = wd_dp.data + dp_bytes; + + /* CRT mode private key */ + wd_dq.dsize = dq_bytes; + memcpy(wd_dq.data, dmq1, dq_bytes); + + wd_dp.dsize = dp_bytes; + memcpy(wd_dp.data, dmp1, dp_bytes); + + wd_q.dsize = q_bytes; + memcpy(wd_q.data, q, q_bytes); + + wd_p.dsize = p_bytes; + memcpy(wd_p.data, p, p_bytes); + + wd_qinv.dsize = qinv_bytes; + memcpy(wd_qinv.data, iqmp, qinv_bytes); + + if (wcrypto_set_rsa_crt_prikey_params(ctx, &wd_dq, + &wd_dp, &wd_qinv, + &wd_q, &wd_p)) { + HPRE_TST_PRT("failed to set rsa crt prikey!\n"); + ret = -EINVAL; + goto gen_fail; + } + + + if (crt_privkey_file) { + memcpy(crt_privkey_file, wd_dq.data, (key_bits >> 4) * 5); + memcpy(crt_privkey_file + (key_bits >> 4) * 5, + wd_e.data, (key_bits >> 2)); + } + + } else { + //wd_rsa_get_prikey_params(prikey, &wd_d, &wd_n); + wd_d.data = wd_mem + (wd_lenth - d_bytes); + + /* common mode private key */ + wd_d.dsize = d_bytes; + memcpy(wd_d.data, d, d_bytes); + + if (wcrypto_set_rsa_prikey_params(ctx, &wd_d, &wd_n)) { + HPRE_TST_PRT("failed to set rsa prikey!\n"); + ret = -EINVAL; + goto gen_fail; + } + + if (privkey_file) { + memcpy(privkey_file, wd_d.data, key_size); + memcpy(privkey_file + key_size, wd_n.data, key_size); + memcpy(privkey_file + 2 * key_size, wd_e.data, key_size); + memcpy(privkey_file + 3 * key_size, wd_n.data, key_size); + } + } + +gen_fail: + free(wd_mem); + + return ret; +} + +static int get_hpre_keygen_opdata(void *ctx, + struct wcrypto_rsa_op_data *opdata) +{ + struct wcrypto_rsa_pubkey *pubkey; + struct wcrypto_rsa_prikey *prikey; + struct wd_dtb t_e, t_p, t_q; + struct wd_dtb *e, *p, *q; + + wcrypto_get_rsa_pubkey(ctx, &pubkey); + wcrypto_get_rsa_pubkey_params(pubkey, &e, NULL); + wcrypto_get_rsa_prikey(ctx, &prikey); + + if (wcrypto_rsa_is_crt(ctx)) { + wcrypto_get_rsa_crt_prikey_params(prikey, NULL , NULL, NULL, &q, &p); + } else { + e = &t_e; + p = &t_p; + q = &t_q; + e->data = rsa_key_in->e; + e->dsize = rsa_key_in->e_size; + p->data = rsa_key_in->p; + p->dsize = rsa_key_in->p_size; + q->data = rsa_key_in->q; + q->dsize = rsa_key_in->q_size; + } + + opdata->in = wcrypto_new_kg_in(ctx, e, p, q); + if (!opdata->in) { + HPRE_TST_PRT("failed to create rsa kgen in!\n"); + return -ENOMEM; + } + opdata->out = wcrypto_new_kg_out(ctx); + if (!opdata->out) { + HPRE_TST_PRT("failed to create rsa kgen out!\n"); + wcrypto_del_kg_in(ctx, opdata->in); + return -ENOMEM; + } + + return 0; +} + +static void *rsa_wd_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wcrypto_rsa_ctx_setup setup; + struct wcrypto_rsa_op_data opdata; + struct wd_queue *queue; + void *key_info = NULL; + void *ctx = NULL; + void *tag = NULL; + void *pool; + u32 count = 0; + int ret; + + memset(&setup, 0, sizeof(setup)); + memset(&opdata, 0, sizeof(opdata)); + pool = g_thread_queue.bd_res[pdata->td_id].pool; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + + setup.br.alloc = (void *)wd_alloc_blk; + setup.br.free = (void *)wd_free_blk; + setup.br.iova_map = (void *)wd_blk_iova_map; + setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + setup.br.get_bufsize = (void *)wd_blksize; + setup.br.usr = pool; + setup.key_bits = pdata->keybits; + setup.is_crt = pdata->kmode; + + ctx = wcrypto_create_rsa_ctx(queue, &setup); + if (!ctx) + return NULL; + + key_info = malloc(key_size * 16); + if (!key_info) { + HPRE_TST_PRT("failed to alloc RSA key info!\n"); + return NULL; + } + memset(key_info, 0, key_size * 16); + + rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); + if (!rsa_key_in) { + HPRE_TST_PRT("failed to alloc RSA key input param!\n"); + goto key_release; + } + rsa_key_in->e = rsa_key_in + 1; + rsa_key_in->p = rsa_key_in->e + key_size; + rsa_key_in->q = rsa_key_in->p + (key_size >> 1); + + ret = get_rsa_key_from_sample(ctx, key_info, key_info, + pdata->keybits, pdata->kmode); + if (ret) { + HPRE_TST_PRT("failed to get sample key data!\n"); + goto sample_release; + } + + opdata.in_bytes = key_size; + opdata.out_bytes = key_size; + opdata.op_type = pdata->optype; + if (opdata.op_type == WCRYPTO_RSA_GENKEY) { + ret = get_hpre_keygen_opdata(ctx, &opdata); + if (ret){ + HPRE_TST_PRT("failed to fill rsa key gen req!\n"); + goto sample_release; + } + } else { + opdata.in = wd_alloc_blk(pool); + if (!opdata.in) { + HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); + goto sample_release; + } + memset(opdata.in, 0, opdata.in_bytes); + memcpy(opdata.in + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); + + opdata.out = wd_alloc_blk(pool); + if (!opdata.out) { + HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); + goto in_release; + } + } + + do { + ret = wcrypto_do_rsa(ctx, &opdata, tag); + if (ret || opdata.status) { + HPRE_TST_PRT("failed to do rsa task, status: %d\n", opdata.status); + goto out_release; + } + + count++; + if (get_run_state() == 0) + break; + } while(true); + + /* clean output buffer remainings in the last time operation */ + if (opdata.op_type == WCRYPTO_RSA_GENKEY) { + char *data; + int len; + + len = wcrypto_rsa_kg_out_data((void *)opdata.out, &data); + if (len < 0) { + HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); + goto out_release; + } + memset(data, 0, len); + + wcrypto_del_kg_in(ctx, opdata.in); + opdata.in = NULL; + wcrypto_del_kg_out(ctx, opdata.out); + opdata.out = NULL; + } + +out_release: + if (opdata.out) + wd_free_blk(pool, opdata.out); +in_release: + if (opdata.in) + wd_free_blk(pool, opdata.in); +sample_release: + free(rsa_key_in); +key_release: + free(key_info); + + wcrypto_del_rsa_ctx(ctx); + add_recv_data(count, key_size); + + return NULL; +} + +static void rsa_async_cb(const void *msg, void *tag) +{ + //struct wcrypto_rsa_msg *massage = msg; + //struct rsa_async_tag *ptag = tag; + //u32 op_type = tag->op_type; + //void *ctx = tag->ctx; + + return; +} + +static void *rsa_wd_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wcrypto_rsa_ctx_setup setup; + struct wcrypto_rsa_op_data opdata; + struct rsa_async_tag *tag = NULL; + struct wd_queue *queue; + void *key_info = NULL; + void *ctx = NULL; + int try_cnt = 0; + void *pool; + u32 count = 0; + int i, ret; + + memset(&setup, 0, sizeof(setup)); + memset(&opdata, 0, sizeof(opdata)); + pool = g_thread_queue.bd_res[pdata->td_id].pool; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + + setup.cb = (void *)rsa_async_cb; + setup.br.alloc = (void *)wd_alloc_blk; + setup.br.free = (void *)wd_free_blk; + setup.br.iova_map = (void *)wd_blk_iova_map; + setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + setup.br.get_bufsize = (void *)wd_blksize; + setup.br.usr = pool; + setup.key_bits = pdata->keybits; + setup.is_crt = pdata->kmode; + + ctx = wcrypto_create_rsa_ctx(queue, &setup); + if (!ctx) + return NULL; + + key_info = malloc(key_size * 16); + if (!key_info) { + HPRE_TST_PRT("failed to alloc RSA key info!\n"); + return NULL; + } + memset(key_info, 0, key_size * 16); + + rsa_key_in = malloc(2 * key_size + sizeof(struct hpre_rsa_key_in)); + if (!rsa_key_in) { + HPRE_TST_PRT("failed to alloc RSA key input param!\n"); + goto key_release; + } + rsa_key_in->e = rsa_key_in + 1; + rsa_key_in->p = rsa_key_in->e + key_size; + rsa_key_in->q = rsa_key_in->p + (key_size >> 1); + + ret = get_rsa_key_from_sample(ctx, key_info, key_info, + pdata->keybits, pdata->kmode); + if (ret) { + HPRE_TST_PRT("failed to get sample key data!\n"); + goto sample_release; + } + + opdata.in_bytes = key_size; + opdata.out_bytes = key_size; + opdata.op_type = pdata->optype; + if (opdata.op_type == WCRYPTO_RSA_GENKEY) { + ret = get_hpre_keygen_opdata(ctx, &opdata); + if (ret){ + HPRE_TST_PRT("failed to fill rsa key gen req!\n"); + goto sample_release; + } + } else { + opdata.in = wd_alloc_blk(pool); + if (!opdata.in) { + HPRE_TST_PRT("failed to alloc rsa in buffer!\n"); + goto sample_release; + } + memset(opdata.in, 0, opdata.in_bytes); + memcpy(opdata.in + key_size - sizeof(rsa_m), rsa_m, sizeof(rsa_m)); + + opdata.out = wd_alloc_blk(pool); + if (!opdata.out) { + HPRE_TST_PRT("failed to alloc rsa out buffer!\n"); + goto in_release; + } + } + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + HPRE_TST_PRT("failed to malloc rsa tag!\n"); + goto out_release; + } + + do { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + tag[i].ctx = ctx; + tag[i].cnt = i; + tag[i].optype = opdata.op_type; + + ret = wcrypto_do_rsa(ctx, &opdata, &tag[i]); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + HPRE_TST_PRT("Test RSA send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret) { + HPRE_TST_PRT("failed to do rsa async task!\n"); + goto tag_release; + } + count++; + } while(true); + + /* clean output buffer remainings in the last time operation */ + if (opdata.op_type == WCRYPTO_RSA_GENKEY) { + char *data; + int len; + + len = wcrypto_rsa_kg_out_data((void *)opdata.out, &data); + if (len < 0) { + HPRE_TST_PRT("failed to wd rsa get key gen out data!\n"); + goto out_release; + } + memset(data, 0, len); + + wcrypto_del_kg_in(ctx, opdata.in); + opdata.in = NULL; + wcrypto_del_kg_out(ctx, opdata.out); + opdata.out = NULL; + } + +tag_release: + free(tag); +out_release: + if (opdata.out) + wd_free_blk(pool, opdata.out); +in_release: + if (opdata.in) + wd_free_blk(pool, opdata.in); +sample_release: + free(rsa_key_in); +key_release: + free(key_info); + + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + wcrypto_del_rsa_ctx(ctx); + + add_send_complete(); + + return NULL; +} + +static int get_dh_param_from_sample(struct hpre_dh_param *setup, + u32 key_bits, u8 is_g2) +{ + setup->key_bits = key_bits; + + switch (key_bits) { + case 768: + setup->x = dh_xa_768; + setup->p = dh_p_768; + setup->except_pub_key = dh_except_b_pubkey_768; + setup->pub_key = dh_except_a_pubkey_768; + setup->share_key = dh_share_key_768; + setup->x_size = sizeof(dh_xa_768); + setup->p_size = sizeof(dh_p_768); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_768); + setup->pub_key_size = sizeof(dh_except_a_pubkey_768); + setup->share_key_size = sizeof(dh_share_key_768); + break; + case 1024: + setup->x = dh_xa_1024; + setup->p = dh_p_1024; + setup->except_pub_key = dh_except_b_pubkey_1024; + setup->pub_key = dh_except_a_pubkey_1024; + setup->share_key = dh_share_key_1024; + setup->x_size = sizeof(dh_xa_1024); + setup->p_size = sizeof(dh_p_1024); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1024); + setup->pub_key_size = sizeof(dh_except_a_pubkey_1024); + setup->share_key_size = sizeof(dh_share_key_1024); + break; + case 1536: + setup->x = dh_xa_1536; + setup->p = dh_p_1536; + setup->except_pub_key = dh_except_b_pubkey_1536; + setup->pub_key = dh_except_a_pubkey_1536; + setup->share_key = dh_share_key_1536; + setup->x_size = sizeof(dh_xa_1536); + setup->p_size = sizeof(dh_p_1536); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_1536); + setup->pub_key_size = sizeof(dh_except_a_pubkey_1536); + setup->share_key_size = sizeof(dh_share_key_1536); + break; + case 2048: + setup->x = dh_xa_2048; + setup->p = dh_p_2048; + setup->except_pub_key = dh_except_b_pubkey_2048; + setup->pub_key = dh_except_a_pubkey_2048; + setup->share_key = dh_share_key_2048; + setup->x_size = sizeof(dh_xa_2048); + setup->p_size = sizeof(dh_p_2048); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_2048); + setup->pub_key_size = sizeof(dh_except_a_pubkey_2048); + setup->share_key_size = sizeof(dh_share_key_2048); + break; + case 3072: + setup->x = dh_xa_3072; + setup->p = dh_p_3072; + setup->except_pub_key = dh_except_b_pubkey_3072; + setup->pub_key = dh_except_a_pubkey_3072; + setup->share_key = dh_share_key_3072; + setup->x_size = sizeof(dh_xa_3072); + setup->p_size = sizeof(dh_p_3072); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_3072); + setup->pub_key_size = sizeof(dh_except_a_pubkey_3072); + setup->share_key_size = sizeof(dh_share_key_3072); + break; + case 4096: + setup->x = dh_xa_4096; + setup->p = dh_p_4096; + setup->except_pub_key = dh_except_b_pubkey_4096; + setup->pub_key = dh_except_a_pubkey_4096; + setup->share_key = dh_share_key_4096; + setup->x_size = sizeof(dh_xa_4096); + setup->p_size = sizeof(dh_p_4096); + setup->except_pub_key_size = sizeof(dh_except_b_pubkey_4096); + setup->pub_key_size = sizeof(dh_except_a_pubkey_4096); + setup->share_key_size = sizeof(dh_share_key_4096); + break; + default: + HPRE_TST_PRT("failed to find dh keybits %u\n", key_bits); + return -EINVAL; + } + + if (is_g2) { + setup->g = dh_g_2; + } else { + setup->g = dh_g_5; + } + setup->g_size = 1; + + return 0; +} + +static int get_dh_opdata_param(void *ctx, struct wcrypto_dh_op_data *opdata, + struct hpre_dh_param *setup, int key_size) +{ + unsigned char *ag_bin = NULL; + void *pool = setup->pool; + struct wd_dtb ctx_g; + int ret; + + ag_bin = wd_alloc_blk(pool); + if (!ag_bin) + return -ENOMEM; + + memset(ag_bin, 0, 2 * key_size); + opdata->pv = ag_bin; + + opdata->x_p = wd_alloc_blk(pool); + if (!opdata->x_p) + goto ag_error; + + memset(opdata->x_p, 0, 2 * key_size); + + opdata->pri = wd_alloc_blk(pool); + if (!opdata->pri) + goto xp_error; + + memset(opdata->pri, 0, 2 * key_size); + opdata->pri_bytes = 2 * key_size; + + ctx_g.data = malloc(key_size); + if (!ctx_g.data) + goto ctx_release; + + if (setup->optype == WCRYPTO_DH_PHASE1) { // GEN1 + memcpy(opdata->x_p, setup->x, setup->x_size); + memcpy(opdata->x_p + key_size, setup->p, setup->p_size); + memcpy(ctx_g.data, setup->g, setup->g_size); + opdata->pbytes = setup->p_size; + opdata->xbytes = setup->x_size; + ctx_g.dsize = setup->g_size; + ctx_g.bsize = key_size; + + ret = wcrypto_set_dh_g(ctx, &ctx_g); + if (ret) + HPRE_TST_PRT("wd_dh_set_g run failed\n"); + } else { // GEN1 + memcpy(opdata->x_p, setup->x, setup->x_size); + memcpy(opdata->x_p + key_size, setup->p, setup->p_size); + memcpy(opdata->pv, setup->except_pub_key, setup->except_pub_key_size); + opdata->pbytes = setup->p_size; + opdata->xbytes = setup->x_size; + opdata->pvbytes = setup->except_pub_key_size; + } + + free(ctx_g.data); + + return 0; + +ctx_release: + wd_free_blk(pool, opdata->pri); +xp_error: + wd_free_blk(pool, opdata->x_p); +ag_error: + wd_free_blk(pool, opdata->pv); + + return -ENOMEM; +} + +static void *dh_wd_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wcrypto_dh_ctx_setup dh_setup; + struct wcrypto_dh_op_data opdata; + struct hpre_dh_param setup; + struct wd_queue *queue; + void *ctx = NULL; + void *tag = NULL; + void *pool; + u32 count = 0; + int ret; + + memset(&dh_setup, 0, sizeof(dh_setup)); + memset(&opdata, 0, sizeof(opdata)); + + pool = g_thread_queue.bd_res[pdata->td_id].pool; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + dh_setup.key_bits = pdata->keybits; + dh_setup.br.alloc = (void *)wd_alloc_blk; + dh_setup.br.free = (void *)wd_free_blk; + dh_setup.br.iova_map = (void *)wd_blk_iova_map; + dh_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + dh_setup.br.get_bufsize = (void *)wd_blksize; + dh_setup.br.usr = pool; + if (pdata->optype == WCRYPTO_DH_PHASE2) + dh_setup.is_g2 = true; // G1 is 0; G2 is 1; + + ctx = wcrypto_create_dh_ctx(queue, &dh_setup); + if (!ctx) + return NULL; + + ret = get_dh_param_from_sample(&setup, pdata->keybits, pdata->kmode); + if (ret) + goto ctx_release; + + setup.optype = pdata->optype; + setup.pool = pool; + opdata.op_type = pdata->optype; + ret = get_dh_opdata_param(ctx, &opdata, &setup, key_size); + if (ret){ + HPRE_TST_PRT("failed to fill dh key gen req!\n"); + goto param_release; + } + + do { + ret = wcrypto_do_dh(ctx, &opdata, tag); + if (ret || opdata.status) { + HPRE_TST_PRT("failed to do dh task, status: %d\n", opdata.status); + goto param_release; + } + + count++; + if (get_run_state() == 0) + break; + } while(true); + +param_release: + wd_free_blk(pool, opdata.x_p); + wd_free_blk(pool, opdata.pv); + wd_free_blk(pool, opdata.pri); +ctx_release: + wcrypto_del_dh_ctx(ctx); + add_recv_data(count, key_size); + + return NULL; +} + +static void dh_async_cb(const void *msg, void *tag) +{ + //struct wcrypto_dh_msg *massage = msg; + //struct rsa_async_tag *ptag = tag; + //u32 op_type = tag->op_type; + //void *ctx = tag->ctx; + + return; +} + +static void *dh_wd_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + struct wcrypto_dh_ctx_setup dh_setup; + struct wcrypto_dh_op_data opdata; + struct rsa_async_tag *tag = NULL; + struct hpre_dh_param setup; + struct wd_queue *queue; + void *ctx = NULL; + int try_cnt = 0; + void *pool; + u32 count = 0; + int i, ret; + + memset(&dh_setup, 0, sizeof(dh_setup)); + memset(&opdata, 0, sizeof(opdata)); + + pool = g_thread_queue.bd_res[pdata->td_id].pool; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + dh_setup.key_bits = pdata->keybits; + dh_setup.br.alloc = (void *)wd_alloc_blk; + dh_setup.br.free = (void *)wd_free_blk; + dh_setup.br.iova_map = (void *)wd_blk_iova_map; + dh_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + dh_setup.br.get_bufsize = (void *)wd_blksize; + dh_setup.cb = (void *)dh_async_cb; + dh_setup.br.usr = pool; + if (pdata->optype == WCRYPTO_DH_PHASE2) + dh_setup.is_g2 = true; // G1 is 0; G2 is 1; + + ctx = wcrypto_create_dh_ctx(queue, &dh_setup); + if (!ctx) + return NULL; + + ret = get_dh_param_from_sample(&setup, pdata->keybits, pdata->kmode); + if (ret) + goto ctx_release; + + setup.optype = pdata->optype; + setup.pool = pool; + opdata.op_type = pdata->optype; + ret = get_dh_opdata_param(ctx, &opdata, &setup, key_size); + if (ret){ + HPRE_TST_PRT("failed to fill dh key gen req!\n"); + goto param_release; + } + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + HPRE_TST_PRT("failed to malloc dh tag!\n"); + goto param_release; + } + + do { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + tag[i].ctx = ctx; + tag[i].cnt = i; + tag[i].optype = opdata.op_type; + + ret = wcrypto_do_dh(ctx, &opdata, &tag[i]); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + HPRE_TST_PRT("Test DH send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret) { + HPRE_TST_PRT("failed to do rsa async task!\n"); + goto tag_release; + } + + count++; + } while(true); + +tag_release: + free(tag); +param_release: + wd_free_blk(pool, opdata.x_p); + wd_free_blk(pool, opdata.pv); + wd_free_blk(pool, opdata.pri); +ctx_release: + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + + wcrypto_del_dh_ctx(ctx); + add_send_complete(); + + return NULL; +} + +static int get_ecc_curve(struct hpre_ecc_setup *setup, u32 cid) +{ + switch (cid) { + case 0: // secp128R1 + setup->nid = 706; + setup->curve_id = WCRYPTO_SECP128R1; + break; + case 1: // secp192K1 + setup->nid = 711; + setup->curve_id = WCRYPTO_SECP192K1; + break; + case 2: // secp256K1 + setup->nid = 714; + setup->curve_id = WCRYPTO_SECP256K1; + break; + case 3: // brainpoolP320R1 + setup->nid = 929; + setup->curve_id = WCRYPTO_BRAINPOOLP320R1; + break; + case 4: // brainpoolP384R1 + setup->nid = 931; + setup->curve_id = WCRYPTO_BRAINPOOLP384R1; + break; + case 5: // secp521R1 + setup->nid = 716; + setup->curve_id = WCRYPTO_SECP521R1; + break; + default: + HPRE_TST_PRT("failed to get ecc curve id!\n"); + return -EINVAL; + } + + return 0; +} + +static int get_ecc_key_param(struct wcrypto_ecc_curve *param, u32 key_bits) +{ + u32 key_size = (key_bits + 7) / 8; + + switch (key_bits) { + case 128: + param->a.data = ecdh_a_secp128r1; + param->b.data = ecdh_b_secp128r1; + param->p.data = ecdh_p_secp128r1; + param->n.data = ecdh_n_secp128r1; + param->g.x.data = ecdh_g_secp128r1; + param->g.y.data = ecdh_g_secp128r1 + key_size; + case 192: + param->a.data = ecdh_a_secp192k1; + param->b.data = ecdh_b_secp192k1; + param->p.data = ecdh_p_secp192k1; + param->n.data = ecdh_n_secp192k1; + param->g.x.data = ecdh_g_secp192k1; + param->g.y.data = ecdh_g_secp192k1 + key_size; + case 224: + param->a.data = ecdh_a_secp224r1; + param->b.data = ecdh_b_secp224r1; + param->p.data = ecdh_p_secp224r1; + param->n.data = ecdh_n_secp224r1; + param->g.x.data = ecdh_g_secp224r1; + param->g.y.data = ecdh_g_secp224r1 + key_size; + case 256: + param->a.data = ecdh_a_secp256k1; + param->b.data = ecdh_b_secp256k1; + param->p.data = ecdh_p_secp256k1; + param->n.data = ecdh_n_secp256k1; + param->g.x.data = ecdh_g_secp256k1; + param->g.y.data = ecdh_g_secp256k1 + key_size; + case 320: + param->a.data = ecdh_a_secp320k1; + param->b.data = ecdh_b_secp320k1; + param->p.data = ecdh_p_secp320k1; + param->n.data = ecdh_n_secp320k1; + param->g.x.data = ecdh_g_secp320k1; + param->g.y.data = ecdh_g_secp320k1 + key_size; + case 384: + param->a.data = ecdh_a_secp384r1; + param->b.data = ecdh_b_secp384r1; + param->p.data = ecdh_p_secp384r1; + param->n.data = ecdh_n_secp384r1; + param->g.x.data = ecdh_g_secp384r1; + param->g.y.data = ecdh_g_secp384r1 + key_size; + case 521: + param->a.data = ecdh_a_secp521r1; + param->b.data = ecdh_b_secp521r1; + param->p.data = ecdh_p_secp521r1; + param->n.data = ecdh_n_secp521r1; + param->g.x.data = ecdh_g_secp521r1; + param->g.y.data = ecdh_g_secp521r1 + key_size; + default: + HPRE_TST_PRT("key_bits %d not find\n", key_bits); + return -EINVAL; + } + + param->a.bsize = key_size; + param->a.dsize = key_size; + param->b.bsize = key_size; + param->b.dsize = key_size; + param->p.bsize = key_size; + param->p.dsize = key_size; + param->n.bsize = key_size; + param->n.dsize = key_size; + param->g.x.bsize = key_size; + param->g.x.dsize = key_size; + param->g.y.bsize = key_size; + param->g.y.dsize = key_size; + + return 0; +} + +static int ecc_get_rand(char *out, size_t out_len, void *usr) +{ + //int ret; + + get_rand_data((u8 *)out, out_len); + //ret = RAND_priv_bytes((void *)out, out_len); + //if (ret != 1) { + // HPRE_TST_PRT("failed to get ecc rand data:%d\n", ret); + // return -EINVAL; + //} + + return 0; +} + +static int ecc_compute_hash(const char *in, size_t in_len, + char *out, size_t out_len, void *usr) +{ + /* perf test for none hash check */ + return 0; +} + +static int get_ecc_param_from_sample(struct hpre_ecc_setup *setup, + u32 subtype, u32 key_bits) +{ + int key_size = (key_bits + 7) / 8; + u32 len; + + setup->key_bits = key_bits; + + if (setup->nid == 714 || key_bits == 256) { // NID_secp256k1 + /* sm2 */ + if (subtype == SM2_TYPE) { + setup->priv_key = sm2_priv; + setup->priv_key_size = sizeof(sm2_priv); + setup->pub_key = sm2_pubkey; + setup->pub_key_size = sizeof(sm2_pubkey); + + len = SM2_DG_SZ; + setup->msg = malloc(len); + if (!setup->msg) + return -1; + memset(setup->msg, 0xFF, len); + + if (true) { // for msg_sigest mode + memcpy(setup->msg, sm2_digest, sizeof(sm2_digest)); + setup->msg_size = sizeof(sm2_digest); + } else { + memcpy(setup->msg, sm2_plaintext, sizeof(sm2_plaintext)); + setup->msg_size = sizeof(sm2_plaintext); + } + + if (setup->msg_size > 512) { + setup->ciphertext = sm2_ciphertext_l; + setup->ciphertext_size = sizeof(sm2_ciphertext_l); + setup->plaintext = sm2_plaintext_l; + setup->plaintext_size = sizeof(sm2_plaintext_l); + } else { + setup->ciphertext = sm2_ciphertext; + setup->ciphertext_size = sizeof(sm2_ciphertext); + setup->plaintext = sm2_plaintext; + setup->plaintext_size = sizeof(sm2_plaintext); + } + + setup->k = sm2_k; + setup->k_size = sizeof(sm2_k); + setup->userid = sm2_id; + setup->userid_size = sizeof(sm2_id); + setup->sign = sm2_sign_data; + setup->sign_size = sizeof(sm2_sign_data); + + } else { + setup->priv_key = ecdh_da_secp256k1; + setup->except_pub_key = ecdh_except_b_pubkey_secp256k1; + setup->pub_key = ecdh_cp_pubkey_secp256k1; + setup->share_key = ecdh_cp_sharekey_secp256k1; + setup->priv_key_size = sizeof(ecdh_da_secp256k1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp256k1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp256k1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp256k1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp256k1; + setup->msg_size = sizeof(ecc_except_e_secp256k1); + setup->k = ecc_except_kinv_secp256k1; + setup->k_size = sizeof(ecc_except_kinv_secp256k1); + setup->rp = ecdh_cp_pubkey_secp256k1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + } + } else if (setup->nid == 706 || key_bits == 128) { + setup->priv_key = ecdh_da_secp128r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp128r1; + setup->pub_key = ecdh_cp_pubkey_secp128r1; + setup->share_key = ecdh_cp_sharekey_secp128r1; + setup->priv_key_size = sizeof(ecdh_da_secp128r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp128r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp128r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp128r1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp128r1; + setup->msg_size = sizeof(ecc_except_e_secp128r1); + setup->k = ecc_except_kinv_secp128r1; + setup->k_size = sizeof(ecc_except_kinv_secp128r1); + setup->rp = ecdh_cp_pubkey_secp128r1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp128r1; + setup->sign_size = sizeof(ecc_cp_sign_secp128r1); + + } else if (setup->nid == 711 || key_bits == 192) { + setup->priv_key = ecdh_da_secp192k1; + setup->except_pub_key = ecdh_except_b_pubkey_secp192k1; + setup->pub_key = ecdh_cp_pubkey_secp192k1; + setup->share_key = ecdh_cp_sharekey_secp192k1; + setup->priv_key_size = sizeof(ecdh_da_secp192k1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp192k1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp192k1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp192k1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp192k1; + setup->msg_size = sizeof(ecc_except_e_secp192k1); + setup->k = ecc_except_kinv_secp192k1; + setup->k_size = sizeof(ecc_except_kinv_secp192k1); + setup->rp = ecdh_cp_pubkey_secp192k1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + } else if (setup->nid == 712 || key_bits == 224) { + setup->priv_key = ecdh_da_secp224r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp224r1; + setup->pub_key = ecdh_cp_pubkey_secp224r1; + setup->share_key = ecdh_cp_sharekey_secp224r1; + setup->priv_key_size = sizeof(ecdh_da_secp224r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp224r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp224r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp224r1); + } else if (setup->nid == 929 || key_bits == 320) { + setup->priv_key = ecdh_da_secp320k1; + setup->except_pub_key = ecdh_except_b_pubkey_secp320k1; + setup->pub_key = ecdh_cp_pubkey_secp320k1; + setup->share_key = ecdh_cp_sharekey_secp320k1; + setup->priv_key_size = sizeof(ecdh_da_secp320k1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp320k1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp320k1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp320k1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp320k1; + setup->msg_size = sizeof(ecc_except_e_secp320k1); + setup->k = ecc_except_kinv_secp320k1; + setup->k_size = sizeof(ecc_except_kinv_secp320k1); + setup->rp = ecdh_cp_pubkey_secp192k1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + + } else if (setup->nid == 931 || key_bits == 384) { + setup->priv_key = ecdh_da_secp384r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp384r1; + setup->pub_key = ecdh_cp_pubkey_secp384r1; + setup->share_key = ecdh_cp_sharekey_secp384r1; + setup->priv_key_size = sizeof(ecdh_da_secp384r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp384r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp384r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp384r1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp384r1; + setup->msg_size = sizeof(ecc_except_e_secp384r1); + setup->k = ecc_except_kinv_secp384r1; + setup->k_size = sizeof(ecc_except_kinv_secp384r1); + setup->rp = ecdh_cp_pubkey_secp384r1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + } else if (setup->nid == 716 || key_bits == 521) { + setup->priv_key = ecdh_da_secp521r1; + setup->except_pub_key = ecdh_except_b_pubkey_secp521r1; + setup->pub_key = ecdh_cp_pubkey_secp521r1; + setup->share_key = ecdh_cp_sharekey_secp521r1; + setup->priv_key_size = sizeof(ecdh_da_secp521r1); + setup->except_pub_key_size = sizeof(ecdh_except_b_pubkey_secp521r1); + setup->pub_key_size = sizeof(ecdh_cp_pubkey_secp521r1); + setup->share_key_size = sizeof(ecdh_cp_sharekey_secp521r1); + + /* ecc sign */ + setup->msg = ecc_except_e_secp521r1; + setup->msg_size = sizeof(ecc_except_e_secp521r1); + setup->k = ecc_except_kinv_secp521r1; + setup->k_size = sizeof(ecc_except_kinv_secp521r1); + setup->rp = ecdh_cp_pubkey_secp521r1 + 1; + setup->rp_size = key_size; + + /* ecc verf */ + setup->sign = ecc_cp_sign_secp256k1; + setup->sign_size = sizeof(ecc_cp_sign_secp256k1); + + } else { + HPRE_TST_PRT("init test sess setup not find this bits %d or nid %d\n", + key_bits, setup->nid); + return -EINVAL; + } + + return 0; +} + +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) +{ + int key_insize = (pdata->keybits + 7) / 8; + u32 optype = pdata->optype; + struct wcrypto_ecc_out *ecc_out = NULL; + struct wcrypto_ecc_in *ecc_in = NULL; + struct wcrypto_ecc_point pub; + struct wd_dtb d, e, k; + int ret = 0; + + if (optype == WCRYPTO_ECDSA_SIGN) {// Sign + ecc_out = wcrypto_new_ecdsa_sign_out(ctx); + if (!ecc_out) { + HPRE_TST_PRT("failed to get ecdsa out!\n"); + return -ENOMEM; + } + + d.data = (void *)setup->priv_key; + d.dsize = setup->priv_key_size; + d.bsize = setup->priv_key_size; + ret = wcrypto_set_ecc_prikey(ecc_key, &d); + if (ret) { + HPRE_TST_PRT("failed to set ecdsa prikey!\n"); + goto del_ecc_out; + } + + pub.x.data = (void *)setup->pub_key + 1; + pub.x.dsize = key_insize; + pub.x.bsize = key_insize; + pub.y.data = pub.x.data + key_insize; + pub.y.dsize = key_insize; + pub.y.bsize = key_insize; + ret = wcrypto_set_ecc_pubkey(ecc_key, &pub); + if (ret) { + HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); + goto del_ecc_out; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = key_insize; + + k.data = (void *)setup->k; + k.dsize = setup->k_size; + k.bsize = key_insize; + ecc_in = wcrypto_new_ecdsa_sign_in(ctx, &e, &k); + if (!ecc_in) { + HPRE_TST_PRT("failed to get ecdsa sign in!\n"); + ret = -ENOMEM; + goto del_ecc_out; + } + + opdata->in = ecc_in; + opdata->out = ecc_out; + } else { // Verf + pub.x.data = (void *)setup->pub_key + 1; + pub.x.dsize = key_insize; + pub.x.bsize = key_insize; + pub.y.data = pub.x.data + key_insize; + pub.y.dsize = key_insize; + pub.y.bsize = key_insize; + ret = wcrypto_set_ecc_pubkey(ecc_key, &pub); + if (ret) { + HPRE_TST_PRT("failed to set ecdsa pubkey!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = key_insize; + + d.data = (void *)setup->sign; + d.dsize = key_insize; + d.bsize = key_insize; + k.data = d.data + key_insize; + k.dsize = key_insize; + k.bsize = key_insize; + ecc_in = wcrypto_new_ecdsa_verf_in(ctx, &e, &d, &k); + if (!ecc_in) { + HPRE_TST_PRT("failed to get ecdsa verf ecc in!\n"); + return -ENOMEM; + } + + opdata->in = ecc_in; + } + + return 0; +del_ecc_out: + if (ecc_out) + (void)wcrypto_del_ecc_out(ctx, ecc_out); + return ret; +} + +static int sm2_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata, + struct hpre_ecc_setup *setup, thread_data *pdata) +{ + int key_insize = (pdata->keybits + 7) / 8; + u32 optype = pdata->optype; + struct wcrypto_ecc_out *ecc_out = NULL; + struct wcrypto_ecc_in *ecc_in = NULL; + struct wcrypto_ecc_point tmp; + struct wd_dtb d, e, k; + + switch (optype) { + case WCRYPTO_SM2_SIGN:// Sign + ecc_out = wcrypto_new_sm2_sign_out(ctx); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = setup->msg_size; + k.data = (void *)setup->k; + k.dsize = setup->k_size; + k.bsize = key_insize; + ecc_in = wcrypto_new_sm2_sign_in(ctx, &e, &k, NULL, 1); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + goto del_ecc_out; + } + opdata->in = ecc_in; + opdata->out = ecc_out; + break; + case WCRYPTO_SM2_VERIFY: // Verf + ecc_out = wcrypto_new_sm2_sign_out(ctx); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->msg; + e.dsize = setup->msg_size; + e.bsize = key_insize; + d.data = (void *)setup->sign; + d.dsize = key_insize; + d.bsize = key_insize; + k.data = d.data + key_insize; + k.dsize = key_insize; + k.bsize = key_insize; + ecc_in = wcrypto_new_sm2_verf_in(ctx, &e, &d, &k, NULL, 1); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + goto del_ecc_out; + } + + opdata->in = ecc_in; + opdata->out = ecc_out; + break; + case WCRYPTO_SM2_ENCRYPT: // Enc + ecc_out = wcrypto_new_sm2_enc_out(ctx, setup->msg_size); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + e.data = (void *)setup->plaintext; + e.dsize = setup->plaintext_size; + e.bsize = setup->plaintext_size; + k.data = (void *)setup->k; + k.dsize = setup->k_size; + k.bsize = key_insize; + ecc_in = wcrypto_new_sm2_enc_in(ctx, &e, &k); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + goto del_ecc_out; + } + opdata->in = ecc_in; + opdata->out = ecc_out; + break; + case WCRYPTO_SM2_DECRYPT: // Dec + tmp.x.data = (void *)setup->ciphertext; + tmp.x.dsize = 32; + tmp.y.data = tmp.x.data + 32; + tmp.y.dsize = 32; + e.data = tmp.y.data + 32; + e.dsize = 32; + d.data = e.data + 32; + d.dsize = setup->ciphertext_size - 32 * 3; + ecc_in = wcrypto_new_sm2_dec_in(ctx, &tmp, &d, &e); + if (!ecc_in) { + HPRE_TST_PRT("failed to alloc sm2 ecc in!\n"); + return -ENOMEM; + } + + ecc_out = wcrypto_new_sm2_dec_out(ctx, d.dsize); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + goto del_ecc_in; + } + + opdata->in = ecc_in; + opdata->out = ecc_out; + break; + case WCRYPTO_SM2_KG: // KG + ecc_out = wcrypto_new_sm2_kg_out(ctx); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc sm2 ecc out!\n"); + return -ENOMEM; + } + + opdata->out = ecc_out; + break; + default: + HPRE_TST_PRT("failed to match sm2 optype!\n"); + return -ENOMEM; + } + + return 0; + +del_ecc_in: + if (ecc_in) + (void)wcrypto_del_ecc_in(ctx, ecc_in); +del_ecc_out: + if (ecc_out) + (void)wcrypto_del_ecc_out(ctx, ecc_out); + + return -ENOMEM; +} + +static int ecc_param_fill(void *ctx, struct wcrypto_ecc_op_data *opdata, + struct wcrypto_ecc_key *ecc_key, struct hpre_ecc_setup *setup, + thread_data *pdata) +{ + int key_insize = (pdata->keybits + 7) / 8; + u32 subtype = pdata->subtype; + u32 optype = pdata->optype; + struct wcrypto_ecc_out *ecc_out = NULL; + struct wcrypto_ecc_in *ecc_in = NULL; + struct wcrypto_ecc_point tmp; + struct wd_dtb d; + int ret = 0; + + ecc_out = wcrypto_new_ecxdh_out(ctx); + if (!ecc_out) { + HPRE_TST_PRT("failed to alloc ecxdh out!\n"); + return -ENOMEM; + } + if (optype == WCRYPTO_ECXDH_GEN_KEY) { // gen + d.data = (void *)setup->priv_key; + d.dsize = setup->priv_key_size; + d.bsize = setup->priv_key_size; + ret = wcrypto_set_ecc_prikey(ecc_key, &d); + if (ret) { + HPRE_TST_PRT("failed to set ecc prikey!\n"); + goto del_ecc_out; + } + + opdata->out = ecc_out; + } else { // compute + if (subtype == ECDH_TYPE) + tmp.x.data = setup->except_pub_key; + else + tmp.x.data = setup->except_pub_key + 1; + tmp.x.bsize = key_insize; + tmp.x.dsize = key_insize; + tmp.y.data = tmp.x.data + key_insize; + tmp.y.bsize = key_insize; + tmp.y.dsize = key_insize; + ecc_in = wcrypto_new_ecxdh_in(ctx, &tmp); + if (!ecc_in) { + HPRE_TST_PRT("failed to get ecxdh sign in!\n"); + goto del_ecc_out; + } + + d.data = (void *)setup->priv_key; + d.dsize = setup->priv_key_size; + d.bsize = setup->priv_key_size; + ret = wcrypto_set_ecc_prikey(ecc_key, &d); + if (ret) { + HPRE_TST_PRT("failed to set ecc prikey!\n"); + goto del_ecc_out; + } + + opdata->in = ecc_in; + opdata->out = ecc_out; + } + + return 0; + +del_ecc_out: + if (ecc_out) + (void)wcrypto_del_ecc_out(ctx, ecc_out); + + return ret; +} + +static void *ecc_wd_sync_run(void *arg) +{ + typedef int (*wd_do)(void *ctx, struct wcrypto_ecc_op_data *opdata, + void *tag); + wd_do wcrypto_do_ecc = NULL; + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + u32 subtype = pdata->subtype; + struct wcrypto_ecc_ctx_setup ctx_setup; + struct wcrypto_ecc_op_data opdata; + struct wcrypto_ecc_curve param; + struct hpre_ecc_setup setup; + struct wcrypto_ecc_key *ecc_key; + struct wcrypto_ecc_point pbk; + struct wd_queue *queue; + struct wd_dtb prk; + void *ctx = NULL; + void *tag = NULL; + void *pool; + u32 cid = ECC_CURVE_ID; + u32 count = 0; + int ret; + + memset(&ctx_setup, 0, sizeof(ctx_setup)); + memset(¶m, 0, sizeof(param)); + memset(&opdata, 0, sizeof(opdata)); + + pool = g_thread_queue.bd_res[pdata->td_id].pool; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + + memset(&setup, 0, sizeof(setup)); + if (subtype != X448_TYPE || subtype != X25519_TYPE) { + ret = get_ecc_curve(&setup, cid); + if (ret) + return NULL; + } + + ctx_setup.br.alloc = (void *)wd_alloc_blk; + ctx_setup.br.free = (void *)wd_free_blk; + ctx_setup.br.iova_map = (void *)wd_blk_iova_map; + ctx_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + ctx_setup.br.get_bufsize = (void *)wd_blksize; + ctx_setup.br.usr = pool; + + ctx_setup.key_bits = pdata->keybits; + if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { + if (cid > ECC_CURVE_ID) { + ctx_setup.cv.type = WCRYPTO_CV_CFG_PARAM; + get_ecc_key_param(¶m, pdata->keybits); + ctx_setup.cv.cfg.pparam = ¶m; + } else { + ctx_setup.cv.type = WCRYPTO_CV_CFG_ID; + ctx_setup.cv.cfg.id = setup.curve_id; + } + } + + ctx_setup.rand.cb = ecc_get_rand; + // set def setting; + ctx_setup.hash.cb = ecc_compute_hash; + ctx_setup.hash.type = WCRYPTO_HASH_SHA256; + + ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); + if (ret) + return NULL; + + ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup); + if (!ctx) + goto msg_release; + + prk.data = (void *)setup.priv_key; + prk.dsize = setup.priv_key_size; + prk.bsize = setup.priv_key_size; + pbk.x.data = (char *)setup.pub_key + 1; + pbk.x.dsize = key_size; + pbk.x.bsize = key_size; + pbk.y.data = pbk.x.data + key_size; + pbk.y.dsize = key_size; + pbk.y.bsize = key_size; + + ecc_key = wcrypto_get_ecc_key(ctx); + ret = wcrypto_set_ecc_prikey(ecc_key, &prk); + if (ret) { + HPRE_TST_PRT("failed to set ecc prikey!\n"); + goto sess_release; + } + + ret = wcrypto_set_ecc_pubkey(ecc_key, &pbk); + if (ret) { + HPRE_TST_PRT("failed to set ecc pubkey!\n"); + goto sess_release; + } + + opdata.op_type = pdata->optype; + switch (subtype) { + case ECDSA_TYPE: // ECC alg + ret = ecdsa_param_fill(ctx, &opdata, ecc_key, &setup, pdata); + if (ret) + goto src_release; + wcrypto_do_ecc = wcrypto_do_ecdsa; + break; + case SM2_TYPE: // SM2 alg + ret = sm2_param_fill(ctx, &opdata, &setup, pdata); + if (ret) + goto src_release; + wcrypto_do_ecc = wcrypto_do_sm2; + break; + default: // ECDH, X25519, X448 alg + ret = ecc_param_fill(ctx, &opdata, ecc_key, &setup, pdata); + if (ret) + goto src_release; + wcrypto_do_ecc = wcrypto_do_ecxdh; + break; + } + + do { + ret = wcrypto_do_ecc(ctx, &opdata, tag); + if (ret || opdata.status) { + HPRE_TST_PRT("failed to do ecc task, status: %d\n", opdata.status); + goto src_release; + } + + count++; + if (get_run_state() == 0) + break; + } while(true); + +src_release: + if (opdata.in) + (void)wcrypto_del_ecc_in(ctx, opdata.in); + if (opdata.out) + (void)wcrypto_del_ecc_out(ctx, opdata.out); +sess_release: + wcrypto_del_ecc_ctx(ctx); +msg_release: + if (subtype == SM2_TYPE) + free(setup.msg); + add_recv_data(count, key_size); + + return NULL; +} + +static void ecc_async_cb(const void *msg, void *tag) +{ + //struct wcrypto_ecc_msg *massage = msg; + //struct rsa_async_tag *ptag = tag; + //u32 op_type = tag->op_type; + //void *ctx = tag->ctx; + + return; +} + +static void *ecc_wd_async_run(void *arg) +{ + typedef int (*wd_do)(void *ctx, struct wcrypto_ecc_op_data *opdata, + void *tag); + wd_do wcrypto_do_ecc = NULL; + thread_data *pdata = (thread_data *)arg; + int key_size = pdata->keybits >> 3; + u32 subtype = pdata->subtype; + struct rsa_async_tag *tag = NULL; + struct wcrypto_ecc_ctx_setup ctx_setup; + struct wcrypto_ecc_op_data opdata; + struct wcrypto_ecc_curve param; + struct hpre_ecc_setup setup; + struct wcrypto_ecc_key *ecc_key; + struct wcrypto_ecc_point pbk; + struct wd_queue *queue; + struct wd_dtb prk; + void *ctx = NULL; + int try_cnt = 0; + void *pool; + u32 cid = ECC_CURVE_ID; + u32 count = 0; + int i, ret; + + memset(&ctx_setup, 0, sizeof(ctx_setup)); + memset(¶m, 0, sizeof(param)); + memset(&opdata, 0, sizeof(opdata)); + + pool = g_thread_queue.bd_res[pdata->td_id].pool; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + + memset(&setup, 0, sizeof(setup)); + if (subtype != X448_TYPE || subtype != X25519_TYPE) { + ret = get_ecc_curve(&setup, cid); + if (ret) + return NULL; + } + + ctx_setup.cb = (void *)ecc_async_cb; + ctx_setup.br.alloc = (void *)wd_alloc_blk; + ctx_setup.br.free = (void *)wd_free_blk; + ctx_setup.br.iova_map = (void *)wd_blk_iova_map; + ctx_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + ctx_setup.br.get_bufsize = (void *)wd_blksize; + ctx_setup.br.usr = pool; + + ctx_setup.key_bits = pdata->keybits; + if (subtype == ECDH_TYPE || subtype == ECDSA_TYPE) { + if (cid > ECC_CURVE_ID) { + ctx_setup.cv.type = WCRYPTO_CV_CFG_PARAM; + get_ecc_key_param(¶m, pdata->keybits); + ctx_setup.cv.cfg.pparam = ¶m; + } else { + ctx_setup.cv.type = WCRYPTO_CV_CFG_ID; + ctx_setup.cv.cfg.id = setup.curve_id; + } + } + + ctx_setup.rand.cb = ecc_get_rand; + // set def setting; + ctx_setup.hash.cb = ecc_compute_hash; + ctx_setup.hash.type = WCRYPTO_HASH_SHA256; + + ret = get_ecc_param_from_sample(&setup, subtype, pdata->keybits); + if (ret) + return NULL; + + ctx = wcrypto_create_ecc_ctx(queue, &ctx_setup); + if (!ctx) + goto msg_release; + + prk.data = (void *)setup.priv_key; + prk.dsize = setup.priv_key_size; + prk.bsize = setup.priv_key_size; + pbk.x.data = (char *)setup.pub_key + 1; + pbk.x.dsize = key_size; + pbk.x.bsize = key_size; + pbk.y.data = pbk.x.data + key_size; + pbk.y.dsize = key_size; + pbk.y.bsize = key_size; + + ecc_key = wcrypto_get_ecc_key(ctx); + ret = wcrypto_set_ecc_prikey(ecc_key, &prk); + if (ret) { + HPRE_TST_PRT("failed to set ecc prikey!\n"); + goto sess_release; + } + + ret = wcrypto_set_ecc_pubkey(ecc_key, &pbk); + if (ret) { + HPRE_TST_PRT("failed to set ecc pubkey!\n"); + goto sess_release; + } + + opdata.op_type = pdata->optype; + switch (subtype) { + case ECDSA_TYPE: // ECC alg + ret = ecdsa_param_fill(ctx, &opdata, ecc_key, &setup, pdata); + if (ret) + goto src_release; + wcrypto_do_ecc = wcrypto_do_ecdsa; + break; + case SM2_TYPE: // SM2 alg + ret = sm2_param_fill(ctx, &opdata, &setup, pdata); + if (ret) + goto src_release; + wcrypto_do_ecc = wcrypto_do_sm2; + break; + default: // ECDH, X25519, X448 alg + ret = ecc_param_fill(ctx, &opdata, ecc_key, &setup, pdata); + if (ret) + goto src_release; + wcrypto_do_ecc = wcrypto_do_ecxdh; + break; + } + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + HPRE_TST_PRT("failed to malloc ecc tag!\n"); + goto src_release; + } + + do { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + tag[i].ctx = ctx; + tag[i].cnt = i; + tag[i].optype = opdata.op_type; + + ret = wcrypto_do_ecc(ctx, &opdata, &tag[i]); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + HPRE_TST_PRT("Test ECC send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret) { + HPRE_TST_PRT("failed to do rsa async task!\n"); + goto tag_release; + } + count++; + } while(true); + +tag_release: + free(tag); +src_release: + if (opdata.in) + (void)wcrypto_del_ecc_in(ctx, opdata.in); + if (opdata.out) + (void)wcrypto_del_ecc_out(ctx, opdata.out); +sess_release: + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + + wcrypto_del_ecc_ctx(ctx); +msg_release: + if (subtype == SM2_TYPE) + free(setup.msg); + add_send_complete(); + + return NULL; +} + +static int hpre_wd_sync_threads(struct acc_option *options) +{ + typedef void *(*hpre_sync_run)(void *arg); + hpre_sync_run wd_hpre_sync_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + threads_option.subtype = options->subtype; + threads_option.td_id = 0; + ret = hpre_wd_param_parse(&threads_option, options); + if (ret) + return ret; + + switch (options->subtype) { + case RSA_TYPE: + wd_hpre_sync_run = rsa_wd_sync_run; + break; + case DH_TYPE: + wd_hpre_sync_run = dh_wd_sync_run; + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + wd_hpre_sync_run = ecc_wd_sync_run; + break; + default: + HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); + return -EINVAL; + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].kmode = threads_option.kmode; + threads_args[i].keybits = threads_option.keybits; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, wd_hpre_sync_run, &threads_args[i]); + if (ret) { + HPRE_TST_PRT("Create sync thread fail!\n"); + goto sync_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + HPRE_TST_PRT("Join sync thread fail!\n"); + goto sync_error; + } + } + +sync_error: + return ret; +} + +static int hpre_wd_async_threads(struct acc_option *options) +{ + typedef void *(*hpre_async_run)(void *arg); + hpre_async_run wd_hpre_async_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + pthread_t pollid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + threads_option.subtype = options->subtype; + threads_option.td_id = 0; + ret = hpre_wd_param_parse(&threads_option, options); + if (ret) + return ret; + + switch (options->subtype) { + case RSA_TYPE: + wd_hpre_async_run = rsa_wd_async_run; + break; + case DH_TYPE: + wd_hpre_async_run = dh_wd_async_run; + break; + case ECDH_TYPE: + case ECDSA_TYPE: + case SM2_TYPE: + case X25519_TYPE: + case X448_TYPE: + wd_hpre_async_run = ecc_wd_async_run; + break; + default: + HPRE_TST_PRT("failed to parse alg subtype on uninit!\n"); + return -EINVAL; + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].td_id = i; + /* poll thread */ + ret = pthread_create(&pollid[i], NULL, hpre_wd_poll, &threads_args[i]); + if (ret) { + HPRE_TST_PRT("Create poll thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].subtype = threads_option.subtype; + threads_args[i].kmode = threads_option.kmode; + threads_args[i].keybits = threads_option.keybits; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, wd_hpre_async_run, &threads_args[i]); + if (ret) { + HPRE_TST_PRT("Create async thread fail!\n"); + goto async_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + HPRE_TST_PRT("Join async thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(pollid[i], NULL); + if (ret) { + HPRE_TST_PRT("Join poll thread fail!\n"); + goto async_error; + } + } + +async_error: + return ret; +} + +int hpre_wd_benchmark(struct acc_option *options) +{ + u32 ptime; + int ret; + + g_thread_num = options->threads; + + if (options->optype >= (WCRYPTO_EC_OP_MAX - WCRYPTO_ECDSA_VERIFY)) { + HPRE_TST_PRT("HPRE optype error: %u\n", options->optype); + return -EINVAL; + } + + ret = init_hpre_wd_queue(options); + if (ret) + return ret; + + get_pid_cpu_time(&ptime); + time_start(options->times); + if (options->syncmode) + ret = hpre_wd_async_threads(options); + else + ret = hpre_wd_sync_threads(options); + cal_perfermance_data(options, ptime); + if (ret) + return ret; + + uninit_hpre_wd_queue(); + + return 0; +} diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.h b/uadk_tool/benchmark/hpre_wd_benchmark.h new file mode 100644 index 0000000..0cc94a3 --- /dev/null +++ b/uadk_tool/benchmark/hpre_wd_benchmark.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#ifndef HPRE_WD_BENCHMARK_H +#define HPRE_WD_BENCHMARK_H + +extern int hpre_wd_benchmark(struct acc_option *options); +#endif /* HPRE_WD_BENCHMARK_H */
Add performance test function of SVA mode for Zlib, Gzip algorithm of ZIP module.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/benchmark/include/fse.h | 51 + uadk_tool/benchmark/zip_uadk_benchmark.c | 1200 ++++++++++++++++++++++ uadk_tool/benchmark/zip_uadk_benchmark.h | 6 + 3 files changed, 1257 insertions(+) create mode 100644 uadk_tool/benchmark/include/fse.h create mode 100644 uadk_tool/benchmark/zip_uadk_benchmark.c create mode 100644 uadk_tool/benchmark/zip_uadk_benchmark.h
diff --git a/uadk_tool/benchmark/include/fse.h b/uadk_tool/benchmark/include/fse.h new file mode 100644 index 0000000..73c3eda --- /dev/null +++ b/uadk_tool/benchmark/include/fse.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#ifndef ZSTD_LZ77_FSE_H +#define ZSTD_LZ77_FSE_H + +#include <limits.h> +#include <stddef.h> + +typedef struct ZSTD_CCtx_s ZSTD_CCtx; + +typedef struct seqDef_s { + unsigned int offset; + unsigned short litLength; + unsigned short matchLength; +} seqDef; + +typedef struct COMP_4TUPLE_TAG_S { + char *litStart; /* literal start address */ + seqDef *sequencesStart; /* sequences start address */ + unsigned int litlen; /* literal effective data length */ + unsigned int seqnum; /* sequences array's elements numbers */ + unsigned int longLengthID; /* litlen overflow flag */ + unsigned int longLengthPos; /* litlen overflow index */ + char *additional_p; /* start address of additional data */ +} COMP_TUPLE_TAG; + +typedef struct ZSTD_inBuffer_s { + const void* src; /* < start of input buffer */ + size_t size; /* < size of input buffer */ + size_t pos; /* < position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ +} ZSTD_inBuffer; + +typedef struct ZSTD_outBuffer_s { + void* dst; /* < start of output buffer */ + size_t size; /* < size of output buffer */ + size_t pos; /* < position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ +} ZSTD_outBuffer; + +typedef enum { + ZSTD_e_continue = 0, /* collect more data, encoder decides when to output compressed result, for optimal compression ratio */ + ZSTD_e_flush = 1, /* flush any data provided so far */ + ZSTD_e_end = 2 /* flush any remaining data _and_ close current frame. */ +} ZSTD_EndDirective; + +/* the complete implementation code in libfse */ +#ifdef ZLIB_FSE +ZSTD_CCtx* zstd_soft_fse_init(unsigned int level); +int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode); +#endif + +#endif diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c new file mode 100644 index 0000000..ba18e6d --- /dev/null +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -0,0 +1,1200 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include <numa.h> +#include "uadk_benchmark.h" + +#include "zip_uadk_benchmark.h" +#include "include/wd_comp.h" +#include "include/wd_sched.h" +#include "include/fse.h" + +#define ZIP_TST_PRT printf +#define PATH_SIZE 64 +#define ZIP_FILE "./zip" +#define COMP_LEN_RATE 2 +#define DECOMP_LEN_RATE 2 + +struct uadk_bd { + u8 *src; + u8 *dst; + u32 src_len; + u32 dst_len; +}; + +struct bd_pool { + struct uadk_bd *bds; +}; + +struct thread_pool { + struct bd_pool *pool; +} g_zip_pool; + +enum ZIP_OP_MODE { + BLOCK_MODE, + STREAM_MODE +}; + +struct zip_async_tag { + handle_t sess; + u32 td_id; + u32 bd_idx; + u32 cm_len; + ZSTD_CCtx *cctx; +}; + +typedef struct uadk_thread_res { + u32 alg; + u32 mode; // block/stream + u32 optype; + u32 td_id; +} thread_data; + +struct zip_file_head { + u32 file_size; + u32 block_num; + u32 blk_sz[MAX_POOL_LENTH]; +}; + +static struct wd_ctx_config g_ctx_cfg; +static struct wd_sched *g_sched; +static unsigned int g_thread_num; +static unsigned int g_ctxnum; +static unsigned int g_pktlen; +static unsigned int g_prefetch; + +#ifndef ZLIB_FSE +static ZSTD_CCtx* zstd_soft_fse_init(unsigned int level) +{ + return NULL; +} + +static int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode) +{ + return input->size; +} +#endif + +static int save_file_data(const char *alg, u32 pkg_len, u32 optype) +{ + struct zip_file_head *fhead = NULL; + char file_path[PATH_SIZE]; + u32 total_file_size = 0; + double comp_rate = 0.0; + u32 full_size; + ssize_t size; + int j, fd; + int ret = 0; + + optype = optype % WD_DIR_MAX; + if (optype != WD_DIR_COMPRESS) //compress + return 0; + + ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); + if (ret < 0) + return -EINVAL; + + ret = access(file_path, F_OK); + if (!ret) { + ZIP_TST_PRT("compress data file: %s has exist!\n", file_path); + return 0; + } + + fd = open(file_path, O_WRONLY|O_CREAT, 0777); + if (fd < 0) { + ZIP_TST_PRT("compress data file open %s fail (%d)!\n", file_path, -errno); + return -ENODEV; + } + + fhead = malloc(sizeof(*fhead)); + if (!fhead) { + ZIP_TST_PRT("failed to alloc file head memory\n"); + ret = -ENOMEM; + goto fd_error; + } + + // init file head informations + for (j = 0; j < MAX_POOL_LENTH; j++) { + fhead->blk_sz[j] = g_zip_pool.pool[0].bds[j].dst_len; + total_file_size += fhead->blk_sz[j]; + } + fhead->block_num = MAX_POOL_LENTH; + fhead->file_size = total_file_size; + size = write(fd, fhead, sizeof(*fhead)); + if (size < 0) { + ZIP_TST_PRT("compress write file head failed: %lu!\n", size); + ret = -EINVAL; + goto write_error; + } + + // write data for one buffer one buffer to file line. + for (j = 0; j < MAX_POOL_LENTH; j++) { + size = write(fd, g_zip_pool.pool[0].bds[j].dst, + fhead->blk_sz[j]); + if (size < 0) { + ZIP_TST_PRT("compress write data error size: %lu!\n", size); + ret = -ENODEV; + break; + } + } + +write_error: + free(fhead); +fd_error: + close(fd); + + full_size = g_pktlen * MAX_POOL_LENTH; + comp_rate = (double) total_file_size / full_size; + ZIP_TST_PRT("compress data rate: %.1f%%!\n", comp_rate * 100); + + return ret; +} + +static int load_file_data(const char *alg, u32 pkg_len, u32 optype) +{ + struct zip_file_head *fhead = NULL; + char file_path[PATH_SIZE]; + ssize_t size = 0xff; + int i, j, fd; + int ret; + + optype = optype % WD_DIR_MAX; + if (optype != WD_DIR_DECOMPRESS) //decompress + return 0; + + ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); + if (ret < 0) + return -EINVAL; + + ret = access(file_path, F_OK); + if (ret) { + ZIP_TST_PRT("Decompress data file: %s not exist!\n", file_path); + return -EINVAL; + } + + // read data from file + fd = open(file_path, O_RDONLY, 0); + if (fd < 0) { + ZIP_TST_PRT("Decompress data file open %s fail (%d)!\n", file_path, -errno); + return -ENODEV; + } + + fhead = malloc(sizeof(*fhead)); + if (!fhead) { + ZIP_TST_PRT("failed to alloc file head memory\n"); + ret = -ENOMEM; + goto fd_err; + } + size = read(fd, fhead, sizeof(*fhead)); + if (size < 0 || fhead->block_num != MAX_POOL_LENTH) { + ZIP_TST_PRT("failed to read file head\n"); + ret = -EINVAL; + goto read_err; + } + + // read data for one buffer one buffer from file line + for (j = 0; j < MAX_POOL_LENTH; j++) { + memset(g_zip_pool.pool[0].bds[j].src, 0x0, + g_zip_pool.pool[0].bds[j].src_len); + if (size != 0) { // zero size buffer no need to read; + size = read(fd, g_zip_pool.pool[0].bds[j].src, + fhead->blk_sz[j]); + if (size < 0) { + ZIP_TST_PRT("Decompress read data error size: %lu!\n", size); + ret = -EINVAL; + goto read_err; + } else if (size == 0) { + ZIP_TST_PRT("Read file to the end!"); + } + } + g_zip_pool.pool[0].bds[j].src_len = size; + } + + for (i = 1; i < g_thread_num; i++) { + for (j = 0; j < MAX_POOL_LENTH; j++) { + if (g_zip_pool.pool[0].bds[j].src_len) + memcpy(g_zip_pool.pool[i].bds[j].src, + g_zip_pool.pool[0].bds[j].src, + g_zip_pool.pool[0].bds[j].src_len); + g_zip_pool.pool[i].bds[j].src_len = + g_zip_pool.pool[0].bds[j].src_len; + } + } + +read_err: + free(fhead); +fd_err: + close(fd); + + return ret; +} + +static int zip_uadk_param_parse(thread_data *tddata, struct acc_option *options) +{ + u32 algtype = options->algtype; + u32 optype = options->optype; + u8 mode = BLOCK_MODE; + u8 alg; + + if (optype >= WD_DIR_MAX << 1) { + ZIP_TST_PRT("Fail to get zip optype!\n"); + return -EINVAL; + } else if (optype >= WD_DIR_MAX) { + mode = STREAM_MODE; + } + + optype = optype % WD_DIR_MAX; + + switch(algtype) { + case ZLIB: + alg = WD_ZLIB; + break; + case GZIP: + alg = WD_GZIP; + break; + case DEFLATE: + alg = WD_DEFLATE; + break; + case LZ77_ZSTD: + alg = WD_LZ77_ZSTD; + if (optype == WD_DIR_DECOMPRESS) + ZIP_TST_PRT("Zip LZ77_ZSTD just support compress!\n"); + optype = WD_DIR_COMPRESS; + break; + default: + ZIP_TST_PRT("Fail to set zip alg\n"); + return -EINVAL; + } + + tddata->alg = alg; + tddata->mode = mode; + tddata->optype = optype; + + return 0; +} + +static int init_ctx_config(char *alg, int mode, int optype) +{ + struct uacce_dev_list *list; + struct sched_params param; + int i, max_node; + int ret = 0; + + max_node = numa_max_node() + 1; + if (max_node <= 0) + return -EINVAL; + + list = wd_get_accel_list(alg); + if (!list) { + ZIP_TST_PRT("Fail 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; + + g_sched = wd_sched_rr_alloc(SCHED_POLICY_RR, 2, max_node, wd_comp_poll_ctx); + if (!g_sched) { + ZIP_TST_PRT("Fail to alloc sched!\n"); + goto out; + } + + /* If there is no numa, we defualt config to zero */ + if (list->dev->numa_id < 0) + list->dev->numa_id = 0; + + 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; + } + g_sched->name = SCHED_SINGLE; + + /* + * All contexts for 2 modes & 2 types. + * The test only uses one kind of contexts at the same time. + */ + optype = optype % WD_DIR_MAX; + param.numa_id = list->dev->numa_id; + param.type = optype; + param.mode = mode; + param.begin = 0; + param.end = g_ctxnum - 1; + ret = wd_sched_rr_instance(g_sched, ¶m); + if (ret) { + ZIP_TST_PRT("Fail to fill sched data!\n"); + goto out; + } + + /* init */ + ret = wd_comp_init(&g_ctx_cfg, g_sched); + if (ret) { + ZIP_TST_PRT("Fail to cipher ctx!\n"); + goto out; + } + + wd_free_list_accels(list); + + return 0; +out: + free(g_ctx_cfg.ctxs); + wd_sched_rr_release(g_sched); + + return ret; +} + +static void uninit_ctx_config(void) +{ + int i; + + /* uninit */ + wd_comp_uninit(); + + for (i = 0; i < g_ctx_cfg.ctx_num; i++) + wd_release_ctx(g_ctx_cfg.ctxs[i].ctx); + free(g_ctx_cfg.ctxs); + wd_sched_rr_release(g_sched); +} + +static int init_uadk_bd_pool(u32 optype) +{ + u32 outsize; + u32 insize; + int i, j; + + // make the block not align to 4K + optype = optype % WD_DIR_MAX; + if (optype == WD_DIR_COMPRESS) {//compress + insize = g_pktlen; + outsize = g_pktlen * COMP_LEN_RATE; + } else { // decompress + insize = g_pktlen; + outsize = g_pktlen * DECOMP_LEN_RATE; + } + + g_zip_pool.pool = malloc(g_thread_num * sizeof(struct bd_pool)); + if (!g_zip_pool.pool) { + ZIP_TST_PRT("init uadk pool alloc thread failed!\n"); + return -ENOMEM; + } else { + for (i = 0; i < g_thread_num; i++) { + g_zip_pool.pool[i].bds = malloc(MAX_POOL_LENTH * + sizeof(struct uadk_bd)); + if (!g_zip_pool.pool[i].bds) { + ZIP_TST_PRT("init uadk bds alloc failed!\n"); + goto malloc_error1; + } + for (j = 0; j < MAX_POOL_LENTH; j++) { + g_zip_pool.pool[i].bds[j].src = malloc(insize); + if (!g_zip_pool.pool[i].bds[j].src) + goto malloc_error2; + g_zip_pool.pool[i].bds[j].src_len = insize; + + g_zip_pool.pool[i].bds[j].dst = malloc(outsize); + if (!g_zip_pool.pool[i].bds[j].dst) + goto malloc_error3; + g_zip_pool.pool[i].bds[j].dst_len = outsize; + + get_rand_data(g_zip_pool.pool[i].bds[j].src, insize); + if (g_prefetch) + get_rand_data(g_zip_pool.pool[i].bds[j].dst, outsize); + } + } + } + + return 0; + +malloc_error3: + free(g_zip_pool.pool[i].bds[j].src); +malloc_error2: + for (j--; j >= 0; j--) { + free(g_zip_pool.pool[i].bds[j].src); + free(g_zip_pool.pool[i].bds[j].dst); + } +malloc_error1: + for (i--; i >= 0; i--) { + for (j = 0; j < MAX_POOL_LENTH; j++) { + free(g_zip_pool.pool[i].bds[j].src); + free(g_zip_pool.pool[i].bds[j].dst); + } + free(g_zip_pool.pool[i].bds); + g_zip_pool.pool[i].bds = NULL; + } + free(g_zip_pool.pool); + g_zip_pool.pool = NULL; + + ZIP_TST_PRT("init uadk bd pool alloc failed!\n"); + return -ENOMEM; +} + +static void free_uadk_bd_pool(void) +{ + int i, j; + + for (i = 0; i < g_thread_num; i++) { + if (g_zip_pool.pool[i].bds) { + for (j = 0; j < MAX_POOL_LENTH; j++) { + free(g_zip_pool.pool[i].bds[j].src); + free(g_zip_pool.pool[i].bds[j].dst); + } + } + free(g_zip_pool.pool[i].bds); + g_zip_pool.pool[i].bds = NULL; + } + free(g_zip_pool.pool); + g_zip_pool.pool = NULL; +} + +/*-------------------------------uadk benchmark main code-------------------------------------*/ +static void *zip_lz77_async_cb(struct wd_comp_req *req, void *data) +{ + struct zip_async_tag *tag = req->cb_param; + struct bd_pool *uadk_pool; + int td_id = tag->td_id; + int idx = tag->bd_idx; + ZSTD_inBuffer zstd_input; + ZSTD_outBuffer zstd_output; + ZSTD_CCtx *cctx = tag->cctx; + size_t fse_size; + + uadk_pool = &g_zip_pool.pool[td_id]; + uadk_pool->bds[idx].dst_len = req->dst_len; + + zstd_input.src = req->src; + zstd_input.size = req->src_len; + zstd_input.pos = 0; + zstd_output.dst = uadk_pool->bds[idx].dst; + zstd_output.size = tag->cm_len; + zstd_output.pos = 0; + fse_size = zstd_soft_fse(req->priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); + + uadk_pool->bds[idx].dst_len = fse_size; + + return NULL; +} + +static void *zip_async_cb(struct wd_comp_req *req, void *data) +{ + struct zip_async_tag *tag = req->cb_param; + struct bd_pool *uadk_pool; + int td_id = tag->td_id; + int idx = tag->bd_idx; + + uadk_pool = &g_zip_pool.pool[td_id]; + uadk_pool->bds[idx].dst_len = req->dst_len; + + return NULL; +} + +static void *zip_uadk_poll(void *data) +{ + thread_data *pdata = (thread_data *)data; + u32 expt = ACC_QUEUE_SIZE * g_thread_num; + u32 id = pdata->td_id; + u32 last_time = 2; // poll need one more recv time + u32 count = 0; + u32 recv = 0; + int ret; + + if (id > g_ctxnum) + return NULL; + + while (last_time) { + ret = wd_comp_poll_ctx(id, expt, &recv); + count += recv; + recv = 0; + if (unlikely(ret != -WD_EAGAIN && ret < 0)) { + ZIP_TST_PRT("poll ret: %u!\n", ret); + goto recv_error; + } + + if (get_run_state() == 0) + last_time--; + } + +recv_error: + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *zip_uadk_blk_lz77_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_comp_sess_setup comp_setup = {0}; + ZSTD_CCtx *cctx = zstd_soft_fse_init(15); + ZSTD_inBuffer zstd_input = {0}; + ZSTD_outBuffer zstd_output = {0}; + COMP_TUPLE_TAG *ftuple = NULL; + struct bd_pool *uadk_pool; + struct wd_comp_req creq; + char *hw_buff_out = NULL; + size_t fse_size; + handle_t h_sess; + u32 first_len = 0; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_zip_pool.pool[pdata->td_id]; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&creq, 0, sizeof(creq)); + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WD_COMP_L8; + comp_setup.win_sz = WD_COMP_WS_8K; + h_sess = wd_comp_alloc_sess(&comp_setup); + if (!h_sess) + return NULL; + + creq.op_type = pdata->optype; + creq.src_len = g_pktlen; + out_len = uadk_pool->bds[0].dst_len; + + creq.cb = NULL; + creq.data_fmt = 0; + creq.status = 0; + + ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); + if (!ftuple) + goto fse_err; + + hw_buff_out = malloc(out_len * MAX_POOL_LENTH); + if (!hw_buff_out) + goto hw_buff_err; + memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); + + while(1) { + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = &hw_buff_out[i]; //temp out + creq.src_len = uadk_pool->bds[i].src_len; + creq.dst_len = out_len; + creq.priv = &ftuple[i]; + + ret = wd_do_comp_sync(h_sess, &creq); + if (ret || creq.status) + break; + + count++; + zstd_input.src = creq.src; + zstd_input.size = creq.src_len; + zstd_input.pos = 0; + zstd_output.dst = uadk_pool->bds[i].dst; + zstd_output.size = out_len; + zstd_output.pos = 0; + fse_size = zstd_soft_fse(creq.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); + + uadk_pool->bds[i].dst_len = fse_size; + if (unlikely(i == 0)) + first_len = fse_size; + if (get_run_state() == 0) + break; + } + +hw_buff_err: + free(hw_buff_out); +fse_err: + free(ftuple); + wd_comp_free_sess(h_sess); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, creq.dst_len); + if (pdata->optype == WD_DIR_COMPRESS) + add_recv_data(count, creq.src_len); + else + add_recv_data(count, first_len); + + return NULL; +} + +static void *zip_uadk_stm_lz77_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_comp_sess_setup comp_setup = {0}; + ZSTD_CCtx *cctx = zstd_soft_fse_init(15); + ZSTD_inBuffer zstd_input = {0}; + ZSTD_outBuffer zstd_output = {0}; + COMP_TUPLE_TAG *ftuple = NULL; + struct bd_pool *uadk_pool; + struct wd_comp_req creq; + char *hw_buff_out = NULL; + size_t fse_size; + handle_t h_sess; + u32 first_len = 0; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_zip_pool.pool[pdata->td_id]; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&creq, 0, sizeof(creq)); + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WD_COMP_L8; + comp_setup.win_sz = WD_COMP_WS_8K; + h_sess = wd_comp_alloc_sess(&comp_setup); + if (!h_sess) + return NULL; + + creq.op_type = pdata->optype; + creq.src_len = g_pktlen; + out_len = uadk_pool->bds[0].dst_len; + + creq.cb = NULL; + creq.data_fmt = 0; + creq.status = 0; + + ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); + if (!ftuple) + goto fse_err; + + hw_buff_out = malloc(out_len * MAX_POOL_LENTH); + if (!hw_buff_out) + goto hw_buff_err; + memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); + + while(1) { + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = &hw_buff_out[i]; //temp out + creq.src_len = uadk_pool->bds[i].src_len; + creq.dst_len = out_len; + creq.priv = &ftuple[i]; + + ret = wd_do_comp_strm(h_sess, &creq); + if (ret < 0 || creq.status == WD_IN_EPARA) { + ZIP_TST_PRT("wd comp, invalid or incomplete data! " + "ret(%d), req.status(%u)\n", ret, creq.status); + break; + } + + count++; + zstd_input.src = creq.src; + zstd_input.size = creq.src_len; + zstd_input.pos = 0; + zstd_output.dst = uadk_pool->bds[i].dst; + zstd_output.size = out_len; + zstd_output.pos = 0; + fse_size = zstd_soft_fse(creq.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); + + uadk_pool->bds[i].dst_len = fse_size; + if (unlikely(i == 0)) + first_len = fse_size; + if (get_run_state() == 0) + break; + } + +hw_buff_err: + free(hw_buff_out); +fse_err: + free(ftuple); + wd_comp_free_sess(h_sess); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, creq.dst_len); + if (pdata->optype == WD_DIR_COMPRESS) + add_recv_data(count, creq.src_len); + else + add_recv_data(count, first_len); + + return NULL; +} + +static void *zip_uadk_blk_lz77_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_comp_sess_setup comp_setup = {0}; + ZSTD_CCtx *cctx = zstd_soft_fse_init(15); + COMP_TUPLE_TAG *ftuple = NULL; + struct bd_pool *uadk_pool; + struct wd_comp_req creq; + struct zip_async_tag *tag; + char *hw_buff_out = NULL; + handle_t h_sess; + u32 out_len = 0; + u32 count = 0; + u32 try_cnt = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_zip_pool.pool[pdata->td_id]; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&creq, 0, sizeof(creq)); + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WD_COMP_L8; + comp_setup.win_sz = WD_COMP_WS_8K; + h_sess = wd_comp_alloc_sess(&comp_setup); + if (!h_sess) + return NULL; + + creq.op_type = pdata->optype; + creq.src_len = g_pktlen; + out_len = uadk_pool->bds[0].dst_len; + + creq.cb = zip_lz77_async_cb; + creq.data_fmt = 0; + creq.status = 0; + + ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); + if (!ftuple) + goto fse_err; + + hw_buff_out = malloc(out_len * MAX_POOL_LENTH); + if (!hw_buff_out) + goto hw_buff_err; + memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + ZIP_TST_PRT("failed to malloc zip tag!\n"); + goto tag_err; + } + + while(1) { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = &hw_buff_out[i]; //temp out + creq.src_len = uadk_pool->bds[i].src_len; + creq.dst_len = out_len; + creq.priv = &ftuple[i]; + + tag[i].td_id = pdata->td_id; + tag[i].bd_idx = i; + tag[i].cm_len = out_len; + tag[i].cctx = cctx; + creq.cb_param = &tag[i]; + + ret = wd_do_comp_async(h_sess, &creq); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + ZIP_TST_PRT("Test LZ77 compress send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret || creq.status) { + break; + } + count++; + } + + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + +tag_err: + free(tag); +hw_buff_err: + free(hw_buff_out); +fse_err: + free(ftuple); + wd_comp_free_sess(h_sess); + + // ZIP_TST_PRT("LZ77 valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, creq.dst_len); + + add_send_complete(); + + return NULL; +} + +static void *zip_uadk_blk_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_comp_sess_setup comp_setup = {0}; + struct bd_pool *uadk_pool; + struct wd_comp_req creq; + handle_t h_sess; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_zip_pool.pool[pdata->td_id]; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&creq, 0, sizeof(creq)); + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WD_COMP_L8; + comp_setup.win_sz = WD_COMP_WS_8K; + h_sess = wd_comp_alloc_sess(&comp_setup); + if (!h_sess) + return NULL; + + creq.op_type = pdata->optype; + creq.src_len = g_pktlen; + out_len = uadk_pool->bds[0].dst_len; + + creq.cb = NULL; + creq.data_fmt = 0; + creq.priv = 0; + creq.status = 0; + + while(1) { + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = uadk_pool->bds[i].dst; + creq.src_len = uadk_pool->bds[i].src_len; + creq.dst_len = out_len; + + ret = wd_do_comp_sync(h_sess, &creq); + if (ret || creq.status) + break; + + count++; + uadk_pool->bds[i].dst_len = creq.dst_len; + if (get_run_state() == 0) + break; + } + wd_comp_free_sess(h_sess); + + //ZIP_TST_PRT("valid pool len: %u, send count BD: %u, input len: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, creq.src_len, g_pktlen); + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *zip_uadk_stm_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_comp_sess_setup comp_setup = {0}; + struct bd_pool *uadk_pool; + struct wd_comp_req creq; + handle_t h_sess; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_zip_pool.pool[pdata->td_id]; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&creq, 0, sizeof(creq)); + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WD_COMP_L8; + comp_setup.win_sz = WD_COMP_WS_8K; + h_sess = wd_comp_alloc_sess(&comp_setup); + if (!h_sess) + return NULL; + + creq.op_type = pdata->optype; + creq.src_len = g_pktlen; + out_len = uadk_pool->bds[0].dst_len; + + creq.cb = NULL; + creq.data_fmt = 0; + creq.priv = 0; + creq.status = 0; + + while(1) { + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = uadk_pool->bds[i].dst; + creq.src_len = uadk_pool->bds[i].src_len; + creq.dst_len = out_len; + + ret = wd_do_comp_strm(h_sess, &creq); + if (ret < 0 || creq.status == WD_IN_EPARA) { + ZIP_TST_PRT("wd comp, invalid or incomplete data! " + "ret(%d), req.status(%u)\n", ret, creq.status); + break; + } + + count++; + uadk_pool->bds[i].dst_len = creq.dst_len; + + if (get_run_state() == 0) + break; + } + wd_comp_free_sess(h_sess); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, creq.dst_len); + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *zip_uadk_blk_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_comp_sess_setup comp_setup = {0}; + struct bd_pool *uadk_pool; + struct zip_async_tag *tag; + struct wd_comp_req creq; + handle_t h_sess; + int try_cnt = 0; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_zip_pool.pool[pdata->td_id]; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&creq, 0, sizeof(creq)); + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WD_COMP_L8; + comp_setup.win_sz = WD_COMP_WS_8K; + h_sess = wd_comp_alloc_sess(&comp_setup); + if (!h_sess) + return NULL; + + creq.op_type = pdata->optype; + creq.src_len = g_pktlen; + out_len = uadk_pool->bds[0].dst_len; + + creq.cb = zip_async_cb; + creq.data_fmt = 0; + creq.priv = 0; + creq.status = 0; + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + ZIP_TST_PRT("failed to malloc zip tag!\n"); + wd_comp_free_sess(h_sess); + return NULL; + } + + while(1) { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = uadk_pool->bds[i].dst; + creq.src_len = uadk_pool->bds[i].src_len; + creq.dst_len = out_len; + + tag[i].td_id = pdata->td_id; + tag[i].bd_idx = i; + creq.cb_param = &tag[i]; + + ret = wd_do_comp_async(h_sess, &creq); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + ZIP_TST_PRT("Test compress send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret || creq.status) { + break; + } + count++; + } + + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + + free(tag); + wd_comp_free_sess(h_sess); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, creq.dst_len); + + add_send_complete(); + + return NULL; +} + +static int zip_uadk_sync_threads(struct acc_option *options) +{ + typedef void *(*zip_sync_run)(void *arg); + zip_sync_run uadk_zip_sync_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + ret = zip_uadk_param_parse(&threads_option, options); + if (ret) + return ret; + + if (threads_option.mode == 1) {// stream mode + if (threads_option.alg == LZ77_ZSTD) + uadk_zip_sync_run = zip_uadk_stm_lz77_sync_run; + else + uadk_zip_sync_run = zip_uadk_stm_sync_run; + } else { + if (threads_option.alg == LZ77_ZSTD) + uadk_zip_sync_run = zip_uadk_blk_lz77_sync_run; + else + uadk_zip_sync_run = zip_uadk_blk_sync_run; + } + for (i = 0; i < g_thread_num; i++) { + threads_args[i].alg = threads_option.alg; + threads_args[i].mode = threads_option.mode; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, uadk_zip_sync_run, &threads_args[i]); + if (ret) { + ZIP_TST_PRT("Create sync thread fail!\n"); + goto sync_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + ZIP_TST_PRT("Join sync thread fail!\n"); + goto sync_error; + } + } + +sync_error: + return ret; +} + +static int zip_uadk_async_threads(struct acc_option *options) +{ + typedef void *(*zip_async_run)(void *arg); + zip_async_run uadk_zip_async_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + pthread_t pollid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + ret = zip_uadk_param_parse(&threads_option, options); + if (ret) + return ret; + + if (threads_option.mode == STREAM_MODE) {// stream mode + ZIP_TST_PRT("Stream mode can't support async mode!\n"); + return 0; + } + + if (threads_option.alg == LZ77_ZSTD) + uadk_zip_async_run = zip_uadk_blk_lz77_async_run; + else + uadk_zip_async_run = zip_uadk_blk_async_run; + + for (i = 0; i < g_ctxnum; i++) { + threads_args[i].td_id = i; + /* poll thread */ + ret = pthread_create(&pollid[i], NULL, zip_uadk_poll, &threads_args[i]); + if (ret) { + ZIP_TST_PRT("Create poll thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].alg = threads_option.alg; + threads_args[i].mode = threads_option.mode; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, uadk_zip_async_run, &threads_args[i]); + if (ret) { + ZIP_TST_PRT("Create async thread fail!\n"); + goto async_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + ZIP_TST_PRT("Join async thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_ctxnum; i++) { + ret = pthread_join(pollid[i], NULL); + if (ret) { + ZIP_TST_PRT("Join poll thread fail!\n"); + goto async_error; + } + } + +async_error: + return ret; +} + +int zip_uadk_benchmark(struct acc_option *options) +{ + u32 ptime; + int ret; + + g_thread_num = options->threads; + g_pktlen = options->pktlen; + g_ctxnum = options->ctxnums; + g_prefetch = options->prefetch; + + if (options->optype >= WD_DIR_MAX * 2) { + ZIP_TST_PRT("ZIP optype error: %u\n", options->optype); + return -EINVAL; + } + + ret = init_ctx_config(options->algclass, options->syncmode, options->optype); + if (ret) + return ret; + + ret = init_uadk_bd_pool(options->optype); + if (ret) + return ret; + + ret = load_file_data(options->algname, options->pktlen, options->optype); + if (ret) + return ret; + + get_pid_cpu_time(&ptime); + time_start(options->times); + if (options->syncmode) + ret = zip_uadk_async_threads(options); + else + ret = zip_uadk_sync_threads(options); + cal_perfermance_data(options, ptime); + if (ret) + return ret; + + ret = save_file_data(options->algname, options->pktlen, options->optype); + if (ret) + return ret; + + free_uadk_bd_pool(); + uninit_ctx_config(); + + return 0; +} diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.h b/uadk_tool/benchmark/zip_uadk_benchmark.h new file mode 100644 index 0000000..a3cfbc0 --- /dev/null +++ b/uadk_tool/benchmark/zip_uadk_benchmark.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#ifndef ZIP_UADK_BENCHMARK_H +#define ZIP_UADK_BENCHMARK_H + +extern int zip_uadk_benchmark(struct acc_option *options); +#endif /* ZIP_UADK_BENCHMARK_H */
Add NO-SVA mode performance test function for Zlib, Gzip algorithm of ZIP module.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/benchmark/zip_wd_benchmark.c | 1257 ++++++++++++++++++++++++ uadk_tool/benchmark/zip_wd_benchmark.h | 6 + 2 files changed, 1263 insertions(+) create mode 100644 uadk_tool/benchmark/zip_wd_benchmark.c create mode 100644 uadk_tool/benchmark/zip_wd_benchmark.h
diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c new file mode 100644 index 0000000..0df78cd --- /dev/null +++ b/uadk_tool/benchmark/zip_wd_benchmark.c @@ -0,0 +1,1257 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +#include <numa.h> +#include "uadk_benchmark.h" + +#include "zip_wd_benchmark.h" +#include "v1/wd_comp.h" +#include "v1/wd.h" +#include "v1/wd_bmm.h" +#include "v1/wd_util.h" +#include "include/fse.h" + +#define ZIP_TST_PRT printf +#define PATH_SIZE 64 +#define ZIP_FILE "./zip" +#define WCRYPTO_DIR_MAX (WCRYPTO_INFLATE + 1) +#define ALIGN_SIZE 64 + +#define COMP_LEN_RATE 2 +#define DECOMP_LEN_RATE 2 + +#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) + +struct wd_bd { + u8 *src; + u8 *dst; + u32 src_len; + u32 dst_len; +}; + +struct thread_bd_res { + struct wd_queue *queue; + void *pool; + struct wd_bd *bds; +}; + +struct thread_queue_res { + struct thread_bd_res *bd_res; +}; + +static struct thread_queue_res g_thread_queue; + +enum ZIP_OP_MODE { + BLOCK_MODE, + STREAM_MODE +}; + +struct zip_async_tag { + void *ctx; + u32 td_id; + u32 bd_idx; + u32 cm_len; + void *priv; + ZSTD_CCtx *cctx; +}; + +typedef struct uadk_thread_res { + u32 alg; + u32 mode; // block/stream + u32 optype; + u32 td_id; +} thread_data; + +struct zip_file_head { + u32 file_size; + u32 block_num; + u32 blk_sz[MAX_POOL_LENTH]; +}; + +static unsigned int g_thread_num; +static unsigned int g_pktlen; + +#ifndef ZLIB_FSE +static ZSTD_CCtx* zstd_soft_fse_init(unsigned int level) +{ + return NULL; +} + +static int zstd_soft_fse(void *Ftuple, ZSTD_inBuffer *input, ZSTD_outBuffer *output, ZSTD_CCtx * cctx, ZSTD_EndDirective cmode) +{ + return input->size; +} +#endif + +static int save_file_data(const char *alg, u32 pkg_len, u32 optype) +{ + struct zip_file_head *fhead = NULL; + char file_path[PATH_SIZE]; + u32 total_file_size = 0; + double comp_rate = 0.0; + u32 full_size; + ssize_t size; + int j, fd; + int ret = 0; + + optype = optype % WCRYPTO_DIR_MAX; + if (optype != WCRYPTO_DEFLATE) //compress + return 0; + + ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); + if (ret < 0) + return -EINVAL; + + ret = access(file_path, F_OK); + if (!ret) { + ZIP_TST_PRT("compress data file: %s has exist!\n", file_path); + return 0; + } + + fd = open(file_path, O_WRONLY|O_CREAT, 0777); + if (fd < 0) { + ZIP_TST_PRT("compress data file open %s failed (%d)!\n", file_path, -errno); + return -ENODEV; + } + + fhead = malloc(sizeof(*fhead)); + if (!fhead) { + ZIP_TST_PRT("failed to alloc file head memory\n"); + ret = -ENOMEM; + goto fd_error; + } + + // init file head informations + for (j = 0; j < MAX_POOL_LENTH; j++) { + fhead->blk_sz[j] = g_thread_queue.bd_res[0].bds[j].dst_len; + total_file_size += fhead->blk_sz[j]; + } + fhead->block_num = MAX_POOL_LENTH; + fhead->file_size = total_file_size; + size = write(fd, fhead, sizeof(*fhead)); + if (size < 0) { + ZIP_TST_PRT("compress write file head failed: %lu!\n", size); + ret = -ENODEV; + goto write_error; + } + + // write data for one buffer one buffer to file line. + for (j = 0; j < MAX_POOL_LENTH; j++) { + size = write(fd, g_thread_queue.bd_res[0].bds[j].dst, + fhead->blk_sz[j]); + if (size < 0) { + ZIP_TST_PRT("compress write data error size: %lu!\n", size); + ret = -ENODEV; + break; + } + } + +write_error: + free(fhead); +fd_error: + close(fd); + + full_size = g_pktlen * MAX_POOL_LENTH; + comp_rate = (double) total_file_size / full_size; + ZIP_TST_PRT("compress data rate: %.1f%%!\n", comp_rate * 100); + + return ret; +} + +static int load_file_data(const char *alg, u32 pkg_len, u32 optype) +{ + struct zip_file_head *fhead = NULL; + char file_path[PATH_SIZE]; + ssize_t size = 0xff; + int i, j, fd; + int ret; + + optype = optype % WCRYPTO_DIR_MAX; + if (optype != WCRYPTO_INFLATE) //decompress + return 0; + + ret = snprintf(file_path, PATH_SIZE, "%s_%u.%s", ZIP_FILE, pkg_len, alg); + if (ret < 0) + return -EINVAL; + + ret = access(file_path, F_OK); + if (ret) { + ZIP_TST_PRT("Decompress data file: %s not exist!\n", file_path); + return -EINVAL; + } + + // read data from file + fd = open(file_path, O_RDONLY, 0); + if (fd < 0) { + ZIP_TST_PRT("Decompress data file open %s fail (%d)!\n", file_path, -errno); + return -ENODEV; + } + + fhead = malloc(sizeof(*fhead)); + if (!fhead) { + ZIP_TST_PRT("failed to alloc file head memory\n"); + ret = -ENOMEM; + goto fd_err; + } + size = read(fd, fhead, sizeof(*fhead)); + if (size < 0 || fhead->block_num != MAX_POOL_LENTH) { + ZIP_TST_PRT("failed to read file head\n"); + ret = -EINVAL; + goto read_err; + } + + // read data for one buffer one buffer from file line + for (j = 0; j < MAX_POOL_LENTH; j++) { + memset(g_thread_queue.bd_res[0].bds[j].src, 0x0, + g_thread_queue.bd_res[0].bds[j].src_len); + if (size != 0) { // zero size buffer no need to read; + size = read(fd, g_thread_queue.bd_res[0].bds[j].src, + fhead->blk_sz[j]); + if (size < 0) { + ZIP_TST_PRT("Decompress read data error size: %lu!\n", size); + ret = -EINVAL; + goto read_err; + } else if (size == 0) { + ZIP_TST_PRT("Read file to the end!"); + } + } + g_thread_queue.bd_res[0].bds[j].src_len = size; + } + + for (i = 1; i < g_thread_num; i++) { + for (j = 0; j < MAX_POOL_LENTH; j++) { + if (g_thread_queue.bd_res[0].bds[j].src_len) + memcpy(g_thread_queue.bd_res[i].bds[j].src, + g_thread_queue.bd_res[0].bds[j].src, + g_thread_queue.bd_res[0].bds[j].src_len); + g_thread_queue.bd_res[i].bds[j].src_len = + g_thread_queue.bd_res[0].bds[j].src_len; + } + } + +read_err: + free(fhead); +fd_err: + close(fd); + + return ret; +} + +static int zip_wd_param_parse(thread_data *tddata, struct acc_option *options) +{ + u32 algtype = options->algtype; + u32 optype = options->optype; + u8 mode = BLOCK_MODE; + u8 alg; + + if (optype >= WCRYPTO_DIR_MAX << 1) { + ZIP_TST_PRT("Fail to get zip optype!\n"); + return -EINVAL; + } else if (optype > WCRYPTO_INFLATE) { + mode = STREAM_MODE; + } + + optype = optype % WCRYPTO_DIR_MAX; + + switch(algtype) { + case ZLIB: + alg = WCRYPTO_ZLIB; + break; + case GZIP: + alg = WCRYPTO_GZIP; + break; + case DEFLATE: + alg = WCRYPTO_RAW_DEFLATE; + break; + case LZ77_ZSTD: + alg = WCRYPTO_LZ77_ZSTD; + if (optype == WCRYPTO_INFLATE) + ZIP_TST_PRT("Zip LZ77_ZSTD just support compress!\n"); + optype = WCRYPTO_DEFLATE; + break; + default: + ZIP_TST_PRT("Fail to set zip alg\n"); + return -EINVAL; + } + + tddata->alg = alg; + tddata->mode = mode; + tddata->optype = optype; + + return 0; +} + +static int init_zip_wd_queue(struct acc_option *options) +{ + struct wd_blkpool_setup blksetup; + struct wd_bd *bds = NULL; + void *pool = NULL; + u32 outsize; + u32 insize; + u8 op_type; + int i, j; + int ret = 0; + + op_type = options->optype % WCRYPTO_DIR_MAX; + if (op_type == WCRYPTO_DEFLATE) {//compress + insize = g_pktlen; + outsize = g_pktlen * COMP_LEN_RATE; + } else { // decompress + insize = g_pktlen; + outsize = g_pktlen * DECOMP_LEN_RATE; + } + + g_thread_queue.bd_res = malloc(g_thread_num * sizeof(struct thread_bd_res)); + if (!g_thread_queue.bd_res) { + ZIP_TST_PRT("malloc thread res memory fail!\n"); + return -ENOMEM; + } + + for (i = 0; i < g_thread_num; i++) { + g_thread_queue.bd_res[i].queue = malloc(sizeof(struct wd_queue)); + g_thread_queue.bd_res[i].queue->capa.alg = options->algclass; + // 0 is compress, 1 is decompress + g_thread_queue.bd_res[i].queue->capa.priv.direction = op_type; + /* nodemask need to be clean */ + g_thread_queue.bd_res[i].queue->node_mask = 0x0; + memset(g_thread_queue.bd_res[i].queue->dev_path, 0x0, PATH_STR_SIZE); + + ret = wd_request_queue(g_thread_queue.bd_res[i].queue); + if (ret) { + ZIP_TST_PRT("request queue %d fail!\n", i); + ret = -EINVAL; + goto queue_out; + } + } + + // use no-sva pbuffer, MAX_BLOCK_NM at least 4 times of MAX_POOL_LENTH + memset(&blksetup, 0, sizeof(blksetup)); + outsize = ALIGN(outsize, ALIGN_SIZE); + blksetup.block_size = outsize; + blksetup.block_num = MAX_BLOCK_NM; + blksetup.align_size = ALIGN_SIZE; + // ZIP_TST_PRT("create pool memory: %d KB\n", (MAX_BLOCK_NM * blksetup.block_size) >> 10); + + for (j = 0; j < g_thread_num; j++) { + g_thread_queue.bd_res[j].pool = wd_blkpool_create(g_thread_queue.bd_res[j].queue, &blksetup); + if (!g_thread_queue.bd_res[j].pool) { + ZIP_TST_PRT("create %dth pool fail!\n", j); + ret = -ENOMEM; + goto pool_err; + } + pool = g_thread_queue.bd_res[j].pool; + + g_thread_queue.bd_res[j].bds = malloc(sizeof(struct wd_bd) * MAX_POOL_LENTH); + if (!g_thread_queue.bd_res[j].bds) + goto bds_error; + bds = g_thread_queue.bd_res[j].bds; + + for (i = 0; i < MAX_POOL_LENTH; i++) { + bds[i].src = wd_alloc_blk(pool); + if (!bds[i].src) { + ret = -ENOMEM; + goto blk_error2; + } + bds[i].src_len = insize; + + bds[i].dst = wd_alloc_blk(pool); + if (!bds[i].dst) { + ret = -ENOMEM; + goto blk_error3; + } + bds[i].dst_len = outsize; + + get_rand_data(bds[i].src, insize); + } + + } + + return 0; + +blk_error3: + wd_free_blk(pool, bds[i].src); +blk_error2: + for (i--; i >= 0; i--) { + wd_free_blk(pool, bds[i].src); + wd_free_blk(pool, bds[i].dst); + } +bds_error: + wd_blkpool_destroy(g_thread_queue.bd_res[j].pool); +pool_err: + for (j--; j >= 0; j--) { + pool = g_thread_queue.bd_res[j].pool; + bds = g_thread_queue.bd_res[j].bds; + for (i = 0; i < MAX_POOL_LENTH; i++) { + wd_free_blk(pool, bds[i].src); + wd_free_blk(pool, bds[i].dst); + } + free(bds); + wd_blkpool_destroy(pool); + } +queue_out: + for (i--; i >= 0; i--) { + wd_release_queue(g_thread_queue.bd_res[i].queue); + free(g_thread_queue.bd_res[i].queue); + } + free(g_thread_queue.bd_res); + return ret; +} + +static void uninit_zip_wd_queue(void) +{ + struct wd_bd *bds = NULL; + void *pool = NULL; + int j, i; + + for (j = 0; j < g_thread_num; j++) { + pool = g_thread_queue.bd_res[j].pool; + bds = g_thread_queue.bd_res[j].bds; + for (i = 0; i < MAX_POOL_LENTH; i++) { + wd_free_blk(pool, bds[i].src); + wd_free_blk(pool, bds[i].dst); + } + + free(bds); + wd_blkpool_destroy(pool); + wd_release_queue(g_thread_queue.bd_res[j].queue); + } + + free(g_thread_queue.bd_res); +} + +/*-------------------------------uadk benchmark main code-------------------------------------*/ +static void zip_lz77_async_cb(const void *message, void *data) +{ + const struct wcrypto_comp_msg *cbmsg = message; + struct zip_async_tag *tag = data; + ZSTD_CCtx *cctx = tag->cctx; + ZSTD_inBuffer zstd_input; + ZSTD_outBuffer zstd_output; + struct wd_bd *bd_pool; + int td_id = tag->td_id; + int idx = tag->bd_idx; + size_t fse_size; + + bd_pool = g_thread_queue.bd_res[td_id].bds; + bd_pool[idx].dst_len = cbmsg->produced; + + zstd_input.src = cbmsg->src; + zstd_input.size = cbmsg->in_size; + zstd_input.pos = 0; + zstd_output.dst = bd_pool[idx].dst; + zstd_output.size = tag->cm_len; + zstd_output.pos = 0; + fse_size = zstd_soft_fse(tag->priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); + + bd_pool[idx].dst_len = fse_size; +} + +static void zip_async_cb(const void *message, void *data) +{ + const struct wcrypto_comp_msg *cbmsg = message; + struct zip_async_tag *tag = data; + struct wd_bd *bd_pool; + int td_id = tag->td_id; + int idx = tag->bd_idx; + + bd_pool = g_thread_queue.bd_res[td_id].bds; + bd_pool[idx].dst_len = cbmsg->produced; +} + +static void *zip_wd_poll(void *data) +{ + thread_data *pdata = (thread_data *)data; + u32 expt = ACC_QUEUE_SIZE * g_thread_num; + struct wd_queue *queue; + u32 id = pdata->td_id; + u32 last_time = 2; // poll need one more recv time + u32 count = 0; + int recv = 0; + + if (id > g_thread_num) + return NULL; + + queue = g_thread_queue.bd_res[id].queue; + while (last_time) { + recv = wcrypto_comp_poll(queue, expt); + if (unlikely(recv != -WD_EAGAIN && recv < 0)) { + ZIP_TST_PRT("poll ret: %u!\n", recv); + goto recv_error; + } + + count += recv; + recv = 0; + + if (get_run_state() == 0) + last_time--; + } + +recv_error: + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *zip_wd_blk_lz77_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + ZSTD_CCtx *cctx = zstd_soft_fse_init(15); + ZSTD_inBuffer zstd_input = {0}; + ZSTD_outBuffer zstd_output = {0}; + COMP_TUPLE_TAG *ftuple = NULL; + struct wcrypto_comp_ctx_setup comp_setup; + struct wcrypto_comp_op_data opdata; + struct wcrypto_comp_ctx *ctx; + struct wd_queue *queue; + struct wd_bd *bd_pool; + u8 *hw_buff_out = NULL; + size_t fse_size; + u32 first_len = 0; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&opdata, 0, sizeof(opdata)); + + comp_setup.br.alloc = (void *)wd_alloc_blk; + comp_setup.br.free = (void *)wd_free_blk; + comp_setup.br.iova_map = (void *)wd_blk_iova_map; + comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + comp_setup.br.get_bufsize = (void *)wd_blksize; + comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WCRYPTO_COMP_L8; + comp_setup.win_size = WCRYPTO_COMP_WS_8K; + comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; + + ctx = wcrypto_create_comp_ctx(queue, &comp_setup); + if (!ctx) + return NULL; + + opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; + opdata.alg_type = pdata->alg; + opdata.priv = NULL; + opdata.status = 0; + if (pdata->optype == WCRYPTO_INFLATE) + opdata.flush = WCRYPTO_SYNC_FLUSH; + else + opdata.flush = WCRYPTO_FINISH; + + out_len = bd_pool[0].dst_len; + + ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); + if (!ftuple) + goto fse_err; + + hw_buff_out = malloc(out_len * MAX_POOL_LENTH); + if (!hw_buff_out) + goto hw_buff_err; + memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); + + while(1) { + i = count % MAX_POOL_LENTH; + opdata.in = bd_pool[i].src; + opdata.out = &hw_buff_out[i]; //temp out + opdata.in_len = bd_pool[i].src_len; + opdata.avail_out = out_len; + opdata.priv = &ftuple[i]; + + ret = wcrypto_do_comp(ctx, &opdata, NULL); + if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || + opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) + break; + + count++; + zstd_input.src = opdata.in; + zstd_input.size = opdata.in_len; + zstd_input.pos = 0; + zstd_output.dst = bd_pool[i].dst; + zstd_output.size = out_len; + zstd_output.pos = 0; + fse_size = zstd_soft_fse(opdata.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); + + bd_pool[i].dst_len = fse_size; + if (unlikely(i == 0)) + first_len = fse_size; + if (get_run_state() == 0) + break; + } + +hw_buff_err: + free(hw_buff_out); +fse_err: + free(ftuple); + wcrypto_del_comp_ctx(ctx); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, opdata.produced); + if (pdata->optype == WCRYPTO_DEFLATE) + add_recv_data(count, opdata.in_len); + else + add_recv_data(count, first_len); + + return NULL; +} + +static void *zip_wd_stm_lz77_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + ZSTD_CCtx *cctx = zstd_soft_fse_init(15); + ZSTD_inBuffer zstd_input = {0}; + ZSTD_outBuffer zstd_output = {0}; + COMP_TUPLE_TAG *ftuple = NULL; + struct wcrypto_comp_ctx_setup comp_setup; + struct wcrypto_comp_op_data opdata; + struct wcrypto_comp_ctx *ctx; + struct wd_queue *queue; + struct wd_bd *bd_pool; + u8 *hw_buff_out = NULL; + size_t fse_size; + u32 first_len = 0; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&opdata, 0, sizeof(opdata)); + + comp_setup.br.alloc = (void *)wd_alloc_blk; + comp_setup.br.free = (void *)wd_free_blk; + comp_setup.br.iova_map = (void *)wd_blk_iova_map; + comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + comp_setup.br.get_bufsize = (void *)wd_blksize; + comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WCRYPTO_COMP_L8; + comp_setup.win_size = WCRYPTO_COMP_WS_8K; + comp_setup.stream_mode = WCRYPTO_COMP_STATEFUL; + + ctx = wcrypto_create_comp_ctx(queue, &comp_setup); + if (!ctx) + return NULL; + + opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; + opdata.alg_type = pdata->alg; + opdata.priv = NULL; + opdata.status = 0; + if (pdata->optype == WCRYPTO_INFLATE) + opdata.flush = WCRYPTO_SYNC_FLUSH; + else + opdata.flush = WCRYPTO_FINISH; + + out_len = bd_pool[0].dst_len; + + ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); + if (!ftuple) + goto fse_err; + + hw_buff_out = malloc(out_len * MAX_POOL_LENTH); + if (!hw_buff_out) + goto hw_buff_err; + memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); + + while(1) { + i = count % MAX_POOL_LENTH; + opdata.in = bd_pool[i].src; + opdata.out = &hw_buff_out[i]; //temp out + opdata.in_len = bd_pool[i].src_len; + opdata.avail_out = out_len; + opdata.priv = &ftuple[i]; + + ret = wcrypto_do_comp(ctx, &opdata, NULL); + if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || + opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { + ZIP_TST_PRT("wd comp, invalid or incomplete data! " + "ret(%d), req.status(%u)\n", ret, opdata.status); + break; + } + + count++; + zstd_input.src = opdata.in; + zstd_input.size = opdata.in_len; + zstd_input.pos = 0; + zstd_output.dst = opdata.out; + zstd_output.size = out_len; + zstd_output.pos = 0; + fse_size = zstd_soft_fse(opdata.priv, &zstd_input, &zstd_output, cctx, ZSTD_e_end); + + bd_pool[i].dst_len = fse_size; + if (unlikely(i == 0)) + first_len = fse_size; + if (get_run_state() == 0) + break; + } + +hw_buff_err: + free(hw_buff_out); +fse_err: + free(ftuple); + wcrypto_del_comp_ctx(ctx); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, opdata.produced); + if (pdata->optype == WCRYPTO_DEFLATE) + add_recv_data(count, opdata.in_len); + else + add_recv_data(count, first_len); + + return NULL; +} + +static void *zip_wd_blk_lz77_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + ZSTD_CCtx *cctx = zstd_soft_fse_init(15); + COMP_TUPLE_TAG *ftuple = NULL; + struct wcrypto_comp_ctx_setup comp_setup; + struct wcrypto_comp_op_data opdata; + struct wcrypto_comp_ctx *ctx; + struct zip_async_tag *tag; + u8 *hw_buff_out = NULL; + struct wd_queue *queue; + struct wd_bd *bd_pool; + u32 out_len = 0; + u32 count = 0; + u32 try_cnt = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&opdata, 0, sizeof(opdata)); + + comp_setup.br.alloc = (void *)wd_alloc_blk; + comp_setup.br.free = (void *)wd_free_blk; + comp_setup.br.iova_map = (void *)wd_blk_iova_map; + comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + comp_setup.br.get_bufsize = (void *)wd_blksize; + comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WCRYPTO_COMP_L8; + comp_setup.win_size = WCRYPTO_COMP_WS_8K; + comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; + comp_setup.cb = zip_lz77_async_cb; + + ctx = wcrypto_create_comp_ctx(queue, &comp_setup); + if (!ctx) + return NULL; + + opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; + opdata.alg_type = pdata->alg; + opdata.priv = NULL; + opdata.status = 0; + if (pdata->optype == WCRYPTO_INFLATE) + opdata.flush = WCRYPTO_SYNC_FLUSH; + else + opdata.flush = WCRYPTO_FINISH; + + out_len = bd_pool[0].dst_len; + + ftuple = malloc(sizeof(COMP_TUPLE_TAG) * MAX_POOL_LENTH); + if (!ftuple) + goto fse_err; + + hw_buff_out = malloc(out_len * MAX_POOL_LENTH); + if (!hw_buff_out) + goto hw_buff_err; + memset(hw_buff_out, 0x0, out_len * MAX_POOL_LENTH); + + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + ZIP_TST_PRT("failed to malloc zip tag!\n"); + goto tag_err; + } + + while(1) { + if (get_run_state() == 0) + break; + + try_cnt = 0; + i = count % MAX_POOL_LENTH; + opdata.in = bd_pool[i].src; + opdata.out = &hw_buff_out[i]; //temp out + opdata.in_len = bd_pool[i].src_len; + opdata.avail_out = out_len; + opdata.priv = &ftuple[i]; + + tag[i].td_id = pdata->td_id; + tag[i].ctx = ctx; + tag[i].td_id = pdata->td_id; + tag[i].cm_len = out_len; + tag[i].cctx = cctx; + tag[i].priv = opdata.priv; + + ret = wcrypto_do_comp(ctx, &opdata, &tag[i]); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + ZIP_TST_PRT("Test LZ77 compress send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || + opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { + break; + } + count++; + } + + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + +tag_err: + free(tag); +hw_buff_err: + free(hw_buff_out); +fse_err: + free(ftuple); + wcrypto_del_comp_ctx(ctx); + + // ZIP_TST_PRT("LZ77 valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, opdata.produced); + + add_send_complete(); + + return NULL; +} + +static void *zip_wd_blk_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_comp_ctx_setup comp_setup; + struct wcrypto_comp_op_data opdata; + struct wcrypto_comp_ctx *ctx; + struct wd_queue *queue; + struct wd_bd *bd_pool; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&opdata, 0, sizeof(opdata)); + + comp_setup.br.alloc = (void *)wd_alloc_blk; + comp_setup.br.free = (void *)wd_free_blk; + comp_setup.br.iova_map = (void *)wd_blk_iova_map; + comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + comp_setup.br.get_bufsize = (void *)wd_blksize; + comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WCRYPTO_COMP_L8; + comp_setup.win_size = WCRYPTO_COMP_WS_8K; + comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; + + ctx = wcrypto_create_comp_ctx(queue, &comp_setup); + if (!ctx) + return NULL; + + opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; + opdata.alg_type = pdata->alg; + opdata.priv = NULL; + opdata.status = 0; + if (pdata->optype == WCRYPTO_INFLATE) + opdata.flush = WCRYPTO_SYNC_FLUSH; + else + opdata.flush = WCRYPTO_FINISH; + + out_len = bd_pool[0].dst_len; + + while(1) { + i = count % MAX_POOL_LENTH; + opdata.in = bd_pool[i].src; + opdata.out = bd_pool[i].dst; + opdata.in_len = bd_pool[i].src_len; + opdata.avail_out = out_len; + + ret = wcrypto_do_comp(ctx, &opdata, NULL); + if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || + opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) + break; + + count++; + bd_pool[i].dst_len = opdata.produced; + if (get_run_state() == 0) + break; + } + wcrypto_del_comp_ctx(ctx); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, opdata.produced); + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *zip_wd_stm_sync_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_comp_ctx_setup comp_setup; + struct wcrypto_comp_op_data opdata; + struct wcrypto_comp_ctx *ctx; + struct wd_queue *queue; + struct wd_bd *bd_pool; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&opdata, 0, sizeof(opdata)); + + comp_setup.br.alloc = (void *)wd_alloc_blk; + comp_setup.br.free = (void *)wd_free_blk; + comp_setup.br.iova_map = (void *)wd_blk_iova_map; + comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + comp_setup.br.get_bufsize = (void *)wd_blksize; + comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WCRYPTO_COMP_L8; + comp_setup.win_size = WCRYPTO_COMP_WS_8K; + comp_setup.stream_mode = WCRYPTO_COMP_STATEFUL; + + ctx = wcrypto_create_comp_ctx(queue, &comp_setup); + if (!ctx) + return NULL; + + opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; + opdata.alg_type = pdata->alg; + opdata.priv = NULL; + opdata.status = 0; + if (pdata->optype == WCRYPTO_INFLATE) + opdata.flush = WCRYPTO_SYNC_FLUSH; + else + opdata.flush = WCRYPTO_FINISH; + + out_len = bd_pool[0].dst_len; + + while(1) { + i = count % MAX_POOL_LENTH; + opdata.in = bd_pool[i].src; + opdata.out = bd_pool[i].dst; + opdata.in_len = bd_pool[i].src_len; + opdata.avail_out = out_len; + + ret = wcrypto_do_comp(ctx, &opdata, NULL); + if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || + opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { + ZIP_TST_PRT("wd comp, invalid or incomplete data! " + "ret(%d), req.status(%u)\n", ret, opdata.status); + break; + } + + count++; + bd_pool[i].dst_len = opdata.produced; + if (get_run_state() == 0) + break; + } + wcrypto_del_comp_ctx(ctx); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, opdata.produced); + add_recv_data(count, g_pktlen); + + return NULL; + +} + +static void *zip_wd_blk_async_run(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_comp_ctx_setup comp_setup; + struct wcrypto_comp_op_data opdata; + struct wcrypto_comp_ctx *ctx; + struct zip_async_tag *tag; + struct wd_queue *queue; + struct wd_bd *bd_pool; + int try_cnt = 0; + u32 out_len = 0; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_pool = g_thread_queue.bd_res[pdata->td_id].bds; + queue = g_thread_queue.bd_res[pdata->td_id].queue; + memset(&comp_setup, 0, sizeof(comp_setup)); + memset(&opdata, 0, sizeof(opdata)); + + comp_setup.br.alloc = (void *)wd_alloc_blk; + comp_setup.br.free = (void *)wd_free_blk; + comp_setup.br.iova_map = (void *)wd_blk_iova_map; + comp_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + comp_setup.br.get_bufsize = (void *)wd_blksize; + comp_setup.br.usr = g_thread_queue.bd_res[pdata->td_id].pool; + + comp_setup.alg_type = pdata->alg; + comp_setup.op_type = pdata->optype; + comp_setup.comp_lv = WCRYPTO_COMP_L8; + comp_setup.win_size = WCRYPTO_COMP_WS_8K; + comp_setup.stream_mode = WCRYPTO_COMP_STATELESS; + comp_setup.cb = zip_async_cb; + + ctx = wcrypto_create_comp_ctx(queue, &comp_setup); + if (!ctx) + return NULL; + + opdata.stream_pos = WCRYPTO_COMP_STREAM_NEW; + opdata.alg_type = pdata->alg; + opdata.priv = NULL; + opdata.status = 0; + if (pdata->optype == WCRYPTO_INFLATE) + opdata.flush = WCRYPTO_SYNC_FLUSH; + else + opdata.flush = WCRYPTO_FINISH; + + out_len = bd_pool[0].dst_len; + tag = malloc(sizeof(*tag) * MAX_POOL_LENTH); + if (!tag) { + ZIP_TST_PRT("failed to malloc zip tag!\n"); + goto tag_release; + } + + while(1) { + if (get_run_state() == 0) + break; + + i = count % MAX_POOL_LENTH; + opdata.in = bd_pool[i].src; + opdata.out = bd_pool[i].dst; + opdata.in_len = bd_pool[i].src_len; + opdata.avail_out = out_len; + + try_cnt = 0; + tag[i].ctx = ctx; + tag[i].td_id = pdata->td_id; + tag[i].bd_idx = i; + + ret = wcrypto_do_comp(ctx, &opdata, &tag[i]); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + ZIP_TST_PRT("Test compress send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } else if (ret || opdata.status == WCRYPTO_DECOMP_END_NOSPACE || + opdata.status == WD_IN_EPARA || opdata.status == WD_VERIFY_ERR) { + break; + } + + count++; + } + + while (1) { + if (get_recv_time() > 0) // wait Async mode finish recv + break; + usleep(SEND_USLEEP); + } + +tag_release: + free(tag); + wcrypto_del_comp_ctx(ctx); + + // ZIP_TST_PRT("valid pool len: %u, send count BD: %u, output len: %u!\n", + // MAX_POOL_LENTH, count, opdata.produced); + + add_send_complete(); + + return NULL; +} + +static int zip_wd_sync_threads(struct acc_option *options) +{ + typedef void *(*zip_sync_run)(void *arg); + zip_sync_run wd_zip_sync_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + ret = zip_wd_param_parse(&threads_option, options); + if (ret) + return ret; + + if (threads_option.mode == 1) {// stream mode + if (threads_option.alg == LZ77_ZSTD) + wd_zip_sync_run = zip_wd_stm_lz77_sync_run; + else + wd_zip_sync_run = zip_wd_stm_sync_run; + } else { + if (threads_option.alg == LZ77_ZSTD) + wd_zip_sync_run = zip_wd_blk_lz77_sync_run; + else + wd_zip_sync_run = zip_wd_blk_sync_run; + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].alg = threads_option.alg; + threads_args[i].mode = threads_option.mode; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, wd_zip_sync_run, &threads_args[i]); + if (ret) { + ZIP_TST_PRT("Create sync thread fail!\n"); + goto sync_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + ZIP_TST_PRT("Join sync thread fail!\n"); + goto sync_error; + } + } + +sync_error: + return ret; +} + +static int zip_wd_async_threads(struct acc_option *options) +{ + typedef void *(*zip_async_run)(void *arg); + zip_async_run wd_zip_async_run = NULL; + thread_data threads_args[THREADS_NUM]; + thread_data threads_option; + pthread_t tdid[THREADS_NUM]; + pthread_t pollid[THREADS_NUM]; + int i, ret; + + /* alg param parse and set to thread data */ + ret = zip_wd_param_parse(&threads_option, options); + if (ret) + return ret; + + if (threads_option.mode == STREAM_MODE) {// stream mode + ZIP_TST_PRT("Stream mode can't support async mode!\n"); + return 0; + } + + if (threads_option.alg == LZ77_ZSTD) + wd_zip_async_run = zip_wd_blk_lz77_async_run; + else + wd_zip_async_run = zip_wd_blk_async_run; + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].td_id = i; + /* poll thread */ + ret = pthread_create(&pollid[i], NULL, zip_wd_poll, &threads_args[i]); + if (ret) { + ZIP_TST_PRT("Create poll thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_thread_num; i++) { + threads_args[i].alg = threads_option.alg; + threads_args[i].mode = threads_option.mode; + threads_args[i].optype = threads_option.optype; + threads_args[i].td_id = i; + ret = pthread_create(&tdid[i], NULL, wd_zip_async_run, &threads_args[i]); + if (ret) { + ZIP_TST_PRT("Create async thread fail!\n"); + goto async_error; + } + } + + /* join thread */ + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(tdid[i], NULL); + if (ret) { + ZIP_TST_PRT("Join async thread fail!\n"); + goto async_error; + } + } + + for (i = 0; i < g_thread_num; i++) { + ret = pthread_join(pollid[i], NULL); + if (ret) { + ZIP_TST_PRT("Join poll thread fail!\n"); + goto async_error; + } + } + +async_error: + return ret; +} + +int zip_wd_benchmark(struct acc_option *options) +{ + u32 ptime; + int ret; + + g_thread_num = options->threads; + g_pktlen = options->pktlen; + + if (options->optype >= WCRYPTO_DIR_MAX * 2) { + ZIP_TST_PRT("ZIP optype error: %u\n", options->optype); + return -EINVAL; + } + + ret = init_zip_wd_queue(options); + if (ret) + return ret; + + ret = load_file_data(options->algname, options->pktlen, options->optype); + if (ret) + return ret; + + get_pid_cpu_time(&ptime); + time_start(options->times); + if (options->syncmode) + ret = zip_wd_async_threads(options); + else + ret = zip_wd_sync_threads(options); + cal_perfermance_data(options, ptime); + if (ret) + return ret; + + ret = save_file_data(options->algname, options->pktlen, options->optype); + if (ret) + return ret; + + uninit_zip_wd_queue(); + + return 0; +} diff --git a/uadk_tool/benchmark/zip_wd_benchmark.h b/uadk_tool/benchmark/zip_wd_benchmark.h new file mode 100644 index 0000000..86ef497 --- /dev/null +++ b/uadk_tool/benchmark/zip_wd_benchmark.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +#ifndef ZIP_WD_BENCHMARK_H +#define ZIP_WD_BENCHMARK_H + +extern int zip_wd_benchmark(struct acc_option *options); +#endif /* ZIP_WD_BENCHMARK_H */
Turn on the test function of HPRE and ZIP modules.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- uadk_tool/Makefile.am | 18 ++++++++++++++---- uadk_tool/benchmark/uadk_benchmark.c | 22 +++++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/uadk_tool/Makefile.am b/uadk_tool/Makefile.am index f04b2f0..3f451b6 100644 --- a/uadk_tool/Makefile.am +++ b/uadk_tool/Makefile.am @@ -8,25 +8,35 @@ AM_CFLAGS=-Wall -fno-strict-aliasing -I$(top_srcdir) -I$(top_srcdir)/benchmark/i bin_PROGRAMS=uadk_tool
uadk_tool_SOURCES=uadk_tool.c dfx/uadk_dfx.c dfx/uadk_dfx.h \ - benchmark/uadk_benchmark.c benchmark/uadk_benchmark.h \ - benchmark/sec_uadk_benchmark.c benchmark/sec_uadk_benchmark.h \ - benchmark/sec_wd_benchmark.c benchmark/sec_wd_benchmark.h + benchmark/uadk_benchmark.c benchmark/uadk_benchmark.h \ + benchmark/sec_uadk_benchmark.c benchmark/sec_uadk_benchmark.h \ + benchmark/sec_wd_benchmark.c benchmark/sec_wd_benchmark.h \ + benchmark/hpre_uadk_benchmark.c benchmark/hpre_uadk_benchmark.h \ + benchmark/hpre_wd_benchmark.c hpre_wd_benchmark.h \ + benchmark/zip_uadk_benchmark.c benchmark/zip_uadk_benchmark.h \ + benchmark/zip_wd_benchmark.c benchmark/zip_wd_benchmark.h
if WD_STATIC_DRV AM_CFLAGS+=-Bstatic uadk_tool_LDADD=$(libwd_la_OBJECTS) \ $(libwd_crypto_la_OBJECTS) \ + ../.libs/libwd_comp.a \ ../.libs/libhisi_sec.a \ ../.libs/libhisi_hpre.a \ ../.libs/libhisi_zip.a \ -ldl -lnuma else uadk_tool_LDADD=-L../.libs -l:libwd.so.2 -l:libwd_crypto.so.2 \ - -lnuma + -l:libwd_comp.so.2 -lnuma endif
uadk_tool_LDFLAGS=-Wl,-rpath,'/usr/local/lib'
+if WITH_ZLIB_FSE_DIR +AM_CFLAGS += -DZLIB_FSE +uadk_tool_LDADD+= $(with_zlib_fse_dir)/libfse.a +endif + if WITH_OPENSSL_DIR AM_CFLAGS+= -DWITH_OPENSSL_DIR -I$(with_openssl_dir)/include
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 2904cba..d3b9ef3 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -8,7 +8,12 @@ #include "sec_wd_benchmark.h" #include "sec_soft_benchmark.h"
-#define BYTES_TO_KB 10 +#include "hpre_uadk_benchmark.h" +#include "hpre_wd_benchmark.h" + +#include "zip_uadk_benchmark.h" +#include "zip_wd_benchmark.h" + #define TABLE_SPACE_SIZE 8
/*----------------------------------------head struct--------------------------------------------------------*/ @@ -424,8 +429,18 @@ static int benchmark_run(struct acc_option *option) #endif break; case HPRE_TYPE: + if (option->modetype & SVA_MODE) { + ret = hpre_uadk_benchmark(option); + } else if (option->modetype & NOSVA_MODE) { + ret = hpre_wd_benchmark(option); + } break; case ZIP_TYPE: + if (option->modetype & SVA_MODE) { + ret = zip_uadk_benchmark(option); + } else if (option->modetype & NOSVA_MODE) { + ret = zip_wd_benchmark(option); + } break; }
@@ -546,8 +561,9 @@ static void print_help(void) 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(" [--sync/--async]: start asynchronous/synchronous mode test\n"); - ACC_TST_PRT(" [--optype 0/1]:\n"); - ACC_TST_PRT(" encryption/decryption or compression/decompression\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"); + ACC_TST_PRT(" HPRE: 0~5:keygen, key compute, Enc, Dec, Sign, Verify\n"); ACC_TST_PRT(" [--pktlen]:\n"); ACC_TST_PRT(" set the length of BD message in bytes\n"); ACC_TST_PRT(" [--seconds]:\n");