1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/arc4impl.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,117 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#ifndef ARC4IMPL_H
1.23 +#define ARC4IMPL_H
1.24 +
1.25 +/**
1.26 +@file
1.27 +@internalComponent
1.28 +@released
1.29 +*/
1.30 +
1.31 +#include "symmetriccipherimpl.h"
1.32 +#include <e32base.h>
1.33 +#include <e32cmn.h>
1.34 +#include "keys.h"
1.35 +
1.36 +
1.37 +/**
1.38 +Plug-in class for ARC4 stream cipher
1.39 +*/
1.40 +namespace SoftwareCrypto
1.41 + {
1.42 + using namespace CryptoSpi;
1.43 +
1.44 + NONSHARABLE_CLASS(CArc4Impl) : public CSymmetricStreamCipherImpl
1.45 + {
1.46 + public:
1.47 +
1.48 + /**
1.49 + Number of bytes to discard by default from an ARC4 key stream.
1.50 + */
1.51 + static const TUint KDefaultDiscardBytes = 768;
1.52 +
1.53 + /**
1.54 + The size of the substitution box (i.e. lookup table) in bytes.
1.55 + */
1.56 + static const TInt KSBoxSize = 256;
1.57 +
1.58 + /**
1.59 + Maximum ARC4 key size in bytes.2048 bits
1.60 + */
1.61 + static const TInt KMaxARC4KeyBytes = 256;
1.62 +
1.63 + /**
1.64 + Creates an instance of an ARC4 symmetric cipher plug-in.
1.65 + @param aKey The key
1.66 + @param aDiscardBytes The number of bytes to drop from
1.67 + the beginning of the key stream.
1.68 + @return A pointer to a CArc4Impl instance
1.69 + */
1.70 + static CArc4Impl* NewL(const CKey& aKey, TInt aDiscardBytes);
1.71 +
1.72 + /**
1.73 + Creates an instance of an ARC4 symmetric cipher plug-in,
1.74 + and leave it on the cleanup stack
1.75 + @param aKey The key
1.76 + @param aDiscardBytes The number of bytes to drop from
1.77 + the beginning of the key stream.
1.78 + @return A pointer to a CArc4Impl instance
1.79 + */
1.80 + static CArc4Impl* NewLC(const CKey& aKey, TInt aDiscardBytes);
1.81 +
1.82 + //Destructor
1.83 + ~CArc4Impl();
1.84 +
1.85 + //Override MPlugin virtual function
1.86 + void Reset();
1.87 +
1.88 + //Override CSymmetricCipherImpl virtual functions
1.89 + TUid ImplementationUid() const;
1.90 + TBool IsValidKeyLength(TInt aKeyBytes) const;
1.91 + const CExtendedCharacteristics* GetExtendedCharacteristicsL();
1.92 +
1.93 + static CExtendedCharacteristics* CreateExtendedCharacteristicsL();
1.94 +
1.95 + private:
1.96 + //Constructor
1.97 + CArc4Impl(TInt aDiscardBytes);
1.98 +
1.99 + //second phase of construction
1.100 + void ConstructL(const CKey& aKey);
1.101 +
1.102 + //Override CSymmetricStreamCipherImpl virtual functions
1.103 + void DoProcess(TDes8& aData);
1.104 +
1.105 + void GenerateSBox();
1.106 + TUint8 GenerateByte();
1.107 + void DiscardBytes(TInt aDiscardBytes);
1.108 +
1.109 + private:
1.110 + TUint8 ix;
1.111 + TUint8 iy;
1.112 + TInt iDiscardBytes;
1.113 + TUint8 iState[KSBoxSize];
1.114 + };
1.115 + }
1.116 +
1.117 +#endif //ARC4IMPL_H
1.118 +
1.119 +
1.120 +