implemented SHA512_Transform and unit test
This commit is contained in:
parent
82fb498ed5
commit
5fb9aa3f9b
18
src/ssl.c
18
src/ssl.c
@ -17181,19 +17181,27 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#if defined(OPENSSL_EXTRA)
|
||||
int wolfSSL_SHA512_Transform(WOLFSSL_SHA512_CTX* sha,
|
||||
|
||||
int wolfSSL_SHA512_Transform(WOLFSSL_SHA512_CTX* sha512,
|
||||
const unsigned char* data)
|
||||
{
|
||||
int ret = WOLFSSL_SUCCESS;
|
||||
|
||||
WOLFSSL_ENTER("SHA512_Transform");
|
||||
(void)sha;
|
||||
(void)data;
|
||||
#if defined(LITTLE_ENDIAN_ORDER)
|
||||
{
|
||||
ByteReverseWords64((word64*)data, (word64*)data,
|
||||
WC_SHA512_BLOCK_SIZE);
|
||||
}
|
||||
#endif
|
||||
ret = wc_Sha512Transform((wc_Sha512*)sha512, data);
|
||||
|
||||
/* return 1 on success, 0 otherwise */
|
||||
if (ret == 0)
|
||||
return 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
|
52
tests/api.c
52
tests/api.c
@ -33161,8 +33161,7 @@ static void test_wolfSSL_SHA_Transform(void)
|
||||
|
||||
static void test_wolfSSL_SHA256_Transform(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
|
||||
defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_SHA256)
|
||||
byte input1[] = "";
|
||||
byte input2[] = "abc";
|
||||
byte local[WC_SHA256_BLOCK_SIZE];
|
||||
@ -33227,6 +33226,54 @@ static void test_wolfSSL_SHA256(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_wolfSSL_SHA512_Transform(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_SHA512)
|
||||
byte input1[] = "";
|
||||
byte input2[] = "abc";
|
||||
byte local[WC_SHA512_BLOCK_SIZE];
|
||||
word32 sLen = 0;
|
||||
unsigned char output1[] =
|
||||
"\xe8\xcb\x4a\x77\xd5\x81\x78\xcf\x70\x80\xc7\xfb\xe0\x62\x33\x53"
|
||||
"\xda\x0e\x46\x87\x9d\x63\x67\x02\xb0\x31\x59\xe8\x40\xcb\x86\x30"
|
||||
"\xa3\x23\xa0\x88\x52\xc9\x7d\x71\xe0\xb5\xe0\x4c\xc1\xb2\xba\x96"
|
||||
"\x0b\x3e\xe3\xea\x04\xfe\xc4\x6f\xee\x8b\x66\xbd\x0c\xd8\xf4\x91";
|
||||
unsigned char output2[] =
|
||||
"\x0d\xcc\xa0\xeb\x4e\x93\x10\x11\x21\xc8\x04\xfb\x9c\x43\x33\xfd"
|
||||
"\x41\x31\xab\xca\x3d\x26\xb4\xa9\xab\xd7\x67\xe1\xaf\xaa\xc6\xe2"
|
||||
"\x83\x4e\xba\x2c\x54\x2e\x8f\x31\x98\x38\x2b\x8f\x9d\xec\x88\xbe"
|
||||
"\x4d\x5e\x8b\x53\x9d\x4e\xd2\x14\xf0\x96\x20\xaf\x69\x6c\x68\xde";
|
||||
|
||||
WOLFSSL_SHA512_CTX sha512;
|
||||
|
||||
printf(testingFmt, "wolfSSL_SHA512_Transform()");
|
||||
|
||||
XMEMSET(&sha512, 0, sizeof(sha512));
|
||||
XMEMSET(&local, 0, sizeof(local));
|
||||
|
||||
/* Init SHA512 CTX */
|
||||
AssertIntEQ(wolfSSL_SHA512_Init(&sha512), 1);
|
||||
|
||||
/* Do Transform*/
|
||||
sLen = XSTRLEN((char*)input1);
|
||||
XMEMCPY(local, input1, sLen);
|
||||
AssertIntEQ(wolfSSL_SHA512_Transform(&sha512, (const byte*)&local[0]), 1);
|
||||
AssertIntEQ(XMEMCMP(&((wc_Sha512*)&sha512)->digest[0], output1,
|
||||
WC_SHA512_DIGEST_SIZE), 0);
|
||||
|
||||
/* Init SHA512 CTX */
|
||||
AssertIntEQ(wolfSSL_SHA512_Init(&sha512), 1);
|
||||
sLen = XSTRLEN((char*)input2);
|
||||
XMEMSET(local, 0, WC_SHA512_BLOCK_SIZE);
|
||||
XMEMCPY(local, input2, sLen);
|
||||
AssertIntEQ(wolfSSL_SHA512_Transform(&sha512, (const byte*)&local[0]), 1);
|
||||
AssertIntEQ(XMEMCMP(&((wc_Sha512*)&sha512)->digest[0], output2,
|
||||
WC_SHA512_DIGEST_SIZE), 0);
|
||||
(void)input1;
|
||||
printf(resultFmt, passed);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_wolfSSL_X509_get_serialNumber(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && !defined(NO_RSA)
|
||||
@ -41118,6 +41165,7 @@ void ApiTest(void)
|
||||
test_wolfSSL_SHA256();
|
||||
test_wolfSSL_SHA256_Transform();
|
||||
test_wolfSSL_SHA224();
|
||||
test_wolfSSL_SHA512_Transform();
|
||||
test_wolfSSL_X509_get_serialNumber();
|
||||
test_wolfSSL_X509_CRL();
|
||||
test_wolfSSL_d2i_X509_REQ();
|
||||
|
@ -916,7 +916,32 @@ void wc_Sha512Free(wc_Sha512* sha512)
|
||||
wolfAsync_DevCtxFree(&sha512->asyncDev, WOLFSSL_ASYNC_MARKER_SHA512);
|
||||
#endif /* WOLFSSL_ASYNC_CRYPT */
|
||||
}
|
||||
#if defined(OPENSSL_EXTRA)
|
||||
int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data)
|
||||
{
|
||||
int ret ;
|
||||
/* back up buffer */
|
||||
#if defined(WOLFSSL_SMALL_STACK)
|
||||
word64* buffer;
|
||||
buffer = (word64*) XMALLOC(sizeof(word64) * 16, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (buffer == NULL)
|
||||
return MEMORY_E;
|
||||
#else
|
||||
word64 buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64)];
|
||||
#endif
|
||||
|
||||
XMEMCPY(buffer, sha->buffer, WC_SHA512_BLOCK_SIZE);
|
||||
XMEMCPY(sha->buffer, data, WC_SHA512_BLOCK_SIZE);
|
||||
|
||||
ret = Transform_Sha512(sha);
|
||||
|
||||
XMEMCPY(sha->buffer, buffer, WC_SHA512_BLOCK_SIZE);
|
||||
#if defined(WOLFSSL_SMALL_STACK)
|
||||
XFREE(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -180,6 +180,9 @@ WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst);
|
||||
WOLFSSL_API int wc_Sha512GetFlags(wc_Sha512* sha512, word32* flags);
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_EXTRA)
|
||||
WOLFSSL_API int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data);
|
||||
#endif
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
#if defined(WOLFSSL_SHA384)
|
||||
|
Loading…
x
Reference in New Issue
Block a user