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 __BUFFEREDTRANSFORMATION_H__
28 #define __BUFFEREDTRANSFORMATION_H__
31 #include <msymmetriccipher.h>
32 #include <blocktransformation.h>
37 * Abstract class, deriving from CSymmetricCipher, encapsulating the buffering
38 * logic for block ciphers.
40 * It is responsible for feeding complete blocks of plaintext or ciphertext to
41 * the underlying encryptor or decryptor. Since the only difference between
42 * block cipher encryption and decryption is the ProcessFinalL() call,
43 * CBufferedTransformation implements all functions (by buffering and/or
44 * forwarding to the encryptor/decryptor) except ProcessFinalL() and
45 * MaxFinalOutputLength().
47 * See the Cryptography api-guide documentation for the rules that this class
48 * and derived classes must follow.
51 class CBufferedTransformation : public CSymmetricCipher
54 /** The destructor frees all resources owned by the object, prior to its destruction. */
55 IMPORT_C virtual ~CBufferedTransformation();
58 * Encrypts or decrypts the input using the underlying block cipher, buffering
59 * the input as necessary.
61 * See the Cryptography api-guide documentation.
63 * @param aInput The input is appended to the internal buffer (initially empty),
64 * then all whole blocks are encrypted using the underlying block
65 * transformation and written into aOutput. Any leftover bytes will
67 * @param aOutput The resulting processed data appended to aOutput. aOutput must
68 * have at least MaxOutputLength() empty bytes remaining in its length.
70 virtual void Process(const TDesC8& aInput, TDes8& aOutput);
71 virtual TInt MaxOutputLength(TInt aInputLength) const;
73 virtual TInt BlockSize() const;
74 virtual TInt KeySize() const;
77 * Gets the underlying block transform.
79 * @return A pointer to the CBlockTransformation object
81 IMPORT_C CBlockTransformation* BlockTransformer() const;
84 CBufferedTransformation();
86 void ConstructL(CBlockTransformation* aBT, CPadding* aPadding);
88 /** A block transformation object */
89 CBlockTransformation* iBT;
90 /** A descriptor which provides a buffer the length of the block size of iBT */
91 HBufC8* iInputStoreBuf;
92 /** A pointer to iInputStoreBuf */
99 * Subclass of CBufferedTransformation for buffered encryption.
101 * Objects of this class are intialised with, and subsequently own, an encryptor
102 * derived from CBlockTransformation and a subclass of CPadding.
105 class CBufferedEncryptor : public CBufferedTransformation
109 * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding.
111 * @param aBT Block transformation object (encryptor)
112 * @param aPadding Padding object (deriving from CPadding)
113 * @return A pointer to the new CBufferedEncryptor object
115 IMPORT_C static CBufferedEncryptor* NewL(CBlockTransformation* aBT,
119 * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding.
121 * The returned pointer is put onto the cleanup stack.
123 * @param aBT Block transformation object (encryptor)
124 * @param aPadding Padding object (deriving from CPadding)
125 * @return A pointer to the new CBufferedEncryptor object
127 IMPORT_C static CBufferedEncryptor* NewLC(CBlockTransformation* aBT,
131 * Completes an encryption operation using the underlying block transformation, but
132 * first ensuring that input data is block aligned using the previously supplied
135 * See the Cryptography api-guide documentation.
137 * @param aInput The final input data to be processed.
138 * @param aOutput The resulting processed data appended to aOutput. aOutput must
139 * have at least MaxFinalOutputLength() empty bytes remaining in its
142 virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
143 virtual TInt MaxFinalOutputLength(TInt aInputLength) const;
145 /** @internalComponent */
146 void ConstructL(CBlockTransformation* aBT, CPadding* aPadding);
149 CBufferedEncryptor();
153 * Subclass of CBufferedTransformation for buffered decryption.
155 * Objects of this class are intialised with, and subsequently own, a decryptor
156 * derived from CBlockTransformation and a subclass of CPadding.
159 class CBufferedDecryptor : public CBufferedTransformation
163 * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding.
165 * @param aBT Block transformation object (decryptor)
166 * @param aPadding Padding object (deriving from CPadding)
167 * @return A pointer to the CBufferedDecryptor object.
169 IMPORT_C static CBufferedDecryptor* NewL(CBlockTransformation* aBT,
173 * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding.
175 * The returned pointer is put onto the cleanup stack.
177 * @param aBT Block transformation object (decryptor)
178 * @param aPadding Padding object (deriving from CPadding)
179 * @return A pointer to the new CBufferedDecryptor object
181 IMPORT_C static CBufferedDecryptor* NewLC(CBlockTransformation* aBT,
185 * Completes a decryption operation using the underlying block transformation and
186 * unpads the decrypted data.
188 * @param aInput The data to be processed and unpadded.
189 * aInput must be a whole number of blocks.
190 * @param aOutput The resulting processed and unpadded data appened to aOutput.
191 * aOutput must have at least MaxFinalOutputLength() empty bytes
192 * remaining in its length.
194 virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
195 virtual TInt MaxFinalOutputLength(TInt aInputLength) const;
197 /** @internalComponent */
198 void ConstructL(CBlockTransformation* aBT, CPadding* aPadding);
201 CBufferedDecryptor();
204 #endif // __CBUFFEREDTRANSFORMATION_H__