rweather / arduinolibs

Arduino Cryptography Library
444 stars 212 forks source link

RNG Watchdog compilation error for Arduino Uno WiFi rev2 #49

Open JurriaanD opened 4 years ago

JurriaanD commented 4 years ago

Hi, I've been using your library on an Arduino Uno and everythings works great (thank you!). However, when I try to compile for the Arduino Uno WiFi rev2, I get a long list of errors from the RNG.cpp file. (error log below). The lines mentioned in the error log are related to the RNG watchdog. I found #31 and the suggested fix did stop the compiler errors, but I'm not sure what noise source to replace it with/how to do it.

Steps to reproduce:

This happens on Windows 10 as well as Arch Linux.

Full error log (pastebin)

Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno WiFi Rev2, ATMEGA328"

[System data, see pastebin]

C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp: In function 'void WDT_vect()':

C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:239:27: error: 'TCNT0' was not declared in this scope
     unsigned char value = TCNT0;
                           ^~~~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:239:27: note: suggested alternative: 'TCA0'
     unsigned char value = TCNT0;
                           ^~~~~
                           TCA0
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp: In destructor 'RNGClass::~RNGClass()':
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:288:5: error: 'MCUSR' was not declared in this scope
     MCUSR &= ~(1 << WDRF);
     ^~~~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:288:21: error: 'WDRF' was not declared in this scope
     MCUSR &= ~(1 << WDRF);
                     ^~~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:288:21: note: suggested alternative: 'DDRD'
     MCUSR &= ~(1 << WDRF);
                     ^~~~
                     DDRD
In file included from C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:37:0:
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:291:30: error: 'WDCE' was not declared in this scope
     _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
                              ^
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:291:30: note: suggested alternative: 'ADC0'
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:291:54: error: 'WDE' was not declared in this scope
     _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
                                                      ^~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:291:54: note: suggested alternative: 'WDT'
     _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
                                                      ^~~
                                                      WDT
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:292:23: error: no match for 'operator=' (operand types are 'WDT_t {aka WDT_struct}' and 'int')
     _WD_CONTROL_REG = 0;
                       ^
In file included from c:\users\jurriaan\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\io.h:677:0,
                 from c:\users\jurriaan\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\pgmspace.h:90,
                 from C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\utility/ProgMemUtil.h:27,
                 from C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:27:
c:\users\jurriaan\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\iom4809.h:2054:16: note: candidate: WDT_struct& WDT_struct::operator=(const WDT_struct&)
 typedef struct WDT_struct
                ^~~~~~~~~~
c:\users\jurriaan\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\iom4809.h:2054:16: note:   no known conversion for argument 1 from 'int' to 'const WDT_struct&'
c:\users\jurriaan\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\iom4809.h:2054:16: note: candidate: WDT_struct& WDT_struct::operator=(WDT_struct&&)
c:\users\jurriaan\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino5\avr\include\avr\iom4809.h:2054:16: note:   no known conversion for argument 1 from 'int' to 'WDT_struct&&'
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp: In member function 'void RNGClass::begin(const char*)':
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:485:5: error: 'MCUSR' was not declared in this scope
     MCUSR &= ~(1 << WDRF);
     ^~~~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:485:21: error: 'WDRF' was not declared in this scope
     MCUSR &= ~(1 << WDRF);
                     ^~~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:485:21: note: suggested alternative: 'DDRD'
     MCUSR &= ~(1 << WDRF);
                     ^~~~
                     DDRD
In file included from C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:37:0:
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:489:30: error: 'WDCE' was not declared in this scope
     _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
                              ^
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:489:30: note: suggested alternative: 'ADC0'
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:489:54: error: 'WDE' was not declared in this scope
     _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
                                                      ^~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:489:54: note: suggested alternative: 'WDT'
     _WD_CONTROL_REG |= (1 << _WD_CHANGE_BIT) | (1 << WDE);
                                                      ^~~
                                                      WDT
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:490:29: error: 'WDIE' was not declared in this scope
     _WD_CONTROL_REG = (1 << WDIE);
                             ^~~~
C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto\src\RNG.cpp:490:29: note: suggested alternative: 'WDT'
     _WD_CONTROL_REG = (1 << WDIE);
                             ^~~~
                             WDT
"C:\\Users\\Jurriaan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino5/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10812 -DARDUINO_AVR_UNO_WIFI_REV2 -DARDUINO_ARCH_MEGAAVR -DUNO_WIFI_REV2_328MODE -DMILLIS_USE_TIMERB3 "-IC:\\Users\\Jurriaan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.5\\cores\\arduino/api/deprecated" "-IC:\\Users\\Jurriaan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.5\\cores\\arduino" "-IC:\\Users\\Jurriaan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\megaavr\\1.8.5\\variants\\uno2018" "-IC:\\Users\\Jurriaan\\Documents\\Arduino\\libraries\\Crypto\\src" "C:\\Users\\Jurriaan\\Documents\\Arduino\\libraries\\Crypto\\src\\XTS.cpp" -o "C:\\Users\\Jurriaan\\AppData\\Local\\Temp\\arduino_build_653946\\libraries\\Crypto\\XTS.cpp.o"
Using library Crypto at version 0.2.0 in folder: C:\Users\Jurriaan\Documents\Arduino\libraries\Crypto 
exit status 1
Error compiling for board Arduino Uno WiFi Rev2.
rweather commented 4 years ago

According to the web page for the Uno+Wifi rev2, it includes a "ECC608 crypto chip accelerator" for security purposes. According to the web page for the ECC608, it includes a random number generator: https://www.microchip.com/wwwproducts/en/ATECC608A.

If you can figure out how to access the ECC608's random number functionality from a sketch, then you might be able to use that as a noise source for the RNG class. I'm not familiar with that chip myself.