CryptRandom is a module for generating cryptographically useful random bytes under RISC OS. It can use a number of sources to provide this information to clients needing secure, or high quality random data.
Computers are, by their nature, deterministic - so applying the same sequence of inputs to any program is likely to produce the same result. This is a bad thing when it comes to cryptography, as if you use a known sequence to encrypt a data stream, next time you turn on your machine you'll use the same known sequence, making the code possible to break. Thus we need a random sequence so that no pattern can be spotted in it. Basic provides a pseudo-random sequence, but this is the same every time the machine is turned on, so is not very good. It is also just a sequence, which will eventually repeat. True randomness is only possible on a computer by attaching it to other devices such as a radioactive source - not very practical.
CryptRandom applies another method, which will produce different values showing to no known pattern, which are different each time you switch the machine on. This is much less secure than using a true random source, but better than using a predictable random number generator like that Basic uses.
The CryptRandom module provides SWI calls which allow access to random data retrieved from a variety of sources.
The version of CryptRandom supplied with RISC OS Pyromaniac has been limited in its behaviour. It can be configured to use different implementations, but the two implementations supplied are simplistic. The configurations may be configured with the 'cryptrandom.implementation' configuration option. The implementation can be given a seed with the 'cryptrandom.seed' configuration option.
- 'null' - returns the same value every time, from the seed.
- 'python' - uses the default python random number generator for its values.
It should not therefore be relied on for cryptographicly reliable random numbers. RISC OS Pyromaniac is intended for debug and diagnostics, so this should be sufficient.
|R0||=||Random byte value (0-255)|
This SWI reads a byte from the pool, and subsequently stirs it.
This SWI stirs the random pool - this should not be necessary in normal use
|R0||=||Pointer to block of noise data to add|
|R1||=||Size of data in the block|
Adds a block of noise to the random pool - shouldn't be necessary in normal use.
|R0||=||Pointer to block to fill with random bytes|
|R1||=||Number of bytes to fill into the buffer|
Generates a block of random data. Note this is called with interrupts off, so large blocks may cause your machine to hang while they are generated. Note also the entropy generated by this call is likely to be less than multiple SWI CryptRandom_Byte calls (since times/battery status etc are likely to be the same during this call, but not if _Byte calls are spread at different points in your program), so randomness may suffer as a result.
|R0||=||Random 32-bit word from the pool|
This reads a 4 bytes from the pool, and assembles them into a 32-bit word.