20151211_RNG

This commit is contained in:
tekka007
2015-12-11 16:17:36 +01:00
parent 714d630c92
commit ec0a5d2bc6
2 changed files with 6 additions and 3 deletions
@@ -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"));
@@ -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);