GaloisInc / HaLVM

The Haskell Lightweight Virtual Machine (HaLVM): GHC running on Xen
BSD 3-Clause "New" or "Revised" License
1.05k stars 88 forks source link

Optionally emulate /dev/urandom CRNG for transparent entropy on cryptonite #127

Closed protoben closed 6 years ago

protoben commented 6 years ago

For some applications (e.g., using libraries that rely on cryptonite's getRandomBytes run in IO on architectures without the RDRAND instruction), it would be useful to have a source of entropy on HaLVM with a transparent interface via reading /dev/urandom. This branch accomplishes that.

If --enable-urandom is passed to configure, the functions in System.IO, Data.ByteString, etc., that could be used to read /dev/urandom succeed. The bytes returned are the output of a port of the ChaCha20 CRNG used in Linux 4.14 for /dev/urandom. The CRNG is seeded with the low-order bits of multiple invocations of rdtsc, which is what Linux does on x86_64 when RDRAND isn't available.

If nothing or --disable-urandom is passed to configure, all associated code is removed by the prerocessor.

protoben commented 6 years ago

Associated PRs on other repos: