Creating the same random numbers

Javier Martinez Canillas martinez.javier at gmail.com
Sat Jan 29 19:34:17 EST 2011


>> But in short answer yes, if you use the same seed the same answer
>> would be generated, assuming no further entropy is used later I.e
>> dependent on method employed to expand. Though then the 'randomness'
>> is in the seed not the output. Its this capability which allows simple
>> access control token devices to operate.
>>
> I'm not quite familiar with the number generators in the kernel.

Most random number generation functions are not truly random since
they are deterministic. To simulate a random behaviour those functions
are parametrized with a seed.

The kernel has a different approach and its random number generator
function is truly random. The kernel uses random events (hardware
interrupts) to feed an entropy pool. When random bytes are desired,
they are obtained by appliying the SHA hash of the contents of the
entropy pool.

Since hardware devices raises interrupts in a non-deterministic way,
the pool data is also non-deterministic and so are the values returned
by get_random_bytes().
>
> You mentioned the seed value. Is there a way to set a seed value before
> I invoke get_random_bytes? Could you direct me to a page / source file
> where I can get more information about it?
>

No, there isn't a seed for the get_random_bytes() for the reason i said before.

If you want a very high quality random number sequence and you want to
use that sequence with different functions, then I think your approach
is the best.

If you want to access from kernel space, use get_random_bytes() to
create the sequence, save the sequence and use it with all your
different functions.

On the other hand if you want to create the sequence from userpace,
read it from /dev/random that is only a interface that the kernel
exports to access the number random generator.

If you need a better understading of the kernel number generator look
at the code of drivers/char/random.c.

Best regards,

-- 
-----------------------------------------
Javier Martínez Canillas
(+34) 682 39 81 69
PhD Student in High Performance Computing
Computer Architecture and Operating System Department (CAOS)
Universitat Autònoma de Barcelona
Barcelona, Spain



More information about the Kernelnewbies mailing list