Update contrib.
2 * Copyright (c) 2005-2010 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
33 class CRandom : public CBase
42 * Implementations of this method should fill the passed
43 * buffer with the generated pseudo-random data up to the
44 * current length, discarding any current contents. The
45 * implementations should leave with KErrNotSecure when
46 * the generated random data is not secure enough.
48 * @param aDest The buffer to fill with random data
49 * @leave KErrNotSecure Random data generated is not
50 * secure enough for crytographic operations
51 * otherwise, leaves with any other system wide error code.
54 virtual void GenerateBytesL(TDes8& aDest) = 0;
56 IMPORT_C CRandom(void);
58 CRandom(const CRandom&);
59 CRandom& operator=(const CRandom&);
64 * Sets a pseudo-random number generator implementation to use for this thread.
66 * @param aRNG The pseudo-random number generator to use.
69 IMPORT_C void SetThreadRandomL(CRandom* aRNG);
73 * Sets a pseudo-random number generator implementation to use
74 * for this thread, placing it on the cleanup stack.
76 * @param aRNG The pseudo-random number generator to use.
79 IMPORT_C void SetThreadRandomLC(CRandom* aRNG);
82 void DeleteThreadRandom(TAny* aPtr);
86 * Destroys the currently installed random number generator
87 * that is in use for this thread.
90 IMPORT_C void DestroyThreadRandom(void);
94 * Generates pseudo-random data.
95 * Fills the provided buffer up to its current length,
96 * discarding any data that it may currently contain.
98 * @param aDest The buffer to fill with random data
99 * @leave KErrNotSecure The random data generated is
100 * not secure enough for cryptographic operations
101 * otherwise, leaves with any other system wide error codes.
104 IMPORT_C void GenerateRandomBytesL(TDes8& aDest);
107 class CSystemRandom : public CRandom
110 * This default pseudo-random number generator uses system state
111 * to generate entropy for the generation of random numbers.
123 * Constructs a new pseudo-random number generator.
125 * @return A ready-to-use random number generator.
127 IMPORT_C static CSystemRandom* NewL(void);
131 * Constructs a new pseudo-random number generator,
132 * and places it on the cleanup stack.
134 * @return A ready-to-use random number generator.
137 IMPORT_C static CSystemRandom* NewLC(void);
141 * Implements the contract as specified in the base class, CRandom, filling the buffer
142 * supplied with random data up to its current length, discarding its current content.
143 * It will leave under no memory condition.
145 * @param aDest The buffer to be filled with random data
148 virtual void GenerateBytesL(TDes8& aDest);
153 CSystemRandom(const CSystemRandom&);
154 CSystemRandom& operator=(const CSystemRandom&);
164 * The user interface to the random number generator.
174 * Fills the provided buffer with pseudo-random data up to its current length,
175 * discarding any current content.
177 * This method will not return secure random numbers for some time after the phone boot-up. Because,
178 * pseudo-random number generator will take some time to attain a secure state by collecting enough
179 * entropy samples after the boot-up. Till that time, the pseudo-random numbers generated may not be
180 * cryptographically secure and there is no way to get to know about it with this API.
181 * So, if explcit notification on the strength of the random numbers is necessary, use TRandom::SecureRandomL.
183 * @param aDestination The buffer in which to write the random data.
184 * @deprecated Use RandomL() instead
185 * @panic This function can panic under low memory conditions
188 IMPORT_C static void Random(TDes8& aDestination);
192 * Fills the provided buffer with pseudo-random data up to its current length,
193 * discarding any current content.
195 * This method will not return secure random numbers for some time after the phone boot-up. Because,
196 * pseudo-random number generator will take some time to attain a secure state by collecting enough
197 * entropy samples after the boot-up. Till that time, the pseudo-random numbers generated may not be
198 * cryptographically secure and there is no way to get to know about it with this API.
199 * So, if explcit notification on the strength of the random numbers is necessary, use TRandom::SecureRandomL.
201 * @param aDestination The buffer in which to write the random data.
202 * @leave This function can leave under low memory conditions
205 IMPORT_C static void RandomL(TDes8& aDestination);
209 * Fills the provided buffer with the pseudo-random data up to its current length, discarding any current
210 * content of the descriptor. When this method returns normally (with out leave), the system state is secure
211 * and hence the random numbers generated are cryptographically secure as well. When this method leaves with
212 * the error code KErrNotSecure, the system internal state is not secure and hence the random numbers too.
214 * Though this method leaves when the system internal state is not secure, still the descriptor will be filled
215 * with pseudo-random bytes. This random data may or may not be secure enough. Recommended to treat these numbers
218 * @param aDestination The buffer in which to write the random data.
219 * @leave KErrNotSecure The generated random numbers is not secure enough for cryptographic operations.
220 * Otherwise, leaves with some other system wide error codes.
223 IMPORT_C static void SecureRandomL(TDes8& aDestination);
226 class RRandomSession:public RSessionBase
229 * The client interface to the system random number generator. End
230 * users should use TRandom instead of this interface.
238 IMPORT_C RRandomSession(void);
242 * Fills the provided buffer with pseudo-random data up to its
243 * current length, discarding any current content.
245 * @param aDestination The buffer in to which to write the random data
248 IMPORT_C TInt GetRandom(TDes8& aDestination);
252 * Opens a new session with the random number generator.
255 IMPORT_C void ConnectL(void);
258 #endif // __RANDOM_H__