pseudo_random and arc4random
robert at linuxfromscratch.org
Fri Jun 2 20:18:18 PDT 2006
I was updating the kernel pseudo_random and libc arc4random patches, and
checked open and net bsd to see if they have made recent changes. I noticed
'use the new fat random sysctl to get initial state.' in their cvs log, and I
thought to myself "I want a fat random sysctl too". The pseudo_random/frandom
kernel patch gives 16 byte output from sysctl, in the patch I substituted 16
with 256, and increased the buffer from 64 to 1024 (multiplied everything by
4), and it works pretty nice.
This is the standard 16 bytes:
kernel.random.erandom = cb39026ddaac9bed446b9d94718d5577
This is 256 bytes:
This works with the urandom sysctl too. I put a patch here:
I also fixed class_device_create so frandom can compile as a module on the
more recent kernels, and fixed the menu a bit so both sysctl drivers are now
menu options. I would like to find someone familiar with recent 2.6 kernels
to check over the pseudo_random patch, because it was originally made for
kernel 2.4 (the devfs stuff could be removed now).
The urandom sysctl uses significant amount of kernel entropy, but erandom
still uses none. I have yet to check why sysctl urandom and /dev/urandom use
very different amounts of entropy.
So now the arc4random library can fill a 128 byte buffer with a single sysctl
call, instead of 8, and the looping code can be removed, so it can run a bit
This new kernel patch should work fine with the old arc4 library, the looping
code will just run once instead of 8 times.
I imagine this uses more system memory to run... 4 times more, but not more
cpu resources. This may or may not be a problem with systems with little
memory. More testing is needed to see if there are any other issues.
More information about the hlfs-dev