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.
27 #ifndef __PBENCRYPTOR_H__
28 #define __PBENCRYPTOR_H__
32 #include <msymmetriccipher.h>
35 * Implements the password based encryption of elements.
37 * @see CPBEncryptElement
40 class CPBEncryptorElement : public CPBEncryptor
44 * Creates a new CPBEncryptorElement object from the specified cipher,
45 * key, and Initialization Vector (IV).
47 * @param aCipher The encryption cipher
48 * @param aKey The encryption key
49 * @param aIV The Initialization Vector
50 * @return A pointer to the new CPBEncryptorElement object
52 IMPORT_C static CPBEncryptorElement* NewL(TPBECipher aCipher,
53 const TDesC8& aKey, const TDesC8& aIV);
56 * Creates a new CPBEncryptorElement object from the specified cipher,
59 * Puts a pointer to the returned object onto the cleanup stack.
61 * @param aCipher The encryption cipher
62 * @param aKey The encryption key
63 * @param aIV The Initialization Vector
64 * @return A pointer to the new CPBEncryptorElement object
66 IMPORT_C static CPBEncryptorElement* NewLC(TPBECipher aCipher,
67 const TDesC8& aKey, const TDesC8& aIV);
70 * Transforms aInput into its encrypted form, aOutput.
72 * aOutput must have CPBEncryptorElement::MaxOutputLength() empty bytes remaining in its length.
74 * See the Cryptography api-guide documentation for an explanation of
75 * how buffering of data supplied to this function is handled.
77 * @param aInput The plaintext.
78 * @param aOutput The ciphertext.
80 void Process(const TDesC8& aInput, TDes8& aOutput);
83 * Transforms aInput into its encrypted form, aOutput, and applies a
84 * padding scheme to ensure a block aligned result.
86 * aOutput must have CPBEncryptorElement::MaxFinalOutputLength()
87 * empty bytes remaining in its length.
89 * See the Cryptography api-guide documentation for an explanation of
90 * how buffering of data supplied to this function is handled.
92 * @param aInput The plaintext.
93 * @param aOutput The ciphertext.
95 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
98 * Gets the maximum size of the output resulting from calling Process() with a
101 * @param aMaxInputLength The maximum input length in bytes.
102 * @return The maximum output length in bytes.
104 TInt MaxOutputLength(TUint aMaxInputLength) const;
107 * Gets the maximum size of the output resulting from calling ProcessFinalL()
108 * with a given input length.
110 * @param aMaxInputLength The maximum input length in bytes.
111 * @return TInt The maximum output length in bytes.
113 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
116 virtual ~CPBEncryptorElement();
118 CPBEncryptorElement();
119 void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
121 CSymmetricCipher* iCipher;
125 * Implements the password based decryption of elements.
129 class CPBDecryptorElement : public CPBDecryptor
133 * Creates a new CPBDecryptorElement object from the specified cipher,
136 * @param aCipher The decryption cipher
137 * @param aKey The decryption key
138 * @param aIV The Initialization Vector
139 * @return A pointer to the new CPBDecryptorElement object
141 IMPORT_C static CPBDecryptorElement* NewL(const TPBECipher aCipher,
142 const TDesC8& aKey, const TDesC8& aIV);
145 * Creates a new CPBDecryptorElement object from the specified cipher,
148 * Puts a pointer to the returned object onto the cleanup stack.
150 * @param aCipher The decryption cipher
151 * @param aKey The decryption key
152 * @param aIV The Initialization Vector
153 * @return A pointer to the new CPBDecryptorElement object
155 IMPORT_C static CPBDecryptorElement* NewLC(const TPBECipher aCipher,
156 const TDesC8& aKey, const TDesC8& aIV);
159 * Transforms aInput into its decrypted form, aOutput.
161 * aOutput must have CPBDecryptorElement::MaxOutputLength() empty bytes
162 * remaining in its length.
164 * See the Cryptography api-guide documentation for an explanation of
165 * how buffering of data supplied to this function is handled.
167 * @param aInput The ciphertext.
168 * @param aOutput The plaintext.
170 void Process(const TDesC8& aInput, TDes8& aOutput);
173 * Transforms aInput into its decrypted form, aOutput.
175 * aOutput must have CPBDecryptorElement::MaxFinalOutputLength()
176 * empty bytes remaining in its length.
178 * @param aInput The ciphertext.
179 * @param aOutput The plaintext.
181 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
184 * Gets the maximum size of the output given a certain input length.
186 * @param aMaxInputLength The maximum input length in bytes.
187 * @return The maximum output length in bytes.
189 TInt MaxOutputLength(TUint aMaxInputLength) const;
192 * Gets the maximum size of the output given a certain input length.
194 * @param aMaxInputLength The maximum input length in bytes.
195 * @return The maximum output length in bytes.
197 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
200 virtual ~CPBDecryptorElement();
202 CPBDecryptorElement();
203 void ConstructL(const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
205 CSymmetricCipher* iCipher;
209 * Implements the password based encryption of multiple elements.
214 class CPBEncryptorSet : public CPBEncryptor
218 * Creates a new CPBEncryptorSet object from the specified cipher and key,
219 * and a random Initialization Vector (IV).
221 * @param aCipher The encryption cipher
222 * @param aKey The encryption key
223 * @return A pointer to the new CPBEncryptorSet object
225 IMPORT_C static CPBEncryptorSet* NewL(const TPBECipher aCipher,
229 * Creates a new CPBEncryptorSet object from the specified cipher and key,
232 * Puts a pointer to the returned object onto the cleanup stack.
234 * @param aCipher The encryption cipher
235 * @param aKey The encryption key
236 * @return A pointer to the new CPBEncryptorSet object
238 IMPORT_C static CPBEncryptorSet* NewLC(const TPBECipher aCipher,
242 * Resets the CPBEncryptorSet object back to its original state
243 * and clears all its buffers.
245 IMPORT_C void Reset(void);
248 * Transforms aInput into its encrypted form, aOutput.
250 * aOutput must have CPBEncryptorSet::MaxOutputLength() empty bytes
251 * remaining in its length.
253 * @param aInput The plaintext.
254 * @param aOutput The ciphertext.
256 void Process(const TDesC8& aInput, TDes8& aOutput);
259 * Transforms aInput into its encrypted form, aOutput, and applies a
260 * padding scheme to ensure a block aligned result.
262 * aOutput must have CPBEncryptorSet::MaxFinalOutputLength()
263 * empty bytes remaining in its length.
265 * @param aInput The plaintext.
266 * @param aOutput The ciphertext.
268 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
271 * Gets the maximum size of the output given a certain input length.
273 * @param aMaxInputLength The maximum input length in bytes.
274 * @return The maximum output length in bytes.
276 TInt MaxOutputLength(TUint aMaxInputLength) const;
279 * Gets the maximum size of the output given a certain input length.
281 * @param aMaxInputLength The maximum input length in bytes.
282 * @return The maximum output length in bytes.
284 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
287 virtual ~CPBEncryptorSet();
290 void ConstructL(TPBECipher aCipher, const TDesC8& aKey);
292 CSymmetricCipher* iCipher;
299 * Implements the password based decryption of multiple elements.
303 class CPBDecryptorSet : public CPBDecryptor
307 * Creates a new CPBDecryptorSet object from the specified cipher and key,
310 * @param aCipher The decryption cipher
311 * @param aKey The decryption key
312 * @return A pointer to the new CPBDecryptorSet object
314 IMPORT_C static CPBDecryptorSet* NewL(const TPBECipher aCipher,
318 * Creates a new CPBDecryptorSet object from the specified cipher and key,
321 * Puts a pointer to the returned object onto the cleanup stack.
323 * @param aCipher The decryption cipher
324 * @param aKey The decryption key
325 * @return A pointer to the new CPBDecryptorSet object
327 IMPORT_C static CPBDecryptorSet* NewLC(const TPBECipher aCipher,
331 * Resets the CPBDecryptorSet object back to its original state
332 * and clears all its buffers.
334 IMPORT_C void Reset(void);
337 * Transforms aInput into its decrypted form, aOutput.
339 * aOutput must have CPBDecryptorSet::MaxOutputLength() empty bytes
340 * remaining in its length.
342 * @param aInput The ciphertext.
343 * @param aOutput The plaintext.
345 void Process(const TDesC8& aInput, TDes8& aOutput);
348 * Transforms aInput into its decrypted form, aOutput, and applies a
349 * padding scheme to ensure a block aligned result.
351 * aOutput must have CPBDecryptorSet::MaxFinalOutputLength()
352 * empty bytes remaining in its length.
354 * @param aInput The ciphertext.
355 * @param aOutput The plaintext.
357 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
360 * Gets the maximum size of the output given a certain input length.
362 * @param aMaxInputLength The maximum input length in bytes.
363 * @return The maximum output length in bytes.
365 TInt MaxOutputLength(TUint aMaxInputLength) const;
368 * Gets the maximum size of the output given a certain input length.
370 * @param aMaxInputLength The maximum input length in bytes.
371 * @return The maximum output length in bytes.
373 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
376 virtual ~CPBDecryptorSet();
379 void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
381 TPtrC8 ProcessIV(const TDesC8& aInput);
383 CSymmetricCipher* iCipher;