|
|
@@ -98,6 +98,36 @@ hydro_random_init(void)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+#elif defined(PARTICLE) && defined(PLATFORM_ID) && PLATFORM_ID > 2 && !defined(__unix__)
|
|
|
+
|
|
|
+// Note: All particle platforms except for the Spark Core have a HW RNG. Only allow building on supported platforms for now.
|
|
|
+// PLATFORM_ID definitions: https://github.com/particle-iot/device-os/blob/mesh-develop/hal/shared/platforms.h
|
|
|
+
|
|
|
+#include "Particle.h"
|
|
|
+
|
|
|
+static int
|
|
|
+hydro_random_init(void)
|
|
|
+{
|
|
|
+ const char ctx[hydro_hash_CONTEXTBYTES] = { 'h', 'y', 'd', 'r', 'o', 'P', 'R', 'G' };
|
|
|
+ hydro_hash_state st;
|
|
|
+ uint16_t ebits = 0;
|
|
|
+
|
|
|
+ hydro_hash_init(&st, ctx, NULL);
|
|
|
+
|
|
|
+ while (ebits < 256) {
|
|
|
+ uint32_t r = HAL_RNG_GetRandomNumber();
|
|
|
+
|
|
|
+ delay(10);
|
|
|
+ hydro_hash_update(&st, (const uint32_t *) &r, sizeof r);
|
|
|
+ ebits += 32;
|
|
|
+ }
|
|
|
+
|
|
|
+ hydro_hash_final(&st, hydro_random_context.state, sizeof hydro_random_context.state);
|
|
|
+ hydro_random_context.counter = ~LOAD64_LE(hydro_random_context.state);
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
#elif (defined(NRF52832_XXAA) || defined(NRF52832_XXAB)) && !defined(__unix__)
|
|
|
|
|
|
// Important: The SoftDevice *must* be activated to enable reading from the RNG
|