Because the java releases the memory immediately after the memory is used. So the engine should not use user memory for storage the key.
Signed-off-by: Kai Ye yekai13@huawei.com --- src/uadk_cipher.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/uadk_cipher.c b/src/uadk_cipher.c index 5dd2178..60f5058 100644 --- a/src/uadk_cipher.c +++ b/src/uadk_cipher.c @@ -36,6 +36,7 @@ #define BYTE_BITS 8 #define IV_LEN 16 #define ENV_ENABLED 1 +#define MAX_KEY_LEN 64
struct cipher_engine { struct wd_ctx_config ctx_cfg; @@ -57,7 +58,7 @@ struct cipher_priv_ctx { struct wd_cipher_sess_setup setup; struct wd_cipher_req req; unsigned char iv[IV_LEN]; - const unsigned char *key; + unsigned char key[MAX_KEY_LEN]; int switch_flag; void *sw_ctx_data; /* Crypto small packet offload threshold */ @@ -694,7 +695,7 @@ static int uadk_e_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, if (unlikely(ret != 1)) return 0;
- priv->key = key; + memcpy(priv->key, key, EVP_CIPHER_CTX_key_length(ctx)); priv->switch_threshold = SMALL_PACKET_OFFLOAD_THRESHOLD_DEFAULT;
return 1;