From ec0a5d2bc6397cabcefc5cf2e83e276938b14bca Mon Sep 17 00:00:00 2001 From: tekka007 Date: Fri, 11 Dec 2015 16:17:36 +0100 Subject: [PATCH] 20151211_RNG --- libraries/MySensors/core/MySensorCore.cpp | 5 +++++ libraries/MySensors/core/MySigningAtsha204Soft.cpp | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/core/MySensorCore.cpp b/libraries/MySensors/core/MySensorCore.cpp index 79f1444..8d79bb6 100644 --- a/libraries/MySensors/core/MySensorCore.cpp +++ b/libraries/MySensors/core/MySensorCore.cpp @@ -63,6 +63,11 @@ void _begin() { #if !defined(MY_DISABLED_SERIAL) hwInit(); #endif + + #if defined(MY_SIGNING_SOFT) + // initialize pseudo-RNG + randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN)); + #endif debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILIIES ", " LIBRARY_VERSION ")\n")); diff --git a/libraries/MySensors/core/MySigningAtsha204Soft.cpp b/libraries/MySensors/core/MySigningAtsha204Soft.cpp index bbf0602..0068222 100644 --- a/libraries/MySensors/core/MySigningAtsha204Soft.cpp +++ b/libraries/MySensors/core/MySigningAtsha204Soft.cpp @@ -91,14 +91,12 @@ static void DEBUG_SIGNING_PRINTBUF(const __FlashStringHelper* str, uint8_t* buf, bool signerGetNonce(MyMessage &msg) { DEBUG_SIGNING_PRINTBUF(F("Signing backend: ATSHA204Soft"), NULL, 0); - // Set randomseed - randomSeed(analogRead(MY_SIGNING_SOFT_RANDOMSEED_PIN)); // We used a basic whitening technique that takes the first byte of a new random value and builds up a 32-byte random value // This 32-byte random value is then hashed (SHA256) to produce the resulting nonce _signing_sha256.init(); for (int i = 0; i < 32; i++) { - _signing_sha256.write(random(255)); + _signing_sha256.write(random(256)); } memcpy(_signing_current_nonce, _signing_sha256.result(), MAX_PAYLOAD); DEBUG_SIGNING_PRINTBUF(F("SHA256: "), _signing_current_nonce, 32);