sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the sl@0: * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __BUFFEREDTRANSFORMATION_H__ sl@0: #define __BUFFEREDTRANSFORMATION_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: class CPadding; sl@0: sl@0: /** sl@0: * Abstract class, deriving from CSymmetricCipher, encapsulating the buffering sl@0: * logic for block ciphers. sl@0: * sl@0: * It is responsible for feeding complete blocks of plaintext or ciphertext to sl@0: * the underlying encryptor or decryptor. Since the only difference between sl@0: * block cipher encryption and decryption is the ProcessFinalL() call, sl@0: * CBufferedTransformation implements all functions (by buffering and/or sl@0: * forwarding to the encryptor/decryptor) except ProcessFinalL() and sl@0: * MaxFinalOutputLength(). sl@0: * sl@0: * See the Cryptography api-guide documentation for the rules that this class sl@0: * and derived classes must follow. sl@0: * sl@0: */ sl@0: class CBufferedTransformation : public CSymmetricCipher sl@0: { sl@0: public: sl@0: /** The destructor frees all resources owned by the object, prior to its destruction. */ sl@0: IMPORT_C virtual ~CBufferedTransformation(); sl@0: public: sl@0: /** sl@0: * Encrypts or decrypts the input using the underlying block cipher, buffering sl@0: * the input as necessary. sl@0: * sl@0: * See the Cryptography api-guide documentation. sl@0: * sl@0: * @param aInput The input is appended to the internal buffer (initially empty), sl@0: * then all whole blocks are encrypted using the underlying block sl@0: * transformation and written into aOutput. Any leftover bytes will sl@0: * be buffered. sl@0: * @param aOutput The resulting processed data appended to aOutput. aOutput must sl@0: * have at least MaxOutputLength() empty bytes remaining in its length. sl@0: */ sl@0: virtual void Process(const TDesC8& aInput, TDes8& aOutput); sl@0: virtual TInt MaxOutputLength(TInt aInputLength) const; sl@0: virtual void Reset(); sl@0: virtual TInt BlockSize() const; sl@0: virtual TInt KeySize() const; sl@0: public: sl@0: /** sl@0: * Gets the underlying block transform. sl@0: * sl@0: * @return A pointer to the CBlockTransformation object sl@0: */ sl@0: IMPORT_C CBlockTransformation* BlockTransformer() const; sl@0: protected: sl@0: /** @internalAll */ sl@0: CBufferedTransformation(); sl@0: /** @internalAll */ sl@0: void ConstructL(CBlockTransformation* aBT, CPadding* aPadding); sl@0: protected: sl@0: /** A block transformation object */ sl@0: CBlockTransformation* iBT; sl@0: /** A descriptor which provides a buffer the length of the block size of iBT */ sl@0: HBufC8* iInputStoreBuf; sl@0: /** A pointer to iInputStoreBuf */ sl@0: TPtr8 iInputStore; sl@0: /** The padding */ sl@0: CPadding* iPadding; sl@0: }; sl@0: sl@0: /** sl@0: * Subclass of CBufferedTransformation for buffered encryption. sl@0: * sl@0: * Objects of this class are intialised with, and subsequently own, an encryptor sl@0: * derived from CBlockTransformation and a subclass of CPadding. sl@0: * sl@0: */ sl@0: class CBufferedEncryptor : public CBufferedTransformation sl@0: { sl@0: public: sl@0: /** sl@0: * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding. sl@0: * sl@0: * @param aBT Block transformation object (encryptor) sl@0: * @param aPadding Padding object (deriving from CPadding) sl@0: * @return A pointer to the new CBufferedEncryptor object sl@0: */ sl@0: IMPORT_C static CBufferedEncryptor* NewL(CBlockTransformation* aBT, sl@0: CPadding* aPadding); sl@0: sl@0: /** sl@0: * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding. sl@0: * sl@0: * The returned pointer is put onto the cleanup stack. sl@0: * sl@0: * @param aBT Block transformation object (encryptor) sl@0: * @param aPadding Padding object (deriving from CPadding) sl@0: * @return A pointer to the new CBufferedEncryptor object sl@0: */ sl@0: IMPORT_C static CBufferedEncryptor* NewLC(CBlockTransformation* aBT, sl@0: CPadding* aPadding); sl@0: public: sl@0: /** sl@0: * Completes an encryption operation using the underlying block transformation, but sl@0: * first ensuring that input data is block aligned using the previously supplied sl@0: * CPadding object. sl@0: * sl@0: * See the Cryptography api-guide documentation. sl@0: * sl@0: * @param aInput The final input data to be processed. sl@0: * @param aOutput The resulting processed data appended to aOutput. aOutput must sl@0: * have at least MaxFinalOutputLength() empty bytes remaining in its sl@0: * length. sl@0: */ sl@0: virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); sl@0: virtual TInt MaxFinalOutputLength(TInt aInputLength) const; sl@0: protected: sl@0: /** @internalComponent */ sl@0: void ConstructL(CBlockTransformation* aBT, CPadding* aPadding); sl@0: sl@0: /** @internalAll */ sl@0: CBufferedEncryptor(); sl@0: }; sl@0: sl@0: /** sl@0: * Subclass of CBufferedTransformation for buffered decryption. sl@0: * sl@0: * Objects of this class are intialised with, and subsequently own, a decryptor sl@0: * derived from CBlockTransformation and a subclass of CPadding. sl@0: * sl@0: */ sl@0: class CBufferedDecryptor : public CBufferedTransformation sl@0: { sl@0: public: sl@0: /** sl@0: * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding. sl@0: * sl@0: * @param aBT Block transformation object (decryptor) sl@0: * @param aPadding Padding object (deriving from CPadding) sl@0: * @return A pointer to the CBufferedDecryptor object. sl@0: */ sl@0: IMPORT_C static CBufferedDecryptor* NewL(CBlockTransformation* aBT, sl@0: CPadding* aPadding); sl@0: sl@0: /** sl@0: * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding. sl@0: * sl@0: * The returned pointer is put onto the cleanup stack. sl@0: * sl@0: * @param aBT Block transformation object (decryptor) sl@0: * @param aPadding Padding object (deriving from CPadding) sl@0: * @return A pointer to the new CBufferedDecryptor object sl@0: */ sl@0: IMPORT_C static CBufferedDecryptor* NewLC(CBlockTransformation* aBT, sl@0: CPadding* aPadding); sl@0: public: sl@0: /** sl@0: * Completes a decryption operation using the underlying block transformation and sl@0: * unpads the decrypted data. sl@0: * sl@0: * @param aInput The data to be processed and unpadded. sl@0: * aInput must be a whole number of blocks. sl@0: * @param aOutput The resulting processed and unpadded data appened to aOutput. sl@0: * aOutput must have at least MaxFinalOutputLength() empty bytes sl@0: * remaining in its length. sl@0: */ sl@0: virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); sl@0: virtual TInt MaxFinalOutputLength(TInt aInputLength) const; sl@0: protected: sl@0: /** @internalComponent */ sl@0: void ConstructL(CBlockTransformation* aBT, CPadding* aPadding); sl@0: sl@0: /** @internalAll */ sl@0: CBufferedDecryptor(); sl@0: }; sl@0: sl@0: #endif // __CBUFFEREDTRANSFORMATION_H__