mbedTLS: Add ESP8266 hardware entropy source discovered by @foogod
Addresses #3, provided turns out to be an effective HWRNG.
This commit is contained in:
parent
1b22cc088e
commit
b03f279f74
3 changed files with 76 additions and 3 deletions
27
extras/mbedtls/hardware_entropy.c
Normal file
27
extras/mbedtls/hardware_entropy.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ESP8266 "Hardware RNG" (validity still being confirmed) support for ESP8266
|
||||
*
|
||||
* Based on research done by @foogod.
|
||||
*
|
||||
* Please don't rely on this too much as an entropy source, quite yet...
|
||||
*
|
||||
* Part of esp-open-rtos
|
||||
* Copyright (C) 2015 Angus Gratton
|
||||
* BSD Licensed as described in the file LICENSE
|
||||
*/
|
||||
#include <mbedtls/entropy_poll.h>
|
||||
#include <esp/wdev_regs.h>
|
||||
#include <string.h>
|
||||
|
||||
int mbedtls_hardware_poll( void *data,
|
||||
unsigned char *output, size_t len, size_t *olen )
|
||||
{
|
||||
(void)(data);
|
||||
for(int i = 0; i < len; i+=4) {
|
||||
uint32_t random = WDEV.HWRNG;
|
||||
/* using memcpy here in case output is unaligned */
|
||||
memcpy(output + i, &random, (i+4 <= len) ? 4 : (len % 4));
|
||||
}
|
||||
if(olen)
|
||||
*olen = len;
|
||||
return 0;
|
||||
}
|
|
@ -289,7 +289,8 @@
|
|||
*
|
||||
* Uncomment to use your own hardware entropy collector.
|
||||
*/
|
||||
//#define MBEDTLS_ENTROPY_HARDWARE_ALT
|
||||
/* hardware RNG interface provided in hardware_entropy.c */
|
||||
#define MBEDTLS_ENTROPY_HARDWARE_ALT
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_AES_ROM_TABLES
|
||||
|
@ -777,7 +778,7 @@
|
|||
* This option is only useful if both MBEDTLS_SHA256_C and
|
||||
* MBEDTLS_SHA512_C are defined. Otherwise the available hash module is used.
|
||||
*/
|
||||
//#define MBEDTLS_ENTROPY_FORCE_SHA256
|
||||
#define MBEDTLS_ENTROPY_FORCE_SHA256
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_MEMORY_DEBUG
|
||||
|
@ -2350,7 +2351,8 @@
|
|||
|
||||
/* CTR_DRBG options */
|
||||
//#define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 /**< Amount of entropy used per seed by default (48 with SHA-512, 32 with SHA-256) */
|
||||
//#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 /**< Interval before reseed is performed by default */
|
||||
/* this is normally 10x higher, but reseeding seems quite inexpensive on esp8266 */
|
||||
#define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 1000 /**< Interval before reseed is performed by default */
|
||||
//#define MBEDTLS_CTR_DRBG_MAX_INPUT 256 /**< Maximum number of additional input bytes */
|
||||
//#define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 /**< Maximum number of requested bytes per call */
|
||||
//#define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 /**< Maximum size of (re)seed buffer */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue