*** BLURB HERE ***
Chenghai Huang (2): uadk: code cleanup uadk: code cleanup for error codes and variable type
Longfang Liu (1): uadk: fixed some input parameter checking issues
Qi Tao (2): uadk: fix header file is not self contained sec/uadk: resolve white-box security review comments
Wenkai Lin (2): uadk/v1: remove print actions after wd_get_cookies uadk: fix sec send and recv check failed
Zhiqi Song (1): uadk/sec: add return value judgement
drv/hisi_sec.c | 276 +++++++++++++++++++++++----------------- include/wd.h | 1 + include/wd_alg_common.h | 1 + include/wd_cipher.h | 1 + include/wd_sched.h | 1 + include/wd_util.h | 14 ++ v1/wd_aead.c | 4 +- v1/wd_cipher.c | 4 +- v1/wd_digest.c | 4 +- wd.c | 6 +- wd_aead.c | 13 +- wd_cipher.c | 13 +- wd_comp.c | 4 +- wd_dh.c | 4 +- wd_digest.c | 12 +- wd_ecc.c | 4 +- wd_rsa.c | 4 +- wd_sched.c | 14 +- wd_util.c | 10 +- 19 files changed, 244 insertions(+), 146 deletions(-)
From: Wenkai Lin linwenkai6@hisilicon.com
Print information after wd_get_cookies returning EBUSY can seriously affect performance,so remove it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_aead.c | 4 +--- v1/wd_cipher.c | 4 +--- v1/wd_digest.c | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c index f688309..38429fc 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -593,10 +593,8 @@ int wcrypto_burst_aead(void *a_ctx, struct wcrypto_aead_op_data **opdata, return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num); - if (unlikely(ret)) { - WD_ERR("failed to get cookies %d!\n", ret); + if (unlikely(ret)) return ret; - }
for (i = 0; i < num; i++) { cookies[i]->tag.priv = opdata[i]->priv; diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index 60a0f25..f95015d 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -477,10 +477,8 @@ int wcrypto_burst_cipher(void *ctx, struct wcrypto_cipher_op_data **c_opdata, return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num); - if (unlikely(ret)) { - WD_ERR("failed to get cookies %d!\n", ret); + if (unlikely(ret)) return ret; - }
for (i = 0; i < num; i++) { cookies[i]->tag.priv = c_opdata[i]->priv; diff --git a/v1/wd_digest.c b/v1/wd_digest.c index b617350..b8ea5ce 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -456,10 +456,8 @@ int wcrypto_burst_digest(void *d_ctx, struct wcrypto_digest_op_data **opdata, return -WD_EINVAL;
ret = wd_get_cookies(&ctxt->pool, (void **)cookies, num); - if (unlikely(ret)) { - WD_ERR("failed to get cookies %d!\n", ret); + if (unlikely(ret)) return ret; - }
for (i = 0; i < num; i++) { cookies[i]->tag.priv = opdata[i]->priv;
From: Wenkai Lin linwenkai6@hisilicon.com
Header files are not self contained, fix it.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd.h | 1 + include/wd_alg_common.h | 1 + include/wd_cipher.h | 1 + include/wd_sched.h | 1 + include/wd_util.h | 2 ++ 5 files changed, 6 insertions(+)
diff --git a/include/wd.h b/include/wd.h index 0e67cad..6ee2ef5 100644 --- a/include/wd.h +++ b/include/wd.h @@ -7,6 +7,7 @@ #ifndef __WD_H #define __WD_H #include <errno.h> +#include <numa.h> #include <fcntl.h> #include <stdbool.h> #include <stdint.h> diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 77845a4..5652db3 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -9,6 +9,7 @@
#include <pthread.h> #include <stdbool.h> +#include <numa.h> #include "wd.h" #include "wd_alg.h"
diff --git a/include/wd_cipher.h b/include/wd_cipher.h index 7e63402..a712b53 100644 --- a/include/wd_cipher.h +++ b/include/wd_cipher.h @@ -8,6 +8,7 @@ #define __WD_CIPHER_H
#include <dlfcn.h> +#include <asm/types.h> #include "wd_alg_common.h"
#ifdef __cplusplus diff --git a/include/wd_sched.h b/include/wd_sched.h index a492d70..b145172 100644 --- a/include/wd_sched.h +++ b/include/wd_sched.h @@ -6,6 +6,7 @@
#ifndef SCHED_SAMPLE_h #define SCHED_SAMPLE_h +#include <asm/types.h> #include "wd_alg_common.h"
#ifdef __cplusplus diff --git a/include/wd_util.h b/include/wd_util.h index be9798c..78c5d23 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -13,7 +13,9 @@ #include <sys/shm.h> #include <asm/types.h>
+#include "wd.h" #include "wd_sched.h" +#include "wd_alg.h"
#ifdef __cplusplus extern "C" {
Modify or delete improper comments in uadk/sec module.
Signed-off-by: Qi Tao taoqi10@huawei.com --- wd_digest.c | 2 +- wd_util.c | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/wd_digest.c b/wd_digest.c index 2307bf1..bc67878 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -131,7 +131,7 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) int ret;
if (!key || !sess) { - WD_ERR("failed to check key param!\n"); + WD_ERR("invalid: failed to check input param, sess or key is NULL!\n"); return -WD_EINVAL; }
diff --git a/wd_util.c b/wd_util.c index bfa3af0..409a8c8 100644 --- a/wd_util.c +++ b/wd_util.c @@ -408,7 +408,6 @@ void wd_uninit_async_request_pool(struct wd_async_msg_pool *pool) pool->pool_num = 0; }
-/* fix me: this is old wd_get_req_from_pool */ void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, int ctx_idx, __u32 tag) { @@ -1344,7 +1343,6 @@ static struct async_task_queue *find_async_queue(struct wd_env_config *config, return head + offset; }
-/* fix me: all return value here, and no config input */ int wd_add_task_to_async_queue(struct wd_env_config *config, __u32 idx) { struct async_task_queue *task_queue;
From: Longfang Liu liulongfang@huawei.com
Inside the asynchronous packet receiving interface of all submodules. When the number of expected received packets is 0. Failure to intercept will result in abnormal packet recycling. As a result, the number of normal service packets does not match.
In addition, when the expected value is 0, it will cause the while loop control adjustment to flip, resulting in other receiving operations.
Signed-off-by: Longfang Liu liulongfang@huawei.com --- wd_aead.c | 2 +- wd_cipher.c | 2 +- wd_comp.c | 4 ++-- wd_dh.c | 4 ++-- wd_digest.c | 2 +- wd_ecc.c | 4 ++-- wd_rsa.c | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/wd_aead.c b/wd_aead.c index 87d61c3..ff43086 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -816,7 +816,7 @@ int wd_aead_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { + if (unlikely(!count || !expt)) { WD_ERR("invalid: aead poll ctx input param is NULL!\n"); return -WD_EINVAL; } diff --git a/wd_cipher.c b/wd_cipher.c index 58d34f7..0187c9c 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -730,7 +730,7 @@ int wd_cipher_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { + if (unlikely(!count || !expt)) { WD_ERR("invalid: cipher poll ctx input param is NULL!\n"); return -WD_EINVAL; } diff --git a/wd_comp.c b/wd_comp.c index 6e71d35..cabd17f 100644 --- a/wd_comp.c +++ b/wd_comp.c @@ -340,8 +340,8 @@ int wd_comp_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { - WD_ERR("invalid: comp poll count is 0!\n"); + if (unlikely(!count || !expt)) { + WD_ERR("invalid: comp poll count or expt is 0!\n"); return -WD_EINVAL; }
diff --git a/wd_dh.c b/wd_dh.c index 40a52e5..dac55ca 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -438,8 +438,8 @@ int wd_dh_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { - WD_ERR("invalid: count is NULL!\n"); + if (unlikely(!count || !expt)) { + WD_ERR("invalid: dh poll count or expt is NULL!\n"); return -WD_EINVAL; }
diff --git a/wd_digest.c b/wd_digest.c index bc67878..1f2b3b2 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -701,7 +701,7 @@ int wd_digest_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { + if (unlikely(!count || !expt)) { WD_ERR("invalid: digest poll ctx input param is NULL!\n"); return -WD_EINVAL; } diff --git a/wd_ecc.c b/wd_ecc.c index 4323e54..b5e7e36 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -2272,8 +2272,8 @@ int wd_ecc_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { - WD_ERR("invalid: param count is NULL!\n"); + if (unlikely(!count || !expt)) { + WD_ERR("invalid: ecc poll param count or expt is NULL!\n"); return -WD_EINVAL; }
diff --git a/wd_rsa.c b/wd_rsa.c index 1813676..b71540f 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -495,8 +495,8 @@ int wd_rsa_poll_ctx(__u32 idx, __u32 expt, __u32 *count) __u32 tmp = expt; int ret;
- if (unlikely(!count)) { - WD_ERR("invalid: param count is NULL!\n"); + if (unlikely(!count || !expt)) { + WD_ERR("invalid: rsa poll count or expt is NULL!\n"); return -WD_EINVAL; }
From: Chenghai Huang huangchenghai2@huawei.com
Add the input pointer checking.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- include/wd_util.h | 12 ++++++++++++ wd.c | 2 +- wd_aead.c | 11 +++++++++++ wd_cipher.c | 11 +++++++++++ wd_digest.c | 8 +++++++- wd_sched.c | 14 ++++++++++++-- wd_util.c | 8 ++++++++ 7 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/include/wd_util.h b/include/wd_util.h index 78c5d23..3059ac1 100644 --- a/include/wd_util.h +++ b/include/wd_util.h @@ -235,6 +235,18 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx, void *wd_find_msg_in_pool(struct wd_async_msg_pool *pool, int ctx_idx, __u32 tag);
+/* + * wd_check_src_dst() - Check the request input and output + * @src: input data pointer. + * @in_bytes: input data length. + * @dst: output data pointer. + * @out_bytes: output data length. + * + * Return -WD_EINVAL when in_bytes or out_bytes is non-zero, the + * corresponding input or output pointers is NULL, otherwise return 0. + */ +int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes); + /* * wd_check_datalist() - Check the data list length * @head: Data list's head pointer. diff --git a/wd.c b/wd.c index e88c993..998c9be 100644 --- a/wd.c +++ b/wd.c @@ -756,7 +756,7 @@ struct uacce_dev *wd_find_dev_by_numa(struct uacce_dev_list *list, int numa_id) }
while (p) { - if (numa_id != p->dev->numa_id) { + if (p->dev && numa_id != p->dev->numa_id) { p = p->next; continue; } diff --git a/wd_aead.c b/wd_aead.c index ff43086..6d49d76 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -361,6 +361,11 @@ static int wd_aead_param_check(struct wd_aead_sess *sess, return -WD_EINVAL; }
+ if (unlikely(!req->iv || !req->mac)) { + WD_ERR("invalid: aead input iv or mac is NULL!\n"); + return -WD_EINVAL; + } + if (unlikely(sess->cmode == WD_CIPHER_CBC && req->in_bytes == 0)) { WD_ERR("aead input data length is zero!\n"); return -WD_EINVAL; @@ -384,6 +389,12 @@ static int wd_aead_param_check(struct wd_aead_sess *sess, return -WD_EINVAL; }
+ ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); + return -WD_EINVAL; + } + if (req->data_fmt == WD_SGL_BUF) { len = req->in_bytes + req->assoc_bytes; ret = wd_check_datalist(req->list_src, len); diff --git a/wd_cipher.c b/wd_cipher.c index 0187c9c..47c0bf8 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -542,6 +542,11 @@ static int cipher_iv_len_check(struct wd_cipher_req *req, if (sess->mode == WD_CIPHER_ECB) return 0;
+ if (!req->iv) { + WD_ERR("invalid: cipher input iv is NULL!\n"); + ret = -WD_EINVAL; + } + switch (sess->alg) { case WD_CIPHER_AES: case WD_CIPHER_SM4: @@ -589,6 +594,12 @@ static int wd_cipher_check_params(handle_t h_sess, return -WD_EINVAL; }
+ ret = wd_check_src_dst(req->src, req->in_bytes, req->dst, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: src/dst addr is NULL when src/dst size is non-zero!\n"); + return -WD_EINVAL; + } + if (req->data_fmt == WD_SGL_BUF) { ret = wd_check_datalist(req->list_src, req->in_bytes); if (unlikely(ret)) { diff --git a/wd_digest.c b/wd_digest.c index 1f2b3b2..9008bcb 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -514,12 +514,18 @@ static int wd_digest_param_check(struct wd_digest_sess *sess, return ret;
if (unlikely(sess->alg == WD_DIGEST_AES_GMAC && - req->iv_bytes != GMAC_IV_LEN)) { + (!req->iv || req->iv_bytes != GMAC_IV_LEN))) { WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n", req->iv_bytes); return -WD_EINVAL; }
+ ret = wd_check_src_dst(req->in, req->in_bytes, req->out, req->out_bytes); + if (unlikely(ret)) { + WD_ERR("invalid: in/out addr is NULL when in/out size is non-zero!\n"); + return -WD_EINVAL; + } + if (req->data_fmt == WD_SGL_BUF) { ret = wd_check_datalist(req->list_in, req->in_bytes); if (unlikely(ret)) { diff --git a/wd_sched.c b/wd_sched.c index d1c829f..7aeea73 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -311,8 +311,8 @@ static int session_sched_poll_policy(handle_t h_sched_ctx, __u32 expect, __u32 * __u16 i; int ret;
- if (unlikely(!count || !sched_ctx)) { - WD_ERR("invalid: sched ctx is NULL or count is zero!\n"); + if (unlikely(!count || !sched_ctx || !sched_ctx->poll_func)) { + WD_ERR("invalid: sched ctx or poll_func is NULL or count is zero!\n"); return -WD_EINVAL; }
@@ -375,6 +375,11 @@ static int sched_none_poll_policy(handle_t h_sched_ctx, __u32 poll_num = 0; int ret;
+ if (!sched_ctx || !sched_ctx->poll_func) { + WD_ERR("invalid: sched ctx or poll_func is NULL!\n"); + return -WD_EINVAL; + } + while (loop_times > 0) { /* Default use ctx 0 */ loop_times--; @@ -417,6 +422,11 @@ static int sched_single_poll_policy(handle_t h_sched_ctx, __u32 poll_num = 0; int ret;
+ if (!sched_ctx || !sched_ctx->poll_func) { + WD_ERR("invalid: sched ctx or poll_func is NULL!\n"); + return -WD_EINVAL; + } + while (loop_times > 0) { /* Default async mode use ctx 0 */ loop_times--; diff --git a/wd_util.c b/wd_util.c index 409a8c8..91f1d73 100644 --- a/wd_util.c +++ b/wd_util.c @@ -459,6 +459,14 @@ void wd_put_msg_to_pool(struct wd_async_msg_pool *pool, int ctx_idx, __u32 tag) __atomic_clear(&p->used[tag - 1], __ATOMIC_RELEASE); }
+int wd_check_src_dst(void *src, __u32 in_bytes, void *dst, __u32 out_bytes) +{ + if ((in_bytes && !src) || (out_bytes && !dst)) + return -WD_EINVAL; + + return 0; +} + int wd_check_datalist(struct wd_datalist *head, __u32 size) { struct wd_datalist *tmp = head;
From: Wenkai Lin linwenkai6@hisilicon.com
The send and recv pointers should be assigned at the beginning, not during wd initialization.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/hisi_sec.c | 260 ++++++++++++++++++++++++++++--------------------- 1 file changed, 149 insertions(+), 111 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 03e7037..bc4434f 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -539,12 +539,93 @@ static __u32 g_sec_hmac_full_len[WD_DIGEST_TYPE_MAX] = { static int hisi_sec_init(struct wd_alg_driver *drv, void *conf); static void hisi_sec_exit(struct wd_alg_driver *drv);
+static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); + +static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); + +static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); +static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg); + +static int cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_qp *qp = (struct hisi_qp *)h_qp; + struct hisi_qm_queue_info q_info = qp->q_info; + + if (q_info.hw_type == HISI_QM_API_VER2_BASE) + return hisi_sec_cipher_send(drv, ctx, msg); + return hisi_sec_cipher_send_v3(drv, ctx, msg); +} + +static int cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_qp *qp = (struct hisi_qp *)h_qp; + struct hisi_qm_queue_info q_info = qp->q_info; + + if (q_info.hw_type == HISI_QM_API_VER2_BASE) + return hisi_sec_cipher_recv(drv, ctx, msg); + return hisi_sec_cipher_recv_v3(drv, ctx, msg); +} + +static int digest_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_qp *qp = (struct hisi_qp *)h_qp; + struct hisi_qm_queue_info q_info = qp->q_info; + + if (q_info.hw_type == HISI_QM_API_VER2_BASE) + return hisi_sec_digest_send(drv, ctx, msg); + return hisi_sec_digest_send_v3(drv, ctx, msg); +} + +static int digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_qp *qp = (struct hisi_qp *)h_qp; + struct hisi_qm_queue_info q_info = qp->q_info; + + if (q_info.hw_type == HISI_QM_API_VER2_BASE) + return hisi_sec_digest_recv(drv, ctx, msg); + return hisi_sec_digest_recv_v3(drv, ctx, msg); +} + +static int aead_send(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_qp *qp = (struct hisi_qp *)h_qp; + struct hisi_qm_queue_info q_info = qp->q_info; + + if (q_info.hw_type == HISI_QM_API_VER2_BASE) + return hisi_sec_aead_send(drv, ctx, msg); + return hisi_sec_aead_send_v3(drv, ctx, msg); +} + +static int aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg) +{ + handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); + struct hisi_qp *qp = (struct hisi_qp *)h_qp; + struct hisi_qm_queue_info q_info = qp->q_info; + + if (q_info.hw_type == HISI_QM_API_VER2_BASE) + return hisi_sec_aead_recv(drv, ctx, msg); + return hisi_sec_aead_recv_v3(drv, ctx, msg); +} + static int hisi_sec_get_usage(void *param) { return 0; }
-#define GEN_SEC_ALG_DRIVER(sec_alg_name) \ +#define GEN_SEC_ALG_DRIVER(sec_alg_name, alg_type) \ {\ .drv_name = "hisi_sec2",\ .alg_name = (sec_alg_name),\ @@ -555,57 +636,59 @@ static int hisi_sec_get_usage(void *param) .fallback = 0,\ .init = hisi_sec_init,\ .exit = hisi_sec_exit,\ + .send = alg_type##_send,\ + .recv = alg_type##_recv,\ .get_usage = hisi_sec_get_usage,\ }
static struct wd_alg_driver cipher_alg_driver[] = { - GEN_SEC_ALG_DRIVER("ecb(aes)"), - GEN_SEC_ALG_DRIVER("cbc(aes)"), - GEN_SEC_ALG_DRIVER("xts(aes)"), - GEN_SEC_ALG_DRIVER("ecb(sm4)"), - GEN_SEC_ALG_DRIVER("cbc(sm4)"), - GEN_SEC_ALG_DRIVER("ctr(sm4)"), - GEN_SEC_ALG_DRIVER("xts(sm4)"), - GEN_SEC_ALG_DRIVER("ecb(des)"), - GEN_SEC_ALG_DRIVER("cbc(des)"), - GEN_SEC_ALG_DRIVER("ecb(des3_ede)"), - GEN_SEC_ALG_DRIVER("cbc(des3_ede)"), - - GEN_SEC_ALG_DRIVER("ctr(aes)"), - GEN_SEC_ALG_DRIVER("ofb(aes)"), - GEN_SEC_ALG_DRIVER("cfb(aes)"), - GEN_SEC_ALG_DRIVER("cbc-cs1(aes)"), - GEN_SEC_ALG_DRIVER("cbc-cs2(aes)"), - GEN_SEC_ALG_DRIVER("cbc-cs3(aes)"), - GEN_SEC_ALG_DRIVER("ofb(sm4)"), - GEN_SEC_ALG_DRIVER("cfb(sm4)"), - GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)"), - GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)"), - GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)"), + GEN_SEC_ALG_DRIVER("ecb(aes)", cipher), + GEN_SEC_ALG_DRIVER("cbc(aes)", cipher), + GEN_SEC_ALG_DRIVER("xts(aes)", cipher), + GEN_SEC_ALG_DRIVER("ecb(sm4)", cipher), + GEN_SEC_ALG_DRIVER("cbc(sm4)", cipher), + GEN_SEC_ALG_DRIVER("ctr(sm4)", cipher), + GEN_SEC_ALG_DRIVER("xts(sm4)", cipher), + GEN_SEC_ALG_DRIVER("ecb(des)", cipher), + GEN_SEC_ALG_DRIVER("cbc(des)", cipher), + GEN_SEC_ALG_DRIVER("ecb(des3_ede)", cipher), + GEN_SEC_ALG_DRIVER("cbc(des3_ede)", cipher), + + GEN_SEC_ALG_DRIVER("ctr(aes)", cipher), + GEN_SEC_ALG_DRIVER("ofb(aes)", cipher), + GEN_SEC_ALG_DRIVER("cfb(aes)", cipher), + GEN_SEC_ALG_DRIVER("cbc-cs1(aes)", cipher), + GEN_SEC_ALG_DRIVER("cbc-cs2(aes)", cipher), + GEN_SEC_ALG_DRIVER("cbc-cs3(aes)", cipher), + GEN_SEC_ALG_DRIVER("ofb(sm4)", cipher), + GEN_SEC_ALG_DRIVER("cfb(sm4)", cipher), + GEN_SEC_ALG_DRIVER("cbc-cs1(sm4)", cipher), + GEN_SEC_ALG_DRIVER("cbc-cs2(sm4)", cipher), + GEN_SEC_ALG_DRIVER("cbc-cs3(sm4)", cipher), };
static struct wd_alg_driver digest_alg_driver[] = { - GEN_SEC_ALG_DRIVER("sm3"), - GEN_SEC_ALG_DRIVER("md5"), - GEN_SEC_ALG_DRIVER("sha1"), - GEN_SEC_ALG_DRIVER("sha224"), - GEN_SEC_ALG_DRIVER("sha256"), - GEN_SEC_ALG_DRIVER("sha384"), - GEN_SEC_ALG_DRIVER("sha512"), - GEN_SEC_ALG_DRIVER("sha512-224"), - GEN_SEC_ALG_DRIVER("sha512-256"), - GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)"), - GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)"), - GEN_SEC_ALG_DRIVER("cmac(aes)"), - GEN_SEC_ALG_DRIVER("gmac(aes)"), + GEN_SEC_ALG_DRIVER("sm3", digest), + GEN_SEC_ALG_DRIVER("md5", digest), + GEN_SEC_ALG_DRIVER("sha1", digest), + GEN_SEC_ALG_DRIVER("sha224", digest), + GEN_SEC_ALG_DRIVER("sha256", digest), + GEN_SEC_ALG_DRIVER("sha384", digest), + GEN_SEC_ALG_DRIVER("sha512", digest), + GEN_SEC_ALG_DRIVER("sha512-224", digest), + GEN_SEC_ALG_DRIVER("sha512-256", digest), + GEN_SEC_ALG_DRIVER("xcbc-mac-96(aes)", digest), + GEN_SEC_ALG_DRIVER("xcbc-prf-128(aes)", digest), + GEN_SEC_ALG_DRIVER("cmac(aes)", digest), + GEN_SEC_ALG_DRIVER("gmac(aes)", digest), };
static struct wd_alg_driver aead_alg_driver[] = { - GEN_SEC_ALG_DRIVER("ccm(aes)"), - GEN_SEC_ALG_DRIVER("gcm(aes)"), - GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))"), - GEN_SEC_ALG_DRIVER("ccm(sm4)"), - GEN_SEC_ALG_DRIVER("gcm(sm4)"), + GEN_SEC_ALG_DRIVER("ccm(aes)", aead), + GEN_SEC_ALG_DRIVER("gcm(aes)", aead), + GEN_SEC_ALG_DRIVER("authenc(hmac(sha256),cbc(aes))", aead), + GEN_SEC_ALG_DRIVER("ccm(sm4)", aead), + GEN_SEC_ALG_DRIVER("gcm(sm4)", aead), };
static void dump_sec_msg(void *msg, const char *alg) @@ -1092,10 +1175,10 @@ static int fill_cipher_bd2(struct wd_cipher_msg *msg, struct hisi_sec_sqe *sqe) return 0; }
-int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) +static int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_cipher_msg *msg = cipher_msg; + struct wd_cipher_msg *msg = wd_msg; struct hisi_sec_sqe sqe; __u16 count = 0; int ret; @@ -1137,10 +1220,10 @@ int hisi_sec_cipher_send(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) return 0; }
-int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) +static int hisi_sec_cipher_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_cipher_msg *recv_msg = cipher_msg; + struct wd_cipher_msg *recv_msg = wd_msg; struct hisi_sec_sqe sqe; __u16 count = 0; int ret; @@ -1295,10 +1378,10 @@ static int fill_cipher_bd3(struct wd_cipher_msg *msg, struct hisi_sec_sqe3 *sqe) return 0; }
-int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) +static int hisi_sec_cipher_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_cipher_msg *msg = cipher_msg; + struct wd_cipher_msg *msg = wd_msg; struct hisi_sec_sqe3 sqe; __u16 count = 0; int ret; @@ -1385,10 +1468,10 @@ static void parse_cipher_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "cipher"); }
-int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *cipher_msg) +static int hisi_sec_cipher_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_cipher_msg *recv_msg = cipher_msg; + struct wd_cipher_msg *recv_msg = wd_msg; struct hisi_sec_sqe3 sqe; __u16 count = 0; int ret; @@ -1658,10 +1741,10 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) return 0; }
-int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) +static int hisi_sec_digest_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_digest_msg *msg = digest_msg; + struct wd_digest_msg *msg = wd_msg; struct hisi_sec_sqe sqe; __u16 count = 0; __u8 scene; @@ -1725,10 +1808,10 @@ put_sgl: return ret; }
-int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) +static int hisi_sec_digest_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_digest_msg *recv_msg = digest_msg; + struct wd_digest_msg *recv_msg = wd_msg; struct hisi_sec_sqe sqe; __u16 count = 0; int ret; @@ -1902,10 +1985,10 @@ static void fill_digest_v3_scene(struct hisi_sec_sqe3 *sqe, sqe->bd_param |= (__u16)(de | scene); }
-int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) +static int hisi_sec_digest_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_digest_msg *msg = digest_msg; + struct wd_digest_msg *msg = wd_msg; struct hisi_sec_sqe3 sqe; __u16 count = 0; int ret; @@ -2001,10 +2084,10 @@ static void parse_digest_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "digest"); }
-int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *digest_msg) +static int hisi_sec_digest_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_digest_msg *recv_msg = digest_msg; + struct wd_digest_msg *recv_msg = wd_msg; struct hisi_sec_sqe3 sqe; __u16 count = 0; int ret; @@ -2473,10 +2556,10 @@ int aead_msg_state_check(struct wd_aead_msg *msg) return 0; }
-int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) +static int hisi_sec_aead_send(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_aead_msg *msg = aead_msg; + struct wd_aead_msg *msg = wd_msg; struct hisi_sec_sqe sqe; __u16 count = 0; int ret; @@ -2595,10 +2678,10 @@ static bool soft_compute_check(struct hisi_qp *qp, struct wd_aead_msg *msg) qp->q_info.qp_mode == CTX_MODE_SYNC; }
-int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) +static int hisi_sec_aead_recv(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_aead_msg *recv_msg = aead_msg; + struct wd_aead_msg *recv_msg = wd_msg; struct hisi_sec_sqe sqe; __u16 count = 0; int ret; @@ -2857,10 +2940,10 @@ static int fill_aead_bd3(struct wd_aead_msg *msg, struct hisi_sec_sqe3 *sqe) return 0; }
-int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) +static int hisi_sec_aead_send_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_aead_msg *msg = aead_msg; + struct wd_aead_msg *msg = wd_msg; struct hisi_sec_sqe3 sqe; __u16 count = 0; int ret; @@ -2957,10 +3040,10 @@ static void parse_aead_bd3(struct hisi_qp *qp, struct hisi_sec_sqe3 *sqe, dump_sec_msg(temp_msg, "aead"); }
-int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) +static int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *wd_msg) { handle_t h_qp = (handle_t)wd_ctx_get_priv(ctx); - struct wd_aead_msg *recv_msg = aead_msg; + struct wd_aead_msg *recv_msg = wd_msg; struct hisi_sec_sqe3 sqe; __u16 count = 0; int ret; @@ -2985,50 +3068,6 @@ int hisi_sec_aead_recv_v3(struct wd_alg_driver *drv, handle_t ctx, void *aead_msg) return 0; }
-static void hisi_sec_driver_adapter(struct hisi_qp *qp) -{ - struct hisi_qm_queue_info q_info = qp->q_info; - int alg_num, i; - - if (q_info.hw_type == HISI_QM_API_VER2_BASE) { - WD_INFO("hisi sec init HIP08!\n"); - alg_num = ARRAY_SIZE(cipher_alg_driver); - for (i = 0; i < alg_num; i++) { - cipher_alg_driver[i].send = hisi_sec_cipher_send; - cipher_alg_driver[i].recv = hisi_sec_cipher_recv; - } - - alg_num = ARRAY_SIZE(digest_alg_driver); - for (i = 0; i < alg_num; i++) { - digest_alg_driver[i].send = hisi_sec_digest_send; - digest_alg_driver[i].recv = hisi_sec_digest_recv; - } - alg_num = ARRAY_SIZE(aead_alg_driver); - for (i = 0; i < alg_num; i++) { - aead_alg_driver[i].send = hisi_sec_aead_send; - aead_alg_driver[i].recv = hisi_sec_aead_recv; - } - } else { - WD_INFO("hisi sec init HIP09!\n"); - alg_num = ARRAY_SIZE(cipher_alg_driver); - for (i = 0; i < alg_num; i++) { - cipher_alg_driver[i].send = hisi_sec_cipher_send_v3; - cipher_alg_driver[i].recv = hisi_sec_cipher_recv_v3; - } - - alg_num = ARRAY_SIZE(digest_alg_driver); - for (i = 0; i < alg_num; i++) { - digest_alg_driver[i].send = hisi_sec_digest_send_v3; - digest_alg_driver[i].recv = hisi_sec_digest_recv_v3; - } - alg_num = ARRAY_SIZE(aead_alg_driver); - for (i = 0; i < alg_num; i++) { - aead_alg_driver[i].send = hisi_sec_aead_send_v3; - aead_alg_driver[i].recv = hisi_sec_aead_recv_v3; - } - } -} - static int hisi_sec_init(struct wd_alg_driver *drv, void *conf) { struct hisi_sec_ctx *priv = (struct hisi_sec_ctx *)drv->priv; @@ -3069,7 +3108,6 @@ static int hisi_sec_init(struct wd_alg_driver *drv, void *conf) config->ctxs[i].sqn = qm_priv.sqn; } memcpy(&priv->config, config, sizeof(struct wd_ctx_config_internal)); - hisi_sec_driver_adapter((struct hisi_qp *)h_qp); drv->priv = priv;
return 0;
From: Chenghai Huang huangchenghai2@huawei.com
Unify the use of error return name. Modify the variable type in hisi_sec to reduce variable conversion.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- drv/hisi_sec.c | 12 ++++++------ wd.c | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index bc4434f..7d27638 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -517,12 +517,12 @@ struct hisi_sec_sqe3 { __le32 counter; } __attribute__((packed, aligned(4)));
-static int g_digest_a_alg[WD_DIGEST_TYPE_MAX] = { +static __u32 g_digest_a_alg[WD_DIGEST_TYPE_MAX] = { A_ALG_SM3, A_ALG_MD5, A_ALG_SHA1, A_ALG_SHA256, A_ALG_SHA224, A_ALG_SHA384, A_ALG_SHA512, A_ALG_SHA512_224, A_ALG_SHA512_256 };
-static int g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = { +static __u32 g_hmac_a_alg[WD_DIGEST_TYPE_MAX] = { A_ALG_HMAC_SM3, A_ALG_HMAC_MD5, A_ALG_HMAC_SHA1, A_ALG_HMAC_SHA256, A_ALG_HMAC_SHA224, A_ALG_HMAC_SHA384, A_ALG_HMAC_SHA512, A_ALG_HMAC_SHA512_224, A_ALG_HMAC_SHA512_256, @@ -1518,7 +1518,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg,
if (msg->mode == WD_DIGEST_NORMAL) sqe->type2.mac_key_alg |= - (__u32)g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET; + g_digest_a_alg[msg->alg] << AUTH_ALG_OFFSET; else if (msg->mode == WD_DIGEST_HMAC) { if (msg->key_bytes & WORD_ALIGNMENT_MASK) { WD_ERR("failed to check digest key_bytes, size = %u\n", @@ -1530,7 +1530,7 @@ static int fill_digest_bd2_alg(struct wd_digest_msg *msg, sqe->type2.a_key_addr = (__u64)(uintptr_t)msg->key;
sqe->type2.mac_key_alg |= - (__u32)g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET; + g_hmac_a_alg[msg->alg] << AUTH_ALG_OFFSET; } else { WD_ERR("failed to check digest mode, mode = %u\n", msg->mode); return -WD_EINVAL; @@ -1887,7 +1887,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg,
if (msg->mode == WD_DIGEST_NORMAL) { sqe->auth_mac_key |= - (__u32)g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; + g_digest_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; } else if (msg->mode == WD_DIGEST_HMAC) { ret = hmac_key_len_check(msg); if (ret) @@ -1897,7 +1897,7 @@ static int fill_digest_bd3_alg(struct wd_digest_msg *msg, WORD_BYTES) << SEC_AKEY_OFFSET_V3; sqe->a_key_addr = (__u64)(uintptr_t)msg->key; sqe->auth_mac_key |= - (__u32)g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3; + g_hmac_a_alg[msg->alg] << SEC_AUTH_ALG_OFFSET_V3;
if (msg->alg == WD_DIGEST_AES_GMAC) { sqe->auth_mac_key |= AI_GEN_IVIN_ADDR << SEC_AI_GEN_OFFSET_V3; diff --git a/wd.c b/wd.c index 998c9be..2d9a42c 100644 --- a/wd.c +++ b/wd.c @@ -228,7 +228,7 @@ static int get_dev_info(struct uacce_dev *dev) return ret; else if (value == 1) { WD_ERR("skip isolated uacce device!\n"); - return -ENODEV; + return -WD_ENODEV; } }
@@ -237,7 +237,7 @@ static int get_dev_info(struct uacce_dev *dev) return ret; else if (!((unsigned int)dev->flags & UACCE_DEV_SVA)) { WD_ERR("skip none sva uacce device!\n"); - return -ENODEV; + return -WD_ENODEV; }
ret = get_int_attr(dev, "region_mmio_size", &value);
From: Zhiqi Song songzhiqi1@huawei.com
Add return value judgement of aead_get_aes_key_len().
Signed-off-by: Zhiqi Song songzhiqi1@huawei.com --- drv/hisi_sec.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 7d27638..ce4cbf4 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -2152,6 +2152,8 @@ static int fill_aead_bd2_alg(struct wd_aead_msg *msg, case WD_CIPHER_AES: sqe->type2.c_alg = C_ALG_AES; ret = aead_get_aes_key_len(msg, &c_key_len); + if (ret) + return ret; sqe->type2.icvw_kmode = (__u16)c_key_len << SEC_CKEY_OFFSET; break; default: @@ -2721,6 +2723,8 @@ static int fill_aead_bd3_alg(struct wd_aead_msg *msg, case WD_CIPHER_AES: sqe->c_mode_alg |= C_ALG_AES << SEC_CALG_OFFSET_V3; ret = aead_get_aes_key_len(msg, &c_key_len); + if (ret) + return ret; sqe->c_icv_key |= (__u16)c_key_len << SEC_CKEY_OFFSET_V3; break; default: