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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue