diff --git a/src/internal.c b/src/internal.c index 36d2086ab..8844c9ac8 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6001,6 +6001,7 @@ static INLINE void Md5Rounds(int rounds, const byte* data, int sz) for (i = 0; i < rounds; i++) wc_Md5Update(&md5, data, sz); + wc_Md5Free(&md5) ; /* in case needed to release resources */ } @@ -6015,6 +6016,7 @@ static INLINE void ShaRounds(int rounds, const byte* data, int sz) for (i = 0; i < rounds; i++) wc_ShaUpdate(&sha, data, sz); + wc_ShaFree(&sha) ; /* in case needed to release resources */ } #endif @@ -6032,7 +6034,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_Sha256Free(&sha256) ; /* in case needed to release resources */ } #endif @@ -6051,6 +6053,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_Sha384Free(&sha384) ; /* in case needed to release resources */ } #endif @@ -6069,6 +6072,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_Sha512Free(&sha512) ; /* in case needed to release resources */ } #endif diff --git a/wolfcrypt/src/hash.c b/wolfcrypt/src/hash.c old mode 100644 new mode 100755 index d397e91fa..58fce69f8 --- a/wolfcrypt/src/hash.c +++ b/wolfcrypt/src/hash.c @@ -42,6 +42,7 @@ void wc_Md5GetHash(Md5* md5, byte* hash) WOLFSSL_API void wc_Md5RestorePos(Md5* m1, Md5* m2) { *m1 = *m2 ; } + #endif #if !defined(NO_SHA) @@ -136,8 +137,10 @@ int wc_Sha256Hash(const byte* data, word32 len, byte* hash) return ret; } + #endif /* !defined(NO_SHA256) */ +#endif /* !defined(WOLFSSL_TI_HASH) */ #if defined(WOLFSSL_SHA512) int wc_Sha512Hash(const byte* data, word32 len, byte* hash) @@ -207,6 +210,3 @@ int wc_Sha384Hash(const byte* data, word32 len, byte* hash) #endif /* defined(WOLFSSL_SHA384) */ #endif /* defined(WOLFSSL_SHA512) */ - -#endif /* !defined(WOLFSSL_TI_HASH) */ - diff --git a/wolfcrypt/src/port/ti/ti-hash.c b/wolfcrypt/src/port/ti/ti-hash.c old mode 100644 new mode 100755 index 04e6650b6..56526af86 --- a/wolfcrypt/src/port/ti/ti-hash.c +++ b/wolfcrypt/src/port/ti/ti-hash.c @@ -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 diff --git a/wolfssl/wolfcrypt/hash.h b/wolfssl/wolfcrypt/hash.h old mode 100644 new mode 100755 index 2b35d5a6a..4cdd85f11 --- a/wolfssl/wolfcrypt/hash.h +++ b/wolfssl/wolfcrypt/hash.h @@ -24,10 +24,19 @@ #include +#ifdef __cplusplus + extern "C" { +#endif + #ifndef NO_MD5 #include WOLFSSL_API void wc_Md5GetHash(Md5*, byte*); WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ; +#if defined(WOLFSSL_TI_HASH) + WOLFSSL_API void wc_Md5Free(Md5*); +#else + #define wc_Md5Free(d) +#endif #endif #ifndef NO_SHA @@ -35,6 +44,11 @@ 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*); +#if defined(WOLFSSL_TI_HASH) + WOLFSSL_API void wc_ShaFree(Sha*); +#else + #define wc_ShaFree(d) +#endif #endif #ifndef NO_SHA256 @@ -42,15 +56,34 @@ 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*); +#if defined(WOLFSSL_TI_HASH) + WOLFSSL_API void wc_Sha256Free(Sha256*); +#else + #define wc_Sha256Free(d) +#endif #endif #ifdef WOLFSSL_SHA512 #include WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*); +#if defined(WOLFSSL_TI_HASH) + WOLFSSL_API void wc_Sha512Free(Sha512*); +#else + #define wc_Sha512Free(d) +#endif #if defined(WOLFSSL_SHA384) WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*); + #if defined(WOLFSSL_TI_HASH) + WOLFSSL_API void wc_Sha384Free(Sha384*); + #else + #define wc_Sha384Free(d) + #endif #endif /* defined(WOLFSSL_SHA384) */ #endif /* WOLFSSL_SHA512 */ +#ifdef __cplusplus + } /* extern "C" */ +#endif + #endif /* WOLF_CRYPT_HASH_H */