os/security/crypto/weakcryptospi/test/tplugins/inc/desimpl.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-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	__DESIMPL_H__
    20 #define	__DESIMPL_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 DES block cipher
    35 */
    36 namespace SoftwareCrypto
    37 	{
    38 	using namespace CryptoSpi;
    39 	
    40 	NONSHARABLE_CLASS(CDesImpl) : public CSymmetricBlockCipherImpl
    41 		{
    42 	public:
    43 	
    44 		/**
    45 		Creates an instance of a DES (Data Encryption Standard) symmetric cipher plug-in.
    46 		@param aKey The key
    47 		@param aCryptoMode whether to encrypt or decrypt
    48 		@param aOperationMode The block cipher mode ECB, CBC, CTR etc
    49 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
    50 		@return A pointer to a CDesImpl instance
    51 		*/
    52 		static CDesImpl* NewL(TUid aImplementationUid, const CKey& aKey, 
    53 			TUid aCryptoMode, TUid aOperationMode, TUid aPadding);
    54 
    55 		/**
    56 		Creates an instance of a DES (Data Encryption Standard) 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 T block cipher mode ECB, CBC, CTR etc
    61 		@param aPadding The padding scheme to use None, SSLv3, PKCS#7
    62 		@return A pointer to a CDesImpl instance
    63 		*/
    64 		static CDesImpl* NewLC(TUid aImplementationUid, const CKey& aKey, 
    65 			TUid aCryptoMode,	TUid aOperationMode, TUid aPadding);
    66 		
    67 		// From CSymmetricCipherImpl
    68 		TInt GetKeyStrength() const;
    69 		TBool IsValidKeyLength(TInt aKeyBytes) const;
    70 		TUid ImplementationUid() const;
    71 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
    72 		
    73 		static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
    74 
    75 				
    76 		/// Destructor
    77 		~CDesImpl();		
    78 	protected:
    79 		/**
    80 		Constructor
    81 		@param aBlockBytes The block size in bytes (needed to allow
    82 		3DES implementation to inherit from this class)
    83 		@param aOperationMode The mode of operation e.g. CBC
    84 		@param aCryptoMode Whether to encrypt or decrypt
    85 		@param aPaddingMode The padding mode to use. None, SSL, PKCS#7
    86 		*/
    87 		CDesImpl(TUid aImplementationUid, TUint8 aBlockBytes, TUid aOperationMode, TUid aCryptoMode, TUid aPaddingMode);
    88 		
    89 		/**	
    90 		Second phase of construction
    91 		@param aKey The key object
    92 		*/
    93 		void ConstructL(const CKey& aKey);	
    94 			
    95 		// These protected functions are re-used by 3DES
    96 		/**
    97 		Transforms a block of data
    98 		@param l The left half of the block to transform
    99 		@param r The right half of the block to transform
   100 		@param aKeySchedule The keyschedule to use for the transformation
   101 		*/
   102 		void DoTransform(TUint32& l, TUint32& r, const TUint32* aKeySchedule);
   103 		
   104 		/**
   105 		Setup the key schedule for encryption
   106 		@param aKey The input key
   107 		@param aKeySchedule A pointer to the key schedule buffer
   108 		*/
   109 		void SetEncryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
   110 		
   111 		/**
   112 		Setup the key schedule for decryption
   113 		@param aKey The input key
   114 		@param aKeySchedule A pointer to the key schedule buffer		
   115 		*/
   116 		void SetDecryptKeySchedule(const TDesC8& aKey, TUint32* aKeySchedule);
   117 		
   118 		static const TUint8 KDesBlockBytes = 8;
   119 		static const TUint8 KDesKeyBytes = 8;						
   120 
   121 	private:														
   122 
   123 		/**
   124 		Creates the key schedule iK from CBlockTransformationImpl::iKey.
   125 		This should be called from ConstructL and Reset
   126 		*/
   127 		void SetKeySchedule();			
   128 
   129 		// From CSymmetricBlockCipherImpl
   130 		void TransformEncrypt(TUint8* aBuffer, TUint aNumBlocks);
   131 		void TransformDecrypt(TUint8* aBuffer, TUint aNumBlocks);
   132 					
   133 	private:
   134 		
   135 		TUid iImplementationUid; 
   136 	
   137 		/// Size of the key schedule in words
   138 		static const TUint KKeyScheduleSize = 32;
   139 		
   140 		/// the key schedule
   141 		TUint32 iK[KKeyScheduleSize];
   142 		};
   143 	}
   144 
   145 #endif // __DESIMPL_H__