From 912c3769290d1174da60f2321dbdb29c54bcd0a2 Mon Sep 17 00:00:00 2001 From: Ken MacKay Date: Fri, 7 Mar 2014 23:23:36 -0800 Subject: [PATCH] Modified test sketch to use built-in random() function, and made it loop forever. --- ecc_test/ecc_test.ino | 44 +++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/ecc_test/ecc_test.ino b/ecc_test/ecc_test.ino index 2af1283..bf35816 100644 --- a/ecc_test/ecc_test.ino +++ b/ecc_test/ecc_test.ino @@ -15,19 +15,38 @@ #include +extern "C" { + +static int RNG(uint8_t *p_dest, unsigned p_size) +{ + while(p_size) { + long v = random(); + unsigned l_amount = min(p_size, sizeof(long)); + memcpy(p_dest, &v, l_amount); + p_size -= l_amount; + p_dest += l_amount; + } + return 1; +} + +} + void setup() { - Scout.setup(); - uint8_t l_private1[ECC_BYTES]; - uint8_t l_private2[ECC_BYTES]; - - uint8_t l_public1[ECC_BYTES * 2]; - uint8_t l_public2[ECC_BYTES * 2]; - - uint8_t l_secret1[ECC_BYTES]; - uint8_t l_secret2[ECC_BYTES]; - - Serial.print("Testing ecc\n"); - + Scout.setup(); + uint8_t l_private1[ECC_BYTES]; + uint8_t l_private2[ECC_BYTES]; + + uint8_t l_public1[ECC_BYTES * 2]; + uint8_t l_public2[ECC_BYTES * 2]; + + uint8_t l_secret1[ECC_BYTES]; + uint8_t l_secret2[ECC_BYTES]; + + Serial.print("Testing ecc\n"); + + ecc_set_rng(&RNG); + + for(;;) { unsigned long a = millis(); ecc_make_key(l_public1, l_private1); unsigned long b = millis(); @@ -78,6 +97,7 @@ void setup() { { Serial.print("Shared secrets are identical\n"); } + } } void loop() {