*** BLURB HERE ***
Chenghai Huang (2): uadk_provider: fixed the variable type inconsistency issue uadk_provider/sec: cleanup variable definition and return value
Zhiqi Song (4): async: modify the condition for async module uninit uadk_provider/pkey: cleanup unused functions in pkey uadk_provider/pkey: cleanup variable definition and return uadk_provider: fix discards 'const' qulifier from pointer
src/uadk_async.c | 85 ++++++------ src/uadk_async.h | 1 + src/uadk_engine_init.c | 3 +- src/uadk_prov_cipher.c | 285 ++++++++++++++++++++--------------------- src/uadk_prov_dh.c | 3 +- src/uadk_prov_digest.c | 66 +++++----- src/uadk_prov_init.c | 2 +- src/uadk_prov_pkey.c | 171 ++++++++++++------------- src/uadk_prov_pkey.h | 59 +-------- src/uadk_prov_rsa.c | 44 ++++++- src/uadk_prov_sm2.c | 252 ++++++++++++++++++------------------ 11 files changed, 477 insertions(+), 494 deletions(-)
From: Chenghai Huang huangchenghai2@huawei.com
The output parameter outl is of the size_t * type in the interface defined by OpenSSL. The int * type is different in uadk_prov_cipher.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- src/uadk_prov_cipher.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index 45f5d6e..78480e6 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -329,7 +329,7 @@ static int uadk_prov_cipher_soft_work(struct cipher_priv_ctx *priv, unsigned cha }
static int uadk_prov_cipher_soft_final(struct cipher_priv_ctx *priv, unsigned char *out, - int *outl) + size_t *outl) { int sw_final_len = 0;
@@ -681,7 +681,7 @@ static int ossl_cipher_unpadblock(unsigned char *buf, size_t *buflen, size_t blo }
static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out, - int *outl, size_t outsize, + size_t *outl, size_t outsize, const unsigned char *in, size_t inlen) { size_t blksz = priv->blksize; @@ -729,7 +729,7 @@ static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out, }
static int uadk_prov_do_cipher(struct cipher_priv_ctx *priv, unsigned char *out, - int *outl, size_t outsize, + size_t *outl, size_t outsize, const unsigned char *in, size_t inlen) { size_t blksz = priv->blksize; @@ -831,7 +831,7 @@ static OSSL_FUNC_cipher_gettable_ctx_params_fn uadk_prov_cipher_gettable_ctx_par static OSSL_FUNC_cipher_set_ctx_params_fn uadk_prov_cipher_set_ctx_params; static OSSL_FUNC_cipher_settable_ctx_params_fn uadk_prov_cipher_settable_ctx_params;
-static int uadk_prov_cipher_cipher(void *vctx, unsigned char *out, int *outl, +static int uadk_prov_cipher_cipher(void *vctx, unsigned char *out, size_t *outl, size_t outsize, const unsigned char *in, size_t inl) { @@ -861,9 +861,9 @@ static int uadk_prov_cipher_cipher(void *vctx, unsigned char *out, int *outl, }
static int uadk_prov_cipher_block_encrypto(struct cipher_priv_ctx *priv, - unsigned char *out, int *outl, size_t outsize) + unsigned char *out, size_t *outl, size_t outsize) { - int blksz = priv->blksize; + size_t blksz = priv->blksize; int ret;
if (priv->pad) { @@ -893,7 +893,7 @@ static int uadk_prov_cipher_block_encrypto(struct cipher_priv_ctx *priv, }
static int uadk_prov_cipher_block_decrypto(struct cipher_priv_ctx *priv, - unsigned char *out, int *outl, size_t outsize) + unsigned char *out, size_t *outl, size_t outsize) { size_t blksz = priv->blksize; int ret; @@ -932,7 +932,7 @@ static int uadk_prov_cipher_block_decrypto(struct cipher_priv_ctx *priv, }
static int uadk_prov_cipher_block_final(void *vctx, unsigned char *out, - int *outl, size_t outsize) + size_t *outl, size_t outsize) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx; int ret; @@ -952,7 +952,7 @@ static int uadk_prov_cipher_block_final(void *vctx, unsigned char *out, }
static int uadk_prov_cipher_block_update(void *vctx, unsigned char *out, - int *outl, size_t outsize, + size_t *outl, size_t outsize, const unsigned char *in, size_t inl) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx; @@ -974,7 +974,7 @@ static int uadk_prov_cipher_block_update(void *vctx, unsigned char *out, }
static int uadk_prov_cipher_stream_update(void *vctx, unsigned char *out, - int *outl, size_t outsize, + size_t *outl, size_t outsize, const unsigned char *in, size_t inl) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx; @@ -1024,7 +1024,7 @@ do_soft: }
static int uadk_prov_cipher_stream_final(void *vctx, unsigned char *out, - int *outl, size_t outsize) + size_t *outl, size_t outsize) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx;
From: Chenghai Huang huangchenghai2@huawei.com
Cleanup variable definition and return value, make the function clearer.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- src/uadk_prov_cipher.c | 265 ++++++++++++++++++++--------------------- src/uadk_prov_digest.c | 66 +++++----- 2 files changed, 159 insertions(+), 172 deletions(-)
diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index 78480e6..de1c8cc 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -38,13 +38,12 @@ #define CTX_ASYNC_DEC 3 #define CTX_NUM 4 #define IV_LEN 16 -#define ENV_ENABLED 1 #define MAX_KEY_LEN 64 #define ALG_NAME_SIZE 128 #define GENERIC_BLOCK_SIZE 16
-#define UADK_E_SUCCESS 1 -#define UADK_E_FAIL 0 +#define UADK_P_SUCCESS 1 +#define UADK_P_FAIL 0
/* Internal flags that can be queried */ #define PROV_CIPHER_FLAG_AEAD 0x0001 @@ -206,7 +205,7 @@ int ossl_cipher_cbc_cts_mode_name2id(const char *name) static int uadk_fetch_sw_cipher(struct cipher_priv_ctx *priv) { if (priv->sw_cipher) - return UADK_E_SUCCESS; + return UADK_P_SUCCESS;
switch (priv->nid) { case ID_aes_128_cbc: @@ -289,9 +288,9 @@ static int uadk_fetch_sw_cipher(struct cipher_priv_ctx *priv) }
if (unlikely(priv->sw_cipher == NULL)) - return UADK_E_FAIL; + return UADK_P_FAIL;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_sw_init(struct cipher_priv_ctx *priv, @@ -299,33 +298,33 @@ static int uadk_prov_cipher_sw_init(struct cipher_priv_ctx *priv, const unsigned char *iv) { if (!uadk_fetch_sw_cipher(priv)) - return UADK_E_FAIL; + return UADK_P_FAIL;
if (!EVP_CipherInit_ex2(priv->sw_ctx, priv->sw_cipher, key, iv, priv->enc, NULL)) { fprintf(stderr, "SW cipher init error!\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
priv->switch_threshold = SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_soft_work(struct cipher_priv_ctx *priv, unsigned char *out, int *outl, const unsigned char *in, size_t len) { if (priv->sw_cipher == NULL) - return UADK_E_FAIL; + return UADK_P_FAIL;
if (!EVP_CipherUpdate(priv->sw_ctx, out, outl, in, len)) { fprintf(stderr, "EVP_CipherUpdate sw_ctx failed.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
priv->switch_flag = UADK_DO_SOFT;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_soft_final(struct cipher_priv_ctx *priv, unsigned char *out, @@ -334,21 +333,21 @@ static int uadk_prov_cipher_soft_final(struct cipher_priv_ctx *priv, unsigned ch int sw_final_len = 0;
if (priv->sw_cipher == NULL) - return UADK_E_FAIL; + return UADK_P_FAIL;
if (!EVP_CipherFinal_ex(priv->sw_ctx, out, &sw_final_len)) { fprintf(stderr, "EVP_CipherFinal_ex sw_ctx failed.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; } *outl = sw_final_len; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static void uadk_prov_cipher_dev_init(struct cipher_priv_ctx *priv);
static int uadk_cipher_poll(void *ctx) { - __u64 rx_cnt = 0; + __u64 recv_cnt = 0; __u32 recv = 0; /* Poll one packet currently */ int expt = 1; @@ -358,10 +357,10 @@ static int uadk_cipher_poll(void *ctx) ret = wd_cipher_poll(expt, &recv); if (ret < 0 || recv >= expt) return ret; - rx_cnt++; - } while (rx_cnt < ENGINE_RECV_MAX_CNT); + recv_cnt++; + } while (recv_cnt < ENGINE_RECV_MAX_CNT);
- fprintf(stderr, "failed to poll msg: timeout!\n"); + fprintf(stderr, "failed to poll provider cipher msg: timeout!\n");
return -ETIMEDOUT; } @@ -375,16 +374,12 @@ static int uadk_get_cipher_info(struct cipher_priv_ctx *priv) if (priv->nid == cipher_info_table[i].nid) { priv->setup.alg = cipher_info_table[i].alg; priv->setup.mode = cipher_info_table[i].mode; - break; + return UADK_P_SUCCESS; } }
- if (unlikely(i == cipher_counts)) { - fprintf(stderr, "failed to setup the private ctx.\n"); - return UADK_E_FAIL; - } - - return UADK_E_SUCCESS; + fprintf(stderr, "failed to setup the private ctx.\n"); + return UADK_P_FAIL; }
static int uadk_prov_cipher_init(struct cipher_priv_ctx *priv, @@ -393,9 +388,9 @@ static int uadk_prov_cipher_init(struct cipher_priv_ctx *priv, { int ret;
- if (ivlen > IV_LEN || keylen > MAX_KEY_LEN) { + if ((iv && ivlen != priv->ivlen) || (key && keylen != priv->keylen)) { fprintf(stderr, "invalid keylen or ivlen.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
if (iv) { @@ -405,7 +400,7 @@ static int uadk_prov_cipher_init(struct cipher_priv_ctx *priv,
ret = uadk_get_cipher_info(priv); if (unlikely(!ret)) - return UADK_E_FAIL; + return UADK_P_FAIL;
if (key) { memcpy(priv->key, key, keylen); @@ -417,22 +412,19 @@ static int uadk_prov_cipher_init(struct cipher_priv_ctx *priv,
uadk_prov_cipher_dev_init(priv);
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static void async_cb(struct wd_cipher_req *req, void *data) { - struct uadk_e_cb_info *cb_param; + struct uadk_e_cb_info *cipher_cb_param; struct async_op *op;
- if (!req) - return; - - cb_param = req->cb_param; - if (!cb_param) + if (!req || !req->cb_param) return;
- op = cb_param->op; + cipher_cb_param = req->cb_param; + op = cipher_cb_param->op; if (op && op->job && !op->done) { op->done = 1; async_free_poll_task(op->idx, 1); @@ -446,9 +438,9 @@ static int uadk_do_cipher_sync(struct cipher_priv_ctx *priv)
ret = wd_do_cipher_sync(priv->sess, &priv->req); if (ret) - return UADK_E_FAIL; + return UADK_P_FAIL;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *op) @@ -458,7 +450,7 @@ static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *o
if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { fprintf(stderr, "async cipher init failed.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
cb_param.op = op; @@ -467,7 +459,7 @@ static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *o priv->req.cb_param = &cb_param; ret = async_get_free_task(&idx); if (!ret) - return UADK_E_FAIL; + return UADK_P_FAIL;
op->idx = idx; do { @@ -475,15 +467,15 @@ static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *o if (ret < 0 && ret != -EBUSY) { fprintf(stderr, "do sec cipher failed, switch to soft cipher.\n"); async_free_poll_task(op->idx, 0); - return UADK_E_FAIL; + return UADK_P_FAIL; } } while (ret == -EBUSY);
ret = async_pause_job(priv, op, ASYNC_TASK_CIPHER); if (!ret) - return UADK_E_FAIL; + return UADK_P_FAIL;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static void uadk_cipher_mutex_infork(void) @@ -546,14 +538,14 @@ static int uadk_prov_cipher_ctx_init(struct cipher_priv_ctx *priv)
if (!priv->key_set || (!priv->iv_set && priv->ivlen)) { fprintf(stderr, "key or iv is not set yet!\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
priv->req.iv_bytes = priv->ivlen; priv->req.iv = priv->iv;
if (priv->switch_flag == UADK_DO_SOFT) - return UADK_E_FAIL; + return UADK_P_FAIL;
uadk_prov_cipher_dev_init(priv);
@@ -567,7 +559,7 @@ static int uadk_prov_cipher_ctx_init(struct cipher_priv_ctx *priv) priv->sess = wd_cipher_alloc_sess(&priv->setup); if (!priv->sess) { fprintf(stderr, "uadk failed to alloc session!\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; } }
@@ -576,10 +568,10 @@ static int uadk_prov_cipher_ctx_init(struct cipher_priv_ctx *priv) wd_cipher_free_sess(priv->sess); priv->sess = 0; fprintf(stderr, "uadk failed to set key!\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
/* @@ -627,18 +619,18 @@ static int ossl_cipher_trailingdata(unsigned char *buf, size_t *buflen, size_t b const unsigned char **in, size_t *inlen) { if (*inlen == 0) - return UADK_E_SUCCESS; + return UADK_P_SUCCESS;
if (*buflen + *inlen > blocksize) { ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); - return UADK_E_FAIL; + return UADK_P_FAIL; }
memcpy(buf + *buflen, *in, *inlen); *buflen += *inlen; *inlen = 0;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
/* Pad the final block for encryption */ @@ -658,7 +650,7 @@ static int ossl_cipher_unpadblock(unsigned char *buf, size_t *buflen, size_t blo
if (len != blocksize) { ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR); - return UADK_E_FAIL; + return UADK_P_FAIL; }
/* @@ -668,16 +660,16 @@ static int ossl_cipher_unpadblock(unsigned char *buf, size_t *buflen, size_t blo pad = buf[blocksize - 1]; if (pad == 0 || pad > blocksize) { ERR_raise(ERR_LIB_PROV, PROV_R_BAD_DECRYPT); - return UADK_E_FAIL; + return UADK_P_FAIL; } for (i = 0; i < pad; i++) { if (buf[--len] != pad) { ERR_raise(ERR_LIB_PROV, PROV_R_BAD_DECRYPT); - return UADK_E_FAIL; + return UADK_P_FAIL; } } *buflen = len; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out, @@ -690,7 +682,7 @@ static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out,
if (outsize < blksz) { ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); - return UADK_E_FAIL; + return UADK_P_FAIL; }
priv->switch_flag = UADK_DO_HW; @@ -701,13 +693,13 @@ static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out, priv->req.out_buf_bytes = inlen;
ret = uadk_prov_cipher_ctx_init(priv); - if (ret != UADK_E_SUCCESS) + if (ret != UADK_P_SUCCESS) return ret;
ret = async_setup_async_event_notification(&op); if (!ret) { fprintf(stderr, "failed to setup async event notification.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
if (op.job == NULL) { @@ -715,17 +707,17 @@ static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out, ret = uadk_do_cipher_sync(priv); if (!ret) { async_clear_async_event_notification(); - return UADK_E_FAIL; + return UADK_P_FAIL; } } else { ret = uadk_do_cipher_async(priv, &op); if (!ret) { async_clear_async_event_notification(); - return UADK_E_FAIL; + return UADK_P_FAIL; } }
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_do_cipher(struct cipher_priv_ctx *priv, unsigned char *out, @@ -757,7 +749,7 @@ static int uadk_prov_do_cipher(struct cipher_priv_ctx *priv, unsigned char *out, */ if (priv->bufsz == blksz && (priv->enc || inlen > 0 || !priv->pad)) { ret = uadk_prov_hw_cipher(priv, out, outl, outsize, priv->buf, blksz); - if (ret != UADK_E_SUCCESS) { + if (ret != UADK_P_SUCCESS) { fprintf(stderr, "do hw ciphers failed.\n"); if (priv->sw_cipher) goto do_soft; @@ -777,7 +769,7 @@ static int uadk_prov_do_cipher(struct cipher_priv_ctx *priv, unsigned char *out,
if (nextblocks > 0) { ret = uadk_prov_hw_cipher(priv, out, outl, outsize, in, nextblocks); - if (ret != UADK_E_SUCCESS) { + if (ret != UADK_P_SUCCESS) { fprintf(stderr, "last block do hw ciphers failed.\n"); if (priv->sw_cipher) goto do_soft; @@ -791,7 +783,7 @@ static int uadk_prov_do_cipher(struct cipher_priv_ctx *priv, unsigned char *out, out: if (inlen != 0 && !ossl_cipher_trailingdata(priv->buf, &priv->bufsz, blksz, &in, &inlen)) - return UADK_E_FAIL; + return UADK_P_FAIL;
*outl = outlint; return inlen == 0; @@ -806,11 +798,11 @@ do_soft: ret = uadk_prov_cipher_soft_work(priv, out, &outlint, in, inlen); if (ret) { *outl = outlint; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
fprintf(stderr, "do soft ciphers failed.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
void uadk_prov_destroy_cipher(void) @@ -831,33 +823,33 @@ static OSSL_FUNC_cipher_gettable_ctx_params_fn uadk_prov_cipher_gettable_ctx_par static OSSL_FUNC_cipher_set_ctx_params_fn uadk_prov_cipher_set_ctx_params; static OSSL_FUNC_cipher_settable_ctx_params_fn uadk_prov_cipher_settable_ctx_params;
-static int uadk_prov_cipher_cipher(void *vctx, unsigned char *out, size_t *outl, - size_t outsize, const unsigned char *in, +static int uadk_prov_cipher_cipher(void *vctx, unsigned char *output, size_t *outl, + size_t outsize, const unsigned char *input, size_t inl) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx; int ret;
- if (!vctx || !in || !out || !outl) - return UADK_E_FAIL; + if (!vctx || !output || !input || !outl) + return UADK_P_FAIL;
if (inl == 0) { *outl = 0; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
if (outsize < inl) { ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); - return UADK_E_FAIL; + return UADK_P_FAIL; }
- ret = uadk_prov_do_cipher(priv, out, outl, outsize, in, inl); - if (ret != UADK_E_SUCCESS) + ret = uadk_prov_do_cipher(priv, output, outl, outsize, input, inl); + if (ret != UADK_P_SUCCESS) return ret;
*outl = inl;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_block_encrypto(struct cipher_priv_ctx *priv, @@ -870,26 +862,26 @@ static int uadk_prov_cipher_block_encrypto(struct cipher_priv_ctx *priv, ossl_cipher_padblock(priv->buf, &priv->bufsz, blksz); } else if (priv->bufsz == 0) { *outl = 0; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; } else if (priv->bufsz != blksz) { ERR_raise(ERR_LIB_PROV, PROV_R_WRONG_FINAL_BLOCK_LENGTH); - return UADK_E_FAIL; + return UADK_P_FAIL; }
if (outsize < blksz) { ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); - return UADK_E_FAIL; + return UADK_P_FAIL; }
ret = uadk_prov_hw_cipher(priv, out, outl, outsize, priv->buf, blksz); - if (ret != UADK_E_SUCCESS) { + if (ret != UADK_P_SUCCESS) { fprintf(stderr, "do hw ciphers failed, switch to soft ciphers.\n"); return uadk_prov_cipher_soft_final(priv, out, outl); }
*outl = blksz;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_block_decrypto(struct cipher_priv_ctx *priv, @@ -902,33 +894,33 @@ static int uadk_prov_cipher_block_decrypto(struct cipher_priv_ctx *priv, if (priv->bufsz != blksz) { if (priv->bufsz == 0 && !priv->pad) { *outl = 0; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; } ERR_raise(ERR_LIB_PROV, PROV_R_WRONG_FINAL_BLOCK_LENGTH); - return UADK_E_FAIL; + return UADK_P_FAIL; }
ret = uadk_prov_hw_cipher(priv, priv->buf, outl, outsize, priv->buf, blksz); - if (ret != UADK_E_SUCCESS) { + if (ret != UADK_P_SUCCESS) { fprintf(stderr, "do hw ciphers failed, switch to soft ciphers.\n"); return uadk_prov_cipher_soft_final(priv, out, outl); }
if (priv->pad && !ossl_cipher_unpadblock(priv->buf, &priv->bufsz, blksz)) { /* ERR_raise already called */ - return UADK_E_FAIL; + return UADK_P_FAIL; }
if (outsize < priv->bufsz) { ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); - return UADK_E_FAIL; + return UADK_P_FAIL; }
memcpy(out, priv->buf, priv->bufsz); *outl = priv->bufsz; priv->bufsz = 0;
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_block_final(void *vctx, unsigned char *out, @@ -938,7 +930,7 @@ static int uadk_prov_cipher_block_final(void *vctx, unsigned char *out, int ret;
if (!vctx || !out || !outl) - return UADK_E_FAIL; + return UADK_P_FAIL;
if (priv->switch_flag == UADK_DO_SOFT) return uadk_prov_cipher_soft_final(priv, out, outl); @@ -951,47 +943,47 @@ static int uadk_prov_cipher_block_final(void *vctx, unsigned char *out, return ret; }
-static int uadk_prov_cipher_block_update(void *vctx, unsigned char *out, +static int uadk_prov_cipher_block_update(void *vctx, unsigned char *output, size_t *outl, size_t outsize, - const unsigned char *in, size_t inl) + const unsigned char *input, size_t inl) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx;
- if (!vctx || !in || !out || !outl) - return UADK_E_FAIL; + if (!vctx || !input || !output || !outl) + return UADK_P_FAIL;
if (inl == 0) { *outl = 0; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
if (outsize < inl) { ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); - return UADK_E_FAIL; + return UADK_P_FAIL; }
- return uadk_prov_do_cipher(priv, out, outl, outsize, in, inl); + return uadk_prov_do_cipher(priv, output, outl, outsize, input, inl); }
-static int uadk_prov_cipher_stream_update(void *vctx, unsigned char *out, +static int uadk_prov_cipher_stream_update(void *vctx, unsigned char *output, size_t *outl, size_t outsize, - const unsigned char *in, size_t inl) + const unsigned char *input, size_t inl) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx; int len = 0; int ret;
- if (!vctx || !in || !out || !outl) - return UADK_E_FAIL; + if (!vctx || !outl || !input || !output) + return UADK_P_FAIL;
if (inl == 0) { *outl = 0; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
if (outsize < inl) { ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL); - return UADK_E_FAIL; + return UADK_P_FAIL; }
if (priv->sw_cipher && @@ -1001,26 +993,26 @@ static int uadk_prov_cipher_stream_update(void *vctx, unsigned char *out, goto do_soft; }
- ret = uadk_prov_hw_cipher(priv, out, outl, outsize, in, inl); - if (ret != UADK_E_SUCCESS) { + ret = uadk_prov_hw_cipher(priv, output, outl, outsize, input, inl); + if (ret != UADK_P_SUCCESS) { if (priv->sw_cipher) goto do_soft; return ret; }
*outl = inl; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS;
do_soft: /* have isseu if both using hw and soft partly */ - ret = uadk_prov_cipher_soft_work(priv, out, &len, in, inl); + ret = uadk_prov_cipher_soft_work(priv, output, &len, input, inl); if (ret) { *outl = len; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
fprintf(stderr, "do soft ciphers failed.\n"); - return UADK_E_FAIL; + return UADK_P_FAIL; }
static int uadk_prov_cipher_stream_final(void *vctx, unsigned char *out, @@ -1029,13 +1021,13 @@ static int uadk_prov_cipher_stream_final(void *vctx, unsigned char *out, struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx;
if (!vctx || !out || !outl) - return UADK_E_FAIL; + return UADK_P_FAIL;
if (priv->switch_flag == UADK_DO_SOFT) return uadk_prov_cipher_soft_final(priv, out, outl);
*outl = 0; - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_einit(void *vctx, const unsigned char *key, size_t keylen, @@ -1045,7 +1037,7 @@ static int uadk_prov_cipher_einit(void *vctx, const unsigned char *key, size_t k struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx;
if (!vctx) - return UADK_E_FAIL; + return UADK_P_FAIL;
priv->req.op_type = WD_CIPHER_ENCRYPTION; priv->enc = 1; @@ -1060,7 +1052,7 @@ static int uadk_prov_cipher_dinit(void *vctx, const unsigned char *key, size_t k struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)vctx;
if (!vctx) - return UADK_E_FAIL; + return UADK_P_FAIL;
priv->req.op_type = WD_CIPHER_DECRYPTION; priv->enc = 0; @@ -1088,7 +1080,7 @@ static int uadk_prov_cipher_set_ctx_params(void *vctx, const OSSL_PARAM params[] const OSSL_PARAM *p;
if (!vctx) - return UADK_E_FAIL; + return UADK_P_FAIL;
p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_PADDING); if (p != NULL) { @@ -1096,7 +1088,7 @@ static int uadk_prov_cipher_set_ctx_params(void *vctx, const OSSL_PARAM params[]
if (!OSSL_PARAM_get_uint(p, &pad)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } priv->pad = pad ? 1 : 0; EVP_CIPHER_CTX_set_padding(priv->sw_ctx, pad); @@ -1108,11 +1100,11 @@ static int uadk_prov_cipher_set_ctx_params(void *vctx, const OSSL_PARAM params[]
if (!OSSL_PARAM_get_size_t(p, &keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } if (priv->keylen != keylen) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); - return UADK_E_FAIL; + return UADK_P_FAIL; } }
@@ -1122,11 +1114,11 @@ static int uadk_prov_cipher_set_ctx_params(void *vctx, const OSSL_PARAM params[]
if (!OSSL_PARAM_get_size_t(p, &ivlen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } if (priv->ivlen != ivlen) { ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH); - return UADK_E_FAIL; + return UADK_P_FAIL; } }
@@ -1136,13 +1128,13 @@ static int uadk_prov_cipher_set_ctx_params(void *vctx, const OSSL_PARAM params[]
if (p->data_type != OSSL_PARAM_UTF8_STRING) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; }
id = ossl_cipher_cbc_cts_mode_name2id(p->data); if (id < 0) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; }
priv->cts_mode = (unsigned int)id; @@ -1151,7 +1143,7 @@ static int uadk_prov_cipher_set_ctx_params(void *vctx, const OSSL_PARAM params[] ALG_NAME_SIZE - 1); }
- return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static int uadk_prov_cipher_get_ctx_params(void *vctx, OSSL_PARAM params[]) @@ -1160,34 +1152,34 @@ static int uadk_prov_cipher_get_ctx_params(void *vctx, OSSL_PARAM params[]) OSSL_PARAM *p;
if (!vctx || !params) - return UADK_E_FAIL; + return UADK_P_FAIL;
p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN); if (p != NULL && !OSSL_PARAM_set_size_t(p, priv->keylen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN); if (p != NULL && !OSSL_PARAM_set_size_t(p, priv->ivlen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_PADDING); if (p != NULL && !OSSL_PARAM_set_uint(p, priv->pad)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IV); if (p != NULL && !OSSL_PARAM_set_octet_string(p, priv->iv, priv->ivlen) && !OSSL_PARAM_set_octet_ptr(p, &priv->iv, priv->ivlen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_UPDATED_IV); if (p != NULL && !OSSL_PARAM_set_octet_string(p, priv->iv, priv->ivlen) && !OSSL_PARAM_set_octet_ptr(p, &priv->iv, priv->ivlen)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CTS_MODE); if (p != NULL) { @@ -1195,10 +1187,10 @@ static int uadk_prov_cipher_get_ctx_params(void *vctx, OSSL_PARAM params[])
if (name == NULL || !OSSL_PARAM_set_utf8_string(p, name)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } } - return UADK_E_SUCCESS; + return UADK_P_SUCCESS; }
static const OSSL_PARAM uadk_prov_default_ctx_params[] = { @@ -1243,29 +1235,30 @@ static int ossl_cipher_generic_get_params(OSSL_PARAM params[], unsigned int md, p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_MODE); if (p != NULL && !OSSL_PARAM_set_uint(p, md)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_CUSTOM_IV); if (p != NULL && !OSSL_PARAM_set_int(p, (flags & PROV_CIPHER_FLAG_CUSTOM_IV) != 0)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_KEYLEN); if (p != NULL && !OSSL_PARAM_set_size_t(p, kbits)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_BLOCK_SIZE); if (p != NULL && !OSSL_PARAM_set_size_t(p, blkbits)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } p = OSSL_PARAM_locate(params, OSSL_CIPHER_PARAM_IVLEN); if (p != NULL && !OSSL_PARAM_set_size_t(p, ivbits)) { ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER); - return UADK_E_FAIL; + return UADK_P_FAIL; } - return UADK_E_SUCCESS; + + return UADK_P_SUCCESS; }
static void uadk_prov_cipher_freectx(void *ctx) @@ -1291,9 +1284,9 @@ static OSSL_FUNC_cipher_newctx_fn uadk_##nm##_newctx; \ static void *uadk_##nm##_newctx(void *provctx) \ { \ struct cipher_priv_ctx *ctx = OPENSSL_zalloc(sizeof(*ctx)); \ - \ if (ctx == NULL) \ return NULL; \ + \ ctx->blksize = blk_size; \ ctx->keylen = key_len; \ ctx->ivlen = iv_len; \ @@ -1306,7 +1299,7 @@ static void *uadk_##nm##_newctx(void *provctx) \ if (strcmp(#typ, "block") == 0) \ ctx->pad = 1; \ return ctx; \ -} \ +} \ static OSSL_FUNC_cipher_get_params_fn uadk_##nm##_get_params; \ static int uadk_##nm##_get_params(OSSL_PARAM params[]) \ { \ diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 9cfa475..0fe31d2 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -347,8 +347,8 @@ static void uadk_fill_mac_buffer_len(struct digest_priv_ctx *priv)
static int uadk_digest_update_inner(struct digest_priv_ctx *priv, const void *data, size_t data_len) { - unsigned char *tmpdata = (unsigned char *)data; - size_t left_len = data_len; + unsigned char *input_data = (unsigned char *)data; + size_t remain_len = data_len; size_t processing_len; int ret;
@@ -363,20 +363,20 @@ static int uadk_digest_update_inner(struct digest_priv_ctx *priv, const void *da */ if (priv->last_update_bufflen != 0) { processing_len = DIGEST_BLOCK_SIZE - priv->last_update_bufflen; - uadk_memcpy(priv->data + priv->last_update_bufflen, tmpdata, + uadk_memcpy(priv->data + priv->last_update_bufflen, input_data, processing_len);
priv->req.in_bytes = DIGEST_BLOCK_SIZE; priv->req.in = priv->data; priv->last_update_bufflen = 0; } else { - if (left_len > BUF_LEN) + if (remain_len > BUF_LEN) processing_len = BUF_LEN; else - processing_len = left_len - (left_len % DIGEST_BLOCK_SIZE); + processing_len = remain_len - (remain_len % DIGEST_BLOCK_SIZE);
priv->req.in_bytes = processing_len; - priv->req.in = tmpdata; + priv->req.in = input_data; }
if (priv->state == SEC_DIGEST_INIT) @@ -385,18 +385,18 @@ static int uadk_digest_update_inner(struct digest_priv_ctx *priv, const void *da priv->state = SEC_DIGEST_DOING;
priv->req.out = priv->out; - left_len -= processing_len; - tmpdata += processing_len; + remain_len -= processing_len; + input_data += processing_len;
ret = wd_do_digest_sync(priv->sess, &priv->req); if (ret) { fprintf(stderr, "do sec digest update failed, switch to soft digest.\n"); goto do_soft_digest; } - } while (left_len > DIGEST_BLOCK_SIZE); + } while (remain_len > DIGEST_BLOCK_SIZE);
- priv->last_update_bufflen = left_len; - uadk_memcpy(priv->data, tmpdata, priv->last_update_bufflen); + priv->last_update_bufflen = remain_len; + uadk_memcpy(priv->data, input_data, priv->last_update_bufflen);
return UADK_DIGEST_SUCCESS;
@@ -411,7 +411,7 @@ do_soft_digest: return ret; }
- return uadk_digest_soft_update(priv, tmpdata, left_len); + return uadk_digest_soft_update(priv, input_data, remain_len); }
fprintf(stderr, "do soft digest failed during updating!\n"); @@ -442,16 +442,14 @@ soft_update:
static void uadk_async_cb(struct wd_digest_req *req, void *data) { - struct uadk_e_cb_info *cb_param; + struct uadk_e_cb_info *digest_cb_param; struct async_op *op;
- if (!req) + if (!req || !req->cb_param) return;
- cb_param = req->cb_param; - if (!cb_param) - return; - op = cb_param->op; + digest_cb_param = req->cb_param; + op = digest_cb_param->op; if (op && op->job && !op->done) { op->done = 1; async_free_poll_task(op->idx, 1); @@ -588,6 +586,12 @@ static int uadk_digest_digest(struct digest_priv_ctx *priv, const void *data, si return UADK_DIGEST_FAIL; }
+ ret = async_setup_async_event_notification(&op); + if (unlikely(!ret)) { + fprintf(stderr, "failed to setup async event notification.\n"); + return UADK_DIGEST_FAIL; + } + priv->req.has_next = DIGEST_END; priv->req.in = priv->data; priv->req.out = priv->out; @@ -596,29 +600,19 @@ static int uadk_digest_digest(struct digest_priv_ctx *priv, const void *data, si
uadk_fill_mac_buffer_len(priv);
- ret = async_setup_async_event_notification(&op); - if (unlikely(!ret)) { - fprintf(stderr, "failed to setup async event notification.\n"); - return UADK_DIGEST_FAIL; - } - - if (op.job == NULL) { + if (op.job == NULL) ret = uadk_do_digest_sync(priv); - if (!ret) - goto uadk_do_digest_err; - } else { + else ret = uadk_do_digest_async(priv, &op); - if (!ret) - goto uadk_do_digest_err; + + if (!ret) { + fprintf(stderr, "do sec single block digest failed.\n"); + async_clear_async_event_notification(); + return ret; } memcpy(digest, priv->req.out, priv->req.out_bytes);
return UADK_DIGEST_SUCCESS; - -uadk_do_digest_err: - fprintf(stderr, "do sec single block digest failed.\n"); - async_clear_async_event_notification(); - return ret; }
static void uadk_digest_cleanup(struct digest_priv_ctx *priv) @@ -701,7 +695,7 @@ static void *uadk_prov_dupctx(void *dctx) return NULL;
in = (struct digest_priv_ctx *)dctx; - ret = OPENSSL_zalloc(sizeof(struct digest_priv_ctx)); + ret = OPENSSL_malloc(sizeof(struct digest_priv_ctx)); if (ret) memcpy(ret, in, sizeof(struct digest_priv_ctx)); return ret;
From: Zhiqi Song songzhiqi1@huawei.com
Change the name of async_poll_task_free() to async_module_uninit(). This name will better indicates that its function is to release resources of the async_module_init().
Add check for hardware support before calling async_module_uninit() in engine destroy process. As async_module_init() will be called only when supported by hardware, async_module_uninit() should also add this kind of check, otherwise it will release incorrect resources.
And do not call async_module_uninit() at OPENSSL_atexit(). Because in dynamic unload scenario, the function entry of async_module_uninit() will not valid, calling it as part of OPENSSL_cleanup will generate segmentation fault.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- src/uadk_async.c | 85 +++++++++++++++++++++++------------------- src/uadk_async.h | 1 + src/uadk_engine_init.c | 3 +- src/uadk_prov_init.c | 2 +- 4 files changed, 51 insertions(+), 40 deletions(-)
diff --git a/src/uadk_async.c b/src/uadk_async.c index 6fe78e8..b88e9ea 100644 --- a/src/uadk_async.c +++ b/src/uadk_async.c @@ -109,34 +109,6 @@ int async_clear_async_event_notification(void) return UADK_E_SUCCESS; }
-void async_poll_task_free(void) -{ - struct async_poll_task *task; - int error; - - /* Disable async poll state first */ - uadk_e_set_async_poll_state(DISABLE_ASYNC_POLLING); - - error = pthread_mutex_lock(&poll_queue.async_task_mutex); - if (error) - return; - - task = poll_queue.head; - if (task) - OPENSSL_free(task); - - poll_queue.head = NULL; - - sem_post(&poll_queue.full_sem); - pthread_join(poll_queue.thread_id, NULL); - - pthread_mutex_unlock(&poll_queue.async_task_mutex); - pthread_attr_destroy(&poll_queue.thread_attr); - sem_destroy(&poll_queue.empty_sem); - sem_destroy(&poll_queue.full_sem); - pthread_mutex_destroy(&poll_queue.async_task_mutex); -} - static int async_get_poll_task(int *id) { int idx = poll_queue.rid; @@ -335,10 +307,9 @@ static void *async_poll_process_func(void *args) } }
- if (!uadk_e_get_async_poll_state()) { - /* exit by main thread */ + /* exit by main thread */ + if (!uadk_e_get_async_poll_state()) break; - }
task = async_get_queue_task(); if (!task) { @@ -372,26 +343,64 @@ int async_module_init(void) if (pthread_mutex_init(&(poll_queue.async_task_mutex), NULL) < 0) return UADK_E_FAIL;
- poll_queue.head = OPENSSL_malloc(ASYNC_QUEUE_TASK_NUM * sizeof(struct async_poll_task)); + poll_queue.head = OPENSSL_zalloc(ASYNC_QUEUE_TASK_NUM * sizeof(struct async_poll_task)); if (!poll_queue.head) - return UADK_E_FAIL; + goto destroy_mutex;
if (sem_init(&poll_queue.empty_sem, 0, ASYNC_QUEUE_TASK_NUM) != 0) - goto err; + goto free_head;
if (sem_init(&poll_queue.full_sem, 0, 0) != 0) - goto err; + goto destroy_empty_sem;
uadk_e_set_async_poll_state(ENABLE_ASYNC_POLLING);
pthread_attr_init(&poll_queue.thread_attr); if (pthread_create(&thread_id, &poll_queue.thread_attr, async_poll_process_func, NULL)) - goto err; + goto destroy_full_sem;
poll_queue.thread_id = thread_id; + return UADK_E_SUCCESS;
-err: - async_poll_task_free(); +destroy_full_sem: + uadk_e_set_async_poll_state(DISABLE_ASYNC_POLLING); + sem_destroy(&poll_queue.full_sem); + pthread_attr_destroy(&poll_queue.thread_attr); +destroy_empty_sem: + sem_destroy(&poll_queue.empty_sem); +free_head: + OPENSSL_free(poll_queue.head); +destroy_mutex: + pthread_mutex_destroy(&poll_queue.async_task_mutex); + return UADK_E_FAIL; } + +void async_module_uninit(void) +{ + int error; + struct async_poll_task *task; + + /* Disable async poll state first */ + uadk_e_set_async_poll_state(DISABLE_ASYNC_POLLING); + + error = pthread_mutex_lock(&poll_queue.async_task_mutex); + if (error) + return; + + sem_post(&poll_queue.full_sem); + pthread_join(poll_queue.thread_id, NULL); + + task = poll_queue.head; + if (task) + OPENSSL_free(task); + + poll_queue.head = NULL; + + pthread_mutex_unlock(&poll_queue.async_task_mutex); + pthread_attr_destroy(&poll_queue.thread_attr); + sem_destroy(&poll_queue.empty_sem); + sem_destroy(&poll_queue.full_sem); + pthread_mutex_destroy(&poll_queue.async_task_mutex); +} diff --git a/src/uadk_async.h b/src/uadk_async.h index 5afc3c6..dcb94d3 100644 --- a/src/uadk_async.h +++ b/src/uadk_async.h @@ -80,6 +80,7 @@ int async_clear_async_event_notification(void); int async_pause_job(void *ctx, struct async_op *op, enum task_type type); void async_register_poll_fn(int type, async_recv_t func); int async_module_init(void); +void async_module_uninit(void); int async_wake_job(ASYNC_JOB *job); void async_free_poll_task(int id, bool is_cb); int async_get_free_task(int *id); diff --git a/src/uadk_engine_init.c b/src/uadk_engine_init.c index c9cdd10..bba382f 100644 --- a/src/uadk_engine_init.c +++ b/src/uadk_engine_init.c @@ -232,7 +232,8 @@ static int uadk_destroy(ENGINE *e) if (uadk_dh) uadk_e_destroy_dh();
- async_poll_task_free(); + if (uadk_cipher || uadk_digest || uadk_rsa || uadk_dh || uadk_ecc) + async_module_uninit();
pthread_mutex_lock(&uadk_engine_mutex); uadk_inited = 0; diff --git a/src/uadk_prov_init.c b/src/uadk_prov_init.c index 010c87b..ab0705f 100644 --- a/src/uadk_prov_init.c +++ b/src/uadk_prov_init.c @@ -205,7 +205,7 @@ static void uadk_teardown(void *provctx) uadk_prov_dh_uninit(); OPENSSL_free(ctx); OSSL_PROVIDER_unload(prov); - async_poll_task_free(); + async_module_uninit(); }
static const OSSL_DISPATCH uadk_dispatch_table[] = {
From: Zhiqi Song songzhiqi1@huawei.com
Remove some default function definitions in pkey, as some algs will not use these functions actually. Avoid compile warning "defined but not used".
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- src/uadk_prov_pkey.h | 58 -------------------------------------------- src/uadk_prov_rsa.c | 41 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 58 deletions(-)
diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h index d61e966..ad06cad 100644 --- a/src/uadk_prov_pkey.h +++ b/src/uadk_prov_pkey.h @@ -277,26 +277,6 @@ static OSSL_FUNC_signature_get_ctx_md_params_fn uadk_signature_##nm##_get_ctx_md static OSSL_FUNC_signature_gettable_ctx_md_params_fn uadk_signature_##nm##_gettable_ctx_md_params; \ static OSSL_FUNC_signature_set_ctx_md_params_fn uadk_signature_##nm##_set_ctx_md_params; \ static OSSL_FUNC_signature_settable_ctx_md_params_fn uadk_signature_##nm##_settable_ctx_md_params; \ -static UADK_PKEY_SIGNATURE get_default_##nm##_signature(void) \ -{ \ - static UADK_PKEY_SIGNATURE s_signature; \ - static int initilazed; \ - \ - if (!initilazed) { \ - UADK_PKEY_SIGNATURE *signature = \ - (UADK_PKEY_SIGNATURE *)EVP_SIGNATURE_fetch(NULL, #alg, \ - "provider=default"); \ - \ - if (signature) { \ - s_signature = *signature; \ - EVP_SIGNATURE_free((EVP_SIGNATURE *)signature); \ - initilazed = 1; \ - } else { \ - fprintf(stderr, "failed to EVP_SIGNATURE_fetch default provider\n"); \ - } \ - } \ - return s_signature; \ -} \ const OSSL_DISPATCH uadk_##nm##_signature_functions[] = { \ { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))uadk_signature_##nm##_newctx }, \ { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))uadk_signature_##nm##_sign_init }, \ @@ -373,26 +353,6 @@ static OSSL_FUNC_asym_cipher_get_ctx_params_fn uadk_asym_cipher_##nm##_get_ctx_p static OSSL_FUNC_asym_cipher_gettable_ctx_params_fn uadk_asym_cipher_##nm##_gettable_ctx_params; \ static OSSL_FUNC_asym_cipher_set_ctx_params_fn uadk_asym_cipher_##nm##_set_ctx_params; \ static OSSL_FUNC_asym_cipher_settable_ctx_params_fn uadk_asym_cipher_##nm##_settable_ctx_params; \ -static UADK_PKEY_ASYM_CIPHER get_default_##nm##_asym_cipher(void) \ -{ \ - static UADK_PKEY_ASYM_CIPHER s_asym_cipher; \ - static int initilazed; \ - \ - if (!initilazed) { \ - UADK_PKEY_ASYM_CIPHER *asym_cipher = \ - (UADK_PKEY_ASYM_CIPHER *)EVP_ASYM_CIPHER_fetch(NULL, #alg, \ - "provider=default"); \ - \ - if (asym_cipher) { \ - s_asym_cipher = *asym_cipher; \ - EVP_ASYM_CIPHER_free((EVP_ASYM_CIPHER *)asym_cipher); \ - initilazed = 1; \ - } else { \ - fprintf(stderr, "failed to EVP_ASYM_CIPHER_fetch default provider\n"); \ - } \ - } \ - return s_asym_cipher; \ -} \ const OSSL_DISPATCH uadk_##nm##_asym_cipher_functions[] = { \ { OSSL_FUNC_ASYM_CIPHER_NEWCTX, (void (*)(void))uadk_asym_cipher_##nm##_newctx }, \ { OSSL_FUNC_ASYM_CIPHER_ENCRYPT_INIT, \ @@ -444,24 +404,6 @@ typedef struct { static OSSL_FUNC_keyexch_settable_ctx_params_fn uadk_keyexch_##nm##_settable_ctx_params; \ static OSSL_FUNC_keyexch_get_ctx_params_fn uadk_keyexch_##nm##_get_ctx_params; \ static OSSL_FUNC_keyexch_gettable_ctx_params_fn uadk_keyexch_##nm##_gettable_ctx_params; \ -static UADK_PKEY_KEYEXCH get_default_##nm##_keyexch(void) \ -{ \ - UADK_PKEY_KEYEXCH s_keyexch; \ - static int initilazed; \ - \ - if (!initilazed) { \ - UADK_PKEY_KEYEXCH *keyexch = \ - (UADK_PKEY_KEYEXCH *)EVP_KEYEXCH_fetch(NULL, #alg, "provider=default"); \ - if (keyexch) { \ - s_keyexch = *keyexch; \ - EVP_KEYEXCH_free((EVP_KEYEXCH *)keyexch); \ - initilazed = 1; \ - } else { \ - fprintf(stderr, "failed to EVP_KEYEXCH_fetch default provider\n"); \ - } \ - } \ - return s_keyexch; \ -} \ const OSSL_DISPATCH uadk_##nm##_keyexch_functions[] = { \ { OSSL_FUNC_KEYEXCH_NEWCTX, (void (*)(void))uadk_keyexch_##nm##_newctx }, \ { OSSL_FUNC_KEYEXCH_INIT, (void (*)(void))uadk_keyexch_##nm##_init }, \ diff --git a/src/uadk_prov_rsa.c b/src/uadk_prov_rsa.c index 181222a..563a0e5 100644 --- a/src/uadk_prov_rsa.c +++ b/src/uadk_prov_rsa.c @@ -285,6 +285,47 @@ enum { MAX_CODE, };
+static UADK_PKEY_SIGNATURE get_default_rsa_signature(void) +{ + static UADK_PKEY_SIGNATURE s_signature; + static int initilazed; + + if (!initilazed) { + UADK_PKEY_SIGNATURE *signature = + (UADK_PKEY_SIGNATURE *)EVP_SIGNATURE_fetch(NULL, "RSA", "provider=default"); + + if (signature) { + s_signature = *signature; + EVP_SIGNATURE_free((EVP_SIGNATURE *)signature); + initilazed = 1; + } else { + fprintf(stderr, "failed to EVP_SIGNATURE_fetch default RSA provider\n"); + } + } + return s_signature; +} + +static UADK_PKEY_ASYM_CIPHER get_default_rsa_asym_cipher(void) +{ + static UADK_PKEY_ASYM_CIPHER s_asym_cipher; + static int initilazed; + + if (!initilazed) { + UADK_PKEY_ASYM_CIPHER *asym_cipher = + (UADK_PKEY_ASYM_CIPHER *)EVP_ASYM_CIPHER_fetch(NULL, "RSA", + "provider=default"); + + if (asym_cipher) { + s_asym_cipher = *asym_cipher; + EVP_ASYM_CIPHER_free((EVP_ASYM_CIPHER *)asym_cipher); + initilazed = 1; + } else { + fprintf(stderr, "failed to EVP_ASYM_CIPHER_fetch default RSA provider\n"); + } + } + return s_asym_cipher; +} + static void uadk_rsa_clear_flags(RSA *r, int flags) { r->flags &= ~flags;
From: Zhiqi Song songzhiqi1@huawei.com
Cleanup variable definition and return value, make the function clearer.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- src/uadk_prov_pkey.c | 171 +++++++++++++++-------------- src/uadk_prov_pkey.h | 1 + src/uadk_prov_sm2.c | 252 +++++++++++++++++++++---------------------- 3 files changed, 212 insertions(+), 212 deletions(-)
diff --git a/src/uadk_prov_pkey.c b/src/uadk_prov_pkey.c index d02b165..d1f7afe 100644 --- a/src/uadk_prov_pkey.c +++ b/src/uadk_prov_pkey.c @@ -75,17 +75,17 @@ static void uadk_prov_asym_cipher_set_support_state(int alg_tag, int value) p_asym_cipher_support_state[alg_tag] = value; }
-static int uadk_prov_ecc_get_hw_keybits(int bits) +static int uadk_prov_ecc_get_hw_keybits(int key_bits) { - if (bits > ECC384BITS) + if (key_bits > ECC384BITS) return ECC521BITS; - else if (bits > ECC320BITS) + else if (key_bits > ECC320BITS) return ECC384BITS; - else if (bits > ECC256BITS) + else if (key_bits > ECC256BITS) return ECC320BITS; - else if (bits > ECC192BITS) + else if (key_bits > ECC192BITS) return ECC256BITS; - else if (bits > ECC128BITS) + else if (key_bits > ECC128BITS) return ECC192BITS; else return ECC128BITS; @@ -105,18 +105,18 @@ int uadk_prov_ecc_get_rand(char *out, size_t out_len, void *usr) BIGNUM *k; int ret;
- if (!out) { + if (out == NULL) { fprintf(stderr, "out is NULL\n"); - return -1; + return UADK_P_INVALID; }
k = BN_new(); - if (!k) + if (k == NULL) return -ENOMEM;
do { ret = BN_priv_rand_range(k, usr); - if (!ret) { + if (ret == 0) { fprintf(stderr, "failed to BN_priv_rand_range\n"); ret = -EINVAL; goto err; @@ -132,7 +132,7 @@ int uadk_prov_ecc_get_rand(char *out, size_t out_len, void *usr)
ret = 0; if (count < 0) - ret = -1; + ret = UADK_P_INVALID; err: BN_free(k);
@@ -160,12 +160,12 @@ int uadk_prov_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *p, { # if OPENSSL_VERSION_NUMBER > 0x10101000L if (!EC_POINT_get_affine_coordinates(group, p, x, y, ctx)) - return -1; + return UADK_P_FAIL; # else if (!EC_POINT_get_affine_coordinates_GFp(group, p, x, y, ctx)) - return -1; + return UADK_P_FAIL; # endif - return 0; + return UADK_P_SUCCESS; }
int uadk_prov_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, @@ -173,100 +173,100 @@ int uadk_prov_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, { # if OPENSSL_VERSION_NUMBER > 0x10101000L if (!EC_GROUP_get_curve(group, p, a, b, ctx)) - return -1; + return UADK_P_FAIL; # else if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) - return -1; + return UADK_P_FAIL; # endif - return 0; + return UADK_P_SUCCESS; }
-static void uadk_prov_fill_ecc_cv_param(struct wd_ecc_curve *pparam, +static void uadk_prov_fill_ecc_cv_param(struct wd_ecc_curve *ecc_param, struct curve_param *cv_param, BIGNUM *g_x, BIGNUM *g_y) { - pparam->p.dsize = BN_bn2bin(cv_param->p, (void *)pparam->p.data); - pparam->a.dsize = BN_bn2bin(cv_param->a, (void *)pparam->a.data); - if (!pparam->a.dsize) { - pparam->a.dsize = 1; - pparam->a.data[0] = 0; + ecc_param->p.dsize = BN_bn2bin(cv_param->p, (void *)ecc_param->p.data); + ecc_param->a.dsize = BN_bn2bin(cv_param->a, (void *)ecc_param->a.data); + if (!ecc_param->a.dsize) { + ecc_param->a.dsize = 1; + ecc_param->a.data[0] = 0; }
- pparam->b.dsize = BN_bn2bin(cv_param->b, (void *)pparam->b.data); - if (!pparam->b.dsize) { - pparam->b.dsize = 1; - pparam->b.data[0] = 0; + ecc_param->b.dsize = BN_bn2bin(cv_param->b, (void *)ecc_param->b.data); + if (!ecc_param->b.dsize) { + ecc_param->b.dsize = 1; + ecc_param->b.data[0] = 0; }
- pparam->g.x.dsize = BN_bn2bin(g_x, (void *)pparam->g.x.data); - pparam->g.y.dsize = BN_bn2bin(g_y, (void *)pparam->g.y.data); - pparam->n.dsize = BN_bn2bin(cv_param->order, (void *)pparam->n.data); + ecc_param->g.x.dsize = BN_bn2bin(g_x, (void *)ecc_param->g.x.data); + ecc_param->g.y.dsize = BN_bn2bin(g_y, (void *)ecc_param->g.y.data); + ecc_param->n.dsize = BN_bn2bin(cv_param->order, (void *)ecc_param->n.data); }
static int uadk_prov_set_sess_setup_cv(const EC_GROUP *group, struct wd_ecc_curve_cfg *cv) { - struct wd_ecc_curve *pparam = cv->cfg.pparam; + struct wd_ecc_curve *ecc_param = cv->cfg.pparam; struct curve_param *cv_param; + int ret = UADK_P_FAIL; BIGNUM *g_x, *g_y; - int ret = -1; - BN_CTX *ctx; + BN_CTX *bn_ctx;
- ctx = BN_CTX_new(); - if (!ctx) + bn_ctx = BN_CTX_new(); + if (!bn_ctx) return ret;
- BN_CTX_start(ctx); + BN_CTX_start(bn_ctx);
cv_param = OPENSSL_malloc(sizeof(struct curve_param)); if (!cv_param) goto free_ctx;
- cv_param->p = BN_CTX_get(ctx); + cv_param->p = BN_CTX_get(bn_ctx); if (!cv_param->p) goto free_cv;
- cv_param->a = BN_CTX_get(ctx); + cv_param->a = BN_CTX_get(bn_ctx); if (!cv_param->a) goto free_cv;
- cv_param->b = BN_CTX_get(ctx); + cv_param->b = BN_CTX_get(bn_ctx); if (!cv_param->b) goto free_cv;
- g_x = BN_CTX_get(ctx); + g_x = BN_CTX_get(bn_ctx); if (!g_x) goto free_cv;
- g_y = BN_CTX_get(ctx); + g_y = BN_CTX_get(bn_ctx); if (!g_y) goto free_cv;
- ret = uadk_prov_get_curve(group, cv_param->p, cv_param->a, cv_param->b, ctx); - if (ret) + ret = uadk_prov_get_curve(group, cv_param->p, cv_param->a, cv_param->b, bn_ctx); + if (ret == 0) goto free_cv;
cv_param->g = EC_GROUP_get0_generator(group); if (!cv_param->g) goto free_cv;
- ret = uadk_prov_get_affine_coordinates(group, cv_param->g, g_x, g_y, ctx); - if (ret) + ret = uadk_prov_get_affine_coordinates(group, cv_param->g, g_x, g_y, bn_ctx); + if (ret == 0) goto free_cv;
cv_param->order = EC_GROUP_get0_order(group); if (!cv_param->order) goto free_cv;
- uadk_prov_fill_ecc_cv_param(pparam, cv_param, g_x, g_y); + uadk_prov_fill_ecc_cv_param(ecc_param, cv_param, g_x, g_y); cv->type = WD_CV_CFG_PARAM; - ret = 0; + ret = UADK_P_SUCCESS;
free_cv: OPENSSL_free(cv_param); free_ctx: - BN_CTX_end(ctx); - BN_CTX_free(ctx); + BN_CTX_end(bn_ctx); + BN_CTX_free(bn_ctx);
return ret; } @@ -289,13 +289,13 @@ handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, char *alg) sp.cv.cfg.pparam = ¶m; group = EC_KEY_get0_group(eckey); ret = uadk_prov_set_sess_setup_cv(group, &sp.cv); - if (ret) { + if (ret == 0) { fprintf(stderr, "failed to set_sess_setup_cv\n"); return (handle_t)0; }
order = EC_GROUP_get0_order(group); - if (!order) { + if (order == NULL) { fprintf(stderr, "failed to get ecc order\n"); return (handle_t)0; } @@ -309,7 +309,7 @@ handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, char *alg) sch_p.numa_id = -1; sp.sched_param = &sch_p; sess = wd_ecc_alloc_sess(&sp); - if (!sess) + if (sess == (handle_t)0) fprintf(stderr, "failed to alloc ecc sess\n");
return sess; @@ -317,30 +317,30 @@ handle_t uadk_prov_ecc_alloc_sess(const EC_KEY *eckey, char *alg)
void uadk_prov_ecc_cb(void *req_t) { - struct wd_ecc_req *req_new = (struct wd_ecc_req *)req_t; - struct uadk_e_cb_info *cb_param; - struct wd_ecc_req *req_origin; - struct async_op *op; + struct wd_ecc_req *ecc_req_new = (struct wd_ecc_req *)req_t; + struct uadk_e_cb_info *ecc_cb_param; + struct wd_ecc_req *ecc_req_origin; + struct async_op *ecc_async_op;
- if (!req_new) + if (ecc_req_new == NULL) return;
- cb_param = req_new->cb_param; - if (!cb_param) + ecc_cb_param = ecc_req_new->cb_param; + if (ecc_cb_param == NULL) return;
- req_origin = cb_param->priv; - if (!req_origin) + ecc_req_origin = ecc_cb_param->priv; + if (ecc_req_origin == NULL) return;
- req_origin->status = req_new->status; + ecc_req_origin->status = ecc_req_new->status;
- op = cb_param->op; - if (op && op->job && !op->done) { - op->done = 1; - op->ret = 0; - async_free_poll_task(op->idx, 1); - async_wake_job(op->job); + ecc_async_op = ecc_cb_param->op; + if (ecc_async_op && ecc_async_op->job && !ecc_async_op->done) { + ecc_async_op->done = 1; + ecc_async_op->ret = 0; + async_free_poll_task(ecc_async_op->idx, 1); + async_wake_job(ecc_async_op->job); } }
@@ -384,7 +384,7 @@ int uadk_prov_ecc_crypto(handle_t sess, struct wd_ecc_req *req, void *usr) } while (ret == -EBUSY);
ret = async_pause_job(usr, &op, ASYNC_TASK_ECC); - if (!ret) + if (ret == 0) goto err;
if (req->status) @@ -555,7 +555,7 @@ static int ossl_ec_encoding_name2id(const char *name) return encoding_nameid_map[i].id; }
- return -1; + return UADK_P_INVALID; }
static int ossl_ec_pt_format_name2id(const char *name) @@ -571,7 +571,7 @@ static int ossl_ec_pt_format_name2id(const char *name) return format_nameid_map[i].id; }
- return -1; + return UADK_P_INVALID; }
int uadk_prov_ecc_genctx_check(struct ec_gen_ctx *gctx, EC_KEY *ec) @@ -663,25 +663,24 @@ void uadk_prov_signature_alg(void) } }
-int uadk_prov_ecc_set_private_key(handle_t sess, const EC_KEY *eckey) +int uadk_prov_ecc_set_private_key(handle_t sess, const EC_KEY *ec) { - unsigned char bin[UADK_ECC_MAX_KEY_BYTES]; + unsigned char prikey_bin[UADK_ECC_MAX_KEY_BYTES]; struct wd_ecc_key *ecc_key; const EC_GROUP *group; struct wd_dtb prikey; const BIGNUM *d; + int buflen, ret; size_t degree; - int buflen; - int ret;
- d = EC_KEY_get0_private_key(eckey); - if (!d) { + d = EC_KEY_get0_private_key(ec); + if (d == NULL) { fprintf(stderr, "private key not set\n"); return UADK_P_FAIL; }
- group = EC_KEY_get0_group(eckey); - if (!group) { + group = EC_KEY_get0_group(ec); + if (group == NULL) { fprintf(stderr, "failed to get ecc group\n"); return UADK_P_FAIL; } @@ -689,8 +688,8 @@ int uadk_prov_ecc_set_private_key(handle_t sess, const EC_KEY *eckey) degree = EC_GROUP_get_degree(group); buflen = BITS_TO_BYTES(degree); ecc_key = wd_ecc_get_key(sess); - prikey.data = (void *)bin; - prikey.dsize = BN_bn2binpad(d, bin, buflen); + prikey.data = (void *)prikey_bin; + prikey.dsize = BN_bn2binpad(d, prikey_bin, buflen);
ret = wd_ecc_set_prikey(ecc_key, &prikey); if (ret) { @@ -713,7 +712,7 @@ bool uadk_prov_is_all_zero(const unsigned char *data, size_t dlen) return true; }
-int uadk_prov_ecc_set_public_key(handle_t sess, const EC_KEY *eckey) +int uadk_prov_ecc_set_public_key(handle_t sess, const EC_KEY *ec) { unsigned char *point_bin = NULL; struct wd_ecc_point pubkey; @@ -722,16 +721,16 @@ int uadk_prov_ecc_set_public_key(handle_t sess, const EC_KEY *eckey) const EC_GROUP *group; int ret, len;
- point = EC_KEY_get0_public_key(eckey); - if (!point) { + point = EC_KEY_get0_public_key(ec); + if (point == NULL) { fprintf(stderr, "pubkey not set!\n"); return UADK_P_FAIL; }
- group = EC_KEY_get0_group(eckey); + group = EC_KEY_get0_group(ec); len = EC_POINT_point2buf(group, point, UADK_OCTET_STRING, &point_bin, NULL); - if (!len) { + if (len == 0) { fprintf(stderr, "EC_POINT_point2buf error.\n"); return UADK_P_FAIL; } diff --git a/src/uadk_prov_pkey.h b/src/uadk_prov_pkey.h index ad06cad..0e27fcb 100644 --- a/src/uadk_prov_pkey.h +++ b/src/uadk_prov_pkey.h @@ -44,6 +44,7 @@ #define UADK_P_INTI_SUCCESS 0 #define UADK_P_SUCCESS 1 #define UADK_P_FAIL 0 +#define UADK_P_INVALID (-1) #define PROV_SEND_MAX_CNT 90000000 #define PROV_RECV_MAX_CNT 60000000 #define PROV_ENV_RECV_MAX_CNT 60000 diff --git a/src/uadk_prov_sm2.c b/src/uadk_prov_sm2.c index 1e0bd5a..b6d5d01 100644 --- a/src/uadk_prov_sm2.c +++ b/src/uadk_prov_sm2.c @@ -498,7 +498,7 @@ static int uadk_prov_sm2_keygen_init_iot(handle_t sess, struct wd_ecc_req *req) { struct wd_ecc_out *ecc_out = wd_sm2_new_kg_out(sess);
- if (!ecc_out) { + if (ecc_out == NULL) { fprintf(stderr, "failed to new sign out\n"); return UADK_P_FAIL; } @@ -510,16 +510,16 @@ static int uadk_prov_sm2_keygen_init_iot(handle_t sess, struct wd_ecc_req *req)
static int uadk_prov_sm2_set_key_to_ec_key(EC_KEY *ec, struct wd_ecc_req *req) { - unsigned char buff[ECC_POINT_SIZE(SM2_KEY_BYTES) + 1] = {0}; + unsigned char key_buff[ECC_POINT_SIZE(SM2_KEY_BYTES) + 1] = {0}; struct wd_ecc_point *pubkey = NULL; struct wd_dtb *privkey = NULL; int x_offset, y_offset, ret; const EC_GROUP *group; EC_POINT *point, *ptr; - BIGNUM *tmp; + BIGNUM *bn_key;
wd_sm2_get_kg_out_params(req->dst, &privkey, &pubkey); - if (!privkey || !pubkey) { + if (privkey == NULL || pubkey == NULL) { fprintf(stderr, "failed to get privkey or pubkey\n"); return UADK_P_FAIL; } @@ -529,31 +529,31 @@ static int uadk_prov_sm2_set_key_to_ec_key(EC_KEY *ec, struct wd_ecc_req *req) return UADK_P_FAIL; }
- tmp = BN_bin2bn((unsigned char *)privkey->data, privkey->dsize, NULL); - ret = EC_KEY_set_private_key(ec, tmp); - BN_free(tmp); - if (!ret) { + bn_key = BN_bin2bn((unsigned char *)privkey->data, privkey->dsize, NULL); + ret = EC_KEY_set_private_key(ec, bn_key); + BN_free(bn_key); + if (ret == 0) { fprintf(stderr, "failed to EC KEY set private key\n"); return UADK_P_FAIL; }
group = EC_KEY_get0_group(ec); point = EC_POINT_new(group); - if (!point) { + if (point == NULL) { fprintf(stderr, "failed to EC POINT new\n"); return UADK_P_FAIL; }
- buff[0] = UADK_OCTET_STRING; + key_buff[0] = UADK_OCTET_STRING; /* The component of sm2 pubkey need a SM2_KEY_BYTES align */ x_offset = 1 + SM2_KEY_BYTES - pubkey->x.dsize; y_offset = 1 + ECC_POINT_SIZE(SM2_KEY_BYTES) - pubkey->y.dsize; - memcpy(buff + x_offset, pubkey->x.data, pubkey->x.dsize); - memcpy(buff + y_offset, pubkey->y.data, pubkey->y.dsize); - tmp = BN_bin2bn(buff, ECC_POINT_SIZE(SM2_KEY_BYTES) + 1, NULL); - ptr = EC_POINT_bn2point(group, tmp, point, NULL); - BN_free(tmp); - if (!ptr) { + memcpy(key_buff + x_offset, pubkey->x.data, pubkey->x.dsize); + memcpy(key_buff + y_offset, pubkey->y.data, pubkey->y.dsize); + bn_key = BN_bin2bn(key_buff, ECC_POINT_SIZE(SM2_KEY_BYTES) + 1, NULL); + ptr = EC_POINT_bn2point(group, bn_key, point, NULL); + BN_free(bn_key); + if (ptr == NULL) { fprintf(stderr, "failed to EC_POINT_bn2point\n"); EC_POINT_free(point); return UADK_P_FAIL; @@ -561,7 +561,7 @@ static int uadk_prov_sm2_set_key_to_ec_key(EC_KEY *ec, struct wd_ecc_req *req)
ret = EC_KEY_set_public_key(ec, point); EC_POINT_free(point); - if (!ret) { + if (ret == 0) { fprintf(stderr, "failed to EC_KEY_set_public_key\n"); return UADK_P_FAIL; } @@ -579,13 +579,13 @@ static int uadk_prov_sm2_check_priv_key(EC_KEY *eckey) return UADK_P_SUCCESS;
priv_key = BN_new(); - if (!priv_key) { + if (priv_key == NULL) { fprintf(stderr, "failed to BN_new priv_key\n"); return UADK_P_FAIL; }
ret = EC_KEY_set_private_key(eckey, priv_key); - if (!ret) + if (ret == 0) fprintf(stderr, "failed to set private key\n");
BN_free(priv_key); @@ -865,7 +865,7 @@ static int uadk_prov_compute_hash(const char *in, size_t in_len, EVP_MD_CTX *hash;
hash = EVP_MD_CTX_new(); - if (!hash) + if (hash == NULL) return -WD_EINVAL;
if (EVP_DigestInit(hash, digest) == 0 || @@ -935,7 +935,7 @@ static int uadk_prov_sm2_update_sess(SM2_PROV_CTX *smctx) setup.rand.cb = uadk_prov_ecc_get_rand; setup.rand.usr = (void *)order; sess = wd_ecc_alloc_sess(&setup); - if (!sess) { + if (sess == (handle_t)0) { fprintf(stderr, "failed to alloc sess\n"); BN_free(order); smctx->init_status = CTX_INIT_FAIL; @@ -1128,30 +1128,30 @@ static int uadk_prov_sm2_update_private_key(SM2_PROV_CTX *smctx, EC_KEY *eckey) static int uadk_prov_sm2_sign_bin_to_ber(struct wd_dtb *r, struct wd_dtb *s, unsigned char *sig, size_t *siglen) { + BIGNUM *bn_r, *bn_s; ECDSA_SIG *e_sig; - BIGNUM *br, *bs; int sltmp, ret;
e_sig = ECDSA_SIG_new(); - if (!e_sig) { + if (e_sig == NULL) { fprintf(stderr, "failed to ECDSA_SIG_new\n"); return UADK_P_FAIL; }
- br = BN_bin2bn((void *)r->data, r->dsize, NULL); - if (!br) { + bn_r = BN_bin2bn((void *)r->data, r->dsize, NULL); + if (bn_r == NULL) { fprintf(stderr, "failed to BN_bin2bn r\n"); goto free_sig; }
- bs = BN_bin2bn((void *)s->data, s->dsize, NULL); - if (!bs) { + bn_s = BN_bin2bn((void *)s->data, s->dsize, NULL); + if (bn_s == NULL) { fprintf(stderr, "failed to BN_bin2bn s\n"); goto free_r; }
- ret = ECDSA_SIG_set0(e_sig, br, bs); - if (!ret) { + ret = ECDSA_SIG_set0(e_sig, bn_r, bn_s); + if (ret == 0) { fprintf(stderr, "failed to ECDSA_SIG_set0\n"); goto free_s; } @@ -1166,9 +1166,9 @@ static int uadk_prov_sm2_sign_bin_to_ber(struct wd_dtb *r, struct wd_dtb *s, return UADK_P_SUCCESS;
free_s: - BN_free(bs); + BN_free(bn_s); free_r: - BN_free(br); + BN_free(bn_r); free_sig: ECDSA_SIG_free(e_sig);
@@ -1182,10 +1182,10 @@ static int uadk_prov_sm2_sign_ber_to_bin(unsigned char *sig, size_t sig_len, unsigned char *der = NULL; ECDSA_SIG *e_sig = NULL; int len1, len2; - BIGNUM *b_r, *b_s; + BIGNUM *bn_r, *bn_s;
e_sig = ECDSA_SIG_new(); - if (!e_sig) { + if (e_sig == NULL) { fprintf(stderr, "failed to ECDSA_SIG_new\n"); return UADK_P_FAIL; } @@ -1203,26 +1203,26 @@ static int uadk_prov_sm2_sign_ber_to_bin(unsigned char *sig, size_t sig_len, goto free_der; }
- b_r = (void *)ECDSA_SIG_get0_r((const ECDSA_SIG *)e_sig); - if (!b_r) { + bn_r = (void *)ECDSA_SIG_get0_r((const ECDSA_SIG *)e_sig); + if (bn_r == NULL) { fprintf(stderr, "failed to get r\n"); goto free_der; }
- b_s = (void *)ECDSA_SIG_get0_s((const ECDSA_SIG *)e_sig); - if (!b_s) { + bn_s = (void *)ECDSA_SIG_get0_s((const ECDSA_SIG *)e_sig); + if (bn_s == NULL) { fprintf(stderr, "failed to get s\n"); goto free_der; }
- len1 = BN_num_bytes(b_r); - len2 = BN_num_bytes(b_s); + len1 = BN_num_bytes(bn_r); + len2 = BN_num_bytes(bn_s); if (len1 > UADK_ECC_MAX_KEY_BYTES || len2 > UADK_ECC_MAX_KEY_BYTES) { fprintf(stderr, "r or s bytes = (%d, %d) error\n", len1, len2); goto free_der; } - r->dsize = BN_bn2bin(b_r, (void *)r->data); - s->dsize = BN_bn2bin(b_s, (void *)s->data); + r->dsize = BN_bn2bin(bn_r, (void *)r->data); + s->dsize = BN_bn2bin(bn_s, (void *)s->data);
OPENSSL_free(der); ECDSA_SIG_free(e_sig); @@ -1262,7 +1262,7 @@ static int uadk_prov_sm2_sign(PROV_SM2_SIGN_CTX *psm2ctx, }
wd_sm2_get_sign_out_params(req.dst, &r, &s); - if (!r || !s) { + if (r == NULL || s == NULL) { fprintf(stderr, "failed to get sign result\n"); return UADK_P_FAIL; } @@ -1345,7 +1345,7 @@ static int uadk_prov_sm2_verify_init_iot(handle_t sess, struct wd_ecc_req *req, struct wd_ecc_in *ecc_in;
ecc_in = wd_sm2_new_verf_in(sess, e, r, s, NULL, 1); - if (!ecc_in) { + if (ecc_in == NULL) { fprintf(stderr, "failed to new verf in\n"); return UADK_E_FAIL; } @@ -1599,34 +1599,34 @@ static int uadk_prov_check_pkey_point_param(struct sm2_param *param, EVP_MD_CTX return UADK_P_SUCCESS; }
-static int uadk_prov_get_sm2_param(struct sm2_param *sm2_param, BN_CTX *ctx) +static int uadk_prov_get_sm2_param(struct sm2_param *params, BN_CTX *ctx) { - sm2_param->p = BN_CTX_get(ctx); - if (!sm2_param->p) + params->p = BN_CTX_get(ctx); + if (params->p == NULL) goto end;
- sm2_param->a = BN_CTX_get(ctx); - if (!sm2_param->a) + params->a = BN_CTX_get(ctx); + if (params->a == NULL) goto end;
- sm2_param->b = BN_CTX_get(ctx); - if (!sm2_param->b) + params->b = BN_CTX_get(ctx); + if (params->b == NULL) goto end;
- sm2_param->xG = BN_CTX_get(ctx); - if (!sm2_param->xG) + params->xG = BN_CTX_get(ctx); + if (params->xG == NULL) goto end;
- sm2_param->yG = BN_CTX_get(ctx); - if (!sm2_param->yG) + params->yG = BN_CTX_get(ctx); + if (params->yG == NULL) goto end;
- sm2_param->xA = BN_CTX_get(ctx); - if (!sm2_param->xA) + params->xA = BN_CTX_get(ctx); + if (params->xA == NULL) goto end;
- sm2_param->yA = BN_CTX_get(ctx); - if (!sm2_param->yA) + params->yA = BN_CTX_get(ctx); + if (params->yA == NULL) goto end;
return UADK_P_SUCCESS; @@ -1682,7 +1682,7 @@ static int uadk_prov_sm2_compute_z_digest(uint8_t *out, const EVP_MD *digest, const EC_KEY *key) { const EC_GROUP *group = EC_KEY_get0_group(key); - struct sm2_param *param = NULL; + struct sm2_param *params = NULL; int ret = UADK_P_FAIL; uint8_t *buf = NULL; BN_CTX *ctx = NULL; @@ -1697,43 +1697,43 @@ static int uadk_prov_sm2_compute_z_digest(uint8_t *out, const EVP_MD *digest, if (ctx == NULL) goto free_hash;
- param = OPENSSL_zalloc(sizeof(struct sm2_param)); - if (param == NULL) { + params = OPENSSL_zalloc(sizeof(struct sm2_param)); + if (params == NULL) { fprintf(stderr, "failed to malloc sm2 param\n"); goto free_ctx; }
- if (uadk_prov_get_sm2_param(param, ctx) == UADK_P_FAIL) - goto free_param; + if (uadk_prov_get_sm2_param(params, ctx) == UADK_P_FAIL) + goto free_params;
if (uadk_prov_check_digest_evp_lib(digest, hash, id_len, id) == UADK_P_FAIL) - goto free_param; + goto free_params;
- if (EC_GROUP_get_curve(group, param->p, param->a, param->b, ctx) == 0) { + if (EC_GROUP_get_curve(group, params->p, params->a, params->b, ctx) == 0) { fprintf(stderr, "failed to EC_GROUP_get_curve\n"); - goto free_param; + goto free_params; }
- p_bytes = BN_num_bytes(param->p); + p_bytes = BN_num_bytes(params->p); buf = OPENSSL_zalloc(p_bytes); if (buf == NULL) { fprintf(stderr, "failed to alloc buffer\n"); - goto free_param; + goto free_params; }
- if (!uadk_prov_check_equation_param(param, hash, buf, p_bytes) || - !uadk_prov_check_base_point_group_param(param, ctx, key) || - !uadk_prov_check_base_point_param(param, hash, buf, p_bytes) || - !uadk_prov_check_pkey_point_group_param(param, ctx, key) || - !uadk_prov_check_pkey_point_param(param, hash, buf, p_bytes, out)) + if (!uadk_prov_check_equation_param(params, hash, buf, p_bytes) || + !uadk_prov_check_base_point_group_param(params, ctx, key) || + !uadk_prov_check_base_point_param(params, hash, buf, p_bytes) || + !uadk_prov_check_pkey_point_group_param(params, ctx, key) || + !uadk_prov_check_pkey_point_param(params, hash, buf, p_bytes, out)) goto free_buf;
ret = UADK_P_SUCCESS;
free_buf: OPENSSL_free(buf); -free_param: - OPENSSL_free(param); +free_params: + OPENSSL_free(params); free_ctx: BN_CTX_free(ctx); free_hash: @@ -1788,13 +1788,13 @@ static int uadk_signature_sm2_digest_sign_update(void *vpsm2ctx, const unsigned int ret;
if (psm2ctx == NULL) { - fprintf(stderr, "invalid: sign update psm2ctx is NULL\n"); + fprintf(stderr, "invalid: psm2ctx is NULL in digest sign update\n"); return UADK_P_FAIL; }
smctx = psm2ctx->sm2_pctx; if (smctx == NULL) { - fprintf(stderr, "invalid smctx is NULL in compute z digest\n"); + fprintf(stderr, "invalid: smctx is NULL in compute z digest\n"); return UADK_P_FAIL; }
@@ -2433,7 +2433,7 @@ static int uadk_prov_sm2_encrypt_check(PROV_SM2_ASYM_CTX *psm2ctx, const EVP_MD *md; int c3_size;
- if (!smctx || !smctx->sess) { + if (smctx == NULL || smctx->sess == (handle_t)0) { fprintf(stderr, "smctx or sess NULL\n"); return UADK_P_FAIL; } @@ -2476,7 +2476,7 @@ static int uadk_prov_sm2_encrypt_init_iot(handle_t sess, struct wd_ecc_req *req, struct wd_dtb e = {0};
ecc_out = wd_sm2_new_enc_out(sess, inlen); - if (!ecc_out) { + if (ecc_out == NULL) { fprintf(stderr, "failed to new enc out\n"); return UADK_P_FAIL; } @@ -2484,7 +2484,7 @@ static int uadk_prov_sm2_encrypt_init_iot(handle_t sess, struct wd_ecc_req *req, e.data = (void *)in; e.dsize = inlen; ecc_in = wd_sm2_new_enc_in(sess, NULL, &e); - if (!ecc_in) { + if (ecc_in == NULL) { fprintf(stderr, "failed to new enc in\n"); wd_ecc_del_out(sess, ecc_out); return UADK_P_FAIL; @@ -2499,58 +2499,58 @@ static int uadk_prov_sm2_asym_bin_to_ber(struct wd_ecc_point *c1, struct wd_dtb *c2, struct wd_dtb *c3, unsigned char *ber, size_t *ber_len) { - struct sm2_ciphertext ctext_struct; - int ciphertext_leni, ret; + struct sm2_ciphertext ctext; + int ctext_leni, ret; BIGNUM *x1, *y1;
x1 = BN_bin2bn((void *)c1->x.data, c1->x.dsize, NULL); - if (!x1) { + if (x1 == NULL) { fprintf(stderr, "failed to BN_bin2bn x1\n"); return UADK_P_FAIL; }
y1 = BN_bin2bn((void *)c1->y.data, c1->y.dsize, NULL); - if (!y1) { + if (y1 == NULL) { fprintf(stderr, "failed to BN_bin2bn y1\n"); ret = UADK_P_FAIL; goto free_x1; }
- ctext_struct.C1x = x1; - ctext_struct.C1y = y1; - ctext_struct.C3 = ASN1_OCTET_STRING_new(); - if (!ctext_struct.C3) { + ctext.C1x = x1; + ctext.C1y = y1; + ctext.C3 = ASN1_OCTET_STRING_new(); + if (ctext.C3 == NULL) { ret = UADK_P_FAIL; goto free_y1; }
- ret = ASN1_OCTET_STRING_set(ctext_struct.C3, (void *)c3->data, c3->dsize); - if (!ret) + ret = ASN1_OCTET_STRING_set(ctext.C3, (void *)c3->data, c3->dsize); + if (ret == 0) goto free_c3;
- ctext_struct.C2 = ASN1_OCTET_STRING_new(); - if (!ctext_struct.C2) { + ctext.C2 = ASN1_OCTET_STRING_new(); + if (ctext.C2 == NULL) { ret = UADK_P_FAIL; goto free_c3; }
- ret = ASN1_OCTET_STRING_set(ctext_struct.C2, (void *)c2->data, c2->dsize); - if (!ret) + ret = ASN1_OCTET_STRING_set(ctext.C2, (void *)c2->data, c2->dsize); + if (ret == 0) goto free_c2;
- ciphertext_leni = i2d_SM2_Ciphertext(&ctext_struct, &ber); + ctext_leni = i2d_SM2_Ciphertext(&ctext, &ber); /* Ensure cast to size_t is safe */ - if (ciphertext_leni < 0) { + if (ctext_leni < 0) { ret = UADK_P_FAIL; goto free_c2; } - *ber_len = (size_t)ciphertext_leni; + *ber_len = (size_t)ctext_leni; ret = UADK_P_SUCCESS;
free_c2: - ASN1_OCTET_STRING_free(ctext_struct.C2); + ASN1_OCTET_STRING_free(ctext.C2); free_c3: - ASN1_OCTET_STRING_free(ctext_struct.C3); + ASN1_OCTET_STRING_free(ctext.C3); free_y1: BN_free(y1); free_x1: @@ -2586,7 +2586,7 @@ static int uadk_prov_sm2_encrypt(PROV_SM2_ASYM_CTX *vpsm2ctx, }
wd_sm2_get_enc_out_params(req.dst, &c1, &c2, &c3); - if (!c1 || !c2 || !c3) + if (c1 == NULL || c2 == NULL || c3 == NULL) goto uninit_iot;
ret = uadk_prov_sm2_asym_bin_to_ber(c1, c2, c3, out, outlen); @@ -2715,7 +2715,7 @@ static int uadk_prov_sm2_decrypt_check(SM2_PROV_CTX *smctx, const EVP_MD *md; int hash_size;
- if (!smctx || !smctx->sess) { + if (smctx == NULL || smctx->sess == (handle_t)0) { fprintf(stderr, "smctx or sess NULL\n"); return UADK_P_FAIL; } @@ -2745,29 +2745,29 @@ static int uadk_prov_sm2_decrypt_check(SM2_PROV_CTX *smctx, return UADK_P_SUCCESS; }
-static int uadk_prov_sm2_asym_ber_to_bin(const EVP_MD *md, struct sm2_ciphertext *ctext_struct, +static int uadk_prov_sm2_asym_ber_to_bin(const EVP_MD *md, struct sm2_ciphertext *ctext, struct wd_ecc_point *c1, struct wd_dtb *c2, struct wd_dtb *c3) { - int len, len1, md_size; + int c1x_len, c1y_len, md_size;
if (md == NULL) { fprintf(stderr, "invalid: md is NULL\n"); return UADK_P_FAIL; }
- len = BN_num_bytes(ctext_struct->C1x); - len1 = BN_num_bytes(ctext_struct->C1y); - c1->x.data = malloc(len + len1 + ctext_struct->C2->length + ctext_struct->C3->length); - if (!c1->x.data) + c1x_len = BN_num_bytes(ctext->C1x); + c1y_len = BN_num_bytes(ctext->C1y); + c1->x.data = malloc(c1x_len + c1y_len + ctext->C2->length + ctext->C3->length); + if (c1->x.data == NULL) return UADK_P_FAIL;
- c1->y.data = c1->x.data + len; - c3->data = c1->y.data + len1; - c2->data = c3->data + ctext_struct->C3->length; - memcpy(c2->data, ctext_struct->C2->data, ctext_struct->C2->length); - memcpy(c3->data, ctext_struct->C3->data, ctext_struct->C3->length); - c2->dsize = ctext_struct->C2->length; - c3->dsize = ctext_struct->C3->length; + c1->y.data = c1->x.data + c1x_len; + c3->data = c1->y.data + c1y_len; + c2->data = c3->data + ctext->C3->length; + memcpy(c2->data, ctext->C2->data, ctext->C2->length); + memcpy(c3->data, ctext->C3->data, ctext->C3->length); + c2->dsize = ctext->C2->length; + c3->dsize = ctext->C3->length; md_size = EVP_MD_size(md); if (c3->dsize != md_size) { fprintf(stderr, "invalid: c3 dsize(%u) != hash_size(%d)\n", c3->dsize, md_size); @@ -2775,8 +2775,8 @@ static int uadk_prov_sm2_asym_ber_to_bin(const EVP_MD *md, struct sm2_ciphertext return UADK_P_FAIL; }
- c1->x.dsize = BN_bn2bin(ctext_struct->C1x, (void *)c1->x.data); - c1->y.dsize = BN_bn2bin(ctext_struct->C1y, (void *)c1->y.data); + c1->x.dsize = BN_bn2bin(ctext->C1x, (void *)c1->x.data); + c1->y.dsize = BN_bn2bin(ctext->C1y, (void *)c1->y.data);
return UADK_P_SUCCESS; } @@ -2788,13 +2788,13 @@ static int uadk_prov_sm2_decrypt_init_iot(handle_t sess, struct wd_ecc_req *req, struct wd_ecc_in *ecc_in;
ecc_out = wd_sm2_new_dec_out(sess, c2->dsize); - if (!ecc_out) { + if (ecc_out == NULL) { fprintf(stderr, "failed to new dec out\n"); return UADK_P_FAIL; }
ecc_in = wd_sm2_new_dec_in(sess, c1, c2, c3); - if (!ecc_in) { + if (ecc_in == NULL) { fprintf(stderr, "failed to new dec in\n"); wd_ecc_del_out(sess, ecc_out); return UADK_P_FAIL; @@ -2811,7 +2811,7 @@ static int uadk_prov_sm2_get_plaintext(struct wd_ecc_req *req, struct wd_dtb *ptext = NULL;
wd_sm2_get_dec_out_params(req->dst, &ptext); - if (!ptext) { + if (ptext == NULL) { fprintf(stderr, "failed to get ptext\n"); return UADK_P_FAIL; } @@ -2832,7 +2832,7 @@ static int uadk_prov_sm2_decrypt(PROV_SM2_ASYM_CTX *ctx, const unsigned char *in, size_t inlen) { SM2_PROV_CTX *smctx = ctx->sm2_pctx; - struct sm2_ciphertext *ctext_struct; + struct sm2_ciphertext *ctext; struct wd_ecc_req req = {0}; struct wd_ecc_point c1; struct wd_dtb c2, c3; @@ -2843,12 +2843,12 @@ static int uadk_prov_sm2_decrypt(PROV_SM2_ASYM_CTX *ctx, if (ret == UADK_P_FAIL) return ret;
- ctext_struct = d2i_SM2_Ciphertext(NULL, &in, inlen); - if (ctext_struct == NULL) + ctext = d2i_SM2_Ciphertext(NULL, &in, inlen); + if (ctext == NULL) return UADK_P_FAIL;
md = (smctx->sm2_md->md == NULL) ? EVP_sm3() : smctx->sm2_md->md; - ret = uadk_prov_sm2_asym_ber_to_bin(md, ctext_struct, &c1, &c2, &c3); + ret = uadk_prov_sm2_asym_ber_to_bin(md, ctext, &c1, &c2, &c3); if (ret == UADK_P_FAIL) goto free_ctext;
@@ -2873,7 +2873,7 @@ static int uadk_prov_sm2_decrypt(PROV_SM2_ASYM_CTX *ctx, wd_ecc_del_in(smctx->sess, req.src); wd_ecc_del_out(smctx->sess, req.dst); free(c1.x.data); - SM2_Ciphertext_free(ctext_struct); + SM2_Ciphertext_free(ctext);
return UADK_P_SUCCESS;
@@ -2883,7 +2883,7 @@ uninit_iot: free_c1: free(c1.x.data); free_ctext: - SM2_Ciphertext_free(ctext_struct); + SM2_Ciphertext_free(ctext); return UADK_P_FAIL; }
@@ -2892,7 +2892,7 @@ static int uadk_prov_sm2_plaintext_size(const unsigned char *ct, size_t ct_size, struct sm2_ciphertext *sm2_ctext;
sm2_ctext = d2i_SM2_Ciphertext(NULL, &ct, ct_size); - if (!sm2_ctext) { + if (sm2_ctext == NULL) { fprintf(stderr, "invalid sm2 encoding\n"); return UADK_P_FAIL; }
From: Zhiqi Song songzhiqi1@huawei.com
Modify the definition method of alg_name when passing it to wd_xxx_init2() function, fixing the compile waring: 'discards 'const' qulifier from pointer type'.
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- src/uadk_prov_dh.c | 3 ++- src/uadk_prov_rsa.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/uadk_prov_dh.c b/src/uadk_prov_dh.c index a6a20a8..e5c956c 100644 --- a/src/uadk_prov_dh.c +++ b/src/uadk_prov_dh.c @@ -583,12 +583,13 @@ static void uadk_prov_dh_mutex_infork(void)
static int uadk_prov_dh_init(void) { + char alg_name[] = "dh"; int ret;
pthread_atfork(NULL, NULL, uadk_prov_dh_mutex_infork); pthread_mutex_lock(&dh_mutex); if (g_dh_prov.pid != getpid()) { - ret = wd_dh_init2("dh", SCHED_POLICY_RR, TASK_HW); + ret = wd_dh_init2(alg_name, SCHED_POLICY_RR, TASK_HW); if (unlikely(ret)) { pthread_mutex_unlock(&dh_mutex); return ret; diff --git a/src/uadk_prov_rsa.c b/src/uadk_prov_rsa.c index 563a0e5..9872b27 100644 --- a/src/uadk_prov_rsa.c +++ b/src/uadk_prov_rsa.c @@ -1024,12 +1024,13 @@ static void uadk_rsa_mutex_infork(void)
static int uadk_prov_rsa_init(void) { + char alg_name[] = "rsa"; int ret;
pthread_atfork(NULL, NULL, uadk_rsa_mutex_infork); pthread_mutex_lock(&rsa_mutex); if (g_rsa_prov.pid != getpid()) { - ret = wd_rsa_init2("rsa", SCHED_POLICY_RR, TASK_MIX); + ret = wd_rsa_init2(alg_name, SCHED_POLICY_RR, TASK_MIX); if (unlikely(ret)) { pthread_mutex_unlock(&rsa_mutex); return ret;