os/security/crypto/weakcryptospi/test/tplugins/inc/rc2impl.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	__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 <cryptospi/keys.h>
    31 #include "symmetriccipherimpl.h"
    32 
    33 /**
    34 Plug-in class for RC2 block cipher
    35 */
    36 namespace SoftwareCrypto
    37 	{
    38 	NONSHARABLE_CLASS(CRc2Impl) : public CSymmetricBlockCipherImpl
    39 		{
    40 	public:
    41 	
    42 		/**
    43 		Creates an instance of an RC2 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 		@param aEffectiveKeyLenBits The effective key length in bits
    49 		@return A pointer to a CRc2Impl instance
    50 		*/
    51 		static CRc2Impl* NewL(const CryptoSpi::CKey& aKey, 
    52 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits);
    53 
    54 		/**
    55 		Creates an instance of an RC2 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 		@param aEffectiveKeyLenBits The effective key length in bits
    62 		@return A pointer to a CRc2Impl instance
    63 		*/
    64 		static CRc2Impl* NewLC(const CryptoSpi::CKey& aKey, 
    65 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding, TInt aEffectiveKeyLenBits);
    66 		
    67 		// From CSymmetricCipherImpl
    68 		TBool IsValidKeyLength(TInt aKeyBytes) const;
    69 		TUid ImplementationUid() const;
    70 		TInt GetKeyStrength() const;
    71 				
    72 		/// Destructor
    73 		~CRc2Impl();
    74 		
    75 		/** SSL Effective Key Length Compatibility - for compatibility with SSL */
    76 		static const TUint KDefaultEffectiveKeyLenBits = 1024;
    77 
    78 	private:
    79 		/**
    80 		Constructor
    81 		@param aOperationMode The mode of operation e.g. CBC
    82 		@param aCryptoMode Whether to encrypt or decrypt
    83 		@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
    84 		*/
    85 		CRc2Impl(TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
    86 			
    87 		///	second phase of construction	
    88 		void ConstructL(const CKey& aKey, TInt aEffectiveKeyLenBits);
    89 					
    90 		/**
    91 		Expands the key (iKey) to iEffectiveKeyLenBits and stores the result in iK
    92 		*/
    93 		void SetKeySchedule();
    94 		
    95 		// From CSymmetricBlockCipherImpl
    96 		void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
    97 		void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);		
    98 
    99 	private:		
   100 		static const TUint8 KRc2BlockBytes = 8;
   101 		static const TInt KRc2MaxKeySizeBytes = 128;	
   102 		static const TInt KRc2ExpandedKeyLen = 64;
   103 		/**
   104 	 	 The expanded key buffer.
   105 		 Each iK[i] is a 16-bit word.
   106 	 	 */
   107 		TUint16 iK[KRc2ExpandedKeyLen];	//	128 bytes		
   108 		
   109 		/** The effective key length in bits */
   110 		TInt iEffectiveKeyLenBits;	
   111 		};
   112 	}
   113 
   114 #endif //__RC2_H__