From 027f18919a44438805a1828d1a3765bc7b921e0e Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 20 Jul 2018 11:54:36 -0600 Subject: [PATCH 1/3] Resolving some unwanted dependencies --- wolfcrypt/src/random.c | 2 ++ wolfcrypt/test/test.c | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 9677a70ad..c1aef714d 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -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; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index fbe4e290e..b63b72506 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -123,9 +123,12 @@ #include #endif +#ifndef NO_INLINE #define WOLFSSL_MISC_INCLUDED #include - +#else +#include +#endif /* only for stack size check */ #ifdef HAVE_STACK_SIZE @@ -17515,6 +17518,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 +17548,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 +17565,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 +17636,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 +17680,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 */ From 887e3deee8c5d87310bd71ad61fd061cf176c561 Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 20 Jul 2018 13:30:06 -0600 Subject: [PATCH 2/3] Move ForceZero test to api.c and turn on tests when inline disabled --- configure.ac | 1 - tests/api.c | 38 +++++++++++++++++++++++++++++++++++++- wolfcrypt/test/test.c | 40 ---------------------------------------- 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/configure.ac b/configure.ac index 19c74590d..730407d08 100644 --- a/configure.ac +++ b/configure.ac @@ -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"]) diff --git a/tests/api.c b/tests/api.c index 0c3eaec7e..0f1dfd263 100644 --- a/tests/api.c +++ b/tests/api.c @@ -218,7 +218,6 @@ #include #endif - #ifndef NO_RSA #include #include @@ -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 +#else +#include +#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"); } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index b63b72506..52981a203 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -123,13 +123,6 @@ #include #endif -#ifndef NO_INLINE -#define WOLFSSL_MISC_INCLUDED -#include -#else -#include -#endif - /* only for stack size check */ #ifdef HAVE_STACK_SIZE #include @@ -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 */ From c432bb5e8200bca1633eccd2fddbdbec9f26e49c Mon Sep 17 00:00:00 2001 From: kaleb-himes Date: Fri, 20 Jul 2018 14:41:46 -0600 Subject: [PATCH 3/3] Revert back to no tests for test.h consideration --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 730407d08..19c74590d 100644 --- a/configure.ac +++ b/configure.ac @@ -3318,6 +3318,7 @@ 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"])