;;; Carry some entropy across reboots. Adapted from examples in random(4). ;;; We assume Linux >= 2.6, where the poolsize is always 4096 bits (according to ;;; random(4). Otherwise, the example in random(4) reads the 'poolsize' file and ;;; creates a seed of equal size. ;;; This should be run during system shutdown. It saves some random state as a ;;; seed for /dev/urandom, to be used on the next boot. (define (urandom-shutdown seed) (touch seed) (chmod seed #o600) (write-seed seed)) ;;; This should be run at boot, before starting anything that needs random ;;; numbers (sshd, TLS server, etc). (define (urandom-boot seed) (and (if (file-exists? seed) (zero? (system (string-append "cat " seed " > /dev/urandom"))) (touch seed)) (chmod seed #o600) (write-seed seed))) ;;; On Debian, '/var/lib/urandom/random-seed'. ;;; random(4) suggests '/var/run/random-seed'. (define seed "/tmp/random-seed") (define (write-seed seed) (zero? (system* "dd" "if=/dev/urandom" (string-append "of=" seed) "count=1" "bs=512"))) ;; If Linux is not >= 2.6, then 'bs' ;; must be calculated as shown in ;; random(4). (define (touch file) (close-port (open-file file "a0b")))