|
|
|
|
The Security crypto component exposes the Random API whose
broad purpose is the generation of cryptographically strong random numbers.
The Random number library is supplied by random.dll and
the classes implementing the Random algorithms are provided by the Random
Server, randsvr.exe (which is for internal use only).
Several cryptographic applications rely upon the randomness, unpredictability and irreproducibility of the random number generator, such as:
one-time pads
key generation
random nonces
Initialization Vectors (IVs)
salts to be hashed with passwords
unique parameters in signing operations.
The RNG uses the RANROT algorithm seeded by random data available on the target hardware (e.g. free running counters available on ARM processors).
In order to be fully compliant with DSS (Digital Signature Standard), applications using the cryptography library must supply a FIPS-186-2 CR 1 compliant random number generator. The library provides a mechanism for using such a random number generator if required.
The diagram below shows the main classes used in the RNG, which are
implemented in random.dll. The colour of the boxes indicates the
type of Symbian class, i.e., M, C, R or
T class. For detailed information on each component see the
Cryptography API Reference material.
TRandom is a cryptographically stong random number
generator. Its declaration is:
class TRandom
{
public:
IMPORT_C static void Random(TDes8& aDestination);
};
TRandom::Random() generates random bytes by first
connecting to the random number generation server (using
RRandomSession). It the attempt to connect fails,
TRandom::Random() panics with a category of Randsvr
connect.
The server then fills aDestination with randomly generated
bytes up to its current length (not its maximum length). If this fails,
TRandom::Random() panics with a category of Randsvr
get. If aDestination is 1024 or more bytes long, multiple
calls are made to the server. Finally, TRandom closes the session.
TRandom can be used like this:
HBufC8* rand = HBufC8::NewLC(5);
TPtr8 pRand=rand->Des();
pRand.SetLength(5);
TRandom::Random(pRand);
...
CleanupStack::PopAndDestroy(rand);