Move ForceZero test to api.c and turn on tests when inline disabled

This commit is contained in:
kaleb-himes
2018-07-20 13:30:06 -06:00
parent 027f18919a
commit 887e3deee8
3 changed files with 37 additions and 42 deletions

View File

@@ -3318,7 +3318,6 @@ AC_ARG_ENABLE([examples],
)
AS_IF([test "x$ENABLED_FILESYSTEM" = "xno"], [ENABLED_EXAMPLES="no"])
AS_IF([test "x$ENABLED_INLINE" = "xno"], [ENABLED_EXAMPLES="no"])
AS_IF([test "x$ENABLED_CRYPTONLY" = "xyes"], [ENABLED_EXAMPLES="no"])
AM_CONDITIONAL([BUILD_EXAMPLE_SERVERS], [test "x$ENABLED_EXAMPLES" = "xyes" && test "x$ENABLED_LEANTLS" = "xno"])
AM_CONDITIONAL([BUILD_EXAMPLE_CLIENTS], [test "x$ENABLED_EXAMPLES" = "xyes"])

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

@@ -123,13 +123,6 @@
#include <wolfssl/wolfcrypt/cryptodev.h>
#endif
#ifndef NO_INLINE
#define WOLFSSL_MISC_INCLUDED
#include <wolfcrypt/src/misc.c>
#else
#include <wolfssl/wolfcrypt/misc.h>
#endif
/* only for stack size check */
#ifdef HAVE_STACK_SIZE
#include <wolfssl/ssl.h>
@@ -345,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);
@@ -964,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);
@@ -19662,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 */