Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions IDE/ECLIPSE/MICRIUM/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ static void App_TaskStart (void *p_arg)

10. Now you are ready to download and debug your image on the board.

## Random seed

Micrium provides no entropy source. Unless you configure one, wolfSSL seeds its DRBG from uC/LIB `Math_Rand()` and the build emits a warning saying so. Keys and nonces generated this way are predictable. Before production, supply a hardware RNG in `user_settings.h`:

```
extern int my_trng_seed(unsigned char* output, unsigned int sz); /* return 0 on success */
#define CUSTOM_RAND_GENERATE_SEED my_trng_seed
```

The test results below were collected from the NXP Kinetis K70 (Freescale TWR-K70F120M MCU) tower system board with the following software and tool chains:

- IAR Embedded Workbench IDE - ARM 8.32.1 (IAR ELF Linker V8.32.1.169/W32 for ARM)
Expand Down
3 changes: 3 additions & 0 deletions IDE/ECLIPSE/MICRIUM/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#define MICRIUM

/* Supply a hardware RNG seed via CUSTOM_RAND_GENERATE_SEED for production
* use. See IDE/ECLIPSE/MICRIUM/README.md */

/* You can select one or all of the following tests */
#define WOLFSSL_WOLFCRYPT_TEST
#define WOLFSSL_BENCHMARK_TEST
Expand Down
28 changes: 28 additions & 0 deletions wolfcrypt/src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -10598,6 +10598,34 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
}
}

return 0;
}
#elif defined(MICRIUM) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
#if !defined(_MSC_VER) && !defined(__TASKING__)
#warning "MICRIUM: seeding the DRBG from Math_Rand(), not an entropy source. Define CUSTOM_RAND_GENERATE_SEED to a hardware RNG."
#else
#pragma message("Warning: MICRIUM: seeding the DRBG from Math_Rand(), not an entropy source. Define CUSTOM_RAND_GENERATE_SEED to a hardware RNG.")
#endif
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
{
word32 i = 0;
word32 len;
RAND_NBR rnd;

(void)os;

if (output == NULL)
return BAD_FUNC_ARG;

while (i < sz) {
rnd = Math_Rand();
len = sz - i;
if (len > (word32)sizeof(rnd))
len = (word32)sizeof(rnd);
XMEMCPY(&output[i], &rnd, len);
i += len;
}

return 0;
}
#elif defined(WOLFSSL_VXWORKS)
Expand Down
5 changes: 0 additions & 5 deletions wolfssl/wolfcrypt/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2969,11 +2969,6 @@
#define NO_WOLFSSL_DIR
#define NO_WRITEV

#if !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(STM32_RNG) && \
!defined(CUSTOM_RAND_GENERATE)
#define CUSTOM_RAND_TYPE RAND_NBR
#define CUSTOM_RAND_GENERATE Math_Rand
#endif
#define STRING_USER
#define XSTRCASECMP(s1,s2) strcasecmp((s1),(s2))
#define XSTRCMP(s1,s2) strcmp((s1),(s2))
Expand Down
Loading