implemented SHA256_Transform
WIP SHA512_Transform
This commit is contained in:
parent
cb3fa8ff9e
commit
95cf3675e9
38
src/ssl.c
38
src/ssl.c
@ -17007,8 +17007,29 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_EXTRA)
|
||||
int wolfSSL_SHA256_Transform(WOLFSSL_SHA256_CTX* sha256,
|
||||
const unsigned char* data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
WOLFSSL_ENTER("SHA256_Transform");
|
||||
#if defined(LITTLE_ENDIAN_ORDER)
|
||||
{
|
||||
ByteReverseWords((word32*)data, (word32*)data, WC_SHA256_BLOCK_SIZE);
|
||||
}
|
||||
#endif
|
||||
ret = wc_Sha256Transform((wc_Sha256*)sha256, data);
|
||||
|
||||
|
||||
/* return 1 on success, 0 otherwise */
|
||||
if (ret == 0)
|
||||
return 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA384
|
||||
|
||||
int wolfSSL_SHA384_Init(WOLFSSL_SHA384_CTX* sha)
|
||||
@ -17111,7 +17132,20 @@ 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,
|
||||
const unsigned char* data)
|
||||
{
|
||||
int ret = WOLFSSL_SUCCESS;
|
||||
|
||||
WOLFSSL_ENTER("SHA512_Transform");
|
||||
(void)sha;
|
||||
(void)data;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_SHA512 */
|
||||
|
||||
#ifdef WOLFSSL_SHA3
|
||||
|
44
tests/api.c
44
tests/api.c
@ -33026,6 +33026,49 @@ static void test_wolfSSL_SHA224(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
byte input1[] = "";
|
||||
byte input2[] = "abc";
|
||||
byte local[WC_SHA256_BLOCK_SIZE];
|
||||
word32 sLen = 0;
|
||||
unsigned char output1[] =
|
||||
"\xbe\x98\x56\xda\x69\xb4\xb9\x17\x99\x57\x33\x62\xca\xbe\x9f\x77"
|
||||
"\x91\xd4\xe5\x8c\x43\x62\xd2\xc0\xea\xf9\xfe\xba\xd8\xa9\x37\x18";
|
||||
unsigned char output2[] =
|
||||
"\x67\xd4\x4e\x1d\x67\x61\x7c\x67\x26\x76\x10\x44\xb8\xff\x10\x78"
|
||||
"\x39\x9a\xc8\x40\x8c\x60\x16\x73\x05\xd6\x61\xa6\x35\x8c\xf2\x91";
|
||||
|
||||
WOLFSSL_SHA256_CTX sha256;
|
||||
|
||||
printf(testingFmt, "wolfSSL_SHA256_Transform()");
|
||||
|
||||
XMEMSET(&sha256, 0, sizeof(sha256));
|
||||
XMEMSET(&local, 0, sizeof(local));
|
||||
|
||||
/* Init SHA256 CTX */
|
||||
AssertIntEQ(wolfSSL_SHA256_Init(&sha256), 1);
|
||||
/* Do Transform*/
|
||||
sLen = XSTRLEN((char*)input1);
|
||||
XMEMCPY(local, input1, sLen);
|
||||
AssertIntEQ(wolfSSL_SHA256_Transform(&sha256, (const byte*)&local[0]), 1);
|
||||
AssertIntEQ(XMEMCMP(&((wc_Sha256*)&sha256)->digest[0], output1, WC_SHA256_DIGEST_SIZE), 0);
|
||||
|
||||
/* Init SHA256 CTX */
|
||||
AssertIntEQ(wolfSSL_SHA256_Init(&sha256), 1);
|
||||
sLen = XSTRLEN((char*)input2);
|
||||
XMEMSET(local, 0, WC_SHA256_BLOCK_SIZE);
|
||||
XMEMCPY(local, input2, sLen);
|
||||
AssertIntEQ(wolfSSL_SHA256_Transform(&sha256, (const byte*)&local[0]), 1);
|
||||
AssertIntEQ(XMEMCMP(&((wc_Sha256*)&sha256)->digest[0], output2, WC_SHA256_DIGEST_SIZE), 0);
|
||||
|
||||
printf(resultFmt, passed);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_wolfSSL_SHA256(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_SHA256) && \
|
||||
@ -40936,6 +40979,7 @@ void ApiTest(void)
|
||||
test_wolfSSL_PEM_write_DHparams();
|
||||
test_wolfSSL_AES_ecb_encrypt();
|
||||
test_wolfSSL_SHA256();
|
||||
test_wolfSSL_SHA256_Transform();
|
||||
test_wolfSSL_SHA224();
|
||||
test_wolfSSL_X509_get_serialNumber();
|
||||
test_wolfSSL_X509_CRL();
|
||||
|
@ -1295,6 +1295,12 @@ static int InitSha256(wc_Sha256* sha256)
|
||||
return InitSha256(sha256); /* reset state */
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_EXTRA)
|
||||
int wc_Sha256Transform(wc_Sha256* sha, const unsigned char* data)
|
||||
{
|
||||
return (Transform_Sha256(sha, data));
|
||||
}
|
||||
#endif
|
||||
#endif /* XTRANSFORM */
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
|
@ -118,9 +118,10 @@ typedef struct WOLFSSL_SHA256_CTX {
|
||||
|
||||
WOLFSSL_API int wolfSSL_SHA256_Init(WOLFSSL_SHA256_CTX*);
|
||||
WOLFSSL_API int wolfSSL_SHA256_Update(WOLFSSL_SHA256_CTX*, const void*,
|
||||
unsigned long);
|
||||
unsigned long);
|
||||
WOLFSSL_API int wolfSSL_SHA256_Final(unsigned char*, WOLFSSL_SHA256_CTX*);
|
||||
|
||||
WOLFSSL_API int wolfSSL_SHA256_Transform(WOLFSSL_SHA256_CTX*,
|
||||
const unsigned char *data);
|
||||
enum {
|
||||
SHA256_DIGEST_LENGTH = 32
|
||||
};
|
||||
@ -131,6 +132,8 @@ typedef WOLFSSL_SHA256_CTX SHA256_CTX;
|
||||
#define SHA256_Init wolfSSL_SHA256_Init
|
||||
#define SHA256_Update wolfSSL_SHA256_Update
|
||||
#define SHA256_Final wolfSSL_SHA256_Final
|
||||
#define SHA256_Transform wolfSSL_SHA256_Transform
|
||||
|
||||
#if defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
|
||||
/* SHA256 is only available in non-fips mode because of SHA256 enum in FIPS
|
||||
* build. */
|
||||
@ -176,9 +179,10 @@ typedef struct WOLFSSL_SHA512_CTX {
|
||||
|
||||
WOLFSSL_API int wolfSSL_SHA512_Init(WOLFSSL_SHA512_CTX*);
|
||||
WOLFSSL_API int wolfSSL_SHA512_Update(WOLFSSL_SHA512_CTX*, const void*,
|
||||
unsigned long);
|
||||
unsigned long);
|
||||
WOLFSSL_API int wolfSSL_SHA512_Final(unsigned char*, WOLFSSL_SHA512_CTX*);
|
||||
|
||||
WOLFSSL_API int wolfSSL_SHA512_Transform(WOLFSSL_SHA512_CTX*,
|
||||
const unsigned char*);
|
||||
enum {
|
||||
SHA512_DIGEST_LENGTH = 64
|
||||
};
|
||||
@ -189,6 +193,7 @@ typedef WOLFSSL_SHA512_CTX SHA512_CTX;
|
||||
#define SHA512_Init wolfSSL_SHA512_Init
|
||||
#define SHA512_Update wolfSSL_SHA512_Update
|
||||
#define SHA512_Final wolfSSL_SHA512_Final
|
||||
#define SHA512_Transform wolfSSL_SHA512_Transform
|
||||
#if defined(NO_OLD_SHA_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
|
||||
/* SHA512 is only available in non-fips mode because of SHA512 enum in FIPS
|
||||
* build. */
|
||||
|
@ -198,7 +198,9 @@ WOLFSSL_API int wc_Sha256Update(wc_Sha256*, const byte*, word32);
|
||||
WOLFSSL_API int wc_Sha256FinalRaw(wc_Sha256*, byte*);
|
||||
WOLFSSL_API int wc_Sha256Final(wc_Sha256*, byte*);
|
||||
WOLFSSL_API void wc_Sha256Free(wc_Sha256*);
|
||||
|
||||
#if defined(OPENSSL_EXTRA)
|
||||
WOLFSSL_API int wc_Sha256Transform(wc_Sha256*, const byte*);
|
||||
#endif
|
||||
WOLFSSL_API int wc_Sha256GetHash(wc_Sha256*, byte*);
|
||||
WOLFSSL_API int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user