Support AES-CBC CTS mode in uadk v1. Support user self-defined data in uadk v1. Sync and add test code for new features.
Longfang Liu (5): uadk_tool: Optimize sec's sva benchmark code uadk_tool: Optimize sec's software benchmark code uadk_tool: Optimize sec's no-sva benchmark code uadk_tool: add latency test function for uadk_tools uadk_tool: Update test function for init2
Zhiqi Song (3): uadk/v1/cipher: support aes-cbc cts mode uadk_tool: support test case for aes cbc cts mode uadk/v1/cipher: support user self-defined data functions
uadk_tool/benchmark/hpre_uadk_benchmark.c | 3 + uadk_tool/benchmark/hpre_wd_benchmark.c | 3 + uadk_tool/benchmark/sec_soft_benchmark.c | 794 +++++++++++------ uadk_tool/benchmark/sec_uadk_benchmark.c | 734 ++++++++++------ uadk_tool/benchmark/sec_wd_benchmark.c | 989 +++++++++++++--------- uadk_tool/benchmark/uadk_benchmark.c | 158 +++- uadk_tool/benchmark/uadk_benchmark.h | 35 +- uadk_tool/benchmark/zip_uadk_benchmark.c | 12 +- uadk_tool/benchmark/zip_wd_benchmark.c | 12 +- v1/drv/hisi_sec_udrv.c | 253 +++++- v1/drv/hisi_sec_udrv.h | 6 + v1/wd_cipher.c | 7 +- v1/wd_cipher.h | 4 + 13 files changed, 2037 insertions(+), 973 deletions(-)
Support AES-CBC CTS(ciphertext stealing) mode in v1, including CBC-CS1, CBC-CS2, CBC-CS3.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- v1/drv/hisi_sec_udrv.c | 100 ++++++++++++++++++++++++++++++++++++++--- v1/drv/hisi_sec_udrv.h | 6 +++ v1/wd_cipher.c | 3 ++ v1/wd_cipher.h | 4 ++ 4 files changed, 106 insertions(+), 7 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index 32bded4..f73fc8f 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -179,6 +179,18 @@ static int fill_cipher_bd2_mode(struct wcrypto_cipher_msg *msg, case WCRYPTO_CIPHER_XTS: sqe->type2.c_mode = C_MODE_XTS; break; + case WCRYPTO_CIPHER_CBC_CS1: + sqe->type2.c_mode = C_MODE_CBC_CS; + sqe->type2.c_width = C_WIDTH_CS1; + break; + case WCRYPTO_CIPHER_CBC_CS2: + sqe->type2.c_mode = C_MODE_CBC_CS; + sqe->type2.c_width = C_WIDTH_CS2; + break; + case WCRYPTO_CIPHER_CBC_CS3: + sqe->type2.c_mode = C_MODE_CBC_CS; + sqe->type2.c_width = C_WIDTH_CS3; + break; default: WD_ERR("Invalid cipher alg type!\n"); ret = -WD_EINVAL; @@ -253,6 +265,9 @@ static void update_iv(struct wcrypto_cipher_msg *msg) { switch (msg->mode) { case WCRYPTO_CIPHER_CBC: + case WCRYPTO_CIPHER_CBC_CS1: + case WCRYPTO_CIPHER_CBC_CS2: + case WCRYPTO_CIPHER_CBC_CS3: if (msg->op_type == WCRYPTO_CIPHER_ENCRYPTION && msg->out_bytes >= msg->iv_bytes) update_iv_from_res(msg->iv, msg->out, @@ -360,6 +375,18 @@ static int fill_cipher_bd1_mode(struct wcrypto_cipher_msg *msg, case WCRYPTO_CIPHER_XTS: sqe->type1.c_mode = C_MODE_XTS; break; + case WCRYPTO_CIPHER_CBC_CS1: + sqe->type1.c_mode = C_MODE_CBC_CS; + sqe->type1.c_width = C_WIDTH_CS1; + break; + case WCRYPTO_CIPHER_CBC_CS2: + sqe->type1.c_mode = C_MODE_CBC_CS; + sqe->type1.c_width = C_WIDTH_CS2; + break; + case WCRYPTO_CIPHER_CBC_CS3: + sqe->type1.c_mode = C_MODE_CBC_CS; + sqe->type1.c_width = C_WIDTH_CS3; + break; default: WD_ERR("Invalid cipher alg type for bd1\n"); return -WD_EINVAL; @@ -587,8 +614,32 @@ map_in_error: return ret; }
+static int aes_sm4_param_check(struct wcrypto_cipher_msg *msg) +{ + if (msg->alg == WCRYPTO_CIPHER_AES && + msg->in_bytes <= CBC_AES_BLOCK_SIZE && + (msg->mode == WCRYPTO_CIPHER_CBC_CS1 || + msg->mode == WCRYPTO_CIPHER_CBC_CS2 || + msg->mode == WCRYPTO_CIPHER_CBC_CS3)) { + WD_ERR("failed to check input bytes of AES CTS, size = %u\n", + msg->in_bytes); + return -WD_EINVAL; + } + + if ((msg->in_bytes & (CBC_AES_BLOCK_SIZE - 1)) && + (msg->mode == WCRYPTO_CIPHER_CBC || + msg->mode == WCRYPTO_CIPHER_ECB)) { + WD_ERR("input AES or SM4 cipher parameter is error!\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; +} + static int cipher_param_check(struct wcrypto_cipher_msg *msg) { + int ret; + if (unlikely(msg->in_bytes > MAX_CIPHER_LENGTH || !msg->in_bytes)) { WD_ERR("input cipher len is too large!\n"); @@ -616,10 +667,9 @@ static int cipher_param_check(struct wcrypto_cipher_msg *msg) }
if (msg->alg == WCRYPTO_CIPHER_AES || msg->alg == WCRYPTO_CIPHER_SM4) { - if (unlikely(msg->in_bytes & (CBC_AES_BLOCK_SIZE - 1))) { - WD_ERR("input AES or SM4 cipher parameter is error!\n"); - return -WD_EINVAL; - } + ret = aes_sm4_param_check(msg); + if (ret) + return ret; }
return WD_SUCCESS; @@ -793,6 +843,18 @@ static int fill_cipher_bd3_mode(struct wcrypto_cipher_msg *msg, case WCRYPTO_CIPHER_CFB: sqe->c_mode = C_MODE_CFB; break; + case WCRYPTO_CIPHER_CBC_CS1: + sqe->c_mode = C_MODE_CBC_CS; + sqe->c_width = C_WIDTH_CS1; + break; + case WCRYPTO_CIPHER_CBC_CS2: + sqe->c_mode = C_MODE_CBC_CS; + sqe->c_width = C_WIDTH_CS2; + break; + case WCRYPTO_CIPHER_CBC_CS3: + sqe->c_mode = C_MODE_CBC_CS; + sqe->c_width = C_WIDTH_CS3; + break; default: WD_ERR("Invalid cipher alg type!\n"); ret = -WD_EINVAL; @@ -843,7 +905,7 @@ static int fill_cipher_bd3(struct wd_queue *q, struct hisi_sec_bd3_sqe *sqe, return ret; }
-static int sm4_aes_mode_check(int mode) +static int sm4_mode_check(int mode) { switch (mode) { case WCRYPTO_CIPHER_ECB: @@ -860,6 +922,26 @@ static int sm4_aes_mode_check(int mode) } }
+static int aes_mode_check(int mode) +{ + switch (mode) { + case WCRYPTO_CIPHER_ECB: + case WCRYPTO_CIPHER_CBC: + case WCRYPTO_CIPHER_OFB: + case WCRYPTO_CIPHER_CFB: + case WCRYPTO_CIPHER_CTR: + case WCRYPTO_CIPHER_XTS: + case WCRYPTO_CIPHER_CCM: + case WCRYPTO_CIPHER_GCM: + case WCRYPTO_CIPHER_CBC_CS1: + case WCRYPTO_CIPHER_CBC_CS2: + case WCRYPTO_CIPHER_CBC_CS3: + return WD_SUCCESS; + default: + return -WD_EINVAL; + } +} + static int triple_des_mode_check(int mode) { switch (mode) { @@ -878,8 +960,10 @@ static int cipher_comb_param_check(struct wcrypto_cipher_msg *msg)
switch (msg->alg) { case WCRYPTO_CIPHER_SM4: + ret = sm4_mode_check(msg->mode); + break; case WCRYPTO_CIPHER_AES: - ret = sm4_aes_mode_check(msg->mode); + ret = aes_mode_check(msg->mode); break; case WCRYPTO_CIPHER_DES: case WCRYPTO_CIPHER_3DES: @@ -2213,8 +2297,10 @@ static int aead_comb_param_check(struct wcrypto_aead_msg *msg)
switch (msg->calg) { case WCRYPTO_CIPHER_SM4: + ret = sm4_mode_check(msg->cmode); + break; case WCRYPTO_CIPHER_AES: - ret = sm4_aes_mode_check(msg->cmode); + ret = aes_mode_check(msg->cmode); break; default: return -WD_EINVAL; diff --git a/v1/drv/hisi_sec_udrv.h b/v1/drv/hisi_sec_udrv.h index af96a76..9db4af8 100644 --- a/v1/drv/hisi_sec_udrv.h +++ b/v1/drv/hisi_sec_udrv.h @@ -461,6 +461,12 @@ enum C_MODE { C_MODE_CBC_CS = 0x9 };
+enum SEC_C_WIDTH { + C_WIDTH_CS1 = 0x1, + C_WIDTH_CS2 = 0x2, + C_WIDTH_CS3 = 0x3, +}; + enum CKEY_LEN { CKEY_LEN_128_BIT = 0x0, CKEY_LEN_192_BIT = 0x1, diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index 6c0ef69..1b50089 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -83,6 +83,9 @@ static __u32 get_iv_block_size(int alg, int mode)
switch (mode) { case WCRYPTO_CIPHER_CBC: + case WCRYPTO_CIPHER_CBC_CS1: + case WCRYPTO_CIPHER_CBC_CS2: + case WCRYPTO_CIPHER_CBC_CS3: case WCRYPTO_CIPHER_OFB: if (alg == WCRYPTO_CIPHER_3DES || alg == WCRYPTO_CIPHER_DES) diff --git a/v1/wd_cipher.h b/v1/wd_cipher.h index 591a590..dafd8a4 100644 --- a/v1/wd_cipher.h +++ b/v1/wd_cipher.h @@ -47,6 +47,10 @@ enum wcrypto_cipher_mode { WCRYPTO_CIPHER_CFB, WCRYPTO_CIPHER_CCM, WCRYPTO_CIPHER_GCM, + WCRYPTO_CIPHER_CBC_CS1, + WCRYPTO_CIPHER_CBC_CS2, + WCRYPTO_CIPHER_CBC_CS3, + WCRYPTO_CIPHER_MODE_MAX, };
/**
From: Longfang Liu liulongfang@huawei.com
Update the performance test code of sec's sva mode, and optimize the performance test code of sec's sva mode by splitting sub-functions.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/sec_uadk_benchmark.c | 677 ++++++++++++++--------- 1 file changed, 411 insertions(+), 266 deletions(-)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 09cd8f4..11cf8a1 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -24,9 +24,10 @@ struct bd_pool {
struct thread_pool { struct bd_pool *pool; - u8 *iv; - u8 *key; - u8 *mac; + u8 **iv; + u8 **key; + u8 **mac; + u8 **hash; } g_uadk_pool;
typedef struct uadk_thread_res { @@ -37,6 +38,9 @@ typedef struct uadk_thread_res { u32 ivsize; u32 optype; u32 td_id; + bool is_union; + u32 dalg; + u32 dmode; } thread_data;
static struct wd_ctx_config g_ctx_cfg; @@ -601,20 +605,15 @@ recv_error: return NULL; }
-static void *sec_uadk_async_run(void *arg) +static void *sec_uadk_cipher_async(void *arg) { thread_data *pdata = (thread_data *)arg; struct wd_cipher_sess_setup cipher_setup = {0}; - struct wd_aead_sess_setup aead_setup = {0}; - struct wd_digest_sess_setup digest_setup = {0}; struct wd_cipher_req creq; - struct wd_aead_req areq; - struct wd_digest_req dreq; struct bd_pool *uadk_pool; - u8 *priv_iv, *priv_key, *priv_mac; + u8 *priv_iv, *priv_key; int try_cnt = 0; handle_t h_sess; - u32 auth_size = 16; u32 count = 0; int ret, i = 0;
@@ -622,313 +621,431 @@ static void *sec_uadk_async_run(void *arg) return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id]; - priv_iv = &g_uadk_pool.iv[pdata->td_id]; - priv_key = &g_uadk_pool.key[pdata->td_id]; - priv_mac = &g_uadk_pool.mac[pdata->td_id]; + priv_iv = g_uadk_pool.iv[pdata->td_id]; + priv_key = g_uadk_pool.key[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) { - case CIPHER_TYPE: - cipher_setup.alg = pdata->alg; - cipher_setup.mode = pdata->mode; - h_sess = wd_cipher_alloc_sess(&cipher_setup); - if (!h_sess) - return NULL; - ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize); - if (ret) { - SEC_TST_PRT("test sec cipher set key is failed!\n"); - wd_cipher_free_sess(h_sess); - return NULL; - } + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; + h_sess = wd_cipher_alloc_sess(&cipher_setup); + if (!h_sess) + return NULL; + ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize); + if (ret) { + SEC_TST_PRT("test sec cipher set key is failed!\n"); + wd_cipher_free_sess(h_sess); + return NULL; + }
- creq.op_type = pdata->optype; - creq.iv = priv_iv; - creq.iv_bytes = pdata->ivsize; - creq.in_bytes = g_pktlen; - creq.out_bytes = g_pktlen; - creq.out_buf_bytes = g_pktlen; - creq.data_fmt = 0; - creq.state = 0; - creq.cb = cipher_async_cb; - - 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; - - ret = wd_do_cipher_async(h_sess, &creq); - if (ret < 0) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; + creq.op_type = pdata->optype; + creq.iv = priv_iv; + creq.iv_bytes = pdata->ivsize; + creq.in_bytes = g_pktlen; + creq.out_bytes = g_pktlen; + creq.out_buf_bytes = g_pktlen; + creq.data_fmt = 0; + creq.state = 0; + creq.cb = cipher_async_cb; + + 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; + + ret = wd_do_cipher_async(h_sess, &creq); + if (ret < 0) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } - count++; + continue; } - wd_cipher_free_sess(h_sess); - break; - case AEAD_TYPE: // just ccm and gcm - aead_setup.calg = pdata->alg; - aead_setup.cmode = pdata->mode; - h_sess = wd_aead_alloc_sess(&aead_setup); - if (!h_sess) - return NULL; - ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize); - if (ret) { - SEC_TST_PRT("test sec cipher set key is failed!\n"); - wd_aead_free_sess(h_sess); - return NULL; - } - ret = wd_aead_set_authsize(h_sess, auth_size); + count++; + } + wd_cipher_free_sess(h_sess); + + add_send_complete(); + + return NULL; +} + +static void *sec_uadk_aead_async(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_aead_sess_setup aead_setup = {0}; + u8 *priv_iv, *priv_key, *priv_mac, *priv_hash; + struct wd_aead_req areq; + struct bd_pool *uadk_pool; + int try_cnt = 0; + handle_t h_sess; + u32 auth_size = 16; + u32 count = 0; + int ret, i; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_uadk_pool.pool[pdata->td_id]; + priv_iv = g_uadk_pool.iv[pdata->td_id]; + priv_key = g_uadk_pool.key[pdata->td_id]; + priv_hash = g_uadk_pool.hash[pdata->td_id]; + priv_mac = g_uadk_pool.mac[pdata->td_id]; + + memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; + if (pdata->is_union) { + aead_setup.dalg = pdata->dalg; + aead_setup.dmode = pdata->dmode; + } + h_sess = wd_aead_alloc_sess(&aead_setup); + if (!h_sess) + return NULL; + ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize); + if (ret) { + SEC_TST_PRT("test sec cipher set key is failed!\n"); + wd_aead_free_sess(h_sess); + return NULL; + } + if (pdata->is_union) { + ret = wd_aead_set_akey(h_sess, (const __u8*)priv_hash, 16); if (ret) { - SEC_TST_PRT("set auth size fail, authsize: 16\n"); + SEC_TST_PRT("test sec aead set akey is failed!\n"); wd_aead_free_sess(h_sess); return NULL; } + } + ret = wd_aead_set_authsize(h_sess, auth_size); + if (ret) { + SEC_TST_PRT("set auth size fail, authsize: 16\n"); + wd_aead_free_sess(h_sess); + return NULL; + } + + areq.op_type = pdata->optype; + areq.iv = priv_iv; // aead IV need update with param + areq.mac = priv_mac; + areq.iv_bytes = pdata->ivsize; + areq.mac_bytes = auth_size; + areq.assoc_bytes = 16; + areq.in_bytes = g_pktlen; + if (pdata->is_union) + areq.mac_bytes = 32; + if (areq.op_type) // decrypto + areq.out_bytes = g_pktlen + 16; // aadsize = 16; + else + areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32;
- areq.op_type = pdata->optype; - areq.iv = priv_iv; // aead IV need update with param - areq.mac = priv_mac; - areq.iv_bytes = pdata->ivsize; - areq.mac_bytes = auth_size; - areq.assoc_bytes = 16; - areq.in_bytes = g_pktlen; - if (areq.op_type)// decrypto - areq.out_bytes = g_pktlen + 16; // aadsize = 16; - else - areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32; - - areq.data_fmt = 0; - areq.state = 0; - areq.cb = aead_async_cb; - - while(1) { - if (get_run_state() == 0) - break; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - areq.src = uadk_pool->bds[i].src; - areq.dst = uadk_pool->bds[i].dst; - - ret = wd_do_aead_async(h_sess, &areq); - if (ret < 0) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; + areq.data_fmt = 0; + areq.state = 0; + areq.cb = aead_async_cb; + + while(1) { + if (get_run_state() == 0) + break; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + areq.src = uadk_pool->bds[i].src; + areq.dst = uadk_pool->bds[i].dst; + + ret = wd_do_aead_async(h_sess, &areq); + if (ret < 0) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } - count++; + continue; } - wd_aead_free_sess(h_sess); - break; - case DIGEST_TYPE: - digest_setup.alg = pdata->alg; - digest_setup.mode = pdata->mode; // digest mode is optype - h_sess = wd_digest_alloc_sess(&digest_setup); - if (!h_sess) + count++; + } + wd_aead_free_sess(h_sess); + + add_send_complete(); + + return NULL; +} + +static void *sec_uadk_digest_async(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_digest_sess_setup digest_setup = {0}; + struct wd_digest_req dreq; + struct bd_pool *uadk_pool; + u8 *priv_iv, *priv_key; + int try_cnt = 0; + handle_t h_sess; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_uadk_pool.pool[pdata->td_id]; + priv_iv = g_uadk_pool.iv[pdata->td_id]; + priv_key = g_uadk_pool.key[pdata->td_id]; + + memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; // digest mode is optype + h_sess = wd_digest_alloc_sess(&digest_setup); + if (!h_sess) + return NULL; + if (digest_setup.mode == WD_DIGEST_HMAC) { + ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4); + if (ret) { + SEC_TST_PRT("test sec_digest set key is failed!\n"); + wd_digest_free_sess(h_sess); return NULL; - if (digest_setup.mode == WD_DIGEST_HMAC) { - ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4); - if (ret) { - SEC_TST_PRT("test sec digest set key is failed!\n"); - wd_digest_free_sess(h_sess); - return NULL; - } } - dreq.in_bytes = g_pktlen; - dreq.out_bytes = 16; - dreq.out_buf_bytes = 16; - dreq.data_fmt = 0; - dreq.state = 0; - dreq.has_next = 0; - dreq.cb = digest_async_cb; - - while(1) { - if (get_run_state() == 0) - break; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - dreq.in = uadk_pool->bds[i].src; - dreq.out = uadk_pool->bds[i].dst; - - ret = wd_do_digest_async(h_sess, &dreq); - if (ret < 0) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; + } + dreq.in_bytes = g_pktlen; + dreq.out_bytes = 16; + dreq.out_buf_bytes = 16; + dreq.data_fmt = 0; + dreq.state = 0; + dreq.has_next = 0; + dreq.cb = digest_async_cb; + + while(1) { + if (get_run_state() == 0) + break; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + dreq.in = uadk_pool->bds[i].src; + dreq.out = uadk_pool->bds[i].dst; + + ret = wd_do_digest_async(h_sess, &dreq); + if (ret < 0) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } - count++; + continue; } - wd_digest_free_sess(h_sess); - break; + count++; } + wd_digest_free_sess(h_sess);
add_send_complete();
return NULL; }
-static void *sec_uadk_sync_run(void *arg) +static void *sec_uadk_cipher_sync(void *arg) { thread_data *pdata = (thread_data *)arg; struct wd_cipher_sess_setup cipher_setup = {0}; - struct wd_aead_sess_setup aead_setup = {0}; - struct wd_digest_sess_setup digest_setup = {0}; struct wd_cipher_req creq; + struct bd_pool *uadk_pool; + u8 *priv_iv, *priv_key; + handle_t h_sess; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_uadk_pool.pool[pdata->td_id]; + priv_iv = g_uadk_pool.iv[pdata->td_id]; + priv_key = g_uadk_pool.key[pdata->td_id]; + + memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; + h_sess = wd_cipher_alloc_sess(&cipher_setup); + if (!h_sess) + return NULL; + ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize); + if (ret) { + SEC_TST_PRT("test sec cipher set key is failed!\n"); + wd_cipher_free_sess(h_sess); + return NULL; + } + + creq.op_type = pdata->optype; + creq.iv = priv_iv; + creq.iv_bytes = pdata->ivsize; + creq.in_bytes = g_pktlen; + creq.out_bytes = g_pktlen; + creq.out_buf_bytes = g_pktlen; + creq.data_fmt = 0; + creq.state = 0; + + while(1) { + i = count % MAX_POOL_LENTH; + creq.src = uadk_pool->bds[i].src; + creq.dst = uadk_pool->bds[i].dst; + ret = wd_do_cipher_sync(h_sess, &creq); + if ((ret < 0 && ret != -WD_EBUSY) || creq.state) + break; + count++; + if (get_run_state() == 0) + break; + } + wd_cipher_free_sess(h_sess); + + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *sec_uadk_aead_sync(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_aead_sess_setup aead_setup = {0}; + u8 *priv_iv, *priv_key, *priv_hash, *priv_mac; struct wd_aead_req areq; - struct wd_digest_req dreq; struct bd_pool *uadk_pool; - u8 *priv_iv, *priv_key, *priv_mac; handle_t h_sess; u32 auth_size = 16; u32 count = 0; - int ret, i = 0; + int ret, i;
if (pdata->td_id > g_thread_num) return NULL;
uadk_pool = &g_uadk_pool.pool[pdata->td_id]; - priv_iv = &g_uadk_pool.iv[pdata->td_id]; - priv_key = &g_uadk_pool.key[pdata->td_id]; - priv_mac = &g_uadk_pool.mac[pdata->td_id]; + + priv_iv = g_uadk_pool.iv[pdata->td_id]; + priv_key = g_uadk_pool.key[pdata->td_id]; + priv_hash = g_uadk_pool.hash[pdata->td_id]; + priv_mac = g_uadk_pool.mac[pdata->td_id];
memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) { - case CIPHER_TYPE: - cipher_setup.alg = pdata->alg; - cipher_setup.mode = pdata->mode; - h_sess = wd_cipher_alloc_sess(&cipher_setup); - if (!h_sess) - return NULL; - ret = wd_cipher_set_key(h_sess, (const __u8*)priv_key, pdata->keysize); - if (ret) { - SEC_TST_PRT("test sec cipher set key is failed!\n"); - wd_cipher_free_sess(h_sess); - return NULL; - } + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; + h_sess = wd_aead_alloc_sess(&aead_setup); + if (!h_sess) + return NULL; + ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize); + if (ret) { + SEC_TST_PRT("test sec cipher set key is failed!\n"); + wd_aead_free_sess(h_sess); + return NULL; + }
- creq.op_type = pdata->optype; - creq.iv = priv_iv; - creq.iv_bytes = pdata->ivsize; - creq.in_bytes = g_pktlen; - creq.out_bytes = g_pktlen; - creq.out_buf_bytes = g_pktlen; - creq.data_fmt = 0; - creq.state = 0; - - while(1) { - i = count % MAX_POOL_LENTH; - creq.src = uadk_pool->bds[i].src; - creq.dst = uadk_pool->bds[i].dst; - ret = wd_do_cipher_sync(h_sess, &creq); - if ((ret < 0 && ret != -WD_EBUSY) || creq.state) - break; - count++; - if (get_run_state() == 0) - break; - } - wd_cipher_free_sess(h_sess); - break; - case AEAD_TYPE: // just ccm and gcm - aead_setup.calg = pdata->alg; - aead_setup.cmode = pdata->mode; - h_sess = wd_aead_alloc_sess(&aead_setup); - if (!h_sess) - return NULL; - ret = wd_aead_set_ckey(h_sess, (const __u8*)priv_key, pdata->keysize); + if (pdata->is_union) { + ret = wd_aead_set_akey(h_sess, (const __u8*)priv_hash, 16); if (ret) { - SEC_TST_PRT("test sec cipher set key is failed!\n"); - wd_aead_free_sess(h_sess); - return NULL; - } - ret = wd_aead_set_authsize(h_sess, auth_size); - if (ret) { - SEC_TST_PRT("set auth size fail, authsize: 16\n"); + SEC_TST_PRT("test sec aead set akey is failed!\n"); wd_aead_free_sess(h_sess); return NULL; } + }
- areq.op_type = pdata->optype; - areq.iv = priv_iv; // aead IV need update with param - areq.mac = priv_mac; - areq.mac_bytes = 16; - areq.iv_bytes = pdata->ivsize; - areq.assoc_bytes = 16; - areq.in_bytes = g_pktlen; - areq.mac_bytes = auth_size; - if (areq.op_type)// decrypto - areq.out_bytes = g_pktlen + 16; // aadsize = 16; - else - areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32; - - areq.data_fmt = 0; - areq.state = 0; - - while(1) { - i = count % MAX_POOL_LENTH; - areq.src = uadk_pool->bds[i].src; - areq.dst = uadk_pool->bds[i].dst; - count++; - ret = wd_do_aead_sync(h_sess, &areq); - if (ret || areq.state) - break; - if (get_run_state() == 0) - break; - } + ret = wd_aead_set_authsize(h_sess, auth_size); + if (ret) { + SEC_TST_PRT("set auth size fail, authsize: 16\n"); wd_aead_free_sess(h_sess); - break; - case DIGEST_TYPE: - digest_setup.alg = pdata->alg; - digest_setup.mode = pdata->mode; // digest mode is optype - h_sess = wd_digest_alloc_sess(&digest_setup); - if (!h_sess) + return NULL; + } + + areq.op_type = pdata->optype; + areq.iv = priv_iv; // aead IV need update with param + areq.mac = priv_mac; + areq.mac_bytes = 16; + areq.iv_bytes = pdata->ivsize; + areq.assoc_bytes = 16; + areq.in_bytes = g_pktlen; + areq.mac_bytes = auth_size; + if (areq.op_type)// decrypto + areq.out_bytes = g_pktlen + 16; // aadsize = 16; + else + areq.out_bytes = g_pktlen + 32; // aadsize + authsize = 32; + + areq.data_fmt = 0; + areq.state = 0; + + while(1) { + i = count % MAX_POOL_LENTH; + areq.src = uadk_pool->bds[i].src; + areq.dst = uadk_pool->bds[i].dst; + count++; + ret = wd_do_aead_sync(h_sess, &areq); + if (ret || areq.state) + break; + if (get_run_state() == 0) + break; + } + wd_aead_free_sess(h_sess); + + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *sec_uadk_digest_sync(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wd_digest_sess_setup digest_setup = {0}; + struct wd_digest_req dreq; + struct bd_pool *uadk_pool; + u8 *priv_iv, *priv_key; + handle_t h_sess; + u32 count = 0; + int ret, i = 0; + + if (pdata->td_id > g_thread_num) + return NULL; + + uadk_pool = &g_uadk_pool.pool[pdata->td_id]; + priv_iv = g_uadk_pool.iv[pdata->td_id]; + priv_key = g_uadk_pool.key[pdata->td_id]; + + memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; // digest mode is optype + h_sess = wd_digest_alloc_sess(&digest_setup); + if (!h_sess) + return NULL; + if (digest_setup.mode == WD_DIGEST_HMAC) { + ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4); + if (ret) { + SEC_TST_PRT("test sec digest set key is failed!\n"); + wd_digest_free_sess(h_sess); return NULL; - if (digest_setup.mode == WD_DIGEST_HMAC) { - ret = wd_digest_set_key(h_sess, (const __u8*)priv_key, 4); - if (ret) { - SEC_TST_PRT("test sec digest set key is failed!\n"); - wd_digest_free_sess(h_sess); - return NULL; - } - } - dreq.in_bytes = g_pktlen; - dreq.out_bytes = 16; - dreq.out_buf_bytes = 16; - dreq.data_fmt = 0; - dreq.state = 0; - dreq.has_next = 0; - - while(1) { - i = count % MAX_POOL_LENTH; - dreq.in = uadk_pool->bds[i].src; - dreq.out = uadk_pool->bds[i].dst; - ret = wd_do_digest_sync(h_sess, &dreq); - if (ret || dreq.state) - break; - count++; - if (get_run_state() == 0) - break; } - wd_digest_free_sess(h_sess); - break; } + dreq.in_bytes = g_pktlen; + dreq.out_bytes = 16; + dreq.out_buf_bytes = 16; + dreq.data_fmt = 0; + dreq.state = 0; + dreq.has_next = 0; + + while(1) { + i = count % MAX_POOL_LENTH; + dreq.in = uadk_pool->bds[i].src; + dreq.out = uadk_pool->bds[i].dst; + ret = wd_do_digest_sync(h_sess, &dreq); + if (ret || dreq.state) + break; + count++; + if (get_run_state() == 0) + break; + } + wd_digest_free_sess(h_sess);
add_recv_data(count, g_pktlen);
@@ -937,6 +1054,8 @@ static void *sec_uadk_sync_run(void *arg)
int sec_uadk_sync_threads(struct acc_option *options) { + typedef void *(*sec_sync_run)(void *arg); + sec_sync_run uadk_sec_sync_run = NULL; thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; @@ -947,6 +1066,18 @@ int sec_uadk_sync_threads(struct acc_option *options) if (ret) return ret;
+ switch (options->subtype) { + case CIPHER_TYPE: + uadk_sec_sync_run = sec_uadk_cipher_sync; + break; + case AEAD_TYPE: + uadk_sec_sync_run = sec_uadk_aead_sync; + break; + case DIGEST_TYPE: + uadk_sec_sync_run = sec_uadk_digest_sync; + break; + } + for (i = 0; i < g_thread_num; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].alg = threads_option.alg; @@ -955,7 +1086,7 @@ int sec_uadk_sync_threads(struct acc_option *options) threads_args[i].ivsize = threads_option.ivsize; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; - ret = pthread_create(&tdid[i], NULL, sec_uadk_sync_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, uadk_sec_sync_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create sync thread fail!\n"); goto sync_error; @@ -977,6 +1108,8 @@ sync_error:
int sec_uadk_async_threads(struct acc_option *options) { + typedef void *(*sec_async_run)(void *arg); + sec_async_run uadk_sec_async_run = NULL; thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; @@ -988,6 +1121,18 @@ int sec_uadk_async_threads(struct acc_option *options) if (ret) return ret;
+ switch (options->subtype) { + case CIPHER_TYPE: + uadk_sec_async_run = sec_uadk_cipher_async; + break; + case AEAD_TYPE: + uadk_sec_async_run = sec_uadk_aead_async; + break; + case DIGEST_TYPE: + uadk_sec_async_run = sec_uadk_digest_async; + break; + } + for (i = 0; i < g_ctxnum; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].td_id = i; @@ -1007,7 +1152,7 @@ int sec_uadk_async_threads(struct acc_option *options) threads_args[i].ivsize = threads_option.ivsize; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; - ret = pthread_create(&tdid[i], NULL, sec_uadk_async_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, uadk_sec_async_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create async thread fail!\n"); goto async_error;
From: Longfang Liu liulongfang@huawei.com
Update the performance test code of sec's software mode, and optimize the performance test code of sec's software mode by splitting sub-functions.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/sec_soft_benchmark.c | 790 +++++++++++++++-------- 1 file changed, 517 insertions(+), 273 deletions(-)
diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c index a622329..c7870aa 100644 --- a/uadk_tool/benchmark/sec_soft_benchmark.c +++ b/uadk_tool/benchmark/sec_soft_benchmark.c @@ -36,17 +36,20 @@ struct thread_pool { typedef struct soft_thread_res { const EVP_CIPHER *evp_cipher; const EVP_MD *evp_md; + ENGINE *engine; u32 subtype; u32 mode; u32 keysize; u32 optype; u32 td_id; u32 engine_flag; + u32 sync_mode; } soft_thread;
typedef struct soft_jobs_res { const EVP_CIPHER *evp_cipher; const EVP_MD *evp_md; + ENGINE *engine; u32 subtype; u32 mode; u32 keysize; @@ -56,12 +59,20 @@ typedef struct soft_jobs_res { u32 use_engine; } jobs_data;
+typedef struct soft_loop_args { + ASYNC_JOB *in_job; + ASYNC_WAIT_CTX *wait_ctx; + bool job_valid; +} jobs_args; + #define MAX_IVK_LENTH 64 #define DEF_IVK_DATA 0xAA +#define MAX_JOBS_NUM MAX_CTX_NUM
static unsigned int g_thread_num; static unsigned int g_ctxnum; static unsigned int g_pktlen; +static unsigned int g_jobsnum;
static int init_soft_bd_pool(void) { @@ -396,25 +407,18 @@ static int sec_soft_param_parse(soft_thread *tddata, struct acc_option *options) return 0; }
-static int sec_soft_jobfunc(void *args) +static int sec_soft_cipher_jobfunc(void *args) { jobs_data *jdata = (jobs_data *)args; const EVP_CIPHER *evp_cipher = jdata->evp_cipher; - const EVP_MD *evp_md = jdata->evp_md; u32 optype = jdata->optype; u32 jid = jdata->jobid; struct bd_pool *soft_pool; u8 *priv_iv, *priv_key; int ret, outl, i = 0; EVP_CIPHER_CTX *ctx; - EVP_MD_CTX *md_ctx; - HMAC_CTX *hm_ctx; ASYNC_JOB *currjob; - u8 faketag[16] = {0xcc}; - u8 aad[13] = {0xcc}; - u8 tag[12] = {0}; - u8 mac[EVP_MAX_MD_SIZE] = {0x00}; - u32 ssl_size = 0; + u32 count = 0; u8 *src, *dst;
currjob = ASYNC_get_current_job(); @@ -423,7 +427,7 @@ static int sec_soft_jobfunc(void *args) return 0; }
- if (!evp_cipher && !evp_md) { + if (!evp_cipher) { SSL_TST_PRT("Error: openssl not support!\n"); return 0; } @@ -438,54 +442,110 @@ static int sec_soft_jobfunc(void *args) memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(jdata->subtype) { - case CIPHER_TYPE: - ctx = EVP_CIPHER_CTX_new(); - if (!ctx) - return 0; - - EVP_CIPHER_CTX_set_padding(ctx, 0); + ctx = EVP_CIPHER_CTX_new(); + if (!ctx) + return 0;
- ret = EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); - if (ret != 1) { - SSL_TST_PRT("Error: EVP_CipherInit_ex fail ret: %d\n", ret); - break; - } + EVP_CIPHER_CTX_init(ctx);
+ while (1) { i = jid % MAX_POOL_LENTH; src = soft_pool->bds[i].src; dst = soft_pool->bds[i].dst; - if (optype) - ret = EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); - else - ret = EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen); - if (ret != 1) - EVP_CipherInit_ex(ctx, NULL, NULL, NULL, priv_iv, -1);
- if (optype) + if (optype) { + ret = EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); + if (ret != 1) { + SSL_TST_PRT("Error: EVP_CipherInit_ex fail ret: %d\n", ret); + break; + } + + ret = EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); + if (ret != 1) + break; + EVP_CIPHER_CTX_set_padding(ctx, 0); EVP_DecryptFinal_ex(ctx, dst, &outl); - else + } else { + ret = EVP_EncryptInit_ex(ctx, evp_cipher, jdata->engine, priv_key, priv_iv); + if (ret != 1) + break; + + ret = EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen); + if (ret != 1) + break; + EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO); EVP_EncryptFinal_ex(ctx, dst, &outl); + }
- EVP_CIPHER_CTX_free(ctx); - break; - case AEAD_TYPE: - ctx = EVP_CIPHER_CTX_new(); - if (!ctx) - return 0; + count++; + if (get_run_state() == 0) + break; + }
- EVP_CIPHER_CTX_set_padding(ctx, 0); + EVP_CIPHER_CTX_cleanup(ctx); + EVP_CIPHER_CTX_free(ctx);
- ret = EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); - if (ret != 1) { - SSL_TST_PRT("Error: AEAD EVP_CipherInit_ex fail ret: %d\n", ret); - break; - } + add_recv_data(count, g_pktlen);
+ return 0; +} + +static int sec_soft_aead_jobfunc(void *args) +{ + jobs_data *jdata = (jobs_data *)args; + const EVP_CIPHER *evp_cipher = jdata->evp_cipher; + u32 optype = jdata->optype; + u32 jid = jdata->jobid; + struct bd_pool *soft_pool; + u8 *priv_iv, *priv_key; + int ret, outl, i = 0; + EVP_CIPHER_CTX *ctx; + ASYNC_JOB *currjob; + u8 faketag[16] = {0xcc}; + u8 aad[13] = {0xcc}; + u8 tag[12] = {0}; + u32 count = 0; + u8 *src, *dst; + + currjob = ASYNC_get_current_job(); + if (!currjob) { + SSL_TST_PRT("Error: not executing within a job\n"); + return 0; + } + + if (!evp_cipher) { + SSL_TST_PRT("Error: openssl not support!\n"); + return 0; + } + + if (jdata->td_id > g_thread_num) + return 0; + + soft_pool = &g_soft_pool.pool[jdata->td_id]; + priv_iv = &g_soft_pool.iv[jdata->td_id]; + priv_key = &g_soft_pool.key[jdata->td_id]; + + memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + ctx = EVP_CIPHER_CTX_new(); + if (!ctx) + return 0; + + EVP_CIPHER_CTX_set_padding(ctx, 0); + + ret = EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); + if (ret != 1) { + SSL_TST_PRT("Error: AEAD EVP_CipherInit_ex fail ret: %d\n", ret); + return 0; + } + + while (1) { if (jdata->mode == WD_CIPHER_CCM) { i = jid % MAX_POOL_LENTH; src = soft_pool->bds[i].src; dst = soft_pool->bds[i].dst; + if (optype) { EVP_CIPHER_CTX_ctrl(ctx, 0x11, sizeof(tag), tag); /* reset iv */ @@ -508,8 +568,7 @@ static int sec_soft_jobfunc(void *args) dst = soft_pool->bds[i].dst; if (optype) { EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, priv_iv); - EVP_CIPHER_CTX_ctrl(ctx, 0x11, - sizeof(faketag), tag); + EVP_CIPHER_CTX_ctrl(ctx, 0x11, sizeof(faketag), tag); EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); EVP_DecryptFinal_ex(ctx, dst + outl, &outl); @@ -520,53 +579,105 @@ static int sec_soft_jobfunc(void *args) EVP_DecryptFinal_ex(ctx, dst + outl, &outl); } } - EVP_CIPHER_CTX_free(ctx); + count++; + if (get_run_state() == 0) + break; + } + EVP_CIPHER_CTX_free(ctx);
- break; - case DIGEST_TYPE: - if (!optype) { //normal mode - md_ctx = EVP_MD_CTX_new(); - if (!md_ctx) - return 0; + add_recv_data(count, g_pktlen); + + return 0; +} + +static int sec_soft_digest_jobfunc(void *args) +{ + jobs_data *jdata = (jobs_data *)args; + const EVP_MD *evp_md = jdata->evp_md; + u32 optype = jdata->optype; + u32 jid = jdata->jobid; + struct bd_pool *soft_pool; + u8 mac[EVP_MAX_MD_SIZE] = {0x00}; + EVP_MD_CTX *md_ctx; + HMAC_CTX *hm_ctx; + ASYNC_JOB *currjob; + u32 ssl_size = 0; + u8 *priv_key, *src; + u32 count = 0; + int i = 0; + + currjob = ASYNC_get_current_job(); + if (!currjob) { + SSL_TST_PRT("Error: not executing within a job\n"); + return 0; + } + + if (!evp_md) { + SSL_TST_PRT("Error: openssl not support!\n"); + return 0; + } + + if (jdata->td_id > g_thread_num) + return 0; + + soft_pool = &g_soft_pool.pool[jdata->td_id]; + priv_key = &g_soft_pool.key[jdata->td_id];
+ memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + if (!optype) { //normal mode + md_ctx = EVP_MD_CTX_new(); + if (!md_ctx) + return 0; + + while (1) { i = jid % MAX_POOL_LENTH; src = soft_pool->bds[i].src;
EVP_DigestInit_ex(md_ctx, evp_md, NULL); EVP_DigestUpdate(md_ctx, src, g_pktlen); EVP_DigestFinal_ex(md_ctx, mac, &ssl_size); - // EVP_Digest(src, g_pktlen, mac, &ssl_size, evp_md, NULL);
+ count++; + if (get_run_state() == 0) + break; + } EVP_MD_CTX_free(md_ctx); - } else { //hmac mode - hm_ctx = HMAC_CTX_new(); - if (!hm_ctx) - return 0; - + } else { //hmac mode + hm_ctx = HMAC_CTX_new(); + if (!hm_ctx) + return 0; + while (1) { i = jid % MAX_POOL_LENTH; src = soft_pool->bds[i].src;
HMAC_Init_ex(hm_ctx, priv_key, jdata->keysize, evp_md, NULL); HMAC_Update(hm_ctx, src, g_pktlen); HMAC_Final(hm_ctx, mac, &ssl_size); - // HMAC(evp_md, priv_key, jdata->keysize, src, g_pktlen, mac, &ssl_size);
- HMAC_CTX_free(hm_ctx); + count++; + if (get_run_state() == 0) + break; } - break; + HMAC_CTX_free(hm_ctx); } - return 0; }
static void *sec_soft_async_run(void *arg) { + typedef int (*sec_soft_run)(void *arg); + sec_soft_run sec_soft_jobfunc = NULL; soft_thread *pdata = (soft_thread *)arg; - ASYNC_WAIT_CTX *waitctx = NULL; - ASYNC_JOB *job = NULL; - int ret, jobret = 0; + jobs_args loop_jobs[MAX_JOBS_NUM]; + OSSL_ASYNC_FD waitfd = 0; jobs_data jobdata; - u32 count = 0; + fd_set waitfdset; + size_t numfds = 0; + int i, j, k, ret; + int jobret = 0; + u32 valid_jobs = 0; + u32 jobs_num;
jobdata.evp_cipher = pdata->evp_cipher; jobdata.evp_md = pdata->evp_md; @@ -575,31 +686,177 @@ static void *sec_soft_async_run(void *arg) jobdata.optype = pdata->optype; jobdata.subtype = pdata->subtype; jobdata.td_id = pdata->td_id; + jobdata.engine = pdata->engine;
- waitctx = ASYNC_WAIT_CTX_new(); - if (!waitctx) { - SSL_TST_PRT("Error: create ASYNC_WAIT_CTX failed\n"); + jobs_num = g_jobsnum; + if (jobs_num > MAX_JOBS_NUM) { + SSL_TST_PRT("Error: check async jobs num failed.\n"); return NULL; } + memset(loop_jobs, 0x0, sizeof(jobs_args) * MAX_JOBS_NUM);
- while (1) { - jobdata.jobid = count; - ret = ASYNC_start_job(&job, waitctx, &jobret, sec_soft_jobfunc, - (void *)&jobdata, sizeof(jobs_data)); + switch (pdata->subtype) { + case CIPHER_TYPE: + sec_soft_jobfunc = sec_soft_cipher_jobfunc; + break; + case AEAD_TYPE: + sec_soft_jobfunc = sec_soft_aead_jobfunc; + break; + case DIGEST_TYPE: + sec_soft_jobfunc = sec_soft_digest_jobfunc; + break; + } + + /* one thread for one job */ + for (i = 0; i < jobs_num; i++) { + loop_jobs[i].wait_ctx = ASYNC_WAIT_CTX_new(); + if (!loop_jobs[i].wait_ctx) { + SSL_TST_PRT("Error: create ASYNC_WAIT_CTX failed\n"); + goto async_error; + } + + jobdata.jobid = i; + ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret, + sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data)); switch(ret) { case ASYNC_ERR: - SSL_TST_PRT("Error: start soft async job err. \n"); - goto exit_pause; + SSL_TST_PRT("Error: start soft async job err.\n"); + break; case ASYNC_NO_JOBS: - SSL_TST_PRT("Error: can't get soft async job from job pool. \n"); - goto exit_pause; + SSL_TST_PRT("Error: can't get soft async job from job pool.\n"); + break; case ASYNC_PAUSE: - SSL_TST_PRT("Info: job was paused \n"); + loop_jobs[i].job_valid = true; + valid_jobs++; break; case ASYNC_FINISH: break; default: - SSL_TST_PRT("Error: do soft async job err. \n"); + SSL_TST_PRT("Error: do soft async job err.\n"); + } + } + + j = valid_jobs; + while (j > 0) { + for (i = 0; i < jobs_num; i++) { + FD_ZERO(&waitfdset); + if (!loop_jobs[i].job_valid) + continue; + + /* Wait for the job to be woken */ + if (!ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, NULL, &numfds) || + numfds > 1) { + SSL_TST_PRT("Error: unexpected number of fds.\n"); + continue; + } + ASYNC_WAIT_CTX_get_all_fds(loop_jobs[i].wait_ctx, &waitfd, &numfds); + FD_SET(waitfd, &waitfdset); + + ret = select(waitfd + 1, &waitfdset, NULL, NULL, NULL); + if (ret == -1) { + SSL_TST_PRT("Error: select soft async job error.\n"); + goto async_finish; + } else if (ret == 0 || (ret == -1 && errno == EINTR)) { + SSL_TST_PRT("Infor: select soft async job result continue.\n"); + continue; + } + + jobdata.jobid = i; + ret = ASYNC_start_job(&loop_jobs[i].in_job, loop_jobs[i].wait_ctx, &jobret, + sec_soft_jobfunc, (void *)&jobdata, sizeof(jobs_data)); + switch(ret) { + case ASYNC_ERR: + loop_jobs[i].job_valid = false; + j--; + SSL_TST_PRT("Error: restart soft async job err.\n"); + break; + case ASYNC_NO_JOBS: + SSL_TST_PRT("Error: can't get soft async job from job pool.\n"); + break; + case ASYNC_PAUSE: + break; + case ASYNC_FINISH: + loop_jobs[i].job_valid = false; + j--; + break; + default: + SSL_TST_PRT("Error: do soft async job err.\n"); + } + } + } + +async_finish: + i = jobs_num; +async_error: + for (k = 0; k < i; k++) + ASYNC_WAIT_CTX_free(loop_jobs[k].wait_ctx); + + add_send_complete(); + + return NULL; +} + +static void *sec_soft_cipher_sync(void *arg) +{ + soft_thread *pdata = (soft_thread *)arg; + const EVP_CIPHER *evp_cipher = pdata->evp_cipher; + u32 optype = pdata->optype; + struct bd_pool *soft_pool; + u8 *priv_iv, *priv_key; + EVP_CIPHER_CTX *ctx = NULL; + u32 count = 0; + u8 *src, *dst; + int ret, i = 0; + int outl = 0; + + if (!evp_cipher) { + SSL_TST_PRT("Error: openssl not support!\n"); + return NULL; + } + + if (pdata->td_id > g_thread_num) + return NULL; + + soft_pool = &g_soft_pool.pool[pdata->td_id]; + priv_iv = &g_soft_pool.iv[pdata->td_id]; + priv_key = &g_soft_pool.key[pdata->td_id]; + + memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + ctx = EVP_CIPHER_CTX_new(); + if (!ctx) + return NULL; + + EVP_CIPHER_CTX_init(ctx); + + while (1) { + i = count % MAX_POOL_LENTH; + src = soft_pool->bds[i].src; + dst = soft_pool->bds[i].dst; + + if (optype) { + ret = EVP_DecryptInit_ex(ctx, evp_cipher, pdata->engine, priv_key, priv_iv); + if (ret != 1) + break; + + ret = EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); + if (ret != 1) + break; + + EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO); + EVP_DecryptFinal_ex(ctx, dst, &outl); + } else { + ret = EVP_EncryptInit_ex(ctx, evp_cipher, pdata->engine, priv_key, priv_iv); + if (ret != 1) + break; + + ret = EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen); + if (ret != 1) + break; + + EVP_CIPHER_CTX_set_padding(ctx, EVP_PADDING_ZERO); + EVP_EncryptFinal_ex(ctx, dst, &outl); }
count++; @@ -607,36 +864,31 @@ static void *sec_soft_async_run(void *arg) break; }
-exit_pause: - ASYNC_WAIT_CTX_free(waitctx); + EVP_CIPHER_CTX_cleanup(ctx); + EVP_CIPHER_CTX_free(ctx);
add_recv_data(count, g_pktlen);
return NULL; }
-static void *sec_soft_sync_run(void *arg) +static void *sec_soft_aead_sync(void *arg) { soft_thread *pdata = (soft_thread *)arg; const EVP_CIPHER *evp_cipher = pdata->evp_cipher; - const EVP_MD *evp_md = pdata->evp_md; u32 optype = pdata->optype; - u8 mac[EVP_MAX_MD_SIZE] = {0x00}; struct bd_pool *soft_pool; u8 *priv_iv, *priv_key; EVP_CIPHER_CTX *ctx = NULL; - EVP_MD_CTX *md_ctx = NULL; - HMAC_CTX *hm_ctx = NULL; u8 faketag[16] = {0xcc}; u8 aad[13] = {0xcc}; u8 tag[12] = {0}; - u32 ssl_size = 0; u32 count = 0; u8 *src, *dst; int ret, i = 0; int outl = 0;
- if (!evp_cipher && !evp_md) { + if (!evp_cipher) { SSL_TST_PRT("Error: openssl not support!\n"); return NULL; } @@ -651,14 +903,13 @@ static void *sec_soft_sync_run(void *arg) memset(priv_iv, DEF_IVK_DATA, MAX_IVK_LENTH); memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) { - case CIPHER_TYPE: - ctx = EVP_CIPHER_CTX_new(); - if (!ctx) - return NULL; + ctx = EVP_CIPHER_CTX_new(); + if (!ctx) + return NULL;
- EVP_CIPHER_CTX_set_padding(ctx, 0); + EVP_CIPHER_CTX_set_padding(ctx, 0);
+ if (pdata->mode == WD_CIPHER_CCM) { while (1) { i = count % MAX_POOL_LENTH; src = soft_pool->bds[i].src; @@ -682,130 +933,168 @@ static void *sec_soft_sync_run(void *arg) if (get_run_state() == 0) break; } + } else { + while (1) { + i = count % MAX_POOL_LENTH; + src = soft_pool->bds[i].src; + dst = soft_pool->bds[i].dst;
- EVP_CIPHER_CTX_free(ctx); + (void)EVP_CipherInit_ex(ctx, evp_cipher, pdata->engine, priv_key, priv_iv, optype);
- break; - case AEAD_TYPE: - ctx = EVP_CIPHER_CTX_new(); - if (!ctx) + if (optype) { + EVP_DecryptInit_ex(ctx, NULL, pdata->engine, NULL, priv_iv); + EVP_CIPHER_CTX_ctrl(ctx, 0x11, sizeof(faketag), tag); + EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); + EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); + ret = EVP_DecryptFinal_ex(ctx, dst + outl, &outl); + } else { + EVP_DecryptInit_ex(ctx, NULL, pdata->engine, NULL, priv_iv); + EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); + EVP_EncryptUpdate(ctx, NULL, &outl, NULL, g_pktlen); + ret = EVP_DecryptFinal_ex(ctx, dst + outl, &outl); + } + if (ret != 1) + EVP_CipherInit_ex(ctx, evp_cipher, pdata->engine, priv_key, priv_iv, optype); + + count++; + if (get_run_state() == 0) + break; + } + } + EVP_CIPHER_CTX_free(ctx); + + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *sec_soft_digest_sync(void *arg) +{ + soft_thread *pdata = (soft_thread *)arg; + const EVP_CIPHER *evp_cipher = pdata->evp_cipher; + const EVP_MD *evp_md = pdata->evp_md; + u32 optype = pdata->optype; + u8 mac[EVP_MAX_MD_SIZE] = {0x00}; + struct bd_pool *soft_pool; + EVP_MD_CTX *md_ctx = NULL; + HMAC_CTX *hm_ctx = NULL; + u8 *priv_key, *src; + u32 ssl_size = 0; + u32 count = 0; + int i = 0; + + if (!evp_cipher && !evp_md) { + SSL_TST_PRT("Error: openssl not support!\n"); + return NULL; + } + + if (pdata->td_id > g_thread_num) + return NULL; + + soft_pool = &g_soft_pool.pool[pdata->td_id]; + priv_key = &g_soft_pool.key[pdata->td_id]; + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + if (!optype) { + md_ctx = EVP_MD_CTX_new(); + if (!md_ctx) return NULL;
- EVP_CIPHER_CTX_set_padding(ctx, 0); - - if (pdata->mode == WD_CIPHER_CCM) { - while (1) { - i = count % MAX_POOL_LENTH; - src = soft_pool->bds[i].src; - dst = soft_pool->bds[i].dst; - - (void)EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); - - if (optype) { - EVP_CIPHER_CTX_ctrl(ctx, 0x11, sizeof(tag), tag); - /* reset iv */ - EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, priv_iv); - ret = EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); - } else { - /* restore iv length field */ - EVP_EncryptUpdate(ctx, NULL, &outl, NULL, g_pktlen); - /* counter is reset on every update */ - ret = EVP_EncryptUpdate(ctx, dst, &outl, src, g_pktlen); - } - if (ret != 1) - EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); - - if (optype) - EVP_DecryptFinal_ex(ctx, dst, &outl); - else - EVP_EncryptFinal_ex(ctx, dst, &outl); - - count++; - if (get_run_state() == 0) - break; - } - } else { - while (1) { - i = count % MAX_POOL_LENTH; - src = soft_pool->bds[i].src; - dst = soft_pool->bds[i].dst; - - (void)EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); - - if (optype) { - EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, priv_iv); - EVP_CIPHER_CTX_ctrl(ctx, 0x11, - sizeof(faketag), tag); - EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); - EVP_DecryptUpdate(ctx, dst, &outl, src, g_pktlen); - ret = EVP_DecryptFinal_ex(ctx, dst + outl, &outl); - } else { - EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, priv_iv); - EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); - EVP_EncryptUpdate(ctx, NULL, &outl, NULL, g_pktlen); - ret = EVP_DecryptFinal_ex(ctx, dst + outl, &outl); - } - if (ret != 1) - EVP_CipherInit_ex(ctx, evp_cipher, NULL, priv_key, priv_iv, optype); - - count++; - if (get_run_state() == 0) - break; - } + while (1) { + i = count % MAX_POOL_LENTH; + src = soft_pool->bds[i].src; + + EVP_DigestInit_ex(md_ctx, evp_md, NULL); + EVP_DigestUpdate(md_ctx, src, g_pktlen); + EVP_DigestFinal_ex(md_ctx, mac, &ssl_size); + + count++; + if (get_run_state() == 0) + break; } - EVP_CIPHER_CTX_free(ctx); + EVP_MD_CTX_free(md_ctx); + } else { //hmac mode + hm_ctx = HMAC_CTX_new(); + if (!hm_ctx) + return NULL; + + while (1) { + i = count % MAX_POOL_LENTH; + src = soft_pool->bds[i].src; + + HMAC_Init_ex(hm_ctx, priv_key, pdata->keysize, evp_md, NULL); + HMAC_Update(hm_ctx, src, g_pktlen); + HMAC_Final(hm_ctx, mac, &ssl_size); + + count++; + if (get_run_state() == 0) + break; + } + HMAC_CTX_free(hm_ctx); + } + add_recv_data(count, g_pktlen); + + return NULL; +} + +static int uadk_engine_register(soft_thread *options, char *engine_name) +{ + if (!options->engine_flag) + return 0; + + ERR_load_ENGINE_strings(); + OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL);
+ options->engine = ENGINE_by_id(engine_name); + if (!options->engine) { + SSL_TST_PRT("setup uadk engine failed!\n"); + return -EINVAL; + } + + ENGINE_init(options->engine); + switch(options->subtype) { + case CIPHER_TYPE: + ENGINE_register_ciphers(options->engine); break; + case AEAD_TYPE: + SSL_TST_PRT("Openssl not support AEAD ALG!\n"); + return -EINVAL; case DIGEST_TYPE: - if (!optype) { //normal mode - md_ctx = EVP_MD_CTX_new(); - if (!md_ctx) - return NULL; - - while (1) { - i = count % MAX_POOL_LENTH; - src = soft_pool->bds[i].src; - - EVP_DigestInit_ex(md_ctx, evp_md, NULL); - EVP_DigestUpdate(md_ctx, src, g_pktlen); - EVP_DigestFinal_ex(md_ctx, mac, &ssl_size); - // EVP_Digest(src, g_pktlen, mac, &ssl_size, evp_md, NULL); - - count++; - if (get_run_state() == 0) - break; - } - EVP_MD_CTX_free(md_ctx); - } else { //hmac mode - hm_ctx = HMAC_CTX_new(); - if (!hm_ctx) - return NULL; - - while (1) { - i = count % MAX_POOL_LENTH; - src = soft_pool->bds[i].src; - - HMAC_Init_ex(hm_ctx, priv_key, pdata->keysize, evp_md, NULL); - HMAC_Update(hm_ctx, src, g_pktlen); - HMAC_Final(hm_ctx, mac, &ssl_size); - // HMAC(evp_md, priv_key, pdata->keysize, src, g_pktlen, mac, &ssl_size); - - count++; - if (get_run_state() == 0) - break; - } - HMAC_CTX_free(hm_ctx); - } + ENGINE_register_digests(options->engine); break; + default: + return -EINVAL; } + ENGINE_free(options->engine);
- add_recv_data(count, g_pktlen); + return 0; +}
- return NULL; +static void uadk_engine_unregister(soft_thread *options) +{ + if (!options->engine_flag) + return; + + switch(options->subtype) { + case CIPHER_TYPE: + ENGINE_unregister_ciphers(options->engine); + break; + case AEAD_TYPE: + // ENGINE_unregister_ciphers(e); //openssl not support aead + break; + case DIGEST_TYPE: + ENGINE_unregister_digests(options->engine); + break; + default: + return; + } + ENGINE_free(options->engine); }
int sec_soft_sync_threads(struct acc_option *options) { + typedef void *(*sec_sync_run)(void *arg); + sec_sync_run soft_sec_sync_run = NULL; soft_thread threads_args[THREADS_NUM]; soft_thread threads_option; pthread_t tdid[THREADS_NUM]; @@ -816,6 +1105,24 @@ int sec_soft_sync_threads(struct acc_option *options) if (ret) return ret;
+ threads_option.engine_flag = options->engine_flag; + threads_option.sync_mode = options->syncmode; + ret = uadk_engine_register(&threads_option, options->engine); + if (ret) + return ret; + + switch (options->subtype) { + case CIPHER_TYPE: + soft_sec_sync_run = sec_soft_cipher_sync; + break; + case AEAD_TYPE: + soft_sec_sync_run = sec_soft_aead_sync; + break; + case DIGEST_TYPE: + soft_sec_sync_run = sec_soft_digest_sync; + break; + } + for (i = 0; i < g_thread_num; i++) { threads_args[i].evp_cipher = threads_option.evp_cipher; threads_args[i].evp_md = threads_option.evp_md; @@ -825,7 +1132,7 @@ int sec_soft_sync_threads(struct acc_option *options) threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; threads_args[i].engine_flag = options->engine_flag; - ret = pthread_create(&tdid[i], NULL, sec_soft_sync_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, soft_sec_sync_run, &threads_args[i]); if (ret) { SSL_TST_PRT("Create sync thread fail!\n"); goto sync_error; @@ -842,8 +1149,8 @@ int sec_soft_sync_threads(struct acc_option *options) }
sync_error: + uadk_engine_unregister(&threads_option); return ret; - }
int sec_soft_async_threads(struct acc_option *options) @@ -858,6 +1165,12 @@ int sec_soft_async_threads(struct acc_option *options) if (ret) return ret;
+ threads_option.engine_flag = options->engine_flag; + threads_option.sync_mode = options->syncmode; + ret = uadk_engine_register(&threads_option, options->engine); + if (ret) + return ret; + for (i = 0; i < g_thread_num; i++) { threads_args[i].evp_cipher = threads_option.evp_cipher; threads_args[i].evp_md = threads_option.evp_md; @@ -884,74 +1197,10 @@ int sec_soft_async_threads(struct acc_option *options) }
async_error: + uadk_engine_unregister(&threads_option); return ret; }
-static int uadk_engine_register(struct acc_option *options) -{ - ENGINE *e = NULL; - - if (!options->engine_flag) - return 0; - - ERR_load_ENGINE_strings(); - OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_DYNAMIC, NULL); - - e = ENGINE_by_id(options->engine); - if (!e) { - SSL_TST_PRT("setup uadk engine failed!\n"); - return -EINVAL; - } - - ENGINE_init(e); - switch(options->subtype) { - case CIPHER_TYPE: - ENGINE_register_ciphers(e); - break; - case AEAD_TYPE: - SSL_TST_PRT("Openssl not support AEAD ALG!\n"); - return -EINVAL; - case DIGEST_TYPE: - ENGINE_register_digests(e); - break; - default: - return -EINVAL; - } - ENGINE_free(e); - - return 0; -} - -static void uadk_engine_unregister(struct acc_option *options) -{ - ENGINE *e = NULL; - - if (!options->engine_flag) - return; - - e = ENGINE_by_id(options->engine); - if (!e) { - SSL_TST_PRT("Error: not find uadk engine \n"); - return; - } - - ENGINE_init(e); - switch(options->subtype) { - case CIPHER_TYPE: - ENGINE_unregister_ciphers(e); - break; - case AEAD_TYPE: - // ENGINE_unregister_ciphers(e); //openssl not support aead - break; - case DIGEST_TYPE: - ENGINE_unregister_digests(e); - break; - default: - return; - } - ENGINE_free(e); -} - int sec_soft_benchmark(struct acc_option *options) { u32 ptime; @@ -969,10 +1218,6 @@ int sec_soft_benchmark(struct acc_option *options) if (ret) return ret;
- ret = uadk_engine_register(options); - if (ret) - return ret; - get_pid_cpu_time(&ptime); time_start(options->times); if (options->syncmode) @@ -983,7 +1228,6 @@ int sec_soft_benchmark(struct acc_option *options) if (ret) return ret;
- uadk_engine_unregister(options); free_soft_bd_pool();
return 0;
From: Longfang Liu liulongfang@huawei.com
Update the performance test code of sec's no-sva mode, and optimize the performance test code of sec's no-sva mode by splitting sub-functions.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/sec_wd_benchmark.c | 934 +++++++++++++++---------- 1 file changed, 556 insertions(+), 378 deletions(-)
diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index d2da73b..6d3f8da 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -14,6 +14,7 @@ #define MAX_IVK_LENTH 64 #define DEF_IVK_DATA 0xAA #define SQE_SIZE 128 +#define SEC_PERF_KEY_LEN 16
typedef struct wd_thread_res { u32 subtype; @@ -23,6 +24,9 @@ typedef struct wd_thread_res { u32 ivsize; u32 optype; u32 td_id; + bool is_union; + u32 dalg; + u32 dmode; } thread_data;
struct thread_bd_res { @@ -47,6 +51,9 @@ static struct thread_queue_res g_thread_queue; static unsigned int g_thread_num; static unsigned int g_pktlen;
+static char wd_aead_key[] = "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7" + "\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"; + static void *cipher_async_cb(void *message, void *cipher_tag) { return NULL; @@ -547,15 +554,11 @@ recv_error: return NULL; }
-static void *sec_wd_async_run(void *arg) +static void *sec_wd_cipher_async(void *arg) { thread_data *pdata = (thread_data *)arg; struct wcrypto_cipher_ctx_setup cipher_setup = {0}; - struct wcrypto_aead_ctx_setup aead_setup = {0}; - struct wcrypto_digest_ctx_setup digest_setup = {0}; struct wcrypto_cipher_op_data copdata; - struct wcrypto_aead_op_data aopdata; - struct wcrypto_digest_op_data dopdata; struct wcrypto_async_tag *tag = NULL; char priv_key[MAX_IVK_LENTH]; struct thread_bd_res *bd_res; @@ -566,7 +569,6 @@ static void *sec_wd_async_run(void *arg) void **res_iv; u32 count = 0; int try_cnt = 0; - u32 authsize; int ret, i = 0; void *pool;
@@ -588,211 +590,305 @@ static void *sec_wd_async_run(void *arg) } tag->thread_id = pdata->td_id;
- switch(pdata->subtype) { - case CIPHER_TYPE: - cipher_setup.alg = pdata->alg; - cipher_setup.mode = pdata->mode; - cipher_setup.cb = (void *)cipher_async_cb; - cipher_setup.br.alloc = (void *)wd_alloc_blk; - cipher_setup.br.free = (void *)wd_free_blk; - cipher_setup.br.iova_map = (void *)wd_blk_iova_map; - cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - cipher_setup.br.get_bufsize = (void *)wd_blksize; - cipher_setup.br.usr = pool; - - ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); - if (!ctx) { - SEC_TST_PRT("wd create cipher ctx fail!\n"); - return NULL; - } - tag->ctx = ctx; + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; + cipher_setup.cb = (void *)cipher_async_cb; + cipher_setup.br.alloc = (void *)wd_alloc_blk; + cipher_setup.br.free = (void *)wd_free_blk; + cipher_setup.br.iova_map = (void *)wd_blk_iova_map; + cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + cipher_setup.br.get_bufsize = (void *)wd_blksize; + cipher_setup.br.usr = pool; + + ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); + if (!ctx) { + SEC_TST_PRT("wd create cipher ctx fail!\n"); + return NULL; + } + tag->ctx = ctx;
- 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); - 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); + return NULL; + } + + if (queue->capa.priv.direction == 0) + copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; + else + copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + + copdata.in_bytes = g_pktlen; + copdata.out_bytes = g_pktlen; + copdata.iv_bytes = pdata->ivsize; + copdata.priv = NULL; + + tag->cnt = 0; + copdata.in = res_in[0]; + copdata.out = res_out[0]; + copdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; }
- if (queue->capa.priv.direction == 0) - copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; - else - copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + count++; + i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + copdata.in = res_in[i]; + copdata.out = res_out[i]; + copdata.iv = res_iv[i]; + }
- copdata.in_bytes = g_pktlen; - copdata.out_bytes = g_pktlen; - copdata.iv_bytes = pdata->ivsize; - copdata.priv = NULL; + add_send_complete();
- tag->cnt = 0; - copdata.in = res_in[0]; - copdata.out = res_out[0]; - copdata.iv = res_iv[0]; + while (1) { + if (get_recv_time() > 0) // wait async mode finish recv + break; usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_cipher(ctx, &copdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + }
- count++; - i = count % MAX_POOL_LENTH; - tag->cnt = i; - try_cnt = 0; - copdata.in = res_in[i]; - copdata.out = res_out[i]; - copdata.iv = res_iv[i]; - } + wcrypto_del_cipher_ctx(ctx);
- break; - case AEAD_TYPE: // just ccm and gcm - aead_setup.calg = pdata->alg; - aead_setup.cmode = pdata->mode; - aead_setup.cb = (void *)aead_async_cb; - aead_setup.br.alloc = (void *)wd_alloc_blk; - aead_setup.br.free = (void *)wd_free_blk; - aead_setup.br.iova_map = (void *)wd_blk_iova_map; - aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - aead_setup.br.get_bufsize = (void *)wd_blksize; - aead_setup.br.usr = pool; - - ctx = wcrypto_create_aead_ctx(queue, &aead_setup); - if (!ctx) { - SEC_TST_PRT("wd create aead ctx fail!\n"); - return NULL; - } - tag->ctx = ctx; + 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); - return NULL; - } +static void *sec_wd_aead_async(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_aead_ctx_setup aead_setup = {0}; + struct wcrypto_aead_op_data aopdata; + struct wcrypto_async_tag *tag = NULL; + char priv_key[MAX_IVK_LENTH]; + char priv_hash[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void **res_in; + void **res_out; + void **res_iv; + u32 count = 0; + int try_cnt = 0; + u32 authsize; + int ret, i = 0; + void *pool;
- authsize = 16; //set defaut size - ret = wcrypto_aead_setauthsize(ctx, authsize); - if (ret) { - SEC_TST_PRT("set authsize fail!\n"); - wcrypto_del_aead_ctx(ctx); - return NULL; - } + if (pdata->td_id > g_thread_num) + return NULL; + + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + res_iv = bd_res->iv; + + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + memset(priv_hash, 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"); + return NULL; + } + tag->thread_id = pdata->td_id; + + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; + aead_setup.cb = (void *)aead_async_cb; + aead_setup.br.alloc = (void *)wd_alloc_blk; + aead_setup.br.free = (void *)wd_free_blk; + aead_setup.br.iova_map = (void *)wd_blk_iova_map; + aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + aead_setup.br.get_bufsize = (void *)wd_blksize; + aead_setup.br.usr = pool; + if (pdata->is_union) { + aead_setup.dalg = pdata->dalg; + aead_setup.dmode = pdata->dmode; + } + + + ctx = wcrypto_create_aead_ctx(queue, &aead_setup); + if (!ctx) { + SEC_TST_PRT("wd create aead ctx fail!\n"); + return NULL; + } + tag->ctx = ctx; + + 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); + return NULL; + } + + authsize = 16; //set defaut size + ret = wcrypto_aead_setauthsize(ctx, authsize); + if (ret) { + SEC_TST_PRT("set authsize fail!\n"); + wcrypto_del_aead_ctx(ctx); + return NULL; + }
- if (queue->capa.priv.direction == 0) { - aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; - aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; - } else { + if (queue->capa.priv.direction == 0) { + aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; + aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; + } else { aopdata.op_type = WCRYPTO_CIPHER_DECRYPTION_DIGEST; aopdata.out_bytes = g_pktlen + 16; // aad + plen; }
- aopdata.assoc_size = 16; - aopdata.in_bytes = g_pktlen; - aopdata.out_bytes = g_pktlen; - aopdata.iv_bytes = pdata->ivsize; - aopdata.priv = NULL; - aopdata.out_buf_bytes = g_pktlen * 2; - - tag->cnt = 0; - aopdata.in = res_in[0]; - aopdata.out = res_out[0]; - aopdata.iv = res_iv[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + aopdata.assoc_size = 16; + aopdata.in_bytes = g_pktlen; + aopdata.out_bytes = g_pktlen; + aopdata.iv_bytes = pdata->ivsize; + aopdata.priv = NULL; + aopdata.out_buf_bytes = g_pktlen * 2; + + tag->cnt = 0; + aopdata.in = res_in[0]; + aopdata.out = res_out[0]; + aopdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break;
- count++; - i = count % MAX_POOL_LENTH; - tag->cnt = i; - try_cnt = 0; - aopdata.in = res_in[i]; - aopdata.out = res_out[i]; - aopdata.iv = res_iv[i]; + ret = wcrypto_do_aead(ctx, &aopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; }
- break; - case DIGEST_TYPE: - digest_setup.alg = pdata->alg; - digest_setup.mode = pdata->mode; - digest_setup.cb = (void *)digest_async_cb; - digest_setup.br.alloc = (void *)wd_alloc_blk; - digest_setup.br.free = (void *)wd_free_blk; - digest_setup.br.iova_map = (void *)wd_blk_iova_map; - digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - digest_setup.br.get_bufsize = (void *)wd_blksize; - digest_setup.br.usr = pool; - - ctx = wcrypto_create_digest_ctx(queue, &digest_setup); - if (!ctx) { - SEC_TST_PRT("wd create digest ctx fail!\n"); + count++; + i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + aopdata.in = res_in[i]; + aopdata.out = res_out[i]; + aopdata.iv = res_iv[i]; + } + + add_send_complete(); + + while (1) { + if (get_recv_time() > 0) // wait async mode finish recv + break; + usleep(SEND_USLEEP); + } + + wcrypto_del_aead_ctx(ctx); + + return NULL; +} + +static void *sec_wd_digest_async(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_digest_ctx_setup digest_setup = {0}; + struct wcrypto_digest_op_data dopdata; + struct wcrypto_async_tag *tag = NULL; + char priv_key[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void **res_in; + void **res_out; + u32 count = 0; + int try_cnt = 0; + int ret, i = 0; + void *pool; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + + 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"); + return NULL; + } + tag->thread_id = pdata->td_id; + + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; + digest_setup.cb = (void *)digest_async_cb; + digest_setup.br.alloc = (void *)wd_alloc_blk; + digest_setup.br.free = (void *)wd_free_blk; + digest_setup.br.iova_map = (void *)wd_blk_iova_map; + digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + digest_setup.br.get_bufsize = (void *)wd_blksize; + digest_setup.br.usr = pool; + + ctx = wcrypto_create_digest_ctx(queue, &digest_setup); + if (!ctx) { + SEC_TST_PRT("wd create digest ctx fail!\n"); + return NULL; + } + tag->ctx = ctx; + + if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { + ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, + (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd digest set key fail!\n"); + wcrypto_del_digest_ctx(ctx); return NULL; } - tag->ctx = ctx; - - if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { - ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, - (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd digest set key fail!\n"); - wcrypto_del_digest_ctx(ctx); - return NULL; - } - } + }
- dopdata.in_bytes = g_pktlen; - dopdata.out_bytes = 16; - dopdata.has_next = 0; - dopdata.priv = NULL; + dopdata.in_bytes = g_pktlen; + dopdata.out_bytes = 16; + dopdata.has_next = 0; + dopdata.priv = NULL; + tag->cnt = 0; + dopdata.in = res_in[0]; + dopdata.out = res_out[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break;
- tag->cnt = 0; - dopdata.in = res_in[0]; - dopdata.out = res_out[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; + ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } - - count++; - i = count % MAX_POOL_LENTH; - tag->cnt = i; - try_cnt = 0; - dopdata.in = res_in[i]; - dopdata.out = res_out[i]; + continue; }
- break; + count++; + i = count % MAX_POOL_LENTH; + tag->cnt = i; + try_cnt = 0; + dopdata.in = res_in[i]; + dopdata.out = res_out[i]; }
add_send_complete(); @@ -803,30 +899,16 @@ static void *sec_wd_async_run(void *arg) usleep(SEND_USLEEP); }
- switch(pdata->subtype) { - case CIPHER_TYPE: - wcrypto_del_cipher_ctx(ctx); - break; - case AEAD_TYPE: - wcrypto_del_aead_ctx(ctx); - break; - case DIGEST_TYPE: - wcrypto_del_digest_ctx(ctx); - break; - } + wcrypto_del_digest_ctx(ctx);
return NULL; }
-static void *sec_wd_sync_run(void *arg) +static void *sec_wd_cipher_sync(void *arg) { thread_data *pdata = (thread_data *)arg; struct wcrypto_cipher_ctx_setup cipher_setup = {0}; - struct wcrypto_aead_ctx_setup aead_setup = {0}; - struct wcrypto_digest_ctx_setup digest_setup = {0}; struct wcrypto_cipher_op_data copdata; - struct wcrypto_aead_op_data aopdata; - struct wcrypto_digest_op_data dopdata; char priv_key[MAX_IVK_LENTH]; struct thread_bd_res *bd_res; struct wd_queue *queue; @@ -837,7 +919,6 @@ static void *sec_wd_sync_run(void *arg) void **res_iv; u32 count = 0; int try_cnt = 0; - u32 authsize; int ret, i = 0; void *pool;
@@ -853,203 +934,272 @@ static void *sec_wd_sync_run(void *arg)
memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH);
- switch(pdata->subtype) { - case CIPHER_TYPE: - cipher_setup.alg = pdata->alg; - cipher_setup.mode = pdata->mode; - cipher_setup.br.alloc = (void *)wd_alloc_blk; - cipher_setup.br.free = (void *)wd_free_blk; - cipher_setup.br.iova_map = (void *)wd_blk_iova_map; - cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - cipher_setup.br.get_bufsize = (void *)wd_blksize; - cipher_setup.br.usr = pool; - - ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); - if (!ctx) { - SEC_TST_PRT("wd create cipher ctx fail!\n"); - return NULL; - } + cipher_setup.alg = pdata->alg; + cipher_setup.mode = pdata->mode; + cipher_setup.br.alloc = (void *)wd_alloc_blk; + cipher_setup.br.free = (void *)wd_free_blk; + cipher_setup.br.iova_map = (void *)wd_blk_iova_map; + cipher_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + cipher_setup.br.get_bufsize = (void *)wd_blksize; + cipher_setup.br.usr = pool; + + ctx = wcrypto_create_cipher_ctx(queue, &cipher_setup); + if (!ctx) { + SEC_TST_PRT("wd create cipher ctx fail!\n"); + 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); - 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); + return NULL; + } + + if (queue->capa.priv.direction == 0) + copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; + else + copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + + copdata.in_bytes = g_pktlen; + copdata.out_bytes = g_pktlen; + copdata.iv_bytes = pdata->ivsize; + copdata.priv = NULL; + + copdata.in = res_in[0]; + copdata.out = res_out[0]; + copdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_cipher(ctx, &copdata, tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; }
- if (queue->capa.priv.direction == 0) - copdata.op_type = WCRYPTO_CIPHER_ENCRYPTION; - else - copdata.op_type = WCRYPTO_CIPHER_DECRYPTION; + count++; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + copdata.in = res_in[i]; + copdata.out = res_out[i]; + copdata.iv = res_iv[i]; + } + wcrypto_del_cipher_ctx(ctx);
- copdata.in_bytes = g_pktlen; - copdata.out_bytes = g_pktlen; - copdata.iv_bytes = pdata->ivsize; - copdata.priv = NULL; + add_recv_data(count, g_pktlen);
- copdata.in = res_in[0]; - copdata.out = res_out[0]; - copdata.iv = res_iv[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_cipher(ctx, &copdata, tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test cipher send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + return NULL; +}
- count++; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - copdata.in = res_in[i]; - copdata.out = res_out[i]; - copdata.iv = res_iv[i]; - } - wcrypto_del_cipher_ctx(ctx); +static void *sec_wd_aead_sync(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_aead_ctx_setup aead_setup = {0}; + struct wcrypto_aead_op_data aopdata; + char priv_key[MAX_IVK_LENTH]; + char priv_hash[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void *tag = NULL; + void **res_in; + void **res_out; + void **res_iv; + u32 count = 0; + int try_cnt = 0; + u32 authsize; + int ret, i; + void *pool;
- break; - case AEAD_TYPE: // just ccm and gcm - aead_setup.calg = pdata->alg; - aead_setup.cmode = pdata->mode; - aead_setup.br.alloc = (void *)wd_alloc_blk; - aead_setup.br.free = (void *)wd_free_blk; - aead_setup.br.iova_map = (void *)wd_blk_iova_map; - aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - aead_setup.br.get_bufsize = (void *)wd_blksize; - aead_setup.br.usr = pool; - - ctx = wcrypto_create_aead_ctx(queue, &aead_setup); - if (!ctx) { - SEC_TST_PRT("wd create aead ctx fail!\n"); - return NULL; - } + if (pdata->td_id > g_thread_num) + 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); - return NULL; - } + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + res_iv = bd_res->iv;
- authsize = 16; //set defaut size - ret = wcrypto_aead_setauthsize(ctx, authsize); - if (ret) { - SEC_TST_PRT("set authsize fail!\n"); - wcrypto_del_aead_ctx(ctx); - return NULL; - } + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + memcpy(priv_hash, wd_aead_key, SEC_PERF_KEY_LEN); + + aead_setup.calg = pdata->alg; + aead_setup.cmode = pdata->mode; + aead_setup.br.alloc = (void *)wd_alloc_blk; + aead_setup.br.free = (void *)wd_free_blk; + aead_setup.br.iova_map = (void *)wd_blk_iova_map; + aead_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + aead_setup.br.get_bufsize = (void *)wd_blksize; + aead_setup.br.usr = pool; + if (pdata->is_union) { + aead_setup.dalg = pdata->dalg; + aead_setup.dmode = pdata->dmode; + }
- if (queue->capa.priv.direction == 0) { - aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; - aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; - } else { - aopdata.op_type = WCRYPTO_CIPHER_DECRYPTION_DIGEST; - aopdata.out_bytes = g_pktlen + 16; // aad + plen; - }
- aopdata.assoc_size = 16; - aopdata.in_bytes = g_pktlen; - aopdata.out_bytes = g_pktlen; - aopdata.iv_bytes = pdata->ivsize; - aopdata.priv = NULL; - aopdata.out_buf_bytes = g_pktlen * 2; + ctx = wcrypto_create_aead_ctx(queue, &aead_setup);
- aopdata.in = res_in[0]; - aopdata.out = res_out[0]; - aopdata.iv = res_iv[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_aead(ctx, &aopdata, tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + if (!ctx) { + SEC_TST_PRT("wd create aead ctx fail!\n"); + return NULL; + }
- count++; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - aopdata.in = res_in[i]; - aopdata.out = res_out[i]; - aopdata.iv = res_iv[i]; - } + 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); + return NULL; + }
- break; - case DIGEST_TYPE: - digest_setup.alg = pdata->alg; - digest_setup.mode = pdata->mode; - digest_setup.br.alloc = (void *)wd_alloc_blk; - digest_setup.br.free = (void *)wd_free_blk; - digest_setup.br.iova_map = (void *)wd_blk_iova_map; - digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; - digest_setup.br.get_bufsize = (void *)wd_blksize; - digest_setup.br.usr = pool; - - ctx = wcrypto_create_digest_ctx(queue, &digest_setup); - if (!ctx) { - SEC_TST_PRT("wd create digest ctx fail!\n"); - return NULL; - } + authsize = 16; //set defaut size + ret = wcrypto_aead_setauthsize(ctx, authsize); + if (ret) { + SEC_TST_PRT("set authsize fail!\n"); + wcrypto_del_aead_ctx(ctx); + return NULL; + } + + if (queue->capa.priv.direction == 0) { + aopdata.op_type = WCRYPTO_CIPHER_ENCRYPTION_DIGEST; + aopdata.out_bytes = g_pktlen + 32; // aad + plen + authsize; + } else { + aopdata.op_type = WCRYPTO_CIPHER_DECRYPTION_DIGEST; + aopdata.out_bytes = g_pktlen + 16; // aad + plen; + }
- if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { - ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, - (__u16)pdata->keysize); - if (ret) { - SEC_TST_PRT("wd digest set key fail!\n"); - wcrypto_del_digest_ctx(ctx); - return NULL; + aopdata.assoc_size = 16; + aopdata.in_bytes = g_pktlen; + aopdata.out_bytes = g_pktlen; + aopdata.iv_bytes = pdata->ivsize; + aopdata.priv = NULL; + aopdata.out_buf_bytes = g_pktlen * 2; + + aopdata.in = res_in[0]; + aopdata.out = res_out[0]; + aopdata.iv = res_iv[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_aead(ctx, &aopdata, tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test aead send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; } + continue; }
- dopdata.in_bytes = g_pktlen; - dopdata.out_bytes = 16; - dopdata.has_next = 0; - dopdata.priv = NULL; + count++; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + aopdata.in = res_in[i]; + aopdata.out = res_out[i]; + aopdata.iv = res_iv[i]; + } + + wcrypto_del_aead_ctx(ctx);
- dopdata.in = res_in[0]; - dopdata.out = res_out[0]; - usleep(SEND_USLEEP); - while(1) { - if (get_run_state() == 0) - break; - - ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); - if (ret == -WD_EBUSY) { - usleep(SEND_USLEEP * try_cnt); - try_cnt++; - if (try_cnt > MAX_TRY_CNT) { - SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); - try_cnt = 0; - } - continue; - } + add_recv_data(count, g_pktlen); + + return NULL; +} + +static void *sec_wd_digest_sync(void *arg) +{ + thread_data *pdata = (thread_data *)arg; + struct wcrypto_digest_ctx_setup digest_setup = {0}; + struct wcrypto_digest_op_data dopdata; + char priv_key[MAX_IVK_LENTH]; + struct thread_bd_res *bd_res; + struct wd_queue *queue; + void *ctx = NULL; + void *tag = NULL; + void **res_in; + void **res_out; + u32 count = 0; + int try_cnt = 0; + int ret, i; + void *pool; + + if (pdata->td_id > g_thread_num) + return NULL; + + bd_res = &g_thread_queue.bd_res[pdata->td_id]; + queue = bd_res->queue; + pool = bd_res->pool; + res_in = bd_res->in; + res_out = bd_res->out; + + memset(priv_key, DEF_IVK_DATA, MAX_IVK_LENTH); + + digest_setup.alg = pdata->alg; + digest_setup.mode = pdata->mode; + digest_setup.br.alloc = (void *)wd_alloc_blk; + digest_setup.br.free = (void *)wd_free_blk; + digest_setup.br.iova_map = (void *)wd_blk_iova_map; + digest_setup.br.iova_unmap = (void *)wd_blk_iova_unmap; + digest_setup.br.get_bufsize = (void *)wd_blksize; + digest_setup.br.usr = pool; + + ctx = wcrypto_create_digest_ctx(queue, &digest_setup); + if (!ctx) { + SEC_TST_PRT("wd create digest ctx fail!\n"); + return NULL; + }
- count++; - try_cnt = 0; - i = count % MAX_POOL_LENTH; - dopdata.in = res_in[i]; - dopdata.out = res_out[i]; + if (digest_setup.mode == WCRYPTO_DIGEST_HMAC) { + ret = wcrypto_set_digest_key(ctx, (__u8*)priv_key, + (__u16)pdata->keysize); + if (ret) { + SEC_TST_PRT("wd digest set key fail!\n"); + wcrypto_del_digest_ctx(ctx); + return NULL; } - wcrypto_del_digest_ctx(ctx); - break; }
+ dopdata.in_bytes = g_pktlen; + dopdata.out_bytes = 16; + dopdata.has_next = 0; + dopdata.priv = NULL; + dopdata.in = res_in[0]; + dopdata.out = res_out[0]; + usleep(SEND_USLEEP); + while(1) { + if (get_run_state() == 0) + break; + + ret = wcrypto_do_digest(ctx, &dopdata, (void *)tag); + if (ret == -WD_EBUSY) { + usleep(SEND_USLEEP * try_cnt); + try_cnt++; + if (try_cnt > MAX_TRY_CNT) { + SEC_TST_PRT("Test digest send fail %d times!\n", MAX_TRY_CNT); + try_cnt = 0; + } + continue; + } + + count++; + try_cnt = 0; + i = count % MAX_POOL_LENTH; + dopdata.in = res_in[i]; + dopdata.out = res_out[i]; + } + wcrypto_del_digest_ctx(ctx); + add_recv_data(count, g_pktlen);
return NULL; @@ -1057,6 +1207,8 @@ static void *sec_wd_sync_run(void *arg)
int sec_wd_sync_threads(struct acc_option *options) { + typedef void *(*sec_sync_run)(void *arg); + sec_sync_run wd_sec_sync_run = NULL; thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; @@ -1067,6 +1219,18 @@ int sec_wd_sync_threads(struct acc_option *options) if (ret) return ret;
+ switch (options->subtype) { + case CIPHER_TYPE: + wd_sec_sync_run = sec_wd_cipher_sync; + break; + case AEAD_TYPE: + wd_sec_sync_run = sec_wd_aead_sync; + break; + case DIGEST_TYPE: + wd_sec_sync_run = sec_wd_digest_sync; + break; + } + for (i = 0; i < g_thread_num; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].alg = threads_option.alg; @@ -1075,7 +1239,7 @@ int sec_wd_sync_threads(struct acc_option *options) threads_args[i].ivsize = threads_option.ivsize; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; - ret = pthread_create(&tdid[i], NULL, sec_wd_sync_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, wd_sec_sync_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create sync thread fail!\n"); goto sync_error; @@ -1098,6 +1262,8 @@ sync_error:
int sec_wd_async_threads(struct acc_option *options) { + typedef void *(*sec_async_run)(void *arg); + sec_async_run wd_sec_async_run = NULL; thread_data threads_args[THREADS_NUM]; thread_data threads_option; pthread_t tdid[THREADS_NUM]; @@ -1120,6 +1286,18 @@ int sec_wd_async_threads(struct acc_option *options) } }
+ switch (options->subtype) { + case CIPHER_TYPE: + wd_sec_async_run = sec_wd_cipher_async; + break; + case AEAD_TYPE: + wd_sec_async_run = sec_wd_aead_async; + break; + case DIGEST_TYPE: + wd_sec_async_run = sec_wd_digest_async; + break; + } + for (i = 0; i < g_thread_num; i++) { threads_args[i].subtype = threads_option.subtype; threads_args[i].alg = threads_option.alg; @@ -1128,7 +1306,7 @@ int sec_wd_async_threads(struct acc_option *options) threads_args[i].ivsize = threads_option.ivsize; threads_args[i].optype = threads_option.optype; threads_args[i].td_id = i; - ret = pthread_create(&tdid[i], NULL, sec_wd_async_run, &threads_args[i]); + ret = pthread_create(&tdid[i], NULL, wd_sec_async_run, &threads_args[i]); if (ret) { SEC_TST_PRT("Create async thread fail!\n"); goto async_error;
From: Longfang Liu liulongfang@huawei.com
Add latency test function for symmetric algorithm, asymmetric algorithm and compression algorithm in uadk_tools, and add this function for SVA mode and No-SVA mode at the same time.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi@huawei.com --- uadk_tool/benchmark/hpre_uadk_benchmark.c | 3 +++ uadk_tool/benchmark/hpre_wd_benchmark.c | 3 +++ uadk_tool/benchmark/sec_soft_benchmark.c | 4 ++++ uadk_tool/benchmark/sec_uadk_benchmark.c | 3 +++ uadk_tool/benchmark/sec_wd_benchmark.c | 1 + uadk_tool/benchmark/uadk_benchmark.c | 29 +++++++++++++++++++++-- uadk_tool/benchmark/uadk_benchmark.h | 11 ++++++--- uadk_tool/benchmark/zip_uadk_benchmark.c | 12 ++++------ uadk_tool/benchmark/zip_wd_benchmark.c | 12 ++++------ 9 files changed, 57 insertions(+), 21 deletions(-)
diff --git a/uadk_tool/benchmark/hpre_uadk_benchmark.c b/uadk_tool/benchmark/hpre_uadk_benchmark.c index e722c36..495f50b 100644 --- a/uadk_tool/benchmark/hpre_uadk_benchmark.c +++ b/uadk_tool/benchmark/hpre_uadk_benchmark.c @@ -1198,6 +1198,7 @@ key_release: free(key_info);
wd_rsa_free_sess(h_sess); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -1651,6 +1652,7 @@ param_release: free(req.pri); sess_release: wd_dh_free_sess(h_sess); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -2083,6 +2085,7 @@ msg_release: if (subtype == SM2_TYPE) free(setup.msg);
+ cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; diff --git a/uadk_tool/benchmark/hpre_wd_benchmark.c b/uadk_tool/benchmark/hpre_wd_benchmark.c index 354e0e1..231b569 100644 --- a/uadk_tool/benchmark/hpre_wd_benchmark.c +++ b/uadk_tool/benchmark/hpre_wd_benchmark.c @@ -928,6 +928,7 @@ key_release: free(key_info);
wcrypto_del_rsa_ctx(ctx); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -1324,6 +1325,7 @@ param_release: wd_free_blk(pool, opdata.pri); ctx_release: wcrypto_del_dh_ctx(ctx); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; @@ -2193,6 +2195,7 @@ sess_release: msg_release: if (subtype == SM2_TYPE) free(setup.msg); + cal_avg_latency(count); add_recv_data(count, key_size);
return NULL; diff --git a/uadk_tool/benchmark/sec_soft_benchmark.c b/uadk_tool/benchmark/sec_soft_benchmark.c index c7870aa..a4a2fdb 100644 --- a/uadk_tool/benchmark/sec_soft_benchmark.c +++ b/uadk_tool/benchmark/sec_soft_benchmark.c @@ -867,6 +867,7 @@ static void *sec_soft_cipher_sync(void *arg) EVP_CIPHER_CTX_cleanup(ctx); EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -963,6 +964,7 @@ static void *sec_soft_aead_sync(void *arg) } EVP_CIPHER_CTX_free(ctx);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -1032,6 +1034,8 @@ static void *sec_soft_digest_sync(void *arg) } HMAC_CTX_free(hm_ctx); } + + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 11cf8a1..7828eab 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -901,6 +901,7 @@ static void *sec_uadk_cipher_sync(void *arg) } wd_cipher_free_sess(h_sess);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -988,6 +989,7 @@ static void *sec_uadk_aead_sync(void *arg) } wd_aead_free_sess(h_sess);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -1047,6 +1049,7 @@ static void *sec_uadk_digest_sync(void *arg) } wd_digest_free_sess(h_sess);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index 6d3f8da..50c966c 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -1112,6 +1112,7 @@ static void *sec_wd_aead_sync(void *arg)
wcrypto_del_aead_ctx(ctx);
+ cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 752553d..6313ac6 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -18,6 +18,7 @@
/*----------------------------------------head struct--------------------------------------------------------*/ static unsigned int g_run_state = 1; +static struct acc_option *g_run_options; static pthread_mutex_t acc_mutex = PTHREAD_MUTEX_INITIALIZER; static struct _recv_data { double pkg_len; @@ -290,6 +291,18 @@ void get_rand_data(u8 *addr, u32 size) #endif }
+ +void cal_avg_latency(u32 count) +{ + double latency; + + if (!g_run_options || !g_run_options->latency) + return; + + latency = (double)g_run_options->times * SEC_2_USEC / count; + ACC_TST_PRT("thread<%lu> avg latency: %.1fus\n", gettid(), latency); +} + /*-------------------------------------main code------------------------------------------------------*/
static void parse_alg_param(struct acc_option *option) @@ -474,6 +487,7 @@ int acc_benchmark_run(struct acc_option *option) ACC_TST_PRT("start UADK benchmark test.\n"); parse_alg_param(option); dump_param(option); + g_run_options = option;
pthread_mutex_init(&acc_mutex, NULL); if (option->multis <= 1) { @@ -580,6 +594,8 @@ static void print_help(void) 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(" [--latency]:\n"); + ACC_TST_PRT(" test the running time of packets\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"); @@ -616,7 +632,8 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) {"prefetch", no_argument, 0, 12}, {"engine", required_argument, 0, 13}, {"alglist", no_argument, 0, 14}, - {"help", no_argument, 0, 15}, + {"latency", no_argument, 0, 15}, + {"help", no_argument, 0, 16}, {0, 0, 0, 0} };
@@ -665,8 +682,11 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) break; case 14: print_support_alg(); - goto to_exit; + break; case 15: + option->latency = true; + break; + case 16: print_help(); goto to_exit; default: @@ -735,6 +755,11 @@ int acc_option_convert(struct acc_option *option) goto param_err; }
+ if (option->syncmode == ASYNC_MODE && option->latency) { + ACC_TST_PRT("uadk benchmark async mode can't test latency\n"); + goto param_err; + } + return 0;
param_err: diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index a344fac..5071457 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -32,12 +32,14 @@ #define MAX_POOL_LENTH 4096 #define MAX_TRY_CNT 5000 #define SEND_USLEEP 100 +#define SEC_2_USEC 1000000
-typedef unsigned char u8; -typedef unsigned int u32; -typedef unsigned long long u64; +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])) +#define gettid() syscall(__NR_gettid)
/** * struct acc_option - Define the test acc app option list. @@ -47,6 +49,7 @@ typedef unsigned long long u64; * @modetype: sva, no-sva, soft mode * @optype: enc/dec, comp/decomp * @prefetch: write allocated memory to prevent page faults + * @latency: test packet running time */ struct acc_option { char algname[64]; @@ -65,6 +68,7 @@ struct acc_option { char engine[64]; u32 engine_flag; u32 prefetch; + bool latency; };
enum acc_type { @@ -177,6 +181,7 @@ 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); +extern void cal_avg_latency(u32 count);
int acc_cmd_parse(int argc, char *argv[], struct acc_option *option); int acc_default_case(struct acc_option *option); diff --git a/uadk_tool/benchmark/zip_uadk_benchmark.c b/uadk_tool/benchmark/zip_uadk_benchmark.c index ba18e6d..ffffa9b 100644 --- a/uadk_tool/benchmark/zip_uadk_benchmark.c +++ b/uadk_tool/benchmark/zip_uadk_benchmark.c @@ -603,8 +603,7 @@ 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); + cal_avg_latency(count); if (pdata->optype == WD_DIR_COMPRESS) add_recv_data(count, creq.src_len); else @@ -700,8 +699,7 @@ 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); + cal_avg_latency(count); if (pdata->optype == WD_DIR_COMPRESS) add_recv_data(count, creq.src_len); else @@ -872,8 +870,7 @@ static void *zip_uadk_blk_sync_run(void *arg) } 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); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -936,8 +933,7 @@ static void *zip_uadk_stm_sync_run(void *arg) } 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); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; diff --git a/uadk_tool/benchmark/zip_wd_benchmark.c b/uadk_tool/benchmark/zip_wd_benchmark.c index 0df78cd..8d013c5 100644 --- a/uadk_tool/benchmark/zip_wd_benchmark.c +++ b/uadk_tool/benchmark/zip_wd_benchmark.c @@ -591,8 +591,7 @@ 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); + cal_avg_latency(count); if (pdata->optype == WCRYPTO_DEFLATE) add_recv_data(count, opdata.in_len); else @@ -703,8 +702,7 @@ 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); + cal_avg_latency(count); if (pdata->optype == WCRYPTO_DEFLATE) add_recv_data(count, opdata.in_len); else @@ -906,8 +904,7 @@ static void *zip_wd_blk_sync_run(void *arg) } 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); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL; @@ -983,8 +980,7 @@ static void *zip_wd_stm_sync_run(void *arg) } 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); + cal_avg_latency(count); add_recv_data(count, g_pktlen);
return NULL;
From: Longfang Liu liulongfang@huawei.com
Add support for init2 performance test function for uadk_tools.
Signed-off-by: Longfang Liu liulongfang@huawei.com Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/uadk_benchmark.c | 113 ++++++++++++++++++++++++++- uadk_tool/benchmark/uadk_benchmark.h | 15 +++- 2 files changed, 126 insertions(+), 2 deletions(-)
diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 6313ac6..1524291 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -117,6 +117,9 @@ static struct acc_alg_item alg_options[] = { {"aes-128-gcm", AES_128_GCM}, {"aes-192-gcm", AES_192_GCM}, {"aes-256-gcm", AES_256_GCM}, + {"aes-128-cbc-sha256-hmac", AES_128_CBC_SHA256_HMAC}, + {"aes-192-cbc-sha256-hmac", AES_192_CBC_SHA256_HMAC}, + {"aes-256-cbc-sha256-hmac", AES_256_CBC_SHA256_HMAC}, {"sm4-128-ccm", SM4_128_CCM}, {"sm4-128-gcm", SM4_128_GCM}, {"sm3", SM3_ALG}, @@ -128,9 +131,90 @@ static struct acc_alg_item alg_options[] = { {"sha512", SHA512_ALG}, {"sha512-224", SHA512_224}, {"sha512-256", SHA512_256}, + {"trng", TRNG}, {"", ALG_MAX} };
+static struct acc_alg_item alg_name_options[] = { + {"zlib", ZLIB}, + {"gzip", GZIP}, + {"deflate", DEFLATE}, + {"lz77_zstd", LZ77_ZSTD}, + {"rsa", RSA_1024}, + {"rsa", RSA_2048}, + {"rsa", RSA_3072}, + {"rsa", RSA_4096}, + {"rsa", RSA_1024_CRT}, + {"rsa", RSA_2048_CRT}, + {"rsa", RSA_3072_CRT}, + {"rsa", RSA_4096_CRT}, + {"dh", DH_768}, + {"dh", DH_1024}, + {"dh", DH_1536}, + {"dh", DH_2048}, + {"dh", DH_3072}, + {"dh", DH_4096}, + {"ecdh", ECDH_256}, + {"ecdh", ECDH_384}, + {"ecdh", ECDH_521}, + {"ecdsa", ECDSA_256}, + {"ecdsa", ECDSA_384}, + {"ecdsa", ECDSA_521}, + {"sm2", SM2_ALG}, + {"x25519", X25519_ALG}, + {"x448", X448_ALG}, + {"ecb(aes)", AES_128_ECB}, + {"ecb(aes)", AES_192_ECB}, + {"ecb(aes)", AES_256_ECB}, + {"cbc(aes)", AES_128_CBC}, + {"cbc(aes)", AES_192_CBC}, + {"cbc(aes)", AES_256_CBC}, + {"ctr(aes)", AES_128_CTR}, + {"ctr(aes)", AES_192_CTR}, + {"ctr(aes)", AES_256_CTR}, + {"ofb(aes)", AES_128_OFB}, + {"ofb(aes)", AES_192_OFB}, + {"ofb(aes)", AES_256_OFB}, + {"cfb(aes)", AES_128_CFB}, + {"cfb(aes)", AES_192_CFB}, + {"cfb(aes)", AES_256_CFB}, + {"xts(aes)", AES_256_XTS}, + {"xts(aes)", AES_512_XTS}, + {"ecb(des3_ede)", DES3_128_ECB}, + {"ecb(des3_ede)", DES3_192_ECB}, + {"cbc(des3_ede)", DES3_128_CBC}, + {"cbc(des3_ede)", DES3_192_CBC}, + {"ecb(sm4)", SM4_128_ECB}, + {"cbc(sm4)", SM4_128_CBC}, + {"ctr(sm4)", SM4_128_CTR}, + {"ofb(sm4)", SM4_128_OFB}, + {"cfb(sm4)", SM4_128_CFB}, + {"xts(sm4)", SM4_128_XTS}, + {"ccm(aes)", AES_128_CCM}, + {"ccm(aes)", AES_192_CCM}, + {"ccm(aes)", AES_256_CCM}, + {"gcm(aes)", AES_128_GCM}, + {"gcm(aes)", AES_192_GCM}, + {"gcm(aes)", AES_256_GCM}, + {"authenc(hmac(sha256),cbc(aes))", AES_128_CBC_SHA256_HMAC}, + {"authenc(hmac(sha256),cbc(aes))", AES_192_CBC_SHA256_HMAC}, + {"authenc(hmac(sha256),cbc(aes))", AES_256_CBC_SHA256_HMAC}, + {"ccm(sm4)", SM4_128_CCM}, + {"gcm(sm4)", SM4_128_GCM}, + {"sm3", SM3_ALG}, + {"md5", MD5_ALG}, + {"sha1", SHA1_ALG}, + {"sha256", SHA256_ALG}, + {"sha224", SHA224_ALG}, + {"sha384", SHA384_ALG}, + {"sha512", SHA512_ALG}, + {"sha512-224", SHA512_224}, + {"sha512-256", SHA512_256}, + {"trng", TRNG}, + {"", ALG_MAX} +}; + + /*-------------------------------------tool code------------------------------------------------------*/ void add_send_complete(void) { @@ -188,6 +272,20 @@ static int get_alg_type(const char *alg_name) return alg; }
+int get_alg_name(int alg, char *alg_name) +{ + int i; + + for (i = 0; i < ALG_MAX; i++) { + if (alg == alg_name_options[i].alg) { + strcpy(alg_name, alg_name_options[i].name); + return 0; + } + } + + return -EINVAL; +} + static int get_mode_type(const char *mode_name) { u32 modetype = INVALID_MODE; @@ -475,6 +573,8 @@ static void dump_param(struct acc_option *option) ACC_TST_PRT(" [--acctype]: %u\n", option->acctype); ACC_TST_PRT(" [--prefetch]:%u\n", option->prefetch); ACC_TST_PRT(" [--engine]: %s\n", option->engine); + ACC_TST_PRT(" [--latency]: %u\n", option->latency); + ACC_TST_PRT(" [--init2]: %u\n", option->inittype); }
int acc_benchmark_run(struct acc_option *option) @@ -596,6 +696,8 @@ static void print_help(void) ACC_TST_PRT(" list the all support alg\n"); ACC_TST_PRT(" [--latency]:\n"); ACC_TST_PRT(" test the running time of packets\n"); + ACC_TST_PRT(" [--init2]:\n"); + ACC_TST_PRT(" select init2 mode in the init interface of UADK SVA\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"); @@ -633,7 +735,8 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) {"engine", required_argument, 0, 13}, {"alglist", no_argument, 0, 14}, {"latency", no_argument, 0, 15}, - {"help", no_argument, 0, 16}, + {"init2", no_argument, 0, 16}, + {"help", no_argument, 0, 17}, {0, 0, 0, 0} };
@@ -687,6 +790,9 @@ int acc_cmd_parse(int argc, char *argv[], struct acc_option *option) option->latency = true; break; case 16: + option->inittype = INIT2_TYPE; + break; + case 17: print_help(); goto to_exit; default: @@ -760,6 +866,11 @@ int acc_option_convert(struct acc_option *option) goto param_err; }
+ if (option->inittype == INIT2_TYPE && option->modetype != SVA_MODE) { + ACC_TST_PRT("uadk benchmark No-SVA mode can't use init2\n"); + goto param_err; + } + return 0;
param_err: diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index 5071457..e75a99d 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -44,12 +44,13 @@ typedef unsigned long long u64; /** * 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. + * @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 * @latency: test packet running time + * @inittype: source init method type, defined in enum acc_init_type */ struct acc_option { char algname[64]; @@ -69,6 +70,7 @@ struct acc_option { u32 engine_flag; u32 prefetch; bool latency; + u32 inittype; };
enum acc_type { @@ -77,6 +79,12 @@ enum acc_type { ZIP_TYPE, };
+enum acc_init_type { + INIT_TYPE = 0, + INIT2_TYPE, + MAX_TYPE, +}; + enum alg_type { DEFAULT_TYPE, CIPHER_TYPE, @@ -157,6 +165,9 @@ enum test_alg { AES_128_GCM, AES_192_GCM, AES_256_GCM, + AES_128_CBC_SHA256_HMAC, + AES_192_CBC_SHA256_HMAC, + AES_256_CBC_SHA256_HMAC, SM4_128_CCM, SM4_128_GCM, SM3_ALG, // digest @@ -168,6 +179,7 @@ enum test_alg { SHA512_ALG, SHA512_224, SHA512_256, // digest key all set 4 Bytes + TRNG, ALG_MAX, };
@@ -182,6 +194,7 @@ extern void add_recv_data(u32 cnt, u32 pkglen); extern void add_send_complete(void); extern u32 get_recv_time(void); extern void cal_avg_latency(u32 count); +extern int get_alg_name(int alg, char *alg_name);
int acc_cmd_parse(int argc, char *argv[], struct acc_option *option); int acc_default_case(struct acc_option *option);
Add test case for AES-CBC CTS mode, CS1/2/3, for both uadk v1 and uadk v2 in uadk_tool benchmark tool.
Use param such as '--alg aes-128-cbc-cs1' to enable cs1 mode test.
Use 'uadk_tool benchmark --alglist' to find the name of other modes.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- uadk_tool/benchmark/sec_uadk_benchmark.c | 54 ++++++++++++++++++++++++ uadk_tool/benchmark/sec_wd_benchmark.c | 54 ++++++++++++++++++++++++ uadk_tool/benchmark/uadk_benchmark.c | 18 ++++++++ uadk_tool/benchmark/uadk_benchmark.h | 9 ++++ 4 files changed, 135 insertions(+)
diff --git a/uadk_tool/benchmark/sec_uadk_benchmark.c b/uadk_tool/benchmark/sec_uadk_benchmark.c index 7828eab..f3fee4f 100644 --- a/uadk_tool/benchmark/sec_uadk_benchmark.c +++ b/uadk_tool/benchmark/sec_uadk_benchmark.c @@ -112,6 +112,60 @@ static int sec_uadk_param_parse(thread_data *tddata, struct acc_option *options) mode = WD_CIPHER_CBC; alg = WD_CIPHER_AES; break; + case AES_128_CBC_CS1: + keysize = 16; + ivsize = 16; + mode = WD_CIPHER_CBC_CS1; + alg = WD_CIPHER_AES; + break; + case AES_128_CBC_CS2: + keysize = 16; + ivsize = 16; + mode = WD_CIPHER_CBC_CS2; + alg = WD_CIPHER_AES; + break; + case AES_128_CBC_CS3: + keysize = 16; + ivsize = 16; + mode = WD_CIPHER_CBC_CS3; + alg = WD_CIPHER_AES; + break; + case AES_192_CBC_CS1: + keysize = 24; + ivsize = 16; + mode = WD_CIPHER_CBC_CS1; + alg = WD_CIPHER_AES; + break; + case AES_192_CBC_CS2: + keysize = 24; + ivsize = 16; + mode = WD_CIPHER_CBC_CS2; + alg = WD_CIPHER_AES; + break; + case AES_192_CBC_CS3: + keysize = 24; + ivsize = 16; + mode = WD_CIPHER_CBC_CS3; + alg = WD_CIPHER_AES; + break; + case AES_256_CBC_CS1: + keysize = 32; + ivsize = 16; + mode = WD_CIPHER_CBC_CS1; + alg = WD_CIPHER_AES; + break; + case AES_256_CBC_CS2: + keysize = 32; + ivsize = 16; + mode = WD_CIPHER_CBC_CS2; + alg = WD_CIPHER_AES; + break; + case AES_256_CBC_CS3: + keysize = 32; + ivsize = 16; + mode = WD_CIPHER_CBC_CS3; + alg = WD_CIPHER_AES; + break; case AES_128_CTR: keysize = 16; ivsize = 16; diff --git a/uadk_tool/benchmark/sec_wd_benchmark.c b/uadk_tool/benchmark/sec_wd_benchmark.c index 50c966c..b6efccf 100644 --- a/uadk_tool/benchmark/sec_wd_benchmark.c +++ b/uadk_tool/benchmark/sec_wd_benchmark.c @@ -116,6 +116,60 @@ static int sec_wd_param_parse(thread_data *tddata, struct acc_option *options) mode = WCRYPTO_CIPHER_CBC; alg = WCRYPTO_CIPHER_AES; break; + case AES_128_CBC_CS1: + keysize = 16; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS1; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_128_CBC_CS2: + keysize = 16; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS2; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_128_CBC_CS3: + keysize = 16; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS3; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_192_CBC_CS1: + keysize = 24; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS1; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_192_CBC_CS2: + keysize = 24; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS2; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_192_CBC_CS3: + keysize = 24; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS3; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_256_CBC_CS1: + keysize = 32; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS1; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_256_CBC_CS2: + keysize = 32; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS2; + alg = WCRYPTO_CIPHER_AES; + break; + case AES_256_CBC_CS3: + keysize = 32; + ivsize = 16; + mode = WCRYPTO_CIPHER_CBC_CS3; + alg = WCRYPTO_CIPHER_AES; + break; case AES_128_CTR: keysize = 16; ivsize = 16; diff --git a/uadk_tool/benchmark/uadk_benchmark.c b/uadk_tool/benchmark/uadk_benchmark.c index 1524291..1078327 100644 --- a/uadk_tool/benchmark/uadk_benchmark.c +++ b/uadk_tool/benchmark/uadk_benchmark.c @@ -90,6 +90,15 @@ static struct acc_alg_item alg_options[] = { {"aes-128-cbc", AES_128_CBC}, {"aes-192-cbc", AES_192_CBC}, {"aes-256-cbc", AES_256_CBC}, + {"aes-128-cbc-cs1", AES_128_CBC_CS1}, + {"aes-128-cbc-cs2", AES_128_CBC_CS2}, + {"aes-128-cbc-cs3", AES_128_CBC_CS3}, + {"aes-192-cbc-cs1", AES_192_CBC_CS1}, + {"aes-192-cbc-cs2", AES_192_CBC_CS2}, + {"aes-192-cbc-cs3", AES_192_CBC_CS3}, + {"aes-256-cbc-cs1", AES_256_CBC_CS1}, + {"aes-256-cbc-cs2", AES_256_CBC_CS2}, + {"aes-256-cbc-cs3", AES_256_CBC_CS3}, {"aes-128-ctr", AES_128_CTR}, {"aes-192-ctr", AES_192_CTR}, {"aes-256-ctr", AES_256_CTR}, @@ -169,6 +178,15 @@ static struct acc_alg_item alg_name_options[] = { {"cbc(aes)", AES_128_CBC}, {"cbc(aes)", AES_192_CBC}, {"cbc(aes)", AES_256_CBC}, + {"cbc-cs1(aes)", AES_128_CBC_CS1}, + {"cbc-cs2(aes)", AES_128_CBC_CS2}, + {"cbc-cs3(aes)", AES_128_CBC_CS3}, + {"cbc-cs1(aes)", AES_192_CBC_CS1}, + {"cbc-cs2(aes)", AES_192_CBC_CS2}, + {"cbc-cs3(aes)", AES_192_CBC_CS3}, + {"cbc-cs1(aes)", AES_256_CBC_CS1}, + {"cbc-cs2(aes)", AES_256_CBC_CS2}, + {"cbc-cs3(aes)", AES_256_CBC_CS3}, {"ctr(aes)", AES_128_CTR}, {"ctr(aes)", AES_192_CTR}, {"ctr(aes)", AES_256_CTR}, diff --git a/uadk_tool/benchmark/uadk_benchmark.h b/uadk_tool/benchmark/uadk_benchmark.h index e75a99d..4ec6778 100644 --- a/uadk_tool/benchmark/uadk_benchmark.h +++ b/uadk_tool/benchmark/uadk_benchmark.h @@ -138,6 +138,15 @@ enum test_alg { AES_128_CBC, AES_192_CBC, AES_256_CBC, + AES_128_CBC_CS1, + AES_128_CBC_CS2, + AES_128_CBC_CS3, + AES_192_CBC_CS1, + AES_192_CBC_CS2, + AES_192_CBC_CS3, + AES_256_CBC_CS1, + AES_256_CBC_CS2, + AES_256_CBC_CS3, AES_128_CTR, AES_192_CTR, AES_256_CTR,
Support user self-defined data for calculation. This means user do not need to use reserved memory provided by uadk-v1 driver and make the data to be parsed and processed by the uadk-v1 driver. Through this new feature, users can configure the custom data according to 'struct wd_sec_udata', and pass it to the 'priv' member of 'struct wcrypto_cipher_op_data', enabling hardware deal with the user custom data directly.
Note that if users want to set key through custom data, the uadk-v1 api wcrypto_set_cipher_key(), which used to set the key, should not be used any more. Users should set the key with 'struct wd_sec_udata' type and pass it to 'priv' member.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- v1/drv/hisi_sec_udrv.c | 153 ++++++++++++++++++++++++++++++++++------- v1/wd_cipher.c | 4 +- 2 files changed, 130 insertions(+), 27 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index f73fc8f..ecb2ac2 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -395,7 +395,7 @@ static int fill_cipher_bd1_mode(struct wcrypto_cipher_msg *msg, return WD_SUCCESS; }
-static void fill_cipher_bd1_udata(struct hisi_sec_sqe *sqe, +static void fill_cipher_bd1_dif(struct hisi_sec_sqe *sqe, struct wd_sec_udata *udata) { sqe->type1.gran_num = udata->gran_num; @@ -418,6 +418,28 @@ static void fill_cipher_bd1_udata(struct hisi_sec_sqe *sqe, sqe->type1.lba_h = udata->dif.lba >> QM_HADDR_SHIFT; }
+static void fill_cipher_bd1_udata_addr(struct wcrypto_cipher_msg *msg, + struct hisi_sec_sqe *sqe) +{ + uintptr_t phy; + + /* For user self-defined scene, iova = pa */ + phy = (uintptr_t)msg->in; + sqe->type1.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type1.data_src_addr_h = HI_U32(phy); + phy = (uintptr_t)msg->out; + sqe->type1.data_dst_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type1.data_dst_addr_h = HI_U32(phy); + phy = (uintptr_t)msg->key; + sqe->type1.c_key_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type1.c_key_addr_h = HI_U32(phy); + if (msg->iv_bytes) { + phy = (uintptr_t)msg->iv; + sqe->type1.c_ivin_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type1.c_ivin_addr_h = HI_U32(phy); + } +} + static int map_addr(struct wd_queue *q, __u8 *key, __u16 len, __u32 *addr_l, __u32 *addr_h, __u8 data_fmt) { @@ -500,8 +522,8 @@ map_key_error: static int fill_cipher_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe, struct wcrypto_cipher_msg *msg, struct wcrypto_cipher_tag *tag) { - int ret; struct wd_sec_udata *udata = tag->priv; + int ret;
sqe->type = BD_TYPE1; sqe->scene = SCENE_STORAGE; @@ -519,11 +541,16 @@ static int fill_cipher_bd1(struct wd_queue *q, struct hisi_sec_sqe *sqe, if (ret != WD_SUCCESS) return ret;
- fill_cipher_bd1_udata(sqe, udata); - - ret = fill_cipher_bd1_addr(q, msg, sqe); - if (ret != WD_SUCCESS) - return ret; + if (udata) { + /* User self-defined data with DIF scence */ + fill_cipher_bd1_dif(sqe, udata); + fill_cipher_bd1_udata_addr(msg, sqe); + } else { + /* Reserved for non user self-defined data scence */ + ret = fill_cipher_bd1_addr(q, msg, sqe); + if (ret != WD_SUCCESS) + return ret; + }
sqe->type1.tag = tag->wcrypto_tag.ctx_id;
@@ -636,6 +663,27 @@ static int aes_sm4_param_check(struct wcrypto_cipher_msg *msg) return WD_SUCCESS; }
+static void fill_cipher_bd2_udata_addr(struct wcrypto_cipher_msg *msg, + struct hisi_sec_sqe *sqe) +{ + uintptr_t phy; + + phy = (uintptr_t)msg->in; + sqe->type2.data_src_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type2.data_src_addr_h = HI_U32(phy); + phy = (uintptr_t)msg->out; + sqe->type2.data_dst_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type2.data_dst_addr_h = HI_U32(phy); + phy = (uintptr_t)msg->key; + sqe->type2.c_key_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type2.c_key_addr_h = HI_U32(phy); + if (msg->iv_bytes) { + phy = (uintptr_t)msg->iv; + sqe->type2.c_ivin_addr_l = (__u32)(phy & QM_L32BITS_MASK); + sqe->type2.c_ivin_addr_h = HI_U32(phy); + } +} + static int cipher_param_check(struct wcrypto_cipher_msg *msg) { int ret; @@ -705,9 +753,14 @@ static int fill_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe, return ret; }
- ret = fill_cipher_bd2_addr(q, msg, sqe); - if (ret != WD_SUCCESS) - return ret; + if (tag->priv) { + /* User self-defined data process */ + fill_cipher_bd2_udata_addr(msg, sqe); + } else { + ret = fill_cipher_bd2_addr(q, msg, sqe); + if (ret != WD_SUCCESS) + return ret; + }
if (tag) sqe->type2.tag = tag->wcrypto_tag.ctx_id; @@ -978,10 +1031,11 @@ static int cipher_comb_param_check(struct wcrypto_cipher_msg *msg)
int qm_fill_cipher_sqe(void *message, struct qm_queue_info *info, __u16 i) { - struct hisi_sec_sqe *sqe; struct wcrypto_cipher_msg *msg = message; - struct wd_queue *q = info->q; struct wcrypto_cipher_tag *tag = (void *)(uintptr_t)msg->usr_data; + struct wd_sec_udata *udata = tag->priv; + struct wd_queue *q = info->q; + struct hisi_sec_sqe *sqe; uintptr_t temp; int ret;
@@ -994,10 +1048,13 @@ int qm_fill_cipher_sqe(void *message, struct qm_queue_info *info, __u16 i)
temp = (uintptr_t)info->sq_base + i * info->sqe_size; sqe = (struct hisi_sec_sqe *)temp; - memset(sqe, 0, sizeof(struct hisi_sec_sqe));
- if (tag->priv) + /** + * For user self-defined data with DIF scence, will fill BD1. + * Other scences will fill BD2 by default, including no DIF scence. + */ + if (udata && udata->gran_num != 0) ret = fill_cipher_bd1(q, sqe, msg, tag); else ret = fill_cipher_bd2(q, sqe, msg, tag); @@ -1015,10 +1072,12 @@ int qm_fill_cipher_sqe(void *message, struct qm_queue_info *info, __u16 i)
int qm_fill_cipher_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i) { - struct hisi_sec_bd3_sqe *sqe3; struct wcrypto_cipher_msg *msg = message; - struct wd_queue *q = info->q; struct wcrypto_cipher_tag *tag = (void *)(uintptr_t)msg->usr_data; + struct wd_sec_udata *udata = tag->priv; + struct wd_queue *q = info->q; + struct hisi_sec_bd3_sqe *sqe3; + struct hisi_sec_sqe *sqe; uintptr_t temp; int ret;
@@ -1030,18 +1089,35 @@ int qm_fill_cipher_bd3_sqe(void *message, struct qm_queue_info *info, __u16 i) }
temp = (uintptr_t)info->sq_base + i * info->sqe_size; - sqe3 = (struct hisi_sec_bd3_sqe *)temp;
- memset(sqe3, 0, sizeof(struct hisi_sec_bd3_sqe)); + /* + * For user self-defined data with DIF scence, will fill BD1. + * For user self-defined data without DIF scence, will fill BD2. + * For non user self-defined data scence, will fill BD3. + */ + if (udata) { + sqe = (struct hisi_sec_sqe *)temp; + memset(sqe, 0, sizeof(struct hisi_sec_sqe)); + if (udata->gran_num != 0) + ret = fill_cipher_bd1(q, sqe, msg, tag); + else + ret = fill_cipher_bd2(q, sqe, msg, tag); + } else { + sqe3 = (struct hisi_sec_bd3_sqe *)temp; + memset(sqe3, 0, sizeof(struct hisi_sec_bd3_sqe)); + ret = fill_cipher_bd3(q, sqe3, msg, tag); + }
- ret = fill_cipher_bd3(q, sqe3, msg, tag); if (ret != WD_SUCCESS) return ret;
info->req_cache[i] = msg;
#ifdef DEBUG_LOG - sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS); + if (udata) + sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS); + else + sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS); #endif
return ret; @@ -1671,6 +1747,7 @@ static void cipher_ofb_data_handle(struct wcrypto_cipher_msg *msg) static void parse_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe, struct wcrypto_cipher_msg *cipher_msg) { + struct wcrypto_cipher_tag *tag; __u64 dma_addr;
if (sqe->type2.done != SEC_HW_TASK_DONE || sqe->type2.error_type) { @@ -1680,6 +1757,11 @@ static void parse_cipher_bd2(struct wd_queue *q, struct hisi_sec_sqe *sqe, } else cipher_msg->result = WD_SUCCESS;
+ /* In user self-define data case, may not need addr map, just return */ + tag = (void *)(uintptr_t)cipher_msg->usr_data; + if (tag->priv) + return; + dma_addr = DMA_ADDR(sqe->type2.data_src_addr_h, sqe->type2.data_src_addr_l); drv_iova_unmap(q, cipher_msg->in, (void *)(uintptr_t)dma_addr, @@ -1775,25 +1857,44 @@ int qm_parse_cipher_bd3_sqe(void *msg, const struct qm_queue_info *info, __u16 i, __u16 usr) { struct wcrypto_cipher_msg *cipher_msg = info->req_cache[i]; - struct hisi_sec_bd3_sqe *sqe = msg; + struct hisi_sec_bd3_sqe *sqe3 = msg; struct wd_queue *q = info->q; + struct hisi_sec_sqe *sqe;
if (unlikely(!cipher_msg)) { WD_ERR("info->req_cache is null at index:%hu\n", i); return 0; }
- if (likely(sqe->type == BD_TYPE3)) { - if (unlikely(usr && sqe->tag_l != usr)) + switch (sqe3->type) { + case BD_TYPE3: + if (unlikely(usr && sqe3->tag_l != usr)) return 0; - parse_cipher_bd3(q, sqe, cipher_msg); - } else { + parse_cipher_bd3(q, sqe3, cipher_msg); + break; + case BD_TYPE2: + sqe = (struct hisi_sec_sqe *)sqe3; + if (usr && sqe->type2.tag != usr) + return 0; + parse_cipher_bd2(q, sqe, cipher_msg); + break; + case BD_TYPE1: + sqe = (struct hisi_sec_sqe *)sqe3; + if (usr && sqe->type1.tag != usr) + return 0; + parse_cipher_bd1(q, sqe, cipher_msg); + break; + default: WD_ERR("SEC BD Type error\n"); cipher_msg->result = WD_IN_EPARA; + break; }
#ifdef DEBUG_LOG - sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS); + if (sqe3->type == BD_TYPE3) + sec_dump_bd((unsigned char *)sqe3, SQE_BYTES_NUMS); + else + sec_dump_bd((unsigned char *)sqe, SQE_BYTES_NUMS); #endif
return 1; diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index 1b50089..624adb0 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -69,7 +69,7 @@ static void del_ctx_key(struct wcrypto_cipher_ctx *ctx) if (ctx->key) { if (ctx->setup.data_fmt == WD_FLAT_BUF) memset(ctx->key, 0, MAX_CIPHER_KEY_SIZE); - else if (ctx->setup.data_fmt == WD_SGL_BUF) + else if (ctx->setup.data_fmt == WD_SGL_BUF && ctx->key_bytes) wd_sgl_cp_from_pbuf(ctx->key, 0, tmp, MAX_CIPHER_KEY_SIZE); }
@@ -361,6 +361,8 @@ static int cipher_requests_init(struct wcrypto_cipher_msg **req, req[i]->in_bytes = op[i]->in_bytes; req[i]->out = op[i]->out; req[i]->out_bytes = op[i]->out_bytes; + + /* In user self-define data case, need update key from udata */ udata = op[i]->priv; if (udata && udata->key) { req[i]->key = udata->key;