Enhance randomness (AVR, ESP8266, Linux, NRF5) (#845)
This commit changes the way random numbers are available with MySensors. The AVR platform uses a 32 Bit random seed build from a floating analog pin. The way of the generation of this seed is FIPS 140-2 compliant. For support MCU with a fast way to generate random data, the hwGetentropy() command is now available to allow rapid generation of random data. The ESP8266 platform uses the internal random source for randomness for hwGetentropy() and Arduino's random() function. The NRF5 platform initializes the pseudo random number generator from internal hardware number generator. The internal AES-ECB unit generates random data after filling with HWRNG data by AES-CBC. On Linux getrandom() is implemented via syscall(). signerAtsha204SoftGetNonce speed: AVR = ~14000us (sha204Soft) NRF51 = ~152us (AES-CBC), 1739us (old sha204Soft) NRF52 = ~31us (AES-CBC), 183us (old sha204Soft) ESP8266 = ~20us (RANDOM_REG32), 380us (old sha204Soft) All Nonce results tested for FIPS 140-2 compliance successfully.
This commit is contained in:
@@ -59,6 +59,8 @@ void hwWriteConfigBlock(void *buf, void *adr, size_t length);
|
||||
void hwWriteConfig(int adr, uint8_t value);
|
||||
uint8_t hwReadConfig(int adr);
|
||||
void hwRandomNumberInit();
|
||||
ssize_t hwGetentropy(void *__buffer, size_t __length);
|
||||
#define MY_HW_HAS_GETRANDOM
|
||||
|
||||
#ifndef MY_SERIALDEVICE
|
||||
#define MY_SERIALDEVICE Serial
|
||||
@@ -110,6 +112,20 @@ static __inline__ void __priMaskRestore(const uint32_t *priMask)
|
||||
#define MY_HW_RTC_IRQN RTC0_IRQn
|
||||
#endif
|
||||
|
||||
/** Datastructure for AES ECB unit
|
||||
*/
|
||||
typedef struct {
|
||||
/** AES Key
|
||||
*/
|
||||
uint8_t key[16];
|
||||
/** Unencrypted data
|
||||
*/
|
||||
uint8_t cleartext[16];
|
||||
/** Encrypted data
|
||||
*/
|
||||
uint8_t ciphertext[16];
|
||||
} nrf_ecb_t;
|
||||
|
||||
#ifndef DOXYGEN
|
||||
#define MY_CRITICAL_SECTION
|
||||
// temp. commented, to fix "CircularBuffer.h:94:2: warning: control reaches end of non-void function" error
|
||||
|
||||
Reference in New Issue
Block a user