Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: random/random.c
- Revision:
- 64:d1b9e47aa754
diff -r 28738aaad2a8 -r d1b9e47aa754 random/random.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/random/random.c Fri Apr 12 13:03:45 2019 +0000
@@ -0,0 +1,26 @@
+#include <stdint.h>
+
+#include "hrtimer.h"
+#include "random.h"
+
+/*
+Uses the low 8 bits of the hrtimer to give the number of cycles per scan.
+The cycles per scan depends on many factors including network activity.
+Network activity has a high entropy as it depends on many machines and human activity.
+The minimum scan is typically at least 5000 so taking the low 8 bits should be indeterminate.
+*/
+
+uint8_t RandomBytes[RANDOM_LENGTH];
+
+void RandomMain()
+{
+ //Establish the scan time
+ static uint32_t scanTimer = 0;
+ uint32_t elapsed = HrTimerSinceRepetitive(&scanTimer);
+
+ //Make the random number using the low 8 bits of the scan time as entropy
+ static int position = 0;
+ RandomBytes[position] ^= elapsed & 0xFF;
+ position++;
+ if (position >= RANDOM_LENGTH) position = 0;
+}
\ No newline at end of file