Update contrib.
2 * Copyright (c) 2002-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 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the
16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
34 * Contains the Password Based Encryption parameters.
35 * An object of this class can be input for CPBEncryptElement or CPBEncryptSet objects.
39 class CPBEncryptParms : public CBase
44 Key derivation function.
45 This does not affect the authentication key,
46 which always uses PKCS#5.
54 * Creates a new CPBEncryptParms object.
56 * @param aCipher The cipher to use
57 * @param aSalt The salt
58 * @param aIV The Initialization Vector
59 * @param aIterations The number of iterations of the PBE algorithm
60 * @return A pointer to the new CPBEncryptParms object
62 IMPORT_C static CPBEncryptParms* NewL(TPBECipher aCipher,
63 const TDesC8& aSalt, const TDesC8& aIV, TUint aIterations);
66 * Creates a new CPBEncryptParms object and puts a pointer to it onto the cleanup stack.
68 * @param aCipher The cipher to use
69 * @param aSalt The salt
70 * @param aIV The Initialization Vector
71 * @param aIterations The number of iterations of the PBE algorithm
72 * @return A pointer to the new CPBEncryptParms object
74 IMPORT_C static CPBEncryptParms* NewLC(TPBECipher aCipher,
75 const TDesC8& aSalt, const TDesC8& aIV, TUint aIterations);
78 * Creates a new CPBEncryptParms object from an existing object.
80 * @param aParms The existing encryption parameters object
81 * @return A pointer to the new CPBEncryptParms object
83 IMPORT_C static CPBEncryptParms* NewL(const CPBEncryptParms& aParms);
86 * Creates a new CPBEncryptParms object from an existing object
87 * and puts a pointer to it onto the cleanup stack.
89 * @param aParms The existing encryption parameters object
90 * @return A pointer to the new CPBEncryptParms object
92 IMPORT_C static CPBEncryptParms* NewLC(const CPBEncryptParms& aParms);
95 * Internalizes encryption parameter data from a read stream.
97 * @param aStream The read stream to be internalized
98 * @return A pointer to the new CPBEncryptParms object
101 IMPORT_C static CPBEncryptParms* NewL(RReadStream& aStream);
104 * Internalizes encryption parameter data from a read stream, and
105 * puts a pointer to the new object onto the cleanup stack.
107 * @param aStream The read stream to be internalized
108 * @return A pointer to the new CPBEncryptParms object
110 IMPORT_C static CPBEncryptParms* NewLC(RReadStream& aStream);
113 * Gets the PBE cipher
115 * @return The cipher to use
117 IMPORT_C TPBECipher Cipher() const;
119 Gets the key derivation function (KDF.)
121 @return The key derivation function (KDF) which
122 transforms the password into an encryption key.
124 IMPORT_C TKdf Kdf() const;
131 IMPORT_C TPtrC8 Salt() const;
134 * Gets the number of iterations for the PKCS#5 algorithm.
136 * @return The number of iterations
138 IMPORT_C TInt Iterations() const;
141 * Gets the PBE Initialization Vector
145 IMPORT_C TPtrC8 IV() const;
147 IMPORT_C void SetIV(const TDesC8& aNewIv);
150 * Externalizes the encryption parameters into a write stream.
152 * @param aStream The stream to write to
154 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
155 IMPORT_C static CPBEncryptParms* NewL();
156 IMPORT_C static CPBEncryptParms* NewLC();
158 IMPORT_C void SetCipher(TPBECipher aCipher);
161 * Replace the current cipher. This function resizes the
162 * IV and replaces its existing contents.
164 * @param aCipher New cipher.
165 * @leave System wide error code.
167 inline void SetCipherL(TPBECipher aCipher)
172 IMPORT_C void SetKdf(TKdf aKdf);
173 IMPORT_C void ResizeSaltL(TInt aNewLen);
174 IMPORT_C void SetIterations(TInt aIterCount);
177 virtual ~CPBEncryptParms(void);
179 void DeriveKeyL(const TDesC8& aPassword, TDes8& aKeyBuf) const;
183 #ifdef PBEDATA_NO_EXPORTED_CONSTRUCTORS
185 CPBEncryptParms(void);
188 IMPORT_C CPBEncryptParms(void);
195 void ConstructL(TPBECipher aCipher, const TDesC8& aSalt,
196 const TDesC8& aIV, TUint aIterations);
198 void ConstructL(const CPBEncryptParms& aParms);
200 void ConstructL(RReadStream& aStream);
202 CPBEncryptParms(const CPBEncryptParms&);
203 CPBEncryptParms& operator= (const CPBEncryptParms&);
207 This class contains multiple objects. Its
208 pointer is stored in CPBEncryptParms to preserve
209 BC, because CPBEncryptParms has an exported,
210 protected constructor.
216 The password is processed with this function
217 to generate the encryption key.
229 * Contains the password based authentication data.
230 * Used to check the passphrase when decrypting.
234 class CPBAuthData : public CBase
238 * Derives an authentication key.
240 * @param aPassword The user's initial password
241 * @param aSalt The salt
242 * @param aKeySize The key size
243 * @param aIterations The number of iterations of the PBE algorithm
244 * @return A pointer to the new CPBAuthData object
246 IMPORT_C static CPBAuthData* NewL(const TDesC8& aPassword,
247 const TDesC8& aSalt, TUint aKeySize, TUint aIterations);
250 * Derives an authentication key.
252 * The returned pointer is put onto the cleanup stack.
254 * @param aPassword The user's initial password
255 * @param aSalt The salt
256 * @param aKeySize The key size
257 * @param aIterations The number of iterations of the PBE algorithm
258 * @return A pointer to the new CPBAuthData object
260 IMPORT_C static CPBAuthData* NewLC(const TDesC8& aPassword,
261 const TDesC8& aSalt, TUint aKeySize, TUint aIterations);
264 * Creates a new CPBAuthData object from an existing authentication key.
266 * @param aData The existing CPBAuthData object
267 * @return A pointer to the new CPBAuthData object
269 IMPORT_C static CPBAuthData* NewL(const CPBAuthData& aData);
272 * Creates a new CPBAuthData object from an existing authentication key.
274 * The returned pointer is put onto the cleanup stack.
276 * @param aData The existing CPBAuthData object
277 * @return A pointer to the new CPBAuthData object
279 IMPORT_C static CPBAuthData* NewLC(const CPBAuthData& aData);
282 * Creates a new CPBAuthData object from an existing authentication key
283 * by internalizing the authentication data from a read stream.
285 * @param aStream The stream to read from
286 * @return A pointer to the new CPBAuthData object
288 IMPORT_C static CPBAuthData* NewL(RReadStream& aStream);
291 * Creates a new CPBAuthData object from an existing authentication key
292 * by internalizing the authentication data from a read stream.
294 * The returned pointer is put onto the cleanup stack.
296 * @param aStream The stream to read from
297 * @return A pointer to the new CPBAuthData object
299 IMPORT_C static CPBAuthData* NewLC(RReadStream& aStream);
302 * Gets the authentication key
306 IMPORT_C TPtrC8 Key() const;
309 * Gets the salt used for the authentication
313 IMPORT_C TPtrC8 Salt() const;
316 * Gets the number of iterations of the hashing algorithm.
318 * @return The number of iterations
320 IMPORT_C TInt Iterations() const;
323 * Tests whether two authentication keys are identical
325 * @param aAuth The authentication data object which holds the key to be tested
326 * @return ETrue, if they are identical; EFalse, otherwise
328 IMPORT_C TBool operator==(const CPBAuthData& aAuth) const;
331 * Externalizes the encryption parameters into a write stream.
333 * @param aStream The stream to write to
335 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
338 virtual ~CPBAuthData(void);
340 #ifdef PBEDATA_NO_EXPORTED_CONSTRUCTORS
344 IMPORT_C CPBAuthData(void);
347 void ConstructL(const TDesC8& aPassword, const TDesC8& aSalt,
348 TUint aKeySize, TUint aIterations);
350 void ConstructL(const CPBAuthData& aData);
352 void ConstructL(RReadStream& aStream);
354 CPBAuthData(const CPBAuthData&);
355 CPBAuthData& operator= (const CPBAuthData&);
363 * Represents the information needed to decrypt encrypted data given the correct password.
364 * Contains the authentication key, and the parameters used to derive the encryption key.
365 * A CPBEncryptionData object needs to be stored to recover any data for later use.
367 * @see CPBEncryptParms
372 class CPBEncryptionData : public CBase
376 * Creates a new CPBEncryptionData object
378 * @param aPassword The user's initial password
379 * @param aCipher The cipher to use
380 * @param aAuthSalt The salt used for the authentication
381 * @param aEncryptSalt The salt used for the encryption
382 * @param aIV The Initialization Vector
383 * @param aIterations The number of iterations of the PBE algorithm
384 * @return A pointer to the new CPBEncryptionData object
386 IMPORT_C static CPBEncryptionData* NewL(const TDesC8& aPassword,
387 TPBECipher aCipher, const TDesC8& aAuthSalt,
388 const TDesC8& aEncryptSalt, const TDesC8& aIV, TUint aIterations);
391 * Creates a new CPBEncryptionData object
392 * and puts a pointer to it onto the cleanup stack.
394 * @param aPassword The user's initial password
395 * @param aCipher The cipher to use
396 * @param aAuthSalt The salt used for the authentication
397 * @param aEncryptSalt The salt used for the encryption
398 * @param aIV The Initialization Vector
399 * @param aIterations The number of iterations of the PBE algorithm
400 * @return A pointer to the new CPBEncryptionData object
402 IMPORT_C static CPBEncryptionData* NewLC(const TDesC8& aPassword,
403 TPBECipher aCipher, const TDesC8& aAuthSalt,
404 const TDesC8& aEncryptSalt, const TDesC8& aIV, TUint aIterations);
407 * Creates a new CPBEncryptionData from an existing one.
409 * @param aData The existing CPBEncryptionData object
410 * @return A pointer to the new CPBEncryptionData object
412 IMPORT_C static CPBEncryptionData* NewL(const CPBEncryptionData& aData);
415 * Creates a new CPBEncryptionData from an existing one,
416 * and puts a pointer to it onto the cleanup stack.
418 * @param aData The existing CPBEncryptionData object
419 * @return A pointer to the new CPBEncryptionData object
421 IMPORT_C static CPBEncryptionData* NewLC(const CPBEncryptionData& aData);
424 * Internalizes the encryption data from a read stream.
426 * @param aStream The stream to read from
427 * @return A pointer to the new CPBEncryptionData object
429 IMPORT_C static CPBEncryptionData* NewL(RReadStream& aStream);
432 * Internalizes the encryption data from a read stream,
433 * and puts a pointer to it onto the cleanup stack.
435 * @param aStream The stream to read from
436 * @return A pointer to the new CPBEncryptionData object
438 IMPORT_C static CPBEncryptionData* NewLC(RReadStream& aStream);
439 IMPORT_C static CPBEncryptionData* NewL(
440 const TDesC8& aPassword, const TDesC8& aAuthSalt,
441 const CPBEncryptParms& aParms);
445 * Returns the encryption parameter object.
447 * @return The CPBEncryptParms object
449 IMPORT_C const CPBEncryptParms& EncryptParms() const;
452 * Returns the authentication data object.
454 * @return The CPBAuthData object
456 IMPORT_C const CPBAuthData& AuthData() const;
459 * Externalizes the encryption data into a write stream.
461 * @param aStream The stream to write to
463 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
466 virtual ~CPBEncryptionData(void);
468 #ifdef PBEDATA_NO_EXPORTED_CONSTRUCTORS
469 CPBEncryptionData(void);
472 IMPORT_C CPBEncryptionData(void);
475 void ConstructL(const TDesC8& aPassword, TPBECipher aCipher,
476 const TDesC8& aAuthSalt, const TDesC8& aEncryptSalt, const TDesC8& aIV,
479 void ConstructL(const CPBEncryptionData& aData);
482 const TDesC8& aPassword, const TDesC8& aAuthSalt,
483 const CPBEncryptParms& aParms);
485 void ConstructL(RReadStream& aStream);
487 CPBEncryptionData(const CPBEncryptionData&);
488 CPBEncryptionData& operator= (const CPBEncryptionData&);
490 CPBEncryptParms* iParms;