Refactor unqiue hash types to use same internal values (ex WC_MD5 == WC_HASH_TYPE_MD5). Refactor the Sha3 types to use wc_ naming.

This commit is contained in:
David Garske 2018-03-30 10:50:58 -07:00
parent 264496567a
commit c83e63853d
19 changed files with 422 additions and 316 deletions

View File

@ -4623,7 +4623,7 @@ static int test_wc_InitSha3 (void)
{
int ret = 0;
#if defined(WOLFSSL_SHA3)
Sha3 sha3;
wc_Sha3 sha3;
#if !defined(WOLFSSL_NOSHA3_224)
printf(testingFmt, "wc_InitSha3_224()");
@ -4710,7 +4710,7 @@ static int testing_wc_Sha3_Update (void)
int ret = 0;
#if defined(WOLFSSL_SHA3)
Sha3 sha3;
wc_Sha3 sha3;
byte msg[] = "Everybody's working for the weekend.";
byte msg2[] = "Everybody gets Friday off.";
byte msgCmp[] = "\x45\x76\x65\x72\x79\x62\x6f\x64\x79\x27\x73\x20"
@ -4908,14 +4908,14 @@ static int test_wc_Sha3_224_Final (void)
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
Sha3 sha3;
wc_Sha3 sha3;
const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
"nopnopq";
const char* expOut = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55"
"\x74\x49\x44\x79\xba\x5c\x7e\x7a\xb7\x6e\xf2"
"\x64\xea\xd0\xfc\xce\x33";
byte hash[SHA3_224_DIGEST_SIZE];
byte hashRet[SHA3_224_DIGEST_SIZE];
byte hash[WC_SHA3_224_DIGEST_SIZE];
byte hashRet[WC_SHA3_224_DIGEST_SIZE];
/* Init stack variables. */
XMEMSET(hash, 0, sizeof(hash));
@ -4930,7 +4930,7 @@ static int test_wc_Sha3_224_Final (void)
ret= wc_Sha3_224_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg));
if (ret == 0) {
ret = wc_Sha3_224_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(expOut, hash, SHA3_224_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(expOut, hash, WC_SHA3_224_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -4967,7 +4967,7 @@ static int test_wc_Sha3_224_Final (void)
if (ret == 0) {
ret = wc_Sha3_224_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(hash, hashRet, SHA3_224_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(hash, hashRet, WC_SHA3_224_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5001,14 +5001,14 @@ static int test_wc_Sha3_256_Final (void)
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
Sha3 sha3;
wc_Sha3 sha3;
const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
"nopnopq";
const char* expOut = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8"
"\x23\x5e\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32"
"\xdd\x97\x49\x6d\x33\x76";
byte hash[SHA3_256_DIGEST_SIZE];
byte hashRet[SHA3_256_DIGEST_SIZE];
byte hash[WC_SHA3_256_DIGEST_SIZE];
byte hashRet[WC_SHA3_256_DIGEST_SIZE];
/* Init stack variables. */
XMEMSET(hash, 0, sizeof(hash));
@ -5023,7 +5023,7 @@ static int test_wc_Sha3_256_Final (void)
ret= wc_Sha3_256_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg));
if (ret == 0) {
ret = wc_Sha3_256_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(expOut, hash, SHA3_256_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(expOut, hash, WC_SHA3_256_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5057,7 +5057,7 @@ static int test_wc_Sha3_256_Final (void)
}
if (ret == 0) {
ret = wc_Sha3_256_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(hash, hashRet, SHA3_256_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(hash, hashRet, WC_SHA3_256_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5091,15 +5091,15 @@ static int test_wc_Sha3_384_Final (void)
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
Sha3 sha3;
wc_Sha3 sha3;
const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
"nopnopq";
const char* expOut = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7"
"\x8a\x49\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd"
"\xbc\x32\xb9\xd4\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe"
"\xa1\x9e\xef\x51\xac\xd0\x65\x7c\x22";
byte hash[SHA3_384_DIGEST_SIZE];
byte hashRet[SHA3_384_DIGEST_SIZE];
byte hash[WC_SHA3_384_DIGEST_SIZE];
byte hashRet[WC_SHA3_384_DIGEST_SIZE];
/* Init stack variables. */
XMEMSET(hash, 0, sizeof(hash));
@ -5114,7 +5114,7 @@ static int test_wc_Sha3_384_Final (void)
ret= wc_Sha3_384_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg));
if (ret == 0) {
ret = wc_Sha3_384_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(expOut, hash, SHA3_384_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(expOut, hash, WC_SHA3_384_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5148,7 +5148,7 @@ static int test_wc_Sha3_384_Final (void)
}
if (ret == 0) {
ret = wc_Sha3_384_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(hash, hashRet, SHA3_384_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(hash, hashRet, WC_SHA3_384_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5183,7 +5183,7 @@ static int test_wc_Sha3_512_Final (void)
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
Sha3 sha3;
wc_Sha3 sha3;
const char* msg = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnom"
"nopnopq";
const char* expOut = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10"
@ -5191,8 +5191,8 @@ static int test_wc_Sha3_512_Final (void)
"\xec\x2f\x1e\x91\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53"
"\x02\xba\x1b\x0d\x8d\xc7\x8c\x08\x63\x46\xb5\x33\xb4"
"\x9c\x03\x0d\x99\xa2\x7d\xaf\x11\x39\xd6\xe7\x5e";
byte hash[SHA3_512_DIGEST_SIZE];
byte hashRet[SHA3_512_DIGEST_SIZE];
byte hash[WC_SHA3_512_DIGEST_SIZE];
byte hashRet[WC_SHA3_512_DIGEST_SIZE];
/* Init stack variables. */
XMEMSET(hash, 0, sizeof(hash));
@ -5207,7 +5207,7 @@ static int test_wc_Sha3_512_Final (void)
ret= wc_Sha3_512_Update(&sha3, (byte*)msg, (word32)XSTRLEN(msg));
if (ret == 0) {
ret = wc_Sha3_512_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(expOut, hash, SHA3_512_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(expOut, hash, WC_SHA3_512_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5241,7 +5241,7 @@ static int test_wc_Sha3_512_Final (void)
}
if (ret == 0) {
ret = wc_Sha3_512_Final(&sha3, hash);
if (ret == 0 && XMEMCMP(hash, hashRet, SHA3_512_DIGEST_SIZE) != 0) {
if (ret == 0 && XMEMCMP(hash, hashRet, WC_SHA3_512_DIGEST_SIZE) != 0) {
ret = WOLFSSL_FATAL_ERROR;
}
}
@ -5274,11 +5274,11 @@ static int test_wc_Sha3_224_Copy (void)
{
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
Sha3 sha3, sha3Cpy;
wc_Sha3 sha3, sha3Cpy;
const char* msg = "Everyone gets Friday off.";
word32 msglen = (word32)XSTRLEN(msg);
byte hash[SHA3_224_DIGEST_SIZE];
byte hashCpy[SHA3_224_DIGEST_SIZE];
byte hash[WC_SHA3_224_DIGEST_SIZE];
byte hashCpy[WC_SHA3_224_DIGEST_SIZE];
XMEMSET(hash, 0, sizeof(hash));
XMEMSET(hashCpy, 0, sizeof(hashCpy));
@ -5339,11 +5339,11 @@ static int test_wc_Sha3_256_Copy (void)
{
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
Sha3 sha3, sha3Cpy;
wc_Sha3 sha3, sha3Cpy;
const char* msg = "Everyone gets Friday off.";
word32 msglen = (word32)XSTRLEN(msg);
byte hash[SHA3_256_DIGEST_SIZE];
byte hashCpy[SHA3_256_DIGEST_SIZE];
byte hash[WC_SHA3_256_DIGEST_SIZE];
byte hashCpy[WC_SHA3_256_DIGEST_SIZE];
XMEMSET(hash, 0, sizeof(hash));
XMEMSET(hashCpy, 0, sizeof(hashCpy));
@ -5404,11 +5404,11 @@ static int test_wc_Sha3_384_Copy (void)
{
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_384)
Sha3 sha3, sha3Cpy;
wc_Sha3 sha3, sha3Cpy;
const char* msg = "Everyone gets Friday off.";
word32 msglen = (word32)XSTRLEN(msg);
byte hash[SHA3_384_DIGEST_SIZE];
byte hashCpy[SHA3_384_DIGEST_SIZE];
byte hash[WC_SHA3_384_DIGEST_SIZE];
byte hashCpy[WC_SHA3_384_DIGEST_SIZE];
XMEMSET(hash, 0, sizeof(hash));
XMEMSET(hashCpy, 0, sizeof(hashCpy));
@ -5469,11 +5469,11 @@ static int test_wc_Sha3_512_Copy (void)
int ret = 0;
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
Sha3 sha3, sha3Cpy;
wc_Sha3 sha3, sha3Cpy;
const char* msg = "Everyone gets Friday off.";
word32 msglen = (word32)XSTRLEN(msg);
byte hash[SHA3_512_DIGEST_SIZE];
byte hashCpy[SHA3_512_DIGEST_SIZE];
byte hash[WC_SHA3_512_DIGEST_SIZE];
byte hashCpy[WC_SHA3_512_DIGEST_SIZE];
XMEMSET(hash, 0, sizeof(hash));
XMEMSET(hashCpy, 0, sizeof(hashCpy));

View File

@ -2944,10 +2944,10 @@ exit:
#ifndef WOLFSSL_NOSHA3_224
void bench_sha3_224(int doAsync)
{
Sha3 hash[BENCH_MAX_PENDING];
wc_Sha3 hash[BENCH_MAX_PENDING];
double start;
int ret = 0, i, count = 0, times, pending = 0;
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, SHA3_224_DIGEST_SIZE, HEAP_HINT);
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
/* clear for done cleanup */
XMEMSET(hash, 0, sizeof(hash));
@ -3024,10 +3024,10 @@ exit:
#ifndef WOLFSSL_NOSHA3_256
void bench_sha3_256(int doAsync)
{
Sha3 hash[BENCH_MAX_PENDING];
wc_Sha3 hash[BENCH_MAX_PENDING];
double start;
int ret = 0, i, count = 0, times, pending = 0;
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, SHA3_256_DIGEST_SIZE, HEAP_HINT);
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
/* clear for done cleanup */
XMEMSET(hash, 0, sizeof(hash));
@ -3104,10 +3104,10 @@ exit:
#ifndef WOLFSSL_NOSHA3_384
void bench_sha3_384(int doAsync)
{
Sha3 hash[BENCH_MAX_PENDING];
wc_Sha3 hash[BENCH_MAX_PENDING];
double start;
int ret = 0, i, count = 0, times, pending = 0;
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, SHA3_384_DIGEST_SIZE, HEAP_HINT);
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
/* clear for done cleanup */
XMEMSET(hash, 0, sizeof(hash));
@ -3184,10 +3184,10 @@ exit:
#ifndef WOLFSSL_NOSHA3_512
void bench_sha3_512(int doAsync)
{
Sha3 hash[BENCH_MAX_PENDING];
wc_Sha3 hash[BENCH_MAX_PENDING];
double start;
int ret = 0, i, count = 0, times, pending = 0;
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, SHA3_512_DIGEST_SIZE, HEAP_HINT);
DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
/* clear for done cleanup */
XMEMSET(hash, 0, sizeof(hash));

View File

@ -92,6 +92,11 @@ int wc_HashGetOID(enum wc_HashType hash_type)
/* Not Supported */
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_SHA3_224:
case WC_HASH_TYPE_SHA3_256:
case WC_HASH_TYPE_SHA3_384:
case WC_HASH_TYPE_SHA3_512:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
oid = BAD_FUNC_ARG;
@ -107,45 +112,75 @@ int wc_HashGetDigestSize(enum wc_HashType hash_type)
int dig_size = HASH_TYPE_E; /* Default to hash type error */
switch(hash_type)
{
case WC_HASH_TYPE_MD2:
#ifdef WOLFSSL_MD2
dig_size = MD2_DIGEST_SIZE;
#endif
break;
case WC_HASH_TYPE_MD4:
#ifndef NO_MD4
dig_size = MD4_DIGEST_SIZE;
#endif
break;
case WC_HASH_TYPE_MD5:
#ifndef NO_MD5
#ifndef NO_MD5
dig_size = WC_MD5_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA:
#ifndef NO_SHA
#ifndef NO_SHA
dig_size = WC_SHA_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA224:
#ifdef WOLFSSL_SHA224
#ifdef WOLFSSL_SHA224
dig_size = WC_SHA224_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA256:
#ifndef NO_SHA256
#ifndef NO_SHA256
dig_size = WC_SHA256_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA384:
#if defined(WOLFSSL_SHA512) && defined(WOLFSSL_SHA384)
#if defined(WOLFSSL_SHA512) && defined(WOLFSSL_SHA384)
dig_size = WC_SHA384_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA512:
#ifdef WOLFSSL_SHA512
#ifdef WOLFSSL_SHA512
dig_size = WC_SHA512_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_MD5_SHA:
#if !defined(NO_MD5) && !defined(NO_SHA)
case WC_HASH_TYPE_MD5_SHA: /* Old TLS Specific */
#if !defined(NO_MD5) && !defined(NO_SHA)
dig_size = WC_MD5_DIGEST_SIZE + WC_SHA_DIGEST_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA3_224:
#ifdef WOLFSSL_SHA3
dig_size = WC_SHA3_224_DIGEST_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_256:
#ifdef WOLFSSL_SHA3
dig_size = WC_SHA3_256_DIGEST_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_384:
#ifdef WOLFSSL_SHA3
dig_size = WC_SHA3_384_DIGEST_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_512:
#ifdef WOLFSSL_SHA3
dig_size = WC_SHA3_512_DIGEST_SIZE;
#endif
break;
/* Not Supported */
case WC_HASH_TYPE_MD2:
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
dig_size = BAD_FUNC_ARG;
@ -161,41 +196,75 @@ int wc_HashGetBlockSize(enum wc_HashType hash_type)
int block_size = HASH_TYPE_E; /* Default to hash type error */
switch (hash_type)
{
case WC_HASH_TYPE_MD2:
#ifdef WOLFSSL_MD2
block_size = MD2_BLOCK_SIZE;
#endif
break;
case WC_HASH_TYPE_MD4:
#ifndef NO_MD4
block_size = MD4_BLOCK_SIZE;
#endif
break;
case WC_HASH_TYPE_MD5:
#ifndef NO_MD5
#ifndef NO_MD5
block_size = WC_MD5_BLOCK_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA:
#ifndef NO_SHA
#ifndef NO_SHA
block_size = WC_SHA_BLOCK_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA224:
#ifdef WOLFSSL_SHA224
#ifdef WOLFSSL_SHA224
block_size = WC_SHA224_BLOCK_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA256:
#ifndef NO_SHA256
#ifndef NO_SHA256
block_size = WC_SHA256_BLOCK_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA384:
#if defined(WOLFSSL_SHA512) && defined(WOLFSSL_SHA384)
#if defined(WOLFSSL_SHA512) && defined(WOLFSSL_SHA384)
block_size = WC_SHA384_BLOCK_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_SHA512:
#ifdef WOLFSSL_SHA512
#ifdef WOLFSSL_SHA512
block_size = WC_SHA512_BLOCK_SIZE;
#endif
#endif
break;
case WC_HASH_TYPE_MD5_SHA: /* Old TLS Specific */
#if !defined(NO_MD5) && !defined(NO_SHA)
block_size = WC_MD5_BLOCK_SIZE + WC_SHA_BLOCK_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_224:
#ifdef WOLFSSL_SHA3
block_size = WC_SHA3_224_BLOCK_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_256:
#ifdef WOLFSSL_SHA3
block_size = WC_SHA3_256_BLOCK_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_384:
#ifdef WOLFSSL_SHA3
block_size = WC_SHA3_384_BLOCK_SIZE;
#endif
break;
case WC_HASH_TYPE_SHA3_512:
#ifdef WOLFSSL_SHA3
block_size = WC_SHA3_512_BLOCK_SIZE;
#endif
break;
/* Not Supported */
case WC_HASH_TYPE_MD5_SHA:
case WC_HASH_TYPE_MD2:
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
block_size = BAD_FUNC_ARG;
@ -267,6 +336,11 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data,
/* Not Supported */
case WC_HASH_TYPE_MD2:
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_SHA3_224:
case WC_HASH_TYPE_SHA3_256:
case WC_HASH_TYPE_SHA3_384:
case WC_HASH_TYPE_SHA3_512:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
ret = BAD_FUNC_ARG;
@ -319,6 +393,11 @@ int wc_HashInit(wc_HashAlg* hash, enum wc_HashType type)
case WC_HASH_TYPE_MD5_SHA:
case WC_HASH_TYPE_MD2:
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_SHA3_224:
case WC_HASH_TYPE_SHA3_256:
case WC_HASH_TYPE_SHA3_384:
case WC_HASH_TYPE_SHA3_512:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
ret = BAD_FUNC_ARG;
@ -374,6 +453,11 @@ int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type, const byte* data,
case WC_HASH_TYPE_MD5_SHA:
case WC_HASH_TYPE_MD2:
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_SHA3_224:
case WC_HASH_TYPE_SHA3_256:
case WC_HASH_TYPE_SHA3_384:
case WC_HASH_TYPE_SHA3_512:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
ret = BAD_FUNC_ARG;
@ -426,6 +510,11 @@ int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type, byte* out)
case WC_HASH_TYPE_MD5_SHA:
case WC_HASH_TYPE_MD2:
case WC_HASH_TYPE_MD4:
case WC_HASH_TYPE_SHA3_224:
case WC_HASH_TYPE_SHA3_256:
case WC_HASH_TYPE_SHA3_384:
case WC_HASH_TYPE_SHA3_512:
case WC_HASH_TYPE_BLAKE2B:
case WC_HASH_TYPE_NONE:
default:
ret = BAD_FUNC_ARG;

View File

@ -450,7 +450,7 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
#ifdef WOLFSSL_SHA3
case WC_SHA3_224:
hmac_block_size = WC_SHA3_224_BLOCK_SIZE;
if (length <= SHA3_224_DIGEST_SIZE) {
if (length <= WC_SHA3_224_DIGEST_SIZE) {
if (key != NULL) {
XMEMCPY(ip, key, length);
}
@ -463,12 +463,12 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
if (ret != 0)
break;
length = SHA3_224_DIGEST_SIZE;
length = WC_SHA3_224_DIGEST_SIZE;
}
break;
case WC_SHA3_256:
hmac_block_size = WC_SHA3_256_BLOCK_SIZE;
if (length <= SHA3_256_DIGEST_SIZE) {
if (length <= WC_SHA3_256_DIGEST_SIZE) {
if (key != NULL) {
XMEMCPY(ip, key, length);
}
@ -481,12 +481,12 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
if (ret != 0)
break;
length = SHA3_256_DIGEST_SIZE;
length = WC_SHA3_256_DIGEST_SIZE;
}
break;
case WC_SHA3_384:
hmac_block_size = WC_SHA3_384_BLOCK_SIZE;
if (length <= SHA3_384_DIGEST_SIZE) {
if (length <= WC_SHA3_384_DIGEST_SIZE) {
if (key != NULL) {
XMEMCPY(ip, key, length);
}
@ -499,12 +499,12 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
if (ret != 0)
break;
length = SHA3_384_DIGEST_SIZE;
length = WC_SHA3_384_DIGEST_SIZE;
}
break;
case WC_SHA3_512:
hmac_block_size = WC_SHA3_512_BLOCK_SIZE;
if (length <= SHA3_512_DIGEST_SIZE) {
if (length <= WC_SHA3_512_DIGEST_SIZE) {
if (key != NULL) {
XMEMCPY(ip, key, length);
}
@ -517,7 +517,7 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
if (ret != 0)
break;
length = SHA3_512_DIGEST_SIZE;
length = WC_SHA3_512_DIGEST_SIZE;
}
break;
#endif /* WOLFSSL_SHA3 */
@ -899,7 +899,7 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
if (ret != 0)
break;
ret = wc_Sha3_224_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
SHA3_224_DIGEST_SIZE);
WC_SHA3_224_DIGEST_SIZE);
if (ret != 0)
break;
ret = wc_Sha3_224_Final(&hmac->hash.sha3, hash);
@ -913,7 +913,7 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
if (ret != 0)
break;
ret = wc_Sha3_256_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
SHA3_256_DIGEST_SIZE);
WC_SHA3_256_DIGEST_SIZE);
if (ret != 0)
break;
ret = wc_Sha3_256_Final(&hmac->hash.sha3, hash);
@ -927,7 +927,7 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
if (ret != 0)
break;
ret = wc_Sha3_384_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
SHA3_384_DIGEST_SIZE);
WC_SHA3_384_DIGEST_SIZE);
if (ret != 0)
break;
ret = wc_Sha3_384_Final(&hmac->hash.sha3, hash);
@ -941,7 +941,7 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
if (ret != 0)
break;
ret = wc_Sha3_512_Update(&hmac->hash.sha3, (byte*)hmac->innerHash,
SHA3_512_DIGEST_SIZE);
WC_SHA3_512_DIGEST_SIZE);
if (ret != 0)
break;
ret = wc_Sha3_512_Final(&hmac->hash.sha3, hash);

View File

@ -44,7 +44,7 @@
* heap memory heap hint to use
* devId used for async operations (currently not supported here)
*/
int wc_InitSha3_384(Sha3* sha, void* heap, int devId)
int wc_InitSha3_384(wc_Sha3* sha, void* heap, int devId)
{
XCsuDma_Config* con;
@ -80,7 +80,7 @@ int wc_InitSha3_384(Sha3* sha, void* heap, int devId)
* data message to update SHA3 state with
* len length of data buffer
*/
int wc_Sha3_384_Update(Sha3* sha, const byte* data, word32 len)
int wc_Sha3_384_Update(wc_Sha3* sha, const byte* data, word32 len)
{
if (sha == NULL || (data == NULL && len > 0)) {
return BAD_FUNC_ARG;
@ -96,7 +96,7 @@ int wc_Sha3_384_Update(Sha3* sha, const byte* data, word32 len)
* sha SHA3 structure to get hash
* out digest out, expected to be large enough to hold SHA3 digest
*/
int wc_Sha3_384_Final(Sha3* sha, byte* out)
int wc_Sha3_384_Final(wc_Sha3* sha, byte* out)
{
if (sha == NULL || out == NULL) {
return BAD_FUNC_ARG;
@ -111,7 +111,7 @@ int wc_Sha3_384_Final(Sha3* sha, byte* out)
*
* sha SHA3 structure to free
*/
void wc_Sha3_384_Free(Sha3* sha)
void wc_Sha3_384_Free(wc_Sha3* sha)
{
(void)sha;
/* nothing to free yet */
@ -123,9 +123,9 @@ void wc_Sha3_384_Free(Sha3* sha)
* sha SHA3 structure to get hash
* out digest out, expected to be large enough to hold SHA3 digest
*/
int wc_Sha3_384_GetHash(Sha3* sha, byte* out)
int wc_Sha3_384_GetHash(wc_Sha3* sha, byte* out)
{
Sha3 s;
wc_Sha3 s;
if (sha == NULL || out == NULL) {
return BAD_FUNC_ARG;
@ -145,13 +145,13 @@ int wc_Sha3_384_GetHash(Sha3* sha, byte* out)
* src SHA3 structure to make copy of
* dst [out]structure to hold copy
*/
int wc_Sha3_384_Copy(Sha3* src, Sha3* dst)
int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
{
if (src == NULL || dst== NULL) {
return BAD_FUNC_ARG;
}
XMEMCPY((byte*)dst, (byte*)src, sizeof(Sha3));
XMEMCPY((byte*)dst, (byte*)src, sizeof(wc_Sha3));
return 0;
}

View File

@ -34,7 +34,7 @@
/* fips wrapper calls, user can call direct */
#ifdef HAVE_FIPS
int wc_InitSha3_224(Sha3* sha, void* heap, int devId)
int wc_InitSha3_224(wc_Sha3* sha, void* heap, int devId)
{
(void)heap;
(void)devId;
@ -43,27 +43,27 @@
}
return InitSha3_224_fips(sha);
}
int wc_Sha3_224_Update(Sha3* sha, const byte* data, word32 len)
int wc_Sha3_224_Update(wc_Sha3* sha, const byte* data, word32 len)
{
if (sha == NULL || (data == NULL && len > 0)) {
return BAD_FUNC_ARG;
}
return Sha3_224_Update_fips(sha, data, len);
}
int wc_Sha3_224_Final(Sha3* sha, byte* out)
int wc_Sha3_224_Final(wc_Sha3* sha, byte* out)
{
if (sha == NULL || out == NULL) {
return BAD_FUNC_ARG;
}
return Sha3_224_Final_fips(sha, out);
}
void wc_Sha3_224_Free(Sha3* sha)
void wc_Sha3_224_Free(wc_Sha3* sha)
{
(void)sha;
/* Not supported in FIPS */
}
int wc_InitSha3_256(Sha3* sha, void* heap, int devId)
int wc_InitSha3_256(wc_Sha3* sha, void* heap, int devId)
{
(void)heap;
(void)devId;
@ -72,27 +72,27 @@
}
return InitSha3_256_fips(sha);
}
int wc_Sha3_256_Update(Sha3* sha, const byte* data, word32 len)
int wc_Sha3_256_Update(wc_Sha3* sha, const byte* data, word32 len)
{
if (sha == NULL || (data == NULL && len > 0)) {
return BAD_FUNC_ARG;
}
return Sha3_256_Update_fips(sha, data, len);
}
int wc_Sha3_256_Final(Sha3* sha, byte* out)
int wc_Sha3_256_Final(wc_Sha3* sha, byte* out)
{
if (sha == NULL || out == NULL) {
return BAD_FUNC_ARG;
}
return Sha3_256_Final_fips(sha, out);
}
void wc_Sha3_256_Free(Sha3* sha)
void wc_Sha3_256_Free(wc_Sha3* sha)
{
(void)sha;
/* Not supported in FIPS */
}
int wc_InitSha3_384(Sha3* sha, void* heap, int devId)
int wc_InitSha3_384(wc_Sha3* sha, void* heap, int devId)
{
(void)heap;
(void)devId;
@ -101,27 +101,27 @@
}
return InitSha3_384_fips(sha);
}
int wc_Sha3_384_Update(Sha3* sha, const byte* data, word32 len)
int wc_Sha3_384_Update(wc_Sha3* sha, const byte* data, word32 len)
{
if (sha == NULL || (data == NULL && len > 0)) {
return BAD_FUNC_ARG;
}
return Sha3_384_Update_fips(sha, data, len);
}
int wc_Sha3_384_Final(Sha3* sha, byte* out)
int wc_Sha3_384_Final(wc_Sha3* sha, byte* out)
{
if (sha == NULL || out == NULL) {
return BAD_FUNC_ARG;
}
return Sha3_384_Final_fips(sha, out);
}
void wc_Sha3_384_Free(Sha3* sha)
void wc_Sha3_384_Free(wc_Sha3* sha)
{
(void)sha;
/* Not supported in FIPS */
}
int wc_InitSha3_512(Sha3* sha, void* heap, int devId)
int wc_InitSha3_512(wc_Sha3* sha, void* heap, int devId)
{
(void)heap;
(void)devId;
@ -130,21 +130,21 @@
}
return InitSha3_512_fips(sha);
}
int wc_Sha3_512_Update(Sha3* sha, const byte* data, word32 len)
int wc_Sha3_512_Update(wc_Sha3* sha, const byte* data, word32 len)
{
if (sha == NULL || (data == NULL && len > 0)) {
return BAD_FUNC_ARG;
}
return Sha3_512_Update_fips(sha, data, len);
}
int wc_Sha3_512_Final(Sha3* sha, byte* out)
int wc_Sha3_512_Final(wc_Sha3* sha, byte* out)
{
if (sha == NULL || out == NULL) {
return BAD_FUNC_ARG;
}
return Sha3_512_Final_fips(sha, out);
}
void wc_Sha3_512_Free(Sha3* sha)
void wc_Sha3_512_Free(wc_Sha3* sha)
{
(void)sha;
/* Not supported in FIPS */
@ -668,10 +668,10 @@ static word64 Load64BitBigEndian(const byte* a)
/* Initialize the state for a SHA3-224 hash operation.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* returns 0 on success.
*/
static int InitSha3(Sha3* sha3)
static int InitSha3(wc_Sha3* sha3)
{
int i;
@ -684,13 +684,13 @@ static int InitSha3(Sha3* sha3)
/* Update the SHA-3 hash state with message data.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* data Message data to be hashed.
* len Length of the message data.
* p Number of 64-bit numbers in a block of data to process.
* returns 0 on success.
*/
static int Sha3Update(Sha3* sha3, const byte* data, word32 len, byte p)
static int Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, byte p)
{
byte i;
byte l;
@ -735,13 +735,13 @@ static int Sha3Update(Sha3* sha3, const byte* data, word32 len, byte p)
/* Calculate the SHA-3 hash based on all the message data seen.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result.
* p Number of 64-bit numbers in a block of data to process.
* len Number of bytes in output.
* returns 0 on success.
*/
static int Sha3Final(Sha3* sha3, byte* hash, byte p, byte l)
static int Sha3Final(wc_Sha3* sha3, byte* hash, byte p, byte l)
{
byte i;
byte *s8 = (byte *)sha3->s;
@ -765,12 +765,12 @@ static int Sha3Final(Sha3* sha3, byte* hash, byte p, byte l)
/* Initialize the state for a SHA-3 hash operation.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* heap Heap reference for dynamic memory allocation. (Used in async ops.)
* devId Device identifier for asynchronous operation.
* returns 0 on success.
*/
static int wc_InitSha3(Sha3* sha3, void* heap, int devId)
static int wc_InitSha3(wc_Sha3* sha3, void* heap, int devId)
{
int ret = 0;
@ -794,13 +794,13 @@ static int wc_InitSha3(Sha3* sha3, void* heap, int devId)
/* Update the SHA-3 hash state with message data.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* data Message data to be hashed.
* len Length of the message data.
* p Number of 64-bit numbers in a block of data to process.
* returns 0 on success.
*/
static int wc_Sha3Update(Sha3* sha3, const byte* data, word32 len, byte p)
static int wc_Sha3Update(wc_Sha3* sha3, const byte* data, word32 len, byte p)
{
int ret = 0;
@ -823,13 +823,13 @@ static int wc_Sha3Update(Sha3* sha3, const byte* data, word32 len, byte p)
/* Calculate the SHA-3 hash based on all the message data seen.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result.
* p Number of 64-bit numbers in a block of data to process.
* len Number of bytes in output.
* returns 0 on success.
*/
static int wc_Sha3Final(Sha3* sha3, byte* hash, byte p, byte len)
static int wc_Sha3Final(wc_Sha3* sha3, byte* hash, byte p, byte len)
{
int ret;
@ -856,10 +856,10 @@ static int wc_Sha3Final(Sha3* sha3, byte* hash, byte p, byte len)
/* Dispose of any dynamically allocated data from the SHA3-384 operation.
* (Required for async ops.)
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* returns 0 on success.
*/
static void wc_Sha3Free(Sha3* sha3)
static void wc_Sha3Free(wc_Sha3* sha3)
{
(void)sha3;
@ -874,18 +874,18 @@ static void wc_Sha3Free(Sha3* sha3)
/* Copy the state of the SHA3 operation.
*
* src Sha3 object holding state top copy.
* dst Sha3 object to copy into.
* src wc_Sha3 object holding state top copy.
* dst wc_Sha3 object to copy into.
* returns 0 on success.
*/
static int wc_Sha3Copy(Sha3* src, Sha3* dst)
static int wc_Sha3Copy(wc_Sha3* src, wc_Sha3* dst)
{
int ret = 0;
if (src == NULL || dst == NULL)
return BAD_FUNC_ARG;
XMEMCPY(dst, src, sizeof(Sha3));
XMEMCPY(dst, src, sizeof(wc_Sha3));
#ifdef WOLFSSL_ASYNC_CRYPT
ret = wolfAsync_DevCopy(&src->asyncDev, &dst->asyncDev);
@ -898,16 +898,16 @@ static int wc_Sha3Copy(Sha3* src, Sha3* dst)
* More message data can be added, after this operation, using the current
* state.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 28 bytes.
* p Number of 64-bit numbers in a block of data to process.
* len Number of bytes in output.
* returns 0 on success.
*/
static int wc_Sha3GetHash(Sha3* sha3, byte* hash, byte p, byte len)
static int wc_Sha3GetHash(wc_Sha3* sha3, byte* hash, byte p, byte len)
{
int ret;
Sha3 tmpSha3;
wc_Sha3 tmpSha3;
if (sha3 == NULL || hash == NULL)
return BAD_FUNC_ARG;
@ -922,47 +922,47 @@ static int wc_Sha3GetHash(Sha3* sha3, byte* hash, byte p, byte len)
/* Initialize the state for a SHA3-224 hash operation.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* heap Heap reference for dynamic memory allocation. (Used in async ops.)
* devId Device identifier for asynchronous operation.
* returns 0 on success.
*/
WOLFSSL_API int wc_InitSha3_224(Sha3* sha3, void* heap, int devId)
WOLFSSL_API int wc_InitSha3_224(wc_Sha3* sha3, void* heap, int devId)
{
return wc_InitSha3(sha3, heap, devId);
}
/* Update the SHA3-224 hash state with message data.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* data Message data to be hashed.
* len Length of the message data.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_224_Update(Sha3* sha3, const byte* data, word32 len)
WOLFSSL_API int wc_Sha3_224_Update(wc_Sha3* sha3, const byte* data, word32 len)
{
return wc_Sha3Update(sha3, data, len, SHA3_224_COUNT);
return wc_Sha3Update(sha3, data, len, WC_SHA3_224_COUNT);
}
/* Calculate the SHA3-224 hash based on all the message data seen.
* The state is initialized ready for a new message to hash.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 28 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_224_Final(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_224_Final(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3Final(sha3, hash, SHA3_224_COUNT, SHA3_224_DIGEST_SIZE);
return wc_Sha3Final(sha3, hash, WC_SHA3_224_COUNT, WC_SHA3_224_DIGEST_SIZE);
}
/* Dispose of any dynamically allocated data from the SHA3-224 operation.
* (Required for async ops.)
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* returns 0 on success.
*/
WOLFSSL_API void wc_Sha3_224_Free(Sha3* sha3)
WOLFSSL_API void wc_Sha3_224_Free(wc_Sha3* sha3)
{
wc_Sha3Free(sha3);
}
@ -971,22 +971,22 @@ WOLFSSL_API void wc_Sha3_224_Free(Sha3* sha3)
* More message data can be added, after this operation, using the current
* state.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 28 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_224_GetHash(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_224_GetHash(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3GetHash(sha3, hash, SHA3_224_COUNT, SHA3_224_DIGEST_SIZE);
return wc_Sha3GetHash(sha3, hash, WC_SHA3_224_COUNT, WC_SHA3_224_DIGEST_SIZE);
}
/* Copy the state of the SHA3-224 operation.
*
* src Sha3 object holding state top copy.
* dst Sha3 object to copy into.
* src wc_Sha3 object holding state top copy.
* dst wc_Sha3 object to copy into.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_224_Copy(Sha3* src, Sha3* dst)
WOLFSSL_API int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst)
{
return wc_Sha3Copy(src, dst);
}
@ -994,47 +994,47 @@ WOLFSSL_API int wc_Sha3_224_Copy(Sha3* src, Sha3* dst)
/* Initialize the state for a SHA3-256 hash operation.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* heap Heap reference for dynamic memory allocation. (Used in async ops.)
* devId Device identifier for asynchronous operation.
* returns 0 on success.
*/
WOLFSSL_API int wc_InitSha3_256(Sha3* sha3, void* heap, int devId)
WOLFSSL_API int wc_InitSha3_256(wc_Sha3* sha3, void* heap, int devId)
{
return wc_InitSha3(sha3, heap, devId);
}
/* Update the SHA3-256 hash state with message data.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* data Message data to be hashed.
* len Length of the message data.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_256_Update(Sha3* sha3, const byte* data, word32 len)
WOLFSSL_API int wc_Sha3_256_Update(wc_Sha3* sha3, const byte* data, word32 len)
{
return wc_Sha3Update(sha3, data, len, SHA3_256_COUNT);
return wc_Sha3Update(sha3, data, len, WC_SHA3_256_COUNT);
}
/* Calculate the SHA3-256 hash based on all the message data seen.
* The state is initialized ready for a new message to hash.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 32 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_256_Final(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_256_Final(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3Final(sha3, hash, SHA3_256_COUNT, SHA3_256_DIGEST_SIZE);
return wc_Sha3Final(sha3, hash, WC_SHA3_256_COUNT, WC_SHA3_256_DIGEST_SIZE);
}
/* Dispose of any dynamically allocated data from the SHA3-256 operation.
* (Required for async ops.)
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* returns 0 on success.
*/
WOLFSSL_API void wc_Sha3_256_Free(Sha3* sha3)
WOLFSSL_API void wc_Sha3_256_Free(wc_Sha3* sha3)
{
wc_Sha3Free(sha3);
}
@ -1043,22 +1043,22 @@ WOLFSSL_API void wc_Sha3_256_Free(Sha3* sha3)
* More message data can be added, after this operation, using the current
* state.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 32 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_256_GetHash(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_256_GetHash(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3GetHash(sha3, hash, SHA3_256_COUNT, SHA3_256_DIGEST_SIZE);
return wc_Sha3GetHash(sha3, hash, WC_SHA3_256_COUNT, WC_SHA3_256_DIGEST_SIZE);
}
/* Copy the state of the SHA3-256 operation.
*
* src Sha3 object holding state top copy.
* dst Sha3 object to copy into.
* src wc_Sha3 object holding state top copy.
* dst wc_Sha3 object to copy into.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_256_Copy(Sha3* src, Sha3* dst)
WOLFSSL_API int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst)
{
return wc_Sha3Copy(src, dst);
}
@ -1066,47 +1066,47 @@ WOLFSSL_API int wc_Sha3_256_Copy(Sha3* src, Sha3* dst)
/* Initialize the state for a SHA3-384 hash operation.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* heap Heap reference for dynamic memory allocation. (Used in async ops.)
* devId Device identifier for asynchronous operation.
* returns 0 on success.
*/
WOLFSSL_API int wc_InitSha3_384(Sha3* sha3, void* heap, int devId)
WOLFSSL_API int wc_InitSha3_384(wc_Sha3* sha3, void* heap, int devId)
{
return wc_InitSha3(sha3, heap, devId);
}
/* Update the SHA3-384 hash state with message data.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* data Message data to be hashed.
* len Length of the message data.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_384_Update(Sha3* sha3, const byte* data, word32 len)
WOLFSSL_API int wc_Sha3_384_Update(wc_Sha3* sha3, const byte* data, word32 len)
{
return wc_Sha3Update(sha3, data, len, SHA3_384_COUNT);
return wc_Sha3Update(sha3, data, len, WC_SHA3_384_COUNT);
}
/* Calculate the SHA3-384 hash based on all the message data seen.
* The state is initialized ready for a new message to hash.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 48 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_384_Final(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_384_Final(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3Final(sha3, hash, SHA3_384_COUNT, SHA3_384_DIGEST_SIZE);
return wc_Sha3Final(sha3, hash, WC_SHA3_384_COUNT, WC_SHA3_384_DIGEST_SIZE);
}
/* Dispose of any dynamically allocated data from the SHA3-384 operation.
* (Required for async ops.)
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* returns 0 on success.
*/
WOLFSSL_API void wc_Sha3_384_Free(Sha3* sha3)
WOLFSSL_API void wc_Sha3_384_Free(wc_Sha3* sha3)
{
wc_Sha3Free(sha3);
}
@ -1115,22 +1115,22 @@ WOLFSSL_API void wc_Sha3_384_Free(Sha3* sha3)
* More message data can be added, after this operation, using the current
* state.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 48 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_384_GetHash(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_384_GetHash(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3GetHash(sha3, hash, SHA3_384_COUNT, SHA3_384_DIGEST_SIZE);
return wc_Sha3GetHash(sha3, hash, WC_SHA3_384_COUNT, WC_SHA3_384_DIGEST_SIZE);
}
/* Copy the state of the SHA3-384 operation.
*
* src Sha3 object holding state top copy.
* dst Sha3 object to copy into.
* src wc_Sha3 object holding state top copy.
* dst wc_Sha3 object to copy into.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_384_Copy(Sha3* src, Sha3* dst)
WOLFSSL_API int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst)
{
return wc_Sha3Copy(src, dst);
}
@ -1138,47 +1138,47 @@ WOLFSSL_API int wc_Sha3_384_Copy(Sha3* src, Sha3* dst)
/* Initialize the state for a SHA3-512 hash operation.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* heap Heap reference for dynamic memory allocation. (Used in async ops.)
* devId Device identifier for asynchronous operation.
* returns 0 on success.
*/
WOLFSSL_API int wc_InitSha3_512(Sha3* sha3, void* heap, int devId)
WOLFSSL_API int wc_InitSha3_512(wc_Sha3* sha3, void* heap, int devId)
{
return wc_InitSha3(sha3, heap, devId);
}
/* Update the SHA3-512 hash state with message data.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* data Message data to be hashed.
* len Length of the message data.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_512_Update(Sha3* sha3, const byte* data, word32 len)
WOLFSSL_API int wc_Sha3_512_Update(wc_Sha3* sha3, const byte* data, word32 len)
{
return wc_Sha3Update(sha3, data, len, SHA3_512_COUNT);
return wc_Sha3Update(sha3, data, len, WC_SHA3_512_COUNT);
}
/* Calculate the SHA3-512 hash based on all the message data seen.
* The state is initialized ready for a new message to hash.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 64 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_512_Final(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_512_Final(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3Final(sha3, hash, SHA3_512_COUNT, SHA3_512_DIGEST_SIZE);
return wc_Sha3Final(sha3, hash, WC_SHA3_512_COUNT, WC_SHA3_512_DIGEST_SIZE);
}
/* Dispose of any dynamically allocated data from the SHA3-512 operation.
* (Required for async ops.)
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* returns 0 on success.
*/
WOLFSSL_API void wc_Sha3_512_Free(Sha3* sha3)
WOLFSSL_API void wc_Sha3_512_Free(wc_Sha3* sha3)
{
wc_Sha3Free(sha3);
}
@ -1187,22 +1187,22 @@ WOLFSSL_API void wc_Sha3_512_Free(Sha3* sha3)
* More message data can be added, after this operation, using the current
* state.
*
* sha3 Sha3 object holding state.
* sha3 wc_Sha3 object holding state.
* hash Buffer to hold the hash result. Must be at least 64 bytes.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_512_GetHash(Sha3* sha3, byte* hash)
WOLFSSL_API int wc_Sha3_512_GetHash(wc_Sha3* sha3, byte* hash)
{
return wc_Sha3GetHash(sha3, hash, SHA3_512_COUNT, SHA3_512_DIGEST_SIZE);
return wc_Sha3GetHash(sha3, hash, WC_SHA3_512_COUNT, WC_SHA3_512_DIGEST_SIZE);
}
/* Copy the state of the SHA3-512 operation.
*
* src Sha3 object holding state top copy.
* dst Sha3 object to copy into.
* src wc_Sha3 object holding state top copy.
* dst wc_Sha3 object to copy into.
* returns 0 on success.
*/
WOLFSSL_API int wc_Sha3_512_Copy(Sha3* src, Sha3* dst)
WOLFSSL_API int wc_Sha3_512_Copy(wc_Sha3* src, wc_Sha3* dst)
{
return wc_Sha3Copy(src, dst);
}

View File

@ -2176,9 +2176,9 @@ exit:
#ifndef WOLFSSL_NOSHA3_224
static int sha3_224_test(void)
{
Sha3 sha;
byte hash[SHA3_224_DIGEST_SIZE];
byte hashcopy[SHA3_224_DIGEST_SIZE];
wc_Sha3 sha;
byte hash[WC_SHA3_224_DIGEST_SIZE];
byte hashcopy[WC_SHA3_224_DIGEST_SIZE];
testVector a, b, c;
testVector test_sha[3];
@ -2189,19 +2189,19 @@ static int sha3_224_test(void)
a.output = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1"
"\xab\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7";
a.inLen = XSTRLEN(a.input);
a.outLen = SHA3_224_DIGEST_SIZE;
a.outLen = WC_SHA3_224_DIGEST_SIZE;
b.input = "abc";
b.output = "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76"
"\x6f\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf";
b.inLen = XSTRLEN(b.input);
b.outLen = SHA3_224_DIGEST_SIZE;
b.outLen = WC_SHA3_224_DIGEST_SIZE;
c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
c.output = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79"
"\xba\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33";
c.inLen = XSTRLEN(c.input);
c.outLen = SHA3_224_DIGEST_SIZE;
c.outLen = WC_SHA3_224_DIGEST_SIZE;
test_sha[0] = a;
test_sha[1] = b;
@ -2223,9 +2223,9 @@ static int sha3_224_test(void)
if (ret != 0)
ERROR_OUT(-2030 - i, exit);
if (XMEMCMP(hash, test_sha[i].output, SHA3_224_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0)
ERROR_OUT(-2040 - i, exit);
if (XMEMCMP(hash, hashcopy, SHA3_224_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0)
ERROR_OUT(-2050 - i, exit);
}
@ -2248,7 +2248,7 @@ static int sha3_224_test(void)
ret = wc_Sha3_224_Final(&sha, hash);
if (ret != 0)
ERROR_OUT(-2061, exit);
if (XMEMCMP(hash, large_digest, SHA3_224_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0)
ERROR_OUT(-2062, exit);
} /* END LARGE HASH TEST */
@ -2262,9 +2262,9 @@ exit:
#ifndef WOLFSSL_NOSHA3_256
static int sha3_256_test(void)
{
Sha3 sha;
byte hash[SHA3_256_DIGEST_SIZE];
byte hashcopy[SHA3_256_DIGEST_SIZE];
wc_Sha3 sha;
byte hash[WC_SHA3_256_DIGEST_SIZE];
byte hashcopy[WC_SHA3_256_DIGEST_SIZE];
testVector a, b, c;
testVector test_sha[3];
@ -2276,21 +2276,21 @@ static int sha3_256_test(void)
"\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8"
"\x43\x4a";
a.inLen = XSTRLEN(a.input);
a.outLen = SHA3_256_DIGEST_SIZE;
a.outLen = WC_SHA3_256_DIGEST_SIZE;
b.input = "abc";
b.output = "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90"
"\xbd\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43"
"\x15\x32";
b.inLen = XSTRLEN(b.input);
b.outLen = SHA3_256_DIGEST_SIZE;
b.outLen = WC_SHA3_256_DIGEST_SIZE;
c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
c.output = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e"
"\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d"
"\x33\x76";
c.inLen = XSTRLEN(c.input);
c.outLen = SHA3_256_DIGEST_SIZE;
c.outLen = WC_SHA3_256_DIGEST_SIZE;
test_sha[0] = a;
test_sha[1] = b;
@ -2312,9 +2312,9 @@ static int sha3_256_test(void)
if (ret != 0)
ERROR_OUT(-2130 - i, exit);
if (XMEMCMP(hash, test_sha[i].output, SHA3_256_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0)
ERROR_OUT(-2140 - i, exit);
if (XMEMCMP(hash, hashcopy, SHA3_256_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0)
ERROR_OUT(-2150 - i, exit);
}
@ -2337,7 +2337,7 @@ static int sha3_256_test(void)
ret = wc_Sha3_256_Final(&sha, hash);
if (ret != 0)
ERROR_OUT(-2161, exit);
if (XMEMCMP(hash, large_digest, SHA3_256_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0)
ERROR_OUT(-2162, exit);
} /* END LARGE HASH TEST */
@ -2351,9 +2351,9 @@ exit:
#ifndef WOLFSSL_NOSHA3_384
static int sha3_384_test(void)
{
Sha3 sha;
byte hash[SHA3_384_DIGEST_SIZE];
byte hashcopy[SHA3_384_DIGEST_SIZE];
wc_Sha3 sha;
byte hash[WC_SHA3_384_DIGEST_SIZE];
byte hashcopy[WC_SHA3_384_DIGEST_SIZE];
testVector a, b, c;
testVector test_sha[3];
@ -2366,7 +2366,7 @@ static int sha3_384_test(void)
"\x3a\x2a\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58"
"\xd5\xf0\x04";
a.inLen = XSTRLEN(a.input);
a.outLen = SHA3_384_DIGEST_SIZE;
a.outLen = WC_SHA3_384_DIGEST_SIZE;
b.input = "abc";
b.output = "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad"
@ -2374,7 +2374,7 @@ static int sha3_384_test(void)
"\xe4\xb2\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28"
"\x37\x6d\x25";
b.inLen = XSTRLEN(b.input);
b.outLen = SHA3_384_DIGEST_SIZE;
b.outLen = WC_SHA3_384_DIGEST_SIZE;
c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
c.output = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49"
@ -2382,7 +2382,7 @@ static int sha3_384_test(void)
"\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0"
"\x65\x7c\x22";
c.inLen = XSTRLEN(c.input);
c.outLen = SHA3_384_DIGEST_SIZE;
c.outLen = WC_SHA3_384_DIGEST_SIZE;
test_sha[0] = a;
test_sha[1] = b;
@ -2404,9 +2404,9 @@ static int sha3_384_test(void)
if (ret != 0)
ERROR_OUT(-2230 - i, exit);
if (XMEMCMP(hash, test_sha[i].output, SHA3_384_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0)
ERROR_OUT(-2240 - i, exit);
if (XMEMCMP(hash, hashcopy, SHA3_384_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0)
ERROR_OUT(-2250 - i, exit);
}
@ -2430,7 +2430,7 @@ static int sha3_384_test(void)
ret = wc_Sha3_384_Final(&sha, hash);
if (ret != 0)
ERROR_OUT(-2261, exit);
if (XMEMCMP(hash, large_digest, SHA3_384_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0)
ERROR_OUT(-2262, exit);
} /* END LARGE HASH TEST */
@ -2444,9 +2444,9 @@ exit:
#ifndef WOLFSSL_NOSHA3_512
static int sha3_512_test(void)
{
Sha3 sha;
byte hash[SHA3_512_DIGEST_SIZE];
byte hashcopy[SHA3_512_DIGEST_SIZE];
wc_Sha3 sha;
byte hash[WC_SHA3_512_DIGEST_SIZE];
byte hashcopy[WC_SHA3_512_DIGEST_SIZE];
testVector a, b, c;
testVector test_sha[3];
@ -2460,7 +2460,7 @@ static int sha3_512_test(void)
"\x3a\xc5\x58\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86"
"\x28\x1d\xcd\x26";
a.inLen = XSTRLEN(a.input);
a.outLen = SHA3_512_DIGEST_SIZE;
a.outLen = WC_SHA3_512_DIGEST_SIZE;
b.input = "abc";
b.output = "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09"
@ -2469,7 +2469,7 @@ static int sha3_512_test(void)
"\xe3\x93\x40\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27"
"\x4e\xec\x53\xf0";
b.inLen = XSTRLEN(b.input);
b.outLen = SHA3_512_DIGEST_SIZE;
b.outLen = WC_SHA3_512_DIGEST_SIZE;
c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
c.output = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8"
@ -2478,7 +2478,7 @@ static int sha3_512_test(void)
"\x8c\x08\x63\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11"
"\x39\xd6\xe7\x5e";
c.inLen = XSTRLEN(c.input);
c.outLen = SHA3_512_DIGEST_SIZE;
c.outLen = WC_SHA3_512_DIGEST_SIZE;
test_sha[0] = a;
test_sha[1] = b;
@ -2500,9 +2500,9 @@ static int sha3_512_test(void)
if (ret != 0)
ERROR_OUT(-2330 - i, exit);
if (XMEMCMP(hash, test_sha[i].output, SHA3_512_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0)
ERROR_OUT(-2340 - i, exit);
if (XMEMCMP(hash, hashcopy, SHA3_512_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0)
ERROR_OUT(-2350 - i, exit);
}
@ -2527,7 +2527,7 @@ static int sha3_512_test(void)
ret = wc_Sha3_512_Final(&sha, hash);
if (ret != 0)
ERROR_OUT(-2361, exit);
if (XMEMCMP(hash, large_digest, SHA3_512_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0)
ERROR_OUT(-2362, exit);
} /* END LARGE HASH TEST */
@ -3342,7 +3342,7 @@ int hmac_sha512_test(void)
int hmac_sha3_test(void)
{
Hmac hmac;
byte hash[SHA3_512_DIGEST_SIZE];
byte hash[WC_SHA3_512_DIGEST_SIZE];
const char* key[3] =
{
@ -3375,8 +3375,8 @@ int hmac_sha3_test(void)
const int hashSz[4] =
{
SHA3_224_DIGEST_SIZE, SHA3_256_DIGEST_SIZE,
SHA3_384_DIGEST_SIZE, SHA3_512_DIGEST_SIZE
WC_SHA3_224_DIGEST_SIZE, WC_SHA3_256_DIGEST_SIZE,
WC_SHA3_384_DIGEST_SIZE, WC_SHA3_512_DIGEST_SIZE
};
const char* output[12] =

View File

@ -46,7 +46,7 @@
/* in bytes, variable digest size up to 512 bits (64 bytes) */
enum {
BLAKE2B_ID = 7, /* hash type unique */
BLAKE2B_ID = WC_HASH_TYPE_BLAKE2B,
BLAKE2B_256 = 32 /* 256 bit type, SSL default */
};

View File

@ -46,6 +46,13 @@
#ifdef WOLFSSL_SHA3
#include <wolfssl/wolfcrypt/sha3.h>
#endif
#ifndef NO_MD4
#include <wolfssl/wolfcrypt/md4.h>
#endif
#ifdef WOLFSSL_MD2
#include <wolfssl/wolfcrypt/md2.h>
#endif
#ifdef __cplusplus
extern "C" {
@ -56,20 +63,6 @@
#endif
/* Hash types */
enum wc_HashType {
WC_HASH_TYPE_NONE = 0,
WC_HASH_TYPE_MD2 = 1,
WC_HASH_TYPE_MD4 = 2,
WC_HASH_TYPE_MD5 = 3,
WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
WC_HASH_TYPE_SHA224 = 9,
WC_HASH_TYPE_SHA256 = 5,
WC_HASH_TYPE_SHA384 = 6,
WC_HASH_TYPE_SHA512 = 7,
WC_HASH_TYPE_MD5_SHA = 8,
};
typedef union {
#ifndef NO_MD5
wc_Md5 md5;

View File

@ -58,31 +58,31 @@ enum {
/* If any hash is not enabled, add the ID here. */
#ifdef NO_MD5
WC_MD5 = 0,
WC_MD5 = WC_HASH_TYPE_MD5+,
#endif
#ifdef NO_SHA
WC_SHA = 1,
WC_SHA = WC_HASH_TYPE_SHA,
#endif
#ifdef NO_SHA256
WC_SHA256 = 2,
WC_SHA256 = WC_HASH_TYPE_SHA256,
#endif
#ifndef WOLFSSL_SHA512
WC_SHA512 = 4,
WC_SHA512 = WC_HASH_TYPE_SHA512,
#endif
#ifndef WOLFSSL_SHA384
WC_SHA384 = 5,
WC_SHA384 = WC_HASH_TYPE_SHA384,
#endif
#ifndef HAVE_BLAKE2
BLAKE2B_ID = 7,
BLAKE2B_ID = WC_HASH_TYPE_BLAKE2B,
#endif
#ifndef WOLFSSL_SHA224
WC_SHA224 = 8,
WC_SHA224 = WC_HASH_TYPE_SHA224,
#endif
#ifndef WOLFSSL_SHA3
WC_SHA3_224 = 10,
WC_SHA3_256 = 11,
WC_SHA3_384 = 12,
WC_SHA3_512 = 13,
WC_SHA3_224 = WC_HASH_TYPE_SHA3_224,
WC_SHA3_256 = WC_HASH_TYPE_SHA3_256,
WC_SHA3_384 = WC_HASH_TYPE_SHA3_384,
WC_SHA3_512 = WC_HASH_TYPE_SHA3_512,
#endif
};
@ -120,7 +120,7 @@ typedef union {
Blake2b blake2b;
#endif
#ifdef WOLFSSL_SHA3
Sha3 sha3;
wc_Sha3 sha3;
#endif
} Hash;

View File

@ -37,7 +37,7 @@
/* in bytes */
enum {
MD2 = 6, /* hash type unique */
MD2 = WC_HASH_TYPE_MD2,
MD2_BLOCK_SIZE = 16,
MD2_DIGEST_SIZE = 16,
MD2_PAD_SIZE = 16,

View File

@ -36,7 +36,7 @@
/* in bytes */
enum {
MD4 = 9, /* hash type unique */
MD4 = WC_HASH_TYPE_MD4,
MD4_BLOCK_SIZE = 64,
MD4_DIGEST_SIZE = 16,
MD4_PAD_SIZE = 56

View File

@ -52,12 +52,13 @@
/* in bytes */
enum {
WC_MD5 = 0, /* hash type unique */
WC_MD5 = WC_HASH_TYPE_MD5,
WC_MD5_BLOCK_SIZE = 64,
WC_MD5_DIGEST_SIZE = 16,
WC_MD5_PAD_SIZE = 56
};
#ifdef WOLFSSL_MICROCHIP_PIC32MZ
#include <wolfssl/wolfcrypt/port/pic32/pic32mz-crypt.h>
#endif

View File

@ -34,7 +34,7 @@
typedef struct Sha3 {
XSecure_Sha3 hw;
XCsuDma dma;
} Sha3;
} wc_Sha3;
#ifdef __cplusplus
} /* extern "C" */

View File

@ -72,7 +72,7 @@
/* in bytes */
enum {
WC_SHA = 1, /* hash type unique */
WC_SHA = WC_HASH_TYPE_SHA,
WC_SHA_BLOCK_SIZE = 64,
WC_SHA_DIGEST_SIZE = 20,
WC_SHA_PAD_SIZE = 56

View File

@ -93,12 +93,13 @@
/* in bytes */
enum {
WC_SHA256 = 2, /* hash type unique */
WC_SHA256 = WC_HASH_TYPE_SHA256,
WC_SHA256_BLOCK_SIZE = 64,
WC_SHA256_DIGEST_SIZE = 32,
WC_SHA256_PAD_SIZE = 56
};
#ifdef WOLFSSL_TI_HASH
#include "wolfssl/wolfcrypt/port/ti/ti-hash.h"
#elif defined(WOLFSSL_IMX6_CAAM)
@ -160,12 +161,13 @@ WOLFSSL_API void wc_Sha256SizeSet(wc_Sha256*, word32);
/* in bytes */
enum {
WC_SHA224 = 8, /* hash type unique */
WC_SHA224 = WC_HASH_TYPE_SHA224,
WC_SHA224_BLOCK_SIZE = WC_SHA256_BLOCK_SIZE,
WC_SHA224_DIGEST_SIZE = 28,
WC_SHA224_PAD_SIZE = WC_SHA256_PAD_SIZE
};
typedef wc_Sha256 wc_Sha224;
#endif /* HAVE_FIPS */

View File

@ -44,21 +44,21 @@
/* in bytes */
enum {
SHA3_224 = 10, /* hash type unique */
SHA3_224_DIGEST_SIZE = 28,
SHA3_224_COUNT = 18,
WC_SHA3_224 = WC_HASH_TYPE_SHA3_224,
WC_SHA3_224_DIGEST_SIZE = 28,
WC_SHA3_224_COUNT = 18,
SHA3_256 = 11, /* hash type unique */
SHA3_256_DIGEST_SIZE = 32,
SHA3_256_COUNT = 17,
WC_SHA3_256 = WC_HASH_TYPE_SHA3_256,
WC_SHA3_256_DIGEST_SIZE = 32,
WC_SHA3_256_COUNT = 17,
SHA3_384 = 12, /* hash type unique */
SHA3_384_DIGEST_SIZE = 48,
SHA3_384_COUNT = 13,
WC_SHA3_384 = WC_HASH_TYPE_SHA3_384,
WC_SHA3_384_DIGEST_SIZE = 48,
WC_SHA3_384_COUNT = 13,
SHA3_512 = 13, /* hash type unique */
SHA3_512_DIGEST_SIZE = 64,
SHA3_512_COUNT = 9,
WC_SHA3_512 = WC_HASH_TYPE_SHA3_512,
WC_SHA3_512_DIGEST_SIZE = 64,
WC_SHA3_512_COUNT = 9,
/* These values are used for HMAC, not SHA-3 directly.
* They come from from FIPS PUB 202. */
@ -68,14 +68,17 @@ enum {
WC_SHA3_512_BLOCK_SIZE = 72,
};
#define WC_SHA3_224 SHA3_224
#define WC_SHA3_224_DIGEST_SIZE SHA3_224_DIGEST_SIZE
#define WC_SHA3_256 SHA3_256
#define WC_SHA3_256_DIGEST_SIZE SHA3_256_DIGEST_SIZE
#define WC_SHA3_384 SHA3_384
#define WC_SHA3_384_DIGEST_SIZE SHA3_384_DIGEST_SIZE
#define WC_SHA3_512 SHA3_512
#define WC_SHA3_512_DIGEST_SIZE SHA3_512_DIGEST_SIZE
#ifndef NO_OLD_WC_NAMES
#define SHA3_224 WC_SHA3_224
#define SHA3_224_DIGEST_SIZE WC_SHA3_224_DIGEST_SIZE
#define SHA3_256 WC_SHA3_256
#define SHA3_256_DIGEST_SIZE WC_SHA3_256_DIGEST_SIZE
#define SHA3_384 WC_SHA3_384
#define SHA3_384_DIGEST_SIZE WC_SHA3_384_DIGEST_SIZE
#define SHA3_512 WC_SHA3_512
#define SHA3_512_DIGEST_SIZE WC_SHA3_512_DIGEST_SIZE
#define Sha3 wc_Sha3
#endif
#ifdef WOLFSSL_XILINX_CRYPT
@ -95,37 +98,37 @@ typedef struct Sha3 {
#ifdef WOLFSSL_ASYNC_CRYPT
WC_ASYNC_DEV asyncDev;
#endif /* WOLFSSL_ASYNC_CRYPT */
} Sha3;
} wc_Sha3;
#endif
#endif /* HAVE_FIPS */
WOLFSSL_API int wc_InitSha3_224(Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_224_Update(Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_224_Final(Sha3*, byte*);
WOLFSSL_API void wc_Sha3_224_Free(Sha3*);
WOLFSSL_API int wc_Sha3_224_GetHash(Sha3*, byte*);
WOLFSSL_API int wc_Sha3_224_Copy(Sha3* src, Sha3* dst);
WOLFSSL_API int wc_InitSha3_224(wc_Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_224_Update(wc_Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_224_Final(wc_Sha3*, byte*);
WOLFSSL_API void wc_Sha3_224_Free(wc_Sha3*);
WOLFSSL_API int wc_Sha3_224_GetHash(wc_Sha3*, byte*);
WOLFSSL_API int wc_Sha3_224_Copy(wc_Sha3* src, wc_Sha3* dst);
WOLFSSL_API int wc_InitSha3_256(Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_256_Update(Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_256_Final(Sha3*, byte*);
WOLFSSL_API void wc_Sha3_256_Free(Sha3*);
WOLFSSL_API int wc_Sha3_256_GetHash(Sha3*, byte*);
WOLFSSL_API int wc_Sha3_256_Copy(Sha3* src, Sha3* dst);
WOLFSSL_API int wc_InitSha3_256(wc_Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_256_Update(wc_Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_256_Final(wc_Sha3*, byte*);
WOLFSSL_API void wc_Sha3_256_Free(wc_Sha3*);
WOLFSSL_API int wc_Sha3_256_GetHash(wc_Sha3*, byte*);
WOLFSSL_API int wc_Sha3_256_Copy(wc_Sha3* src, wc_Sha3* dst);
WOLFSSL_API int wc_InitSha3_384(Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_384_Update(Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_384_Final(Sha3*, byte*);
WOLFSSL_API void wc_Sha3_384_Free(Sha3*);
WOLFSSL_API int wc_Sha3_384_GetHash(Sha3*, byte*);
WOLFSSL_API int wc_Sha3_384_Copy(Sha3* src, Sha3* dst);
WOLFSSL_API int wc_InitSha3_384(wc_Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_384_Update(wc_Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_384_Final(wc_Sha3*, byte*);
WOLFSSL_API void wc_Sha3_384_Free(wc_Sha3*);
WOLFSSL_API int wc_Sha3_384_GetHash(wc_Sha3*, byte*);
WOLFSSL_API int wc_Sha3_384_Copy(wc_Sha3* src, wc_Sha3* dst);
WOLFSSL_API int wc_InitSha3_512(Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_512_Update(Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_512_Final(Sha3*, byte*);
WOLFSSL_API void wc_Sha3_512_Free(Sha3*);
WOLFSSL_API int wc_Sha3_512_GetHash(Sha3*, byte*);
WOLFSSL_API int wc_Sha3_512_Copy(Sha3* src, Sha3* dst);
WOLFSSL_API int wc_InitSha3_512(wc_Sha3*, void*, int);
WOLFSSL_API int wc_Sha3_512_Update(wc_Sha3*, const byte*, word32);
WOLFSSL_API int wc_Sha3_512_Final(wc_Sha3*, byte*);
WOLFSSL_API void wc_Sha3_512_Free(wc_Sha3*);
WOLFSSL_API int wc_Sha3_512_GetHash(wc_Sha3*, byte*);
WOLFSSL_API int wc_Sha3_512_Copy(wc_Sha3* src, wc_Sha3* dst);
#ifdef __cplusplus
} /* extern "C" */

View File

@ -81,7 +81,7 @@
/* in bytes */
enum {
WC_SHA512 = 4, /* hash type unique */
WC_SHA512 = WC_HASH_TYPE_SHA512,
WC_SHA512_BLOCK_SIZE = 128,
WC_SHA512_DIGEST_SIZE = 64,
WC_SHA512_PAD_SIZE = 112
@ -133,12 +133,13 @@ WOLFSSL_API int wc_Sha512Copy(wc_Sha512* src, wc_Sha512* dst);
/* in bytes */
enum {
WC_SHA384 = 5, /* hash type unique */
WC_SHA384 = WC_HASH_TYPE_SHA384,
WC_SHA384_BLOCK_SIZE = WC_SHA512_BLOCK_SIZE,
WC_SHA384_DIGEST_SIZE = 48,
WC_SHA384_PAD_SIZE = WC_SHA512_PAD_SIZE
};
typedef wc_Sha512 wc_Sha384;
#endif /* HAVE_FIPS */

View File

@ -483,7 +483,24 @@
MIN_STACK_BUFFER = 8
};
/* hash types */
enum wc_HashType {
WC_HASH_TYPE_NONE = 0,
WC_HASH_TYPE_MD2 = 1,
WC_HASH_TYPE_MD4 = 2,
WC_HASH_TYPE_MD5 = 3,
WC_HASH_TYPE_SHA = 4, /* SHA-1 (not old SHA-0) */
WC_HASH_TYPE_SHA224 = 5,
WC_HASH_TYPE_SHA256 = 6,
WC_HASH_TYPE_SHA384 = 7,
WC_HASH_TYPE_SHA512 = 8,
WC_HASH_TYPE_MD5_SHA = 9,
WC_HASH_TYPE_SHA3_224 = 10,
WC_HASH_TYPE_SHA3_256 = 11,
WC_HASH_TYPE_SHA3_384 = 12,
WC_HASH_TYPE_SHA3_512 = 13,
WC_HASH_TYPE_BLAKE2B = 14,
};
/* settings detection for compile vs runtime math incompatibilities */
enum {