First public contribution.
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
33 class CRandom : public CBase
42 * Implementations of this method should fill the passed
43 * buffer with securely generated random data up to the
44 * current length, discarding any current contents.
46 * @param aDest The buffer in to which to write random data.
49 virtual void GenerateBytesL(TDes8& aDest) = 0;
51 IMPORT_C CRandom(void);
53 CRandom(const CRandom&);
54 CRandom& operator=(const CRandom&);
59 * Sets a secure random number generator implementation to use
62 * @param aRNG The secure random number generator to use.
65 IMPORT_C void SetThreadRandomL(CRandom* aRNG);
69 * Sets a secure random number generator implementation to use
70 * for this thread, placing it on the cleanup stack.
72 * @param aRNG The secure random number generator to use.
75 IMPORT_C void SetThreadRandomLC(CRandom* aRNG);
78 void DeleteThreadRandom(TAny* aPtr);
82 * Destroys the currently installed random number generator
83 * that is in use for this thread.
86 IMPORT_C void DestroyThreadRandom(void);
90 * Generates cryptographically secure random data, filling
91 * the provided buffer up to its current length, discarding
92 * any data that it may currently contain.
94 * @param aDest The buffer to fill with random data
97 IMPORT_C void GenerateRandomBytesL(TDes8& aDest);
99 class CSystemRandom : public CRandom
102 * This default secure random number generator uses
103 * system state to generate entropy for the generation
104 * of cryptographically secure random numbers.
116 * Constructs a new system random number generator.
118 * @return A ready-to-use random number generator.
120 IMPORT_C static CSystemRandom* NewL(void);
124 * Constructs a new system random number generator,
125 * and places it on the cleanup stack.
127 * @return A ready-to-use random number generator.
130 IMPORT_C static CSystemRandom* NewLC(void);
134 * Implements the contract as specified in the base
135 * class, CRandom, filling the buffer supplied with
136 * cryptographically secure random data up to its
137 * current length, discarding its current content.
139 * @param aDest The buffer to which to write random data
142 virtual void GenerateBytesL(TDes8& aDest);
145 CSystemRandom(const CSystemRandom&);
146 CSystemRandom& operator=(const CSystemRandom&);
152 * The user interface to the system cryptographically
153 * secure random number generator.
163 * Fills the provided buffer with secure random data up to its
164 * current length, discarding any current content.
166 * @param aDestination The buffer in which to write the random data.
167 * @deprecated Use RandomL() instead
168 * @panic This function can panic under low memory conditions
171 IMPORT_C static void Random(TDes8& aDestination);
175 * Fills the provided buffer with secure random data up to its
176 * current length, discarding any current content.
178 * @param aDestination The buffer in which to write the random data.
179 * @leave This function can leave under low memory conditions
182 IMPORT_C static void RandomL(TDes8& aDestination);
185 class RRandomSession:public RSessionBase
188 * The client interface to the system random number generator. End
189 * users should use TRandom instead of this interface.
197 IMPORT_C RRandomSession(void);
201 * Fills the provided buffer with secure random data up to its
202 * current length, discarding any current content.
204 * @param aDestination The buffer in to which to write the random data
207 IMPORT_C TInt GetRandom(TDes8& aDestination);
211 * Opens a new session with the random number server.
214 IMPORT_C void ConnectL(void);
217 #endif // __RANDOM_H__