From: Chenghai Huang huangchenghai2@huawei.com
Fixed some bugs of uadk v1 and v2, optimized code function processing, and added file association in compiled files.
Chenghai Huang (11): uadk: Add file association uadk: fix the failure process bug uadk: fix the failure process bug uadk: fix the failure process bug uadk: bugfix uadk v1: adapter code cleanup uadk v1: fix wd_rng resource release bug uadk v1: code cleanup for error codes and header files uadk: concentrate the same definitions uadk v1: optimize the function length uadk v1: concentrate the same definitions
Makefile.am | 4 +- drv/hisi_sec.c | 11 +----- include/wd_alg_common.h | 13 +++++++ include/wd_cipher.h | 1 - include/wd_digest.h | 2 - v1/drv/hisi_sec_udrv.c | 11 +----- v1/wd.c | 63 ++++++++++++++++--------------- v1/wd_adapter.c | 6 +-- v1/wd_aead.c | 15 -------- v1/wd_cipher.c | 9 +---- v1/wd_digest.c | 84 ++++++++++++++++++++++++++--------------- v1/wd_rng.c | 8 ++-- v1/wd_util.h | 17 +++++++++ wd.c | 2 +- wd_aead.c | 9 ----- wd_cipher.c | 7 ---- wd_digest.c | 9 ----- wd_mempool.c | 3 +- wd_sched.c | 2 +- wd_util.c | 1 + 20 files changed, 133 insertions(+), 144 deletions(-)
From: Chenghai Huang huangchenghai2@huawei.com
Add wd_comp file to zip.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 657ed20..e9ec47a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,9 +121,9 @@ libwd_crypto_la_LIBADD= -lwd -ldl -lnuma libwd_crypto_la_LDFLAGS=$(UADK_VERSION) $(UADK_CRYPTO_SYMBOL) libwd_crypto_la_DEPENDENCIES= libwd.la
-libhisi_zip_la_LIBADD= -lwd -ldl +libhisi_zip_la_LIBADD= -lwd -ldl -lwd_comp libhisi_zip_la_LDFLAGS=$(UADK_VERSION) -libhisi_zip_la_DEPENDENCIES= libwd.la +libhisi_zip_la_DEPENDENCIES= libwd.la libwd_comp.la
libhisi_sec_la_LIBADD= -lwd -lwd_crypto libhisi_sec_la_LDFLAGS=$(UADK_VERSION)
From: Chenghai Huang huangchenghai2@huawei.com
After a failure message is returned due to a calloc exception, the mp-ref count must be decreased by 1. Otherwise, an infinite loop occurs when the process invokes the mp command to destroy the process and cannot exit.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- wd_mempool.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/wd_mempool.c b/wd_mempool.c index cb8c80b..ed107d1 100644 --- a/wd_mempool.c +++ b/wd_mempool.c @@ -573,7 +573,7 @@ handle_t wd_blockpool_create(handle_t mempool, size_t block_size, bp = calloc(1, sizeof(struct blkpool)); if (!bp) { WD_ERR("failed to alloc memory for blkpool!\n"); - return (handle_t)(-WD_ENOMEM); + goto err_sub_ref; }
bp->top = block_num; @@ -597,6 +597,7 @@ err_free_mem: free_mem_to_mempool(bp); err_free_bp: free(bp); +err_sub_ref: wd_atomic_sub(&mp->ref, 1); return (handle_t)(-WD_ENOMEM); }
From: Chenghai Huang huangchenghai2@huawei.com
After the sem_post operation of full_sem fails, it need to restore empty_sem to ensure that resources are available.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- wd_util.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/wd_util.c b/wd_util.c index 91f1d73..6134239 100644 --- a/wd_util.c +++ b/wd_util.c @@ -1398,6 +1398,7 @@ err_out: task_queue->cur_task--; task_queue->prod = curr_prod; pthread_mutex_unlock(&task_queue->lock); + sem_post(&task_queue->empty_sem);
return ret; }
From: Chenghai Huang huangchenghai2@huawei.com
Assign numa_num to sched_ctx before err_out for wd_scheduling_rr_release release memoryc orrectly.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- wd_sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd_sched.c b/wd_sched.c index 7aeea73..419280e 100644 --- a/wd_sched.c +++ b/wd_sched.c @@ -642,6 +642,7 @@ struct wd_sched *wd_sched_rr_alloc(__u8 sched_type, __u8 type_num, WD_ERR("failed to alloc memory for sched_ctx!\n"); goto err_out; } + sched_ctx->numa_num = numa_num;
sched->h_sched_ctx = (handle_t)sched_ctx; if (sched_type == SCHED_POLICY_NONE || @@ -662,7 +663,6 @@ simple_ok: sched_ctx->poll_func = func; sched_ctx->policy = sched_type; sched_ctx->type_num = type_num; - sched_ctx->numa_num = numa_num; memset(sched_ctx->numa_map, -1, sizeof(int) * NUMA_NUM_NODES);
sched->sched_init = sched_table[sched_type].sched_init;
From: Chenghai Huang huangchenghai2@huawei.com
Replace strncpy with memcpy to avoid compilation warnings.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- wd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/wd.c b/wd.c index 2d9a42c..abadcf9 100644 --- a/wd.c +++ b/wd.c @@ -426,7 +426,7 @@ handle_t wd_request_ctx(struct uacce_dev *dev)
wd_ctx_init_qfrs_offs(ctx);
- strncpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN); + memcpy(ctx->dev_path, dev->char_dev_path, MAX_DEV_NAME_LEN); ctx->dev_path[MAX_DEV_NAME_LEN - 1] = '\0';
return (handle_t)ctx;
From: Chenghai Huang huangchenghai2@huawei.com
Delete unnecessary processing.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- v1/wd_adapter.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/v1/wd_adapter.c b/v1/wd_adapter.c index 6b0b4d8..6e95562 100644 --- a/v1/wd_adapter.c +++ b/v1/wd_adapter.c @@ -209,9 +209,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size)
ptr = wd_drv_mmap_qfr(q, WD_UACCE_QFRT_SS, tmp); if (ptr == MAP_FAILED) { - int value = errno; - - WD_ERR("wd drv mmap fail!(err =%d)\n", value); + WD_ERR("wd drv mmap fail!(err = %d)\n", errno); return NULL; }
@@ -219,7 +217,7 @@ void *drv_reserve_mem(struct wd_queue *q, size_t size) qinfo->ss_size = tmp; tmp = 0; while (ret > 0) { - info = (unsigned long)i; + info = i; ret = ioctl(qinfo->fd, WD_UACCE_CMD_GET_SS_DMA, &info); if (ret < 0) { drv_show_ss_slices(q);
From: Chenghai Huang huangchenghai2@huawei.com
Before wd_free_id and ctx_num are released, check whether ctx_num is less than or equal to 0 to avoid repeated release.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- v1/wd_rng.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/v1/wd_rng.c b/v1/wd_rng.c index 927665f..24a4b7a 100644 --- a/v1/wd_rng.c +++ b/v1/wd_rng.c @@ -144,14 +144,14 @@ void wcrypto_del_rng_ctx(void *ctx)
wd_uninit_cookie_pool(&cx->pool); wd_spinlock(&qinfo->qlock); - wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1, - WD_MAX_CTX_NUM); - qinfo->ctx_num--; - if (qinfo->ctx_num < 0) { + if (qinfo->ctx_num <= 0) { wd_unspinlock(&qinfo->qlock); WD_ERR("repeat delete trng ctx!\n"); return; } + qinfo->ctx_num--; + wd_free_id(qinfo->ctx_id, WD_MAX_CTX_NUM, cx->ctx_id - 1, + WD_MAX_CTX_NUM); wd_unspinlock(&qinfo->qlock);
free(ctx);
From: Chenghai Huang huangchenghai2@huawei.com
Unify the use of error return name. Adjusting the sequence of header files.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- v1/wd.c | 63 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 31 deletions(-)
diff --git a/v1/wd.c b/v1/wd.c index 3839304..26e7af3 100644 --- a/v1/wd.c +++ b/v1/wd.c @@ -14,18 +14,18 @@ * limitations under the License. */
-#include <stdlib.h> -#include <unistd.h> -#include <signal.h> -#include <sys/types.h> +#include <dirent.h> +#include <errno.h> #include <fcntl.h> +#include <limits.h> +#include <signal.h> +#include <stdlib.h> +#include <string.h> #include <sys/ioctl.h> -#include <errno.h> #include <sys/mman.h> -#include <string.h> -#include <dirent.h> #include <sys/poll.h> -#include <limits.h> +#include <sys/types.h> +#include <unistd.h>
#include "v1/wd_util.h" #include "v1/wd_adapter.h" @@ -94,12 +94,12 @@ static int get_raw_attr(const char *dev_root, const char *attr, fd = open(attr_path, O_RDONLY, 0); if (fd < 0) { WD_ERR("open %s fail, errno = %d!\n", attr_path, errno); - return -ENODEV; + return -WD_ENODEV; } size = read(fd, buf, sz); if (size <= 0) { WD_ERR("read nothing at %s!\n", attr_path); - size = -ENODEV; + size = -WD_ENODEV; }
close(fd); @@ -214,7 +214,7 @@ static bool is_weight_more(unsigned int new, unsigned int old) ins_old = GET_AVAILABLE_INSTANCES(old); dis_old = GET_NODE_DISTANCE(old);
- dbg("dis_new %u, ins_new %u,dis_old %u, ins_old %u\n", + dbg("dis_new %u, ins_new %u, dis_old %u, ins_old %u\n", dis_new, ins_new, dis_old, ins_old);
if (dis_new > dis_old) @@ -240,16 +240,16 @@ static int get_int_attr_all(struct dev_info *dinfo) /* ret == 1 means device has been isolated */ ret = get_int_attr(dinfo, "isolate"); if (ret < 0) - return -ENODEV; + return -WD_ENODEV; else if (ret == 1) - return -EBUSY; + return -WD_EBUSY;
/* ret == 0 means device has no available queues */ ret = get_int_attr(dinfo, "available_instances"); if (ret < 0) - return -ENODEV; + return -WD_ENODEV; else if (ret == 0) - return -EBUSY; + return -WD_EBUSY;
dinfo->available_instances = ret;
@@ -318,13 +318,13 @@ static int get_dev_info(struct dev_info *dinfo, const char *alg) LINUX_DEV_DIR, dinfo->name); if (ret <= 0) { WD_ERR("snprintf err, ret %d!\n", ret); - return -EINVAL; + return -WD_EINVAL; }
ret = access(buf, F_OK); if (ret < 0) { WD_ERR("failed to check file path %s, ret: %d\n", buf, ret); - return -ENODEV; + return -WD_ENODEV; }
ret = get_str_attr_all(dinfo, alg); @@ -407,7 +407,7 @@ static int get_denoted_dev(struct wd_capa *capa, const char *dev, if (!get_dev_info(dinfop, capa->alg)) return 0; WD_ERR("%s not available, will try other devices\n", dev); - return -ENODEV; + return -WD_ENODEV; }
static int find_available_dev(struct dev_info *dinfop, @@ -425,7 +425,7 @@ static int find_available_dev(struct dev_info *dinfop, wd_class = opendir(WD_UACCE_CLASS_DIR); if (!wd_class) { WD_ERR("WD framework is not enabled on the system, errno = %d!\n", errno); - return -ENODEV; + return -WD_ENODEV; }
while (true) { @@ -444,7 +444,7 @@ static int find_available_dev(struct dev_info *dinfop, find_node = true; break; } - } else if (ret == -EPFNOSUPPORT || ret == -EBUSY || ret == -ENODEV) { + } else if (ret == -EPFNOSUPPORT || ret == -WD_EBUSY || ret == -WD_ENODEV) { continue; } else { closedir(wd_class); @@ -470,12 +470,12 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop, if (dev[0] && dev[0] != '/' && !strstr(dev, "../")) { if (!dinfop) { WD_ERR("dinfop NULL!\n"); - return -EINVAL; + return -WD_EINVAL; }
if (q->node_mask) { WD_ERR("dev and node cannot be denoted together!\n"); - return -EINVAL; + return -WD_EINVAL; }
if (!get_denoted_dev(capa, dev, dinfop)) @@ -485,7 +485,7 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop, ret = find_available_dev(dinfop, capa, q->node_mask); if (ret <= 0 && dinfop) { WD_ERR("get /%s path fail!\n", dinfop->name); - return -ENODEV; + return -WD_ENODEV; }
if (num) { @@ -496,14 +496,14 @@ static int find_available_res(struct wd_queue *q, struct dev_info *dinfop, dev_path: if (!dinfop) { WD_ERR("dinfop NULL!\n"); - return -EINVAL; + return -WD_EINVAL; }
ret = snprintf(q->dev_path, PATH_STR_SIZE, "%s/%s", LINUX_DEV_DIR, dinfop->name); if (ret <= 0) { WD_ERR("snprintf err, ret %d!\n", ret); - return -EINVAL; + return -WD_EINVAL; } return 0; } @@ -654,7 +654,7 @@ int wd_send(struct wd_queue *q, void *req) { if (unlikely(!q || !req)) { WD_ERR("wd send input parameter null!\n"); - return -EINVAL; + return -WD_EINVAL; } return wd_burst_send(q, &req, 1); } @@ -663,7 +663,7 @@ int wd_recv(struct wd_queue *q, void **resp) { if (unlikely(!q || !resp)) { WD_ERR("wd recv input parameter null!\n"); - return -EINVAL; + return -WD_EINVAL; } return wd_burst_recv(q, resp, 1); } @@ -676,11 +676,11 @@ int wd_wait(struct wd_queue *q, __u16 ms) int ret;
if (unlikely(!q)) - return -EINVAL; + return -WD_EINVAL;
priv = &q->capa.priv; if (unlikely(!priv->is_poll)) - return -EINVAL; + return -WD_EINVAL;
qinfo = q->qinfo; fds[0].fd = qinfo->fd; @@ -688,7 +688,7 @@ int wd_wait(struct wd_queue *q, __u16 ms)
ret = poll(fds, 1, ms); if (unlikely(ret < 0)) - return -ENODEV; + return -WD_ENODEV;
/* return 0 for no data, 1 for new message */ return ret; @@ -735,7 +735,7 @@ int wd_share_reserved_memory(struct wd_queue *q, /* Just share DMA memory from 'q' in NO-IOMMU mode */ if (qinfo->iommu_type) { WD_ERR("IOMMU opened, not support share mem!\n"); - return -EINVAL; + return -WD_EINVAL; }
if (qinfo->iommu_type != tqinfo->iommu_type) { @@ -871,6 +871,7 @@ void wd_drv_unmmap_qfr(struct wd_queue *q, void *addr, else munmap(addr, size); } + int wd_register_log(wd_log log) { if (!log) {
From: Chenghai Huang huangchenghai2@huawei.com
The sec algorithm has multiple common header files, so they are centrally stored in wd_alg_common.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- drv/hisi_sec.c | 11 ++--------- include/wd_alg_common.h | 13 +++++++++++++ include/wd_cipher.h | 1 - include/wd_digest.h | 2 -- wd_aead.c | 9 --------- wd_cipher.c | 7 ------- wd_digest.c | 9 --------- 7 files changed, 15 insertions(+), 37 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 9102a27..5b114f6 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -63,13 +63,6 @@ #define SEC_MAC_LEN_MASK 0x1F #define SEC_AUTH_LEN_MASK 0x3F
-#define DES_KEY_SIZE 8 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) -#define AES_KEYSIZE_128 16 -#define AES_KEYSIZE_192 24 -#define AES_KEYSIZE_256 32 - #define DES3_BLOCK_SIZE 8 #define AES_BLOCK_SIZE 16 #define CTR_128BIT_COUNTER 16 @@ -823,9 +816,9 @@ static void update_iv_sgl(struct wd_cipher_msg *msg)
static int get_3des_c_key_len(struct wd_cipher_msg *msg, __u8 *c_key_len) { - if (msg->key_bytes == SEC_3DES_2KEY_SIZE) { + if (msg->key_bytes == DES3_2KEY_SIZE) { *c_key_len = CKEY_LEN_3DES_2KEY; - } else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) { + } else if (msg->key_bytes == DES3_3KEY_SIZE) { *c_key_len = CKEY_LEN_3DES_3KEY; } else { WD_ERR("failed to check 3des key size, size = %u\n", diff --git a/include/wd_alg_common.h b/include/wd_alg_common.h index 5652db3..32b8630 100644 --- a/include/wd_alg_common.h +++ b/include/wd_alg_common.h @@ -29,6 +29,19 @@ extern "C" { #define CTX_TYPE_INVALID 9999 #define POLL_TIME 1000
+/* Key size of chiper */ +#define MAX_CIPHER_KEY_SIZE 64 +#define AES_KEYSIZE_128 16 +#define AES_KEYSIZE_192 24 +#define AES_KEYSIZE_256 32 +#define SM4_KEY_SIZE 16 +#define DES_KEY_SIZE 8 +#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) +#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) + +/* Key size of digest */ +#define MAX_HMAC_KEY_SIZE 128U + enum alg_task_type { TASK_MIX = 0x0, TASK_HW, diff --git a/include/wd_cipher.h b/include/wd_cipher.h index a712b53..d54f7fe 100644 --- a/include/wd_cipher.h +++ b/include/wd_cipher.h @@ -18,7 +18,6 @@ extern "C" { #define AES_BLOCK_SIZE 16 #define GCM_IV_SIZE 12 #define DES3_BLOCK_SIZE 8 -#define MAX_CIPHER_KEY_SIZE 64 #define MAX_IV_SIZE AES_BLOCK_SIZE
/** diff --git a/include/wd_digest.h b/include/wd_digest.h index ad4d579..f0916c3 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -14,8 +14,6 @@ extern "C" { #endif
-#define MAX_HMAC_KEY_SIZE 128U - /** * wd_digest_type - Algorithm type of digest * algorithm should be offered by struct wd_digest_arg diff --git a/wd_aead.c b/wd_aead.c index 6d49d76..34a3b86 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -10,15 +10,6 @@ #include "include/drv/wd_aead_drv.h" #include "wd_aead.h"
-#define XTS_MODE_KEY_DIVISOR 2 -#define SM4_KEY_SIZE 16 -#define DES_KEY_SIZE 8 -#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) -#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) -#define AES_KEYSIZE_128 16 -#define AES_KEYSIZE_192 24 -#define AES_KEYSIZE_256 32 - #define WD_AEAD_CCM_GCM_MIN 4U #define WD_AEAD_CCM_GCM_MAX 16
diff --git a/wd_cipher.c b/wd_cipher.c index 47c0bf8..f35ce6f 100644 --- a/wd_cipher.c +++ b/wd_cipher.c @@ -13,13 +13,6 @@
#define XTS_MODE_KEY_SHIFT 1 #define XTS_MODE_KEY_LEN_MASK 0x1 -#define SM4_KEY_SIZE 16 -#define DES_KEY_SIZE 8 -#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) -#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) -#define AES_KEYSIZE_128 16 -#define AES_KEYSIZE_192 24 -#define AES_KEYSIZE_256 32
#define DES_WEAK_KEY_NUM 16
diff --git a/wd_digest.c b/wd_digest.c index 9008bcb..acf341a 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -10,16 +10,7 @@ #include "include/drv/wd_digest_drv.h" #include "wd_digest.h"
-#define XTS_MODE_KEY_DIVISOR 2 -#define SM4_KEY_SIZE 16 -#define DES_KEY_SIZE 8 -#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) #define GMAC_IV_LEN 16 -#define AES_KEYSIZE_128 16 -#define AES_KEYSIZE_192 24 -#define AES_KEYSIZE_256 32 - -#define DES_WEAK_KEY_NUM 4
static __u32 g_digest_mac_len[WD_DIGEST_TYPE_MAX] = { WD_DIGEST_SM3_LEN, WD_DIGEST_MD5_LEN, WD_DIGEST_SHA1_LEN,
From: Chenghai Huang huangchenghai2@huawei.com
The number of lines in the param_check function exceeds 50, so subfunctions are added for optimization.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- v1/wd_digest.c | 83 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 30 deletions(-)
diff --git a/v1/wd_digest.c b/v1/wd_digest.c index b8ea5ce..df8a8af 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -371,21 +371,62 @@ static int digest_recv_sync(struct wcrypto_digest_ctx *d_ctx, return recv_count; }
+static int stream_mode_param_check(struct wcrypto_digest_ctx *d_ctx, + struct wcrypto_digest_op_data *d_opdata, __u32 num) +{ + enum wcrypto_digest_alg alg = d_ctx->setup.alg; + + if (unlikely(num != 1)) { + WD_ERR("invalid: wcrypto_burst_digest does not support stream mode, num = %u!\n", + num); + return -WD_EINVAL; + } + + if (unlikely(d_opdata->in_bytes % d_ctx->align_sz)) { + WD_ERR("invalid: digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz); + return -WD_EINVAL; + } + + if (unlikely(d_opdata->out_bytes < g_digest_mac_full_len[alg])) { + WD_ERR("invalid: digest stream mode out buffer space is not enough!\n"); + return -WD_EINVAL; + } + + return WD_SUCCESS; +} + +static int block_mode_param_check(struct wcrypto_digest_ctx *d_ctx, + struct wcrypto_digest_op_data *d_opdata) +{ + enum wcrypto_digest_alg alg = d_ctx->setup.alg; + + if (unlikely(d_opdata->out_bytes > g_digest_mac_len[alg])) { + WD_ERR("invalid: failed to check digest mac length!\n"); + return -WD_EINVAL; + } + + if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC && + (!d_opdata->iv || d_opdata->iv_bytes != SEC_GMAC_IV_LEN))) { + WD_ERR("invalid: failed to check digest aes_gmac iv length, iv_bytes = %u\n", + d_opdata->iv_bytes); + return -WD_EINVAL; + } + + return 0; +} + static int param_check(struct wcrypto_digest_ctx *d_ctx, struct wcrypto_digest_op_data **d_opdata, void **tag, __u32 num) { - enum wcrypto_digest_alg alg; __u32 i; int ret;
if (unlikely(!d_ctx || !d_opdata || !num || num > WCRYPTO_MAX_BURST_NUM)) { - WD_ERR("input param err!\n"); + WD_ERR("invalid: input param err!\n"); return -WD_EINVAL; }
- alg = d_ctx->setup.alg; - for (i = 0; i < num; i++) { if (unlikely(!d_opdata[i])) { WD_ERR("invalid: digest opdata[%u] is NULL!\n", i); @@ -397,37 +438,19 @@ static int param_check(struct wcrypto_digest_ctx *d_ctx, return -WD_EINVAL; }
- ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, d_opdata[i]->out, d_opdata[i]->out_bytes); + ret = wd_check_src_dst(d_opdata[i]->in, d_opdata[i]->in_bytes, + d_opdata[i]->out, d_opdata[i]->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 (d_opdata[i]->has_next) { - if (unlikely(num != 1)) { - WD_ERR("num > 1, wcrypto_burst_digest does not support stream mode!\n"); - return -WD_EINVAL; - } - if (unlikely(d_opdata[i]->in_bytes % d_ctx->align_sz)) { - WD_ERR("digest stream mode must be %u-byte aligned!\n", d_ctx->align_sz); - return -WD_EINVAL; - } - if (unlikely(d_opdata[i]->out_bytes < g_digest_mac_full_len[alg])) { - WD_ERR("digest stream mode out buffer space is not enough!\n"); - return -WD_EINVAL; - } - } else { - if (unlikely(d_opdata[i]->out_bytes > g_digest_mac_len[alg])) { - WD_ERR("failed to check digest mac length!\n"); - return -WD_EINVAL; - } - if (unlikely(d_ctx->setup.alg == WCRYPTO_AES_GMAC && - (!d_opdata[i]->iv || d_opdata[i]->iv_bytes != SEC_GMAC_IV_LEN))) { - WD_ERR("failed to check digest aes_gmac iv length, iv_bytes = %u\n", - d_opdata[i]->iv_bytes); - return -WD_EINVAL; - } - } + if (d_opdata[i]->has_next) + ret = stream_mode_param_check(d_ctx, d_opdata[i], num); + else + ret = block_mode_param_check(d_ctx, d_opdata[i]); + if (unlikely(ret)) + return ret;
if (unlikely(tag && !tag[i])) { WD_ERR("invalid: tag[%u] is NULL!\n", i);
From: Chenghai Huang huangchenghai2@huawei.com
The sec algorithm has multiple common header files, so they are centrally stored in wd_alg_common.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- v1/drv/hisi_sec_udrv.c | 11 ++--------- v1/wd_aead.c | 15 --------------- v1/wd_cipher.c | 9 +-------- v1/wd_digest.c | 1 - v1/wd_util.h | 17 +++++++++++++++++ 5 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index 02a63c2..d046327 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -31,10 +31,6 @@ #include "config.h" #include "hisi_sec_udrv.h"
-#define DES_KEY_SIZE 8 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) - #define SEC_HW_TASK_DONE 1 #define SEC_HW_ICV_ERR 0x2 #define SEC_SM4_XTS_GB_V3 0x1 @@ -47,11 +43,8 @@ #define CTR_128BIT_COUNTER 16 #define CTR_128BIT_FLIP 0x2 #define DIF_VERIFY_FAIL 2 -#define AES_BLOCK_SIZE 16 #define WCRYPTO_CIPHER_THEN_DIGEST 0 #define WCRYPTO_DIGEST_THEN_CIPHER 1 -#define CBC_3DES_BLOCK_SIZE 8 -#define CBC_AES_BLOCK_SIZE 16 #define AEAD_IV_MAX_BYTES 64 #define MAX_CCM_AAD_LEN 65279 #define SEC_GMAC_IV_LEN 16 @@ -111,9 +104,9 @@ static int get_aes_c_key_len(__u8 mode, __u16 key_bytes, __u8 *c_key_len)
static int get_3des_c_key_len(struct wcrypto_cipher_msg *msg, __u8 *c_key_len) { - if (msg->key_bytes == SEC_3DES_2KEY_SIZE) + if (msg->key_bytes == DES3_2KEY_SIZE) *c_key_len = CKEY_LEN_3DES_2KEY; - else if (msg->key_bytes == SEC_3DES_3KEY_SIZE) + else if (msg->key_bytes == DES3_3KEY_SIZE) *c_key_len = CKEY_LEN_3DES_3KEY; else { WD_ERR("Invalid 3DES key size!\n"); diff --git a/v1/wd_aead.c b/v1/wd_aead.c index 38429fc..380daf0 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -26,24 +26,9 @@ #include "wd_util.h" #include "wd_aead.h"
-#define MAX_AEAD_KEY_SIZE 64 -#define MAX_AEAD_MAC_SIZE 64 -#define MAX_CIPHER_KEY_SIZE 64 #define MAX_AEAD_AUTH_SIZE 64 -#define MAX_AEAD_ASSOC_SIZE 65536 -#define MAX_HMAC_KEY_SIZE 128 #define MAX_AEAD_RETRY_CNT 20000000
-#define DES_KEY_SIZE 8 -#define SM4_KEY_SIZE 16 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE) - -#define AES_BLOCK_SIZE 16 -#define GCM_BLOCK_SIZE 12 - -#define MAX_BURST_NUM 16 - static int g_aead_mac_len[WCRYPTO_MAX_DIGEST_TYPE] = { WCRYPTO_SM3_LEN, WCRYPTO_MD5_LEN, WCRYPTO_SHA1_LEN, WCRYPTO_SHA256_LEN, WCRYPTO_SHA224_LEN, diff --git a/v1/wd_cipher.c b/v1/wd_cipher.c index f95015d..0877993 100644 --- a/v1/wd_cipher.c +++ b/v1/wd_cipher.c @@ -26,17 +26,10 @@ #include "v1/wd_util.h" #include "v1/wd_cipher.h"
-#define MAX_CIPHER_KEY_SIZE 64 #define MAX_CIPHER_RETRY_CNT 20000000
#define XTS_MODE_KEY_LEN_MASK 0x1 -#define DES_KEY_SIZE 8 -#define SM4_KEY_SIZE 16 -#define SEC_3DES_2KEY_SIZE (2 * DES_KEY_SIZE) -#define SEC_3DES_3KEY_SIZE (3 * DES_KEY_SIZE)
-#define CBC_3DES_BLOCK_SIZE 8 -#define CBC_AES_BLOCK_SIZE 16 #define DES_WEAK_KEY_NUM 4 static __u64 des_weak_key[DES_WEAK_KEY_NUM] = {0x0101010101010101, 0xFEFEFEFEFEFEFEFE, 0xE0E0E0E0F1F1F1F1, 0x1F1F1F1F0E0E0E0E}; @@ -300,7 +293,7 @@ static int cipher_key_len_check(struct wcrypto_cipher_ctx_setup *setup, ret = -WD_EINVAL; break; case WCRYPTO_CIPHER_3DES: - if ((key_len != SEC_3DES_2KEY_SIZE) && (key_len != SEC_3DES_3KEY_SIZE)) + if ((key_len != DES3_2KEY_SIZE) && (key_len != DES3_3KEY_SIZE)) ret = -WD_EINVAL; break; default: diff --git a/v1/wd_digest.c b/v1/wd_digest.c index df8a8af..cb9b6e0 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -26,7 +26,6 @@ #include "wd_util.h" #include "wd_digest.h"
-#define MAX_HMAC_KEY_SIZE 128 #define MAX_DIGEST_RETRY_CNT 20000000 #define SEC_SHA1_ALIGN_SZ 64 #define SEC_SHA512_ALIGN_SZ 128 diff --git a/v1/wd_util.h b/v1/wd_util.h index bf17058..9e5fa90 100644 --- a/v1/wd_util.h +++ b/v1/wd_util.h @@ -76,6 +76,23 @@ #define X_DH_OUT_PARAM_NUM 1 #define X_DH_HW_KEY_PARAM_NUM 3
+/* Key size and block size of aead */ +#define MAX_AEAD_KEY_SIZE 64 +#define GCM_BLOCK_SIZE 12 + +/* Key size and block size of chiper */ +#define MAX_CIPHER_KEY_SIZE 64 +#define AES_BLOCK_SIZE 16 +#define DES_KEY_SIZE 8 +#define SM4_KEY_SIZE 16 +#define DES3_2KEY_SIZE (2 * DES_KEY_SIZE) +#define DES3_3KEY_SIZE (3 * DES_KEY_SIZE) +#define CBC_AES_BLOCK_SIZE 16 +#define CBC_3DES_BLOCK_SIZE 8 + +/* Key size and block size of digest */ +#define MAX_HMAC_KEY_SIZE 128 + #define X_DH_OUT_PARAMS_SZ(hsz) ((hsz) * X_DH_OUT_PARAM_NUM) #define X_DH_HW_KEY_SZ(hsz) ((hsz) * X_DH_HW_KEY_PARAM_NUM) #define SM2_KG_OUT_PARAMS_SZ(hsz) ((hsz) * SM2_KG_OUT_PARAM_NUM)