From: Wenkai Lin linwenkai6@hisilicon.com
SM4 CE driver set priv size to 0, allocating memory is not allowed, so set a proper priv size and add size check.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- drv/isa_ce_sm4.c | 3 +++ drv/isa_ce_sm4.h | 5 +++++ 2 files changed, 8 insertions(+)
diff --git a/drv/isa_ce_sm4.c b/drv/isa_ce_sm4.c index 6028367..4aa62f1 100644 --- a/drv/isa_ce_sm4.c +++ b/drv/isa_ce_sm4.c @@ -34,8 +34,11 @@ static int isa_ce_init(struct wd_alg_driver *drv, void *conf) { struct wd_ctx_config_internal *config = conf; + struct sm4_ce_drv_ctx *sctx = drv->priv;
config->epoll_en = 0; + memcpy(&sctx->config, config, sizeof(struct wd_ctx_config_internal)); + return 0; }
diff --git a/drv/isa_ce_sm4.h b/drv/isa_ce_sm4.h index 9ae027d..a80224f 100644 --- a/drv/isa_ce_sm4.h +++ b/drv/isa_ce_sm4.h @@ -6,6 +6,7 @@
#pragma once #include <stdint.h> +#include "wd_alg_common.h"
#ifdef __cplusplus extern "C" { @@ -17,6 +18,10 @@ struct SM4_KEY { __u32 rk[SM4_KEY_SCHEDULE]; };
+struct sm4_ce_drv_ctx { + struct wd_ctx_config_internal config; +}; +
void sm4_v8_set_encrypt_key(const unsigned char *userKey, struct SM4_KEY *key); void sm4_v8_set_decrypt_key(const unsigned char *userKey, struct SM4_KEY *key);