os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/rijndaelimpl.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #ifndef	__RIJNDAELIMPL_H__
    20 #define	__RIJNDAELIMPL_H__
    21 
    22 /**
    23 @file 
    24 @internalComponent
    25 @released
    26 */
    27 
    28 #include <e32base.h>
    29 #include <e32cmn.h>
    30 #include "keys.h"
    31 #include "symmetriccipherimpl.h"
    32 
    33 /**
    34 Plug-in class for AES (Rijndael) block cipher
    35 */
    36 namespace SoftwareCrypto
    37 	{
    38 	using namespace CryptoSpi;
    39 	
    40 	NONSHARABLE_CLASS(CRijndaelImpl) : public CSymmetricBlockCipherImpl
    41 		{
    42 	public:
    43 		/**
    44 		Creates an instance of an AES (Rijndael) symmetric cipher plug-in.
    45 		@param aKey The key
    46 		@param aCryptoMode Whether to encrypt or decrypt
    47 		@param aOperationMode The block cipher mode ECB, CBC, CTR etc
    48 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
    49 		@return A pointer to a CRijndaelImpl instance
    50 		*/
    51 		static CRijndaelImpl* NewL(const CKey& aKey, 
    52 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
    53 
    54 		/**
    55 		Creates an instance of an AES (Rijndael) symmetric cipher plug-in.
    56 		A pointer to the plug-in instance is placed on the cleanup stack.
    57 		@param aKey The key
    58 		@param aCryptoMode Whether to encrypt or decrypt
    59 		@param aOperationMode The block cipher mode ECB, CBC, CTR etc
    60 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
    61 		@return A pointer to a CRijndaelImpl instance
    62 		*/
    63 		static CRijndaelImpl* NewLC(const CKey& aKey, 
    64 			TUid aCryptoMode,	TUid aOperationMode, TUid aPadding);
    65 
    66 		// From CSymmetricCipherImpl
    67 		TBool IsValidKeyLength(TInt aKeyBytes) const;
    68 		TUid ImplementationUid() const;
    69 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
    70 		
    71 		static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
    72 				
    73 		/// Destructor
    74 		~CRijndaelImpl();
    75 
    76 	private:
    77 		/**
    78 		Constructor
    79 		@param aOperationMode The mode of operation e.g. CBC
    80 		@param aCryptoMode Whether to encrypt or decrypt
    81 		@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
    82 		*/
    83 		CRijndaelImpl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
    84 			
    85 		///	second phase of construction	
    86 		void ConstructL(const CKey& aKey);
    87 					
    88 		/**
    89 		Creates the key schedule iK from CBlockTransformationImpl::iKey.
    90 		This should be called from ConstructL and Reset
    91 		*/
    92 		void SetKeySchedule();
    93 		
    94 		/**
    95 		Setup the key schedule for encryption
    96 		@param aKey The input key
    97 		@param aKeySchedule The pointer to the key schedule buffer
    98 		*/
    99 		void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
   100 		
   101 		/**
   102 		Setup the key schedule for decryption
   103 		@param aKey The input key
   104 		@param aKeySchedule The pointer to the key schedule buffer		
   105 		*/
   106 		void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
   107 
   108 		// From CSymmetricBlockCipherImpl
   109 		void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
   110 		void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
   111 				
   112 	private:
   113 	
   114 		/** 
   115 		The key-schedule size in WORDS
   116 		
   117 	 	The maximum size is (((KAESMaxBlockSize/4)+6)+1)*4
   118 	 	*/
   119 	 	static const TUint32 KKeyScheduleSize = 60;
   120 	 	
   121 	 	/// the key schedule
   122 		TUint32 iK[KKeyScheduleSize];
   123 		
   124 		TInt iRounds;
   125 		};
   126 	}
   127 
   128 #endif //__RIJNDAELIMPL_H__