mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 20:24:39 +02:00
Merge pull request #640 from jrblixt/unitTest_api_dev
unit test md5, sha, sha256, sha384, sha512
This commit is contained in:
@@ -52,9 +52,7 @@ int CRYPT_MD5_Initialize(CRYPT_MD5_CTX* md5)
|
|||||||
if (md5 == NULL)
|
if (md5 == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
wc_InitMd5((Md5*)md5);
|
return wc_InitMd5((Md5*)md5);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,9 +63,7 @@ int CRYPT_MD5_DataAdd(CRYPT_MD5_CTX* md5, const unsigned char* input,
|
|||||||
if (md5 == NULL || input == NULL)
|
if (md5 == NULL || input == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
wc_Md5Update((Md5*)md5, input, sz);
|
return wc_Md5Update((Md5*)md5, input, sz);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -77,9 +73,7 @@ int CRYPT_MD5_Finalize(CRYPT_MD5_CTX* md5, unsigned char* digest)
|
|||||||
if (md5 == NULL || digest == NULL)
|
if (md5 == NULL || digest == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
wc_Md5Final((Md5*)md5, digest);
|
return wc_Md5Final((Md5*)md5, digest);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -214,17 +214,22 @@ static int check_md5(void)
|
|||||||
{
|
{
|
||||||
CRYPT_MD5_CTX mcMd5;
|
CRYPT_MD5_CTX mcMd5;
|
||||||
Md5 defMd5;
|
Md5 defMd5;
|
||||||
|
int ret;
|
||||||
byte mcDigest[CRYPT_MD5_DIGEST_SIZE];
|
byte mcDigest[CRYPT_MD5_DIGEST_SIZE];
|
||||||
byte defDigest[MD5_DIGEST_SIZE];
|
byte defDigest[MD5_DIGEST_SIZE];
|
||||||
|
|
||||||
CRYPT_MD5_Initialize(&mcMd5);
|
CRYPT_MD5_Initialize(&mcMd5);
|
||||||
wc_InitMd5(&defMd5);
|
ret = wc_InitMd5(&defMd5);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
CRYPT_MD5_DataAdd(&mcMd5, ourData, OUR_DATA_SIZE);
|
CRYPT_MD5_DataAdd(&mcMd5, ourData, OUR_DATA_SIZE);
|
||||||
wc_Md5Update(&defMd5, ourData, OUR_DATA_SIZE);
|
ret = wc_Md5Update(&defMd5, ourData, OUR_DATA_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
CRYPT_MD5_Finalize(&mcMd5, mcDigest);
|
CRYPT_MD5_Finalize(&mcMd5, mcDigest);
|
||||||
wc_Md5Final(&defMd5, defDigest);
|
ret = wc_Md5Final(&defMd5, defDigest);
|
||||||
|
}
|
||||||
|
|
||||||
if (memcmp(mcDigest, defDigest, CRYPT_MD5_DIGEST_SIZE) != 0) {
|
if (memcmp(mcDigest, defDigest, CRYPT_MD5_DIGEST_SIZE) != 0) {
|
||||||
printf("md5 final memcmp fialed\n");
|
printf("md5 final memcmp fialed\n");
|
||||||
@@ -232,7 +237,7 @@ static int check_md5(void)
|
|||||||
}
|
}
|
||||||
printf("md5 mcapi test passed\n");
|
printf("md5 mcapi test passed\n");
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
49
src/keys.c
49
src/keys.c
@@ -3087,10 +3087,10 @@ int DeriveKeys(WOLFSSL* ssl)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wc_InitMd5(md5);
|
ret = wc_InitMd5(md5);
|
||||||
|
if (ret == 0) {
|
||||||
ret = wc_InitSha(sha);
|
ret = wc_InitSha(sha);
|
||||||
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
XMEMCPY(md5Input, ssl->arrays->masterSecret, SECRET_LEN);
|
XMEMCPY(md5Input, ssl->arrays->masterSecret, SECRET_LEN);
|
||||||
|
|
||||||
@@ -3108,14 +3108,21 @@ int DeriveKeys(WOLFSSL* ssl)
|
|||||||
XMEMCPY(shaInput + idx, ssl->arrays->serverRandom, RAN_LEN);
|
XMEMCPY(shaInput + idx, ssl->arrays->serverRandom, RAN_LEN);
|
||||||
idx += RAN_LEN;
|
idx += RAN_LEN;
|
||||||
XMEMCPY(shaInput + idx, ssl->arrays->clientRandom, RAN_LEN);
|
XMEMCPY(shaInput + idx, ssl->arrays->clientRandom, RAN_LEN);
|
||||||
|
if (ret == 0) {
|
||||||
wc_ShaUpdate(sha, shaInput, (KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN)
|
ret = wc_ShaUpdate(sha, shaInput,
|
||||||
- KEY_PREFIX + j);
|
(KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN) - KEY_PREFIX + j);
|
||||||
wc_ShaFinal(sha, shaOutput);
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_ShaFinal(sha, shaOutput);
|
||||||
|
}
|
||||||
|
|
||||||
XMEMCPY(md5Input + SECRET_LEN, shaOutput, SHA_DIGEST_SIZE);
|
XMEMCPY(md5Input + SECRET_LEN, shaOutput, SHA_DIGEST_SIZE);
|
||||||
wc_Md5Update(md5, md5Input, SECRET_LEN + SHA_DIGEST_SIZE);
|
if (ret == 0) {
|
||||||
wc_Md5Final(md5, keyData + i * MD5_DIGEST_SIZE);
|
ret = wc_Md5Update(md5, md5Input, SECRET_LEN + SHA_DIGEST_SIZE);
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_Md5Final(md5, keyData + i * MD5_DIGEST_SIZE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
@@ -3206,10 +3213,10 @@ static int MakeSslMasterSecret(WOLFSSL* ssl)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wc_InitMd5(md5);
|
ret = wc_InitMd5(md5);
|
||||||
|
if (ret == 0) {
|
||||||
ret = wc_InitSha(sha);
|
ret = wc_InitSha(sha);
|
||||||
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
XMEMCPY(md5Input, ssl->arrays->preMasterSecret, pmsSz);
|
XMEMCPY(md5Input, ssl->arrays->preMasterSecret, pmsSz);
|
||||||
|
|
||||||
@@ -3230,14 +3237,22 @@ static int MakeSslMasterSecret(WOLFSSL* ssl)
|
|||||||
idx += RAN_LEN;
|
idx += RAN_LEN;
|
||||||
XMEMCPY(shaInput + idx, ssl->arrays->serverRandom, RAN_LEN);
|
XMEMCPY(shaInput + idx, ssl->arrays->serverRandom, RAN_LEN);
|
||||||
idx += RAN_LEN;
|
idx += RAN_LEN;
|
||||||
wc_ShaUpdate(sha, shaInput, idx);
|
if (ret == 0) {
|
||||||
wc_ShaFinal(sha, shaOutput);
|
ret = wc_ShaUpdate(sha, shaInput, idx);
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_ShaFinal(sha, shaOutput);
|
||||||
|
}
|
||||||
idx = pmsSz; /* preSz */
|
idx = pmsSz; /* preSz */
|
||||||
XMEMCPY(md5Input + idx, shaOutput, SHA_DIGEST_SIZE);
|
XMEMCPY(md5Input + idx, shaOutput, SHA_DIGEST_SIZE);
|
||||||
idx += SHA_DIGEST_SIZE;
|
idx += SHA_DIGEST_SIZE;
|
||||||
wc_Md5Update(md5, md5Input, idx);
|
if (ret == 0) {
|
||||||
wc_Md5Final(md5, &ssl->arrays->masterSecret[i * MD5_DIGEST_SIZE]);
|
ret = wc_Md5Update(md5, md5Input, idx);
|
||||||
|
}
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_Md5Final(md5,
|
||||||
|
&ssl->arrays->masterSecret[i * MD5_DIGEST_SIZE]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SHOW_SECRETS
|
#ifdef SHOW_SECRETS
|
||||||
|
@@ -566,8 +566,9 @@ static int HashInit(HsHashes* hash)
|
|||||||
ret = wc_InitSha(&hash->hashSha);
|
ret = wc_InitSha(&hash->hashSha);
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_MD5
|
#ifndef NO_MD5
|
||||||
if (ret == 0)
|
if (ret == 0) {
|
||||||
wc_InitMd5(&hash->hashMd5);
|
ret = wc_InitMd5(&hash->hashMd5);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_SHA256
|
#ifndef NO_SHA256
|
||||||
@@ -596,8 +597,9 @@ static int HashUpdate(HsHashes* hash, const byte* input, int sz)
|
|||||||
ret = wc_ShaUpdate(&hash->hashSha, input, sz);
|
ret = wc_ShaUpdate(&hash->hashSha, input, sz);
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_MD5
|
#ifndef NO_MD5
|
||||||
if (ret == 0)
|
if (ret == 0) {
|
||||||
wc_Md5Update(&hash->hashMd5, input, sz);
|
ret = wc_Md5Update(&hash->hashMd5, input, sz);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef NO_SHA256
|
#ifndef NO_SHA256
|
||||||
|
1089
tests/api.c
1089
tests/api.c
File diff suppressed because it is too large
Load Diff
18
tests/hash.c
18
tests/hash.c
@@ -255,6 +255,7 @@ int md4_test(void)
|
|||||||
int md5_test(void)
|
int md5_test(void)
|
||||||
{
|
{
|
||||||
Md5 md5;
|
Md5 md5;
|
||||||
|
int ret;
|
||||||
byte hash[MD5_DIGEST_SIZE];
|
byte hash[MD5_DIGEST_SIZE];
|
||||||
|
|
||||||
testVector a, b, c, d, e;
|
testVector a, b, c, d, e;
|
||||||
@@ -299,11 +300,22 @@ int md5_test(void)
|
|||||||
test_md5[3] = d;
|
test_md5[3] = d;
|
||||||
test_md5[4] = e;
|
test_md5[4] = e;
|
||||||
|
|
||||||
wc_InitMd5(&md5);
|
ret = wc_InitMd5(&md5);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < times; ++i) {
|
for (i = 0; i < times; ++i) {
|
||||||
wc_Md5Update(&md5, (byte*)test_md5[i].input, (word32)test_md5[i].inLen);
|
ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
|
||||||
wc_Md5Final(&md5, hash);
|
(word32)test_md5[i].inLen);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = wc_Md5Final(&md5, hash);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (XMEMCMP(hash, test_md5[i].output, MD5_DIGEST_SIZE) != 0)
|
if (XMEMCMP(hash, test_md5[i].output, MD5_DIGEST_SIZE) != 0)
|
||||||
return -5 - i;
|
return -5 - i;
|
||||||
|
@@ -443,6 +443,9 @@ int wc_Md5Final(Md5* md5, byte* hash)
|
|||||||
|
|
||||||
int wc_InitMd5(Md5* md5)
|
int wc_InitMd5(Md5* md5)
|
||||||
{
|
{
|
||||||
|
if (md5 == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return wc_InitMd5_ex(md5, NULL, INVALID_DEVID);
|
return wc_InitMd5_ex(md5, NULL, INVALID_DEVID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -90,10 +90,22 @@ int wc_PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt,
|
|||||||
switch (hashType) {
|
switch (hashType) {
|
||||||
#ifndef NO_MD5
|
#ifndef NO_MD5
|
||||||
case MD5:
|
case MD5:
|
||||||
wc_InitMd5(&md5);
|
ret = wc_InitMd5(&md5);
|
||||||
wc_Md5Update(&md5, passwd, pLen);
|
if (ret != 0) {
|
||||||
wc_Md5Update(&md5, salt, sLen);
|
return ret;
|
||||||
wc_Md5Final(&md5, buffer);
|
}
|
||||||
|
ret = wc_Md5Update(&md5, passwd, pLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret = wc_Md5Update(&md5, salt, sLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret = wc_Md5Final(&md5, buffer);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* NO_MD5 */
|
#endif /* NO_MD5 */
|
||||||
case SHA:
|
case SHA:
|
||||||
@@ -114,8 +126,14 @@ int wc_PBKDF1(byte* output, const byte* passwd, int pLen, const byte* salt,
|
|||||||
}
|
}
|
||||||
#ifndef NO_MD5
|
#ifndef NO_MD5
|
||||||
else {
|
else {
|
||||||
wc_Md5Update(&md5, buffer, hLen);
|
ret = wc_Md5Update(&md5, buffer, hLen);
|
||||||
wc_Md5Final(&md5, buffer);
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret = wc_Md5Final(&md5, buffer);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -302,13 +320,28 @@ int DoPKCS12Hash(int hashType, byte* buffer, word32 totalLen,
|
|||||||
case MD5:
|
case MD5:
|
||||||
{
|
{
|
||||||
Md5 md5;
|
Md5 md5;
|
||||||
wc_InitMd5(&md5);
|
ret = wc_InitMd5(&md5);
|
||||||
wc_Md5Update(&md5, buffer, totalLen);
|
if (ret != 0) {
|
||||||
wc_Md5Final(&md5, Ai);
|
break;
|
||||||
|
}
|
||||||
|
ret = wc_Md5Update(&md5, buffer, totalLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = wc_Md5Final(&md5, Ai);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 1; i < iterations; i++) {
|
for (i = 1; i < iterations; i++) {
|
||||||
wc_Md5Update(&md5, Ai, u);
|
ret = wc_Md5Update(&md5, Ai, u);
|
||||||
wc_Md5Final(&md5, Ai);
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = wc_Md5Final(&md5, Ai);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -320,12 +353,24 @@ int DoPKCS12Hash(int hashType, byte* buffer, word32 totalLen,
|
|||||||
ret = wc_InitSha(&sha);
|
ret = wc_InitSha(&sha);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
break;
|
break;
|
||||||
wc_ShaUpdate(&sha, buffer, totalLen);
|
ret = wc_ShaUpdate(&sha, buffer, totalLen);
|
||||||
wc_ShaFinal(&sha, Ai);
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = wc_ShaFinal(&sha, Ai);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 1; i < iterations; i++) {
|
for (i = 1; i < iterations; i++) {
|
||||||
wc_ShaUpdate(&sha, Ai, u);
|
ret = wc_ShaUpdate(&sha, Ai, u);
|
||||||
wc_ShaFinal(&sha, Ai);
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ret = wc_ShaFinal(&sha, Ai);
|
||||||
|
if (ret != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -35,22 +35,34 @@
|
|||||||
#ifdef HAVE_FIPS
|
#ifdef HAVE_FIPS
|
||||||
int wc_InitSha(Sha* sha)
|
int wc_InitSha(Sha* sha)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha_fips(sha);
|
return InitSha_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_InitSha_ex(Sha* sha, void* heap, int devId)
|
int wc_InitSha_ex(Sha* sha, void* heap, int devId)
|
||||||
{
|
{
|
||||||
(void)heap;
|
(void)heap;
|
||||||
(void)devId;
|
(void)devId;
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha_fips(sha);
|
return InitSha_fips(sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wc_ShaUpdate(Sha* sha, const byte* data, word32 len)
|
int wc_ShaUpdate(Sha* sha, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return ShaUpdate_fips(sha, data, len);
|
return ShaUpdate_fips(sha, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wc_ShaFinal(Sha* sha, byte* out)
|
int wc_ShaFinal(Sha* sha, byte* out)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || out == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return ShaFinal_fips(sha,out);
|
return ShaFinal_fips(sha,out);
|
||||||
}
|
}
|
||||||
void wc_ShaFree(Sha* sha)
|
void wc_ShaFree(Sha* sha)
|
||||||
@@ -420,8 +432,14 @@ int wc_InitSha_ex(Sha* sha, void* heap, int devId)
|
|||||||
|
|
||||||
int wc_ShaUpdate (Sha* sha, const byte* data, word32 len)
|
int wc_ShaUpdate (Sha* sha, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
byte* local;
|
||||||
|
|
||||||
|
if (sha == NULL ||(data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
/* do block size increments */
|
/* do block size increments */
|
||||||
byte* local = (byte*)sha->buffer;
|
local = (byte*)sha->buffer;
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA)
|
||||||
if (sha->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA) {
|
if (sha->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA) {
|
||||||
@@ -458,7 +476,13 @@ int wc_ShaUpdate(Sha* sha, const byte* data, word32 len)
|
|||||||
|
|
||||||
int wc_ShaFinal(Sha* sha, byte* hash)
|
int wc_ShaFinal(Sha* sha, byte* hash)
|
||||||
{
|
{
|
||||||
byte* local = (byte*)sha->buffer;
|
byte* local;
|
||||||
|
|
||||||
|
if (sha == NULL || hash == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
local = (byte*)sha->buffer;
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA)
|
||||||
if (sha->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA) {
|
if (sha->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA) {
|
||||||
|
@@ -38,20 +38,32 @@
|
|||||||
|
|
||||||
int wc_InitSha256(Sha256* sha)
|
int wc_InitSha256(Sha256* sha)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha256_fips(sha);
|
return InitSha256_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_InitSha256_ex(Sha256* sha, void* heap, int devId)
|
int wc_InitSha256_ex(Sha256* sha, void* heap, int devId)
|
||||||
{
|
{
|
||||||
(void)heap;
|
(void)heap;
|
||||||
(void)devId;
|
(void)devId;
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha256_fips(sha);
|
return InitSha256_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_Sha256Update(Sha256* sha, const byte* data, word32 len)
|
int wc_Sha256Update(Sha256* sha, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return Sha256Update_fips(sha, data, len);
|
return Sha256Update_fips(sha, data, len);
|
||||||
}
|
}
|
||||||
int wc_Sha256Final(Sha256* sha, byte* out)
|
int wc_Sha256Final(Sha256* sha, byte* out)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || out == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return Sha256Final_fips(sha, out);
|
return Sha256Final_fips(sha, out);
|
||||||
}
|
}
|
||||||
void wc_Sha256Free(Sha256* sha)
|
void wc_Sha256Free(Sha256* sha)
|
||||||
@@ -553,9 +565,14 @@ static int InitSha256(Sha256* sha256)
|
|||||||
|
|
||||||
static INLINE int Sha256Final(Sha256* sha256)
|
static INLINE int Sha256Final(Sha256* sha256)
|
||||||
{
|
{
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
byte* local = (byte*)sha256->buffer;
|
byte* local = (byte*)sha256->buffer;
|
||||||
|
|
||||||
|
if (sha256 == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
SAVE_XMM_YMM; /* for Intel AVX */
|
SAVE_XMM_YMM; /* for Intel AVX */
|
||||||
|
|
||||||
AddLength(sha256, sha256->buffLen); /* before adding pads */
|
AddLength(sha256, sha256->buffLen); /* before adding pads */
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <wolfssl/wolfcrypt/settings.h>
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
|
||||||
#ifdef WOLFSSL_SHA512
|
#ifdef WOLFSSL_SHA512
|
||||||
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
|
|
||||||
#include <wolfssl/wolfcrypt/sha512.h>
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
@@ -35,20 +36,35 @@
|
|||||||
#ifdef HAVE_FIPS
|
#ifdef HAVE_FIPS
|
||||||
int wc_InitSha512(Sha512* sha)
|
int wc_InitSha512(Sha512* sha)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
return InitSha512_fips(sha);
|
return InitSha512_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_InitSha512_ex(Sha512* sha, void* heap, int devId)
|
int wc_InitSha512_ex(Sha512* sha, void* heap, int devId)
|
||||||
{
|
{
|
||||||
(void)heap;
|
(void)heap;
|
||||||
(void)devId;
|
(void)devId;
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha512_fips(sha);
|
return InitSha512_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_Sha512Update(Sha512* sha, const byte* data, word32 len)
|
int wc_Sha512Update(Sha512* sha, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
return Sha512Update_fips(sha, data, len);
|
return Sha512Update_fips(sha, data, len);
|
||||||
}
|
}
|
||||||
int wc_Sha512Final(Sha512* sha, byte* out)
|
int wc_Sha512Final(Sha512* sha, byte* out)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || out == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
return Sha512Final_fips(sha, out);
|
return Sha512Final_fips(sha, out);
|
||||||
}
|
}
|
||||||
void wc_Sha512Free(Sha512* sha)
|
void wc_Sha512Free(Sha512* sha)
|
||||||
@@ -60,20 +76,32 @@
|
|||||||
#if defined(WOLFSSL_SHA384) || defined(HAVE_AESGCM)
|
#if defined(WOLFSSL_SHA384) || defined(HAVE_AESGCM)
|
||||||
int wc_InitSha384(Sha384* sha)
|
int wc_InitSha384(Sha384* sha)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha384_fips(sha);
|
return InitSha384_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_InitSha384_ex(Sha384* sha, void* heap, int devId)
|
int wc_InitSha384_ex(Sha384* sha, void* heap, int devId)
|
||||||
{
|
{
|
||||||
(void)heap;
|
(void)heap;
|
||||||
(void)devId;
|
(void)devId;
|
||||||
|
if (sha == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return InitSha384_fips(sha);
|
return InitSha384_fips(sha);
|
||||||
}
|
}
|
||||||
int wc_Sha384Update(Sha384* sha, const byte* data, word32 len)
|
int wc_Sha384Update(Sha384* sha, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return Sha384Update_fips(sha, data, len);
|
return Sha384Update_fips(sha, data, len);
|
||||||
}
|
}
|
||||||
int wc_Sha384Final(Sha384* sha, byte* out)
|
int wc_Sha384Final(Sha384* sha, byte* out)
|
||||||
{
|
{
|
||||||
|
if (sha == NULL || out == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
return Sha384Final_fips(sha, out);
|
return Sha384Final_fips(sha, out);
|
||||||
}
|
}
|
||||||
void wc_Sha384Free(Sha384* sha)
|
void wc_Sha384Free(Sha384* sha)
|
||||||
@@ -524,10 +552,13 @@ static INLINE void AddLength(Sha512* sha512, word32 len)
|
|||||||
static INLINE int Sha512Update(Sha512* sha512, const byte* data, word32 len)
|
static INLINE int Sha512Update(Sha512* sha512, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
/* do block size increments */
|
/* do block size increments */
|
||||||
byte* local = (byte*)sha512->buffer;
|
byte* local = (byte*)sha512->buffer;
|
||||||
|
|
||||||
|
if (sha512 == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
/* check that internal buffLen is valid */
|
/* check that internal buffLen is valid */
|
||||||
if (sha512->buffLen >= SHA512_BLOCK_SIZE)
|
if (sha512->buffLen >= SHA512_BLOCK_SIZE)
|
||||||
return BUFFER_E;
|
return BUFFER_E;
|
||||||
@@ -564,6 +595,10 @@ static INLINE int Sha512Update(Sha512* sha512, const byte* data, word32 len)
|
|||||||
|
|
||||||
int wc_Sha512Update(Sha512* sha512, const byte* data, word32 len)
|
int wc_Sha512Update(Sha512* sha512, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
if (sha512 == NULL ||(data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
||||||
if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
|
if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
|
||||||
#if defined(HAVE_INTEL_QA)
|
#if defined(HAVE_INTEL_QA)
|
||||||
@@ -581,6 +616,10 @@ static INLINE int Sha512Final(Sha512* sha512)
|
|||||||
byte* local = (byte*)sha512->buffer;
|
byte* local = (byte*)sha512->buffer;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (sha512 == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
SAVE_XMM_YMM ; /* for Intel AVX */
|
SAVE_XMM_YMM ; /* for Intel AVX */
|
||||||
AddLength(sha512, sha512->buffLen); /* before adding pads */
|
AddLength(sha512, sha512->buffLen); /* before adding pads */
|
||||||
|
|
||||||
@@ -642,6 +681,10 @@ int wc_Sha512Final(Sha512* sha512, byte* hash)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (sha512 == NULL || hash == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA512)
|
||||||
if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
|
if (sha512->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA512) {
|
||||||
#if defined(HAVE_INTEL_QA)
|
#if defined(HAVE_INTEL_QA)
|
||||||
@@ -1362,6 +1405,10 @@ static int Transform_AVX2(Sha512* sha512)
|
|||||||
#ifdef WOLFSSL_SHA384
|
#ifdef WOLFSSL_SHA384
|
||||||
static int InitSha384(Sha384* sha384)
|
static int InitSha384(Sha384* sha384)
|
||||||
{
|
{
|
||||||
|
if (sha384 == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
sha384->digest[0] = W64LIT(0xcbbb9d5dc1059ed8);
|
sha384->digest[0] = W64LIT(0xcbbb9d5dc1059ed8);
|
||||||
sha384->digest[1] = W64LIT(0x629a292a367cd507);
|
sha384->digest[1] = W64LIT(0x629a292a367cd507);
|
||||||
sha384->digest[2] = W64LIT(0x9159015a3070dd17);
|
sha384->digest[2] = W64LIT(0x9159015a3070dd17);
|
||||||
@@ -1380,6 +1427,9 @@ static int InitSha384(Sha384* sha384)
|
|||||||
|
|
||||||
int wc_Sha384Update(Sha384* sha384, const byte* data, word32 len)
|
int wc_Sha384Update(Sha384* sha384, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
|
if (sha384 == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
|
||||||
if (sha384->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA384) {
|
if (sha384->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA384) {
|
||||||
@@ -1397,6 +1447,10 @@ int wc_Sha384Final(Sha384* sha384, byte* hash)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (sha384 == NULL || hash == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA384)
|
||||||
if (sha384->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA384) {
|
if (sha384->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA384) {
|
||||||
#if defined(HAVE_INTEL_QA)
|
#if defined(HAVE_INTEL_QA)
|
||||||
|
Reference in New Issue
Block a user