<?xml version="1.0"?>
<!DOCTYPE riscos-prm PUBLIC "-//Gerph//DTD PRM documentation 1.03//EN"
                            "http://gerph.org/dtd/103/prm.dtd">

<riscos-prm>
<chapter title="CryptRandom">

<section title="Introduction">
<p>
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.
</p>

<p>
    <version-table>
        <version supplier="Theo Markettos" state="supported"/>
        <version supplier="RISC OS Pyromaniac" riscos-ge="7.29" state="supported"/>
    </version-table>
</p>

</section>

<section title="Overview">

<p>
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 <strong>bad
thing</strong> 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.
</p>

<p>
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.
</p>

<p>
The CryptRandom module provides SWI calls which allow access to random data retrieved
from a variety of sources.
</p>
</section>

<section title="Technical details">
<p>
    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.
</p>

<p>
<list>
    <item>'null' - returns the same value every time, from the seed.</item>
    <item>'python' - uses the default python random number generator for its
    values.</item>
</list>
</p>

<p>
    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.
</p>
</section>

<section title="SWIs">

<swi-definition name="CryptRandom_Byte"
                number="51980"
                description="Reads a byte from the random pool"
                irqs="disabled"
                fiqs="undefined"
                processor-mode="SVC"
                re-entrant="no">
<exit>
    <register-use number="0">Random byte value (0-255)</register-use>
</exit>
<use>
<p>
This SWI reads a byte from the pool, and subsequently stirs it.
</p>
</use>

<related>
<reference type='swi' name='CryptRandom_Block'/>
<reference type='swi' name='CryptRandom_Word'/>
</related>
</swi-definition>


<swi-definition name="CryptRandom_Stir"
                number="51981"
                description="Stirs the random pool"
                irqs="disabled"
                fiqs="undefined"
                processor-mode="SVC"
                re-entrant="no">
<entry>
</entry>
<exit>
</exit>

<use>
<p>
This SWI stirs the random pool - this should not be necessary in normal use
</p>
</use>

<related>
<reference type='swi' name='CryptRandom_AddNoise'/>
</related>
</swi-definition>


<swi-definition name="CryptRandom_AddNoise"
                number="51982"
                description="Introduce data to the random pool"
                irqs="disabled"
                fiqs="undefined"
                processor-mode="SVC"
                re-entrant="no">
<entry>
    <register-use number="0">Pointer to block of noise data to add</register-use>
    <register-use number="1">Size of data in the block</register-use>
</entry>
<exit>
</exit>

<use>
<p>
Adds a block of noise to the random pool - shouldn't be necessary in normal
use.
</p>
</use>
<related>
<reference type='swi' name='CryptRandom_Stir'/>
</related>
</swi-definition>



<swi-definition name="CryptRandom_Block"
                number="51983"
                description="Reads multiple bytes from the random pool"
                irqs="disabled"
                fiqs="undefined"
                processor-mode="SVC"
                re-entrant="no">
<entry>
    <register-use number="0">Pointer to block to fill with random bytes</register-use>
    <register-use number="1">Number of bytes to fill into the buffer</register-use>
</entry>
<exit>
</exit>

<use>
<p>
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 <reference type='swi' name='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.
</p>
</use>
<related>
<reference type='swi' name='CryptRandom_Byte'/>
<reference type='swi' name='CryptRandom_Word'/>
</related>
</swi-definition>


<swi-definition name="CryptRandom_Word"
                number="51984"
                description="Reads a 32-bit word from the random pool"
                irqs="disabled"
                fiqs="undefined"
                processor-mode="SVC"
                re-entrant="no">
<exit>
    <register-use number="0">Random 32-bit word from the pool</register-use>
</exit>
<use>
<p>
This reads a 4 bytes from the pool, and assembles them into a 32-bit word.
</p>
</use>
<related>
<reference type='swi' name='CryptRandom_Byte'/>
<reference type='swi' name='CryptRandom_Block'/>
</related>
</swi-definition>
</section>
</chapter>

<!-- MetaData -->
<meta>
 <maintainer>
  <email name="Gerph" address="gerph@gerph.org" />
  <email name="Theo Markettos" address="theo@markettos.org" />
 </maintainer>
 <disclaimer>
<p>
Original module copyright 2000-1 Theo Markettos.<br/>
Portions copyright Simon Tatham, Gary S. Brown and Eric Young
</p>
 </disclaimer>

 <history>
  <revision number="0.13" author="Theo Markettos" title="Text documentation">
   <change>Original documentation for the CryptRandom module.</change>
  </revision>

  <revision number="0.13a" author="Gerph" title="PRM-in-XML documentation">
   <change>Documentation re-written as PRM-in-XML.</change>
  </revision>

  <revision number="0.13b" author="Gerph" title="Cut down for Pyromaniac">
   <change>Trimmed documentation with just the summary and interfaces.</change>
  </revision>

  <revision number="0.13c" author="Gerph" title="Version information">
   <change>Included version table for compatibility info.</change>
  </revision>
 </history>

</meta>
</riscos-prm>

