sl@0: /* sl@0: * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef ARC4IMPL_H sl@0: #define ARC4IMPL_H sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: sl@0: #include "symmetriccipherimpl.h" sl@0: #include <e32base.h> sl@0: #include <e32cmn.h> sl@0: #include <cryptospi/keys.h> sl@0: sl@0: sl@0: /** sl@0: Plug-in class for ARC4 stream cipher sl@0: */ sl@0: namespace SoftwareCrypto sl@0: { sl@0: using namespace CryptoSpi; sl@0: sl@0: NONSHARABLE_CLASS(CArc4Impl) : public CSymmetricStreamCipherImpl sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: Number of bytes to discard by default from an ARC4 key stream. sl@0: */ sl@0: static const TUint KDefaultDiscardBytes = 768; sl@0: sl@0: /** sl@0: The size of the substitution box (i.e. lookup table) in bytes. sl@0: */ sl@0: static const TInt KSBoxSize = 256; sl@0: sl@0: /** sl@0: Maximum ARC4 key size in bytes.2048 bits sl@0: */ sl@0: static const TInt KMaxARC4KeyBytes = 256; sl@0: sl@0: /** sl@0: Creates an instance of an ARC4 symmetric cipher plug-in. sl@0: @param aKey The key sl@0: @param aDiscardBytes The number of bytes to drop from sl@0: the beginning of the key stream. sl@0: @return A pointer to a CArc4Impl instance sl@0: */ sl@0: static CArc4Impl* NewL(const CKey& aKey, TInt aDiscardBytes); sl@0: sl@0: /** sl@0: Creates an instance of an ARC4 symmetric cipher plug-in, sl@0: and leave it on the cleanup stack sl@0: @param aKey The key sl@0: @param aDiscardBytes The number of bytes to drop from sl@0: the beginning of the key stream. sl@0: @return A pointer to a CArc4Impl instance sl@0: */ sl@0: static CArc4Impl* NewLC(const CKey& aKey, TInt aDiscardBytes); sl@0: sl@0: //Destructor sl@0: ~CArc4Impl(); sl@0: sl@0: //Override MPlugin virtual function sl@0: void Reset(); sl@0: sl@0: //Override CSymmetricCipherImpl virtual functions sl@0: TUid ImplementationUid() const; sl@0: TBool IsValidKeyLength(TInt aKeyBytes) const; sl@0: sl@0: private: sl@0: //Constructor sl@0: CArc4Impl(TInt aDiscardBytes); sl@0: sl@0: //second phase of construction sl@0: void ConstructL(const CKey& aKey); sl@0: sl@0: //Override CSymmetricStreamCipherImpl virtual functions sl@0: void DoProcess(TDes8& aData); sl@0: sl@0: void GenerateSBox(); sl@0: TUint8 GenerateByte(); sl@0: void DiscardBytes(TInt aDiscardBytes); sl@0: sl@0: private: sl@0: TUint8 ix; sl@0: TUint8 iy; sl@0: TInt iDiscardBytes; sl@0: TUint8 iState[KSBoxSize]; sl@0: }; sl@0: } sl@0: sl@0: #endif //ARC4IMPL_H sl@0: sl@0: sl@0: