Browse Source

rng: delay 256 μs before reading a random number

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...
H. Peter Anvin 3 years ago
parent
commit
dac6cd700a
7 changed files with 7041 additions and 7034 deletions
  1. BIN
      fpga/output_files/max80.jbc
  2. BIN
      fpga/output_files/max80.jic
  3. BIN
      fpga/output_files/max80.pof
  4. BIN
      fpga/output_files/max80.sof
  5. 7032 7032
      rv32/boot.mif
  6. 7 0
      rv32/io.h
  7. 2 2
      rv32/system.c

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


File diff suppressed because it is too large
+ 7032 - 7032
rv32/boot.mif


+ 7 - 0
rv32/io.h

@@ -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 */

+ 2 - 2
rv32/system.c

@@ -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);
 	}
     }

Some files were not shown because too many files changed in this diff