sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-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 symmetric cipher application interface
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
/**
|
sl@0
|
21 |
@file
|
sl@0
|
22 |
@publishedPartner
|
sl@0
|
23 |
@released
|
sl@0
|
24 |
*/
|
sl@0
|
25 |
|
sl@0
|
26 |
#ifndef __CRYPTOAPI_SYMMETRICCIPHERAPI_H__
|
sl@0
|
27 |
#define __CRYPTOAPI_SYMMETRICCIPHERAPI_H__
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <e32base.h>
|
sl@0
|
30 |
#include <cryptospi/cryptobaseapi.h>
|
sl@0
|
31 |
|
sl@0
|
32 |
namespace CryptoSpi
|
sl@0
|
33 |
{
|
sl@0
|
34 |
class MSymmetricCipherBase;
|
sl@0
|
35 |
class MSymmetricCipher;
|
sl@0
|
36 |
class MAsyncSymmetricCipher;
|
sl@0
|
37 |
class CKey;
|
sl@0
|
38 |
class CCryptoParams;
|
sl@0
|
39 |
|
sl@0
|
40 |
NONSHARABLE_CLASS(CSymmetricCipherBase) : public CCryptoBase
|
sl@0
|
41 |
{
|
sl@0
|
42 |
public:
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
Destructor
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
virtual ~CSymmetricCipherBase();
|
sl@0
|
47 |
|
sl@0
|
48 |
/**
|
sl@0
|
49 |
Set the key of this cipher. Reset() is called to reinitialise the cipher.
|
sl@0
|
50 |
@param aKey The symmetric key.
|
sl@0
|
51 |
@leave KErrArgument if aKey is not of the expected type.
|
sl@0
|
52 |
@leave KErrNotSupported if the key is not of valid length.
|
sl@0
|
53 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
54 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
55 |
*/
|
sl@0
|
56 |
IMPORT_C void SetKeyL(const CKey& aKey);
|
sl@0
|
57 |
|
sl@0
|
58 |
/**
|
sl@0
|
59 |
Set the operation mode of this cipher. Reset() is called to reinitialise the cipher.
|
sl@0
|
60 |
@param aOperationMode The operation mode e.g. CBC, ECB etc
|
sl@0
|
61 |
@leave KErrNotSupported if the operation mode is not supported.
|
sl@0
|
62 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
63 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
64 |
*/
|
sl@0
|
65 |
IMPORT_C void SetOperationModeL(TUid aOperationMode);
|
sl@0
|
66 |
|
sl@0
|
67 |
/**
|
sl@0
|
68 |
Set the crypto mode of this cipher. Reset() is called to reinitialise the cipher.
|
sl@0
|
69 |
@param aCryptoMode The crypto mode e.g encryption, decryption
|
sl@0
|
70 |
@leave KErrNotSupported if the crypto mode is not supported.
|
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 void SetCryptoModeL(TUid aCryptoMode);
|
sl@0
|
75 |
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
Set padding mode of this cipher. Reset() is called to reinitialise the cipher.
|
sl@0
|
78 |
@param aPaddingMode The padding mode e.g. SSLv3, PKCS7
|
sl@0
|
79 |
@leave KErrNotSupported if the padding mode is not supported.
|
sl@0
|
80 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
81 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
82 |
*/
|
sl@0
|
83 |
IMPORT_C void SetPaddingModeL(TUid aPaddingMode);
|
sl@0
|
84 |
|
sl@0
|
85 |
/**
|
sl@0
|
86 |
Set the initialization vector of this cipher. Reset() is called to reinitialise the cipher.
|
sl@0
|
87 |
@param aIV The initialization vector.
|
sl@0
|
88 |
@leave KErrNotSupported if the current mode of operation does not support this.
|
sl@0
|
89 |
@leave KErrArgument If the length of the Iv is not equal to the block size.
|
sl@0
|
90 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
91 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
IMPORT_C void SetIvL(const TDesC8& aIv);
|
sl@0
|
94 |
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
Returns the maximum length that an output buffer would need to be in order to hold the result
|
sl@0
|
97 |
of the next process operation, given the input length inputLen and the internal
|
sl@0
|
98 |
state of the state of the cipher.
|
sl@0
|
99 |
@param aInputLength The length of the input to process
|
sl@0
|
100 |
@return The length of the output buffer
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
IMPORT_C TInt MaxOutputLength(TInt aInputLength);
|
sl@0
|
103 |
|
sl@0
|
104 |
/**
|
sl@0
|
105 |
Returns the maximum length that an output buffer would need to be in order to hold the result
|
sl@0
|
106 |
of the next processfinal operation, given the input length inputLen and the
|
sl@0
|
107 |
internal state of the cipher.
|
sl@0
|
108 |
@param aInputLength The length of input to process
|
sl@0
|
109 |
@return The length of the output buffer
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
IMPORT_C TInt MaxFinalOutputLength(TInt aInputLength);
|
sl@0
|
112 |
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
Returns the block size in bits. For stream ciphers this is defined to be
|
sl@0
|
115 |
8-bits.
|
sl@0
|
116 |
@return The block size in bits
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
IMPORT_C TInt BlockSize();
|
sl@0
|
119 |
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
Returns the size of the current key in bits.
|
sl@0
|
122 |
@return The size of the current key in bits
|
sl@0
|
123 |
*/
|
sl@0
|
124 |
IMPORT_C TInt KeySize();
|
sl@0
|
125 |
|
sl@0
|
126 |
protected:
|
sl@0
|
127 |
/**
|
sl@0
|
128 |
* @internalComponent
|
sl@0
|
129 |
*
|
sl@0
|
130 |
* Constructor
|
sl@0
|
131 |
**/
|
sl@0
|
132 |
CSymmetricCipherBase(MSymmetricCipherBase* aSymmetricCipher, TInt aHandle);
|
sl@0
|
133 |
};
|
sl@0
|
134 |
|
sl@0
|
135 |
|
sl@0
|
136 |
/**
|
sl@0
|
137 |
Symmetric Cipher API, which wraps a synchronous Symmetric Cipher plugin implementation
|
sl@0
|
138 |
*/
|
sl@0
|
139 |
NONSHARABLE_CLASS(CSymmetricCipher) : public CSymmetricCipherBase
|
sl@0
|
140 |
{
|
sl@0
|
141 |
public:
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
* @internalComponent
|
sl@0
|
145 |
*
|
sl@0
|
146 |
* Create a CSymmetricCipher instance from the given MSymmetricCipher instance
|
sl@0
|
147 |
* @param aSymmetricCipher an Sync Symmetric Cipher plugin instance
|
sl@0
|
148 |
* @return A pointer to a CSymmetricCipher instance
|
sl@0
|
149 |
**/
|
sl@0
|
150 |
static CSymmetricCipher* NewL(MSymmetricCipher* aSymmetricCipher, TInt aHandle);
|
sl@0
|
151 |
|
sl@0
|
152 |
/**
|
sl@0
|
153 |
Destructor
|
sl@0
|
154 |
*/
|
sl@0
|
155 |
IMPORT_C ~CSymmetricCipher();
|
sl@0
|
156 |
|
sl@0
|
157 |
/**
|
sl@0
|
158 |
Encrypts or decrypts aInput and appends the result to aOutput.
|
sl@0
|
159 |
@param aInput The input data to be processed.
|
sl@0
|
160 |
@param aOutput The resulting processed data appended to aOutput.
|
sl@0
|
161 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
162 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
163 |
*/
|
sl@0
|
164 |
IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
165 |
|
sl@0
|
166 |
/**
|
sl@0
|
167 |
Pads aInput to be block aligned using the underlying padding system, then
|
sl@0
|
168 |
encrypts or decrypts the input data, and appends the result to aOutput
|
sl@0
|
169 |
@param aInput The input buffer to be encrypted or decrypted.
|
sl@0
|
170 |
@param aOutput The resulting, padded, processed data is appended to aOutput.
|
sl@0
|
171 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
172 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
173 |
*/
|
sl@0
|
174 |
IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
175 |
|
sl@0
|
176 |
private:
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
Constructor
|
sl@0
|
179 |
*/
|
sl@0
|
180 |
CSymmetricCipher(MSymmetricCipher* aSymmetricCipher, TInt aHandle);
|
sl@0
|
181 |
};
|
sl@0
|
182 |
|
sl@0
|
183 |
/**
|
sl@0
|
184 |
Async Symmetric Cipher API, which wraps an asynchronous Symmetric Cipher plugin implementation
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
NONSHARABLE_CLASS(CAsyncSymmetricCipher) : public CSymmetricCipherBase
|
sl@0
|
187 |
{
|
sl@0
|
188 |
public:
|
sl@0
|
189 |
|
sl@0
|
190 |
/**
|
sl@0
|
191 |
* @internalComponent
|
sl@0
|
192 |
*
|
sl@0
|
193 |
* Create a CAsyncSymmetricCipher instance from the given MAsyncSymmetricCipher instance
|
sl@0
|
194 |
* @param aAsyncSymmetricCipher an async Symmetric Cipher plugin instance
|
sl@0
|
195 |
* @return A pointer to a CAsyncSymmetricCipher instance
|
sl@0
|
196 |
**/
|
sl@0
|
197 |
static CAsyncSymmetricCipher* NewL(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle);
|
sl@0
|
198 |
|
sl@0
|
199 |
/**
|
sl@0
|
200 |
Destructor
|
sl@0
|
201 |
*/
|
sl@0
|
202 |
IMPORT_C ~CAsyncSymmetricCipher();
|
sl@0
|
203 |
|
sl@0
|
204 |
/**
|
sl@0
|
205 |
Encrypts or decrypts aInput and appends the result to aOutput asynchronously
|
sl@0
|
206 |
@param aInput The input data to be processed.
|
sl@0
|
207 |
@param aOutput The resulting processed data appended to aOutput.
|
sl@0
|
208 |
@param aRequestStatus
|
sl@0
|
209 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
210 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
211 |
*/
|
sl@0
|
212 |
IMPORT_C void ProcessL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus);
|
sl@0
|
213 |
|
sl@0
|
214 |
/**
|
sl@0
|
215 |
Asynchronously pads aInput to be block aligned using the underlying padding system,
|
sl@0
|
216 |
encrypts or decrypts the input data, and appends the result to aOutput
|
sl@0
|
217 |
@param aInput The input buffer to be encrypted or decrypted.
|
sl@0
|
218 |
@param aOutput The resulting, padded, processed data is appended to aOutput.
|
sl@0
|
219 |
@param aRequestStatus
|
sl@0
|
220 |
@leave ... Any of the crypto error codes defined in
|
sl@0
|
221 |
cryptospi_errs.h or any of the system-wide error codes.
|
sl@0
|
222 |
*/
|
sl@0
|
223 |
IMPORT_C void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput, TRequestStatus& aRequestStatus);
|
sl@0
|
224 |
|
sl@0
|
225 |
/**
|
sl@0
|
226 |
Cancel the outstanding request
|
sl@0
|
227 |
*/
|
sl@0
|
228 |
IMPORT_C void Cancel();
|
sl@0
|
229 |
|
sl@0
|
230 |
private:
|
sl@0
|
231 |
/**
|
sl@0
|
232 |
Construtor
|
sl@0
|
233 |
*/
|
sl@0
|
234 |
CAsyncSymmetricCipher(MAsyncSymmetricCipher* aAsyncSymmetricCipher, TInt aHandle);
|
sl@0
|
235 |
};
|
sl@0
|
236 |
|
sl@0
|
237 |
|
sl@0
|
238 |
/**
|
sl@0
|
239 |
This Factory to create synchronous and asynchronous symmetric cipher instances
|
sl@0
|
240 |
*/
|
sl@0
|
241 |
class CSymmetricCipherFactory
|
sl@0
|
242 |
{
|
sl@0
|
243 |
public:
|
sl@0
|
244 |
|
sl@0
|
245 |
/**
|
sl@0
|
246 |
Creates a new synchronous instance of a symmetric cipher
|
sl@0
|
247 |
|
sl@0
|
248 |
@param aCipher A reference to a pointer that should be set to point to the new symmetric object.
|
sl@0
|
249 |
@param aAlgorithmUid The algorithm to use
|
sl@0
|
250 |
@param aKey The encryption/decryption key.
|
sl@0
|
251 |
@param aCryptoMode The Symmetric cipher mode.
|
sl@0
|
252 |
@param aOperationMode The Symmetric cipher operation mode.
|
sl@0
|
253 |
@param aPaddingMode The Symmetric cipher padding mode.
|
sl@0
|
254 |
@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
|
sl@0
|
255 |
@return KErrNone if successful; otherwise, a system wide error code.
|
sl@0
|
256 |
*/
|
sl@0
|
257 |
IMPORT_C static void CreateSymmetricCipherL(CSymmetricCipher*& aCipher,
|
sl@0
|
258 |
TUid aAlgorithmUid,
|
sl@0
|
259 |
const CKey& aKey,
|
sl@0
|
260 |
TUid aCryptoMode,
|
sl@0
|
261 |
TUid aOperationMode,
|
sl@0
|
262 |
TUid aPaddingMode,
|
sl@0
|
263 |
const CCryptoParams* aAlgorithmParams);
|
sl@0
|
264 |
|
sl@0
|
265 |
/**
|
sl@0
|
266 |
Creates a new asynchronous instance of a symmetric cipher
|
sl@0
|
267 |
|
sl@0
|
268 |
@param aAsyncCipher A reference to a pointer that should be set to point to the new symmetric object.
|
sl@0
|
269 |
@param aAlgorithmUid The algorithm to use
|
sl@0
|
270 |
@param aKey The encryption/decryption key.
|
sl@0
|
271 |
@param aCryptoMode The Symmetric cipher mode.
|
sl@0
|
272 |
@param aOperationMode The Symmetric cipher operation mode.
|
sl@0
|
273 |
@param aPaddingMode The Symmetric cipher padding mode.
|
sl@0
|
274 |
@param aAlgorithmParams Parameters that are specific to a particular algorithm. This is for extendibility and will normally be null.
|
sl@0
|
275 |
@return KErrNone if successful; otherwise, a system wide error code.
|
sl@0
|
276 |
*/
|
sl@0
|
277 |
IMPORT_C static void CreateAsyncSymmetricCipherL(CAsyncSymmetricCipher*& aAsyncCipher,
|
sl@0
|
278 |
TUid aAlgorithmUid,
|
sl@0
|
279 |
const CKey& aKey,
|
sl@0
|
280 |
TUid aCryptoMode,
|
sl@0
|
281 |
TUid aOperationMode,
|
sl@0
|
282 |
TUid aPaddingMode,
|
sl@0
|
283 |
const CCryptoParams* aAlgorithmParams);
|
sl@0
|
284 |
|
sl@0
|
285 |
};
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
#endif //__CRYPTOAPI_SYMMETRICCIPHERAPI_H__
|