|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-66BBA81D-2488-50B8-8822-43AAAA139DDE" xml:lang="en"><title>Overview |
|
13 of random number generation</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <section id="GUID-B5BD3E1A-AFBB-5526-B5EA-8FA51A17E596"><title>Overview</title> <p>The |
|
15 purpose of the Random Number Generation API is the generation of cryptographically |
|
16 strong random numbers. </p> <p>Several cryptographic applications rely upon |
|
17 the randomness, unpredictability and irreproducibility of the random number |
|
18 generator, such as: </p> <ul> |
|
19 <li id="GUID-15685756-F94B-508C-A08C-8F0ECBC1A4AA"><p>one-time pads </p> </li> |
|
20 <li id="GUID-7E3ED7CE-65C3-5E8B-9FF0-139763F3E54B"><p>key generation </p> </li> |
|
21 <li id="GUID-0C65E7E4-A3F5-5EC4-9851-4A4E3090607B"><p>random nonces </p> </li> |
|
22 <li id="GUID-3C16304A-CDA0-5F50-9D6C-D76C2D6EA586"><p>Initialization Vectors |
|
23 (IVs) </p> </li> |
|
24 <li id="GUID-59F195DE-94E7-56EE-9A7D-EAB5E401DF9A"><p>salts to be hashed with |
|
25 passwords </p> </li> |
|
26 <li id="GUID-96B7B9D1-AB0D-5A54-9C7F-771008F354C1"><p>unique parameters in |
|
27 signing operations. </p> </li> |
|
28 </ul> <p>The RNG uses the <xref href="http://www.agner.org/random/" scope="external">RANROT</xref> algorithm |
|
29 seeded by random data available on the target hardware (for instance free |
|
30 running counters available on ARM processors). <note><p>In order to be <b>fully</b> compliant |
|
31 with DSS (Digital Signature Standard), applications using the cryptography |
|
32 library must supply a <xref href="http://cr.yp.to/bib/2000/-dss.pdf" scope="external">FIPS-186-2</xref> CR |
|
33 1 compliant random number generator. The library provides a mechanism for |
|
34 using such a random number generator if required. </p></note></p> </section> |
|
35 <section id="GUID-9350FD0E-7F09-5D82-BB91-EC1C8D740DBD"><title>The Random |
|
36 Number Generation API</title> <p>The diagram below shows the main classes |
|
37 used in the RNG, which are implemented in <filepath>random.dll</filepath>. |
|
38 For information on each class see the Cryptography API Reference material. </p> <fig id="GUID-5326D881-8795-5803-8B82-EC02C0C40226"> |
|
39 <title> The inheritance hierarchy for the RRandomSession and |
|
40 CSystemRandom classes </title> |
|
41 <image href="GUID-FD1BB5C6-A042-56C9-8F1F-B51BF9DF5389_d0e615621_href.png" placement="inline"/> |
|
42 </fig><p><b>How to use TRandom</b> </p> <p> <codeph>TRandom</codeph> is a |
|
43 cryptographically stong random number generator. Its declaration is: </p> <codeblock id="GUID-53D847C3-2A1A-51D8-93FA-F68EA2374551" xml:space="preserve">class TRandom |
|
44 { |
|
45 public: |
|
46 IMPORT_C static void RandomL(TDes8& aDestination); |
|
47 };</codeblock><note> The function <codeph>TRandom::Random()</codeph> which |
|
48 panics rather than leaves when it cannot obtain a random number, is deprecated |
|
49 from v9.1 onwards. </note> <p> <codeph>TRandom::RandomL()</codeph> generates |
|
50 random bytes by first connecting to the random number generation server (using <codeph>RRandomSession</codeph>). |
|
51 If the attempt to connect fails, <codeph>TRandom::RandomL()</codeph> leaves. </p> <p>The |
|
52 server fills <codeph>aDestination</codeph> with randomly generated bytes up |
|
53 to its current length (not its maximum length). If this fails, <codeph>TRandom::RandomL()</codeph> leaves. |
|
54 If <codeph>aDestination</codeph> is 1024 or more bytes long, multiple calls |
|
55 are made to the server. Finally, <codeph>TRandom</codeph> closes the session. </p> <p> <codeph>TRandom</codeph> can |
|
56 be used like this: </p> <codeblock id="GUID-0472582C-D5BD-520D-848E-9989E8730851" xml:space="preserve">HBufC8* rand = HBufC8::NewLC(5); |
|
57 TPtr8 pRand=rand->Des(); |
|
58 pRand.SetLength(5); |
|
59 TRandom::RandomL(pRand); |
|
60 ... |
|
61 CleanupStack::PopAndDestroy(rand);</codeblock> </section> |
|
62 </conbody></concept> |