cryptoplugins/cryptospiplugins/source/softwarecrypto/arc4impl.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	ARC4IMPL_H
       
    20 #define	ARC4IMPL_H
       
    21 
       
    22 /**
       
    23 @file 
       
    24 @internalComponent
       
    25 @released
       
    26 */
       
    27 
       
    28 #include "symmetriccipherimpl.h"
       
    29 #include <e32base.h>
       
    30 #include <e32cmn.h>
       
    31 #include "keys.h"
       
    32 
       
    33 
       
    34 /**
       
    35 Plug-in class for ARC4 stream cipher
       
    36 */
       
    37 namespace SoftwareCrypto
       
    38 	{
       
    39 	using namespace CryptoSpi;
       
    40 
       
    41 	NONSHARABLE_CLASS(CArc4Impl) : public CSymmetricStreamCipherImpl
       
    42 		{
       
    43 	public:
       
    44 		
       
    45 		/** 
       
    46 		Number of bytes to discard by default from an ARC4 key stream. 
       
    47 		*/
       
    48 		static const TUint KDefaultDiscardBytes = 768;
       
    49 
       
    50 		/** 
       
    51 		The size of the substitution box (i.e. lookup table) in bytes. 
       
    52 		*/
       
    53 		static const TInt KSBoxSize = 256;
       
    54 
       
    55 		/** 
       
    56 		Maximum ARC4 key size in bytes.2048 bits 
       
    57 		*/
       
    58 		static const TInt KMaxARC4KeyBytes = 256; 
       
    59 
       
    60 		/**
       
    61 		Creates an instance of an ARC4 symmetric cipher plug-in.
       
    62 		@param aKey The key
       
    63 		@param aDiscardBytes The number of bytes to drop from 
       
    64 							the beginning of the key stream.
       
    65 		@return A pointer to a CArc4Impl instance
       
    66 		*/
       
    67 		static CArc4Impl* NewL(const CKey& aKey, TInt aDiscardBytes);
       
    68 
       
    69 		/**
       
    70 		Creates an instance of an ARC4 symmetric cipher plug-in,
       
    71 		and leave it on the cleanup stack
       
    72 		@param aKey The key
       
    73 		@param aDiscardBytes The number of bytes to drop from 
       
    74 							the beginning of the key stream.
       
    75 		@return A pointer to a CArc4Impl instance
       
    76 		*/
       
    77 		static CArc4Impl* NewLC(const CKey& aKey, TInt aDiscardBytes);
       
    78 
       
    79 		//Destructor
       
    80 		~CArc4Impl();
       
    81 
       
    82 		//Override MPlugin virtual function
       
    83 		void Reset();
       
    84 		
       
    85 		//Override CSymmetricCipherImpl virtual functions
       
    86 		TUid ImplementationUid() const;
       
    87 		TBool IsValidKeyLength(TInt aKeyBytes) const;
       
    88 		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
       
    89 		
       
    90 		static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
       
    91 		
       
    92 	private:
       
    93 		//Constructor
       
    94 		CArc4Impl(TInt aDiscardBytes);
       
    95 			
       
    96 		//second phase of construction	
       
    97 		void ConstructL(const CKey& aKey);
       
    98 				
       
    99 		//Override CSymmetricStreamCipherImpl virtual functions
       
   100 		void DoProcess(TDes8& aData);	
       
   101 
       
   102 		void GenerateSBox();
       
   103 		TUint8 GenerateByte();
       
   104 		void DiscardBytes(TInt aDiscardBytes);
       
   105 
       
   106 	private:
       
   107 		TUint8 ix;
       
   108 		TUint8 iy;
       
   109 		TInt iDiscardBytes;
       
   110 		TUint8 iState[KSBoxSize];
       
   111 		};
       
   112 	}
       
   113 
       
   114 #endif //ARC4IMPL_H
       
   115 
       
   116 
       
   117