Merge pull request #310 from dgarske/CustRngGenBlock

Added new CUSTOM_RAND_GENERATE_BLOCK option that allows override and …
pull/313/head
toddouska 2016-02-12 13:51:06 -08:00
commit 951fe0a927
4 changed files with 43 additions and 8 deletions

View File

@ -89,6 +89,38 @@ int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
#else /* else build without fips */ #else /* else build without fips */
#include <wolfssl/wolfcrypt/error-crypt.h> #include <wolfssl/wolfcrypt/error-crypt.h>
/* Allow custom RNG system */
#ifdef CUSTOM_RAND_GENERATE_BLOCK
int wc_InitRng(WC_RNG* rng)
{
(void)rng;
return 0;
}
int wc_RNG_GenerateBlock(WC_RNG* rng, byte* output, word32 sz)
{
(void)rng;
XMEMSET(output, 0, sz);
return CUSTOM_RAND_GENERATE_BLOCK(output, sz);
}
int wc_RNG_GenerateByte(WC_RNG* rng, byte* b)
{
return wc_RNG_GenerateBlock(rng, b, 1);
}
int wc_FreeRng(WC_RNG* rng)
{
(void)rng;
return 0;
}
#else
/* Use HASHDRGB with SHA256 */
#if defined(HAVE_HASHDRBG) || defined(NO_RC4) #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
#include <wolfssl/wolfcrypt/sha256.h> #include <wolfssl/wolfcrypt/sha256.h>
@ -1432,5 +1464,6 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
} }
#endif /* USE_WINDOWS_API */ #endif /* USE_WINDOWS_API */
#endif /* CUSTOM_RAND_GENERATE_BLOCK */
#endif /* HAVE_FIPS */ #endif /* HAVE_FIPS */

View File

@ -3559,7 +3559,7 @@ int idea_test(void)
#endif /* HAVE_IDEA */ #endif /* HAVE_IDEA */
#if defined(HAVE_HASHDRBG) || defined(NO_RC4) #if (defined(HAVE_HASHDRBG) || defined(NO_RC4)) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
int random_test(void) int random_test(void)
{ {
@ -3635,7 +3635,7 @@ int random_test(void)
return 0; return 0;
} }
#else /* HAVE_HASHDRBG || NO_RC4 */ #else /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */
int random_test(void) int random_test(void)
{ {
@ -3658,7 +3658,7 @@ int random_test(void)
return 0; return 0;
} }
#endif /* HAVE_HASHDRBG || NO_RC4 */ #endif /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */
#ifdef HAVE_NTRU #ifdef HAVE_NTRU

View File

@ -67,8 +67,8 @@ typedef struct OS_Seed {
#endif #endif
} OS_Seed; } OS_Seed;
#if defined(HAVE_HASHDRBG) || defined(NO_RC4)
#if (defined(HAVE_HASHDRBG) || defined(NO_RC4)) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
#define DRBG_SEED_LEN (440/8) #define DRBG_SEED_LEN (440/8)
@ -84,8 +84,8 @@ typedef struct WC_RNG {
} WC_RNG; } WC_RNG;
#else /* HAVE_HASHDRBG || NO_RC4 */
#else /* (HAVE_HASHDRBG || NO_RC4) && !CUSTOM_RAND_GENERATE_BLOCK */
#define WOLFSSL_RNG_CAVIUM_MAGIC 0xBEEF0004 #define WOLFSSL_RNG_CAVIUM_MAGIC 0xBEEF0004
@ -94,7 +94,9 @@ typedef struct WC_RNG {
typedef struct WC_RNG { typedef struct WC_RNG {
OS_Seed seed; OS_Seed seed;
#ifndef NO_RC4
Arc4 cipher; Arc4 cipher;
#endif
#ifdef HAVE_CAVIUM #ifdef HAVE_CAVIUM
int devId; /* nitrox device id */ int devId; /* nitrox device id */
word32 magic; /* using cavium magic */ word32 magic; /* using cavium magic */
@ -102,8 +104,8 @@ typedef struct WC_RNG {
} WC_RNG; } WC_RNG;
#endif /* HAVE_HASH_DRBG || NO_RC4 */
#endif /* (HAVE_HASHDRBG || NO_RC4) && !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,

View File

@ -1019,9 +1019,9 @@ static char *fgets(char *buff, int sz, FILE *fp)
#define NO_OLD_TLS #define NO_OLD_TLS
#endif #endif
/* If not forcing to use ARC4 as the DRBG, always enable Hash_DRBG */ /* If not forcing ARC4 as the DRBG or using custom RNG block gen, enable Hash_DRBG */
#undef HAVE_HASHDRBG #undef HAVE_HASHDRBG
#ifndef WOLFSSL_FORCE_RC4_DRBG #if !defined(WOLFSSL_FORCE_RC4_DRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
#define HAVE_HASHDRBG #define HAVE_HASHDRBG
#endif #endif