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 __PBE_H__
|
sl@0
|
28 |
#define __PBE_H__
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <e32std.h>
|
sl@0
|
31 |
#include "pbebase.h"
|
sl@0
|
32 |
|
sl@0
|
33 |
class CPBEncryptionData;
|
sl@0
|
34 |
class CPBEncryptor;
|
sl@0
|
35 |
class CPBDecryptor;
|
sl@0
|
36 |
|
sl@0
|
37 |
/**
|
sl@0
|
38 |
* Password Based Encryption ciphers.
|
sl@0
|
39 |
*
|
sl@0
|
40 |
* Note that RC2 has an additional key parameter, the "effective key length".
|
sl@0
|
41 |
*
|
sl@0
|
42 |
* Used in the construction of CPBEncryptElement, CPBEncryptSet, CPBEncryptParms,
|
sl@0
|
43 |
* and CPBEncryptionData objects and in the CPBEncryptParms::Cipher() function.
|
sl@0
|
44 |
*/
|
sl@0
|
45 |
enum TPBECipher
|
sl@0
|
46 |
{
|
sl@0
|
47 |
/** AES cipher in CBC mode with a supplied key size of 128 bits. */
|
sl@0
|
48 |
ECipherAES_CBC_128,
|
sl@0
|
49 |
/** AES cipher in CBC mode with a supplied key size of 192 bits. */
|
sl@0
|
50 |
ECipherAES_CBC_192,
|
sl@0
|
51 |
/** AES cipher in CBC mode with a supplied key size of 256 bits. */
|
sl@0
|
52 |
ECipherAES_CBC_256,
|
sl@0
|
53 |
/** DES cipher in CBC mode (with a supplied key size of 56 bits). */
|
sl@0
|
54 |
ECipherDES_CBC,
|
sl@0
|
55 |
/** Triple-DES cipher in CBC mode. */
|
sl@0
|
56 |
ECipher3DES_CBC,
|
sl@0
|
57 |
/**
|
sl@0
|
58 |
* RC2 cipher in CBC mode with a supplied key length of 40 bits.
|
sl@0
|
59 |
*
|
sl@0
|
60 |
* It has an effective key length of 1024 bits (128 bytes), which is compatible
|
sl@0
|
61 |
* with OpenSSL RC2 encryption.
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
ECipherRC2_CBC_40,
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
* RC2 cipher in CBC mode with a supplied key length of 128 bits.
|
sl@0
|
66 |
*
|
sl@0
|
67 |
* It has an effective key length of 1024 bits (128 bytes), which is compatible
|
sl@0
|
68 |
* with OpenSSL RC2 encryption.
|
sl@0
|
69 |
*/
|
sl@0
|
70 |
ECipherRC2_CBC_128,
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
* RC2 cipher in CBC mode with a supplied key length of 40 bits.
|
sl@0
|
73 |
*
|
sl@0
|
74 |
* It has an effective key length of 128 bits (16 bytes), which is compatible
|
sl@0
|
75 |
* with the RC2 encryption used in PKCS#8 encryption keys generated by OpenSSL
|
sl@0
|
76 |
*/
|
sl@0
|
77 |
ECipherRC2_CBC_40_16,
|
sl@0
|
78 |
/**
|
sl@0
|
79 |
* RC2 cipher in CBC mode with a supplied key length of 128 bits.
|
sl@0
|
80 |
*
|
sl@0
|
81 |
* It has an effective key length of 128 bits (16 bytes), which is compatible
|
sl@0
|
82 |
* with the RC2 encryption used in PKCS#8 encryption keys generated by OpenSSL
|
sl@0
|
83 |
*/
|
sl@0
|
84 |
ECipherRC2_CBC_128_16,
|
sl@0
|
85 |
/**
|
sl@0
|
86 |
* ARC4 cipher with a supplied key length of 128 bits.
|
sl@0
|
87 |
* PKCS#12 PBE encryption algorithm
|
sl@0
|
88 |
*/
|
sl@0
|
89 |
ECipherARC4_128,
|
sl@0
|
90 |
/**
|
sl@0
|
91 |
* ARC4 cipher with a supplied key length of 40 bits.
|
sl@0
|
92 |
* PKCS#12 PBE encryption algorithm
|
sl@0
|
93 |
*/
|
sl@0
|
94 |
ECipherARC4_40,
|
sl@0
|
95 |
/**
|
sl@0
|
96 |
* 2_KeyTriple-DES cipher in CBC mode.
|
sl@0
|
97 |
* PKCS#12 PBE encryption algorithm
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
ECipher2Key3DES_CBC,
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
* RC2 Cipher in CBC mode with a supplied & effective key length of 40 bits.
|
sl@0
|
102 |
* PKCS#12 PBE encryption algorithm
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
ECipherRC2_CBC_40_5,
|
sl@0
|
105 |
};
|
sl@0
|
106 |
|
sl@0
|
107 |
/**
|
sl@0
|
108 |
* Allows the password based encryption and decryption of elements.
|
sl@0
|
109 |
* Contains the encryption key and its associated encryption data.
|
sl@0
|
110 |
* See the Cryptography api-guide documentation for more information
|
sl@0
|
111 |
* and sample code.
|
sl@0
|
112 |
*/
|
sl@0
|
113 |
class CPBEncryptElement : public CPBEncryptionBase
|
sl@0
|
114 |
{
|
sl@0
|
115 |
public:
|
sl@0
|
116 |
/**
|
sl@0
|
117 |
* Creates a new CPBEncryptElement object for encryption of new data.
|
sl@0
|
118 |
*
|
sl@0
|
119 |
* If strong cryptography is present, a 128 bit AES cipher is used;
|
sl@0
|
120 |
* otherwise, for weak cryptography, a 56 bit DES cipher is used.
|
sl@0
|
121 |
*
|
sl@0
|
122 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
123 |
*
|
sl@0
|
124 |
* @param aPassword The user supplied password
|
sl@0
|
125 |
* @return The new CPBEncryptElement object
|
sl@0
|
126 |
*/
|
sl@0
|
127 |
IMPORT_C static CPBEncryptElement* NewL(const TPBPassword& aPassword);
|
sl@0
|
128 |
|
sl@0
|
129 |
/**
|
sl@0
|
130 |
* Creates a new CPBEncryptElement object for encryption of new data.
|
sl@0
|
131 |
*
|
sl@0
|
132 |
* If strong cryptography is present, a 128 bit AES cipher is used;
|
sl@0
|
133 |
* otherwise, for weak cryptography, a 56 bit DES cipher is used.
|
sl@0
|
134 |
*
|
sl@0
|
135 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
136 |
*
|
sl@0
|
137 |
* A pointer to the returned object is put onto the cleanup stack.
|
sl@0
|
138 |
*
|
sl@0
|
139 |
* @param aPassword The user supplied password
|
sl@0
|
140 |
* @return The new CPBEncryptElement object
|
sl@0
|
141 |
*/
|
sl@0
|
142 |
IMPORT_C static CPBEncryptElement* NewLC(const TPBPassword& aPassword);
|
sl@0
|
143 |
|
sl@0
|
144 |
/**
|
sl@0
|
145 |
* Creates a new CPBEncryptElement object for encryption of new data.
|
sl@0
|
146 |
*
|
sl@0
|
147 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
148 |
*
|
sl@0
|
149 |
* @param aPassword The user supplied password
|
sl@0
|
150 |
* @param aCipher The cipher to use
|
sl@0
|
151 |
* @return The new CPBEncryptElement object
|
sl@0
|
152 |
*/
|
sl@0
|
153 |
IMPORT_C static CPBEncryptElement* NewL(const TPBPassword& aPassword,
|
sl@0
|
154 |
TPBECipher aCipher);
|
sl@0
|
155 |
|
sl@0
|
156 |
/**
|
sl@0
|
157 |
* Creates a new CPBEncryptElement object for encryption of new data.
|
sl@0
|
158 |
*
|
sl@0
|
159 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
160 |
*
|
sl@0
|
161 |
* A pointer to the returned object is put onto the cleanup stack.
|
sl@0
|
162 |
*
|
sl@0
|
163 |
* @param aPassword The user supplied password
|
sl@0
|
164 |
* @param aCipher The cipher to use
|
sl@0
|
165 |
* @return The new CPBEncryptElement object
|
sl@0
|
166 |
*/
|
sl@0
|
167 |
IMPORT_C static CPBEncryptElement* NewLC(const TPBPassword& aPassword,
|
sl@0
|
168 |
TPBECipher aCipher);
|
sl@0
|
169 |
|
sl@0
|
170 |
/**
|
sl@0
|
171 |
* Creates a new CPBEncryptElement object for encryption of new data.
|
sl@0
|
172 |
*
|
sl@0
|
173 |
* The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
174 |
*
|
sl@0
|
175 |
* @param aPassword The user supplied password
|
sl@0
|
176 |
* @param aParms An encryption parameter object comprising the cipher,
|
sl@0
|
177 |
* salt, IV, and iteration count value.
|
sl@0
|
178 |
* @return The new CPBEncryptElement object
|
sl@0
|
179 |
*/
|
sl@0
|
180 |
IMPORT_C static CPBEncryptElement* NewL(const TPBPassword& aPassword,
|
sl@0
|
181 |
const CPBEncryptParms& aParms);
|
sl@0
|
182 |
|
sl@0
|
183 |
/**
|
sl@0
|
184 |
* Creates a new CPBEncryptElement object for encryption of new data.
|
sl@0
|
185 |
*
|
sl@0
|
186 |
* The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
187 |
*
|
sl@0
|
188 |
* A pointer to the returned object is put onto the cleanup stack.
|
sl@0
|
189 |
*
|
sl@0
|
190 |
* @param aPassword The user supplied password
|
sl@0
|
191 |
* @param aParms An encryption parameter object comprising the cipher,
|
sl@0
|
192 |
* salt, IV, and iteration count value.
|
sl@0
|
193 |
* @return The new CPBEncryptElement object
|
sl@0
|
194 |
*/
|
sl@0
|
195 |
IMPORT_C static CPBEncryptElement* NewLC(const TPBPassword& aPassword,
|
sl@0
|
196 |
const CPBEncryptParms& aParms);
|
sl@0
|
197 |
|
sl@0
|
198 |
/**
|
sl@0
|
199 |
* Creates a new CPBEncryptElement object for decryption of existing data.
|
sl@0
|
200 |
*
|
sl@0
|
201 |
* If the specified password is valid, the function regenerates the encryption key;
|
sl@0
|
202 |
* otherwise, it leaves with KErrBadPassphrase.
|
sl@0
|
203 |
*
|
sl@0
|
204 |
* @param aData The encryption data object
|
sl@0
|
205 |
* @param aPassword The user supplied password
|
sl@0
|
206 |
* @return The new CPBEncryptElement object
|
sl@0
|
207 |
* @leave KErrBadPassphrase If the specified password is incorrect
|
sl@0
|
208 |
*/
|
sl@0
|
209 |
IMPORT_C static CPBEncryptElement* NewL(const CPBEncryptionData& aData,
|
sl@0
|
210 |
const TPBPassword& aPassword);
|
sl@0
|
211 |
|
sl@0
|
212 |
/**
|
sl@0
|
213 |
* Creates a new CPBEncryptElement object for decryption of existing data.
|
sl@0
|
214 |
*
|
sl@0
|
215 |
* If the specified password is valid, the function regenerates the encryption key;
|
sl@0
|
216 |
* otherwise, it leaves with KErrBadPassphrase.
|
sl@0
|
217 |
*
|
sl@0
|
218 |
* A pointer to the returned object is put onto the cleanup stack.
|
sl@0
|
219 |
*
|
sl@0
|
220 |
* @param aData The encryption data object
|
sl@0
|
221 |
* @param aPassword The user supplied password
|
sl@0
|
222 |
* @return The new CPBEncryptElement object
|
sl@0
|
223 |
* @leave KErrBadPassphrase If the specified password is incorrect
|
sl@0
|
224 |
*/
|
sl@0
|
225 |
IMPORT_C static CPBEncryptElement* NewLC(const CPBEncryptionData& aData,
|
sl@0
|
226 |
const TPBPassword& aPassword);
|
sl@0
|
227 |
|
sl@0
|
228 |
/**
|
sl@0
|
229 |
* Gets the parameters allowing one to re-create the object with the
|
sl@0
|
230 |
* same state at another point in the future.
|
sl@0
|
231 |
*
|
sl@0
|
232 |
* In order to decrypt any information previously encrypted with this object,
|
sl@0
|
233 |
* you <B><I>must</I></B> store this encryption data along with it. Failure
|
sl@0
|
234 |
* to do this will result in the permanent loss of the encrypted information.
|
sl@0
|
235 |
*
|
sl@0
|
236 |
* @return The data allowing one to re-create this object at a later time.
|
sl@0
|
237 |
*/
|
sl@0
|
238 |
const CPBEncryptionData& EncryptionData(void) const;
|
sl@0
|
239 |
|
sl@0
|
240 |
/**
|
sl@0
|
241 |
* Constructs a CPBEncryptor object allowing the encryption of data.
|
sl@0
|
242 |
*
|
sl@0
|
243 |
* @return A pointer to a CPBEncryptor object.
|
sl@0
|
244 |
* The caller assumes ownership of the returned object.
|
sl@0
|
245 |
*/
|
sl@0
|
246 |
CPBEncryptor* NewEncryptL(void) const;
|
sl@0
|
247 |
|
sl@0
|
248 |
/**
|
sl@0
|
249 |
* Constructs a CPBEncryptor object allowing the encryption of data.
|
sl@0
|
250 |
*
|
sl@0
|
251 |
* @return A pointer to a CPBEncryptor object.
|
sl@0
|
252 |
* The caller assumes ownership of the returned object.
|
sl@0
|
253 |
* The returned pointer is left on the cleanup stack.
|
sl@0
|
254 |
*/
|
sl@0
|
255 |
CPBEncryptor* NewEncryptLC(void) const;
|
sl@0
|
256 |
|
sl@0
|
257 |
/**
|
sl@0
|
258 |
* Constructs a CPBDecryptor object allowing the decryption of data.
|
sl@0
|
259 |
*
|
sl@0
|
260 |
* @return A pointer to a CPBDecryptor object.
|
sl@0
|
261 |
* The caller assumes ownership of the returned object.
|
sl@0
|
262 |
*/
|
sl@0
|
263 |
CPBDecryptor* NewDecryptL(void) const;
|
sl@0
|
264 |
|
sl@0
|
265 |
/**
|
sl@0
|
266 |
* Constructs a CPBDecryptor object allowing the decryption of data.
|
sl@0
|
267 |
*
|
sl@0
|
268 |
* @return A pointer to a CPBDecryptor object.
|
sl@0
|
269 |
* The caller assumes ownership of the returned object.
|
sl@0
|
270 |
* The returned pointer is left on the cleanup stack.
|
sl@0
|
271 |
*/
|
sl@0
|
272 |
CPBDecryptor* NewDecryptLC(void) const;
|
sl@0
|
273 |
|
sl@0
|
274 |
/**
|
sl@0
|
275 |
* Gets the maximum output ciphertext length given a specified input plaintext length.
|
sl@0
|
276 |
*
|
sl@0
|
277 |
* @param aPlaintextLength The plaintext length
|
sl@0
|
278 |
* @return The maximum ciphertext length given a plaintext length.
|
sl@0
|
279 |
*/
|
sl@0
|
280 |
TInt MaxCiphertextLength(TInt aPlaintextLength) const;
|
sl@0
|
281 |
|
sl@0
|
282 |
/**
|
sl@0
|
283 |
* Gets the maximum output plaintext length given a specified input ciphertext length.
|
sl@0
|
284 |
*
|
sl@0
|
285 |
* @param aCiphertextLength The ciphertext length
|
sl@0
|
286 |
* @return The maximum plaintext length given a ciphertext length.
|
sl@0
|
287 |
*/
|
sl@0
|
288 |
TInt MaxPlaintextLength(TInt aCiphertextLength) const;
|
sl@0
|
289 |
|
sl@0
|
290 |
/** Destructor */
|
sl@0
|
291 |
virtual ~CPBEncryptElement(void);
|
sl@0
|
292 |
protected:
|
sl@0
|
293 |
/** @internalAll */
|
sl@0
|
294 |
void ConstructL(const TDesC8& aPassword);
|
sl@0
|
295 |
/** @internalAll */
|
sl@0
|
296 |
void ConstructL(const TDesC8& aPassword, const TPBECipher aCipher);
|
sl@0
|
297 |
/** @internalAll */
|
sl@0
|
298 |
void ConstructL(const TDesC8& aPassword, const CPBEncryptParms& aParms);
|
sl@0
|
299 |
/** @internalAll */
|
sl@0
|
300 |
void ConstructL(const CPBEncryptionData& aData, const TPBPassword& aPassword);
|
sl@0
|
301 |
/** @internalAll */
|
sl@0
|
302 |
TBool AuthenticateL(const TPBPassword& aPassword);
|
sl@0
|
303 |
/** @internalAll */
|
sl@0
|
304 |
void MakeEncryptKeyL(TUint aKeySize, const TDesC8& aPassword);
|
sl@0
|
305 |
/** @internalAll */
|
sl@0
|
306 |
CPBEncryptElement(void);
|
sl@0
|
307 |
protected:
|
sl@0
|
308 |
/** The encryption data */
|
sl@0
|
309 |
CPBEncryptionData* iData;
|
sl@0
|
310 |
/** The derived encryption key */
|
sl@0
|
311 |
HBufC8* iEncryptKey;
|
sl@0
|
312 |
private:
|
sl@0
|
313 |
CPBEncryptElement(const CPBEncryptElement&);
|
sl@0
|
314 |
CPBEncryptElement& operator= (const CPBEncryptElement&);
|
sl@0
|
315 |
};
|
sl@0
|
316 |
|
sl@0
|
317 |
/**
|
sl@0
|
318 |
* Derived class to allow the efficient password based encryption and
|
sl@0
|
319 |
* decryption of multiple elements.
|
sl@0
|
320 |
*
|
sl@0
|
321 |
* This is useful if one wants random access to an encrypted source consisting
|
sl@0
|
322 |
* of multiple independent elements, for example, a database or a store.
|
sl@0
|
323 |
*
|
sl@0
|
324 |
* Since it is unreasonable to force the decryption of an entire set to allow
|
sl@0
|
325 |
* access to just a tiny portion of it, and since it is too costly to derive separate
|
sl@0
|
326 |
* keys for each element within the set, a single randomly generated <I>master</I>
|
sl@0
|
327 |
* key is used. This master key is encrypted with the password provided by the
|
sl@0
|
328 |
* user of the class. Known plaintext attacks against the ciphertext are prevented
|
sl@0
|
329 |
* by using a randomly chosen Initialisation Vector (IV) for each element.
|
sl@0
|
330 |
*
|
sl@0
|
331 |
* Contains the master encryption key.
|
sl@0
|
332 |
*
|
sl@0
|
333 |
* See the Cryptography api-guide documentation for more information and sample code.
|
sl@0
|
334 |
*
|
sl@0
|
335 |
* @see CPBEncryptElement
|
sl@0
|
336 |
*
|
sl@0
|
337 |
* @since v8.0
|
sl@0
|
338 |
*/
|
sl@0
|
339 |
class CPBEncryptSet : public CPBEncryptElement
|
sl@0
|
340 |
{
|
sl@0
|
341 |
public:
|
sl@0
|
342 |
/**
|
sl@0
|
343 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
344 |
* (and generates an encrypted master key).
|
sl@0
|
345 |
*
|
sl@0
|
346 |
* If strong cryptography is present, a 128 bit AES cipher is used;
|
sl@0
|
347 |
* otherwise, for weak cryptography, a 56 bit DES cipher is used.
|
sl@0
|
348 |
*
|
sl@0
|
349 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
350 |
*
|
sl@0
|
351 |
* @param aPassword The users password.
|
sl@0
|
352 |
* @return A new CPBEncryptSet object
|
sl@0
|
353 |
*/
|
sl@0
|
354 |
IMPORT_C static CPBEncryptSet* NewL(const TPBPassword& aPassword);
|
sl@0
|
355 |
|
sl@0
|
356 |
/**
|
sl@0
|
357 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
358 |
* (and generates an encrypted master key).
|
sl@0
|
359 |
*
|
sl@0
|
360 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
361 |
*
|
sl@0
|
362 |
* If strong cryptography is present, a 128 bit AES cipher is used;
|
sl@0
|
363 |
* otherwise, for weak cryptography, a 56 bit DES cipher is used.
|
sl@0
|
364 |
*
|
sl@0
|
365 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
366 |
*
|
sl@0
|
367 |
* @param aPassword The user supplied password
|
sl@0
|
368 |
* @return The new CPBEncryptSet object
|
sl@0
|
369 |
*/
|
sl@0
|
370 |
IMPORT_C static CPBEncryptSet* NewLC(const TPBPassword& aPassword);
|
sl@0
|
371 |
|
sl@0
|
372 |
/**
|
sl@0
|
373 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
374 |
* (and generates an encrypted master key).
|
sl@0
|
375 |
*
|
sl@0
|
376 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
377 |
*
|
sl@0
|
378 |
* @param aPassword The user supplied password
|
sl@0
|
379 |
* @param aCipher The cipher to use
|
sl@0
|
380 |
* @return The new CPBEncryptSet object
|
sl@0
|
381 |
*/
|
sl@0
|
382 |
IMPORT_C static CPBEncryptSet* NewL(const TPBPassword& aPassword,
|
sl@0
|
383 |
TPBECipher aCipher);
|
sl@0
|
384 |
|
sl@0
|
385 |
/**
|
sl@0
|
386 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
387 |
* (and generates an encrypted master key).
|
sl@0
|
388 |
*
|
sl@0
|
389 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
390 |
*
|
sl@0
|
391 |
* The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
392 |
*
|
sl@0
|
393 |
* @param aPassword The user supplied password
|
sl@0
|
394 |
* @param aCipher The cipher to use
|
sl@0
|
395 |
* @return The new CPBEncryptSet object
|
sl@0
|
396 |
*/
|
sl@0
|
397 |
IMPORT_C static CPBEncryptSet* NewLC(const TPBPassword& aPassword,
|
sl@0
|
398 |
TPBECipher aCipher);
|
sl@0
|
399 |
|
sl@0
|
400 |
/**
|
sl@0
|
401 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
402 |
* (and generates an encrypted master key).
|
sl@0
|
403 |
*
|
sl@0
|
404 |
* The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
405 |
*
|
sl@0
|
406 |
* @param aPassword The user supplied password
|
sl@0
|
407 |
* @param aParms An encryption parameter object comprising the cipher,
|
sl@0
|
408 |
* salt, IV, and iteration count value.
|
sl@0
|
409 |
* @return The new CPBEncryptSet object
|
sl@0
|
410 |
*/
|
sl@0
|
411 |
IMPORT_C static CPBEncryptSet* NewL(const TPBPassword& aPassword,
|
sl@0
|
412 |
const CPBEncryptParms& aParms);
|
sl@0
|
413 |
|
sl@0
|
414 |
/**
|
sl@0
|
415 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
416 |
* (and generates an encrypted master key).
|
sl@0
|
417 |
*
|
sl@0
|
418 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
419 |
*
|
sl@0
|
420 |
* The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
|
sl@0
|
421 |
*
|
sl@0
|
422 |
* @param aPassword The user supplied password
|
sl@0
|
423 |
* @param aParms An encryption parameter object comprising the cipher,
|
sl@0
|
424 |
* salt, IV, and iteration count value.
|
sl@0
|
425 |
* @return The new CPBEncryptSet object
|
sl@0
|
426 |
*/
|
sl@0
|
427 |
IMPORT_C static CPBEncryptSet* NewLC(const TPBPassword& aPassword,
|
sl@0
|
428 |
const CPBEncryptParms& aParms);
|
sl@0
|
429 |
|
sl@0
|
430 |
/**
|
sl@0
|
431 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
432 |
* (and generates an encrypted master key).
|
sl@0
|
433 |
*
|
sl@0
|
434 |
* If the specified password is valid, the function regenerates the encryption key;
|
sl@0
|
435 |
* otherwise, it leaves with KErrBadPassphrase.
|
sl@0
|
436 |
*
|
sl@0
|
437 |
* @param aData The encryption data object to copy
|
sl@0
|
438 |
* @param aEncryptedMasterKey On return, the encrypted master key
|
sl@0
|
439 |
* @param aPassword The user supplied password
|
sl@0
|
440 |
* @return The new CPBEncryptSet object
|
sl@0
|
441 |
* @leave KErrBadPassphrase If the specified password is incorrect
|
sl@0
|
442 |
*/
|
sl@0
|
443 |
IMPORT_C static CPBEncryptSet* NewL(const CPBEncryptionData& aData,
|
sl@0
|
444 |
const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword);
|
sl@0
|
445 |
|
sl@0
|
446 |
/**
|
sl@0
|
447 |
* Creates a new CPBEncryptSet object for encryption of new data
|
sl@0
|
448 |
* (and generates an encrypted master key).
|
sl@0
|
449 |
*
|
sl@0
|
450 |
* The returned pointer is put onto the cleanup stack.
|
sl@0
|
451 |
*
|
sl@0
|
452 |
* If the specified password is valid, the function regenerates the encryption key;
|
sl@0
|
453 |
* otherwise, it leaves with KErrBadPassphrase.
|
sl@0
|
454 |
*
|
sl@0
|
455 |
* @param aData The encryption data object to copy
|
sl@0
|
456 |
* @param aEncryptedMasterKey On return, the encrypted master key
|
sl@0
|
457 |
* @param aPassword The user supplied password
|
sl@0
|
458 |
* @return The new CPBEncryptSet object
|
sl@0
|
459 |
* @leave KErrBadPassphrase If the specified password is incorrect
|
sl@0
|
460 |
*/
|
sl@0
|
461 |
IMPORT_C static CPBEncryptSet* NewLC(const CPBEncryptionData& aData,
|
sl@0
|
462 |
const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword);
|
sl@0
|
463 |
|
sl@0
|
464 |
/**
|
sl@0
|
465 |
* Gets the encrypted form of the master key.
|
sl@0
|
466 |
*
|
sl@0
|
467 |
* This must be stored along with the object returned by CPBEncryptElement::EncryptionData()
|
sl@0
|
468 |
* in order for the object to be reconstructed with the same state at
|
sl@0
|
469 |
* some time in the future. Failure to do so will result in the permanent
|
sl@0
|
470 |
* loss of any information encrypted with this object.
|
sl@0
|
471 |
*
|
sl@0
|
472 |
* @return The encrypted master key.
|
sl@0
|
473 |
*/
|
sl@0
|
474 |
IMPORT_C const TDesC8& EncryptedMasterKey(void) const;
|
sl@0
|
475 |
|
sl@0
|
476 |
/**
|
sl@0
|
477 |
* Constructs a CPBEncryptor object based on the state of this object
|
sl@0
|
478 |
* (i.e., the cipher and master key) allowing the encryption of data.
|
sl@0
|
479 |
*
|
sl@0
|
480 |
* @return A pointer to a CPBEncryptor object.
|
sl@0
|
481 |
* The caller assumes ownership of the returned object.
|
sl@0
|
482 |
*/
|
sl@0
|
483 |
CPBEncryptor* NewEncryptL(void) const;
|
sl@0
|
484 |
|
sl@0
|
485 |
/**
|
sl@0
|
486 |
* Constructs a CPBEncryptor object based on the state of this object
|
sl@0
|
487 |
* (i.e., the cipher and master key) allowing the encryption of data.
|
sl@0
|
488 |
*
|
sl@0
|
489 |
* @return A pointer to a CPBEncryptor object.
|
sl@0
|
490 |
* The caller assumes ownership of the returned object.
|
sl@0
|
491 |
* The returned pointer is left on the cleanup stack.
|
sl@0
|
492 |
*/
|
sl@0
|
493 |
CPBEncryptor* NewEncryptLC(void) const;
|
sl@0
|
494 |
|
sl@0
|
495 |
/**
|
sl@0
|
496 |
* Constructs a CPBDecryptor object based on the state of this object
|
sl@0
|
497 |
* (i.e., the cipher and master key) allowing the decryption of data.
|
sl@0
|
498 |
*
|
sl@0
|
499 |
* @return A pointer to a CPBDecryptor object.
|
sl@0
|
500 |
* The caller assumes ownership of the returned object.
|
sl@0
|
501 |
*/
|
sl@0
|
502 |
CPBDecryptor* NewDecryptL(void) const;
|
sl@0
|
503 |
|
sl@0
|
504 |
/**
|
sl@0
|
505 |
* Constructs a CPBDecryptor object based on the state of this object
|
sl@0
|
506 |
* (i.e., the cipher and master key) allowing the decryption of data.
|
sl@0
|
507 |
*
|
sl@0
|
508 |
* @return A pointer to a CPBDecryptor object.
|
sl@0
|
509 |
* The caller assumes ownership of the returned object.
|
sl@0
|
510 |
* The returned pointer is left on the cleanup stack.
|
sl@0
|
511 |
*/
|
sl@0
|
512 |
CPBDecryptor* NewDecryptLC(void) const;
|
sl@0
|
513 |
|
sl@0
|
514 |
/**
|
sl@0
|
515 |
* Re-encrypts the master key with the specified new password.
|
sl@0
|
516 |
*
|
sl@0
|
517 |
* @param aNewPassword The new password
|
sl@0
|
518 |
*/
|
sl@0
|
519 |
IMPORT_C void ChangePasswordL(const TPBPassword& aNewPassword);
|
sl@0
|
520 |
|
sl@0
|
521 |
/**
|
sl@0
|
522 |
* Gets the maximum output ciphertext length given a specified input plaintext length.
|
sl@0
|
523 |
*
|
sl@0
|
524 |
* @param aPlaintextLength The plaintext length
|
sl@0
|
525 |
* @return The maximum ciphertext length given a plaintext length.
|
sl@0
|
526 |
*/
|
sl@0
|
527 |
TInt MaxCiphertextLength(TInt aPlaintextLength) const;
|
sl@0
|
528 |
|
sl@0
|
529 |
/**
|
sl@0
|
530 |
* Gets the maximum output plaintext length given a specified input ciphertext length.
|
sl@0
|
531 |
*
|
sl@0
|
532 |
* @param aCiphertextLength The ciphertext length
|
sl@0
|
533 |
* @return The maximum plaintext length given a ciphertext length.
|
sl@0
|
534 |
*/
|
sl@0
|
535 |
TInt MaxPlaintextLength(TInt aCiphertextLength) const;
|
sl@0
|
536 |
|
sl@0
|
537 |
/** Destructor */
|
sl@0
|
538 |
virtual ~CPBEncryptSet(void);
|
sl@0
|
539 |
protected:
|
sl@0
|
540 |
/** @internalAll */
|
sl@0
|
541 |
void ConstructL(const TDesC8& aPassword);
|
sl@0
|
542 |
/** @internalAll */
|
sl@0
|
543 |
void ConstructL(const TDesC8& aPassword, TPBECipher aCipher);
|
sl@0
|
544 |
/** @internalAll */
|
sl@0
|
545 |
void ConstructL(const TDesC8& aPassword, const CPBEncryptParms& aParms);
|
sl@0
|
546 |
/** @internalAll */
|
sl@0
|
547 |
void ConstructMasterKeyL(void);
|
sl@0
|
548 |
/** @internalAll */
|
sl@0
|
549 |
void ConstructL(const CPBEncryptionData& aData,
|
sl@0
|
550 |
const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword);
|
sl@0
|
551 |
/** @internalAll */
|
sl@0
|
552 |
void DecryptMasterKeyL(TDes8& aMasterKey) const;
|
sl@0
|
553 |
/** @internalAll */
|
sl@0
|
554 |
void EncryptMasterKeyL(const TDesC8& aMasterKey);
|
sl@0
|
555 |
protected:
|
sl@0
|
556 |
/** @internalAll */
|
sl@0
|
557 |
CPBEncryptSet(void);
|
sl@0
|
558 |
/** The derived encrypted master key*/
|
sl@0
|
559 |
HBufC8* iEncryptedMasterKey;
|
sl@0
|
560 |
private:
|
sl@0
|
561 |
CPBEncryptSet(const CPBEncryptSet&);
|
sl@0
|
562 |
CPBEncryptSet& operator= (const CPBEncryptSet&);
|
sl@0
|
563 |
};
|
sl@0
|
564 |
|
sl@0
|
565 |
/**
|
sl@0
|
566 |
* Class representing both 8 and 16 bit descriptor passwords.
|
sl@0
|
567 |
* Internally these are stored as 8 bit passwords.
|
sl@0
|
568 |
*/
|
sl@0
|
569 |
class TPBPassword
|
sl@0
|
570 |
{
|
sl@0
|
571 |
public:
|
sl@0
|
572 |
/**
|
sl@0
|
573 |
* Sets the password.
|
sl@0
|
574 |
*
|
sl@0
|
575 |
* Constructs a TPBPassword object with an 8 bit descriptor.
|
sl@0
|
576 |
*
|
sl@0
|
577 |
* Internally this is represented as an octet byte sequence
|
sl@0
|
578 |
* (aka 8 bit TPtrC8 descriptor).
|
sl@0
|
579 |
*
|
sl@0
|
580 |
* @param aPassword A const reference to an 8 bit descriptor.
|
sl@0
|
581 |
* representing the users initial password.
|
sl@0
|
582 |
*/
|
sl@0
|
583 |
IMPORT_C TPBPassword(const TDesC8& aPassword);
|
sl@0
|
584 |
|
sl@0
|
585 |
/**
|
sl@0
|
586 |
* Sets the password.
|
sl@0
|
587 |
*
|
sl@0
|
588 |
* Constructs a TPBPassword object with a 16 bit descriptor.
|
sl@0
|
589 |
*
|
sl@0
|
590 |
* Internally this is represented as an octet byte sequence
|
sl@0
|
591 |
* (aka 8 bit TPtrC8 descriptor).
|
sl@0
|
592 |
*
|
sl@0
|
593 |
* @param aPassword A const reference to a 16 bit descriptor
|
sl@0
|
594 |
* representing the users initial password.
|
sl@0
|
595 |
*/
|
sl@0
|
596 |
IMPORT_C TPBPassword(const TDesC16& aPassword);
|
sl@0
|
597 |
|
sl@0
|
598 |
/**
|
sl@0
|
599 |
* Gets the password.
|
sl@0
|
600 |
*
|
sl@0
|
601 |
* Gets a const reference to an 8 bit descriptor representing the users
|
sl@0
|
602 |
* initial password (which could have been either 8 or 16 bit).
|
sl@0
|
603 |
*
|
sl@0
|
604 |
* @return A const reference to an 8 bit descriptor.
|
sl@0
|
605 |
*/
|
sl@0
|
606 |
IMPORT_C const TDesC8& Password(void) const;
|
sl@0
|
607 |
private:
|
sl@0
|
608 |
TPtrC8 iPassword;
|
sl@0
|
609 |
};
|
sl@0
|
610 |
|
sl@0
|
611 |
#endif
|