cryptoplugins/cryptospiplugins/source/softwarecrypto/rc2impl.h
changeset 19 cd501b96611d
equal deleted inserted replaced
15:da2ae96f639b 19:cd501b96611d
       
     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	__RC2_H__
       
    20 #define	__RC2_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 RC2 block cipher
       
    35 */
       
    36 namespace SoftwareCrypto
       
    37 	{
       
    38 	using namespace CryptoSpi;
       
    39 	
       
    40 	NONSHARABLE_CLASS(CRc2Impl) : public CSymmetricBlockCipherImpl
       
    41 		{
       
    42 	public:
       
    43 		/**
       
    44 		Creates an instance of an RC2 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 		@param aEffectiveKeyLenBits The effective key length in bits
       
    50 		@return A pointer to a CRc2Impl instance
       
    51 		*/
       
    52 		static CRc2Impl* NewL(const CKey& aKey, 
       
    53 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits);
       
    54 
       
    55 		/**
       
    56 		Creates an instance of an RC2 symmetric cipher plug-in.
       
    57 		A pointer to the plug-in instance is placed on the cleanup stack.
       
    58 		@param aKey The key
       
    59 		@param aCryptoMode Whether to encrypt or decrypt
       
    60 		@param aOperationMode The block cipher mode ECB, CBC, CTR etc
       
    61 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
       
    62 		@param aEffectiveKeyLenBits The effective key length in bits
       
    63 		@return A pointer to a CRc2Impl instance
       
    64 		*/
       
    65 		static CRc2Impl* NewLC(const CKey& aKey, 
       
    66 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits);
       
    67 		
       
    68 		// From CSymmetricCipherImpl
       
    69 		TBool IsValidKeyLength(TInt aKeyBytes) const;
       
    70 		TUid ImplementationUid() const;
       
    71 		TInt GetKeyStrength() const;
       
    72 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
       
    73 		
       
    74 		static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
       
    75 				
       
    76 		/// Destructor
       
    77 		~CRc2Impl();
       
    78 		
       
    79 		/** SSL Effective Key Length Compatibility - for compatibility with SSL */
       
    80 		static const TUint KDefaultEffectiveKeyLenBits = 1024;
       
    81 
       
    82 	private:
       
    83 		/**
       
    84 		Constructor
       
    85 		@param aOperationMode The mode of operation e.g. CBC
       
    86 		@param aCryptoMode Whether to encrypt or decrypt
       
    87 		@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
       
    88 		*/
       
    89 		CRc2Impl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
       
    90 			
       
    91 		///	second phase of construction	
       
    92 		void ConstructL(const CKey& aKey, TInt aEffectiveKeyLenBits);
       
    93 					
       
    94 		/**
       
    95 		Expands the key (iKey) to iEffectiveKeyLenBits and stores the result in iK
       
    96 		*/
       
    97 		void SetKeySchedule();
       
    98 		
       
    99 		// From CSymmetricBlockCipherImpl
       
   100 		void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
       
   101 		void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);		
       
   102 
       
   103 	private:		
       
   104 		static const TUint8 KRc2BlockBytes = 8;
       
   105 		static const TInt KRc2MaxKeySizeBytes = 128;	
       
   106 		static const TInt KRc2ExpandedKeyLen = 64;
       
   107 		/**
       
   108 	 	 The expanded key buffer.
       
   109 		 Each iK[i] is a 16-bit word.
       
   110 	 	 */
       
   111 		TUint16 iK[KRc2ExpandedKeyLen];	//	128 bytes		
       
   112 		
       
   113 		/** The effective key length in bits */
       
   114 		TInt iEffectiveKeyLenBits;	
       
   115 		};
       
   116 	}
       
   117 
       
   118 #endif //__RC2_H__