[klibc] [PATCH 1/2] Add minimal arc4random(3) API; self-seeding if /proc is mounted.
maximilian attems
max at stro.at
Sun Jan 30 12:48:21 PST 2011
On Sat, 29 Jan 2011, Thorsten Glaser wrote:
> This patch adds a minimalistic implementation of the
> BSD arc4random(3) API on top of jrand48(3) (which is
> already there, for size reasons) to have a simple,
> self-seeding PRNG (actually SRNG, stretching RNG,
> since it uses proper entropy from the kernel, just
> with an algorithm not usable for cryptography).
>
> Entropy sources:
> - 36 bytes from /proc/sys/kernel/random/uuid
> - position of temp. buffer on stack (randomised on recent kernels)
>
> Additional variation (non-random) via:
> - PID of last stir call
> - PID of current stir call
> - count of arc4random() calls since last stir
> - time of current stir call
> - size of user-provided data
> - position of arc4random_addrandom() argument on stack
> - filedescriptor of /proc/sys/kernel/random/uuid
> - count of bytes read from /proc/sys/kernel/random/uuid
>
> After stirring, it's good for 65535 arc4random() calls.
> The first call to arc4random() after fork() re-stirs.
>
> Signed-off-by: Thorsten Glaser <tg at mirbsd.de>
> ---
> usr/include/stdlib.h | 6 ++
> usr/klibc/Kbuild | 1 +
> usr/klibc/arc4random.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++
hmm this looks like a jrand48() abstraction that has it's better
place in a mksh wrapper, no?
Or was it thought as base for the mkstemp()?
--
maks
More information about the klibc
mailing list