author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
/* |
sl@0 | 2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 3 |
* All rights reserved. |
sl@0 | 4 |
* This component and the accompanying materials are made available |
sl@0 | 5 |
* under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 6 |
* which accompanies this distribution, and is available |
sl@0 | 7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 8 |
* |
sl@0 | 9 |
* Initial Contributors: |
sl@0 | 10 |
* Nokia Corporation - initial contribution. |
sl@0 | 11 |
* |
sl@0 | 12 |
* Contributors: |
sl@0 | 13 |
* |
sl@0 | 14 |
* Description: |
sl@0 | 15 |
* |
sl@0 | 16 |
*/ |
sl@0 | 17 |
|
sl@0 | 18 |
|
sl@0 | 19 |
#ifndef ARC4IMPL_H |
sl@0 | 20 |
#define ARC4IMPL_H |
sl@0 | 21 |
|
sl@0 | 22 |
/** |
sl@0 | 23 |
@file |
sl@0 | 24 |
@internalComponent |
sl@0 | 25 |
@released |
sl@0 | 26 |
*/ |
sl@0 | 27 |
|
sl@0 | 28 |
#include "symmetriccipherimpl.h" |
sl@0 | 29 |
#include <e32base.h> |
sl@0 | 30 |
#include <e32cmn.h> |
sl@0 | 31 |
#include "keys.h" |
sl@0 | 32 |
|
sl@0 | 33 |
|
sl@0 | 34 |
/** |
sl@0 | 35 |
Plug-in class for ARC4 stream cipher |
sl@0 | 36 |
*/ |
sl@0 | 37 |
namespace SoftwareCrypto |
sl@0 | 38 |
{ |
sl@0 | 39 |
using namespace CryptoSpi; |
sl@0 | 40 |
|
sl@0 | 41 |
NONSHARABLE_CLASS(CArc4Impl) : public CSymmetricStreamCipherImpl |
sl@0 | 42 |
{ |
sl@0 | 43 |
public: |
sl@0 | 44 |
|
sl@0 | 45 |
/** |
sl@0 | 46 |
Number of bytes to discard by default from an ARC4 key stream. |
sl@0 | 47 |
*/ |
sl@0 | 48 |
static const TUint KDefaultDiscardBytes = 768; |
sl@0 | 49 |
|
sl@0 | 50 |
/** |
sl@0 | 51 |
The size of the substitution box (i.e. lookup table) in bytes. |
sl@0 | 52 |
*/ |
sl@0 | 53 |
static const TInt KSBoxSize = 256; |
sl@0 | 54 |
|
sl@0 | 55 |
/** |
sl@0 | 56 |
Maximum ARC4 key size in bytes.2048 bits |
sl@0 | 57 |
*/ |
sl@0 | 58 |
static const TInt KMaxARC4KeyBytes = 256; |
sl@0 | 59 |
|
sl@0 | 60 |
/** |
sl@0 | 61 |
Creates an instance of an ARC4 symmetric cipher plug-in. |
sl@0 | 62 |
@param aKey The key |
sl@0 | 63 |
@param aDiscardBytes The number of bytes to drop from |
sl@0 | 64 |
the beginning of the key stream. |
sl@0 | 65 |
@return A pointer to a CArc4Impl instance |
sl@0 | 66 |
*/ |
sl@0 | 67 |
static CArc4Impl* NewL(const CKey& aKey, TInt aDiscardBytes); |
sl@0 | 68 |
|
sl@0 | 69 |
/** |
sl@0 | 70 |
Creates an instance of an ARC4 symmetric cipher plug-in, |
sl@0 | 71 |
and leave it on the cleanup stack |
sl@0 | 72 |
@param aKey The key |
sl@0 | 73 |
@param aDiscardBytes The number of bytes to drop from |
sl@0 | 74 |
the beginning of the key stream. |
sl@0 | 75 |
@return A pointer to a CArc4Impl instance |
sl@0 | 76 |
*/ |
sl@0 | 77 |
static CArc4Impl* NewLC(const CKey& aKey, TInt aDiscardBytes); |
sl@0 | 78 |
|
sl@0 | 79 |
//Destructor |
sl@0 | 80 |
~CArc4Impl(); |
sl@0 | 81 |
|
sl@0 | 82 |
//Override MPlugin virtual function |
sl@0 | 83 |
void Reset(); |
sl@0 | 84 |
|
sl@0 | 85 |
//Override CSymmetricCipherImpl virtual functions |
sl@0 | 86 |
TUid ImplementationUid() const; |
sl@0 | 87 |
TBool IsValidKeyLength(TInt aKeyBytes) const; |
sl@0 | 88 |
const CExtendedCharacteristics* GetExtendedCharacteristicsL(); |
sl@0 | 89 |
|
sl@0 | 90 |
static CExtendedCharacteristics* CreateExtendedCharacteristicsL(); |
sl@0 | 91 |
|
sl@0 | 92 |
private: |
sl@0 | 93 |
//Constructor |
sl@0 | 94 |
CArc4Impl(TInt aDiscardBytes); |
sl@0 | 95 |
|
sl@0 | 96 |
//second phase of construction |
sl@0 | 97 |
void ConstructL(const CKey& aKey); |
sl@0 | 98 |
|
sl@0 | 99 |
//Override CSymmetricStreamCipherImpl virtual functions |
sl@0 | 100 |
void DoProcess(TDes8& aData); |
sl@0 | 101 |
|
sl@0 | 102 |
void GenerateSBox(); |
sl@0 | 103 |
TUint8 GenerateByte(); |
sl@0 | 104 |
void DiscardBytes(TInt aDiscardBytes); |
sl@0 | 105 |
|
sl@0 | 106 |
private: |
sl@0 | 107 |
TUint8 ix; |
sl@0 | 108 |
TUint8 iy; |
sl@0 | 109 |
TInt iDiscardBytes; |
sl@0 | 110 |
TUint8 iState[KSBoxSize]; |
sl@0 | 111 |
}; |
sl@0 | 112 |
} |
sl@0 | 113 |
|
sl@0 | 114 |
#endif //ARC4IMPL_H |
sl@0 | 115 |
|
sl@0 | 116 |
|
sl@0 | 117 |