[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [f-cpu] random number generator



Hi !

gaetan@xeberon.net wrote:

just one question: is it possible to add a kind of rand instruction in the f-cpu instruction set?
It could give a "true" random number (integer) between 0 and MAX_INT (following SIMD flags)...
I mean, random numbers are a great problem in programming, so it could be a good idea to hardwire one generator into the f-cpu...
i don't know if it is possible and if it is useful, but it could be a good idea...

Integer random numbers are a whole field in themselves
and a one-fits-all function is not possible,
the programmer must still closely control the
quality of the datastreams.

There is a deterministic pseudo-random number generator in FC0,
however, but it is not "truely random" : it's just a hardwired LFSR
that is constantly fed by the POPCOUNT unit, which performs
the "Hamming distance" of two operands on the XBAR's read bus.

It is deterministic to allow the core to self-test on power-on.
After reset, the LSFR is cleared and bursts of control signals
are generated, data are cycled though all the execution units
and the LFSR is updated every cycle. In the end, the LFSR
contains a "signature" and the core is stopped if it is wrong,
meaning that a unit or wire is not functioning.

After POST (Power-On Self-Test), the LFSR is still running
and the "signature" is still generated from the CPU's XBAR bus.
This means that the LFSR's contents depends only on the instructions
and the data that the CPU processes.
Given enough time and a multi-user, multi-processing environment,
this should give some randomness but it's only a 64-bit register
and it is not suitable alone for a cryptographics application.

Besides user events, a rather good entropy generator is
an electret microphone connected to the computer's sound card.
It is not only impossible to "replay" (non-deterministic environment
noise like fans, etc, even if the noise is modelable), but the bandwidth is
higher (it could reach 1Kbits/s if well done). There are also other
specialised electronic devices that "generate" noise, amplifying
the electronic noise of the electron's movement in a resistor or
a semiconductor device, but there can be any sort of power-line coupling.

Depending on the application, "true random" numbers have
varying properties, some programs are happy with the glibc functions,
others need the SSL library. In any case, a few good books are
necessary to understand how it works and what is suitable.

YG

*************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe f-cpu       in the body. http://f-cpu.seul.org/