particle.h 842 B

1234567891011121314151617181920212223242526
  1. // Note: All particle platforms except for the Spark Core have a HW RNG. Only allow building on
  2. // supported platforms for now. PLATFORM_ID definitions:
  3. // https://github.com/particle-iot/device-os/blob/mesh-develop/hal/shared/platforms.h
  4. #include <Particle.h>
  5. static int
  6. hydro_random_init(void)
  7. {
  8. const char ctx[hydro_hash_CONTEXTBYTES] = { 'h', 'y', 'd', 'r', 'o', 'P', 'R', 'G' };
  9. hydro_hash_state st;
  10. uint16_t ebits = 0;
  11. hydro_hash_init(&st, ctx, NULL);
  12. while (ebits < 256) {
  13. uint32_t r = HAL_RNG_GetRandomNumber();
  14. hydro_hash_update(&st, (const uint32_t *) &r, sizeof r);
  15. ebits += 32;
  16. }
  17. hydro_hash_final(&st, hydro_random_context.state, sizeof hydro_random_context.state);
  18. hydro_random_context.counter = ~LOAD64_LE(hydro_random_context.state);
  19. return 0;
  20. }