From aeceb0b683aacdcc3a6b6d4e132bad01750b962e Mon Sep 17 00:00:00 2001 From: d00616 Date: Tue, 23 May 2017 21:41:46 +0200 Subject: [PATCH] Fix rasperry pi hwGetentropy() (#856) --- hal/architecture/MyHwLinuxGeneric.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hal/architecture/MyHwLinuxGeneric.cpp b/hal/architecture/MyHwLinuxGeneric.cpp index 3c8070d..c6ac805 100644 --- a/hal/architecture/MyHwLinuxGeneric.cpp +++ b/hal/architecture/MyHwLinuxGeneric.cpp @@ -20,7 +20,6 @@ #include "MyHwLinuxGeneric.h" #include -#include #include #include #include @@ -31,6 +30,7 @@ #include "log.h" static SoftEeprom eeprom = SoftEeprom(MY_LINUX_CONFIG_FILE, 1024); // ATMega328 has 1024 bytes +static FILE *randomFp; bool hwInit(void) { @@ -43,6 +43,10 @@ bool hwInit(void) } #endif #endif + if (!(randomFp = fopen("/dev/urandom", "r"))) { + logError("Cannot open '/dev/urandom'.\n"); + exit(2); + } return true; } @@ -75,8 +79,7 @@ void hwRandomNumberInit() ssize_t hwGetentropy(void *__buffer, size_t __length) { - // getrandom syscall - return syscall(SYS_getrandom, __buffer, __length, GRND_NONBLOCK); + return(fread(__buffer, 1, __length, randomFp)); } unsigned long hwMillis()