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: * Rijndael implementation 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 __RIJNDAEL_H__ sl@0: #define __RIJNDAEL_H__ sl@0: sl@0: #include "blocktransformation.h" sl@0: sl@0: /** sl@0: * Abstract base class for Rijndael, implementing the parts of Rijndael common to both sl@0: * Rijndael encryption and decryption. sl@0: * sl@0: */ sl@0: class CRijndael : public CBlockTransformation sl@0: { sl@0: public: // From CBlockTransformation sl@0: virtual void Reset(void); sl@0: virtual TInt KeySize(void) const; sl@0: /** The destructor frees all resources owned by the object, prior to its destruction. */ sl@0: IMPORT_C virtual ~CRijndael(void); sl@0: protected: sl@0: /** Default constructor */ sl@0: IMPORT_C CRijndael(void); sl@0: virtual void SetKey(const TDesC8& aKey); sl@0: virtual void ConstructL(const TDesC8& aKey); sl@0: protected: sl@0: /** sl@0: * The key schedule sl@0: * sl@0: * The maximum size is (((KAESMaxBlockSize/4)+6)+1)*4 sl@0: */ sl@0: TUint32 iK[60]; sl@0: /** The number of rounds */ sl@0: TUint iRounds; sl@0: /** sl@0: * The input key sl@0: * sl@0: * The key length (in bytes) must be one of the following: sl@0: * - KAESKeySize128 (=16) sl@0: * - KAESKeySize192 (=24) sl@0: * - KAESKeySize256 (=32). sl@0: */ sl@0: HBufC8* iKey; sl@0: private: sl@0: CRijndael(const CRijndael&); sl@0: const CRijndael& operator= (const CRijndael&); sl@0: }; sl@0: sl@0: /** sl@0: * Concrete class for AES encryption. sl@0: * sl@0: */ sl@0: class CAESEncryptor : public CRijndael sl@0: { sl@0: public: // From CBlockTransformation sl@0: /** sl@0: * Creates an instance of this class. sl@0: * sl@0: * @param aKey The key to be used for encryption. The key length must be either sl@0: * KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes. sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CAESEncryptor* NewL(const TDesC8& aKey); sl@0: sl@0: /** sl@0: * Creates an instance of this class and leaves it on the cleanup stack. sl@0: * sl@0: * @param aKey The key to be used for encryption. The key length must be either sl@0: * KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes. sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CAESEncryptor* NewLC(const TDesC8& aKey); sl@0: virtual TInt BlockSize() const; sl@0: virtual void Transform(TDes8& aBlock); sl@0: protected: sl@0: /** @internalAll */ sl@0: CAESEncryptor(void); sl@0: private: sl@0: CAESEncryptor(const CAESEncryptor&); sl@0: const CAESEncryptor& operator= (const CAESEncryptor&); sl@0: }; sl@0: sl@0: /** sl@0: * Concrete class for AES decryption. sl@0: * sl@0: */ sl@0: class CAESDecryptor : public CRijndael sl@0: { sl@0: public: // From CBlockTransformation sl@0: /** sl@0: * Creates an instance of this class. sl@0: * sl@0: * @param aKey The key to be used for decryption. The key length must be either sl@0: * KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes. sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CAESDecryptor* NewL(const TDesC8& aKey); sl@0: sl@0: /** sl@0: * Creates an instance of this class and leaves it on the cleanup stack. sl@0: * sl@0: * @param aKey The key to be used for decryption. The key length must be either sl@0: * KAESKeySize128 (=16), KAESKeySize192 (=24) or KAESKeySize256 (=32) bytes. sl@0: * sl@0: * @leave KErrKeyNotWeakEnough If the key size is larger than that allowed by the sl@0: * cipher strength restrictions of the crypto library. sl@0: * See TCrypto::IsSymmetricWeakEnoughL() sl@0: */ sl@0: IMPORT_C static CAESDecryptor* NewLC(const TDesC8& aKey); sl@0: virtual TInt BlockSize() const; sl@0: virtual void Transform(TDes8& aBlock); sl@0: protected: sl@0: virtual void SetKey(const TDesC8& aKey); sl@0: /** @internalAll */ sl@0: CAESDecryptor(void); sl@0: private: sl@0: CAESDecryptor(const CAESDecryptor&); sl@0: const CAESDecryptor& operator= (const CAESDecryptor&); sl@0: }; sl@0: sl@0: sl@0: #endif // __RIJNDAEL_H__