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 /* @internalComponent */
119 CPBEncryptorElement();
120 /* @internalComponent */
121 void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
123 CSymmetricCipher* iCipher;
127 * Implements the password based decryption of elements.
131 class CPBDecryptorElement : public CPBDecryptor
135 * Creates a new CPBDecryptorElement object from the specified cipher,
138 * @param aCipher The decryption cipher
139 * @param aKey The decryption key
140 * @param aIV The Initialization Vector
141 * @return A pointer to the new CPBDecryptorElement object
143 IMPORT_C static CPBDecryptorElement* NewL(const TPBECipher aCipher,
144 const TDesC8& aKey, const TDesC8& aIV);
147 * Creates a new CPBDecryptorElement object from the specified cipher,
150 * Puts a pointer to the returned object onto the cleanup stack.
152 * @param aCipher The decryption cipher
153 * @param aKey The decryption key
154 * @param aIV The Initialization Vector
155 * @return A pointer to the new CPBDecryptorElement object
157 IMPORT_C static CPBDecryptorElement* NewLC(const TPBECipher aCipher,
158 const TDesC8& aKey, const TDesC8& aIV);
161 * Transforms aInput into its decrypted form, aOutput.
163 * aOutput must have CPBDecryptorElement::MaxOutputLength() empty bytes
164 * remaining in its length.
166 * See the Cryptography api-guide documentation for an explanation of
167 * how buffering of data supplied to this function is handled.
169 * @param aInput The ciphertext.
170 * @param aOutput The plaintext.
172 void Process(const TDesC8& aInput, TDes8& aOutput);
175 * Transforms aInput into its decrypted form, aOutput.
177 * aOutput must have CPBDecryptorElement::MaxFinalOutputLength()
178 * empty bytes remaining in its length.
180 * @param aInput The ciphertext.
181 * @param aOutput The plaintext.
183 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
186 * Gets the maximum size of the output given a certain input length.
188 * @param aMaxInputLength The maximum input length in bytes.
189 * @return The maximum output length in bytes.
191 TInt MaxOutputLength(TUint aMaxInputLength) const;
194 * Gets the maximum size of the output given a certain input length.
196 * @param aMaxInputLength The maximum input length in bytes.
197 * @return The maximum output length in bytes.
199 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
202 virtual ~CPBDecryptorElement();
204 /* @internalComponent */
205 CPBDecryptorElement();
206 /* @internalComponent */
207 void ConstructL(const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
209 CSymmetricCipher* iCipher;
213 * Implements the password based encryption of multiple elements.
218 class CPBEncryptorSet : public CPBEncryptor
222 * Creates a new CPBEncryptorSet object from the specified cipher and key,
223 * and a random Initialization Vector (IV).
225 * @param aCipher The encryption cipher
226 * @param aKey The encryption key
227 * @return A pointer to the new CPBEncryptorSet object
229 IMPORT_C static CPBEncryptorSet* NewL(const TPBECipher aCipher,
233 * Creates a new CPBEncryptorSet object from the specified cipher and key,
236 * Puts a pointer to the returned object onto the cleanup stack.
238 * @param aCipher The encryption cipher
239 * @param aKey The encryption key
240 * @return A pointer to the new CPBEncryptorSet object
242 IMPORT_C static CPBEncryptorSet* NewLC(const TPBECipher aCipher,
246 * Resets the CPBEncryptorSet object back to its original state
247 * and clears all its buffers.
249 IMPORT_C void Reset(void);
252 * Transforms aInput into its encrypted form, aOutput.
254 * aOutput must have CPBEncryptorSet::MaxOutputLength() empty bytes
255 * remaining in its length.
257 * @param aInput The plaintext.
258 * @param aOutput The ciphertext.
260 void Process(const TDesC8& aInput, TDes8& aOutput);
263 * Transforms aInput into its encrypted form, aOutput, and applies a
264 * padding scheme to ensure a block aligned result.
266 * aOutput must have CPBEncryptorSet::MaxFinalOutputLength()
267 * empty bytes remaining in its length.
269 * @param aInput The plaintext.
270 * @param aOutput The ciphertext.
272 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
275 * Gets the maximum size of the output given a certain input length.
277 * @param aMaxInputLength The maximum input length in bytes.
278 * @return The maximum output length in bytes.
280 TInt MaxOutputLength(TUint aMaxInputLength) const;
283 * Gets the maximum size of the output given a certain input length.
285 * @param aMaxInputLength The maximum input length in bytes.
286 * @return The maximum output length in bytes.
288 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
291 virtual ~CPBEncryptorSet();
293 /* @internalComponent */
295 /* @internalComponent */
296 void ConstructL(TPBECipher aCipher, const TDesC8& aKey);
298 CSymmetricCipher* iCipher;
305 * Implements the password based decryption of multiple elements.
309 class CPBDecryptorSet : public CPBDecryptor
313 * Creates a new CPBDecryptorSet object from the specified cipher and key,
316 * @param aCipher The decryption cipher
317 * @param aKey The decryption key
318 * @return A pointer to the new CPBDecryptorSet object
320 IMPORT_C static CPBDecryptorSet* NewL(const TPBECipher aCipher,
324 * Creates a new CPBDecryptorSet object from the specified cipher and key,
327 * Puts a pointer to the returned object onto the cleanup stack.
329 * @param aCipher The decryption cipher
330 * @param aKey The decryption key
331 * @return A pointer to the new CPBDecryptorSet object
333 IMPORT_C static CPBDecryptorSet* NewLC(const TPBECipher aCipher,
337 * Resets the CPBDecryptorSet object back to its original state
338 * and clears all its buffers.
340 IMPORT_C void Reset(void);
343 * Transforms aInput into its decrypted form, aOutput.
345 * aOutput must have CPBDecryptorSet::MaxOutputLength() empty bytes
346 * remaining in its length.
348 * @param aInput The ciphertext.
349 * @param aOutput The plaintext.
351 void Process(const TDesC8& aInput, TDes8& aOutput);
354 * Transforms aInput into its decrypted form, aOutput, and applies a
355 * padding scheme to ensure a block aligned result.
357 * aOutput must have CPBDecryptorSet::MaxFinalOutputLength()
358 * empty bytes remaining in its length.
360 * @param aInput The ciphertext.
361 * @param aOutput The plaintext.
363 void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
366 * Gets the maximum size of the output given a certain input length.
368 * @param aMaxInputLength The maximum input length in bytes.
369 * @return The maximum output length in bytes.
371 TInt MaxOutputLength(TUint aMaxInputLength) const;
374 * Gets the maximum size of the output given a certain input length.
376 * @param aMaxInputLength The maximum input length in bytes.
377 * @return The maximum output length in bytes.
379 TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
382 virtual ~CPBDecryptorSet();
384 /* @internalComponent */
386 /* @internalComponent */
387 void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
389 TPtrC8 ProcessIV(const TDesC8& aInput);
391 CSymmetricCipher* iCipher;