Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/uadk_dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,15 @@ static int dh_do_async(struct uadk_dh_sess *dh_sess, struct async_op *op)
do {
ret = wd_do_dh_async(dh_sess->sess, &dh_sess->req);
if (unlikely(ret < 0)) {
if (unlikely(ret == -WD_HW_EACCESS))
uadk_e_dh_set_status();
else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
if (unlikely(ret != -EBUSY)) {
fprintf(stderr, "do dh async operation failed.\n");
if (unlikely(ret == -WD_HW_EACCESS))
uadk_e_dh_set_status();
} else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT)) {
fprintf(stderr, "do dh async operation timeout.\n");
else
} else {
continue;
}

async_free_poll_task(op->idx, 0);
ret = UADK_E_FAIL;
Expand Down
15 changes: 13 additions & 2 deletions src/uadk_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,15 @@ static int ecdh_keygen_init_iot(handle_t sess, struct wd_ecc_req *req,
return 1;
}

static size_t ecdh_get_ec_size(const EC_GROUP *group)
{
size_t degree;

degree = EC_GROUP_get_degree(group);

return BITS_TO_BYTES(degree);
}

static int ecdh_compkey_init_iot(handle_t sess, struct wd_ecc_req *req,
const EC_POINT *pubkey, const EC_KEY *ecdh)
{
Expand All @@ -1025,6 +1034,7 @@ static int ecdh_compkey_init_iot(handle_t sess, struct wd_ecc_req *req,
struct wd_ecc_in *ecdh_in;
BIGNUM *pkey_x, *pkey_y;
const EC_GROUP *group;
size_t ec_size;
BN_CTX *ctx;
int ret = 0;

Expand All @@ -1045,11 +1055,12 @@ static int ecdh_compkey_init_iot(handle_t sess, struct wd_ecc_req *req,
if (!group)
goto free_ctx;

ec_size = ecdh_get_ec_size(group);
uadk_get_affine_coordinates(group, pubkey, pkey_x, pkey_y, ctx);
in_pkey.x.data = buf_x;
in_pkey.y.data = buf_y;
in_pkey.x.dsize = BN_bn2bin(pkey_x, (unsigned char *)in_pkey.x.data);
in_pkey.y.dsize = BN_bn2bin(pkey_y, (unsigned char *)in_pkey.y.data);
in_pkey.x.dsize = BN_bn2binpad(pkey_x, (unsigned char *)in_pkey.x.data, ec_size);
in_pkey.y.dsize = BN_bn2binpad(pkey_y, (unsigned char *)in_pkey.y.data, ec_size);

/* Set public key */
ecdh_in = wd_ecxdh_new_in(sess, &in_pkey);
Expand Down
11 changes: 7 additions & 4 deletions src/uadk_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,15 @@ static int uadk_ecc_do_async(handle_t sess, struct wd_ecc_req *req,
do {
ret = wd_do_ecc_async(sess, req);
if (unlikely(ret < 0)) {
if (unlikely(ret == -WD_HW_EACCESS))
uadk_e_ecc_set_status();
else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT))
if (unlikely(ret != -EBUSY)) {
fprintf(stderr, "do ecc async operation failed.\n");
if (unlikely(ret == -WD_HW_EACCESS))
uadk_e_ecc_set_status();
} else if (unlikely(cnt++ > ENGINE_SEND_MAX_CNT)) {
fprintf(stderr, "do ecc async operation timeout.\n");
else
} else {
continue;
}

async_free_poll_task(op->idx, 0);
ret = 0;
Expand Down
15 changes: 2 additions & 13 deletions src/uadk_prov_aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,8 @@ static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char
{
int ret;

if (inlen > MAX_AAD_LEN) {
if (priv->mode != ASYNC_MODE)
goto soft;

UADK_ERR("the aad len is out of range, aad len = %zu.\n", inlen);
return UADK_AEAD_FAIL;
}
if (inlen > MAX_AAD_LEN || !inlen)
goto soft;

priv->req.assoc_bytes = inlen;

Expand All @@ -590,9 +585,6 @@ static int uadk_prov_do_aes_gcm_first(struct aead_priv_ctx *priv, unsigned char
return UADK_AEAD_SUCCESS;
}

if (!priv->req.assoc_bytes)
goto soft;

ret = uadk_do_aead_sync_inner(priv, out, in, inlen, AEAD_MSG_FIRST);
if (unlikely(ret < 0))
goto soft;
Expand Down Expand Up @@ -858,9 +850,6 @@ static int uadk_prov_aead_init(struct aead_priv_ctx *priv, const unsigned char *

ret = uadk_prov_aead_dev_init(priv);
if (unlikely(ret < 0)) {
if (ASYNC_get_current_job())
return UADK_OSSL_FAIL;

UADK_ERR("aead switch to soft init.!\n");
return uadk_prov_aead_soft_init(priv, key, iv, params);
}
Expand Down
43 changes: 22 additions & 21 deletions src/uadk_prov_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,7 @@ static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *o
{
struct uadk_e_cb_info cb_param;
int idx, ret;

if (unlikely(priv->switch_flag == UADK_DO_SOFT)) {
UADK_ERR("async cipher init failed.\n");
return UADK_P_FAIL;
}
int cnt = 0;

cb_param.op = op;
cb_param.priv = &priv->req;
Expand All @@ -506,18 +502,29 @@ static int uadk_do_cipher_async(struct cipher_priv_ctx *priv, struct async_op *o
op->idx = idx;
do {
ret = wd_do_cipher_async(priv->sess, &priv->req);
if (ret < 0 && ret != -EBUSY) {
UADK_ERR("do sec cipher failed, switch to soft cipher.\n");
async_free_poll_task(op->idx, 0);
return UADK_P_FAIL;
if (likely(!ret))
break;

if (ret != -EBUSY) {
UADK_ERR("failed to do cipher async\n");
goto free_poll_task;
}

if (unlikely(++cnt > PROV_SEND_MAX_CNT)) {
UADK_ERR("do cipher async operation timeout\n");
goto free_poll_task;
}
} while (ret == -EBUSY);
} while (true);

ret = async_pause_job(priv, op, ASYNC_TASK_CIPHER);
if (!ret || priv->req.state)
return UADK_P_FAIL;

return UADK_P_SUCCESS;

free_poll_task:
async_free_poll_task(op->idx, 0);
return UADK_P_FAIL;
}

static void uadk_cipher_mutex_infork(void)
Expand Down Expand Up @@ -756,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;
Expand Down
7 changes: 5 additions & 2 deletions src/uadk_prov_dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,10 @@ static int uadk_prov_dh_do_crypto(struct uadk_dh_sess *dh_sess)
cnt = 0;
do {
ret = wd_do_dh_async(dh_sess->sess, &dh_sess->req);
if (ret < 0 && ret != -EBUSY) {
if (likely(!ret))
break;

if (ret != -EBUSY) {
UADK_ERR("failed to do dh async\n");
goto free_poll_task;
}
Expand All @@ -934,7 +937,7 @@ static int uadk_prov_dh_do_crypto(struct uadk_dh_sess *dh_sess)
UADK_ERR("do dh async operation timeout\n");
goto free_poll_task;
}
} while (ret == -EBUSY);
} while (true);

ret = async_pause_job(dh_sess, &op, ASYNC_TASK_DH);
if (!ret)
Expand Down
47 changes: 20 additions & 27 deletions src/uadk_prov_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -625,16 +620,19 @@ static int uadk_do_digest_async(struct digest_priv_ctx *priv, struct async_op *o

do {
ret = wd_do_digest_async(priv->sess, &priv->req);
if (ret < 0 && ret != -EBUSY) {
UADK_ERR("do sec digest async failed.\n");
if (likely(!ret))
break;

if (ret != -EBUSY) {
UADK_ERR("do digest async failed.\n");
goto free_poll_task;
}

if (unlikely(++cnt > ENGINE_SEND_MAX_CNT)) {
UADK_ERR("do digest async operation timeout.\n");
goto free_poll_task;
}
} while (ret == -EBUSY);
} while (true);

ret = async_pause_job(priv, op, ASYNC_TASK_DIGEST);
if (!ret || priv->req.state)
Expand All @@ -657,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;
Expand All @@ -676,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;
Expand All @@ -703,8 +696,8 @@ static int uadk_digest_final(struct digest_priv_ctx *priv, unsigned char *digest
ret = UADK_DIGEST_FAIL;
UADK_ERR("do sec digest final failed.\n");
}
clear:
async_clear_async_event_notification();

return ret;
}

Expand Down
6 changes: 4 additions & 2 deletions src/uadk_prov_ecdh_exch.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ static int ecdh_init_req(struct ecdh_sess_ctx *sess_ctx,
struct wd_ecc_in *ecdh_in;
BIGNUM *pkey_x, *pkey_y;
int ret = UADK_P_FAIL;
size_t ec_size;
BN_CTX *ctx;

ctx = BN_CTX_new();
Expand All @@ -231,11 +232,12 @@ static int ecdh_init_req(struct ecdh_sess_ctx *sess_ctx,
if (!pkey_y)
goto free_ctx;

ec_size = ecdh_get_ec_size(sess_ctx->group);
uadk_prov_get_affine_coordinates(sess_ctx->group, sess_ctx->pub_key, pkey_x, pkey_y, ctx);
in_pkey.x.data = buf_x;
in_pkey.y.data = buf_y;
in_pkey.x.dsize = BN_bn2bin(pkey_x, (unsigned char *)in_pkey.x.data);
in_pkey.y.dsize = BN_bn2bin(pkey_y, (unsigned char *)in_pkey.y.data);
in_pkey.x.dsize = BN_bn2binpad(pkey_x, (unsigned char *)in_pkey.x.data, ec_size);
in_pkey.y.dsize = BN_bn2binpad(pkey_y, (unsigned char *)in_pkey.y.data, ec_size);

/* Set public key */
ecdh_in = wd_ecxdh_new_in(sess, &in_pkey);
Expand Down
Loading
Loading