The random number generator is currently not rate-limited in hardware. Add a 256 μs delay - picked out of thin air - to allow the rng to accumulate enough bits of entropy. Should probably run the FIPS test suite to tune this number...
@@ -81,4 +81,11 @@ static inline void wait_romcopy_done(void)
pause();
}
+/* Read a random 32-bit number */
+static inline uint32_t rdrand(void)
+{
+ udelay(256); /* Allow the RNG to do its job */
+ return SYS_RANDOM;
+}
+
#endif /* IO_H */
@@ -104,8 +104,8 @@ void init(void)
if ( 1 ) {
con_puts("Random number generator test:\n");
for (int i = 0; i < 8; i++) {
- uint32_t a = SYS_RANDOM;
- uint32_t b = SYS_RANDOM;
+ uint32_t a = rdrand();
+ uint32_t b = rdrand();
con_printf("%08x %08x delta %08x\n", a, b, a^b);