From: Chenghai Huang huangchenghai2@huawei.com
1.The input and output pointers of the digest_digest interface can be directly used and do not need to be copied. 2. OPENSSL_clear_free can set pointer to zero and does not need to be set to NULL. 3.Pointer type conversion is added to avoid compilation alarms of inconsistent types. 4.Adjust the registration position of the digest function to avoid compilation alarms: note: previous definition of 'uadk_prov_freectx' was here 491 | static void uadk_prov_freectx(void *dctx) | ^~~~~~~~~~~~~~~~~ 5.Add a NULL pointer checking for cipher freectx.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- src/uadk_prov_aead.c | 12 +++--------- src/uadk_prov_cipher.c | 3 +++ src/uadk_prov_digest.c | 35 +++++++++++++++-------------------- 3 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/src/uadk_prov_aead.c b/src/uadk_prov_aead.c index 9861519..d5f860e 100644 --- a/src/uadk_prov_aead.c +++ b/src/uadk_prov_aead.c @@ -944,17 +944,11 @@ static void uadk_prov_aead_freectx(void *ctx) if (!ctx) return;
- if (priv->sess) { + if (priv->sess) wd_aead_free_sess(priv->sess); - priv->sess = 0; - } -
- if (priv->data) { + if (priv->data) OPENSSL_clear_free(priv->data, AEAD_BLOCK_SIZE << 1); - priv->data = NULL; - } -
OPENSSL_clear_free(priv, sizeof(*priv)); } @@ -968,7 +962,7 @@ static void *uadk_##nm##_newctx(void *provctx) \ if (!ctx) \ return NULL; \ \ - ctx->data = OPENSSL_clear_free(ctx, sizeof(*ctx)); \ + ctx->data = OPENSSL_zalloc(AEAD_BLOCK_SIZE << 1); \ if (!ctx->data) { \ OPENSSL_free(ctx); \ return NULL; \ diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index f4a182e..04a6489 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -1265,6 +1265,9 @@ static void uadk_prov_cipher_freectx(void *ctx) { struct cipher_priv_ctx *priv = (struct cipher_priv_ctx *)ctx;
+ if (ctx == NULL) + return; + if (priv->sw_cipher) EVP_CIPHER_free(priv->sw_cipher);
diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 0810629..d78475d 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -636,7 +636,7 @@ static int uadk_digest_digest(struct digest_priv_ctx *priv, const void *data, si struct async_op op; int ret;
- if (!priv->data) { + if (!data) { fprintf(stderr, "failed to do single digest, data in CTX is NULL.\n"); return UADK_DIGEST_FAIL; } @@ -651,11 +651,9 @@ static int uadk_digest_digest(struct digest_priv_ctx *priv, const void *data, si return UADK_DIGEST_FAIL; }
- priv->req.in = priv->data; - priv->req.out = priv->out; + priv->req.in = data; + priv->req.out = digest; priv->req.in_bytes = data_len; - uadk_memcpy(priv->data, data, data_len); - uadk_digest_set_msg_state(priv, true); uadk_fill_mac_buffer_len(priv, true);
@@ -669,25 +667,31 @@ static int uadk_digest_digest(struct digest_priv_ctx *priv, const void *data, si async_clear_async_event_notification(); return ret; } - memcpy(digest, priv->req.out, priv->req.out_bytes);
return UADK_DIGEST_SUCCESS; }
static void uadk_digest_cleanup(struct digest_priv_ctx *priv) { - if (priv->sess) { + if (priv->sess) wd_digest_free_sess(priv->sess); - priv->sess = 0; - }
if (priv->data) - OPENSSL_free(priv->data); + OPENSSL_clear_free(priv->data, DIGEST_BLOCK_SIZE);
if (priv->soft_ctx) - OPENSSL_free(priv->data); + OPENSSL_clear_free(priv->soft_ctx, sizeof(EVP_MD_CTX)); }
+static OSSL_FUNC_digest_freectx_fn uadk_prov_freectx; +static OSSL_FUNC_digest_dupctx_fn uadk_prov_dupctx; +static OSSL_FUNC_digest_init_fn uadk_prov_init; +static OSSL_FUNC_digest_update_fn uadk_prov_update; +static OSSL_FUNC_digest_final_fn uadk_prov_final; +static OSSL_FUNC_digest_digest_fn uadk_prov_digest; +static OSSL_FUNC_digest_gettable_params_fn + uadk_prov_gettable_params; + /* some params related code is copied from OpenSSL v3.0 prov/digestcommon.h */ static const OSSL_PARAM uadk_digest_default_known_gettable_params[] = { OSSL_PARAM_size_t(OSSL_DIGEST_PARAM_BLOCK_SIZE, NULL), @@ -896,15 +900,6 @@ void uadk_prov_destroy_digest(void) pthread_mutex_unlock(&digest_mutex); }
-static OSSL_FUNC_digest_freectx_fn uadk_prov_freectx; -static OSSL_FUNC_digest_dupctx_fn uadk_prov_dupctx; -static OSSL_FUNC_digest_init_fn uadk_prov_init; -static OSSL_FUNC_digest_update_fn uadk_prov_update; -static OSSL_FUNC_digest_final_fn uadk_prov_final; -static OSSL_FUNC_digest_digest_fn uadk_prov_digest; -static OSSL_FUNC_digest_gettable_params_fn - uadk_prov_gettable_params; - #define UADK_PROVIDER_IMPLEMENTATION(name, nid, mdsize, blksize) \ static OSSL_FUNC_digest_newctx_fn uadk_##name##_newctx; \ static void *uadk_##name##_newctx(void *provctx) \