From: Zhushuai Yin <yinzhushuai@huawei.com> Currently, when an SEC device fails to be initialized, the asynchronous test case fails to be executed. This issue is resolved so that the asynchronous scenario can now switch from the hardware calculation to the software calculation after the hardware calculation fails. Signed-off-by: Zhushuai Yin <yinzhushuai@huawei.com> --- src/uadk_prov_cipher.c | 21 +++++---------------- src/uadk_prov_digest.c | 38 ++++++++++++++------------------------ src/uadk_prov_hmac.c | 38 +++++++++++++------------------------- 3 files changed, 32 insertions(+), 65 deletions(-) diff --git a/src/uadk_prov_cipher.c b/src/uadk_prov_cipher.c index 0c3023e..2606c2f 100644 --- a/src/uadk_prov_cipher.c +++ b/src/uadk_prov_cipher.c @@ -490,11 +490,6 @@ static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *o int idx, ret; int cnt = 0; - if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { - UADK_ERR("async cipher init failed.\n"); - return UADK_P_FAIL; - } - cb_param.op = op; cb_param.priv = &priv->req; priv->req.cb = (void *)async_cb; @@ -768,19 +763,13 @@ static int uadk_prov_hw_cipher(struct cipher_priv_ctx *priv, unsigned char *out, return UADK_P_FAIL; } - if (op.job == NULL) { - /* Synchronous, only the synchronous mode supports soft computing */ + if (op.job == NULL) ret = uadk_do_cipher_sync(priv); - if (!ret) { - async_clear_async_event_notification(); - return UADK_P_FAIL; - } - } else { + else ret = uadk_do_cipher_async(priv, &op); - if (!ret) { - async_clear_async_event_notification(); - return UADK_P_FAIL; - } + if (!ret) { + async_clear_async_event_notification(); + return UADK_P_FAIL; } return UADK_P_SUCCESS; diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index aaf3061..0f4cb87 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -606,11 +606,6 @@ static int uadk_do_digest_async(struct digest_priv_ctx *priv, struct async_op *o int idx, ret; int cnt = 0; - if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { - UADK_ERR("digest soft switching is not supported in asynchronous mode.\n"); - return UADK_DIGEST_FAIL; - } - cb_param.op = op; cb_param.priv = &priv->req; priv->req.cb = (void *)uadk_async_cb; @@ -660,12 +655,16 @@ static int uadk_digest_final(struct digest_priv_ctx *priv, unsigned char *digest return UADK_DIGEST_FAIL; } - if (unlikely(priv->switch_flag != UADK_DO_SOFT)) { - ret = uadk_digest_ctx_init(priv); - if (ret != UADK_DIGEST_SUCCESS) - return UADK_DIGEST_FAIL; + if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { + ret = uadk_digest_soft_final(priv, digest); + digest_soft_cleanup(priv); + return ret; } + ret = uadk_digest_ctx_init(priv); + if (ret != UADK_DIGEST_SUCCESS) + return UADK_DIGEST_FAIL; + priv->req.in = priv->data; priv->req.out = priv->out; priv->req.in_bytes = priv->last_update_bufflen; @@ -679,22 +678,13 @@ static int uadk_digest_final(struct digest_priv_ctx *priv, unsigned char *digest return UADK_DIGEST_FAIL; } - if (op.job == NULL) { - /* Synchronous, only the synchronous mode supports soft computing */ - if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { - ret = uadk_digest_soft_final(priv, digest); - digest_soft_cleanup(priv); - goto clear; - } - + if (op.job == NULL) ret = uadk_do_digest_sync(priv); - if (!ret) - goto sync_err; - } else { + else ret = uadk_do_digest_async(priv, &op); - if (!ret) - goto clear; - } + + if (!ret) + goto sync_err; memcpy(digest, priv->req.out, priv->req.out_bytes); return UADK_DIGEST_SUCCESS; @@ -706,8 +696,8 @@ sync_err: ret = UADK_DIGEST_FAIL; UADK_ERR("do sec digest final failed.\n"); } -clear: async_clear_async_event_notification(); + return ret; } diff --git a/src/uadk_prov_hmac.c b/src/uadk_prov_hmac.c index 96da4eb..5a88fe4 100644 --- a/src/uadk_prov_hmac.c +++ b/src/uadk_prov_hmac.c @@ -578,11 +578,6 @@ static int uadk_do_hmac_async(struct hmac_priv_ctx *priv, struct async_op *op) int idx, ret; int cnt = 0; - if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { - UADK_ERR("soft switching is not supported in asynchronous mode.\n"); - return UADK_P_FAIL; - } - cb_param.op = op; cb_param.priv = &priv->req; priv->req.cb = (void *)uadk_hmac_async_cb; @@ -750,13 +745,16 @@ static int uadk_hmac_final(struct hmac_priv_ctx *priv, unsigned char *digest) return UADK_P_FAIL; } - /* It dose not need to be initialized again if the software calculation is applied. */ - if (priv->switch_flag != UADK_DO_SOFT) { - ret = uadk_hmac_ctx_init(priv); - if (!ret) - return UADK_P_FAIL; + if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { + ret = uadk_hmac_soft_final(priv, digest); + hmac_soft_cleanup(priv); + return ret; } + ret = uadk_hmac_ctx_init(priv); + if (!ret) + return UADK_P_FAIL; + priv->req.in = priv->data; priv->req.out = priv->state == SEC_DIGEST_INIT ? digest : priv->out; priv->req.in_bytes = priv->last_update_bufflen; @@ -770,23 +768,13 @@ static int uadk_hmac_final(struct hmac_priv_ctx *priv, unsigned char *digest) return UADK_P_FAIL; } - if (!op.job) { - /* Synchronous, only the synchronous mode supports soft computing */ - if (unlikely(priv->switch_flag == UADK_DO_SOFT)) { - ret = uadk_hmac_soft_final(priv, digest); - hmac_soft_cleanup(priv); - goto clear; - } - + if (!op.job) ret = uadk_do_hmac_sync(priv); - if (!ret) - goto do_hmac_err; - } else { + else ret = uadk_do_hmac_async(priv, &op); - if (!ret) - goto clear; - } + if (!ret) + goto do_hmac_err; if (priv->state != SEC_DIGEST_INIT) memcpy(digest, priv->req.out, priv->req.out_bytes); @@ -801,8 +789,8 @@ do_hmac_err: ret = UADK_P_FAIL; UADK_ERR("do sec digest final failed.\n"); } -clear: async_clear_async_event_notification(); + return ret; } -- 2.43.0