|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * crypto random application interface |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @publishedAll |
|
23 @released |
|
24 */ |
|
25 |
|
26 #ifndef __CRYPTOAPI_RANDOMAPI_H__ |
|
27 #define __CRYPTOAPI_RANDOMAPI_H__ |
|
28 |
|
29 #include <cryptospi/cryptobaseapi.h> |
|
30 |
|
31 namespace CryptoSpi |
|
32 { |
|
33 class MRandom; |
|
34 class MAsyncRandom; |
|
35 class CCryptoParams; |
|
36 /** |
|
37 Synchronous Random API, which wraps a synchronous Random plugin implementation |
|
38 */ |
|
39 NONSHARABLE_CLASS(CRandom) : public CCryptoBase |
|
40 { |
|
41 public: |
|
42 /** |
|
43 * @internalComponent |
|
44 * |
|
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 |
|
48 **/ |
|
49 static CRandom* NewL(MRandom* aRandom, TInt aHandle); |
|
50 |
|
51 /** |
|
52 Destructor |
|
53 */ |
|
54 IMPORT_C ~CRandom(); |
|
55 |
|
56 /** |
|
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 |
|
61 */ |
|
62 IMPORT_C void GenerateRandomBytesL(TDes8& aDest); |
|
63 |
|
64 private: |
|
65 |
|
66 /** |
|
67 Constructor |
|
68 */ |
|
69 CRandom(MRandom* aRandom, TInt aHandle); |
|
70 |
|
71 }; |
|
72 |
|
73 |
|
74 /** |
|
75 Asynchronous Random API, which wraps an asynchronous Random plugin implementation |
|
76 */ |
|
77 |
|
78 NONSHARABLE_CLASS(CAsyncRandom) : public CCryptoBase |
|
79 { |
|
80 public: |
|
81 /** |
|
82 * @internalComponent |
|
83 * |
|
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 |
|
87 **/ |
|
88 static CAsyncRandom* NewL(MAsyncRandom* aAsyncRandom, TInt aHandle); |
|
89 |
|
90 /** |
|
91 Destructor |
|
92 */ |
|
93 IMPORT_C ~CAsyncRandom(); |
|
94 |
|
95 /** |
|
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 |
|
100 * @param aStatus |
|
101 */ |
|
102 IMPORT_C void GenerateRandomBytesL(TDes8& aDest, TRequestStatus& aStatus); |
|
103 |
|
104 private: |
|
105 |
|
106 /** |
|
107 Constructor |
|
108 */ |
|
109 CAsyncRandom(MAsyncRandom* aAsyncRandom, TInt aHandle); |
|
110 |
|
111 }; |
|
112 |
|
113 |
|
114 /** |
|
115 the Factory to create synchronous and asynchronous hash instance |
|
116 */ |
|
117 class CRandomFactory |
|
118 { |
|
119 |
|
120 public: |
|
121 /** |
|
122 Creates a new instance of a Random object. |
|
123 |
|
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. |
|
128 */ |
|
129 IMPORT_C static void CreateRandomL(CRandom*& aRandom, |
|
130 TUid aAlgorithmUid, |
|
131 const CCryptoParams* aAlgorithmParams); |
|
132 |
|
133 /** |
|
134 Creates a new asynchronous instance of a Random object. |
|
135 |
|
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. |
|
140 */ |
|
141 IMPORT_C static void CreateAsyncRandomL(CAsyncRandom*& aAsyncRandom, |
|
142 TUid aAlgorithmUid, |
|
143 const CCryptoParams* aAlgorithmParams); |
|
144 |
|
145 }; |
|
146 } |
|
147 |
|
148 #endif //__CRYPTOAPI_RANDOMAPI_H__ |