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