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