mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Merge pull request #928 from jrblixt/unitTest_api_sha224-RipeMd
Add sha224 RipeMd to unit test
This commit is contained in:
@@ -53,7 +53,7 @@ void bench_md5(void);
|
|||||||
void bench_sha(void);
|
void bench_sha(void);
|
||||||
void bench_sha256(void);
|
void bench_sha256(void);
|
||||||
void bench_sha512(void);
|
void bench_sha512(void);
|
||||||
void bench_ripemd(void);
|
int bench_ripemd(void);
|
||||||
|
|
||||||
void bench_rsa(void);
|
void bench_rsa(void);
|
||||||
void bench_rsaKeyGen(void);
|
void bench_rsaKeyGen(void);
|
||||||
|
432
tests/api.c
432
tests/api.c
@@ -61,6 +61,9 @@
|
|||||||
#ifdef WOLFSSL_SHA384
|
#ifdef WOLFSSL_SHA384
|
||||||
#include <wolfssl/wolfcrypt/sha512.h>
|
#include <wolfssl/wolfcrypt/sha512.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef WOLFSSL_RIPEMD
|
||||||
|
#include <wolfssl/wolfcrypt/ripemd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef OPENSSL_EXTRA
|
#ifdef OPENSSL_EXTRA
|
||||||
#include <wolfssl/openssl/ssl.h>
|
#include <wolfssl/openssl/ssl.h>
|
||||||
@@ -2442,6 +2445,73 @@ static int test_wc_InitSha384 (void)
|
|||||||
return 0;
|
return 0;
|
||||||
} /* END test_wc_InitSha384 */
|
} /* END test_wc_InitSha384 */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Testing wc_InitSha224();
|
||||||
|
*/
|
||||||
|
static int test_wc_InitSha224 (void)
|
||||||
|
{
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
Sha224 sha224;
|
||||||
|
int ret, flag;
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_InitSha224()");
|
||||||
|
|
||||||
|
/* Test good arg. */
|
||||||
|
ret = wc_InitSha224(&sha224);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test bad arg. */
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_InitSha224(NULL);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, flag == 0 ? passed : failed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
} /* END test_wc_InitSha224 */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Testing wc_InitRipeMd()
|
||||||
|
*/
|
||||||
|
static int test_wc_InitRipeMd (void)
|
||||||
|
{
|
||||||
|
#ifdef WOLFSSL_RIPEMD
|
||||||
|
RipeMd ripemd;
|
||||||
|
int ret, flag;
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_InitRipeMd()");
|
||||||
|
|
||||||
|
/* Test good arg. */
|
||||||
|
ret = wc_InitRipeMd(&ripemd);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test bad arg. */
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_InitRipeMd(NULL);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, flag == 0 ? passed : failed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} /* END test_wc_InitRipeMd */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Testing wc_UpdateMd5()
|
* Testing wc_UpdateMd5()
|
||||||
@@ -2859,6 +2929,109 @@ static int test_wc_Sha384Update (void)
|
|||||||
return 0;
|
return 0;
|
||||||
} /* END test_wc_Sha384Update */
|
} /* END test_wc_Sha384Update */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Testing wc_RipeMdUpdate()
|
||||||
|
*/
|
||||||
|
static int test_wc_RipeMdUpdate (void)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_RIPEMD
|
||||||
|
RipeMd ripemd;
|
||||||
|
byte hash[RIPEMD_DIGEST_SIZE];
|
||||||
|
testVector a, b, c;
|
||||||
|
int ret, flag;
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
ret = wc_InitRipeMd(&ripemd);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_RipeMdUpdate()");
|
||||||
|
|
||||||
|
/* Input */
|
||||||
|
if (!flag) {
|
||||||
|
a.input = "a";
|
||||||
|
a.inLen = XSTRLEN(a.input);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdFinal(&ripemd, hash);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update input. */
|
||||||
|
if (!flag) {
|
||||||
|
a.input = "abc";
|
||||||
|
a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
|
||||||
|
"\xb0\x87\xf1\x5a\x0b\xfc";
|
||||||
|
a.inLen = XSTRLEN(a.input);
|
||||||
|
a.outLen = XSTRLEN(a.output);
|
||||||
|
|
||||||
|
ret = wc_RipeMdUpdate(&ripemd, (byte*)a.input, (word32)a.inLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdFinal(&ripemd, hash);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
if (XMEMCMP(hash, a.output, RIPEMD_DIGEST_SIZE) != 0) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pass in bad values. */
|
||||||
|
if (!flag) {
|
||||||
|
b.input = NULL;
|
||||||
|
b.inLen = 0;
|
||||||
|
|
||||||
|
ret = wc_RipeMdUpdate(&ripemd, (byte*)b.input, (word32)b.inLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
c.input = NULL;
|
||||||
|
c.inLen = RIPEMD_DIGEST_SIZE;
|
||||||
|
|
||||||
|
ret = wc_RipeMdUpdate(&ripemd, (byte*)c.input, (word32)c.inLen);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdUpdate(NULL, (byte*)a.input, (word32)a.inLen);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, flag == 0 ? passed : failed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} /* END test_wc_RipeMdUdpate */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* wc_Sha512Update() test.
|
* wc_Sha512Update() test.
|
||||||
*/
|
*/
|
||||||
@@ -2903,11 +3076,11 @@ static int test_wc_Sha512Update (void)
|
|||||||
/* Update input. */
|
/* Update input. */
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
a.input = "abc";
|
a.input = "abc";
|
||||||
a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31"
|
a.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
|
||||||
"\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3"
|
"\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b"
|
||||||
"\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe"
|
"\x55\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c"
|
||||||
"\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5"
|
"\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a"
|
||||||
"\x4c\xa4\x9f";
|
"\x9a\xc9\x4f\xa5\x4c\xa4\x9f";
|
||||||
a.inLen = XSTRLEN(a.input);
|
a.inLen = XSTRLEN(a.input);
|
||||||
a.outLen = XSTRLEN(a.output);
|
a.outLen = XSTRLEN(a.output);
|
||||||
|
|
||||||
@@ -2926,7 +3099,7 @@ static int test_wc_Sha512Update (void)
|
|||||||
|
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
if (XMEMCMP(hash, a.output, SHA512_DIGEST_SIZE) != 0) {
|
if (XMEMCMP(hash, a.output, SHA512_DIGEST_SIZE) != 0) {
|
||||||
flag = SSL_FAILURE;
|
flag = SSL_FATAL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2966,6 +3139,109 @@ static int test_wc_Sha512Update (void)
|
|||||||
|
|
||||||
} /* END test_wc_Sha512Update */
|
} /* END test_wc_Sha512Update */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unit test on wc_Sha224Update
|
||||||
|
*/
|
||||||
|
static int test_wc_Sha224Update (void)
|
||||||
|
{
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
Sha224 sha224;
|
||||||
|
byte hash[SHA224_DIGEST_SIZE];
|
||||||
|
testVector a, b, c;
|
||||||
|
int ret, flag;
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
ret = wc_InitSha224(&sha224);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_Sha224Update()");
|
||||||
|
|
||||||
|
/* Input. */
|
||||||
|
if (!flag) {
|
||||||
|
a.input = "a";
|
||||||
|
a.inLen = XSTRLEN(a.input);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Final(&sha224, hash);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update input. */
|
||||||
|
if (!flag) {
|
||||||
|
a.input = "abc";
|
||||||
|
a.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2"
|
||||||
|
"\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
|
||||||
|
a.inLen = XSTRLEN(a.input);
|
||||||
|
a.outLen = XSTRLEN(a.output);
|
||||||
|
|
||||||
|
ret = wc_Sha224Update(&sha224, (byte*)a.input, (word32)a.inLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Final(&sha224, hash);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
if (XMEMCMP(hash, a.output, SHA224_DIGEST_SIZE) != 0) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pass in bad values. */
|
||||||
|
if (!flag) {
|
||||||
|
b.input = NULL;
|
||||||
|
b.inLen = 0;
|
||||||
|
|
||||||
|
ret = wc_Sha224Update(&sha224, (byte*)b.input, (word32)b.inLen);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
c.input = NULL;
|
||||||
|
c.inLen = SHA224_DIGEST_SIZE;
|
||||||
|
|
||||||
|
ret = wc_Sha224Update(&sha224, (byte*)c.input, (word32)c.inLen);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Update(NULL, (byte*)a.input, (word32)a.inLen);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If not returned then the unit test passed test vectors. */
|
||||||
|
printf(resultFmt, flag == 0 ? passed : failed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} /* END test_wc_Sha224Update */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
|
* Unit test on wc_Md5Final() in wolfcrypt/src/md5.c
|
||||||
*/
|
*/
|
||||||
@@ -3313,6 +3589,144 @@ static int test_wc_Sha384Final (void)
|
|||||||
|
|
||||||
} /* END test_wc_Sha384Final */
|
} /* END test_wc_Sha384Final */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unit test function for wc_RipeMdFinal()
|
||||||
|
*/
|
||||||
|
static int test_wc_RipeMdFinal (void)
|
||||||
|
{
|
||||||
|
#ifdef WOLFSSL_RIPEMD
|
||||||
|
RipeMd ripemd;
|
||||||
|
byte* hash_test[3];
|
||||||
|
byte hash1[RIPEMD_DIGEST_SIZE];
|
||||||
|
byte hash2[2*RIPEMD_DIGEST_SIZE];
|
||||||
|
byte hash3[5*RIPEMD_DIGEST_SIZE];
|
||||||
|
int times, i, ret, flag;
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
/* Initialize */
|
||||||
|
ret = wc_InitRipeMd(&ripemd);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
hash_test[0] = hash1;
|
||||||
|
hash_test[1] = hash2;
|
||||||
|
hash_test[2] = hash3;
|
||||||
|
}
|
||||||
|
|
||||||
|
times = sizeof(hash_test) / sizeof(byte*);
|
||||||
|
|
||||||
|
/* Good test args. */
|
||||||
|
printf(testingFmt, "wc_RipeMdFinal()");
|
||||||
|
/* Testing oversized buffers. */
|
||||||
|
for (i = 0; i < times; i++) {
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdFinal(&ripemd, hash_test[i]);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test bad args. */
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdFinal(NULL, NULL);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdFinal(NULL, hash1);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_RipeMdFinal(&ripemd, NULL);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, flag == 0 ? passed : failed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
} /* END test_wc_RipeMdFinal */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unit test for wc_Sha224Final();
|
||||||
|
*/
|
||||||
|
static int test_wc_Sha224Final (void)
|
||||||
|
{
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
|
Sha224 sha224;
|
||||||
|
byte* hash_test[3];
|
||||||
|
byte hash1[SHA224_DIGEST_SIZE];
|
||||||
|
byte hash2[2*SHA224_DIGEST_SIZE];
|
||||||
|
byte hash3[5*SHA224_DIGEST_SIZE];
|
||||||
|
int times, i, ret, flag;
|
||||||
|
|
||||||
|
flag = 0;
|
||||||
|
|
||||||
|
/* Initialize */
|
||||||
|
ret = wc_InitSha224(&sha224);
|
||||||
|
if (ret) {
|
||||||
|
flag = ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
hash_test[0] = hash1;
|
||||||
|
hash_test[1] = hash2;
|
||||||
|
hash_test[2] = hash3;
|
||||||
|
}
|
||||||
|
|
||||||
|
times = sizeof(hash_test) / sizeof(byte*);
|
||||||
|
|
||||||
|
/* Good test args. */
|
||||||
|
printf(testingFmt, "wc_sha224Final()");
|
||||||
|
/* Testing oversized buffers. */
|
||||||
|
for (i = 0; i < times; i++) {
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Final(&sha224, hash_test[i]);
|
||||||
|
if (ret != 0) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test bad args. */
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Final(NULL, NULL);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Final(NULL, hash1);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
ret = wc_Sha224Final(&sha224, NULL);
|
||||||
|
if (ret != BAD_FUNC_ARG) {
|
||||||
|
flag = SSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(resultFmt, flag == 0 ? passed : failed);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
} /* END test_wc_Sha224Final */
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
| Compatibility Tests
|
| Compatibility Tests
|
||||||
@@ -4566,6 +4980,12 @@ void ApiTest(void)
|
|||||||
AssertFalse(test_wc_InitSha384());
|
AssertFalse(test_wc_InitSha384());
|
||||||
AssertFalse(test_wc_Sha384Update());
|
AssertFalse(test_wc_Sha384Update());
|
||||||
AssertFalse(test_wc_Sha384Final());
|
AssertFalse(test_wc_Sha384Final());
|
||||||
|
AssertFalse(test_wc_InitSha224());
|
||||||
|
AssertFalse(test_wc_Sha224Update());
|
||||||
|
AssertFalse(test_wc_Sha224Final());
|
||||||
|
AssertFalse(test_wc_InitRipeMd());
|
||||||
|
AssertFalse(test_wc_RipeMdUpdate());
|
||||||
|
AssertFalse(test_wc_RipeMdFinal());
|
||||||
printf(" End API Tests\n");
|
printf(" End API Tests\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
19
tests/hash.c
19
tests/hash.c
@@ -590,6 +590,7 @@ int sha384_test()
|
|||||||
int ripemd_test(void)
|
int ripemd_test(void)
|
||||||
{
|
{
|
||||||
RipeMd ripemd;
|
RipeMd ripemd;
|
||||||
|
int ret;
|
||||||
byte hash[RIPEMD_DIGEST_SIZE];
|
byte hash[RIPEMD_DIGEST_SIZE];
|
||||||
|
|
||||||
testVector a, b, c, d;
|
testVector a, b, c, d;
|
||||||
@@ -626,12 +627,22 @@ int ripemd_test(void)
|
|||||||
test_ripemd[2] = c;
|
test_ripemd[2] = c;
|
||||||
test_ripemd[3] = d;
|
test_ripemd[3] = d;
|
||||||
|
|
||||||
wc_InitRipeMd(&ripemd);
|
ret = wc_InitRipeMd(&ripemd);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < times; ++i) {
|
for (i = 0; i < times; ++i) {
|
||||||
wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
|
ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
|
||||||
(word32)test_ripemd[i].inLen);
|
(word32)test_ripemd[i].inLen);
|
||||||
wc_RipeMdFinal(&ripemd, hash);
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = wc_RipeMdFinal(&ripemd, hash);
|
||||||
|
if (ret) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
|
if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
|
||||||
return -10 - i;
|
return -10 - i;
|
||||||
|
@@ -208,7 +208,7 @@ void bench_sha224(int);
|
|||||||
void bench_sha256(int);
|
void bench_sha256(int);
|
||||||
void bench_sha384(int);
|
void bench_sha384(int);
|
||||||
void bench_sha512(int);
|
void bench_sha512(int);
|
||||||
void bench_ripemd(void);
|
int bench_ripemd(void);
|
||||||
void bench_cmac(void);
|
void bench_cmac(void);
|
||||||
void bench_scrypt(void);
|
void bench_scrypt(void);
|
||||||
|
|
||||||
@@ -1039,7 +1039,7 @@ int benchmark_test(void *args)
|
|||||||
|
|
||||||
bench_stats_free();
|
bench_stats_free();
|
||||||
|
|
||||||
if (wolfCrypt_Cleanup() != 0) {
|
if (wolfCrypt_Cleanup() != 0) {
|
||||||
printf("error with wolfCrypt_Cleanup\n");
|
printf("error with wolfCrypt_Cleanup\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2085,24 +2085,36 @@ exit:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_RIPEMD
|
#ifdef WOLFSSL_RIPEMD
|
||||||
void bench_ripemd(void)
|
int bench_ripemd(void)
|
||||||
{
|
{
|
||||||
RipeMd hash;
|
RipeMd hash;
|
||||||
byte digest[RIPEMD_DIGEST_SIZE];
|
byte digest[RIPEMD_DIGEST_SIZE];
|
||||||
double start;
|
double start;
|
||||||
int i, count;
|
int i, count, ret;
|
||||||
|
|
||||||
wc_InitRipeMd(&hash);
|
ret = wc_InitRipeMd(&hash);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bench_stats_start(&count, &start);
|
bench_stats_start(&count, &start);
|
||||||
do {
|
do {
|
||||||
for (i = 0; i < numBlocks; i++) {
|
for (i = 0; i < numBlocks; i++) {
|
||||||
wc_RipeMdUpdate(&hash, bench_plain, BENCH_SIZE);
|
ret = wc_RipeMdUpdate(&hash, bench_plain, BENCH_SIZE);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wc_RipeMdFinal(&hash, digest);
|
ret = wc_RipeMdFinal(&hash, digest);
|
||||||
|
if (ret != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
count += i;
|
count += i;
|
||||||
} while (bench_stats_sym_check(start));
|
} while (bench_stats_sym_check(start));
|
||||||
bench_stats_sym_finish("RIPEMD", 0, count, start);
|
bench_stats_sym_finish("RIPEMD", 0, count, start);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -37,10 +37,14 @@
|
|||||||
#include <wolfcrypt/src/misc.c>
|
#include <wolfcrypt/src/misc.c>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
|
|
||||||
|
int wc_InitRipeMd(RipeMd* ripemd)
|
||||||
void wc_InitRipeMd(RipeMd* ripemd)
|
|
||||||
{
|
{
|
||||||
|
if (ripemd == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
ripemd->digest[0] = 0x67452301L;
|
ripemd->digest[0] = 0x67452301L;
|
||||||
ripemd->digest[1] = 0xEFCDAB89L;
|
ripemd->digest[1] = 0xEFCDAB89L;
|
||||||
ripemd->digest[2] = 0x98BADCFEL;
|
ripemd->digest[2] = 0x98BADCFEL;
|
||||||
@@ -50,6 +54,8 @@ void wc_InitRipeMd(RipeMd* ripemd)
|
|||||||
ripemd->buffLen = 0;
|
ripemd->buffLen = 0;
|
||||||
ripemd->loLen = 0;
|
ripemd->loLen = 0;
|
||||||
ripemd->hiLen = 0;
|
ripemd->hiLen = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -273,10 +279,16 @@ static INLINE void AddLength(RipeMd* ripemd, word32 len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wc_RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len)
|
int wc_RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len)
|
||||||
{
|
{
|
||||||
/* do block size increments */
|
/* do block size increments */
|
||||||
byte* local = (byte*)ripemd->buffer;
|
byte* local;
|
||||||
|
|
||||||
|
if (ripemd == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
local = (byte*)ripemd->buffer;
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
word32 add = min(len, RIPEMD_BLOCK_SIZE - ripemd->buffLen);
|
word32 add = min(len, RIPEMD_BLOCK_SIZE - ripemd->buffLen);
|
||||||
@@ -296,12 +308,19 @@ void wc_RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len)
|
|||||||
ripemd->buffLen = 0;
|
ripemd->buffLen = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wc_RipeMdFinal(RipeMd* ripemd, byte* hash)
|
int wc_RipeMdFinal(RipeMd* ripemd, byte* hash)
|
||||||
{
|
{
|
||||||
byte* local = (byte*)ripemd->buffer;
|
byte* local;
|
||||||
|
|
||||||
|
if (ripemd == NULL || hash == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
local = (byte*)ripemd->buffer;
|
||||||
|
|
||||||
AddLength(ripemd, ripemd->buffLen); /* before adding pads */
|
AddLength(ripemd, ripemd->buffLen); /* before adding pads */
|
||||||
|
|
||||||
@@ -340,7 +359,7 @@ void wc_RipeMdFinal(RipeMd* ripemd, byte* hash)
|
|||||||
#endif
|
#endif
|
||||||
XMEMCPY(hash, ripemd->digest, RIPEMD_DIGEST_SIZE);
|
XMEMCPY(hash, ripemd->digest, RIPEMD_DIGEST_SIZE);
|
||||||
|
|
||||||
wc_InitRipeMd(ripemd); /* reset state */
|
return wc_InitRipeMd(ripemd); /* reset state */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1818,8 +1818,13 @@ static int Transform_AVX2(Sha256* sha256)
|
|||||||
#ifdef WOLFSSL_SHA224
|
#ifdef WOLFSSL_SHA224
|
||||||
static int InitSha224(Sha224* sha224)
|
static int InitSha224(Sha224* sha224)
|
||||||
{
|
{
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (sha224 == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
sha224->digest[0] = 0xc1059ed8;
|
sha224->digest[0] = 0xc1059ed8;
|
||||||
sha224->digest[1] = 0x367cd507;
|
sha224->digest[1] = 0x367cd507;
|
||||||
sha224->digest[2] = 0x3070dd17;
|
sha224->digest[2] = 0x3070dd17;
|
||||||
@@ -1873,6 +1878,10 @@ static int Transform_AVX2(Sha256* sha256)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (sha224 == NULL || (data == NULL && len > 0)) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
|
||||||
if (sha224->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA224) {
|
if (sha224->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA224) {
|
||||||
#if defined(HAVE_INTEL_QA)
|
#if defined(HAVE_INTEL_QA)
|
||||||
@@ -1890,6 +1899,10 @@ static int Transform_AVX2(Sha256* sha256)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (sha224 == NULL || hash == NULL) {
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
|
#if defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_SHA224)
|
||||||
if (sha224->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA224) {
|
if (sha224->asyncDev.marker == WOLFSSL_ASYNC_MARKER_SHA224) {
|
||||||
#if defined(HAVE_INTEL_QA)
|
#if defined(HAVE_INTEL_QA)
|
||||||
|
@@ -1390,6 +1390,7 @@ int sha_test(void)
|
|||||||
int ripemd_test(void)
|
int ripemd_test(void)
|
||||||
{
|
{
|
||||||
RipeMd ripemd;
|
RipeMd ripemd;
|
||||||
|
int ret;
|
||||||
byte hash[RIPEMD_DIGEST_SIZE];
|
byte hash[RIPEMD_DIGEST_SIZE];
|
||||||
|
|
||||||
testVector a, b, c, d;
|
testVector a, b, c, d;
|
||||||
@@ -1426,15 +1427,25 @@ int ripemd_test(void)
|
|||||||
test_ripemd[2] = c;
|
test_ripemd[2] = c;
|
||||||
test_ripemd[3] = d;
|
test_ripemd[3] = d;
|
||||||
|
|
||||||
wc_InitRipeMd(&ripemd);
|
ret = wc_InitRipeMd(&ripemd);
|
||||||
|
if (ret != 0) {
|
||||||
|
return -1800;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < times; ++i) {
|
for (i = 0; i < times; ++i) {
|
||||||
wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
|
ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
|
||||||
(word32)test_ripemd[i].inLen);
|
(word32)test_ripemd[i].inLen);
|
||||||
wc_RipeMdFinal(&ripemd, hash);
|
if (ret != 0) {
|
||||||
|
return -1810 - i;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = wc_RipeMdFinal(&ripemd, hash);
|
||||||
|
if (ret != 0) {
|
||||||
|
return -1820 - i;
|
||||||
|
}
|
||||||
|
|
||||||
if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
|
if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
|
||||||
return -1800 - i;
|
return -1830 - i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -51,9 +51,9 @@ typedef struct RipeMd {
|
|||||||
} RipeMd;
|
} RipeMd;
|
||||||
|
|
||||||
|
|
||||||
WOLFSSL_API void wc_InitRipeMd(RipeMd*);
|
WOLFSSL_API int wc_InitRipeMd(RipeMd*);
|
||||||
WOLFSSL_API void wc_RipeMdUpdate(RipeMd*, const byte*, word32);
|
WOLFSSL_API int wc_RipeMdUpdate(RipeMd*, const byte*, word32);
|
||||||
WOLFSSL_API void wc_RipeMdFinal(RipeMd*, byte*);
|
WOLFSSL_API int wc_RipeMdFinal(RipeMd*, byte*);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Reference in New Issue
Block a user