Pyromaniac

Pyromaniac PRM: CryptRandom

Pyromaniac PRM: CryptRandom

RISC OS PyromaniacCryptRandom

Introduction

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.

Theo Markettos
Supported
RISC OS Pyromaniac7.29
Supported

Overview

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.

Technical details

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.

SWIs

CryptRandom_ByteSWI &51980
Reads a byte from the random pool
None
R0=Random byte value (0-255)
Interrupts are disabled
Fast interrupts are undefined
Processor is in SVC mode
SWI is not re-entrant

This SWI reads a byte from the pool, and subsequently stirs it.

CryptRandom_StirSWI &51981
Stirs the random pool
None
None
Interrupts are disabled
Fast interrupts are undefined
Processor is in SVC mode
SWI is not re-entrant

This SWI stirs the random pool - this should not be necessary in normal use

CryptRandom_AddNoiseSWI &51982
Introduce data to the random pool
R0=Pointer to block of noise data to add
R1=Size of data in the block
None
Interrupts are disabled
Fast interrupts are undefined
Processor is in SVC mode
SWI is not re-entrant

Adds a block of noise to the random pool - shouldn't be necessary in normal use.

CryptRandom_BlockSWI &51983
Reads multiple bytes from the random pool
R0=Pointer to block to fill with random bytes
R1=Number of bytes to fill into the buffer
None
Interrupts are disabled
Fast interrupts are undefined
Processor is in SVC mode
SWI is not re-entrant

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.

CryptRandom_WordSWI &51984
Reads a 32-bit word from the random pool
None
R0=Random 32-bit word from the pool
Interrupts are disabled
Fast interrupts are undefined
Processor is in SVC mode
SWI is not re-entrant

This reads a 4 bytes from the pool, and assembles them into a 32-bit word.