mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-03 12:44:45 +02:00
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:
@@ -278,17 +278,21 @@ extern "C" {
|
||||
/* Size of returned HW RNG value */
|
||||
#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 */
|
||||
#if 1
|
||||
/* Use built-in P-RNG (SHA256 based) with HW RNG */
|
||||
/* P-RNG + HW RNG (P-RNG is ~8K) */
|
||||
#undef HAVE_HASHDRBG
|
||||
#define HAVE_HASHDRBG
|
||||
|
||||
extern unsigned int custom_rand_generate(void);
|
||||
#undef CUSTOM_RAND_GENERATE
|
||||
#define CUSTOM_RAND_GENERATE custom_rand_generate
|
||||
#else
|
||||
#undef WC_NO_HASHDRBG
|
||||
#define WC_NO_HASHDRBG
|
||||
|
||||
/* Bypass P-RNG and use only HW RNG */
|
||||
extern int custom_rand_generate_block(unsigned char* output, unsigned int sz);
|
||||
#undef CUSTOM_RAND_GENERATE_BLOCK
|
||||
|
@@ -122,12 +122,26 @@
|
||||
recurse="Yes" />
|
||||
<file file_name="user_settings.h" />
|
||||
<file file_name="README.md" />
|
||||
<folder
|
||||
Name="source"
|
||||
exclude=""
|
||||
filter=""
|
||||
path="../../src"
|
||||
recurse="No" />
|
||||
<folder Name="source">
|
||||
<file file_name="../../src/bio.c">
|
||||
<configuration Name="ARM_Debug" build_exclude_from_build="Yes" />
|
||||
</file>
|
||||
<file file_name="../../src/crl.c" />
|
||||
<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>
|
||||
</project>
|
||||
<project Name="test">
|
||||
|
@@ -103,20 +103,25 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
|
||||
int wnr_timeout = 0; /* entropy timeout, mililseconds */
|
||||
int wnr_mutex_init = 0; /* flag for mutex init */
|
||||
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)
|
||||
#include "fsl_trng.h"
|
||||
#elif defined(FREESCALE_KSDK_2_0_RNGA)
|
||||
#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
|
||||
/* include headers that may be needed to get good seed */
|
||||
#include <fcntl.h>
|
||||
#ifndef EBSNET
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -602,13 +607,9 @@ int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz)
|
||||
}
|
||||
#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 */
|
||||
ret = RNG_FAILURE_E;
|
||||
|
||||
#endif /* HAVE_HASHDRBG */
|
||||
|
||||
return ret;
|
||||
@@ -1590,6 +1591,11 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
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_LEANPSK)
|
||||
#elif defined(WOLFSSL_IAR_ARM)
|
||||
|
@@ -1025,8 +1025,7 @@ int base64_test()
|
||||
int asn_test()
|
||||
{
|
||||
#ifndef NO_ASN_TIME
|
||||
{
|
||||
time_t now;
|
||||
long now;
|
||||
|
||||
/* Parameter Validation tests. */
|
||||
if (wc_GetTime(NULL, sizeof(now)) != BAD_FUNC_ARG)
|
||||
@@ -1039,7 +1038,6 @@ int asn_test()
|
||||
return -102;
|
||||
if (now == 0)
|
||||
return -103;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@@ -35,11 +35,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Maximum generate block length */
|
||||
/* Maximum generate block length */
|
||||
#ifndef RNG_MAX_BLOCK_LEN
|
||||
#define RNG_MAX_BLOCK_LEN (0x10000)
|
||||
#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)
|
||||
/* To maintain compatibility the default is byte */
|
||||
#define CUSTOM_RAND_TYPE byte
|
||||
@@ -61,7 +67,6 @@
|
||||
* 2. HAVE_INTEL_RDRAND: Uses the Intel RDRAND if supported by CPU.
|
||||
* 3. HAVE_HASHDRBG (requires SHA256 enabled): Uses SHA256 based P-RNG
|
||||
* 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:
|
||||
@@ -83,11 +88,7 @@
|
||||
#elif defined(HAVE_WNR)
|
||||
/* allow whitewood as direct RNG source using wc_GenerateSeed directly */
|
||||
#else
|
||||
#ifndef _MSC_VER
|
||||
#warning "No RNG source defined. Using wc_GenerateSeed directly"
|
||||
#else
|
||||
#pragma message("Warning: No RNG source defined. Using wc_GenerateSeed directly")
|
||||
#endif
|
||||
#error No RNG source defined!
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WNR
|
||||
@@ -124,26 +125,25 @@ typedef struct OS_Seed {
|
||||
#define WC_RNG_TYPE_DEFINED
|
||||
#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
|
||||
/* 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;
|
||||
byte status;
|
||||
#endif
|
||||
OS_Seed seed;
|
||||
void* heap;
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
AsyncCryptDev asyncDev;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* !CUSTOM_RAND_GENERATE_BLOCK */
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
/* NO_OLD_RNGNAME removes RNG struct name to prevent possible type conflicts,
|
||||
@@ -152,6 +152,7 @@ struct WC_RNG {
|
||||
#define RNG WC_RNG
|
||||
#endif
|
||||
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
|
||||
|
||||
|
Reference in New Issue
Block a user