williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@4
|
3 |
* All rights reserved.
|
williamr@4
|
4 |
* This component and the accompanying materials are made available
|
williamr@4
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
williamr@4
|
6 |
* which accompanies this distribution, and is available
|
williamr@4
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Initial Contributors:
|
williamr@4
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Contributors:
|
williamr@4
|
13 |
*
|
williamr@4
|
14 |
* Description:
|
williamr@4
|
15 |
* crypto random application interface
|
williamr@4
|
16 |
*
|
williamr@4
|
17 |
*/
|
williamr@4
|
18 |
|
williamr@4
|
19 |
|
williamr@4
|
20 |
/**
|
williamr@4
|
21 |
@file
|
williamr@4
|
22 |
@publishedAll
|
williamr@4
|
23 |
@released
|
williamr@4
|
24 |
*/
|
williamr@4
|
25 |
|
williamr@4
|
26 |
#ifndef __CRYPTOAPI_RANDOMAPI_H__
|
williamr@4
|
27 |
#define __CRYPTOAPI_RANDOMAPI_H__
|
williamr@4
|
28 |
|
williamr@4
|
29 |
#include <cryptospi/cryptobaseapi.h>
|
williamr@4
|
30 |
|
williamr@4
|
31 |
namespace CryptoSpi
|
williamr@4
|
32 |
{
|
williamr@4
|
33 |
class MRandom;
|
williamr@4
|
34 |
class MAsyncRandom;
|
williamr@4
|
35 |
class CCryptoParams;
|
williamr@4
|
36 |
/**
|
williamr@4
|
37 |
Synchronous Random API, which wraps a synchronous Random plugin implementation
|
williamr@4
|
38 |
*/
|
williamr@4
|
39 |
NONSHARABLE_CLASS(CRandom) : public CCryptoBase
|
williamr@4
|
40 |
{
|
williamr@4
|
41 |
public:
|
williamr@4
|
42 |
/**
|
williamr@4
|
43 |
* @internalComponent
|
williamr@4
|
44 |
*
|
williamr@4
|
45 |
* Create a CRandom instance from the given MRandom instance
|
williamr@4
|
46 |
* @param aRandom The random plugin instance
|
williamr@4
|
47 |
* @return A pointer to a CRandom instance
|
williamr@4
|
48 |
**/
|
williamr@4
|
49 |
static CRandom* NewL(MRandom* aRandom, TInt aHandle);
|
williamr@4
|
50 |
|
williamr@4
|
51 |
/**
|
williamr@4
|
52 |
Destructor
|
williamr@4
|
53 |
*/
|
williamr@4
|
54 |
IMPORT_C ~CRandom();
|
williamr@4
|
55 |
|
williamr@4
|
56 |
/**
|
williamr@4
|
57 |
* Generate enough random bytes to fill the supplied descriptor
|
williamr@4
|
58 |
* If there is not enough entropy available, or another error
|
williamr@4
|
59 |
* occurs (e.g. out of memory) then this method may leave.
|
williamr@4
|
60 |
* @param aDest The returned generated random bytes filling the descriptor
|
williamr@4
|
61 |
*/
|
williamr@4
|
62 |
IMPORT_C void GenerateRandomBytesL(TDes8& aDest);
|
williamr@4
|
63 |
|
williamr@4
|
64 |
private:
|
williamr@4
|
65 |
|
williamr@4
|
66 |
/**
|
williamr@4
|
67 |
Constructor
|
williamr@4
|
68 |
*/
|
williamr@4
|
69 |
CRandom(MRandom* aRandom, TInt aHandle);
|
williamr@4
|
70 |
|
williamr@4
|
71 |
};
|
williamr@4
|
72 |
|
williamr@4
|
73 |
|
williamr@4
|
74 |
/**
|
williamr@4
|
75 |
Asynchronous Random API, which wraps an asynchronous Random plugin implementation
|
williamr@4
|
76 |
*/
|
williamr@4
|
77 |
|
williamr@4
|
78 |
NONSHARABLE_CLASS(CAsyncRandom) : public CCryptoBase
|
williamr@4
|
79 |
{
|
williamr@4
|
80 |
public:
|
williamr@4
|
81 |
/**
|
williamr@4
|
82 |
* @internalComponent
|
williamr@4
|
83 |
*
|
williamr@4
|
84 |
* Create a CRandom instance from the given MRandom instance
|
williamr@4
|
85 |
* @param aAsyncRandom The async random plugin instance
|
williamr@4
|
86 |
* @return A pointer to a CAsyncRandom instance
|
williamr@4
|
87 |
**/
|
williamr@4
|
88 |
static CAsyncRandom* NewL(MAsyncRandom* aAsyncRandom, TInt aHandle);
|
williamr@4
|
89 |
|
williamr@4
|
90 |
/**
|
williamr@4
|
91 |
Destructor
|
williamr@4
|
92 |
*/
|
williamr@4
|
93 |
IMPORT_C ~CAsyncRandom();
|
williamr@4
|
94 |
|
williamr@4
|
95 |
/**
|
williamr@4
|
96 |
* Generate enough random bytes to fill the supplied descriptor
|
williamr@4
|
97 |
* If there is not enough entropy available, or another error
|
williamr@4
|
98 |
* occurs (e.g. out of memory) then this method may leave.
|
williamr@4
|
99 |
* @param aDest The returned generated random bytes filling the descriptor
|
williamr@4
|
100 |
* @param aStatus
|
williamr@4
|
101 |
*/
|
williamr@4
|
102 |
IMPORT_C void GenerateRandomBytesL(TDes8& aDest, TRequestStatus& aStatus);
|
williamr@4
|
103 |
|
williamr@4
|
104 |
private:
|
williamr@4
|
105 |
|
williamr@4
|
106 |
/**
|
williamr@4
|
107 |
Constructor
|
williamr@4
|
108 |
*/
|
williamr@4
|
109 |
CAsyncRandom(MAsyncRandom* aAsyncRandom, TInt aHandle);
|
williamr@4
|
110 |
|
williamr@4
|
111 |
};
|
williamr@4
|
112 |
|
williamr@4
|
113 |
|
williamr@4
|
114 |
/**
|
williamr@4
|
115 |
the Factory to create synchronous and asynchronous hash instance
|
williamr@4
|
116 |
*/
|
williamr@4
|
117 |
class CRandomFactory
|
williamr@4
|
118 |
{
|
williamr@4
|
119 |
|
williamr@4
|
120 |
public:
|
williamr@4
|
121 |
/**
|
williamr@4
|
122 |
Creates a new instance of a Random object.
|
williamr@4
|
123 |
|
williamr@4
|
124 |
@param aRandom A reference to a pointer that should be set to point to the new CRandom object.
|
williamr@4
|
125 |
@param aAlgorithmUid The algorithm to use
|
williamr@4
|
126 |
@param aAlgorithmParams Parameters that are specific this algorithm.
|
williamr@4
|
127 |
@return KErrNone if successful; otherwise, a system wide error code.
|
williamr@4
|
128 |
*/
|
williamr@4
|
129 |
IMPORT_C static void CreateRandomL(CRandom*& aRandom,
|
williamr@4
|
130 |
TUid aAlgorithmUid,
|
williamr@4
|
131 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
132 |
|
williamr@4
|
133 |
/**
|
williamr@4
|
134 |
Creates a new asynchronous instance of a Random object.
|
williamr@4
|
135 |
|
williamr@4
|
136 |
@param aAsyncRandom A reference to a pointer that should be set to point to the new CAsyncRandom object.
|
williamr@4
|
137 |
@param aAlgorithmUid The algorithm to use
|
williamr@4
|
138 |
@param aAlgorithmParams Parameters that are specific this particular algorithm.
|
williamr@4
|
139 |
@return KErrNone if successful; otherwise, a system wide error code.
|
williamr@4
|
140 |
*/
|
williamr@4
|
141 |
IMPORT_C static void CreateAsyncRandomL(CAsyncRandom*& aAsyncRandom,
|
williamr@4
|
142 |
TUid aAlgorithmUid,
|
williamr@4
|
143 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
144 |
|
williamr@4
|
145 |
};
|
williamr@4
|
146 |
}
|
williamr@4
|
147 |
|
williamr@4
|
148 |
#endif //__CRYPTOAPI_RANDOMAPI_H__
|