williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 2008-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 MAC 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_MACAPI_H__
|
williamr@4
|
27 |
#define __CRYPTOAPI_MACAPI_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 CCryptoParams;
|
williamr@4
|
37 |
class CKey;
|
williamr@4
|
38 |
class MMac;
|
williamr@4
|
39 |
class MAsyncMac;
|
williamr@4
|
40 |
|
williamr@4
|
41 |
|
williamr@4
|
42 |
/**
|
williamr@4
|
43 |
* Mac API, which wraps a synchronous Mac plugin implementation
|
williamr@4
|
44 |
* This Mac interface helps the client application to get the message
|
williamr@4
|
45 |
* authentication code value of a given message which provides
|
williamr@4
|
46 |
* data integrity and data origin authentication. These two goals are
|
williamr@4
|
47 |
* dependent upon the scope of the distribution of the secret key.
|
williamr@4
|
48 |
*/
|
williamr@4
|
49 |
|
williamr@4
|
50 |
NONSHARABLE_CLASS(CMac) : public CCryptoBase
|
williamr@4
|
51 |
{
|
williamr@4
|
52 |
public:
|
williamr@4
|
53 |
/**
|
williamr@4
|
54 |
* @internalComponent
|
williamr@4
|
55 |
* Create a CMac instance from the given MMac instance
|
williamr@4
|
56 |
*
|
williamr@4
|
57 |
* @param aMac The mac plugin instance
|
williamr@4
|
58 |
* @param aHandle The current plugin DLL loaded.
|
williamr@4
|
59 |
* @return pointer to a CMac instance
|
williamr@4
|
60 |
*/
|
williamr@4
|
61 |
static CMac* NewL(MMac* aMac, TInt aHandle);
|
williamr@4
|
62 |
|
williamr@4
|
63 |
/**
|
williamr@4
|
64 |
* Adds message to the internal representation of data for which the MAC value
|
williamr@4
|
65 |
* needs to be evaluated and then returns a TPtrC8 of the finalised MAC value
|
williamr@4
|
66 |
* of all the previously appended messages.
|
williamr@4
|
67 |
*
|
williamr@4
|
68 |
* @param aMessage The data for which MAC value is to be evaluated.
|
williamr@4
|
69 |
* @return A descriptor pointer to the buffer containing the
|
williamr@4
|
70 |
* resulting MAC value.
|
williamr@4
|
71 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
72 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
73 |
*/
|
williamr@4
|
74 |
IMPORT_C TPtrC8 MacL(const TDesC8& aMessage);
|
williamr@4
|
75 |
|
williamr@4
|
76 |
/**
|
williamr@4
|
77 |
* Adds data to the internal representation of messages for which the MAC value
|
williamr@4
|
78 |
* needs to be evaluated.
|
williamr@4
|
79 |
*
|
williamr@4
|
80 |
* @param aMessage The data to be included in the MAC evaluation.
|
williamr@4
|
81 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
82 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
83 |
*/
|
williamr@4
|
84 |
IMPORT_C void UpdateL(const TDesC8& aMessage);
|
williamr@4
|
85 |
|
williamr@4
|
86 |
/**
|
williamr@4
|
87 |
* Produces a final MAC value from all the previous updates of data to be MACed.
|
williamr@4
|
88 |
* It resets the MAC algorithm in a state similar to creating a new MAC instance
|
williamr@4
|
89 |
* with the same underlying algorithm and supplied symmetric key.
|
williamr@4
|
90 |
*
|
williamr@4
|
91 |
* @param aMessage The data to be included in the MAC evaluation.
|
williamr@4
|
92 |
* @return A descriptor pointer to the buffer containing the
|
williamr@4
|
93 |
* resulting MAC value.
|
williamr@4
|
94 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
95 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
96 |
*/
|
williamr@4
|
97 |
IMPORT_C TPtrC8 FinalL(const TDesC8& aMessage);
|
williamr@4
|
98 |
|
williamr@4
|
99 |
/**
|
williamr@4
|
100 |
* This re-initialises the underlying MAC algorithm with a new symmetric key.
|
williamr@4
|
101 |
* It resets the MAC algorithm in a state similar to creating a new MAC instance
|
williamr@4
|
102 |
* with the same underlying algorithm but a new symmetric key.
|
williamr@4
|
103 |
*
|
williamr@4
|
104 |
* @param aKey Symmetric key for calculating message authentication code value.
|
williamr@4
|
105 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
106 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
107 |
*/
|
williamr@4
|
108 |
IMPORT_C void ReInitialiseAndSetKeyL(const CKey& aKey);
|
williamr@4
|
109 |
|
williamr@4
|
110 |
/**
|
williamr@4
|
111 |
* Creates a brand new reset CMac object containing no state
|
williamr@4
|
112 |
* information from the current object.
|
williamr@4
|
113 |
*
|
williamr@4
|
114 |
* @return A pointer to the new reset CMac object
|
williamr@4
|
115 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
116 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
117 |
*/
|
williamr@4
|
118 |
IMPORT_C CMac* ReplicateL();
|
williamr@4
|
119 |
|
williamr@4
|
120 |
/**
|
williamr@4
|
121 |
* Creates a new CMac object with the exact same state as
|
williamr@4
|
122 |
* the current object.
|
williamr@4
|
123 |
* This function copies all internal state of the message digest.
|
williamr@4
|
124 |
*
|
williamr@4
|
125 |
* @return A pointer to the new CMac object
|
williamr@4
|
126 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
127 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
128 |
*/
|
williamr@4
|
129 |
IMPORT_C CMac* CopyL();
|
williamr@4
|
130 |
|
williamr@4
|
131 |
/**
|
williamr@4
|
132 |
* This destructor is exported so that the client application after using
|
williamr@4
|
133 |
* a specific plug-in implementation can destroy its instance. Both the framework
|
williamr@4
|
134 |
* and the plug-in use/derived from the same interface 'MPlugin.
|
williamr@4
|
135 |
* By exporting the destructor we are destroying the plug-in instance at
|
williamr@4
|
136 |
* client side via the CryptoSPI framework.
|
williamr@4
|
137 |
*/
|
williamr@4
|
138 |
IMPORT_C ~CMac();
|
williamr@4
|
139 |
|
williamr@4
|
140 |
private:
|
williamr@4
|
141 |
/**
|
williamr@4
|
142 |
* The constructor of this class is private. An user application will use
|
williamr@4
|
143 |
* CMacFactory::CreateMacL for the object's initialisation.
|
williamr@4
|
144 |
*
|
williamr@4
|
145 |
* @param aMac The mac plug-in instance
|
williamr@4
|
146 |
* @param aHandle The current plug-in DLL loaded
|
williamr@4
|
147 |
*/
|
williamr@4
|
148 |
CMac(MMac* aMac, TInt aHandle);
|
williamr@4
|
149 |
};
|
williamr@4
|
150 |
|
williamr@4
|
151 |
|
williamr@4
|
152 |
/**
|
williamr@4
|
153 |
* This is the asynchronous version of CMac class typically used by the
|
williamr@4
|
154 |
* client applications if hardware plug-in implementation of
|
williamr@4
|
155 |
* the MAC interface is present.
|
williamr@4
|
156 |
*/
|
williamr@4
|
157 |
|
williamr@4
|
158 |
NONSHARABLE_CLASS(CAsyncMac) : public CCryptoBase
|
williamr@4
|
159 |
{
|
williamr@4
|
160 |
public:
|
williamr@4
|
161 |
/**
|
williamr@4
|
162 |
* @internalComponent
|
williamr@4
|
163 |
* Create a CAsyncMac instance from the given MAsyncMac instance
|
williamr@4
|
164 |
*
|
williamr@4
|
165 |
* @param aMac The mac plugin instance
|
williamr@4
|
166 |
* @param aHandle The current plugin DLL loaded.
|
williamr@4
|
167 |
* @return pointer to a CMac instance
|
williamr@4
|
168 |
*/
|
williamr@4
|
169 |
static CAsyncMac* NewL(MAsyncMac* aMac, TInt aHandle);
|
williamr@4
|
170 |
|
williamr@4
|
171 |
/**
|
williamr@4
|
172 |
* Adds message to the internal representation of data for which the MAC value
|
williamr@4
|
173 |
* needs to be evaluated and then returns a TPtrC8 of the finalised MAC value
|
williamr@4
|
174 |
* of all the previously appended messages.
|
williamr@4
|
175 |
*
|
williamr@4
|
176 |
* @param aMessage The data for which MAC value is to be evaluated.
|
williamr@4
|
177 |
* @param aStatus Holds the completion status of an asynchronous
|
williamr@4
|
178 |
* request for MAC evaluation.
|
williamr@4
|
179 |
* @return A descriptor pointer to the buffer containing the
|
williamr@4
|
180 |
* resulting MAC value.
|
williamr@4
|
181 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
182 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
183 |
*/
|
williamr@4
|
184 |
IMPORT_C TPtrC8 MacL(const TDesC8& aMessage, TRequestStatus& aStatus);
|
williamr@4
|
185 |
|
williamr@4
|
186 |
/**
|
williamr@4
|
187 |
* Adds data to the internal representation of messages for which the MAC value
|
williamr@4
|
188 |
* needs to be evaluated.
|
williamr@4
|
189 |
*
|
williamr@4
|
190 |
* @param aMessage The data to be included in the MAC evaluation.
|
williamr@4
|
191 |
* @param aStatus Holds the completion status of an asynchronous
|
williamr@4
|
192 |
* request for MAC evaluation.
|
williamr@4
|
193 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
194 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
195 |
*/
|
williamr@4
|
196 |
IMPORT_C void UpdateL(const TDesC8& aMessage, TRequestStatus& aStatus);
|
williamr@4
|
197 |
|
williamr@4
|
198 |
/**
|
williamr@4
|
199 |
* Produces a final MAC value from all the previous updates of data to be MACed.
|
williamr@4
|
200 |
* It resets the MAC algorithm in a state similar to creating a new MAC instance
|
williamr@4
|
201 |
* with the same underlying algorithm and supplied symmetric key.
|
williamr@4
|
202 |
*
|
williamr@4
|
203 |
* @param aMessage The data to be included in the MAC evaluation.
|
williamr@4
|
204 |
* @param aStatus Holds the completion status of an asynchronous
|
williamr@4
|
205 |
* request for MAC evaluation.
|
williamr@4
|
206 |
* @return A descriptor pointer to the buffer containing the
|
williamr@4
|
207 |
* resulting MAC value.
|
williamr@4
|
208 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
209 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
210 |
*/
|
williamr@4
|
211 |
IMPORT_C TPtrC8 FinalL(const TDesC8& aMessage, TRequestStatus& aStatus);
|
williamr@4
|
212 |
|
williamr@4
|
213 |
/**
|
williamr@4
|
214 |
* This re-initialises the underlying MAC algorithm with a new symmetric key.
|
williamr@4
|
215 |
* It resets the MAC algorithm in a state similar to creating a new MAC instance
|
williamr@4
|
216 |
* with the same underlying algorithm but a new symmetric key.
|
williamr@4
|
217 |
*
|
williamr@4
|
218 |
* @param aKey Symmetric key for calculating message authentication code value.
|
williamr@4
|
219 |
* @leave ... Any of the crypto error codes defined in
|
williamr@4
|
220 |
cryptospi_errs.h or any of the system-wide error codes.
|
williamr@4
|
221 |
*/
|
williamr@4
|
222 |
IMPORT_C void ReInitialiseAndSetKeyL(const CKey& aKey);
|
williamr@4
|
223 |
|
williamr@4
|
224 |
/**
|
williamr@4
|
225 |
* Creates a brand new reset CAsyncMac object containing no state
|
williamr@4
|
226 |
* information from the current object.
|
williamr@4
|
227 |
*
|
williamr@4
|
228 |
* @return A pointer to the new reset CAsyncMac object
|
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 CAsyncMac* ReplicateL();
|
williamr@4
|
233 |
|
williamr@4
|
234 |
/**
|
williamr@4
|
235 |
* Creates a new CAsyncMac object with the exact same state as
|
williamr@4
|
236 |
* the current object.
|
williamr@4
|
237 |
* This function copies all internal state of the message digest.
|
williamr@4
|
238 |
*
|
williamr@4
|
239 |
* @return A pointer to the new CAsyncHash object
|
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 CAsyncMac* CopyL();
|
williamr@4
|
244 |
|
williamr@4
|
245 |
/**
|
williamr@4
|
246 |
* Cancels an outstanding request from the client.
|
williamr@4
|
247 |
*/
|
williamr@4
|
248 |
IMPORT_C void Cancel();
|
williamr@4
|
249 |
|
williamr@4
|
250 |
/**
|
williamr@4
|
251 |
* This destructor is exported so that the client application after using
|
williamr@4
|
252 |
* a specific plug-in implementation can destroy its instance. Both the framework
|
williamr@4
|
253 |
* and the plug-in use/derived from the same interface 'MPlugin.
|
williamr@4
|
254 |
* By exporting the destructor we are destroying the plug-in instance at
|
williamr@4
|
255 |
* client side via the CryptoSPI framework.
|
williamr@4
|
256 |
*/
|
williamr@4
|
257 |
IMPORT_C ~CAsyncMac();
|
williamr@4
|
258 |
|
williamr@4
|
259 |
private:
|
williamr@4
|
260 |
/**
|
williamr@4
|
261 |
* The constructor of this class is private. An user application will use
|
williamr@4
|
262 |
* CMacFactory::CreateAsyncMacL for the object's initialisation.
|
williamr@4
|
263 |
*
|
williamr@4
|
264 |
* @param aMac The mac plug-in instance
|
williamr@4
|
265 |
* @param aHandle The current plug-in DLL loaded
|
williamr@4
|
266 |
*/
|
williamr@4
|
267 |
CAsyncMac(MAsyncMac* aMac, TInt aHandle);
|
williamr@4
|
268 |
};
|
williamr@4
|
269 |
|
williamr@4
|
270 |
|
williamr@4
|
271 |
/**
|
williamr@4
|
272 |
* The Factory to create synchronous and asynchronous Mac instances
|
williamr@4
|
273 |
*/
|
williamr@4
|
274 |
|
williamr@4
|
275 |
class CMacFactory
|
williamr@4
|
276 |
{
|
williamr@4
|
277 |
public:
|
williamr@4
|
278 |
|
williamr@4
|
279 |
/**
|
williamr@4
|
280 |
* Create a CMac instance (for software based MAC plug-in dll implementation)
|
williamr@4
|
281 |
*
|
williamr@4
|
282 |
* @param aMac The pointer to CMac. This will be initialised with
|
williamr@4
|
283 |
* the plug-in implementation of the desired MAC algorithm.
|
williamr@4
|
284 |
* @param aAlgorithmUid The specific MAC algorithm desired for evaluation of MAC value.
|
williamr@4
|
285 |
* e.g. MD2, SHA1 or AES-XCBC-MAC-96, AES-XCBC-PRF-128
|
williamr@4
|
286 |
* @param aKey Symmetric key for calculating message authentication code value.
|
williamr@4
|
287 |
* @param aAlgorithmParams The parameters those are specific to a particular MAC algorithm.
|
williamr@4
|
288 |
* This is for extendibility and will normally be null.
|
williamr@4
|
289 |
* @leave KErrNone if successful; otherwise, leaves with a system wide error code.
|
williamr@4
|
290 |
*/
|
williamr@4
|
291 |
IMPORT_C static void CreateMacL(CMac*& aMac,
|
williamr@4
|
292 |
const TUid aAlgorithmUid,
|
williamr@4
|
293 |
const CKey& aKey,
|
williamr@4
|
294 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
295 |
|
williamr@4
|
296 |
/**
|
williamr@4
|
297 |
* Create a CAsyncMac instance (for hardware based MAC plug-in dll implementation)
|
williamr@4
|
298 |
*
|
williamr@4
|
299 |
* @param aMac The pointer to CMac. This will be initialised with
|
williamr@4
|
300 |
* the plug-in implementation of the desired MAC algorithm.
|
williamr@4
|
301 |
* @param aAlgorithmUid The specific MAC algorithm desired for evaluation of MAC value.
|
williamr@4
|
302 |
* e.g. MD2, SHA1 or AES-XCBC-MAC-96, AES-XCBC-PRF-128
|
williamr@4
|
303 |
* @param aKey Symmetric key for calculating message authentication code value.
|
williamr@4
|
304 |
* @param aAlgorithmParams The parameters those are specific to a particular MAC algorithm.
|
williamr@4
|
305 |
* This is for extendibility and will normally be null.
|
williamr@4
|
306 |
* @leave KErrNone if successful; otherwise, leaves with a system wide error code.
|
williamr@4
|
307 |
*/
|
williamr@4
|
308 |
IMPORT_C static void CreateAsyncMacL(CAsyncMac*& aMac,
|
williamr@4
|
309 |
const TUid aAlgorithmUid,
|
williamr@4
|
310 |
const CKey& aKey,
|
williamr@4
|
311 |
const CCryptoParams* aAlgorithmParams);
|
williamr@4
|
312 |
|
williamr@4
|
313 |
private:
|
williamr@4
|
314 |
/**
|
williamr@4
|
315 |
* The class is used as a static class since there is no data
|
williamr@4
|
316 |
* or behaviour in the class that depends on object identity.
|
williamr@4
|
317 |
* Therefore the default constructor of this class is made private.
|
williamr@4
|
318 |
*/
|
williamr@4
|
319 |
CMacFactory();
|
williamr@4
|
320 |
};
|
williamr@4
|
321 |
|
williamr@4
|
322 |
}
|
williamr@4
|
323 |
|
williamr@4
|
324 |
#endif //__CRYPTOAPI_MACAPI_H__
|