diff --git a/src/os400qc3.c b/src/os400qc3.c index 64d4df06b0..f60b850a59 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -956,6 +956,8 @@ null_token(const char *token) void _libssh2_os400qc3_crypto_dtor(_libssh2_os400qc3_crypto_ctx *x) { + if (!x) + return; if (!null_token(x->hash.Alg_Context_Token)) { Qc3DestroyAlgorithmContext(x->hash.Alg_Context_Token, (char *) &ecnull); memset(x->hash.Alg_Context_Token, 0, sizeof x->hash.Alg_Context_Token); @@ -964,6 +966,11 @@ _libssh2_os400qc3_crypto_dtor(_libssh2_os400qc3_crypto_ctx *x) Qc3DestroyKeyContext(x->key.Key_Context_Token, (char *) &ecnull); memset(x->key.Key_Context_Token, 0, sizeof x->key.Key_Context_Token); } + if (x->kek) { + _libssh2_os400qc3_crypto_dtor(x->kek); + free((char *) x->kek); + x->kek = NULL; + } } /******************************************************************* diff --git a/src/os400qc3.h b/src/os400qc3.h index daca943f46..784b3ad493 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -189,10 +189,13 @@ * *******************************************************************/ -typedef struct { /* HMAC & private key algorithms support structure. */ - Qc3_Format_ALGD0100_T hash; /* Hash algorithm. */ - Qc3_Format_KEYD0100_T key; /* Key. */ -} _libssh2_os400qc3_crypto_ctx; +/* HMAC & private key algorithms support structure. */ +typedef struct _libssh2_os400qc3_crypto_ctx _libssh2_os400qc3_crypto_ctx; +struct _libssh2_os400qc3_crypto_ctx { + Qc3_Format_ALGD0100_T hash; /* Hash algorithm. */ + Qc3_Format_KEYD0100_T key; /* Key. */ + _libssh2_os400qc3_crypto_ctx * kek; /* Key encryption. */ +}; typedef struct { /* Big number. */ unsigned char * bignum; /* Number bits, little-endian. */ @@ -240,7 +243,9 @@ typedef struct { /* Algorithm description. */ libssh2_os400qc3_hash_update(&(ctx), data, len) #define libssh2_md5_final(ctx, out) \ libssh2_os400qc3_hash_final(&(ctx), out) -#define libssh2_hmac_ctx_init(ctx) +#define libssh2_hmac_ctx_init(ctx) \ + memset((char *) &(ctx), 0, \ + sizeof(libssh2_hmac_ctx)) #define libssh2_hmac_md5_init(ctx, key, keylen) \ libssh2_os400qc3_hmac_init(ctx, Qc3_MD5, \ key, keylen)