Fixes for building with “CUSTOM_RAND_GENERATE_BLOCK”. Removed seed as backup RNG source. Fixed building on embedded system with time_t not defined (test.c should use long for asn_test).

This commit is contained in:
David Garske
2017-03-22 10:23:37 -07:00
parent 69535198ca
commit c532819659
5 changed files with 67 additions and 44 deletions

View File

@@ -278,17 +278,21 @@ extern "C" {
/* Size of returned HW RNG value */ /* Size of returned HW RNG value */
#define CUSTOM_RAND_TYPE unsigned int #define CUSTOM_RAND_TYPE unsigned int
/* Seed source */
extern unsigned int custom_rand_generate(void);
#undef CUSTOM_RAND_GENERATE
#define CUSTOM_RAND_GENERATE custom_rand_generate
/* Choose RNG method */ /* Choose RNG method */
#if 1 #if 1
/* Use built-in P-RNG (SHA256 based) with HW RNG */ /* Use built-in P-RNG (SHA256 based) with HW RNG */
/* P-RNG + HW RNG (P-RNG is ~8K) */ /* P-RNG + HW RNG (P-RNG is ~8K) */
#undef HAVE_HASHDRBG #undef HAVE_HASHDRBG
#define HAVE_HASHDRBG #define HAVE_HASHDRBG
extern unsigned int custom_rand_generate(void);
#undef CUSTOM_RAND_GENERATE
#define CUSTOM_RAND_GENERATE custom_rand_generate
#else #else
#undef WC_NO_HASHDRBG
#define WC_NO_HASHDRBG
/* Bypass P-RNG and use only HW RNG */ /* Bypass P-RNG and use only HW RNG */
extern int custom_rand_generate_block(unsigned char* output, unsigned int sz); extern int custom_rand_generate_block(unsigned char* output, unsigned int sz);
#undef CUSTOM_RAND_GENERATE_BLOCK #undef CUSTOM_RAND_GENERATE_BLOCK

View File

@@ -122,12 +122,26 @@
recurse="Yes" /> recurse="Yes" />
<file file_name="user_settings.h" /> <file file_name="user_settings.h" />
<file file_name="README.md" /> <file file_name="README.md" />
<folder <folder Name="source">
Name="source" <file file_name="../../src/bio.c">
exclude="" <configuration Name="ARM_Debug" build_exclude_from_build="Yes" />
filter="" </file>
path="../../src" <file file_name="../../src/crl.c" />
recurse="No" /> <file file_name="../../src/include.am" />
<file file_name="../../src/internal.c" />
<file file_name="../../src/io.c" />
<file file_name="../../src/keys.c" />
<file file_name="../../src/libwolfssl.la" />
<file file_name="../../src/ocsp.c" />
<file file_name="../../src/sniffer.c" />
<file file_name="../../src/src_libwolfssl_la-internal.lo" />
<file file_name="../../src/src_libwolfssl_la-io.lo" />
<file file_name="../../src/src_libwolfssl_la-keys.lo" />
<file file_name="../../src/src_libwolfssl_la-ssl.lo" />
<file file_name="../../src/src_libwolfssl_la-tls.lo" />
<file file_name="../../src/ssl.c" />
<file file_name="../../src/tls.c" />
</folder>
</folder> </folder>
</project> </project>
<project Name="test"> <project Name="test">

View File

@@ -103,20 +103,25 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
int wnr_timeout = 0; /* entropy timeout, mililseconds */ int wnr_timeout = 0; /* entropy timeout, mililseconds */
int wnr_mutex_init = 0; /* flag for mutex init */ int wnr_mutex_init = 0; /* flag for mutex init */
wnr_context* wnr_ctx; /* global netRandom context */ wnr_context* wnr_ctx; /* global netRandom context */
#elif !defined(NO_DEV_RANDOM) && !defined(CUSTOM_RAND_GENERATE) && \
!defined(WOLFSSL_GENSEED_FORTEST) && !defined(WOLFSSL_MDK_ARM) && \
!defined(WOLFSSL_IAR_ARM) && !defined(WOLFSSL_ROWLEY_ARM) && \
!defined(WOLFSSL_EMBOS)
#include <fcntl.h>
#ifndef EBSNET
#include <unistd.h>
#endif
#elif defined(FREESCALE_KSDK_2_0_TRNG) #elif defined(FREESCALE_KSDK_2_0_TRNG)
#include "fsl_trng.h" #include "fsl_trng.h"
#elif defined(FREESCALE_KSDK_2_0_RNGA) #elif defined(FREESCALE_KSDK_2_0_RNGA)
#include "fsl_rnga.h" #include "fsl_rnga.h"
#elif defined(NO_DEV_RANDOM)
#elif defined(CUSTOM_RAND_GENERATE)
#elif defined(CUSTOM_RAND_GENERATE_BLOCK)
#elif defined(WOLFSSL_GENSEED_FORTEST)
#elif defined(WOLFSSL_MDK_ARM)
#elif defined(WOLFSSL_IAR_ARM)
#elif defined(WOLFSSL_ROWLEY_ARM)
#elif defined(WOLFSSL_EMBOS)
#else #else
/* include headers that may be needed to get good seed */ /* include headers that may be needed to get good seed */
#include <fcntl.h>
#ifndef EBSNET
#include <unistd.h>
#endif
#endif #endif
@@ -602,13 +607,9 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz)
} }
#else #else
/* try using the generate seed direectly */
ret = wc_GenerateSeed(&rng->seed, output, sz);
if (ret == 0)
return 0;
/* if we get here then there is an RNG configuration error */ /* if we get here then there is an RNG configuration error */
ret = RNG_FAILURE_E; ret = RNG_FAILURE_E;
#endif /* HAVE_HASHDRBG */ #endif /* HAVE_HASHDRBG */
return ret; return ret;
@@ -1590,6 +1591,11 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
return 0; return 0;
} }
#elif defined(CUSTOM_RAND_GENERATE_BLOCK)
/* #define CUSTOM_RAND_GENERATE_BLOCK myRngFunc
* extern int myRngFunc(byte* output, word32 sz);
*/
#elif defined(WOLFSSL_SAFERTOS) #elif defined(WOLFSSL_SAFERTOS)
#elif defined(WOLFSSL_LEANPSK) #elif defined(WOLFSSL_LEANPSK)
#elif defined(WOLFSSL_IAR_ARM) #elif defined(WOLFSSL_IAR_ARM)

