mirror of https://github.com/wolfSSL/wolfssl.git
commit
f922d3f2d6
26
configure.ac
26
configure.ac
|
@ -1525,6 +1525,31 @@ fi
|
|||
AM_CONDITIONAL([BUILD_FIPS], [test "x$ENABLED_FIPS" = "xyes"])
|
||||
|
||||
|
||||
# set sha224 default
|
||||
SHA224_DEFAULT=no
|
||||
if test "$host_cpu" = "x86_64"
|
||||
then
|
||||
if test "x$ENABLED_FIPS" = "xno"
|
||||
then
|
||||
SHA224_DEFAULT=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
# SHA224
|
||||
AC_ARG_ENABLE([sha224],
|
||||
[AS_HELP_STRING([--enable-sha224],[Enable wolfSSL SHA-224 support (default: enabled on x86_64)])],
|
||||
[ ENABLED_SHA224=$enableval ],
|
||||
[ ENABLED_SHA224=$SHA224_DEFAULT ]
|
||||
)
|
||||
|
||||
if test "$ENABLED_SHA224" = "yes"
|
||||
then
|
||||
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA224"
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL([BUILD_SHA224], [test "x$ENABLED_SHA224" = "xyes"])
|
||||
|
||||
|
||||
# set POLY1305 default
|
||||
POLY1305_DEFAULT=yes
|
||||
|
||||
|
@ -3220,6 +3245,7 @@ echo " * NULL Cipher: $ENABLED_NULL_CIPHER"
|
|||
echo " * MD5: $ENABLED_MD5"
|
||||
echo " * RIPEMD: $ENABLED_RIPEMD"
|
||||
echo " * SHA: $ENABLED_SHA"
|
||||
echo " * SHA-224: $ENABLED_SHA224"
|
||||
echo " * SHA-512: $ENABLED_SHA512"
|
||||
echo " * BLAKE2: $ENABLED_BLAKE2"
|
||||
echo " * CMAC: $ENABLED_CMAC"
|
||||
|
|
|
@ -35,6 +35,13 @@
|
|||
#define Sha256Final wc_Sha256Final
|
||||
#define Sha256Hash wc_Sha256Hash
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
#define InitSha224 wc_InitSha224
|
||||
#define Sha224Update wc_Sha224Update
|
||||
#define Sha224Final wc_Sha224Final
|
||||
#define Sha224Hash wc_Sha224Hash
|
||||
#endif
|
||||
|
||||
#endif /* CTAO_CRYPT_SHA256_H */
|
||||
#endif /* NO_SHA256 */
|
||||
|
||||
|
|
69
src/ssl.c
69
src/ssl.c
|
@ -699,6 +699,9 @@ int wolfSSL_GetObjectSize(void)
|
|||
#ifndef NO_SHA
|
||||
printf(" sizeof SHA = %lu\n", sizeof(Sha));
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
printf(" sizeof SHA224 = %lu\n", sizeof(Sha224));
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
printf(" sizeof SHA256 = %lu\n", sizeof(Sha256));
|
||||
#endif
|
||||
|
@ -9652,6 +9655,36 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||
}
|
||||
#endif /* NO_SHA */
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
|
||||
void wolfSSL_SHA224_Init(WOLFSSL_SHA224_CTX* sha)
|
||||
{
|
||||
typedef char sha_test[sizeof(SHA224_CTX) >= sizeof(Sha224) ? 1 : -1];
|
||||
(void)sizeof(sha_test);
|
||||
|
||||
WOLFSSL_ENTER("SHA224_Init");
|
||||
wc_InitSha224((Sha224*)sha); /* OpenSSL compat, no error */
|
||||
}
|
||||
|
||||
|
||||
void wolfSSL_SHA224_Update(WOLFSSL_SHA224_CTX* sha, const void* input,
|
||||
unsigned long sz)
|
||||
{
|
||||
WOLFSSL_ENTER("SHA224_Update");
|
||||
wc_Sha224Update((Sha224*)sha, (const byte*)input, (word32)sz);
|
||||
/* OpenSSL compat, no error */
|
||||
}
|
||||
|
||||
|
||||
void wolfSSL_SHA224_Final(byte* input, WOLFSSL_SHA224_CTX* sha)
|
||||
{
|
||||
WOLFSSL_ENTER("SHA224_Final");
|
||||
wc_Sha224Final((Sha224*)sha, input);
|
||||
/* OpenSSL compat, no error */
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
|
||||
void wolfSSL_SHA256_Init(WOLFSSL_SHA256_CTX* sha256)
|
||||
{
|
||||
|
@ -9763,6 +9796,17 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||
}
|
||||
#endif /* NO_SHA */
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
|
||||
const WOLFSSL_EVP_MD* wolfSSL_EVP_sha224(void)
|
||||
{
|
||||
static const char* type = "SHA224";
|
||||
WOLFSSL_ENTER("EVP_sha224");
|
||||
return type;
|
||||
}
|
||||
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
|
||||
const WOLFSSL_EVP_MD* wolfSSL_EVP_sha256(void)
|
||||
{
|
||||
|
@ -10402,6 +10446,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||
ctx->macType = SHA256;
|
||||
wolfSSL_SHA256_Init((SHA256_CTX*)&ctx->hash);
|
||||
}
|
||||
#ifdef WOLFSSL_SHA224
|
||||
else if (XSTRNCMP(type, "SHA224", 6) == 0) {
|
||||
ctx->macType = SHA224;
|
||||
wolfSSL_SHA224_Init((SHA224_CTX*)&ctx->hash);
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA384
|
||||
else if (XSTRNCMP(type, "SHA384", 6) == 0) {
|
||||
ctx->macType = SHA384;
|
||||
|
@ -10421,7 +10471,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||
}
|
||||
#endif
|
||||
#ifndef NO_SHA
|
||||
/* has to be last since would pick or 256, 384, or 512 too */
|
||||
/* has to be last since would pick or 224, 256, 384, or 512 too */
|
||||
else if (XSTRNCMP(type, "SHA", 3) == 0) {
|
||||
ctx->macType = SHA;
|
||||
wolfSSL_SHA_Init((SHA_CTX*)&ctx->hash);
|
||||
|
@ -10453,6 +10503,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||
(unsigned long)sz);
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
wolfSSL_SHA224_Update((SHA224_CTX*)&ctx->hash, data,
|
||||
(unsigned long)sz);
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
wolfSSL_SHA256_Update((SHA256_CTX*)&ctx->hash, data,
|
||||
|
@ -10497,6 +10553,12 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||
if (s) *s = SHA_DIGEST_SIZE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
wolfSSL_SHA224_Final(md, (SHA224_CTX*)&ctx->hash);
|
||||
if (s) *s = SHA224_DIGEST_SIZE;
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
wolfSSL_SHA256_Final(md, (SHA256_CTX*)&ctx->hash);
|
||||
|
@ -16073,6 +16135,11 @@ int wolfSSL_EVP_MD_size(const WOLFSSL_EVP_MD* type)
|
|||
return MD5_DIGEST_SIZE;
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
else if (XSTRNCMP(type, "SHA224", 6) == 0) {
|
||||
return SHA224_DIGEST_SIZE;
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA384
|
||||
else if (XSTRNCMP(type, "SHA384", 6) == 0) {
|
||||
return SHA384_DIGEST_SIZE;
|
||||
|
|
187
tests/hash.c
187
tests/hash.c
|
@ -40,7 +40,7 @@
|
|||
|
||||
typedef struct testVector {
|
||||
const char* input;
|
||||
const char* output;
|
||||
const char* output;
|
||||
size_t inLen;
|
||||
size_t outLen;
|
||||
} testVector;
|
||||
|
@ -48,12 +48,14 @@ typedef struct testVector {
|
|||
int md4_test(void);
|
||||
int md5_test(void);
|
||||
int sha_test(void);
|
||||
int sha224_test(void);
|
||||
int sha256_test(void);
|
||||
int sha512_test(void);
|
||||
int sha384_test(void);
|
||||
int ripemd_test(void);
|
||||
int hmac_md5_test(void);
|
||||
int hmac_sha_test(void);
|
||||
int hmac_sha224_test(void);
|
||||
int hmac_sha256_test(void);
|
||||
int hmac_sha384_test(void);
|
||||
|
||||
|
@ -66,7 +68,7 @@ int HashTest(void)
|
|||
#ifndef NO_MD4
|
||||
if ( (ret = md4_test()) ) {
|
||||
printf( " MD4 test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " MD4 test passed!\n");
|
||||
#endif
|
||||
|
@ -74,23 +76,31 @@ int HashTest(void)
|
|||
#ifndef NO_MD5
|
||||
if ( (ret = md5_test()) ) {
|
||||
printf( " MD5 test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " MD5 test passed!\n");
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_SHA
|
||||
if ( (ret = sha_test()) ) {
|
||||
printf( " SHA test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " SHA test passed!\n");
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
if ( (ret = sha224_test()) ) {
|
||||
printf( " SHA-224 test failed!\n");
|
||||
return ret;
|
||||
} else
|
||||
printf( " SHA-224 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
if ( (ret = sha256_test()) ) {
|
||||
printf( " SHA-256 test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " SHA-256 test passed!\n");
|
||||
#endif
|
||||
|
@ -98,7 +108,7 @@ int HashTest(void)
|
|||
#ifdef WOLFSSL_SHA512
|
||||
if ( (ret = sha512_test()) ) {
|
||||
printf( " SHA-512 test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " SHA-512 test passed!\n");
|
||||
#endif
|
||||
|
@ -106,7 +116,7 @@ int HashTest(void)
|
|||
#ifdef WOLFSSL_SHA384
|
||||
if ( (ret = sha384_test()) ) {
|
||||
printf( " SHA-384 test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " SHA-384 test passed!\n");
|
||||
#endif
|
||||
|
@ -114,7 +124,7 @@ int HashTest(void)
|
|||
#ifdef WOLFSSL_RIPEMD
|
||||
if ( (ret = ripemd_test()) ) {
|
||||
printf( " RIPEMD test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " RIPEMD test passed!\n");
|
||||
#endif
|
||||
|
@ -123,27 +133,34 @@ int HashTest(void)
|
|||
#ifndef NO_MD5
|
||||
if ( (ret = hmac_md5_test()) ) {
|
||||
printf( " HMAC-MD5 test failed!\n");
|
||||
return ret;
|
||||
return ret;
|
||||
} else
|
||||
printf( " HMAC-MD5 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA
|
||||
if ( (ret = hmac_sha_test()) )
|
||||
if ( (ret = hmac_sha_test()) )
|
||||
printf( " HMAC-SHA test failed!\n");
|
||||
else
|
||||
printf( " HMAC-SHA test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
if ( (ret = hmac_sha224_test()) )
|
||||
printf( " HMAC-SHA224 test failed!\n");
|
||||
else
|
||||
printf( " HMAC-SHA224 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
if ( (ret = hmac_sha256_test()) )
|
||||
if ( (ret = hmac_sha256_test()) )
|
||||
printf( " HMAC-SHA256 test failed!\n");
|
||||
else
|
||||
printf( " HMAC-SHA256 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA384
|
||||
if ( (ret = hmac_sha384_test()) )
|
||||
if ( (ret = hmac_sha384_test()) )
|
||||
printf( " HMAC-SHA384 test failed!\n");
|
||||
else
|
||||
printf( " HMAC-SHA384 test passed!\n");
|
||||
|
@ -151,7 +168,7 @@ int HashTest(void)
|
|||
#endif
|
||||
|
||||
printf(" End HASH Tests\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -167,45 +184,45 @@ int md4_test(void)
|
|||
int times = sizeof(test_md4) / sizeof(testVector), i;
|
||||
|
||||
a.input = "";
|
||||
a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
|
||||
a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
|
||||
"\xc0";
|
||||
a.inLen = XSTRLEN(a.input);
|
||||
a.outLen = XSTRLEN(a.output);
|
||||
|
||||
b.input = "a";
|
||||
b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
|
||||
b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
|
||||
"\x24";
|
||||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = XSTRLEN(b.output);
|
||||
|
||||
c.input = "abc";
|
||||
c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
|
||||
c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
|
||||
"\x9d";
|
||||
c.inLen = XSTRLEN(c.input);
|
||||
c.outLen = XSTRLEN(c.output);
|
||||
|
||||
d.input = "message digest";
|
||||
d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
|
||||
d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
|
||||
"\x4b";
|
||||
d.inLen = XSTRLEN(d.input);
|
||||
d.outLen = XSTRLEN(d.output);
|
||||
|
||||
e.input = "abcdefghijklmnopqrstuvwxyz";
|
||||
e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
|
||||
e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
|
||||
"\xa9";
|
||||
e.inLen = XSTRLEN(e.input);
|
||||
e.outLen = XSTRLEN(e.output);
|
||||
|
||||
f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
|
||||
"6789";
|
||||
f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
|
||||
f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
|
||||
"\xe4";
|
||||
f.inLen = XSTRLEN(f.input);
|
||||
f.outLen = XSTRLEN(f.output);
|
||||
|
||||
g.input = "1234567890123456789012345678901234567890123456789012345678"
|
||||
"9012345678901234567890";
|
||||
g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
|
||||
g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
|
||||
"\x36";
|
||||
g.inLen = XSTRLEN(g.input);
|
||||
g.outLen = XSTRLEN(g.output);
|
||||
|
@ -356,6 +373,52 @@ int sha_test(void)
|
|||
}
|
||||
#endif /* NO_SHA */
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
int sha224_test(void)
|
||||
{
|
||||
Sha224 sha;
|
||||
byte hash[SHA224_DIGEST_SIZE];
|
||||
|
||||
testVector a, b;
|
||||
testVector test_sha[2];
|
||||
int ret;
|
||||
int times = sizeof(test_sha) / sizeof(struct testVector), i;
|
||||
|
||||
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 = SHA224_DIGEST_SIZE;
|
||||
|
||||
b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
b.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
|
||||
"\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
|
||||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
test_sha[0] = a;
|
||||
test_sha[1] = b;
|
||||
|
||||
ret = wc_InitSha224(&sha);
|
||||
if (ret != 0)
|
||||
return -4005;
|
||||
|
||||
for (i = 0; i < times; ++i) {
|
||||
ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
ret = wc_Sha224Final(&sha, hash);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (XMEMCMP(hash, test_sha[i].output, SHA224_DIGEST_SIZE) != 0)
|
||||
return -10 - i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
int sha256_test(void)
|
||||
{
|
||||
|
@ -431,7 +494,7 @@ int sha512_test(void)
|
|||
"\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
|
||||
"\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
|
||||
"\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
|
||||
"\x87\x4b\xe9\x09";
|
||||
"\x87\x4b\xe9\x09";
|
||||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = XSTRLEN(b.output);
|
||||
|
||||
|
@ -533,7 +596,7 @@ int ripemd_test(void)
|
|||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = XSTRLEN(b.output);
|
||||
|
||||
c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
|
||||
"\xf4\x9a\xda\x62\xeb\x2b";
|
||||
c.inLen = XSTRLEN(c.input);
|
||||
|
@ -542,7 +605,7 @@ int ripemd_test(void)
|
|||
d.input = "12345678901234567890123456789012345678901234567890123456"
|
||||
"789012345678901234567890";
|
||||
d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
|
||||
"\x82\xbf\x63\x32\x6b\xfb";
|
||||
"\x82\xbf\x63\x32\x6b\xfb";
|
||||
d.inLen = XSTRLEN(d.input);
|
||||
d.outLen = XSTRLEN(d.output);
|
||||
|
||||
|
@ -704,6 +767,80 @@ int hmac_sha_test(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
|
||||
int hmac_sha224_test(void)
|
||||
{
|
||||
Hmac hmac;
|
||||
byte hash[SHA224_DIGEST_SIZE];
|
||||
|
||||
const char* keys[]=
|
||||
{
|
||||
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
|
||||
"\x0b\x0b\x0b",
|
||||
"Jefe",
|
||||
"\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
|
||||
"\xAA\xAA\xAA"
|
||||
};
|
||||
|
||||
testVector a, b, c;
|
||||
testVector test_hmac[3];
|
||||
|
||||
int ret;
|
||||
int times = sizeof(test_hmac) / sizeof(testVector), i;
|
||||
|
||||
a.input = "Hi There";
|
||||
a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
|
||||
"\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
|
||||
a.inLen = XSTRLEN(a.input);
|
||||
a.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
b.input = "what do ya want for nothing?";
|
||||
b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
|
||||
"\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
|
||||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
|
||||
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
|
||||
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
|
||||
"\xDD\xDD\xDD\xDD\xDD\xDD";
|
||||
c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
|
||||
"\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
|
||||
c.inLen = XSTRLEN(c.input);
|
||||
c.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
test_hmac[0] = a;
|
||||
test_hmac[1] = b;
|
||||
test_hmac[2] = c;
|
||||
|
||||
for (i = 0; i < times; ++i) {
|
||||
#if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
|
||||
if (i == 1)
|
||||
continue; /* cavium can't handle short keys, fips not allowed */
|
||||
#endif
|
||||
ret = wc_HmacSetKey(&hmac, SHA224, (byte*)keys[i],(word32)XSTRLEN(keys[i]));
|
||||
if (ret != 0)
|
||||
return -4021;
|
||||
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
|
||||
(word32)test_hmac[i].inLen);
|
||||
if (ret != 0)
|
||||
return -4022;
|
||||
ret = wc_HmacFinal(&hmac, hash);
|
||||
if (ret != 0)
|
||||
return -4023;
|
||||
|
||||
if (XMEMCMP(hash, test_hmac[i].output, SHA224_DIGEST_SIZE) != 0)
|
||||
return -20 - i;
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
wc_HmacAsyncFree(&hmac);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(NO_HMAC) && !defined(NO_SHA256)
|
||||
int hmac_sha256_test(void)
|
||||
{
|
||||
|
|
|
@ -191,6 +191,7 @@ void bench_camellia(void);
|
|||
|
||||
void bench_md5(void);
|
||||
void bench_sha(void);
|
||||
void bench_sha224(void);
|
||||
void bench_sha256(void);
|
||||
void bench_sha384(void);
|
||||
void bench_sha512(void);
|
||||
|
@ -397,6 +398,9 @@ int benchmark_test(void *args)
|
|||
#ifndef NO_SHA
|
||||
bench_sha();
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
bench_sha224();
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
bench_sha256();
|
||||
#endif
|
||||
|
@ -1163,6 +1167,51 @@ void bench_sha(void)
|
|||
#endif /* NO_SHA */
|
||||
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
void bench_sha224(void)
|
||||
{
|
||||
Sha224 hash;
|
||||
byte digest[SHA224_DIGEST_SIZE];
|
||||
double start, total, persec;
|
||||
int i, ret;
|
||||
|
||||
ret = wc_InitSha224(&hash);
|
||||
if (ret != 0) {
|
||||
printf("InitSha224 failed, ret = %d\n", ret);
|
||||
return;
|
||||
}
|
||||
start = current_time(1);
|
||||
BEGIN_INTEL_CYCLES
|
||||
|
||||
for(i = 0; i < numBlocks; i++) {
|
||||
ret = wc_Sha224Update(&hash, plain, sizeof(plain));
|
||||
if (ret != 0) {
|
||||
printf("Sha224Update failed, ret = %d\n", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ret = wc_Sha224Final(&hash, digest);
|
||||
if (ret != 0) {
|
||||
printf("Sha224Final failed, ret = %d\n", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
END_INTEL_CYCLES
|
||||
total = current_time(0) - start;
|
||||
persec = 1 / total * numBlocks;
|
||||
#ifdef BENCH_EMBEDDED
|
||||
/* since using kB, convert to MB/s */
|
||||
persec = persec / 1024;
|
||||
#endif
|
||||
|
||||
printf("SHA-224 %d %s took %5.3f seconds, %8.3f MB/s", numBlocks,
|
||||
blockType, total, persec);
|
||||
SHOW_INTEL_CYCLES
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
void bench_sha256(void)
|
||||
{
|
||||
|
|
|
@ -750,6 +750,7 @@ static int GetIntRsa(RsaKey* key, mp_int* mpi, const byte* input,
|
|||
static const byte hashMd2hOid[] = {42, 134, 72, 134, 247, 13, 2, 2};
|
||||
static const byte hashMd5hOid[] = {42, 134, 72, 134, 247, 13, 2, 5};
|
||||
static const byte hashSha1hOid[] = {43, 14, 3, 2, 26};
|
||||
static const byte hashSha224hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 4};
|
||||
static const byte hashSha256hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 1};
|
||||
static const byte hashSha384hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 2};
|
||||
static const byte hashSha512hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 3};
|
||||
|
@ -762,12 +763,14 @@ static const byte hashSha512hOid[] = {96, 134, 72, 1, 101, 3, 4, 2, 3};
|
|||
static const byte sigMd2wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1, 2};
|
||||
static const byte sigMd5wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1, 4};
|
||||
static const byte sigSha1wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1, 5};
|
||||
static const byte sigSha224wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,14};
|
||||
static const byte sigSha256wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,11};
|
||||
static const byte sigSha384wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,12};
|
||||
static const byte sigSha512wRsaOid[] = {42, 134, 72, 134, 247, 13, 1, 1,13};
|
||||
#endif /* NO_RSA */
|
||||
#ifdef HAVE_ECC
|
||||
static const byte sigSha1wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 1};
|
||||
static const byte sigSha224wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 1};
|
||||
static const byte sigSha256wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 2};
|
||||
static const byte sigSha384wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 3};
|
||||
static const byte sigSha512wEcdsaOid[] = {42, 134, 72, 206, 61, 4, 3, 4};
|
||||
|
@ -859,6 +862,10 @@ static const byte* OidFromId(word32 id, word32 type, word32* oidSz)
|
|||
oid = hashSha1hOid;
|
||||
*oidSz = sizeof(hashSha1hOid);
|
||||
break;
|
||||
case SHA224h:
|
||||
oid = hashSha224hOid;
|
||||
*oidSz = sizeof(hashSha224hOid);
|
||||
break;
|
||||
case SHA256h:
|
||||
oid = hashSha256hOid;
|
||||
*oidSz = sizeof(hashSha256hOid);
|
||||
|
@ -895,6 +902,10 @@ static const byte* OidFromId(word32 id, word32 type, word32* oidSz)
|
|||
oid = sigSha1wRsaOid;
|
||||
*oidSz = sizeof(sigSha1wRsaOid);
|
||||
break;
|
||||
case CTC_SHA224wRSA:
|
||||
oid = sigSha224wRsaOid;
|
||||
*oidSz = sizeof(sigSha224wRsaOid);
|
||||
break;
|
||||
case CTC_SHA256wRSA:
|
||||
oid = sigSha256wRsaOid;
|
||||
*oidSz = sizeof(sigSha256wRsaOid);
|
||||
|
@ -913,6 +924,10 @@ static const byte* OidFromId(word32 id, word32 type, word32* oidSz)
|
|||
oid = sigSha1wEcdsaOid;
|
||||
*oidSz = sizeof(sigSha1wEcdsaOid);
|
||||
break;
|
||||
case CTC_SHA224wECDSA:
|
||||
oid = sigSha224wEcdsaOid;
|
||||
*oidSz = sizeof(sigSha224wEcdsaOid);
|
||||
break;
|
||||
case CTC_SHA256wECDSA:
|
||||
oid = sigSha256wEcdsaOid;
|
||||
*oidSz = sizeof(sigSha256wEcdsaOid);
|
||||
|
@ -3785,6 +3800,10 @@ int wc_GetCTC_HashOID(int type)
|
|||
case SHA:
|
||||
return SHAh;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
return SHA224h;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
return SHA256h;
|
||||
|
@ -3855,6 +3874,15 @@ static int ConfirmSignature(const byte* buf, word32 bufSz,
|
|||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case CTC_SHA224wRSA:
|
||||
case CTC_SHA224wECDSA:
|
||||
if (wc_Sha224Hash(buf, bufSz, digest) == 0) {
|
||||
typeH = SHA224h;
|
||||
digestSz = SHA224_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
case CTC_SHA256wRSA:
|
||||
case CTC_SHA256wECDSA:
|
||||
|
@ -7613,6 +7641,15 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz,
|
|||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case CTC_SHA224wRSA:
|
||||
case CTC_SHA224wECDSA:
|
||||
if ((ret = wc_Sha224Hash(buffer, sz, digest)) == 0) {
|
||||
typeH = SHA224h;
|
||||
digestSz = SHA224_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
case CTC_SHA256wRSA:
|
||||
case CTC_SHA256wECDSA:
|
||||
|
@ -7622,12 +7659,21 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz,
|
|||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA384
|
||||
case CTC_SHA384wRSA:
|
||||
case CTC_SHA384wECDSA:
|
||||
if ((ret = wc_Sha384Hash(buffer, sz, digest)) == 0) {
|
||||
typeH = SHA384h;
|
||||
digestSz = SHA384_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA512
|
||||
case CTC_SHA512wRSA:
|
||||
case CTC_SHA512wECDSA:
|
||||
if ((ret = wc_Sha512Hash(buffer, sz, digest)) == 0) {
|
||||
typeH = SHA256h;
|
||||
digestSz = SHA256_DIGEST_SIZE;
|
||||
typeH = SHA512h;
|
||||
digestSz = SHA512_DIGEST_SIZE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
|
|
@ -41,6 +41,7 @@ enum Hash_Sum {
|
|||
MD2h = 646,
|
||||
MD5h = 649,
|
||||
SHAh = 88,
|
||||
SHA224h = 417,
|
||||
SHA256h = 414,
|
||||
SHA384h = 415,
|
||||
SHA512h = 416
|
||||
|
@ -68,6 +69,11 @@ int wc_HashGetOID(enum wc_HashType hash_type)
|
|||
oid = SHAh;
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA224:
|
||||
#if defined(WOLFSSL_SHA224)
|
||||
oid = SHA224h;
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA256:
|
||||
#ifndef NO_SHA256
|
||||
oid = SHA256h;
|
||||
|
@ -109,6 +115,11 @@ int wc_HashGetDigestSize(enum wc_HashType hash_type)
|
|||
case WC_HASH_TYPE_SHA:
|
||||
#ifndef NO_SHA
|
||||
dig_size = SHA_DIGEST_SIZE;
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA224:
|
||||
#ifdef WOLFSSL_SHA224
|
||||
dig_size = SHA224_DIGEST_SIZE;
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA256:
|
||||
|
@ -172,6 +183,11 @@ int wc_Hash(enum wc_HashType hash_type, const byte* data,
|
|||
case WC_HASH_TYPE_SHA:
|
||||
#ifndef NO_SHA
|
||||
ret = wc_ShaHash(data, data_len, hash);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA224:
|
||||
#ifdef WOLFSSL_SHA224
|
||||
ret = wc_Sha224Hash(data, data_len, hash);
|
||||
#endif
|
||||
break;
|
||||
case WC_HASH_TYPE_SHA256:
|
||||
|
@ -273,6 +289,56 @@ int wc_ShaHash(const byte* data, word32 len, byte* hash)
|
|||
|
||||
#endif /* !defined(NO_SHA) */
|
||||
|
||||
#if defined(WOLFSSL_SHA224)
|
||||
int wc_Sha224GetHash(Sha224* sha224, byte* hash)
|
||||
{
|
||||
int ret;
|
||||
Sha224 save;
|
||||
|
||||
if (sha224 == NULL || hash == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
save= *sha224;
|
||||
ret = wc_Sha224Final(sha224, hash);
|
||||
*sha224 = save;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wc_Sha224Hash(const byte* data, word32 len, byte* hash)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
Sha224* sha224;
|
||||
#else
|
||||
Sha224 sha224[1];
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
sha224 = (Sha224*)XMALLOC(sizeof(Sha224), NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
if (sha224 == NULL)
|
||||
return MEMORY_E;
|
||||
#endif
|
||||
|
||||
if ((ret = wc_InitSha224(sha224)) != 0) {
|
||||
WOLFSSL_MSG("InitSha224 failed");
|
||||
}
|
||||
else if ((ret = wc_Sha224Update(sha224, data, len)) != 0) {
|
||||
WOLFSSL_MSG("Sha224Update failed");
|
||||
}
|
||||
else if ((ret = wc_Sha224Final(sha224, hash)) != 0) {
|
||||
WOLFSSL_MSG("Sha224Final failed");
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(sha224, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* defined(WOLFSSL_SHA224) */
|
||||
|
||||
#if !defined(NO_SHA256)
|
||||
int wc_Sha256GetHash(Sha256* sha256, byte* hash)
|
||||
{
|
||||
|
|
|
@ -108,7 +108,8 @@ int wc_HKDF(int type, const byte* inKey, word32 inKeySz,
|
|||
int wc_HmacSizeByType(int type)
|
||||
{
|
||||
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|
||||
|| type == SHA512 || type == BLAKE2B_ID)) {
|
||||
|| type == SHA512 || type == BLAKE2B_ID)
|
||||
|| type == SHA224) {
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
|
@ -123,6 +124,11 @@ int wc_HmacSizeByType(int type)
|
|||
return SHA_DIGEST_SIZE;
|
||||
#endif
|
||||
|
||||
#ifdef WOLF_SHA224
|
||||
case SHA224:
|
||||
return SHA224_DIGEST_SIZE;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
return SHA256_DIGEST_SIZE;
|
||||
|
@ -156,7 +162,8 @@ static int InitHmac(Hmac* hmac, int type)
|
|||
hmac->macType = (byte)type;
|
||||
|
||||
if (!(type == MD5 || type == SHA || type == SHA256 || type == SHA384
|
||||
|| type == SHA512 || type == BLAKE2B_ID))
|
||||
|| type == SHA512 || type == BLAKE2B_ID
|
||||
|| type == SHA224))
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
switch (type) {
|
||||
|
@ -172,6 +179,12 @@ static int InitHmac(Hmac* hmac, int type)
|
|||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
ret = wc_InitSha224(&hmac->hash.sha224);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
ret = wc_InitSha256(&hmac->hash.sha256);
|
||||
|
@ -259,6 +272,28 @@ int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 length)
|
|||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
{
|
||||
hmac_block_size = SHA224_BLOCK_SIZE;
|
||||
if (length <= SHA224_BLOCK_SIZE) {
|
||||
XMEMCPY(ip, key, length);
|
||||
}
|
||||
else {
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, key, length);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, ip);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
length = SHA224_DIGEST_SIZE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
{
|
||||
|
@ -378,6 +413,15 @@ static int HmacKeyInnerHash(Hmac* hmac)
|
|||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224,
|
||||
(byte*) hmac->ipad, SHA224_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
ret = wc_Sha256Update(&hmac->hash.sha256,
|
||||
|
@ -453,6 +497,14 @@ int wc_HmacUpdate(Hmac* hmac, const byte* msg, word32 length)
|
|||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224, msg, length);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
ret = wc_Sha256Update(&hmac->hash.sha256, msg, length);
|
||||
|
@ -538,6 +590,30 @@ int wc_HmacFinal(Hmac* hmac, byte* hash)
|
|||
break;
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case SHA224:
|
||||
{
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, (byte*) hmac->innerHash);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224,
|
||||
(byte*) hmac->opad, SHA224_BLOCK_SIZE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = wc_Sha224Update(&hmac->hash.sha224,
|
||||
(byte*) hmac->innerHash, SHA224_DIGEST_SIZE);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
ret = wc_Sha224Final(&hmac->hash.sha224, hash);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
case SHA256:
|
||||
{
|
||||
|
|
|
@ -371,6 +371,11 @@ static int RsaMGF(int type, byte* seed, word32 seedSz, byte* out,
|
|||
break;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
#ifdef WOLFSSL_SHA224
|
||||
case WC_MGF1SHA224:
|
||||
ret = RsaMGF1(WC_HASH_TYPE_SHA224, seed, seedSz, out, outSz, heap);
|
||||
break;
|
||||
#endif
|
||||
case WC_MGF1SHA256:
|
||||
ret = RsaMGF1(WC_HASH_TYPE_SHA256, seed, seedSz, out, outSz, heap);
|
||||
break;
|
||||
|
|
|
@ -49,7 +49,6 @@ int wc_Sha256Final(Sha256* sha, byte* out)
|
|||
return Sha256Final_fips(sha, out);
|
||||
}
|
||||
|
||||
|
||||
#else /* else build without fips */
|
||||
|
||||
#if !defined(NO_SHA256) && defined(WOLFSSL_TI_HASH)
|
||||
|
@ -219,7 +218,7 @@ static int set_cpuid_flags(void) {
|
|||
}
|
||||
|
||||
|
||||
/* #if defined(HAVE_INTEL_AVX1/2) at the tail of sha512 */
|
||||
/* #if defined(HAVE_INTEL_AVX1/2) at the tail of sha256 */
|
||||
static int Transform(Sha256* sha256);
|
||||
|
||||
#if defined(HAVE_INTEL_AVX1)
|
||||
|
@ -441,7 +440,7 @@ static INLINE void AddLength(Sha256* sha256, word32 len)
|
|||
sha256->hiLen++; /* carry low to high */
|
||||
}
|
||||
|
||||
int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len)
|
||||
static INLINE int Sha256Update(Sha256* sha256, const byte* data, word32 len)
|
||||
{
|
||||
|
||||
/* do block size increments */
|
||||
|
@ -479,7 +478,12 @@ int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int wc_Sha256Final(Sha256* sha256, byte* hash)
|
||||
int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len)
|
||||
{
|
||||
return Sha256Update(sha256, data, len);
|
||||
}
|
||||
|
||||
static INLINE int Sha256Final(Sha256* sha256)
|
||||
{
|
||||
byte* local = (byte*)sha256->buffer;
|
||||
int ret;
|
||||
|
@ -537,7 +541,14 @@ int wc_Sha256Final(Sha256* sha256, byte* hash)
|
|||
2 * sizeof(word32));
|
||||
#endif
|
||||
|
||||
ret = XTRANSFORM(sha256, local);
|
||||
return XTRANSFORM(sha256, local);
|
||||
}
|
||||
|
||||
int wc_Sha256Final(Sha256* sha256, byte* hash)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = Sha256Final(sha256);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
|
@ -550,8 +561,6 @@ int wc_Sha256Final(Sha256* sha256, byte* hash)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INTEL_AVX1) || defined(HAVE_INTEL_AVX2)
|
||||
|
||||
#define _DigestToReg(S_0, S_1, S_2, S_3, S_4, S_5, S_6, S_7 )\
|
||||
|
@ -1733,6 +1742,50 @@ static int Transform_AVX2(Sha256* sha256)
|
|||
|
||||
#endif /* HAVE_INTEL_AVX2 */
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
int wc_InitSha224(Sha224* sha224)
|
||||
{
|
||||
sha224->digest[0] = 0xc1059ed8;
|
||||
sha224->digest[1] = 0x367cd507;
|
||||
sha224->digest[2] = 0x3070dd17;
|
||||
sha224->digest[3] = 0xf70e5939;
|
||||
sha224->digest[4] = 0xffc00b31;
|
||||
sha224->digest[5] = 0x68581511;
|
||||
sha224->digest[6] = 0x64f98fa7;
|
||||
sha224->digest[7] = 0xbefa4fa4;
|
||||
|
||||
sha224->buffLen = 0;
|
||||
sha224->loLen = 0;
|
||||
sha224->hiLen = 0;
|
||||
|
||||
#if defined(HAVE_INTEL_AVX1)|| defined(HAVE_INTEL_AVX2)
|
||||
set_Transform() ;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wc_Sha224Update(Sha224* sha224, const byte* data, word32 len)
|
||||
{
|
||||
return Sha256Update((Sha256 *)sha224, data, len);
|
||||
}
|
||||
|
||||
|
||||
int wc_Sha224Final(Sha224* sha224, byte* hash)
|
||||
{
|
||||
int ret = Sha256Final((Sha256 *)sha224);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
#if defined(LITTLE_ENDIAN_ORDER)
|
||||
ByteReverseWords(sha224->digest, sha224->digest, SHA224_DIGEST_SIZE);
|
||||
#endif
|
||||
XMEMCPY(hash, sha224->digest, SHA224_DIGEST_SIZE);
|
||||
|
||||
return wc_InitSha224(sha224); /* reset state */
|
||||
}
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
#endif /* WOLFSSL_TI_HAHS */
|
||||
|
|
|
@ -173,11 +173,13 @@ int md2_test(void);
|
|||
int md5_test(void);
|
||||
int md4_test(void);
|
||||
int sha_test(void);
|
||||
int sha224_test(void);
|
||||
int sha256_test(void);
|
||||
int sha512_test(void);
|
||||
int sha384_test(void);
|
||||
int hmac_md5_test(void);
|
||||
int hmac_sha_test(void);
|
||||
int hmac_sha224_test(void);
|
||||
int hmac_sha256_test(void);
|
||||
int hmac_sha384_test(void);
|
||||
int hmac_sha512_test(void);
|
||||
|
@ -371,6 +373,13 @@ int wolfcrypt_test(void* args)
|
|||
printf( "SHA test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
if ( (ret = sha224_test()) != 0)
|
||||
return err_sys("SHA-224 test failed!\n", ret);
|
||||
else
|
||||
printf( "SHA-224 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
if ( (ret = sha256_test()) != 0)
|
||||
return err_sys("SHA-256 test failed!\n", ret);
|
||||
|
@ -421,6 +430,13 @@ int wolfcrypt_test(void* args)
|
|||
printf( "HMAC-SHA test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
if ( (ret = hmac_sha224_test()) != 0)
|
||||
return err_sys("HMAC-SHA224 test failed!\n", ret);
|
||||
else
|
||||
printf( "HMAC-SHA224 test passed!\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
if ( (ret = hmac_sha256_test()) != 0)
|
||||
return err_sys("HMAC-SHA256 test failed!\n", ret);
|
||||
|
@ -1127,6 +1143,53 @@ int blake2b_test(void)
|
|||
#endif /* HAVE_BLAKE2 */
|
||||
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
int sha224_test(void)
|
||||
{
|
||||
Sha224 sha;
|
||||
byte hash[SHA224_DIGEST_SIZE];
|
||||
|
||||
testVector a, b;
|
||||
testVector test_sha[2];
|
||||
int ret;
|
||||
int times = sizeof(test_sha) / sizeof(struct testVector), i;
|
||||
|
||||
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 = SHA224_DIGEST_SIZE;
|
||||
|
||||
b.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
b.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
|
||||
"\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
|
||||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
test_sha[0] = a;
|
||||
test_sha[1] = b;
|
||||
|
||||
ret = wc_InitSha224(&sha);
|
||||
if (ret != 0)
|
||||
return -4005;
|
||||
|
||||
for (i = 0; i < times; ++i) {
|
||||
ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,(word32)test_sha[i].inLen);
|
||||
if (ret != 0)
|
||||
return -4006;
|
||||
ret = wc_Sha224Final(&sha, hash);
|
||||
if (ret != 0)
|
||||
return -4007;
|
||||
|
||||
if (XMEMCMP(hash, test_sha[i].output, SHA224_DIGEST_SIZE) != 0)
|
||||
return -10 - i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef NO_SHA256
|
||||
int sha256_test(void)
|
||||
{
|
||||
|
@ -1442,6 +1505,84 @@ int hmac_sha_test(void)
|
|||
#endif
|
||||
|
||||
|
||||
#if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
|
||||
int hmac_sha224_test(void)
|
||||
{
|
||||
Hmac hmac;
|
||||
byte hash[SHA224_DIGEST_SIZE];
|
||||
|
||||
const char* keys[]=
|
||||
{
|
||||
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
|
||||
"\x0b\x0b\x0b",
|
||||
"Jefe",
|
||||
"\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
|
||||
"\xAA\xAA\xAA"
|
||||
};
|
||||
|
||||
testVector a, b, c;
|
||||
testVector test_hmac[3];
|
||||
|
||||
int ret;
|
||||
int times = sizeof(test_hmac) / sizeof(testVector), i;
|
||||
|
||||
a.input = "Hi There";
|
||||
a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
|
||||
"\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
|
||||
a.inLen = XSTRLEN(a.input);
|
||||
a.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
b.input = "what do ya want for nothing?";
|
||||
b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
|
||||
"\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
|
||||
b.inLen = XSTRLEN(b.input);
|
||||
b.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
|
||||
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
|
||||
"\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
|
||||
"\xDD\xDD\xDD\xDD\xDD\xDD";
|
||||
c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
|
||||
"\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
|
||||
c.inLen = XSTRLEN(c.input);
|
||||
c.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
test_hmac[0] = a;
|
||||
test_hmac[1] = b;
|
||||
test_hmac[2] = c;
|
||||
|
||||
for (i = 0; i < times; ++i) {
|
||||
#if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
|
||||
if (i == 1)
|
||||
continue; /* cavium can't handle short keys, fips not allowed */
|
||||
#endif
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
if (wc_HmacAsyncInit(&hmac, devId) != 0)
|
||||
return -20011;
|
||||
#endif
|
||||
ret = wc_HmacSetKey(&hmac, SHA224, (byte*)keys[i],(word32)XSTRLEN(keys[i]));
|
||||
if (ret != 0)
|
||||
return -4021;
|
||||
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
|
||||
(word32)test_hmac[i].inLen);
|
||||
if (ret != 0)
|
||||
return -4022;
|
||||
ret = wc_HmacFinal(&hmac, hash);
|
||||
if (ret != 0)
|
||||
return -4023;
|
||||
|
||||
if (XMEMCMP(hash, test_hmac[i].output, SHA224_DIGEST_SIZE) != 0)
|
||||
return -20 - i;
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
wc_HmacAsyncFree(&hmac);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(NO_HMAC) && !defined(NO_SHA256)
|
||||
int hmac_sha256_test(void)
|
||||
{
|
||||
|
@ -6360,6 +6501,26 @@ int openssl_test(void)
|
|||
|
||||
#endif /* NO_SHA */
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
|
||||
e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
|
||||
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
||||
e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
|
||||
"\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
|
||||
e.inLen = XSTRLEN(e.input);
|
||||
e.outLen = SHA224_DIGEST_SIZE;
|
||||
|
||||
EVP_MD_CTX_init(&md_ctx);
|
||||
EVP_DigestInit(&md_ctx, EVP_sha224());
|
||||
|
||||
EVP_DigestUpdate(&md_ctx, e.input, (unsigned long)e.inLen);
|
||||
EVP_DigestFinal(&md_ctx, hash, 0);
|
||||
|
||||
if (XMEMCMP(hash, e.output, SHA224_DIGEST_SIZE) != 0)
|
||||
return -79;
|
||||
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
|
||||
d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||
d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef char WOLFSSL_EVP_CIPHER;
|
|||
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_md5(void);
|
||||
#endif
|
||||
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha1(void);
|
||||
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha224(void);
|
||||
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha256(void);
|
||||
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha384(void);
|
||||
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha512(void);
|
||||
|
@ -83,6 +84,9 @@ typedef union {
|
|||
WOLFSSL_MD5_CTX md5;
|
||||
#endif
|
||||
WOLFSSL_SHA_CTX sha;
|
||||
#ifdef WOLFSSL_SHA224
|
||||
WOLFSSL_SHA224_CTX sha224;
|
||||
#endif
|
||||
WOLFSSL_SHA256_CTX sha256;
|
||||
#ifdef WOLFSSL_SHA384
|
||||
WOLFSSL_SHA384_CTX sha384;
|
||||
|
@ -217,6 +221,7 @@ typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
|
|||
#define EVP_md5 wolfSSL_EVP_md5
|
||||
#endif
|
||||
#define EVP_sha1 wolfSSL_EVP_sha1
|
||||
#define EVP_sha224 wolfSSL_EVP_sha224
|
||||
#define EVP_sha256 wolfSSL_EVP_sha256
|
||||
#define EVP_sha384 wolfSSL_EVP_sha384
|
||||
#define EVP_sha512 wolfSSL_EVP_sha512
|
||||
|
|
|
@ -44,6 +44,31 @@ typedef WOLFSSL_SHA_CTX SHA_CTX;
|
|||
#define SHA1_Final wolfSSL_SHA1_Final
|
||||
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
|
||||
typedef struct WOLFSSL_SHA224_CTX {
|
||||
long long holder[28]; /* big enough, but check on init */
|
||||
} WOLFSSL_SHA224_CTX;
|
||||
|
||||
WOLFSSL_API void wolfSSL_SHA224_Init(WOLFSSL_SHA224_CTX*);
|
||||
WOLFSSL_API void wolfSSL_SHA224_Update(WOLFSSL_SHA224_CTX*, const void*,
|
||||
unsigned long);
|
||||
WOLFSSL_API void wolfSSL_SHA224_Final(unsigned char*, WOLFSSL_SHA224_CTX*);
|
||||
|
||||
enum {
|
||||
SHA224_DIGEST_LENGTH = 28
|
||||
};
|
||||
|
||||
|
||||
typedef WOLFSSL_SHA224_CTX SHA224_CTX;
|
||||
|
||||
#define SHA224_Init wolfSSL_SHA224_Init
|
||||
#define SHA224_Update wolfSSL_SHA224_Update
|
||||
#define SHA224_Final wolfSSL_SHA224_Final
|
||||
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
|
||||
typedef struct WOLFSSL_SHA256_CTX {
|
||||
int holder[28]; /* big enough to hold wolfcrypt sha, but check on init */
|
||||
} WOLFSSL_SHA256_CTX;
|
||||
|
@ -54,7 +79,7 @@ WOLFSSL_API void wolfSSL_SHA256_Update(WOLFSSL_SHA256_CTX*, const void*,
|
|||
WOLFSSL_API void wolfSSL_SHA256_Final(unsigned char*, WOLFSSL_SHA256_CTX*);
|
||||
|
||||
enum {
|
||||
SHA256_DIGEST_LENGTH = 32
|
||||
SHA256_DIGEST_LENGTH = 32
|
||||
};
|
||||
|
||||
|
||||
|
@ -77,7 +102,7 @@ WOLFSSL_API void wolfSSL_SHA384_Update(WOLFSSL_SHA384_CTX*, const void*,
|
|||
WOLFSSL_API void wolfSSL_SHA384_Final(unsigned char*, WOLFSSL_SHA384_CTX*);
|
||||
|
||||
enum {
|
||||
SHA384_DIGEST_LENGTH = 48
|
||||
SHA384_DIGEST_LENGTH = 48
|
||||
};
|
||||
|
||||
|
||||
|
@ -101,7 +126,7 @@ WOLFSSL_API void wolfSSL_SHA512_Update(WOLFSSL_SHA512_CTX*, const void*,
|
|||
WOLFSSL_API void wolfSSL_SHA512_Final(unsigned char*, WOLFSSL_SHA512_CTX*);
|
||||
|
||||
enum {
|
||||
SHA512_DIGEST_LENGTH = 64
|
||||
SHA512_DIGEST_LENGTH = 64
|
||||
};
|
||||
|
||||
|
||||
|
@ -117,7 +142,7 @@ typedef WOLFSSL_SHA512_CTX SHA512_CTX;
|
|||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -221,6 +221,7 @@ enum Hash_Sum {
|
|||
MD2h = 646,
|
||||
MD5h = 649,
|
||||
SHAh = 88,
|
||||
SHA224h = 417,
|
||||
SHA256h = 414,
|
||||
SHA384h = 415,
|
||||
SHA512h = 416
|
||||
|
|
|
@ -63,6 +63,8 @@ enum Ctc_SigType {
|
|||
CTC_MD5wRSA = 648,
|
||||
CTC_SHAwRSA = 649,
|
||||
CTC_SHAwECDSA = 520,
|
||||
CTC_SHA224wRSA = 658,
|
||||
CTC_SHA224wECDSA = 527,
|
||||
CTC_SHA256wRSA = 655,
|
||||
CTC_SHA256wECDSA = 524,
|
||||
CTC_SHA384wRSA = 656,
|
||||
|
|
|
@ -36,6 +36,7 @@ enum wc_HashType {
|
|||
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,
|
||||
|
@ -50,6 +51,8 @@ enum wc_HashType {
|
|||
#define WC_MAX_DIGEST_SIZE SHA384_DIGEST_SIZE
|
||||
#elif !defined(NO_SHA256)
|
||||
#define WC_MAX_DIGEST_SIZE SHA256_DIGEST_SIZE
|
||||
#elif defined(WOLFSSL_SHA224)
|
||||
#define WC_MAX_DIGEST_SIZE SHA224_DIGEST_SIZE
|
||||
#elif !defined(NO_SHA)
|
||||
#define WC_MAX_DIGEST_SIZE SHA_DIGEST_SIZE
|
||||
#elif !defined(NO_MD5)
|
||||
|
@ -101,6 +104,12 @@ WOLFSSL_API int wc_Sha256Hash(const byte*, word32, byte*);
|
|||
#else
|
||||
#define wc_Sha256Free(d)
|
||||
#endif
|
||||
|
||||
#if defined(WOLFSSL_SHA224)
|
||||
WOLFSSL_API int wc_Sha224GetHash(Sha224*, byte*);
|
||||
WOLFSSL_API int wc_Sha224Hash(const byte*, word32, byte*);
|
||||
#define wc_Sha224Free(d)
|
||||
#endif /* defined(WOLFSSL_SHA224) */
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_SHA512
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include <wolfssl/wolfcrypt/sha.h>
|
||||
#endif
|
||||
|
||||
#ifndef NO_SHA256
|
||||
#if !defined(NO_SHA256) || defined(WOLFSSL_SHA224)
|
||||
#include <wolfssl/wolfcrypt/sha256.h>
|
||||
#endif
|
||||
|
||||
|
@ -88,6 +88,9 @@ enum {
|
|||
#ifndef HAVE_BLAKE2
|
||||
BLAKE2B_ID = 7,
|
||||
#endif
|
||||
#ifndef WOLFSSL_SHA224
|
||||
SHA224 = 8,
|
||||
#endif
|
||||
|
||||
/* Select the largest available hash for the buffer size. */
|
||||
#if defined(WOLFSSL_SHA512)
|
||||
|
@ -102,6 +105,9 @@ enum {
|
|||
#elif !defined(NO_SHA256)
|
||||
MAX_DIGEST_SIZE = SHA256_DIGEST_SIZE,
|
||||
HMAC_BLOCK_SIZE = SHA256_BLOCK_SIZE
|
||||
#elif defined(WOLFSSL_SHA224)
|
||||
MAX_DIGEST_SIZE = SHA224_DIGEST_SIZE,
|
||||
HMAC_BLOCK_SIZE = SHA224_BLOCK_SIZE
|
||||
#elif !defined(NO_SHA)
|
||||
MAX_DIGEST_SIZE = SHA_DIGEST_SIZE,
|
||||
HMAC_BLOCK_SIZE = SHA_BLOCK_SIZE
|
||||
|
@ -122,6 +128,9 @@ typedef union {
|
|||
#ifndef NO_SHA
|
||||
Sha sha;
|
||||
#endif
|
||||
#ifdef WOLFSSL_SHA224
|
||||
Sha224 sha224;
|
||||
#endif
|
||||
#ifndef NO_SHA256
|
||||
Sha256 sha256;
|
||||
#endif
|
||||
|
|
|
@ -135,6 +135,7 @@ WOLFSSL_API int wc_RsaSetRNG(RsaKey* key, WC_RNG* rng);
|
|||
/* Mask Generation Function Identifiers */
|
||||
#define WC_MGF1NONE 0
|
||||
#define WC_MGF1SHA1 26
|
||||
#define WC_MGF1SHA224 4
|
||||
#define WC_MGF1SHA256 1
|
||||
#define WC_MGF1SHA384 2
|
||||
#define WC_MGF1SHA512 3
|
||||
|
|
|
@ -76,6 +76,26 @@ WOLFSSL_API int wc_InitSha256(Sha256*);
|
|||
WOLFSSL_API int wc_Sha256Update(Sha256*, const byte*, word32);
|
||||
WOLFSSL_API int wc_Sha256Final(Sha256*, byte*);
|
||||
|
||||
#ifdef WOLFSSL_SHA224
|
||||
|
||||
#ifndef HAVE_FIPS /* avoid redefinition of structs */
|
||||
/* in bytes */
|
||||
enum {
|
||||
SHA224 = 8, /* hash type unique */
|
||||
SHA224_BLOCK_SIZE = SHA256_BLOCK_SIZE,
|
||||
SHA224_DIGEST_SIZE = 28,
|
||||
SHA224_PAD_SIZE = SHA256_PAD_SIZE
|
||||
};
|
||||
|
||||
typedef Sha256 Sha224;
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
WOLFSSL_API int wc_InitSha224(Sha224*);
|
||||
WOLFSSL_API int wc_Sha224Update(Sha224*, const byte*, word32);
|
||||
WOLFSSL_API int wc_Sha224Final(Sha224*, byte*);
|
||||
|
||||
#endif /* WOLFSSL_SHA224 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue