2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * (c) 1999-2003 Symbian Ltd
36 class CRandom : public CBase
45 * Implementations of this method should fill the passed
46 * buffer with securely generated random data up to the
47 * current length, discarding any current contents.
49 * @param aDest The buffer in to which to write random data.
52 virtual void GenerateBytesL(TDes8& aDest) = 0;
54 IMPORT_C CRandom(void);
56 CRandom(const CRandom&);
57 CRandom& operator=(const CRandom&);
62 * Sets a secure random number generator implementation to use
65 * @param aRNG The secure random number generator to use.
68 IMPORT_C void SetThreadRandomL(CRandom* aRNG);
72 * Sets a secure random number generator implementation to use
73 * for this thread, placing it on the cleanup stack.
75 * @param aRNG The secure random number generator to use.
78 IMPORT_C void SetThreadRandomLC(CRandom* aRNG);
81 void DeleteThreadRandom(TAny* aPtr);
85 * Destroys the currently installed random number generator
86 * that is in use for this thread.
89 IMPORT_C void DestroyThreadRandom(void);
93 * Generates cryptographically secure random data, filling
94 * the provided buffer up to its current length, discarding
95 * any data that it may currently contain.
97 * @param aDest The buffer to fill with random data
100 IMPORT_C void GenerateRandomBytesL(TDes8& aDest);
102 class CSystemRandom : public CRandom
105 * This default secure random number generator uses
106 * system state to generate entropy for the generation
107 * of cryptographically secure random numbers.
119 * Constructs a new system random number generator.
121 * @return A ready-to-use random number generator.
123 IMPORT_C static CSystemRandom* NewL(void);
127 * Constructs a new system random number generator,
128 * and places it on the cleanup stack.
130 * @return A ready-to-use random number generator.
133 IMPORT_C static CSystemRandom* NewLC(void);
137 * Implements the contract as specified in the base
138 * class, CRandom, filling the buffer supplied with
139 * cryptographically secure random data up to its
140 * current length, discarding its current content.
142 * @param aDest The buffer to which to write random data
145 virtual void GenerateBytesL(TDes8& aDest);
148 CSystemRandom(const CSystemRandom&);
149 CSystemRandom& operator=(const CSystemRandom&);
155 * The user interface to the system cryptographically
156 * secure random number generator.
166 * Fills the provided buffer with secure random data up to its
167 * current length, discarding any current content.
169 * @param aDestination The buffer in which to write the random data.
170 * @deprecated Use RandomL() instead
171 * @panic This function can panic under low memory conditions
174 IMPORT_C static void Random(TDes8& aDestination);
178 * Fills the provided buffer with secure random data up to its
179 * current length, discarding any current content.
181 * @param aDestination The buffer in which to write the random data.
182 * @leave This function can leave under low memory conditions
185 IMPORT_C static void RandomL(TDes8& aDestination);
188 class RRandomSession:public RSessionBase
191 * The client interface to the system random number generator. End
192 * users should use TRandom instead of this interface.
200 IMPORT_C RRandomSession(void);
204 * Fills the provided buffer with secure random data up to its
205 * current length, discarding any current content.
207 * @param aDestination The buffer in to which to write the random data
210 IMPORT_C TInt GetRandom(TDes8& aDestination);
214 * Opens a new session with the random number server.
217 IMPORT_C void ConnectL(void);
220 #endif // __RANDOM_H__