Merge pull request #1707 from kaleb-himes/ARM_GCC_EX_FIXES

Fixes for building without DRBG and ForceZero test
This commit is contained in:
toddouska
2018-07-23 16:14:43 -07:00
committed by GitHub
3 changed files with 46 additions and 39 deletions

View File

@ -218,7 +218,6 @@
#include <wolfssl/wolfcrypt/blake2.h>
#endif
#ifndef NO_RSA
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/hash.h>
@ -20136,6 +20135,41 @@ static void test_wolfSSL_i2c_ASN1_INTEGER()
printf(resultFmt, passed);
#endif /* OPENSSL_EXTRA */
}
#ifndef NO_INLINE
#define WOLFSSL_MISC_INCLUDED
#include <wolfcrypt/src/misc.c>
#else
#include <wolfssl/wolfcrypt/misc.h>
#endif
static int test_ForceZero(void)
{
unsigned char data[32];
unsigned int i, j, len;
/* Test ForceZero */
for (i = 0; i < sizeof(data); i++) {
for (len = 1; len < sizeof(data) - i; len++) {
for (j = 0; j < sizeof(data); j++)
data[j] = j + 1;
ForceZero(data + i, len);
for (j = 0; j < sizeof(data); j++) {
if (j < i || j >= i + len) {
if (data[j] == 0x00)
return -10200;
}
else if (data[j] != 0x00)
return -10201;
}
}
}
return 0;
}
/*----------------------------------------------------------------------------*
| Main
*----------------------------------------------------------------------------*/
@ -20477,6 +20511,8 @@ void ApiTest(void)
test_wc_PKCS7_EncodeDecodeEnvelopedData();
test_wc_PKCS7_EncodeEncryptedData();
AssertIntEQ(test_ForceZero(), 0);
printf(" End API Tests\n");
}

View File

@ -576,7 +576,9 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
void* heap, int devId)
{
int ret = RNG_FAILURE_E;
#ifdef HAVE_HASHDRBG
word32 entropySz = ENTROPY_SZ;
#endif
(void)nonce;
(void)nonceSz;

View File

@ -123,10 +123,6 @@
#include <wolfssl/wolfcrypt/cryptodev.h>
#endif
#define WOLFSSL_MISC_INCLUDED
#include <wolfcrypt/src/misc.c>
/* only for stack size check */
#ifdef HAVE_STACK_SIZE
#include <wolfssl/ssl.h>
@ -342,7 +338,6 @@ int memcb_test(void);
#ifdef WOLFSSL_IMX6_CAAM_BLOB
int blob_test(void);
#endif
int misc_test(void);
#ifdef WOLF_CRYPTO_DEV
int cryptodev_test(void);
@ -961,11 +956,6 @@ initDefaultName();
printf( "blob test passed!\n");
#endif
if ( (ret = misc_test()) != 0)
return err_sys("misc test failed!\n", ret);
else
printf( "misc test passed!\n");
#ifdef WOLF_CRYPTO_DEV
if ( (ret = cryptodev_test()) != 0)
return err_sys("crypto dev test failed!\n", ret);
@ -17515,6 +17505,7 @@ int ed25519_test(void)
0 /*sizeof(msg1)*/,
sizeof(msg4)
};
#ifndef NO_ASN
static byte privateEd25519[] = {
0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
@ -17544,9 +17535,10 @@ int ed25519_test(void)
0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
0xf7,0x07,0x51,0x1a
};
word32 idx;
ed25519_key key3;
#endif /* NO_ASN */
#endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
/* create ed25519 keys */
@ -17560,7 +17552,9 @@ int ed25519_test(void)
wc_ed25519_init(&key);
wc_ed25519_init(&key2);
#ifndef NO_ASN
wc_ed25519_init(&key3);
#endif
wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key);
wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, &key2);
@ -17629,6 +17623,7 @@ int ed25519_test(void)
#endif /* HAVE_ED25519_VERIFY */
}
#ifndef NO_ASN
/* Try ASN.1 encoded private-only key and public key. */
idx = 0;
if (wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, &key3,
@ -17672,6 +17667,7 @@ int ed25519_test(void)
return -7234 - i;
wc_ed25519_free(&key3);
#endif /* NO_ASN */
#endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
/* clean up keys when done */
@ -19653,33 +19649,6 @@ int blob_test(void)
}
#endif /* WOLFSSL_IMX6_CAAM_BLOB */
int misc_test(void)
{
unsigned char data[32];
unsigned int i, j, len;
/* Test ForceZero */
for (i = 0; i < sizeof(data); i++) {
for (len = 1; len < sizeof(data) - i; len++) {
for (j = 0; j < sizeof(data); j++)
data[j] = j + 1;
ForceZero(data + i, len);
for (j = 0; j < sizeof(data); j++) {
if (j < i || j >= i + len) {
if (data[j] == 0x00)
return -10200;
}
else if (data[j] != 0x00)
return -10201;
}
}
}
return 0;
}
#ifdef WOLF_CRYPTO_DEV
/* Example custom context for crypto callback */