forked from wolfSSL/wolfssl
Merge branch 'custom-seed'
This commit is contained in:
@ -10,4 +10,4 @@ uint32_t hw_get_time_sec(void);
|
||||
uint32_t hw_get_time_msec(void);
|
||||
void hw_uart_printchar(int c);
|
||||
void hw_watchdog_disable(void);
|
||||
int hw_rand(void);
|
||||
uint32_t hw_rand(void);
|
||||
|
@ -167,7 +167,7 @@ void hw_uart_printchar(int c)
|
||||
UART_PORT->D = (uint8_t)c; /* Send the character */
|
||||
}
|
||||
|
||||
int hw_rand(void)
|
||||
uint32_t hw_rand(void)
|
||||
{
|
||||
while((RNG->SR & RNG_SR_OREG_LVL(0xF)) == 0) {}; /* Wait until FIFO has a value available */
|
||||
return RNG->OR; /* Return next value in FIFO output register */
|
||||
|
@ -29,7 +29,7 @@ double current_time(int reset)
|
||||
return time;
|
||||
}
|
||||
|
||||
int custom_rand_generate(void)
|
||||
uint32_t custom_rand_generate(void)
|
||||
{
|
||||
return hw_rand();
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
/* Custom functions */
|
||||
extern int custom_rand_generate(void);
|
||||
#define CUSTOM_RAND_GENERATE custom_rand_generate
|
||||
#define CUSTOM_RAND_TYPE word32
|
||||
#define WOLFSSL_USER_CURRTIME
|
||||
|
||||
/* Debugging - Optional */
|
||||
|
@ -10,12 +10,14 @@
|
||||
project_type="Library" />
|
||||
<folder Name="Source Files">
|
||||
<configuration Name="Common" filter="c;cpp;cxx;cc;h;s;inc" />
|
||||
<folder
|
||||
Name="wolfcrypt"
|
||||
exclude="*.asm;*.s"
|
||||
filter=""
|
||||
path="../../wolfcrypt"
|
||||
recurse="Yes" />
|
||||
<folder Name="wolfcrypt">
|
||||
<folder Name="benchmark" path="../../wolfcrypt/benchmark" />
|
||||
<folder Name="src" path="../../wolfcrypt/src" />
|
||||
<folder Name="test" path="../../wolfcrypt/test" />
|
||||
<folder Name="user-crypto" path="../../wolfcrypt/user-crypto">
|
||||
<configuration Name="Common" build_exclude_from_build="Yes" />
|
||||
</folder>
|
||||
</folder>
|
||||
<folder
|
||||
Name="wolfssl"
|
||||
exclude="*.asm;*.s"
|
||||
@ -24,6 +26,12 @@
|
||||
recurse="Yes" />
|
||||
<file file_name="user_settings.h" />
|
||||
<file file_name="README.md" />
|
||||
<folder
|
||||
Name="source"
|
||||
exclude=""
|
||||
filter=""
|
||||
path="../../src"
|
||||
recurse="No" />
|
||||
</folder>
|
||||
</project>
|
||||
<project Name="test">
|
||||
|
@ -32,6 +32,12 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
|
||||
#if defined(CUSTOM_RAND_GENERATE) && !defined(CUSTOM_RAND_TYPE)
|
||||
/* To maintain compatiblity the default return vaule from CUSTOM_RAND_GENERATE is byte */
|
||||
#define CUSTOM_RAND_TYPE byte
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_FIPS
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz)
|
||||
{
|
||||
@ -973,8 +979,22 @@ static int wc_GenerateRand_IntelRD(OS_Seed* os, byte* output, word32 sz)
|
||||
#endif /* HAVE_INTEL_RDGEN */
|
||||
|
||||
|
||||
#if defined(USE_WINDOWS_API)
|
||||
/* wc_GenerateSeed Implementations */
|
||||
#if defined(CUSTOM_RAND_GENERATE_SEED)
|
||||
|
||||
/* Implement your own random generation function
|
||||
* Return 0 to indicate success
|
||||
* int rand_gen_seed(byte* output, word32 sz);
|
||||
* #define CUSTOM_RAND_GENERATE_SEED rand_gen_seed */
|
||||
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
(void)os;
|
||||
return CUSTOM_RAND_GENERATE_SEED(output, sz);
|
||||
}
|
||||
|
||||
|
||||
#elif defined(USE_WINDOWS_API)
|
||||
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
@ -1088,7 +1108,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
#elif defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX) || \
|
||||
defined(FREESCALE_KSDK_BM) || defined(FREESCALE_FREE_RTOS)
|
||||
|
||||
#ifdef FREESCALE_K70_RNGA
|
||||
#if defined(FREESCALE_K70_RNGA) || defined(FREESCALE_RNGA)
|
||||
/*
|
||||
* wc_Generates a RNG seed using the Random Number Generator Accelerator
|
||||
* on the Kinetis K70. Documentation located in Chapter 37 of
|
||||
@ -1122,7 +1142,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(FREESCALE_K53_RNGB)
|
||||
#elif defined(FREESCALE_K53_RNGB) || defined(FREESCALE_RNGB)
|
||||
/*
|
||||
* wc_Generates a RNG seed using the Random Number Generator (RNGB)
|
||||
* on the Kinetis K53. Documentation located in Chapter 33 of
|
||||
@ -1165,7 +1185,7 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
TRNG_DRV_GetRandomData(TRNG_INSTANCE, output, sz);
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
@ -1273,12 +1293,25 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
word32 i;
|
||||
word32 i = 0;
|
||||
|
||||
(void)os;
|
||||
|
||||
for (i = 0; i < sz; i++ )
|
||||
output[i] = CUSTOM_RAND_GENERATE();
|
||||
while (i < sz)
|
||||
{
|
||||
/* If not aligned or there is odd/remainder */
|
||||
if( (i + sizeof(CUSTOM_RAND_TYPE)) > sz ||
|
||||
((wolfssl_word)&output[i] % sizeof(CUSTOM_RAND_TYPE)) != 0
|
||||
) {
|
||||
/* Single byte at a time */
|
||||
output[i++] = (byte)CUSTOM_RAND_GENERATE();
|
||||
}
|
||||
else {
|
||||
/* Use native 8, 16, 32 or 64 copy instruction */
|
||||
*((CUSTOM_RAND_TYPE*)&output[i]) = CUSTOM_RAND_GENERATE();
|
||||
i += sizeof(CUSTOM_RAND_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user