Merge branch 'kojo-ti'

This commit is contained in:
toddouska
2015-08-18 12:32:25 -07:00
4 changed files with 69 additions and 4 deletions

View File

@@ -6001,6 +6001,7 @@ static INLINE void Md5Rounds(int rounds, const byte* data, int sz)
for (i = 0; i < rounds; i++) for (i = 0; i < rounds; i++)
wc_Md5Update(&md5, data, sz); 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++) for (i = 0; i < rounds; i++)
wc_ShaUpdate(&sha, data, sz); wc_ShaUpdate(&sha, data, sz);
wc_ShaFree(&sha) ; /* in case needed to release resources */
} }
#endif #endif
@@ -6032,7 +6034,7 @@ static INLINE void Sha256Rounds(int rounds, const byte* data, int sz)
wc_Sha256Update(&sha256, data, sz); wc_Sha256Update(&sha256, data, sz);
/* no error check on purpose, dummy round */ /* no error check on purpose, dummy round */
} }
wc_Sha256Free(&sha256) ; /* in case needed to release resources */
} }
#endif #endif
@@ -6051,6 +6053,7 @@ static INLINE void Sha384Rounds(int rounds, const byte* data, int sz)
wc_Sha384Update(&sha384, data, sz); wc_Sha384Update(&sha384, data, sz);
/* no error check on purpose, dummy round */ /* no error check on purpose, dummy round */
} }
wc_Sha384Free(&sha384) ; /* in case needed to release resources */
} }
#endif #endif
@@ -6069,6 +6072,7 @@ static INLINE void Sha512Rounds(int rounds, const byte* data, int sz)
wc_Sha512Update(&sha512, data, sz); wc_Sha512Update(&sha512, data, sz);
/* no error check on purpose, dummy round */ /* no error check on purpose, dummy round */
} }
wc_Sha512Free(&sha512) ; /* in case needed to release resources */
} }
#endif #endif

6
wolfcrypt/src/hash.c Normal file → Executable file
View File

@@ -42,6 +42,7 @@ void wc_Md5GetHash(Md5* md5, byte* hash)
WOLFSSL_API void wc_Md5RestorePos(Md5* m1, Md5* m2) { WOLFSSL_API void wc_Md5RestorePos(Md5* m1, Md5* m2) {
*m1 = *m2 ; *m1 = *m2 ;
} }
#endif #endif
#if !defined(NO_SHA) #if !defined(NO_SHA)
@@ -136,8 +137,10 @@ int wc_Sha256Hash(const byte* data, word32 len, byte* hash)
return ret; return ret;
} }
#endif /* !defined(NO_SHA256) */ #endif /* !defined(NO_SHA256) */
#endif /* !defined(WOLFSSL_TI_HASH) */
#if defined(WOLFSSL_SHA512) #if defined(WOLFSSL_SHA512)
int wc_Sha512Hash(const byte* data, word32 len, byte* hash) 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_SHA384) */
#endif /* defined(WOLFSSL_SHA512) */ #endif /* defined(WOLFSSL_SHA512) */
#endif /* !defined(WOLFSSL_TI_HASH) */

28
wolfcrypt/src/port/ti/ti-hash.c Normal file → Executable file
View File

@@ -151,6 +151,13 @@ static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word3
return ret; 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) #if !defined(NO_MD5)
WOLFSSL_API void wc_InitMd5(Md5* 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) ; 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 */ #endif /* NO_MD5 */
#if !defined(NO_SHA) #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) ; 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 */ #endif /* NO_SHA */
#if defined(HAVE_SHA224) #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) ; 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 */ #endif /* HAVE_SHA224 */
#if !defined(NO_SHA256) #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) ; 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
#endif #endif

33
wolfssl/wolfcrypt/hash.h Normal file → Executable file
View File

@@ -24,10 +24,19 @@
#include <wolfssl/wolfcrypt/types.h> #include <wolfssl/wolfcrypt/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef NO_MD5 #ifndef NO_MD5
#include <wolfssl/wolfcrypt/md5.h> #include <wolfssl/wolfcrypt/md5.h>
WOLFSSL_API void wc_Md5GetHash(Md5*, byte*); WOLFSSL_API void wc_Md5GetHash(Md5*, byte*);
WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ; 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 #endif
#ifndef NO_SHA #ifndef NO_SHA
@@ -35,6 +44,11 @@ WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ;
WOLFSSL_API int wc_ShaGetHash(Sha*, byte*); WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*) ; WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*) ;
WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*); 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 #endif
#ifndef NO_SHA256 #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 int wc_Sha256GetHash(Sha256*, byte*);
WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*) ; WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*) ;
WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*); 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 #endif
#ifdef WOLFSSL_SHA512 #ifdef WOLFSSL_SHA512
#include <wolfssl/wolfcrypt/sha512.h> #include <wolfssl/wolfcrypt/sha512.h>
WOLFSSL_API int wc_Sha512Hash(const byte*, word32, byte*); 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) #if defined(WOLFSSL_SHA384)
WOLFSSL_API int wc_Sha384Hash(const byte*, word32, byte*); 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 /* defined(WOLFSSL_SHA384) */
#endif /* WOLFSSL_SHA512 */ #endif /* WOLFSSL_SHA512 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* WOLF_CRYPT_HASH_H */ #endif /* WOLF_CRYPT_HASH_H */