os/security/crypto/weakcryptospi/test/tplugins/inc/rijndaelimpl.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006-2010 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 <cryptospi/keys.h>
    31 #include "symmetriccipherimpl.h"
    32 
    33 /**
    34 Plug-in class for AES (Rijndael) block cipher
    35 */
    36 namespace SoftwareCrypto
    37 	{
    38 	NONSHARABLE_CLASS(CRijndaelImpl) : public CSymmetricBlockCipherImpl
    39 		{
    40 	public:
    41 	
    42 		/**
    43 		Creates an instance of an AES (Rijndael) symmetric cipher plug-in.
    44 		@param aKey The key
    45 		@param aCryptoMode Whether to encrypt or decrypt
    46 		@param aOperationMode The block cipher mode ECB, CBC, CTR etc
    47 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
    48 		@return A pointer to a CRijndaelImpl instance
    49 		*/
    50 		static CRijndaelImpl* NewL(const CryptoSpi::CKey& aKey, 
    51 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TUid aImplementationUid);
    52 
    53 		/**
    54 		Creates an instance of an AES (Rijndael) symmetric cipher plug-in.
    55 		A pointer to the plug-in instance is placed on the cleanup stack.
    56 		@param aKey The key
    57 		@param aCryptoMode Whether to encrypt or decrypt
    58 		@param aOperationMode The block cipher mode ECB, CBC, CTR etc
    59 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
    60 		@return A pointer to a CRijndaelImpl instance
    61 		*/
    62 		static CRijndaelImpl* NewLC(const CryptoSpi::CKey& aKey, 
    63 			TUid aCryptoMode,	TUid aOperationMode, TUid aPadding, TUid aImplementationUid);
    64 
    65 		// From CSymmetricCipherImpl
    66 		TBool IsValidKeyLength(TInt aKeyBytes) const;
    67 		TUid ImplementationUid() const;
    68 		
    69 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
    70 		static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
    71 
    72 		/// Destructor
    73 		~CRijndaelImpl();
    74 
    75 	private:
    76 		/**
    77 		Constructor
    78 		@param aOperationMode The mode of operation e.g. CBC
    79 		@param aCryptoMode Whether to encrypt or decrypt
    80 		@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
    81 		*/
    82 		CRijndaelImpl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode, 
    83 						TUid aImplementationUid);
    84 			
    85 		///	second phase of construction	
    86 		void ConstructL(const CryptoSpi::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 		TUid iImplementationUid;
   127 		};
   128 	}
   129 
   130 #endif //__RIJNDAELIMPL_H__