diff --git a/wolfcrypt/src/md5.c b/wolfcrypt/src/md5.c index 342aea466..fcaa73965 100755 --- a/wolfcrypt/src/md5.c +++ b/wolfcrypt/src/md5.c @@ -447,6 +447,9 @@ int wc_Md5Final(Md5* md5, byte* hash) int wc_InitMd5(Md5* md5) { + if (md5 == NULL) { + return BAD_FUNC_ARG; + } return wc_InitMd5_ex(md5, NULL, INVALID_DEVID); } diff --git a/wolfcrypt/src/sha.c b/wolfcrypt/src/sha.c index f98cb7272..e35c5ba7d 100755 --- a/wolfcrypt/src/sha.c +++ b/wolfcrypt/src/sha.c @@ -42,6 +42,9 @@ } int wc_InitSha_ex(Sha* sha, void* heap, int devId) { + if (sha == NULL) { + return BAD_FUNC_ARG; + } (void)heap; (void)devId; return InitSha_fips(sha); @@ -543,6 +546,9 @@ int wc_ShaFinal(Sha* sha, byte* hash) int wc_InitSha(Sha* sha) { + if (sha == NULL) { + return BAD_FUNC_ARG; + } return wc_InitSha_ex(sha, NULL, INVALID_DEVID); } diff --git a/wolfcrypt/src/sha256.c b/wolfcrypt/src/sha256.c index 40fc57e53..40eb0f421 100755 --- a/wolfcrypt/src/sha256.c +++ b/wolfcrypt/src/sha256.c @@ -45,6 +45,9 @@ } int wc_InitSha256_ex(Sha256* sha, void* heap, int devId) { + if (sha == NULL) { + return BAD_FUNC_ARG; + } (void)heap; (void)devId; return InitSha256_fips(sha); @@ -562,9 +565,14 @@ static int InitSha256(Sha256* sha256) static INLINE int Sha256Final(Sha256* sha256) { + int ret; byte* local = (byte*)sha256->buffer; + if (sha256 == NULL) { + return BAD_FUNC_ARG; + } + SAVE_XMM_YMM; /* for Intel AVX */ AddLength(sha256, sha256->buffLen); /* before adding pads */ @@ -1918,6 +1926,9 @@ static int Transform_AVX2(Sha256* sha256) int wc_InitSha256(Sha256* sha256) { + if (sha256 == NULL) { + return BAD_FUNC_ARG; + } return wc_InitSha256_ex(sha256, NULL, INVALID_DEVID); } diff --git a/wolfcrypt/src/sha512.c b/wolfcrypt/src/sha512.c index 9d9233605..8b560d04c 100755 --- a/wolfcrypt/src/sha512.c +++ b/wolfcrypt/src/sha512.c @@ -44,6 +44,9 @@ } int wc_InitSha512_ex(Sha512* sha, void* heap, int devId) { + if (sha == NULL) { + return BAD_FUNC_ARG; + } (void)heap; (void)devId; return InitSha512_fips(sha); @@ -537,7 +540,9 @@ static INLINE void AddLength(Sha512* sha512, word32 len) static INLINE int Sha512Update(Sha512* sha512, const byte* data, word32 len) { int ret = 0; - + if (sha512 == NULL || (data == NULL && len > 0)) { + return BAD_FUNC_ARG; + } /* do block size increments */ byte* local = (byte*)sha512->buffer; @@ -598,6 +603,10 @@ static INLINE int Sha512Final(Sha512* sha512) byte* local = (byte*)sha512->buffer; int ret; + if (sha512 == NULL) { + return BAD_FUNC_ARG; + } + SAVE_XMM_YMM ; /* for Intel AVX */ AddLength(sha512, sha512->buffLen); /* before adding pads */