View File

@@ -1025,8 +1025,7 @@ int base64_test()
int asn_test() int asn_test()
{ {
#ifndef NO_ASN_TIME #ifndef NO_ASN_TIME
{ long now;
time_t now;
/* Parameter Validation tests. */ /* Parameter Validation tests. */
if (wc_GetTime(NULL, sizeof(now)) != BAD_FUNC_ARG) if (wc_GetTime(NULL, sizeof(now)) != BAD_FUNC_ARG)
@@ -1039,7 +1038,6 @@ int asn_test()
return -102; return -102;
if (now == 0) if (now == 0)
return -103; return -103;
}
#endif #endif
return 0; return 0;

View File

@@ -35,11 +35,17 @@
extern "C" { extern "C" {
#endif #endif
/* Maximum generate block length */ /* Maximum generate block length */
#ifndef RNG_MAX_BLOCK_LEN #ifndef RNG_MAX_BLOCK_LEN
#define RNG_MAX_BLOCK_LEN (0x10000) #define RNG_MAX_BLOCK_LEN (0x10000)
#endif #endif
/* Size of the BRBG seed */
#ifndef DRBG_SEED_LEN
#define DRBG_SEED_LEN (440/8)
#endif
#if defined(CUSTOM_RAND_GENERATE) && !defined(CUSTOM_RAND_TYPE) #if defined(CUSTOM_RAND_GENERATE) && !defined(CUSTOM_RAND_TYPE)
/* To maintain compatibility the default is byte */ /* To maintain compatibility the default is byte */
#define CUSTOM_RAND_TYPE byte #define CUSTOM_RAND_TYPE byte
@@ -61,7 +67,6 @@
* 2. HAVE_INTEL_RDRAND: Uses the Intel RDRAND if supported by CPU. * 2. HAVE_INTEL_RDRAND: Uses the Intel RDRAND if supported by CPU.
* 3. HAVE_HASHDRBG (requires SHA256 enabled): Uses SHA256 based P-RNG * 3. HAVE_HASHDRBG (requires SHA256 enabled): Uses SHA256 based P-RNG
* seeded via wc_GenerateSeed. This is the default source. * seeded via wc_GenerateSeed. This is the default source.
* 4. Fallback to using wc_GenerateSeed directly.
*/ */
/* Seed source can be overriden by defining one of these: /* Seed source can be overriden by defining one of these:
@@ -83,11 +88,7 @@
#elif defined(HAVE_WNR) #elif defined(HAVE_WNR)
/* allow whitewood as direct RNG source using wc_GenerateSeed directly */ /* allow whitewood as direct RNG source using wc_GenerateSeed directly */
#else #else
#ifndef _MSC_VER #error No RNG source defined!
#warning "No RNG source defined. Using wc_GenerateSeed directly"
#else
#pragma message("Warning: No RNG source defined. Using wc_GenerateSeed directly")
#endif
#endif #endif
#ifdef HAVE_WNR #ifdef HAVE_WNR
@@ -124,26 +125,25 @@ typedef struct OS_Seed {
#define WC_RNG_TYPE_DEFINED #define WC_RNG_TYPE_DEFINED
#endif #endif
#ifndef CUSTOM_RAND_GENERATE_BLOCK
#define DRBG_SEED_LEN (440/8)
struct DRBG; /* Private DRBG state */
/* Hash-based Deterministic Random Bit Generator */
struct WC_RNG {
#ifdef HAVE_HASHDRBG #ifdef HAVE_HASHDRBG
/* Private DRBG state */
struct DRBG;
#endif
/* RNG context */
struct WC_RNG {
OS_Seed seed;
void* heap;
#ifdef HAVE_HASHDRBG
/* Hash-based Deterministic Random Bit Generator */
struct DRBG* drbg; struct DRBG* drbg;
byte status; byte status;
#endif #endif
OS_Seed seed;
void* heap;
#ifdef WOLFSSL_ASYNC_CRYPT #ifdef WOLFSSL_ASYNC_CRYPT
AsyncCryptDev asyncDev; AsyncCryptDev asyncDev;
#endif #endif
}; };
#endif /* !CUSTOM_RAND_GENERATE_BLOCK */
#endif /* HAVE_FIPS */ #endif /* HAVE_FIPS */
/* NO_OLD_RNGNAME removes RNG struct name to prevent possible type conflicts, /* NO_OLD_RNGNAME removes RNG struct name to prevent possible type conflicts,
@@ -152,6 +152,7 @@ struct WC_RNG {
#define RNG WC_RNG #define RNG WC_RNG
#endif #endif
WOLFSSL_LOCAL WOLFSSL_LOCAL
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz); int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);