Update the current driver adaptation and usage method, from fixed
use of Hisilicon device driver to automatic registration of the
driver according to the algorithm.
When the algorithm API layer uses the driver, it is no longer
bound to the fixed device driver, but dynamically obtained
and stored according to the algorithm query to use.
Update the driver and API layer of the zip and sec module, keep the
function of the init interface unchanged, update the implementation
of the init2 interface and match the dynamic loading function.
Changes v2 -> v3:
- Add dynamic library file search function
- Fix some memory handling issues
Changes v1 -> v2:
- Fixed the compatibility method with the previous library file loading
liulongfang (5):
uadk: Add driver dynamic loading function
uadk: added ability to query supported algorithms
uadk: improve the dynamic loading public framework
uadk/zip: Adapt the zip module to the dynamic loading framework
uadk/sec: adapt the sec module to the dynamic loading framework
Makefile.am | 4 +-
drv/hisi_comp.c | 59 +++-
drv/hisi_sec.c | 102 +++++--
include/drv/wd_aead_drv.h | 2 +-
include/drv/wd_cipher_drv.h | 26 --
include/drv/wd_comp_drv.h | 27 --
include/drv/wd_digest_drv.h | 2 +-
include/wd.h | 12 +
include/wd_alg.h | 95 +++++++
include/wd_alg_common.h | 11 +
include/wd_sched.h | 6 +-
include/wd_util.h | 63 ++++-
libwd.map | 8 +
libwd_crypto.map | 3 +
wd.c | 56 +++-
wd_alg.c | 265 +++++++++++++++++
wd_cipher.c | 305 +++++++++++++++-----
wd_comp.c | 293 ++++++++++---------
wd_sched.c | 105 ++++++-
wd_util.c | 547 +++++++++++++++++++++++++++++++++++-
20 files changed, 1697 insertions(+), 294 deletions(-)
create mode 100644 include/wd_alg.h
create mode 100644 wd_alg.c
--
2.33.0
When check whether a 'struct wd_dtb' type variable is all
zero, the length of the data should be the value of 'bsize'.
Directly using 'dsize' may truncate the data in some cases
and cause erroneous judgement.
Signed-off-by: Zhiqi Song <songzhiqi1(a)huawei.com>
---
drv/hisi_hpre.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_hpre.c b/drv/hisi_hpre.c
index aec2f57..9da2bd7 100644
--- a/drv/hisi_hpre.c
+++ b/drv/hisi_hpre.c
@@ -1056,11 +1056,16 @@ static void ecc_get_io_len(__u32 atype, __u32 hsz, size_t *ilen,
}
}
-static bool is_all_zero(struct wd_dtb *e, struct wd_ecc_msg *msg)
+static bool is_all_zero(struct wd_dtb *e)
{
int i;
- for (i = 0; i < e->dsize && i < msg->key_bytes; i++) {
+ if (!e || !e->data) {
+ WD_ERR("invalid: e or e->data is NULL\n");
+ return true;
+ }
+
+ for (i = 0; i < e->bsize; i++) {
if (e->data[i])
return false;
}
@@ -1096,12 +1101,12 @@ static int ecc_prepare_sign_in(struct wd_ecc_msg *msg,
return -WD_EINVAL;
}
hw_msg->sm2_ksel = 1;
- } else if (is_all_zero(k, msg)) {
+ } else if (is_all_zero(k)) {
WD_ERR("invalid: ecc sign in k all zero!\n");
return -WD_EINVAL;
}
- if (is_all_zero(e, msg)) {
+ if (is_all_zero(e)) {
WD_ERR("invalid: ecc sign in e all zero!\n");
return -WD_EINVAL;
}
@@ -1143,7 +1148,7 @@ static int ecc_prepare_verf_in(struct wd_ecc_msg *msg,
s = &vin->s;
r = &vin->r;
- if (is_all_zero(e, msg)) {
+ if (is_all_zero(e)) {
WD_ERR("invalid: ecc verf in e all zero!\n");
return -WD_EINVAL;
}
@@ -1284,7 +1289,7 @@ static int u_is_in_p(struct wd_ecc_msg *msg)
return -WD_EINVAL;
}
- if (is_all_zero(&pbk->x, msg)) {
+ if (is_all_zero(&pbk->x)) {
WD_ERR("invalid: ux is zero!\n");
return -WD_EINVAL;
}
--
2.30.0
In 'struct wd_dtb', the member 'bsize' indicates the whole
buffer size of the data, the member 'dsize' indicates the
valid size of the data. The 'bsize' is generally greater
than or equal to 'dsize'. In some cases, the data will be
filled with zero, the value of 'dsize' will not be updated,
so directly using 'dsize' may truncate the data and cause
erroneous judgement.
The solution is when check whether a 'struct wd_dtb' type
variable is all zero, if 'bsize' is larger than 'dsize',
the length of the data should be the value of 'bsize'.
And the key size value is redundant.
Signed-off-by: Zhiqi Song <songzhiqi1(a)huawei.com>
---
v1/drv/hisi_hpre_udrv.c | 19 +++++++++----------
v1/wd_ecc.c | 14 +++++++-------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/v1/drv/hisi_hpre_udrv.c b/v1/drv/hisi_hpre_udrv.c
index 00ceec2..0eba2d6 100644
--- a/v1/drv/hisi_hpre_udrv.c
+++ b/v1/drv/hisi_hpre_udrv.c
@@ -1106,22 +1106,21 @@ static void correct_random(struct wd_dtb *k)
k->data[lens] = 0;
}
-static bool is_all_zero(struct wd_dtb *e, struct wcrypto_ecc_msg *msg,
- const char *p_name)
+static bool is_all_zero(struct wd_dtb *e, const char *p_name)
{
int i;
if (!e || !e->data) {
- WD_ERR("%s: e or data NULL!\n", p_name);
+ WD_ERR("invalid: %s is NULL!\n", p_name);
return true;
}
- for (i = 0; i < e->dsize && i < msg->key_bytes; i++) {
+ for (i = 0; i < e->bsize; i++) {
if (e->data[i])
return false;
}
- WD_ERR("error: %s all zero!\n", p_name);
+ WD_ERR("invalid: %s all zero!\n", p_name);
return true;
}
@@ -1144,15 +1143,15 @@ static int ecc_prepare_sign_in(struct wcrypto_ecc_msg *msg,
e = &in->dgst;
if (!in->k_set) {
if (msg->op_type != WCRYPTO_SM2_SIGN) {
- WD_ERR("random k not set!\n");
+ WD_ERR("invalid: random k not set!\n");
return -WD_EINVAL;
}
hw_msg->sm2_ksel = 1;
- } else if (is_all_zero(k, msg, "ecc sgn k")) {
+ } else if (is_all_zero(k, "ecc sgn k")) {
return -WD_EINVAL;
}
- if (is_all_zero(e, msg, "ecc sgn e"))
+ if (is_all_zero(e, "ecc sgn e"))
return -WD_EINVAL;
ret = qm_crypto_bin_to_hpre_bin(e->data, (const char *)e->data,
@@ -1192,7 +1191,7 @@ static int ecc_prepare_verf_in(struct wcrypto_ecc_msg *msg, void **data)
s = &vin->s;
r = &vin->r;
- if (is_all_zero(e, msg, "ecc vrf e"))
+ if (is_all_zero(e, "ecc vrf e"))
return -WD_EINVAL;
ret = qm_crypto_bin_to_hpre_bin(e->data, (const char *)e->data,
@@ -1274,7 +1273,7 @@ static int ecc_prepare_sm2_enc_in(struct wcrypto_ecc_msg *msg,
int ret;
if (ein->k_set) {
- if (is_all_zero(k, msg, "sm2 enc k"))
+ if (is_all_zero(k, "sm2 enc k"))
return -WD_EINVAL;
ret = qm_crypto_bin_to_hpre_bin(k->data, (const char *)k->data,
diff --git a/v1/wd_ecc.c b/v1/wd_ecc.c
index e108051..e6b771a 100644
--- a/v1/wd_ecc.c
+++ b/v1/wd_ecc.c
@@ -544,6 +544,7 @@ static struct wcrypto_ecc_in *create_ecc_sign_in(struct wcrypto_ecc_ctx *ctx,
{
if (is_dgst)
return create_ecc_in(ctx, ECC_SIGN_IN_PARAM_NUM);
+
return create_sm2_sign_in(ctx, m_len);
}
@@ -1489,7 +1490,6 @@ static int ecc_request_init(struct wcrypto_ecc_msg *req,
if (req->op_type == WCRYPTO_ECXDH_GEN_KEY ||
req->op_type == WCRYPTO_SM2_KG) {
struct wcrypto_ecc_point *g = NULL;
-
wcrypto_get_ecc_prikey_params((void *)key, NULL, NULL,
NULL, NULL, &g, NULL);
req->in = (void *)g;
@@ -1715,11 +1715,11 @@ static bool less_than_latter(struct wd_dtb *d, struct wd_dtb *n)
return ret < 0;
}
-static bool is_all_zero(struct wd_dtb *p, struct wcrypto_ecc_ctx *ctx)
+static bool is_all_zero(struct wd_dtb *p)
{
int i;
- for (i = 0; i < p->dsize && i < ctx->key_size; i++) {
+ for (i = 0; i < p->bsize; i++) {
if (p->data[i])
return false;
}
@@ -1733,7 +1733,7 @@ static bool check_k_param(struct wd_dtb *k, struct wcrypto_ecc_ctx *ctx)
int ret;
if (unlikely(!k->data)) {
- WD_ERR("error: k->data NULL!\n");
+ WD_ERR("invalid: k->data NULL!\n");
return false;
}
@@ -1744,12 +1744,12 @@ static bool check_k_param(struct wd_dtb *k, struct wcrypto_ecc_ctx *ctx)
}
if (unlikely(!less_than_latter(k, &cv->n))) {
- WD_ERR("error: k >= n\n");
+ WD_ERR("invalid: k >= n!\n");
return false;
}
- if (unlikely(is_all_zero(k, ctx))) {
- WD_ERR("error: k all zero\n");
+ if (unlikely(is_all_zero(k))) {
+ WD_ERR("invalid: k all zero!\n");
return false;
}
--
2.30.0
Update the current driver adaptation and usage method, from fixed
use of Hisilicon device driver to automatic registration of the
driver according to the algorithm.
When the algorithm API layer uses the driver, it is no longer
bound to the fixed device driver, but dynamically obtained
and stored according to the algorithm query to use.
Update the driver and API layer of the zip module, keep the
function of the init interface unchanged, update the implementation
of the init2 interface and match the dynamic loading function.
liulongfang (4):
uadk: Add driver dynamic loading function
uadk: added ability to query supported algorithms
uadk: improve the dynamic loading public framework
uadk/zip: Adapt the zip module to the dynamic loading framework
Makefile.am | 4 +-
drv/hisi_comp.c | 101 ++++++++-
include/drv/wd_comp_drv.h | 27 ---
include/wd.h | 12 +
include/wd_alg.h | 85 ++++++++
include/wd_alg_common.h | 10 +
include/wd_sched.h | 6 +-
include/wd_util.h | 18 +-
libwd.map | 8 +
wd.c | 56 ++++-
wd_alg.c | 265 ++++++++++++++++++++++
wd_comp.c | 160 +++++++-------
wd_util.c | 447 +++++++++++++++++++++++++++++++++++++-
13 files changed, 1068 insertions(+), 131 deletions(-)
create mode 100644 include/wd_alg.h
create mode 100644 wd_alg.c
--
2.33.0
Update the current driver adaptation and usage method, from fixed
use of Hisilicon device driver to automatic registration of the
driver according to the algorithm.
When the algorithm API layer uses the driver, it is no longer
bound to the fixed device driver, but dynamically obtained
and stored according to the algorithm query to use.
Update the driver and API layer of the zip and sec module, keep the
function of the init interface unchanged, update the implementation
of the init2 interface and match the dynamic loading function.
Changes v1 -> v2:
- Fixed the compatibility method with the previous library file loading
liulongfang (5):
uadk: Add driver dynamic loading function
uadk: added ability to query supported algorithms
uadk: improve the dynamic loading public framework
uadk/zip: Adapt the zip module to the dynamic loading framework
uadk/sec: adapt the sec module to the dynamic loading framework
Makefile.am | 4 +-
drv/hisi_comp.c | 59 ++++-
drv/hisi_sec.c | 125 ++++++++--
include/drv/wd_cipher_drv.h | 26 --
include/drv/wd_comp_drv.h | 27 ---
include/wd.h | 12 +
include/wd_alg.h | 95 ++++++++
include/wd_alg_common.h | 10 +
include/wd_sched.h | 6 +-
include/wd_util.h | 19 +-
libwd.map | 8 +
libwd_crypto.map | 3 +
wd.c | 56 ++++-
wd_alg.c | 258 ++++++++++++++++++++
wd_cipher.c | 233 ++++++++++++++----
wd_comp.c | 188 ++++++++-------
wd_sched.c | 57 +++++
wd_util.c | 463 +++++++++++++++++++++++++++++++++++-
18 files changed, 1419 insertions(+), 230 deletions(-)
create mode 100644 include/wd_alg.h
create mode 100644 wd_alg.c
--
2.33.0
This patch set contains some tiny bugfix and cleanup of ecc/rsa/cipher.
Wenkai Lin (1):
cipher: code clean for update iv and check length
Zhiqi Song (4):
rsa: fix wrong input parameters
cipher: fix unused input parameter
uadk_engine: bugfix null dereference in abnormal conditions
ecc: bugfix potential null dereference problems
--
2.30.0