forked from wolfSSL/wolfssl
add wc_Sha256Hash() outside of sha256.[hc]
This commit is contained in:
@ -103,7 +103,40 @@ int wc_Sha256GetHash(Sha256* sha256, byte* hash)
|
||||
WOLFSSL_API void wc_Sha256RestorePos(Sha256* s1, Sha256* s2) {
|
||||
*s1 = *s2 ;
|
||||
}
|
||||
|
||||
int wc_Sha256Hash(const byte* data, word32 len, byte* hash)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
Sha256* sha256;
|
||||
#else
|
||||
Sha256 sha256[1];
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
sha256 = (Sha256*)XMALLOC(sizeof(Sha256), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (sha256 == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
if ((ret = wc_InitSha256(sha256)) != 0) {
|
||||
WOLFSSL_MSG("InitSha256 failed");
|
||||
}
|
||||
else if ((ret = wc_Sha256Update(sha256, data, len)) != 0) {
|
||||
WOLFSSL_MSG("Sha256Update failed");
|
||||
}
|
||||
else if ((ret = wc_Sha256Final(sha256, hash)) != 0) {
|
||||
WOLFSSL_MSG("Sha256Final failed");
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(sha256, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* !defined(NO_SHA256) */
|
||||
|
||||
|
||||
#endif /* !defined(WOLFSSL_TI_HASH) */
|
||||
|
||||
|
@ -545,37 +545,6 @@ int wc_Sha256Final(Sha256* sha256, byte* hash)
|
||||
|
||||
|
||||
|
||||
int wc_Sha256Hash(const byte* data, word32 len, byte* hash)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
Sha256* sha256;
|
||||
#else
|
||||
Sha256 sha256[1];
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
sha256 = (Sha256*)XMALLOC(sizeof(Sha256), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (sha256 == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
if ((ret = wc_InitSha256(sha256)) != 0) {
|
||||
WOLFSSL_MSG("InitSha256 failed");
|
||||
}
|
||||
else if ((ret = wc_Sha256Update(sha256, data, len)) != 0) {
|
||||
WOLFSSL_MSG("Sha256Update failed");
|
||||
}
|
||||
else if ((ret = wc_Sha256Final(sha256, hash)) != 0) {
|
||||
WOLFSSL_MSG("Sha256Final failed");
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(sha256, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
|
||||
|
||||
|
@ -37,6 +37,7 @@ WOLFSSL_API int wc_ShaHash(const byte*, word32, byte*);
|
||||
#include <wolfssl/wolfcrypt/sha256.h>
|
||||
WOLFSSL_API int wc_Sha256GetHash(Sha256*, byte*);
|
||||
WOLFSSL_API void wc_Sha256RestorePos(Sha256*, Sha256*) ;
|
||||
WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -74,7 +74,6 @@ typedef struct Sha256 {
|
||||
WOLFSSL_API int wc_InitSha256(Sha256*);
|
||||
WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32);
|
||||
WOLFSSL_API int wc_Sha256Final(Sha256*, byte*);
|
||||
WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
Reference in New Issue
Block a user