libwd/0119-uadk-ecc-fix-the-use-of-random-k-in-sm2-sign.patch
Younger 5c995b2464 libwd - update some patches
Update some patches for 2203-SP3 only.

Signed-off-by: Yang Shen <shenyang39@huawei.com>
2024-05-24 09:59:01 +08:00

98 lines
2.8 KiB
Diff

From 9212bec7dd58c8390f4a1b9345f64d112291a4d0 Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Thu, 7 Dec 2023 19:19:05 +0800
Subject: [PATCH 119/123] uadk/ecc: fix the use of random k in sm2 sign
Fix the problem that can not get random k when do not set
the value or callback function. There are three ways to
use random k in sm2 sign, fix to support them all in v1
and v2:
- If k is not set and cb has been set, use cb to generate
random k.
- If k is set or has been generated by cb, directly set k.
- If k and cb are not set, hw driver should config to
generate random k.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
v1/wd_ecc.c | 17 +++++++++--------
wd_ecc.c | 15 +++++++++------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index 02f63bf..3da55d2 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -1803,11 +1803,6 @@ static int generate_random(struct wcrypto_ecc_ctx *ctx, struct wd_dtb *k)
struct wcrypto_rand_mt *rand_mt = &ctx->setup.rand;
int ret;
- if (!rand_mt->cb) {
- WD_ERR("failed to get rand cb!\n");
- return -WD_EINVAL;
- }
-
ret = rand_mt->cb(k->data, k->dsize, rand_mt->usr);
if (unlikely(ret))
WD_ERR("failed to rand cb: ret = %d!\n", ret);
@@ -1938,14 +1933,20 @@ static struct wcrypto_ecc_in *new_sign_in(struct wcrypto_ecc_ctx *ctx,
return NULL;
sin = &ecc_in->param.sin;
- if (!k) {
+ sin->k_set = 0;
+ sin->dgst_set = 0;
+
+ /*
+ * If k is not set and cb has been set, use cb to generate random k.
+ * If k is set or has been generated by cb, directly set k.
+ * If k and cb are not set, hw driver should config to generate random k.
+ */
+ if (!k && cx->setup.rand.cb) {
ret = generate_random(cx, &sin->k);
if (unlikely(ret))
goto release_in;
}
- sin->k_set = 0;
- sin->dgst_set = 0;
if (k || cx->setup.rand.cb)
sin->k_set = 1;
diff --git a/wd_ecc.c b/wd_ecc.c
index 97c758c..710f1a0 100644
--- a/wd_ecc.c
+++ b/wd_ecc.c
@@ -1635,11 +1635,6 @@ static int generate_random(struct wd_ecc_sess *sess, struct wd_dtb *k)
struct wd_rand_mt rand_t = sess->setup.rand;
int ret;
- if (!rand_t.cb) {
- WD_ERR("failed to get rand cb!\n");
- return -WD_EINVAL;
- }
-
ret = rand_t.cb(k->data, k->dsize, rand_t.usr);
if (ret)
WD_ERR("failed to do rand cb, ret = %d!\n", ret);
@@ -1769,7 +1764,15 @@ static struct wd_ecc_in *new_sign_in(struct wd_ecc_sess *sess,
return NULL;
sin = &ecc_in->param.sin;
- if (!k) {
+ sin->k_set = 0;
+ sin->dgst_set = 0;
+
+ /*
+ * If k is not set and cb has been set, use cb to generate random k.
+ * If k is set or has been generated by cb, directly set k.
+ * If k and cb are not set, hw driver should config to generate random k.
+ */
+ if (!k && sess_t->setup.rand.cb) {
ret = generate_random(sess_t, &sin->k);
if (ret)
goto release_in;
--
2.31.1.windows.1