Update contrib.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * crypto MAC application interface
26 #ifndef __CRYPTOAPI_MACAPI_H__
27 #define __CRYPTOAPI_MACAPI_H__
30 #include <cryptospi/cryptobaseapi.h>
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.
50 NONSHARABLE_CLASS(CMac) : public CCryptoBase
55 * Create a CMac instance from the given MMac instance
57 * @param aMac The mac plugin instance
58 * @param aHandle The current plugin DLL loaded.
59 * @return pointer to a CMac instance
61 static CMac* NewL(MMac* aMac, TInt aHandle);
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.
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 * @leave ... Any of the crypto error codes defined in
72 cryptospi_errs.h or any of the system-wide error codes.
74 IMPORT_C TPtrC8 MacL(const TDesC8& aMessage);
77 * Adds data to the internal representation of messages for which the MAC value
78 * needs to be evaluated.
80 * @param aMessage The data to be included in the MAC evaluation.
81 * @leave ... Any of the crypto error codes defined in
82 cryptospi_errs.h or any of the system-wide error codes.
84 IMPORT_C void UpdateL(const TDesC8& aMessage);
87 * Produces a final MAC value from all the previous updates of data to be MACed.
88 * It resets the MAC algorithm in a state similar to creating a new MAC instance
89 * with the same underlying algorithm and supplied symmetric key.
91 * @param aMessage The data to be included in the MAC evaluation.
92 * @return A descriptor pointer to the buffer containing the
93 * resulting MAC value.
94 * @leave ... Any of the crypto error codes defined in
95 cryptospi_errs.h or any of the system-wide error codes.
97 IMPORT_C TPtrC8 FinalL(const TDesC8& aMessage);
100 * This re-initialises the underlying MAC algorithm with a new symmetric key.
101 * It resets the MAC algorithm in a state similar to creating a new MAC instance
102 * with the same underlying algorithm but a new symmetric key.
104 * @param aKey Symmetric key for calculating message authentication code value.
105 * @leave ... Any of the crypto error codes defined in
106 cryptospi_errs.h or any of the system-wide error codes.
108 IMPORT_C void ReInitialiseAndSetKeyL(const CKey& aKey);
111 * Creates a brand new reset CMac object containing no state
112 * information from the current object.
114 * @return A pointer to the new reset CMac object
115 * @leave ... Any of the crypto error codes defined in
116 cryptospi_errs.h or any of the system-wide error codes.
118 IMPORT_C CMac* ReplicateL();
121 * Creates a new CMac object with the exact same state as
122 * the current object.
123 * This function copies all internal state of the message digest.
125 * @return A pointer to the new CMac object
126 * @leave ... Any of the crypto error codes defined in
127 cryptospi_errs.h or any of the system-wide error codes.
129 IMPORT_C CMac* CopyL();
132 * This destructor is exported so that the client application after using
133 * a specific plug-in implementation can destroy its instance. Both the framework
134 * and the plug-in use/derived from the same interface 'MPlugin.
135 * By exporting the destructor we are destroying the plug-in instance at
136 * client side via the CryptoSPI framework.
142 * The constructor of this class is private. An user application will use
143 * CMacFactory::CreateMacL for the object's initialisation.
145 * @param aMac The mac plug-in instance
146 * @param aHandle The current plug-in DLL loaded
148 CMac(MMac* aMac, TInt aHandle);
153 * This is the asynchronous version of CMac class typically used by the
154 * client applications if hardware plug-in implementation of
155 * the MAC interface is present.
158 NONSHARABLE_CLASS(CAsyncMac) : public CCryptoBase
163 * Create a CAsyncMac instance from the given MAsyncMac instance
165 * @param aMac The mac plugin instance
166 * @param aHandle The current plugin DLL loaded.
167 * @return pointer to a CMac instance
169 static CAsyncMac* NewL(MAsyncMac* aMac, TInt aHandle);
172 * Adds message to the internal representation of data for which the MAC value
173 * needs to be evaluated and then returns a TPtrC8 of the finalised MAC value
174 * of all the previously appended messages.
176 * @param aMessage The data for which MAC value is to be evaluated.
177 * @param aStatus Holds the completion status of an asynchronous
178 * request for MAC evaluation.
179 * @return A descriptor pointer to the buffer containing the
180 * resulting MAC value.
181 * @leave ... Any of the crypto error codes defined in
182 cryptospi_errs.h or any of the system-wide error codes.
184 IMPORT_C TPtrC8 MacL(const TDesC8& aMessage, TRequestStatus& aStatus);
187 * Adds data to the internal representation of messages for which the MAC value
188 * needs to be evaluated.
190 * @param aMessage The data to be included in the MAC evaluation.
191 * @param aStatus Holds the completion status of an asynchronous
192 * request for MAC evaluation.
193 * @leave ... Any of the crypto error codes defined in
194 cryptospi_errs.h or any of the system-wide error codes.
196 IMPORT_C void UpdateL(const TDesC8& aMessage, TRequestStatus& aStatus);
199 * Produces a final MAC value from all the previous updates of data to be MACed.
200 * It resets the MAC algorithm in a state similar to creating a new MAC instance
201 * with the same underlying algorithm and supplied symmetric key.
203 * @param aMessage The data to be included in the MAC evaluation.
204 * @param aStatus Holds the completion status of an asynchronous
205 * request for MAC evaluation.
206 * @return A descriptor pointer to the buffer containing the
207 * resulting MAC value.
208 * @leave ... Any of the crypto error codes defined in
209 cryptospi_errs.h or any of the system-wide error codes.
211 IMPORT_C TPtrC8 FinalL(const TDesC8& aMessage, TRequestStatus& aStatus);
214 * This re-initialises the underlying MAC algorithm with a new symmetric key.
215 * It resets the MAC algorithm in a state similar to creating a new MAC instance
216 * with the same underlying algorithm but a new symmetric key.
218 * @param aKey Symmetric key for calculating message authentication code value.
219 * @leave ... Any of the crypto error codes defined in
220 cryptospi_errs.h or any of the system-wide error codes.
222 IMPORT_C void ReInitialiseAndSetKeyL(const CKey& aKey);
225 * Creates a brand new reset CAsyncMac object containing no state
226 * information from the current object.
228 * @return A pointer to the new reset CAsyncMac object
229 * @leave ... Any of the crypto error codes defined in
230 cryptospi_errs.h or any of the system-wide error codes.
232 IMPORT_C CAsyncMac* ReplicateL();
235 * Creates a new CAsyncMac object with the exact same state as
236 * the current object.
237 * This function copies all internal state of the message digest.
239 * @return A pointer to the new CAsyncHash object
240 * @leave ... Any of the crypto error codes defined in
241 cryptospi_errs.h or any of the system-wide error codes.
243 IMPORT_C CAsyncMac* CopyL();
246 * Cancels an outstanding request from the client.
248 IMPORT_C void Cancel();
251 * This destructor is exported so that the client application after using
252 * a specific plug-in implementation can destroy its instance. Both the framework
253 * and the plug-in use/derived from the same interface 'MPlugin.
254 * By exporting the destructor we are destroying the plug-in instance at
255 * client side via the CryptoSPI framework.
257 IMPORT_C ~CAsyncMac();
261 * The constructor of this class is private. An user application will use
262 * CMacFactory::CreateAsyncMacL for the object's initialisation.
264 * @param aMac The mac plug-in instance
265 * @param aHandle The current plug-in DLL loaded
267 CAsyncMac(MAsyncMac* aMac, TInt aHandle);
272 * The Factory to create synchronous and asynchronous Mac instances
280 * Create a CMac instance (for software based MAC plug-in dll implementation)
282 * @param aMac The pointer to CMac. This will be initialised with
283 * the plug-in implementation of the desired MAC algorithm.
284 * @param aAlgorithmUid The specific MAC algorithm desired for evaluation of MAC value.
285 * e.g. MD2, SHA1 or AES-XCBC-MAC-96, AES-XCBC-PRF-128
286 * @param aKey Symmetric key for calculating message authentication code value.
287 * @param aAlgorithmParams The parameters those are specific to a particular MAC algorithm.
288 * This is for extendibility and will normally be null.
289 * @leave KErrNone if successful; otherwise, leaves with a system wide error code.
291 IMPORT_C static void CreateMacL(CMac*& aMac,
292 const TUid aAlgorithmUid,
294 const CCryptoParams* aAlgorithmParams);
297 * Create a CAsyncMac instance (for hardware based MAC plug-in dll implementation)
299 * @param aMac The pointer to CMac. This will be initialised with
300 * the plug-in implementation of the desired MAC algorithm.
301 * @param aAlgorithmUid The specific MAC algorithm desired for evaluation of MAC value.
302 * e.g. MD2, SHA1 or AES-XCBC-MAC-96, AES-XCBC-PRF-128
303 * @param aKey Symmetric key for calculating message authentication code value.
304 * @param aAlgorithmParams The parameters those are specific to a particular MAC algorithm.
305 * This is for extendibility and will normally be null.
306 * @leave KErrNone if successful; otherwise, leaves with a system wide error code.
308 IMPORT_C static void CreateAsyncMacL(CAsyncMac*& aMac,
309 const TUid aAlgorithmUid,
311 const CCryptoParams* aAlgorithmParams);
315 * The class is used as a static class since there is no data
316 * or behaviour in the class that depends on object identity.
317 * Therefore the default constructor of this class is made private.
324 #endif //__CRYPTOAPI_MACAPI_H__