move wc_ShaHash() outside of sha.[hc]

This commit is contained in:
toddouska
2015-07-28 16:30:10 -07:00
parent 480bab467d
commit 2f3b7b05ba
5 changed files with 35 additions and 31 deletions

View File

@ -42,6 +42,7 @@
#include <wolfssl/wolfcrypt/logging.h>
#include <wolfssl/wolfcrypt/random.h>
#include <wolfssl/wolfcrypt/hash.h>
#ifndef NO_RC4

View File

@ -24,6 +24,7 @@
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/logging.h>
#if !defined(WOLFSSL_TI_HASH)
@ -55,8 +56,40 @@ int wc_ShaGetHash(Sha* sha, byte* hash)
WOLFSSL_API void wc_ShaRestorePos(Sha* s1, Sha* s2) {
*s1 = *s2 ;
}
int wc_ShaHash(const byte* data, word32 len, byte* hash)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Sha* sha;
#else
Sha sha[1];
#endif
#ifdef WOLFSSL_SMALL_STACK
sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (sha == NULL)
return MEMORY_E;
#endif
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaFinal(sha, hash);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
return ret;
}
#endif /* !defined(NO_SHA) */
#if !defined(NO_SHA256)
int wc_Sha256GetHash(Sha256* sha256, byte* hash)
{

View File

@ -421,36 +421,6 @@ int wc_ShaFinal(Sha* sha, byte* hash)
#endif /* STM32F2_HASH */
int wc_ShaHash(const byte* data, word32 len, byte* hash)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Sha* sha;
#else
Sha sha[1];
#endif
#ifdef WOLFSSL_SMALL_STACK
sha = (Sha*)XMALLOC(sizeof(Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (sha == NULL)
return MEMORY_E;
#endif
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaFinal(sha, hash);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
return ret;
}
#endif /* HAVE_FIPS */
#endif /* WOLFSSL_TI_HASH */

View File

@ -31,6 +31,7 @@ WOLFSSL_API void wc_Md5RestorePos(Md5*, Md5*) ;
#include <wolfssl/wolfcrypt/sha.h>
WOLFSSL_API int wc_ShaGetHash(Sha*, byte*);
WOLFSSL_API void wc_ShaRestorePos(Sha*, Sha*) ;
WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
#endif
#ifndef NO_SHA256
#include <wolfssl/wolfcrypt/sha256.h>

View File

@ -76,7 +76,6 @@ typedef struct Sha {
WOLFSSL_API int wc_InitSha(Sha*);
WOLFSSL_API int wc_ShaUpdate(Sha*, const byte*, word32);
WOLFSSL_API int wc_ShaFinal(Sha*, byte*);
WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
#ifdef __cplusplus
} /* extern "C" */