Update contrib.
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include "../common/inlines.h"
22 #include <cryptostrength.h>
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
25 /** The size of the substitution box (i.e. lookup table) in bytes. */
26 const TInt KSBoxSize = 256;
29 inline TUint8 CARC4::GenerateByte()
31 TUint8 a = iState[ix];
32 iy = (TUint8)((iy + a) & 0xff);
33 TUint8 b = iState[iy];
37 ix = (TUint8)((ix + 1) & 0xff);
38 return (iState[(a + b) & 0xff]);
41 CARC4::CARC4(const TDesC8& aKey, TUint aDiscardBytes)
42 : ix(1), iy(0), iDiscardBytes(aDiscardBytes)
48 EXPORT_C CARC4* CARC4::NewL(const TDesC8& aKey, TUint aDiscardBytes)
50 CARC4* self = NewLC(aKey, aDiscardBytes);
51 CleanupStack::Pop(self);
55 EXPORT_C CARC4* CARC4::NewLC(const TDesC8& aKey, TUint aDiscardBytes)
57 CARC4* self = new(ELeave)CARC4(aKey, aDiscardBytes);
58 CleanupStack::PushL(self);
59 TCrypto::IsSymmetricWeakEnoughL(BytesToBits(aKey.Size()));
63 void CARC4::DoProcess(TDes8& aData)
65 TInt blockLen = aData.Size();
69 TUint8* blockPtr = (TUint8*)&aData[0];
72 *blockPtr++ ^= GenerateByte();
85 TInt CARC4::KeySize() const
90 void CARC4::DiscardBytes(TInt aDiscardBytes)
92 if (aDiscardBytes > 0)
98 while(--aDiscardBytes);
102 void CARC4::GenerateSBox(void)
104 TUint keyBytes = iKey.Size();
107 for (; i < KSBoxSize; i++)
108 iState[i] = (TUint8)i;
110 TUint keyIndex = 0, stateIndex = 0;
112 for (; i < KSBoxSize; i++)
115 stateIndex += iKey[keyIndex] + a;
117 iState[i] = iState[stateIndex];
118 iState[stateIndex] = (TUint8)a;
119 if (++keyIndex >= (TUint)keyBytes)
123 DiscardBytes(iDiscardBytes);