Imported Upstream version 3.13.0+dfsg

This commit is contained in:
Mario Fetka
2018-02-19 12:29:49 +01:00
parent 1893aafd38
commit e07619e148
472 changed files with 168552 additions and 31827 deletions

View File

@@ -1,6 +1,6 @@
/* hash.c has unit tests
*
* Copyright (C) 2006-2016 wolfSSL Inc.
* Copyright (C) 2006-2017 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
@@ -254,8 +254,9 @@ int md4_test(void)
int md5_test(void)
{
Md5 md5;
byte hash[MD5_DIGEST_SIZE];
int ret;
wc_Md5 md5;
byte hash[WC_MD5_DIGEST_SIZE];
testVector a, b, c, d, e;
testVector test_md5[5];
@@ -299,13 +300,24 @@ int md5_test(void)
test_md5[3] = d;
test_md5[4] = e;
wc_InitMd5(&md5);
ret = wc_InitMd5(&md5);
if (ret) {
return ret;
}
for (i = 0; i < times; ++i) {
wc_Md5Update(&md5, (byte*)test_md5[i].input, (word32)test_md5[i].inLen);
wc_Md5Final(&md5, hash);
ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
(word32)test_md5[i].inLen);
if (ret) {
return ret;
}
if (XMEMCMP(hash, test_md5[i].output, MD5_DIGEST_SIZE) != 0)
ret = wc_Md5Final(&md5, hash);
if (ret) {
return ret;
}
if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
return -5 - i;
}
@@ -317,8 +329,8 @@ int md5_test(void)
#ifndef NO_SHA
int sha_test(void)
{
Sha sha;
byte hash[SHA_DIGEST_SIZE];
wc_Sha sha;
byte hash[WC_SHA_DIGEST_SIZE];
testVector a, b, c, d;
testVector test_sha[4];
@@ -365,7 +377,7 @@ int sha_test(void)
wc_ShaUpdate(&sha, (byte*)test_sha[i].input, (word32)test_sha[i].inLen);
wc_ShaFinal(&sha, hash);
if (XMEMCMP(hash, test_sha[i].output, SHA_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
return -10 - i;
}
@@ -376,8 +388,8 @@ int sha_test(void)
#ifdef WOLFSSL_SHA224
int sha224_test(void)
{
Sha224 sha;
byte hash[SHA224_DIGEST_SIZE];
wc_Sha224 sha;
byte hash[WC_SHA224_DIGEST_SIZE];
testVector a, b;
testVector test_sha[2];
@@ -388,13 +400,13 @@ int sha224_test(void)
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;
a.outLen = WC_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;
b.outLen = WC_SHA224_DIGEST_SIZE;
test_sha[0] = a;
test_sha[1] = b;
@@ -411,7 +423,7 @@ int sha224_test(void)
if (ret != 0)
return ret;
if (XMEMCMP(hash, test_sha[i].output, SHA224_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
return -10 - i;
}
@@ -422,8 +434,8 @@ int sha224_test(void)
#ifndef NO_SHA256
int sha256_test(void)
{
Sha256 sha;
byte hash[SHA256_DIGEST_SIZE];
wc_Sha256 sha;
byte hash[WC_SHA256_DIGEST_SIZE];
testVector a, b;
testVector test_sha[2];
@@ -460,7 +472,7 @@ int sha256_test(void)
if (ret != 0)
return ret;
if (XMEMCMP(hash, test_sha[i].output, SHA256_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0)
return -10 - i;
}
@@ -471,8 +483,8 @@ int sha256_test(void)
#ifdef WOLFSSL_SHA512
int sha512_test(void)
{
Sha512 sha;
byte hash[SHA512_DIGEST_SIZE];
wc_Sha512 sha;
byte hash[WC_SHA512_DIGEST_SIZE];
testVector a, b;
testVector test_sha[2];
@@ -514,7 +526,7 @@ int sha512_test(void)
if (ret != 0)
return ret;
if (XMEMCMP(hash, test_sha[i].output, SHA512_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
return -10 - i;
}
@@ -525,8 +537,8 @@ int sha512_test(void)
#ifdef WOLFSSL_SHA384
int sha384_test()
{
Sha384 sha;
byte hash[SHA384_DIGEST_SIZE];
wc_Sha384 sha;
byte hash[WC_SHA384_DIGEST_SIZE];
testVector a, b;
testVector test_sha[2];
@@ -566,7 +578,7 @@ int sha384_test()
if (ret != 0)
return ret;
if (XMEMCMP(hash, test_sha[i].output, SHA384_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
return -10 - i;
}
@@ -578,6 +590,7 @@ int sha384_test()
int ripemd_test(void)
{
RipeMd ripemd;
int ret;
byte hash[RIPEMD_DIGEST_SIZE];
testVector a, b, c, d;
@@ -614,12 +627,22 @@ int ripemd_test(void)
test_ripemd[2] = c;
test_ripemd[3] = d;
wc_InitRipeMd(&ripemd);
ret = wc_InitRipeMd(&ripemd);
if (ret) {
return ret;
}
for (i = 0; i < times; ++i) {
wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
(word32)test_ripemd[i].inLen);
wc_RipeMdFinal(&ripemd, hash);
ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
(word32)test_ripemd[i].inLen);
if (ret) {
return ret;
}
ret = wc_RipeMdFinal(&ripemd, hash);
if (ret) {
return ret;
}
if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
return -10 - i;
@@ -633,7 +656,7 @@ int ripemd_test(void)
int hmac_md5_test(void)
{
Hmac hmac;
byte hash[MD5_DIGEST_SIZE];
byte hash[WC_MD5_DIGEST_SIZE];
const char* keys[]=
{
@@ -673,12 +696,16 @@ int hmac_md5_test(void)
test_hmac[1] = b;
test_hmac[2] = c;
ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
if (ret != 0)
return -20009;
for (i = 0; i < times; ++i) {
#if defined(HAVE_FIPS)
if (i == 1)
continue; /* fips not allowed */
#endif
ret = wc_HmacSetKey(&hmac, MD5, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
if (ret != 0)
return -4014;
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
@@ -689,10 +716,12 @@ int hmac_md5_test(void)
if (ret != 0)
return -4016;
if (XMEMCMP(hash, test_hmac[i].output, MD5_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
return -20 - i;
}
wc_HmacFree(&hmac);
return 0;
}
#endif
@@ -701,7 +730,7 @@ int hmac_md5_test(void)
int hmac_sha_test(void)
{
Hmac hmac;
byte hash[SHA_DIGEST_SIZE];
byte hash[WC_SHA_DIGEST_SIZE];
const char* keys[]=
{
@@ -743,12 +772,16 @@ int hmac_sha_test(void)
test_hmac[1] = b;
test_hmac[2] = c;
ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
if (ret != 0)
return -20009;
for (i = 0; i < times; ++i) {
#if defined(HAVE_FIPS)
if (i == 1)
continue; /* fips not allowed */
#endif
ret = wc_HmacSetKey(&hmac, SHA, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
if (ret != 0)
return -4017;
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
@@ -759,10 +792,12 @@ int hmac_sha_test(void)
if (ret != 0)
return -4019;
if (XMEMCMP(hash, test_hmac[i].output, SHA_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
return -20 - i;
}
wc_HmacFree(&hmac);
return 0;
}
#endif
@@ -771,7 +806,7 @@ int hmac_sha_test(void)
int hmac_sha224_test(void)
{
Hmac hmac;
byte hash[SHA224_DIGEST_SIZE];
byte hash[WC_SHA224_DIGEST_SIZE];
const char* keys[]=
{
@@ -792,13 +827,13 @@ int hmac_sha224_test(void)
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;
a.outLen = WC_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;
b.outLen = WC_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"
@@ -807,18 +842,22 @@ int hmac_sha224_test(void)
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;
c.outLen = WC_SHA224_DIGEST_SIZE;
test_hmac[0] = a;
test_hmac[1] = b;
test_hmac[2] = c;
ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
if (ret != 0)
return -20009;
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]));
ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],(word32)XSTRLEN(keys[i]));
if (ret != 0)
return -4021;
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
@@ -829,13 +868,12 @@ int hmac_sha224_test(void)
if (ret != 0)
return -4023;
if (XMEMCMP(hash, test_hmac[i].output, SHA224_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
return -20 - i;
#ifdef WOLFSSL_ASYNC_CRYPT
wc_HmacAsyncFree(&hmac);
#endif
}
wc_HmacFree(&hmac);
return 0;
}
#endif
@@ -845,7 +883,7 @@ int hmac_sha224_test(void)
int hmac_sha256_test(void)
{
Hmac hmac;
byte hash[SHA256_DIGEST_SIZE];
byte hash[WC_SHA256_DIGEST_SIZE];
const char* keys[]=
{
@@ -890,12 +928,17 @@ int hmac_sha256_test(void)
test_hmac[1] = b;
test_hmac[2] = c;
ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
if (ret != 0)
return -20009;
for (i = 0; i < times; ++i) {
#if defined(HAVE_FIPS)
if (i == 1)
continue; /* fips not allowed */
#endif
ret = wc_HmacSetKey(&hmac,SHA256, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
(word32)XSTRLEN(keys[i]));
if (ret != 0)
return -4020;
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
@@ -906,10 +949,12 @@ int hmac_sha256_test(void)
if (ret != 0)
return -4022;
if (XMEMCMP(hash, test_hmac[i].output, SHA256_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
return -20 - i;
}
wc_HmacFree(&hmac);
return 0;
}
#endif
@@ -919,7 +964,7 @@ int hmac_sha256_test(void)
int hmac_sha384_test(void)
{
Hmac hmac;
byte hash[SHA384_DIGEST_SIZE];
byte hash[WC_SHA384_DIGEST_SIZE];
const char* keys[]=
{
@@ -967,12 +1012,17 @@ int hmac_sha384_test(void)
test_hmac[1] = b;
test_hmac[2] = c;
ret = wc_HmacInit(&hmac, NULL, INVALID_DEVID);
if (ret != 0)
return -20009;
for (i = 0; i < times; ++i) {
#if defined(HAVE_FIPS)
if (i == 1)
continue; /* fips not allowed */
#endif
ret = wc_HmacSetKey(&hmac,SHA384, (byte*)keys[i], (word32)XSTRLEN(keys[i]));
ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
(word32)XSTRLEN(keys[i]));
if (ret != 0)
return -4023;
ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
@@ -983,10 +1033,12 @@ int hmac_sha384_test(void)
if (ret != 0)
return -4025;
if (XMEMCMP(hash, test_hmac[i].output, SHA384_DIGEST_SIZE) != 0)
if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
return -20 - i;
}
wc_HmacFree(&hmac);
return 0;
}
#endif