From 7432d83676c2d9fde390932f72d3847764fcc116 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 2 Apr 2015 06:37:52 +1000 Subject: [PATCH] Wait for entropy pool to fill and autosave in TestRNG example --- libraries/Crypto/examples/TestRNG/TestRNG.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/Crypto/examples/TestRNG/TestRNG.ino b/libraries/Crypto/examples/TestRNG/TestRNG.ino index 7686cb7a..2304a5a0 100644 --- a/libraries/Crypto/examples/TestRNG/TestRNG.ino +++ b/libraries/Crypto/examples/TestRNG/TestRNG.ino @@ -21,6 +21,7 @@ TransistorNoiseSource noise(A1); bool calibrating = false; byte data[32]; unsigned long startTime; +size_t length = 48; // First block should wait for the pool to fill up. void setup() { Serial.begin(9600); @@ -65,8 +66,10 @@ void loop() { RNG.loop(); // Generate output whenever 32 bytes of entropy have been accumulated. - if (RNG.available(sizeof(data))) { + // The first time through, we wait for 48 bytes for a full entropy pool. + if (RNG.available(length)) { RNG.rand(data, sizeof(data)); printHex(data, sizeof(data)); + length = 32; } }