sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2002-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 |
* ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the
|
sl@0
|
16 |
* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
@publishedPartner
|
sl@0
|
24 |
@released
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifndef __PBENCRYPTOR_H__
|
sl@0
|
28 |
#define __PBENCRYPTOR_H__
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <pbe.h>
|
sl@0
|
31 |
#include <padding.h>
|
sl@0
|
32 |
#include <msymmetriccipher.h>
|
sl@0
|
33 |
|
sl@0
|
34 |
/**
|
sl@0
|
35 |
* Implements the password based encryption of elements.
|
sl@0
|
36 |
*
|
sl@0
|
37 |
* @see CPBEncryptElement
|
sl@0
|
38 |
* @since v7.0s
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
class CPBEncryptorElement : public CPBEncryptor
|
sl@0
|
41 |
{
|
sl@0
|
42 |
public:
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
* Creates a new CPBEncryptorElement object from the specified cipher,
|
sl@0
|
45 |
* key, and Initialization Vector (IV).
|
sl@0
|
46 |
*
|
sl@0
|
47 |
* @param aCipher The encryption cipher
|
sl@0
|
48 |
* @param aKey The encryption key
|
sl@0
|
49 |
* @param aIV The Initialization Vector
|
sl@0
|
50 |
* @return A pointer to the new CPBEncryptorElement object
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
IMPORT_C static CPBEncryptorElement* NewL(TPBECipher aCipher,
|
sl@0
|
53 |
const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
54 |
|
sl@0
|
55 |
/**
|
sl@0
|
56 |
* Creates a new CPBEncryptorElement object from the specified cipher,
|
sl@0
|
57 |
* key, and IV.
|
sl@0
|
58 |
*
|
sl@0
|
59 |
* Puts a pointer to the returned object onto the cleanup stack.
|
sl@0
|
60 |
*
|
sl@0
|
61 |
* @param aCipher The encryption cipher
|
sl@0
|
62 |
* @param aKey The encryption key
|
sl@0
|
63 |
* @param aIV The Initialization Vector
|
sl@0
|
64 |
* @return A pointer to the new CPBEncryptorElement object
|
sl@0
|
65 |
*/
|
sl@0
|
66 |
IMPORT_C static CPBEncryptorElement* NewLC(TPBECipher aCipher,
|
sl@0
|
67 |
const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
68 |
|
sl@0
|
69 |
/**
|
sl@0
|
70 |
* Transforms aInput into its encrypted form, aOutput.
|
sl@0
|
71 |
*
|
sl@0
|
72 |
* aOutput must have CPBEncryptorElement::MaxOutputLength() empty bytes remaining in its length.
|
sl@0
|
73 |
*
|
sl@0
|
74 |
* See the Cryptography api-guide documentation for an explanation of
|
sl@0
|
75 |
* how buffering of data supplied to this function is handled.
|
sl@0
|
76 |
*
|
sl@0
|
77 |
* @param aInput The plaintext.
|
sl@0
|
78 |
* @param aOutput The ciphertext.
|
sl@0
|
79 |
*/
|
sl@0
|
80 |
void Process(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
81 |
|
sl@0
|
82 |
/**
|
sl@0
|
83 |
* Transforms aInput into its encrypted form, aOutput, and applies a
|
sl@0
|
84 |
* padding scheme to ensure a block aligned result.
|
sl@0
|
85 |
*
|
sl@0
|
86 |
* aOutput must have CPBEncryptorElement::MaxFinalOutputLength()
|
sl@0
|
87 |
* empty bytes remaining in its length.
|
sl@0
|
88 |
*
|
sl@0
|
89 |
* See the Cryptography api-guide documentation for an explanation of
|
sl@0
|
90 |
* how buffering of data supplied to this function is handled.
|
sl@0
|
91 |
*
|
sl@0
|
92 |
* @param aInput The plaintext.
|
sl@0
|
93 |
* @param aOutput The ciphertext.
|
sl@0
|
94 |
*/
|
sl@0
|
95 |
void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
96 |
|
sl@0
|
97 |
/**
|
sl@0
|
98 |
* Gets the maximum size of the output resulting from calling Process() with a
|
sl@0
|
99 |
* given input length.
|
sl@0
|
100 |
*
|
sl@0
|
101 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
102 |
* @return The maximum output length in bytes.
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
TInt MaxOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
105 |
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
* Gets the maximum size of the output resulting from calling ProcessFinalL()
|
sl@0
|
108 |
* with a given input length.
|
sl@0
|
109 |
*
|
sl@0
|
110 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
111 |
* @return TInt The maximum output length in bytes.
|
sl@0
|
112 |
*/
|
sl@0
|
113 |
TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
114 |
|
sl@0
|
115 |
/** Destructor */
|
sl@0
|
116 |
virtual ~CPBEncryptorElement();
|
sl@0
|
117 |
protected:
|
sl@0
|
118 |
CPBEncryptorElement();
|
sl@0
|
119 |
void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
120 |
private:
|
sl@0
|
121 |
CSymmetricCipher* iCipher;
|
sl@0
|
122 |
};
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
* Implements the password based decryption of elements.
|
sl@0
|
126 |
*
|
sl@0
|
127 |
* @since v7.0s
|
sl@0
|
128 |
*/
|
sl@0
|
129 |
class CPBDecryptorElement : public CPBDecryptor
|
sl@0
|
130 |
{
|
sl@0
|
131 |
public:
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
* Creates a new CPBDecryptorElement object from the specified cipher,
|
sl@0
|
134 |
* key, and IV.
|
sl@0
|
135 |
*
|
sl@0
|
136 |
* @param aCipher The decryption cipher
|
sl@0
|
137 |
* @param aKey The decryption key
|
sl@0
|
138 |
* @param aIV The Initialization Vector
|
sl@0
|
139 |
* @return A pointer to the new CPBDecryptorElement object
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
IMPORT_C static CPBDecryptorElement* NewL(const TPBECipher aCipher,
|
sl@0
|
142 |
const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
143 |
|
sl@0
|
144 |
/**
|
sl@0
|
145 |
* Creates a new CPBDecryptorElement object from the specified cipher,
|
sl@0
|
146 |
* key, and IV.
|
sl@0
|
147 |
*
|
sl@0
|
148 |
* Puts a pointer to the returned object onto the cleanup stack.
|
sl@0
|
149 |
*
|
sl@0
|
150 |
* @param aCipher The decryption cipher
|
sl@0
|
151 |
* @param aKey The decryption key
|
sl@0
|
152 |
* @param aIV The Initialization Vector
|
sl@0
|
153 |
* @return A pointer to the new CPBDecryptorElement object
|
sl@0
|
154 |
*/
|
sl@0
|
155 |
IMPORT_C static CPBDecryptorElement* NewLC(const TPBECipher aCipher,
|
sl@0
|
156 |
const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
157 |
|
sl@0
|
158 |
/**
|
sl@0
|
159 |
* Transforms aInput into its decrypted form, aOutput.
|
sl@0
|
160 |
*
|
sl@0
|
161 |
* aOutput must have CPBDecryptorElement::MaxOutputLength() empty bytes
|
sl@0
|
162 |
* remaining in its length.
|
sl@0
|
163 |
*
|
sl@0
|
164 |
* See the Cryptography api-guide documentation for an explanation of
|
sl@0
|
165 |
* how buffering of data supplied to this function is handled.
|
sl@0
|
166 |
*
|
sl@0
|
167 |
* @param aInput The ciphertext.
|
sl@0
|
168 |
* @param aOutput The plaintext.
|
sl@0
|
169 |
*/
|
sl@0
|
170 |
void Process(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
171 |
|
sl@0
|
172 |
/**
|
sl@0
|
173 |
* Transforms aInput into its decrypted form, aOutput.
|
sl@0
|
174 |
*
|
sl@0
|
175 |
* aOutput must have CPBDecryptorElement::MaxFinalOutputLength()
|
sl@0
|
176 |
* empty bytes remaining in its length.
|
sl@0
|
177 |
*
|
sl@0
|
178 |
* @param aInput The ciphertext.
|
sl@0
|
179 |
* @param aOutput The plaintext.
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
182 |
|
sl@0
|
183 |
/**
|
sl@0
|
184 |
* Gets the maximum size of the output given a certain input length.
|
sl@0
|
185 |
*
|
sl@0
|
186 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
187 |
* @return The maximum output length in bytes.
|
sl@0
|
188 |
*/
|
sl@0
|
189 |
TInt MaxOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
190 |
|
sl@0
|
191 |
/**
|
sl@0
|
192 |
* Gets the maximum size of the output given a certain input length.
|
sl@0
|
193 |
*
|
sl@0
|
194 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
195 |
* @return The maximum output length in bytes.
|
sl@0
|
196 |
*/
|
sl@0
|
197 |
TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
198 |
|
sl@0
|
199 |
/** Destructor */
|
sl@0
|
200 |
virtual ~CPBDecryptorElement();
|
sl@0
|
201 |
protected:
|
sl@0
|
202 |
CPBDecryptorElement();
|
sl@0
|
203 |
void ConstructL(const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
204 |
private:
|
sl@0
|
205 |
CSymmetricCipher* iCipher;
|
sl@0
|
206 |
};
|
sl@0
|
207 |
|
sl@0
|
208 |
/**
|
sl@0
|
209 |
* Implements the password based encryption of multiple elements.
|
sl@0
|
210 |
*
|
sl@0
|
211 |
* @see CPBEncryptSet
|
sl@0
|
212 |
* @since v7.0s
|
sl@0
|
213 |
*/
|
sl@0
|
214 |
class CPBEncryptorSet : public CPBEncryptor
|
sl@0
|
215 |
{
|
sl@0
|
216 |
public:
|
sl@0
|
217 |
/**
|
sl@0
|
218 |
* Creates a new CPBEncryptorSet object from the specified cipher and key,
|
sl@0
|
219 |
* and a random Initialization Vector (IV).
|
sl@0
|
220 |
*
|
sl@0
|
221 |
* @param aCipher The encryption cipher
|
sl@0
|
222 |
* @param aKey The encryption key
|
sl@0
|
223 |
* @return A pointer to the new CPBEncryptorSet object
|
sl@0
|
224 |
*/
|
sl@0
|
225 |
IMPORT_C static CPBEncryptorSet* NewL(const TPBECipher aCipher,
|
sl@0
|
226 |
const TDesC8& aKey);
|
sl@0
|
227 |
|
sl@0
|
228 |
/**
|
sl@0
|
229 |
* Creates a new CPBEncryptorSet object from the specified cipher and key,
|
sl@0
|
230 |
* and a random IV.
|
sl@0
|
231 |
*
|
sl@0
|
232 |
* Puts a pointer to the returned object onto the cleanup stack.
|
sl@0
|
233 |
*
|
sl@0
|
234 |
* @param aCipher The encryption cipher
|
sl@0
|
235 |
* @param aKey The encryption key
|
sl@0
|
236 |
* @return A pointer to the new CPBEncryptorSet object
|
sl@0
|
237 |
*/
|
sl@0
|
238 |
IMPORT_C static CPBEncryptorSet* NewLC(const TPBECipher aCipher,
|
sl@0
|
239 |
const TDesC8& aKey);
|
sl@0
|
240 |
|
sl@0
|
241 |
/**
|
sl@0
|
242 |
* Resets the CPBEncryptorSet object back to its original state
|
sl@0
|
243 |
* and clears all its buffers.
|
sl@0
|
244 |
*/
|
sl@0
|
245 |
IMPORT_C void Reset(void);
|
sl@0
|
246 |
|
sl@0
|
247 |
/**
|
sl@0
|
248 |
* Transforms aInput into its encrypted form, aOutput.
|
sl@0
|
249 |
*
|
sl@0
|
250 |
* aOutput must have CPBEncryptorSet::MaxOutputLength() empty bytes
|
sl@0
|
251 |
* remaining in its length.
|
sl@0
|
252 |
*
|
sl@0
|
253 |
* @param aInput The plaintext.
|
sl@0
|
254 |
* @param aOutput The ciphertext.
|
sl@0
|
255 |
*/
|
sl@0
|
256 |
void Process(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
257 |
|
sl@0
|
258 |
/**
|
sl@0
|
259 |
* Transforms aInput into its encrypted form, aOutput, and applies a
|
sl@0
|
260 |
* padding scheme to ensure a block aligned result.
|
sl@0
|
261 |
*
|
sl@0
|
262 |
* aOutput must have CPBEncryptorSet::MaxFinalOutputLength()
|
sl@0
|
263 |
* empty bytes remaining in its length.
|
sl@0
|
264 |
*
|
sl@0
|
265 |
* @param aInput The plaintext.
|
sl@0
|
266 |
* @param aOutput The ciphertext.
|
sl@0
|
267 |
*/
|
sl@0
|
268 |
void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
269 |
|
sl@0
|
270 |
/**
|
sl@0
|
271 |
* Gets the maximum size of the output given a certain input length.
|
sl@0
|
272 |
*
|
sl@0
|
273 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
274 |
* @return The maximum output length in bytes.
|
sl@0
|
275 |
*/
|
sl@0
|
276 |
TInt MaxOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
277 |
|
sl@0
|
278 |
/**
|
sl@0
|
279 |
* Gets the maximum size of the output given a certain input length.
|
sl@0
|
280 |
*
|
sl@0
|
281 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
282 |
* @return The maximum output length in bytes.
|
sl@0
|
283 |
*/
|
sl@0
|
284 |
TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
285 |
|
sl@0
|
286 |
/** Destructor */
|
sl@0
|
287 |
virtual ~CPBEncryptorSet();
|
sl@0
|
288 |
protected:
|
sl@0
|
289 |
CPBEncryptorSet();
|
sl@0
|
290 |
void ConstructL(TPBECipher aCipher, const TDesC8& aKey);
|
sl@0
|
291 |
private:
|
sl@0
|
292 |
CSymmetricCipher* iCipher;
|
sl@0
|
293 |
HBufC8* iIV;
|
sl@0
|
294 |
TBool iIVSent;
|
sl@0
|
295 |
};
|
sl@0
|
296 |
|
sl@0
|
297 |
|
sl@0
|
298 |
/**
|
sl@0
|
299 |
* Implements the password based decryption of multiple elements.
|
sl@0
|
300 |
*
|
sl@0
|
301 |
* @since v7.0s
|
sl@0
|
302 |
*/
|
sl@0
|
303 |
class CPBDecryptorSet : public CPBDecryptor
|
sl@0
|
304 |
{
|
sl@0
|
305 |
public:
|
sl@0
|
306 |
/**
|
sl@0
|
307 |
* Creates a new CPBDecryptorSet object from the specified cipher and key,
|
sl@0
|
308 |
* and a random IV.
|
sl@0
|
309 |
*
|
sl@0
|
310 |
* @param aCipher The decryption cipher
|
sl@0
|
311 |
* @param aKey The decryption key
|
sl@0
|
312 |
* @return A pointer to the new CPBDecryptorSet object
|
sl@0
|
313 |
*/
|
sl@0
|
314 |
IMPORT_C static CPBDecryptorSet* NewL(const TPBECipher aCipher,
|
sl@0
|
315 |
const TDesC8& aKey);
|
sl@0
|
316 |
|
sl@0
|
317 |
/**
|
sl@0
|
318 |
* Creates a new CPBDecryptorSet object from the specified cipher and key,
|
sl@0
|
319 |
* and a random IV.
|
sl@0
|
320 |
*
|
sl@0
|
321 |
* Puts a pointer to the returned object onto the cleanup stack.
|
sl@0
|
322 |
*
|
sl@0
|
323 |
* @param aCipher The decryption cipher
|
sl@0
|
324 |
* @param aKey The decryption key
|
sl@0
|
325 |
* @return A pointer to the new CPBDecryptorSet object
|
sl@0
|
326 |
*/
|
sl@0
|
327 |
IMPORT_C static CPBDecryptorSet* NewLC(const TPBECipher aCipher,
|
sl@0
|
328 |
const TDesC8& aKey);
|
sl@0
|
329 |
|
sl@0
|
330 |
/**
|
sl@0
|
331 |
* Resets the CPBDecryptorSet object back to its original state
|
sl@0
|
332 |
* and clears all its buffers.
|
sl@0
|
333 |
*/
|
sl@0
|
334 |
IMPORT_C void Reset(void);
|
sl@0
|
335 |
|
sl@0
|
336 |
/**
|
sl@0
|
337 |
* Transforms aInput into its decrypted form, aOutput.
|
sl@0
|
338 |
*
|
sl@0
|
339 |
* aOutput must have CPBDecryptorSet::MaxOutputLength() empty bytes
|
sl@0
|
340 |
* remaining in its length.
|
sl@0
|
341 |
*
|
sl@0
|
342 |
* @param aInput The ciphertext.
|
sl@0
|
343 |
* @param aOutput The plaintext.
|
sl@0
|
344 |
*/
|
sl@0
|
345 |
void Process(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
346 |
|
sl@0
|
347 |
/**
|
sl@0
|
348 |
* Transforms aInput into its decrypted form, aOutput, and applies a
|
sl@0
|
349 |
* padding scheme to ensure a block aligned result.
|
sl@0
|
350 |
*
|
sl@0
|
351 |
* aOutput must have CPBDecryptorSet::MaxFinalOutputLength()
|
sl@0
|
352 |
* empty bytes remaining in its length.
|
sl@0
|
353 |
*
|
sl@0
|
354 |
* @param aInput The ciphertext.
|
sl@0
|
355 |
* @param aOutput The plaintext.
|
sl@0
|
356 |
*/
|
sl@0
|
357 |
void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
|
sl@0
|
358 |
|
sl@0
|
359 |
/**
|
sl@0
|
360 |
* Gets the maximum size of the output given a certain input length.
|
sl@0
|
361 |
*
|
sl@0
|
362 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
363 |
* @return The maximum output length in bytes.
|
sl@0
|
364 |
*/
|
sl@0
|
365 |
TInt MaxOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
366 |
|
sl@0
|
367 |
/**
|
sl@0
|
368 |
* Gets the maximum size of the output given a certain input length.
|
sl@0
|
369 |
*
|
sl@0
|
370 |
* @param aMaxInputLength The maximum input length in bytes.
|
sl@0
|
371 |
* @return The maximum output length in bytes.
|
sl@0
|
372 |
*/
|
sl@0
|
373 |
TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
|
sl@0
|
374 |
|
sl@0
|
375 |
/** Destructor */
|
sl@0
|
376 |
virtual ~CPBDecryptorSet();
|
sl@0
|
377 |
protected:
|
sl@0
|
378 |
CPBDecryptorSet();
|
sl@0
|
379 |
void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
|
sl@0
|
380 |
private:
|
sl@0
|
381 |
TPtrC8 ProcessIV(const TDesC8& aInput);
|
sl@0
|
382 |
private:
|
sl@0
|
383 |
CSymmetricCipher* iCipher;
|
sl@0
|
384 |
HBufC8* iIVBuf;
|
sl@0
|
385 |
TBool iIVSent;
|
sl@0
|
386 |
};
|
sl@0
|
387 |
|
sl@0
|
388 |
#endif
|