summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-08-09 18:19:18 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-08-09 18:19:18 +0200
commit7851407fe89228897d01278bb1929f817821a701 (patch)
treebc15b7bcc143404fc510214a587e2f0a29df4dea
parent15b4bbfc33689b3780b1767301c8e8d6a2084875 (diff)
downloadscripts-7851407fe89228897d01278bb1929f817821a701.tar.gz
hwrand.pl,hwrand.py: forward randomness
Continuously fills the entropy pool from /dev/hwrng, crediting 4 bits of entropy per byte. Hopefully speeds up the provisioning of a test VM that invokes pacman-key --init... Authored by me, posted on https://unix.stackexchange.com/a/302338/8250
-rwxr-xr-xhwrand.pl8
-rwxr-xr-xhwrand.py7
2 files changed, 15 insertions, 0 deletions
diff --git a/hwrand.pl b/hwrand.pl
new file mode 100755
index 0000000..87fd667
--- /dev/null
+++ b/hwrand.pl
@@ -0,0 +1,8 @@
+#!/usr/bin/perl
+open my $hw, "</dev/hwrng" and open my $rnd, "</dev/random" or die;
+for (;;) {
+ my $l = read $hw, my $d, 512;
+ ioctl $rnd, 0x40085203, pack("ii", 4 * $l, $l) . $d or die;
+ vec(my $w, fileno $rnd, 1) = 1;
+ select undef, $w, undef, undef
+}
diff --git a/hwrand.py b/hwrand.py
new file mode 100755
index 0000000..92016a1
--- /dev/null
+++ b/hwrand.py
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+import fcntl, select, struct
+with open('/dev/hwrng', 'rb') as hw, open('/dev/random') as rnd:
+ while True:
+ d = hw.read(512)
+ fcntl.ioctl(rnd, 0x40085203, struct.pack('ii', 4 * len(d), len(d)) + d)
+ select.select([], [rnd], [])