2 * Copyright (c) 2006-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 * crypto random application interface
26 #ifndef __CRYPTOAPI_RANDOMAPI_H__
27 #define __CRYPTOAPI_RANDOMAPI_H__
29 #include <cryptospi/cryptobaseapi.h>
37 Synchronous Random API, which wraps a synchronous Random plugin implementation
39 NONSHARABLE_CLASS(CRandom) : public CCryptoBase
45 * Create a CRandom instance from the given MRandom instance
46 * @param aRandom The random plugin instance
47 * @return A pointer to a CRandom instance
49 static CRandom* NewL(MRandom* aRandom, TInt aHandle);
57 * Generate enough random bytes to fill the supplied descriptor
58 * If there is not enough entropy available, or another error
59 * occurs (e.g. out of memory) then this method may leave.
60 * @param aDest The returned generated random bytes filling the descriptor
62 IMPORT_C void GenerateRandomBytesL(TDes8& aDest);
69 CRandom(MRandom* aRandom, TInt aHandle);
75 Asynchronous Random API, which wraps an asynchronous Random plugin implementation
78 NONSHARABLE_CLASS(CAsyncRandom) : public CCryptoBase
84 * Create a CRandom instance from the given MRandom instance
85 * @param aAsyncRandom The async random plugin instance
86 * @return A pointer to a CAsyncRandom instance
88 static CAsyncRandom* NewL(MAsyncRandom* aAsyncRandom, TInt aHandle);
93 IMPORT_C ~CAsyncRandom();
96 * Generate enough random bytes to fill the supplied descriptor
97 * If there is not enough entropy available, or another error
98 * occurs (e.g. out of memory) then this method may leave.
99 * @param aDest The returned generated random bytes filling the descriptor
102 IMPORT_C void GenerateRandomBytesL(TDes8& aDest, TRequestStatus& aStatus);
109 CAsyncRandom(MAsyncRandom* aAsyncRandom, TInt aHandle);
115 the Factory to create synchronous and asynchronous hash instance
122 Creates a new instance of a Random object.
124 @param aRandom A reference to a pointer that should be set to point to the new CRandom object.
125 @param aAlgorithmUid The algorithm to use
126 @param aAlgorithmParams Parameters that are specific this algorithm.
127 @return KErrNone if successful; otherwise, a system wide error code.
129 IMPORT_C static void CreateRandomL(CRandom*& aRandom,
131 const CCryptoParams* aAlgorithmParams);
134 Creates a new asynchronous instance of a Random object.
136 @param aAsyncRandom A reference to a pointer that should be set to point to the new CAsyncRandom object.
137 @param aAlgorithmUid The algorithm to use
138 @param aAlgorithmParams Parameters that are specific this particular algorithm.
139 @return KErrNone if successful; otherwise, a system wide error code.
141 IMPORT_C static void CreateAsyncRandomL(CAsyncRandom*& aAsyncRandom,
143 const CCryptoParams* aAlgorithmParams);
148 #endif //__CRYPTOAPI_RANDOMAPI_H__