forked from wolfSSL/wolfssl
HashFree for TI hash memory leak
This commit is contained in:
@ -5940,13 +5940,12 @@ static INLINE void Md5Rounds(int rounds, const byte* data, int sz)
|
||||
{
|
||||
Md5 md5;
|
||||
int i;
|
||||
byte dummy[MD5_DIGEST_SIZE] ;
|
||||
|
||||
wc_InitMd5(&md5);
|
||||
|
||||
for (i = 0; i < rounds; i++)
|
||||
wc_Md5Update(&md5, data, sz);
|
||||
wc_Md5Final(&md5, dummy) ; /* in case needed to release resources */
|
||||
wc_Md5Free(&md5) ; /* in case needed to release resources */
|
||||
}
|
||||
|
||||
|
||||
@ -5956,13 +5955,12 @@ static INLINE void ShaRounds(int rounds, const byte* data, int sz)
|
||||
{
|
||||
Sha sha;
|
||||
int i;
|
||||
byte dummy[SHA_DIGEST_SIZE] ;
|
||||
|
||||
wc_InitSha(&sha); /* no error check on purpose, dummy round */
|
||||
|
||||
for (i = 0; i < rounds; i++)
|
||||
wc_ShaUpdate(&sha, data, sz);
|
||||
wc_ShaFinal(&sha, dummy) ; /* in case needed to release resources */
|
||||
wc_ShaFree(&sha) ; /* in case needed to release resources */
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -5973,7 +5971,6 @@ static INLINE void Sha256Rounds(int rounds, const byte* data, int sz)
|
||||
{
|
||||
Sha256 sha256;
|
||||
int i;
|
||||
byte dummy[SHA256_DIGEST_SIZE] ;
|
||||
|
||||
wc_InitSha256(&sha256); /* no error check on purpose, dummy round */
|
||||
|
||||
@ -5981,7 +5978,7 @@ static INLINE void Sha256Rounds(int rounds, const byte* data, int sz)
|
||||
wc_Sha256Update(&sha256, data, sz);
|
||||
/* no error check on purpose, dummy round */
|
||||
}
|
||||
wc_Sha256Final(&sha256, dummy) ; /* in case needed to release resources */
|
||||
wc_Sha256Free(&sha256) ; /* in case needed to release resources */
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -5993,7 +5990,6 @@ static INLINE void Sha384Rounds(int rounds, const byte* data, int sz)
|
||||
{
|
||||
Sha384 sha384;
|
||||
int i;
|
||||
byte dummy[SHA384_DIGEST_SIZE] ;
|
||||
|
||||
wc_InitSha384(&sha384); /* no error check on purpose, dummy round */
|
||||
|
||||
@ -6001,7 +5997,7 @@ static INLINE void Sha384Rounds(int rounds, const byte* data, int sz)
|
||||
wc_Sha384Update(&sha384, data, sz);
|
||||
/* no error check on purpose, dummy round */
|
||||
}
|
||||
wc_Sha384Final(&sha384, dummy) ; /* in case needed to release resources */
|
||||
wc_Sha384Free(&sha384) ; /* in case needed to release resources */
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -6013,7 +6009,6 @@ static INLINE void Sha512Rounds(int rounds, const byte* data, int sz)
|
||||
{
|
||||
Sha512 sha512;
|
||||
int i;
|
||||
byte dummy[SHA512_DIGEST_SIZE] ;
|
||||
|
||||
wc_InitSha512(&sha512); /* no error check on purpose, dummy round */
|
||||
|
||||
@ -6021,7 +6016,7 @@ static INLINE void Sha512Rounds(int rounds, const byte* data, int sz)
|
||||
wc_Sha512Update(&sha512, data, sz);
|
||||
/* no error check on purpose, dummy round */
|
||||
}
|
||||
wc_Sha512Final(&sha512, dummy) ; /* in case needed to release resources */
|
||||
wc_Sha512Free(&sha512) ; /* in case needed to release resources */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
16
wolfcrypt/src/hash.c
Normal file → Executable file
16
wolfcrypt/src/hash.c
Normal file → Executable file
@ -42,6 +42,9 @@ void wc_Md5GetHash(Md5* md5, byte* hash)
|
||||
WOLFSSL_API void wc_Md5RestorePos(Md5* m1, Md5* m2) {
|
||||
*m1 = *m2 ;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Md5Free(Md5* md5) { (void) md5 ; }
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(NO_SHA)
|
||||
@ -89,6 +92,8 @@ int wc_ShaHash(const byte* data, word32 len, byte* hash)
|
||||
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_ShaFree(Sha* sha) { (void) sha ; }
|
||||
|
||||
#endif /* !defined(NO_SHA) */
|
||||
|
||||
#if !defined(NO_SHA256)
|
||||
@ -136,8 +141,12 @@ int wc_Sha256Hash(const byte* data, word32 len, byte* hash)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Sha256Free(Sha256* sha256) { (void)sha256 ; }
|
||||
|
||||
#endif /* !defined(NO_SHA256) */
|
||||
|
||||
#endif /* !defined(WOLFSSL_TI_HASH) */
|
||||
|
||||
#if defined(WOLFSSL_SHA512)
|
||||
int wc_Sha512Hash(const byte* data, word32 len, byte* hash)
|
||||
@ -172,6 +181,8 @@ int wc_Sha512Hash(const byte* data, word32 len, byte* hash)
|
||||
return ret;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Sha512Free(Sha512* sha512) { (void)sha512 ; }
|
||||
|
||||
#if defined(WOLFSSL_SHA384)
|
||||
int wc_Sha384Hash(const byte* data, word32 len, byte* hash)
|
||||
{
|
||||
@ -205,8 +216,7 @@ int wc_Sha384Hash(const byte* data, word32 len, byte* hash)
|
||||
return ret;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Sha384Free(Sha384* sha384) { (void) sha384 ; }
|
||||
|
||||
#endif /* defined(WOLFSSL_SHA384) */
|
||||
#endif /* defined(WOLFSSL_SHA512) */
|
||||
|
||||
#endif /* !defined(WOLFSSL_TI_HASH) */
|
||||
|
||||
|
28
wolfcrypt/src/port/ti/ti-hash.c
Normal file → Executable file
28
wolfcrypt/src/port/ti/ti-hash.c
Normal file → Executable file
@ -151,6 +151,13 @@ static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word3
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int hashFree(wolfssl_TI_Hash *hash)
|
||||
{
|
||||
XFREE(hash->msg, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
hashInit(hash) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
#if !defined(NO_MD5)
|
||||
WOLFSSL_API void wc_InitMd5(Md5* md5)
|
||||
{
|
||||
@ -183,6 +190,11 @@ WOLFSSL_API int wc_Md5Hash(const byte*data, word32 len, byte*hash)
|
||||
return hashHash(data, len, hash, SHAMD5_ALGO_MD5, MD5_DIGEST_SIZE) ;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Md5Free(Md5* md5)
|
||||
{
|
||||
hashFree((wolfssl_TI_Hash *)md5) ;
|
||||
}
|
||||
|
||||
#endif /* NO_MD5 */
|
||||
|
||||
#if !defined(NO_SHA)
|
||||
@ -217,6 +229,11 @@ WOLFSSL_API int wc_ShaHash(const byte*data, word32 len, byte*hash)
|
||||
return hashHash(data, len, hash, SHAMD5_ALGO_SHA1, SHA_DIGEST_SIZE) ;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_ShaFree(Sha* sha)
|
||||
{
|
||||
hashFree((wolfssl_TI_Hash *)sha) ;
|
||||
}
|
||||
|
||||
#endif /* NO_SHA */
|
||||
|
||||
#if defined(HAVE_SHA224)
|
||||
@ -251,6 +268,11 @@ WOLFSSL_API int wc_Sha224Hash(const byte* data, word32 len, byte*hash)
|
||||
return hashHash(data, len, hash, SHAMD5_ALGO_SHA224, SHA224_DIGEST_SIZE) ;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Sha224Free(Sha224* sha224)
|
||||
{
|
||||
hashFree((wolfssl_TI_Hash *)sha224) ;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SHA224 */
|
||||
|
||||
#if !defined(NO_SHA256)
|
||||
@ -284,6 +306,12 @@ WOLFSSL_API int wc_Sha256Hash(const byte* data, word32 len, byte*hash)
|
||||
{
|
||||
return hashHash(data, len, hash, SHAMD5_ALGO_SHA256, SHA256_DIGEST_SIZE) ;
|
||||
}
|
||||
|
||||
WOLFSSL_API void wc_Sha256Free(Sha256* sha256)
|
||||
{
|
||||
hashFree((wolfssl_TI_Hash *)sha256) ;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
5
wolfssl/wolfcrypt/hash.h
Normal file → Executable file
5
wolfssl/wolfcrypt/hash.h
Normal file → Executable file
@ -28,6 +28,7 @@
|
||||
#include <wolfssl/wolfcrypt/md5.h>
|
||||
WOLFSSL_API void wc_Md5GetHash(Md5*, byte*);
|
||||
WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ;
|
||||
WOLFSSL_API void wc_Md5Free(Md5*);
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
@ -35,6 +36,7 @@ WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ;
|
||||
WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
|
||||
WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*) ;
|
||||
WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
|
||||
WOLFSSL_API void wc_ShaFree(Sha*);
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
@ -42,13 +44,16 @@ WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
|
||||
WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
|
||||
WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*) ;
|
||||
WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
|
||||
WOLFSSL_API void wc_Sha256Free(Sha256*);
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA512
|
||||
#include <wolfssl/wolfcrypt/sha512.h>
|
||||
WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*);
|
||||
WOLFSSL_API void wc_Sha512Free(Sha512*);
|
||||
#if defined(WOLFSSL_SHA384)
|
||||
WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*);
|
||||
WOLFSSL_API void wc_Sha384Free(Sha384*);
|
||||
#endif /* defined(WOLFSSL_SHA384) */
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
|
Reference in New Issue
Block a user