From: Weili Qian <qianweili@huawei.com> When looking up the corresponding driver by algorithm type, since the driver does not save the algorithm type, it cannot be directly obtained. Therefore, the algorithm type should be saved during algorithm registration. Signed-off-by: Weili Qian <qianweili@huawei.com> --- include/wd_alg.h | 2 ++ libwd.map | 1 + wd_alg.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++ wd_util.c | 94 ++++-------------------------------------------- 4 files changed, 102 insertions(+), 87 deletions(-) diff --git a/include/wd_alg.h b/include/wd_alg.h index 5ff73ca..848bdf1 100644 --- a/include/wd_alg.h +++ b/include/wd_alg.h @@ -145,6 +145,7 @@ struct wd_alg_list { struct wd_alg_driver *drv; struct wd_alg_list *next; + char alg_type[ALG_NAME_SIZE]; }; /* @@ -178,6 +179,7 @@ int wd_alg_driver_init(struct wd_alg_driver *drv, void *conf); void wd_alg_driver_exit(struct wd_alg_driver *drv); int wd_alg_driver_send(struct wd_alg_driver *drv, handle_t ctx, void *msg); int wd_alg_driver_recv(struct wd_alg_driver *drv, handle_t ctx, void *msg); +int wd_get_alg_type(const char *alg_name, char *alg_type); struct wd_alg_list *wd_get_alg_head(void); diff --git a/libwd.map b/libwd.map index 90eb5c5..5d732d0 100644 --- a/libwd.map +++ b/libwd.map @@ -53,6 +53,7 @@ global: wd_alg_driver_exit; wd_alg_driver_send; wd_alg_driver_recv; + wd_get_alg_type; wd_find_ctx; wd_get_dev_id; diff --git a/wd_alg.c b/wd_alg.c index 9c7c0fd..919483b 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -24,6 +24,97 @@ static struct wd_alg_list *alg_list_tail = &alg_list_head; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +struct acc_alg_item { + const char *name; + const char *algtype; +}; + +static struct acc_alg_item alg_options[] = { + {"zlib", "zlib"}, + {"gzip", "gzip"}, + {"deflate", "deflate"}, + {"lz77_zstd", "lz77_zstd"}, + {"lz4", "lz4"}, + {"lz77_only", "lz77_only"}, + {"hashagg", "hashagg"}, + {"udma", "udma"}, + {"hashjoin", "hashjoin"}, + {"gather", "gather"}, + {"join-gather", "hashjoin"}, + + {"rsa", "rsa"}, + {"dh", "dh"}, + {"ecdh", "ecdh"}, + {"x25519", "x25519"}, + {"x448", "x448"}, + {"ecdsa", "ecdsa"}, + {"sm2", "sm2"}, + + {"ecb(aes)", "cipher"}, + {"cbc(aes)", "cipher"}, + {"xts(aes)", "cipher"}, + {"ofb(aes)", "cipher"}, + {"cfb(aes)", "cipher"}, + {"ctr(aes)", "cipher"}, + {"cbc-cs1(aes)", "cipher"}, + {"cbc-cs2(aes)", "cipher"}, + {"cbc-cs3(aes)", "cipher"}, + {"ecb(sm4)", "cipher"}, + {"xts(sm4)", "cipher"}, + {"cbc(sm4)", "cipher"}, + {"ofb(sm4)", "cipher"}, + {"cfb(sm4)", "cipher"}, + {"ctr(sm4)", "cipher"}, + {"cbc-cs1(sm4)", "cipher"}, + {"cbc-cs2(sm4)", "cipher"}, + {"cbc-cs3(sm4)", "cipher"}, + {"ecb(des)", "cipher"}, + {"cbc(des)", "cipher"}, + {"ecb(des3_ede)", "cipher"}, + {"cbc(des3_ede)", "cipher"}, + + {"ccm(aes)", "aead"}, + {"gcm(aes)", "aead"}, + {"ccm(sm4)", "aead"}, + {"gcm(sm4)", "aead"}, + {"authenc(generic,cbc(aes))", "aead"}, + {"authenc(generic,cbc(sm4))", "aead"}, + + {"sm3", "digest"}, + {"md5", "digest"}, + {"sha1", "digest"}, + {"sha256", "digest"}, + {"sha224", "digest"}, + {"sha384", "digest"}, + {"sha512", "digest"}, + {"sha512-224", "digest"}, + {"sha512-256", "digest"}, + {"cmac(aes)", "digest"}, + {"gmac(aes)", "digest"}, + {"xcbc-mac-96(aes)", "digest"}, + {"xcbc-prf-128(aes)", "digest"}, + {"", ""} +}; + +int wd_get_alg_type(const char *alg_name, char *alg_type) +{ + __u64 i; + + if (!alg_name || !alg_type) { + WD_ERR("invalid: alg_name or alg_type is NULL!\n"); + return -WD_EINVAL; + } + + for (i = 0; i < ARRAY_SIZE(alg_options); i++) { + if (strcmp(alg_name, alg_options[i].name) == 0) { + (void)strcpy(alg_type, alg_options[i].algtype); + return 0; + } + } + + return -WD_EINVAL; +} + static bool wd_check_accel_dev(const char *dev_name) { struct dirent *dev_dir; @@ -182,6 +273,7 @@ int wd_alg_driver_register(struct wd_alg_driver *drv) return -WD_ENOMEM; } + (void)wd_get_alg_type(drv->alg_name, new_alg->alg_type); strncpy(new_alg->alg_name, drv->alg_name, ALG_NAME_SIZE - 1); strncpy(new_alg->drv_name, drv->drv_name, DEV_NAME_LEN - 1); new_alg->priority = drv->priority; diff --git a/wd_util.c b/wd_util.c index 138a078..67a46a6 100644 --- a/wd_util.c +++ b/wd_util.c @@ -98,78 +98,6 @@ struct drv_lib_list { struct drv_lib_list *next; }; -struct acc_alg_item { - const char *name; - const char *algtype; -}; - -static struct acc_alg_item alg_options[] = { - {"zlib", "zlib"}, - {"gzip", "gzip"}, - {"deflate", "deflate"}, - {"lz77_zstd", "lz77_zstd"}, - {"lz4", "lz4"}, - {"lz77_only", "lz77_only"}, - {"hashagg", "hashagg"}, - {"udma", "udma"}, - {"hashjoin", "hashjoin"}, - {"gather", "gather"}, - {"join-gather", "hashjoin"}, - - {"rsa", "rsa"}, - {"dh", "dh"}, - {"ecdh", "ecdh"}, - {"x25519", "x25519"}, - {"x448", "x448"}, - {"ecdsa", "ecdsa"}, - {"sm2", "sm2"}, - - {"ecb(aes)", "cipher"}, - {"cbc(aes)", "cipher"}, - {"xts(aes)", "cipher"}, - {"ofb(aes)", "cipher"}, - {"cfb(aes)", "cipher"}, - {"ctr(aes)", "cipher"}, - {"cbc-cs1(aes)", "cipher"}, - {"cbc-cs2(aes)", "cipher"}, - {"cbc-cs3(aes)", "cipher"}, - {"ecb(sm4)", "cipher"}, - {"xts(sm4)", "cipher"}, - {"cbc(sm4)", "cipher"}, - {"ofb(sm4)", "cipher"}, - {"cfb(sm4)", "cipher"}, - {"ctr(sm4)", "cipher"}, - {"cbc-cs1(sm4)", "cipher"}, - {"cbc-cs2(sm4)", "cipher"}, - {"cbc-cs3(sm4)", "cipher"}, - {"ecb(des)", "cipher"}, - {"cbc(des)", "cipher"}, - {"ecb(des3_ede)", "cipher"}, - {"cbc(des3_ede)", "cipher"}, - - {"ccm(aes)", "aead"}, - {"gcm(aes)", "aead"}, - {"ccm(sm4)", "aead"}, - {"gcm(sm4)", "aead"}, - {"authenc(generic,cbc(aes))", "aead"}, - {"authenc(generic,cbc(sm4))", "aead"}, - - {"sm3", "digest"}, - {"md5", "digest"}, - {"sha1", "digest"}, - {"sha256", "digest"}, - {"sha224", "digest"}, - {"sha384", "digest"}, - {"sha512", "digest"}, - {"sha512-224", "digest"}, - {"sha512-256", "digest"}, - {"cmac(aes)", "digest"}, - {"gmac(aes)", "digest"}, - {"xcbc-mac-96(aes)", "digest"}, - {"xcbc-prf-128(aes)", "digest"}, - {"", ""} -}; - static void *wd_internal_alloc(void *usr, size_t size) { if (size != 0) @@ -2013,18 +1941,6 @@ int wd_init_param_check(struct wd_ctx_config *config, struct wd_sched *sched) return 0; } -static void wd_get_alg_type(const char *alg_name, char *alg_type) -{ - __u64 i; - - for (i = 0; i < ARRAY_SIZE(alg_options); i++) { - if (strcmp(alg_name, alg_options[i].name) == 0) { - (void)strcpy(alg_type, alg_options[i].algtype); - break; - } - } -} - static int wd_alg_init_fallback(struct wd_alg_driver *fb_driver) { if (!fb_driver->init) { @@ -2175,7 +2091,7 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha char *left, *section, *start; struct uacce_dev_list *list; int is_comp; - int ret = 0; + int ret; /* COMP environment variable's format is different, mark it */ is_comp = strncmp(name, "WD_COMP_CTX_NUM", strlen(name)) ? 0 : 1; @@ -2186,7 +2102,10 @@ static int wd_env_set_ctx_nums(const char *alg_name, const char *name, const cha if (!start) return -WD_ENOMEM; - wd_get_alg_type(alg_name, alg_type); + ret = wd_get_alg_type(alg_name, alg_type); + if (ret) + return ret; + list = wd_get_accel_list(alg_type); if (!list) { WD_ERR("failed to get devices!\n"); @@ -3112,7 +3031,8 @@ int wd_alg_attrs_init(struct wd_init_attrs *attrs) } break; case UADK_ALG_HW: - wd_get_alg_type(alg, alg_type); + if (wd_get_alg_type(alg, alg_type)) + return -WD_EINVAL; (void)strcpy(attrs->alg, alg_type); ctx_config = calloc(1, sizeof(*ctx_config)); -- 2.33.0