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 hash 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_HASHAPI_H__
|
williamr@4
|
27 |
#define __CRYPTOAPI_HASHAPI_H__
|
williamr@4
|
28 |
|
williamr@4
|
29 |
#include <e32base.h>
|
williamr@4
|
30 |
#include <cryptospi/cryptobaseapi.h>
|
williamr@4
|
31 |
|
williamr@4
|
32 |
|
williamr@4
|
33 |
namespace CryptoSpi
|
williamr@4
|
34 |
{
|
williamr@4
|
35 |
class MPlugin;
|
williamr@4
|
36 |
class MHash;
|
williamr@4
|
37 |
class MAsyncHash;
|
williamr@4
|
38 |
class CCryptoParams;
|
williamr@4
|
39 |
class CKey;
|
williamr@4
|
40 |
|
williamr@4
|
41 |
/**
|
williamr@4
|
42 |
Hash API, which wraps a synchronous Hash plugin implementation
|
williamr@4
|
43 |
*/
|
williamr@4
|
44 |
NONSHARABLE_CLASS(CHash) : public CCryptoBase
|
williamr@4
|
45 |
{
|
williamr@4
|
46 |
public:
|
williamr@4
|
47 |
/**
|
williamr@4
|
48 |
* @internalComponent
|
williamr@4
|
49 |
*
|
williamr@4
|
50 |
* Create a CHash instance from the given MHash instance
|
williamr@4
|
51 |
* @param aHash The hash plugin instance
|
williamr@4
|
52 |
* @return A pointer to a CHash instance
|
williamr@4
|
53 |
**/
|
williamr@4
|
54 |
static CHash* NewL(MHash* aHash, TInt aHandle);
|
williamr@4
|
55 |
|
williamr@4
|
56 |
/**
|
williamr@4
|
57 |
Destructor
|
williamr@4
|
58 |
*/
|
williamr@4
|
59 |
IMPORT_C ~CHash();
|
williamr@4
|
60 |
|
williamr@4
|
61 |
/**
|
williamr@4
|
62 |
Adds aMessage to the internal representation of data to be hashed,
|
williamr@4
|
63 |
then returns a TPtrC8 of the finalised hash of all the previously
|
williamr@4
|
64 |
appended messages.
|
williamr@4
|
65 |
@param aMessage The data to be included in the hash.
|
williamr@4
|
66 |
@return A descriptor pointer to the buffer containing the resulting hash.
|
williamr@4
|
67 |
*/
|
williamr@4
|
68 |
IMPORT_C TPtrC8 Hash(const TDesC8& aMessage); // Combination of Update and Final
|
williamr@4
|
69 |
|
williamr@4
|
70 |
/**
|
williamr@4
|
71 |
Adds data to the internal representation of messages to be hashed.
|
williamr@4
|
72 |
@param aMessage The data to be included in the hash.
|
williamr@4
|
73 |
*/
|
williamr@4
|
74 |
IMPORT_C void Update(const TDesC8& aMessage);
|
williamr@4
|
75 |
|
williamr@4
|
76 |
/**
|
williamr@4
|
77 |
Produces a final hash value from all the previous updates of data
|
williamr@4
|
78 |
to be hashed.
|
williamr@4
|
79 |
@param aMessage The data to be included in the hash.
|
williamr@4
|
80 |
*/
|
williamr@4
|
81 |
IMPORT_C TPtrC8 Final(const TDesC8& aMessage);
|
williamr@4
|
82 |
|
williamr@4
|
83 |
/**
|
williamr@4
|
84 |
Creates a brand new reset CHash object containing no state
|
williamr@4
|
85 |
information from the current object. This API is only to support
|
williamr@4
|
86 |
the old crypto API for BC reason. It is strongly recommended not to use this API.
|
williamr@4
|
87 |
|
williamr@4
|
88 |
To make a copy of a message digest with its internal state intact,
|
williamr@4
|
89 |
see CopyL().
|
williamr@4
|
90 |
|
williamr@4
|
91 |
@return A pointer to the new reset CHash object.
|
williamr@4
|
92 |
@leave ... Any of the crypto error codes defined in
|
williamr@4
|
93 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
94 |
*/
|
williamr@4
|
95 |
IMPORT_C CHash* ReplicateL();
|
williamr@4
|
96 |
|
williamr@4
|
97 |
/**
|
williamr@4
|
98 |
Creates a new CHash object with the exact same state as
|
williamr@4
|
99 |
the current object.This API is only to support
|
williamr@4
|
100 |
the old crypto API for BC reason. It is strongly recommended not to use this API.
|
williamr@4
|
101 |
|
williamr@4
|
102 |
This function copies all internal state of the message digest.
|
williamr@4
|
103 |
To create a new CHash object without the state of
|
williamr@4
|
104 |
the current object, see ReplicateL().
|
williamr@4
|
105 |
|
williamr@4
|
106 |
@return A pointer to the new CHash object.
|
williamr@4
|
107 |
@leave ... Any of the crypto error codes defined in
|
williamr@4
|
108 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
109 |
*/
|
williamr@4
|
110 |
IMPORT_C CHash* CopyL();
|
williamr@4
|
111 |
|
williamr@4
|
112 |
/**
|
williamr@4
|
113 |
* @deprecated
|
williamr@4
|
114 |
*
|
williamr@4
|
115 |
* Set the key used for HMAC mode operation.
|
williamr@4
|
116 |
* @param aKey The key for HMAC
|
williamr@4
|
117 |
* @leave KErrArgument if aKey is not of the expected type.
|
williamr@4
|
118 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
119 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
120 |
*/
|
williamr@4
|
121 |
IMPORT_C void SetKeyL(const CKey& aKey);
|
williamr@4
|
122 |
|
williamr@4
|
123 |
/**
|
williamr@4
|
124 |
* @deprecated
|
williamr@4
|
125 |
*
|
williamr@4
|
126 |
* Set the operation mode, ie hash or hmac
|
williamr@4
|
127 |
* @param aOperationMode The UID to identifiy the operation mode
|
williamr@4
|
128 |
* @leave KErrNotSupported if the specified operation mode is not supported.
|
williamr@4
|
129 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
130 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
131 |
*/
|
williamr@4
|
132 |
IMPORT_C void SetOperationModeL(TUid aOperationMode);
|
williamr@4
|
133 |
|
williamr@4
|
134 |
private:
|
williamr@4
|
135 |
/**
|
williamr@4
|
136 |
Constructor
|
williamr@4
|
137 |
*/
|
williamr@4
|
138 |
CHash(MHash* aHash, TInt aHandle);
|
williamr@4
|
139 |
};
|
williamr@4
|
140 |
|
williamr@4
|
141 |
|
williamr@4
|
142 |
/**
|
williamr@4
|
143 |
Asynchronous Hash API, which wraps an asynchronous Hash plugin implementation
|
williamr@4
|
144 |
*/
|
williamr@4
|
145 |
NONSHARABLE_CLASS(CAsyncHash) : public CCryptoBase
|
williamr@4
|
146 |
{
|
williamr@4
|
147 |
public:
|
williamr@4
|
148 |
/**
|
williamr@4
|
149 |
* @internalComponent
|
williamr@4
|
150 |
*
|
williamr@4
|
151 |
* Create a CAsyncHash instance from the given MAsyncHash instance
|
williamr@4
|
152 |
* @param aAsyncHash The async hash plugin instance
|
williamr@4
|
153 |
* @return A pointer to a CAsyncHash instance
|
williamr@4
|
154 |
**/
|
williamr@4
|
155 |
static CAsyncHash* NewL(MAsyncHash* aAsyncHash, TInt aHandle);
|
williamr@4
|
156 |
|
williamr@4
|
157 |
/**
|
williamr@4
|
158 |
Destructor
|
williamr@4
|
159 |
*/
|
williamr@4
|
160 |
IMPORT_C ~CAsyncHash();
|
williamr@4
|
161 |
|
williamr@4
|
162 |
/**
|
williamr@4
|
163 |
Adds aMessage to the internal representation of data to be hashed,
|
williamr@4
|
164 |
then returns a TPtrC8 of the finalised hash of all the previously
|
williamr@4
|
165 |
appended messages.
|
williamr@4
|
166 |
@param aMessage The data to be included in the hash.
|
williamr@4
|
167 |
@param aHash A descriptor pointer to the buffer containing the hash result.
|
williamr@4
|
168 |
@param aStatus
|
williamr@4
|
169 |
*/
|
williamr@4
|
170 |
IMPORT_C void Hash(const TDesC8& aMessage, TPtrC8& aHash, TRequestStatus& aStatus);
|
williamr@4
|
171 |
|
williamr@4
|
172 |
/**
|
williamr@4
|
173 |
Adds data to the internal representation of messages to be hashed.
|
williamr@4
|
174 |
@param aMessage The data to be included in the hash.
|
williamr@4
|
175 |
@param aStatus
|
williamr@4
|
176 |
*/
|
williamr@4
|
177 |
IMPORT_C void Update(const TDesC8& aMessage, TRequestStatus& aStatus);
|
williamr@4
|
178 |
|
williamr@4
|
179 |
/**
|
williamr@4
|
180 |
Produces a final hash value from all the previous updates of data
|
williamr@4
|
181 |
to be hashed.
|
williamr@4
|
182 |
@param aMessage The data to be included in the hash.
|
williamr@4
|
183 |
@param aFinal A descriptor pointer to the buffer containing the hash result.
|
williamr@4
|
184 |
@param aStatus
|
williamr@4
|
185 |
@return A descriptor pointer to the buffer containing the resulting hash.
|
williamr@4
|
186 |
*/
|
williamr@4
|
187 |
IMPORT_C void Final(const TDesC8& aMessage, TPtrC8& aFinal, TRequestStatus& aStatus);
|
williamr@4
|
188 |
|
williamr@4
|
189 |
/**
|
williamr@4
|
190 |
Cancel the outstanding request
|
williamr@4
|
191 |
*/
|
williamr@4
|
192 |
IMPORT_C void Cancel();
|
williamr@4
|
193 |
|
williamr@4
|
194 |
/**
|
williamr@4
|
195 |
Creates a brand new reset CAsyncHash object containing no state
|
williamr@4
|
196 |
information from the current object. This API is only to support
|
williamr@4
|
197 |
the old crypto API for BC reason. It is strongly recommended not to use this API.
|
williamr@4
|
198 |
|
williamr@4
|
199 |
To make a copy of a message digest with its internal state intact,
|
williamr@4
|
200 |
see CopyL().
|
williamr@4
|
201 |
|
williamr@4
|
202 |
@return A pointer to the new reset CAsyncHash object.
|
williamr@4
|
203 |
@leave ... Any of the crypto error codes defined in
|
williamr@4
|
204 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
205 |
*/
|
williamr@4
|
206 |
IMPORT_C CAsyncHash* ReplicateL();
|
williamr@4
|
207 |
|
williamr@4
|
208 |
/**
|
williamr@4
|
209 |
Creates a new CAsyncHash object with the exact same state as
|
williamr@4
|
210 |
the current object. This API is only to support
|
williamr@4
|
211 |
the old crypto API for BC reason. It is strongly recommended not to use this API.
|
williamr@4
|
212 |
|
williamr@4
|
213 |
This function copies all internal state of the message digest.
|
williamr@4
|
214 |
To create a new CAsyncHash object without the state of
|
williamr@4
|
215 |
the current object, see ReplicateL().
|
williamr@4
|
216 |
|
williamr@4
|
217 |
@return A pointer to the new CAsyncHash object.
|
williamr@4
|
218 |
@leave ... Any of the crypto error codes defined in
|
williamr@4
|
219 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
220 |
*/
|
williamr@4
|
221 |
IMPORT_C CAsyncHash* CopyL();
|
williamr@4
|
222 |
|
williamr@4
|
223 |
/**
|
williamr@4
|
224 |
* @deprecated
|
williamr@4
|
225 |
*
|
williamr@4
|
226 |
* Set the key used for HMAC mode operation.
|
williamr@4
|
227 |
* @param aKey the key for HMAC
|
williamr@4
|
228 |
* @leave KErrArgument if aKey is not of the expected type.
|
williamr@4
|
229 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
230 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
231 |
*/
|
williamr@4
|
232 |
IMPORT_C void SetKeyL(const CKey& aKey);
|
williamr@4
|
233 |
|
williamr@4
|
234 |
/**
|
williamr@4
|
235 |
* @deprecated
|
williamr@4
|
236 |
*
|
williamr@4
|
237 |
* Set the operation mode, ie hash or hmac
|
williamr@4
|
238 |
* @param aOperationMode The UID to identifiy the operation mode
|
williamr@4
|
239 |
* @leave KErrNotSupported if the specified mode is not supported.
|
williamr@4
|
240 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
241 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
242 |
*/
|
williamr@4
|
243 |
IMPORT_C void SetOperationModeL(TUid aOperationMode);
|
williamr@4
|
244 |
|
williamr@4
|
245 |
private:
|
williamr@4
|
246 |
|
williamr@4
|
247 |
/**
|
williamr@4
|
248 |
Constructor
|
williamr@4
|
249 |
*/
|
williamr@4
|
250 |
CAsyncHash(MAsyncHash* aAsyncHash, TInt aHandle);
|
williamr@4
|
251 |
};
|
williamr@4
|
252 |
|
williamr@4
|
253 |
/**
|
williamr@4
|
254 |
the Factory to create synchronous and asynchronous hash instances
|
williamr@4
|
255 |
*/
|
williamr@4
|
256 |
class CHashFactory
|
williamr@4
|
257 |
{
|
williamr@4
|
258 |
public:
|
williamr@4
|
259 |
|
williamr@4
|
260 |
/**
|
williamr@4
|
261 |
* @deprecated
|
williamr@4
|
262 |
*
|
williamr@4
|
263 |
* Create a CHash instance
|
williamr@4
|
264 |
*
|
williamr@4
|
265 |
* @param aHash The pointer to CHash
|
williamr@4
|
266 |
* @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4
|
williamr@4
|
267 |
* @param aOperationMode The operation mode of the hash e.g. Hash mode, Hmac mode
|
williamr@4
|
268 |
* @param aKey The key for Hmac mode, which should be NULL in Hash mode
|
williamr@4
|
269 |
* @param aAlgorithmParams The parameters that are specific to a particular
|
williamr@4
|
270 |
* algorithm. This is for extendibility and will normally be null.
|
williamr@4
|
271 |
* @return KErrNone if successful; otherwise, a system wide error code.
|
williamr@4
|
272 |
*/
|
williamr@4
|
273 |
IMPORT_C static void CreateHashL(CHash*& aHash,
|
williamr@4
|
274 |
TUid aAlgorithmUid,
|
williamr@4
|
275 |
TUid aOperationMode,
|
williamr@4
|
276 |
const CKey* aKey,
|
williamr@4
|
277 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
278 |
|
williamr@4
|
279 |
/**
|
williamr@4
|
280 |
* @deprecated
|
williamr@4
|
281 |
*
|
williamr@4
|
282 |
* Create a CAsyncHash instance
|
williamr@4
|
283 |
*
|
williamr@4
|
284 |
* @param aAsyncHash The pointer to CAsyncHash
|
williamr@4
|
285 |
* @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4
|
williamr@4
|
286 |
* @param aOperationMode The operation mode of the hash e.g. Hash mode, Hmac mode
|
williamr@4
|
287 |
* @param aKey The key for Hmac mode, which should be NULL in Hash mode
|
williamr@4
|
288 |
* @param aAlgorithmParams The parameters that are specific to a particular
|
williamr@4
|
289 |
* algorithm. This is for extendibility and will normally be null.
|
williamr@4
|
290 |
* @return KErrNone if successful; otherwise, a system wide error code.
|
williamr@4
|
291 |
*/
|
williamr@4
|
292 |
IMPORT_C static void CreateAsyncHashL(CAsyncHash*& aAsyncHash,
|
williamr@4
|
293 |
TUid aAlgorithmUid,
|
williamr@4
|
294 |
TUid aOperationMode,
|
williamr@4
|
295 |
const CKey* aKey,
|
williamr@4
|
296 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
297 |
|
williamr@4
|
298 |
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
|
williamr@4
|
299 |
/**
|
williamr@4
|
300 |
* Create a CHash instance
|
williamr@4
|
301 |
*
|
williamr@4
|
302 |
* @param aHash The pointer to CHash
|
williamr@4
|
303 |
* @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4
|
williamr@4
|
304 |
* @param aAlgorithmParams The parameters that are specific to a particular
|
williamr@4
|
305 |
* algorithm. This is for extendibility and will normally be null.
|
williamr@4
|
306 |
* @return KErrNone if successful; otherwise, a system wide error code.
|
williamr@4
|
307 |
*/
|
williamr@4
|
308 |
IMPORT_C static void CreateHashL(CHash*& aHash,
|
williamr@4
|
309 |
TUid aAlgorithmUid,
|
williamr@4
|
310 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
311 |
|
williamr@4
|
312 |
/**
|
williamr@4
|
313 |
* Create a CAsyncHash instance
|
williamr@4
|
314 |
*
|
williamr@4
|
315 |
* @param aAsyncHash The pointer to CAsyncHash
|
williamr@4
|
316 |
* @param aAlgorithmUid The specific hash algorithm e.g. MD2, SHA1, MD4
|
williamr@4
|
317 |
* @param aAlgorithmParams The parameters that are specific to a particular
|
williamr@4
|
318 |
* algorithm. This is for extendibility and will normally be null.
|
williamr@4
|
319 |
* @return KErrNone if successful; otherwise, a system wide error code.
|
williamr@4
|
320 |
*/
|
williamr@4
|
321 |
IMPORT_C static void CreateAsyncHashL(CAsyncHash*& aAsyncHash,
|
williamr@4
|
322 |
TUid aAlgorithmUid,
|
williamr@4
|
323 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
324 |
#endif
|
williamr@4
|
325 |
|
williamr@4
|
326 |
};
|
williamr@4
|
327 |
}
|
williamr@4
|
328 |
|
williamr@4
|
329 |
#endif //__CRYPTOAPI_HASHAPI_H__
|