Update contrib.
2 * Copyright (c) 1998-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.
19 #include "tactionvector.h"
20 #include "symmetric.h"
22 CTestAction* CActionVector::NewL(RFs& aFs,
23 CConsoleBase& aConsole,
25 const TTestActionSpec& aTestActionSpec)
27 CTestAction* self = CActionVector::NewLC(aFs, aConsole,
28 aOut, aTestActionSpec);
33 CTestAction* CActionVector::NewLC(RFs& aFs,
34 CConsoleBase& aConsole,
36 const TTestActionSpec& aTestActionSpec)
38 CActionVector* self = new(ELeave) CActionVector(aFs, aConsole, aOut);
39 CleanupStack::PushL(self);
40 self->ConstructL(aTestActionSpec);
44 CActionVector::~CActionVector()
50 CActionVector::CActionVector(RFs& aFs,
51 CConsoleBase& aConsole,
54 : CCryptoTestAction(aFs, aConsole, aOut)
58 void CActionVector::DoPerformPrerequisiteL()
62 TPtrC8 vector = Input::ParseElement(*iBody, KVectorStart, KVectorEnd, pos, err);
64 DoInputParseL(vector);
66 CBlockTransformation* encryptor = NULL;
67 CBlockTransformation* decryptor = NULL;
75 encryptor = CDESEncryptor::NewLC(iKey->Des());
76 decryptor = CDESDecryptor::NewL(iKey->Des());
77 CleanupStack::Pop(encryptor);
82 CBlockTransformation* desEncryptor = NULL;
83 CBlockTransformation* desDecryptor = NULL;
85 desEncryptor = CDESEncryptor::NewLC(iKey->Des());
86 desDecryptor = CDESDecryptor::NewLC(iKey->Des());
88 encryptor = CModeCBCEncryptor::NewL(desEncryptor, iIV->Des());
89 CleanupStack::PushL(encryptor);
90 decryptor = CModeCBCDecryptor::NewL(desDecryptor, iIV->Des());
92 CleanupStack::Pop(3, desEncryptor);
97 encryptor = C3DESEncryptor::NewLC(iKey->Des());
98 decryptor = C3DESDecryptor::NewL(iKey->Des());
99 CleanupStack::Pop(encryptor);
104 CBlockTransformation* the3DESencryptor = NULL;
105 CBlockTransformation* the3DESdecryptor = NULL;
107 the3DESencryptor = C3DESEncryptor::NewLC(iKey->Des());
108 the3DESdecryptor = C3DESDecryptor::NewLC(iKey->Des());
110 encryptor = CModeCBCEncryptor::NewL(the3DESencryptor, iIV->Des());
111 CleanupStack::PushL(encryptor);
112 decryptor = CModeCBCDecryptor::NewL(the3DESdecryptor, iIV->Des());
114 CleanupStack::Pop(3, the3DESencryptor);
119 encryptor = CAESEncryptor::NewLC(iKey->Des());
120 decryptor = CAESDecryptor::NewL(iKey->Des());
122 CleanupStack::Pop(encryptor);
127 encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
128 decryptor = CRC2Decryptor::NewL(iKey->Des(), iEffectiveKeyLen);
129 CleanupStack::Pop(encryptor);
134 CBlockTransformation* theRC2encryptor = NULL;
135 CBlockTransformation* theRC2decryptor = NULL;
137 theRC2encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
138 theRC2decryptor = CRC2Decryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
140 encryptor = CModeCBCEncryptor::NewL(theRC2encryptor, iIV->Des());
141 CleanupStack::PushL(encryptor);
142 decryptor = CModeCBCDecryptor::NewL(theRC2decryptor, iIV->Des());
144 CleanupStack::Pop(3, theRC2encryptor);
149 iEncryptor = CARC4::NewL(*iKey,0);
150 iDecryptor = CARC4::NewL(*iKey,0);
155 iEncryptor = CNullCipher::NewL();
156 iDecryptor = CNullCipher::NewL();
163 User::Leave(KErrNotSupported);
167 CleanupStack::PushL(encryptor);
168 CleanupStack::PushL(decryptor);
170 if(!iEncryptor && !iDecryptor)
172 CPaddingSSLv3* dPadding = CPaddingSSLv3::NewLC(decryptor->BlockSize());
173 CPaddingSSLv3* ePadding = CPaddingSSLv3::NewLC(encryptor->BlockSize());
174 iEncryptor = CBufferedEncryptor::NewL(encryptor, ePadding);
175 CleanupStack::Pop(ePadding);
176 iDecryptor = CBufferedDecryptor::NewL(decryptor, dPadding);
177 CleanupStack::Pop(dPadding);
180 iEResult = HBufC8::NewMaxL(iEncryptor->MaxOutputLength(iInput->Length()));
181 iDResult = HBufC8::NewMaxL(iDecryptor->MaxOutputLength(iEResult->Size()));
183 CleanupStack::Pop(2, encryptor);
186 void CActionVector::DoPerformActionL()
188 // First perform the test blockwise (ie passing in one block at a time)
189 TUint blockSize = iEncryptor->BlockSize();
191 while (index <= (iInput->Size() - blockSize))
193 TPtr8 theEncryptResult((TUint8*)&(iEResult->operator[](index)), blockSize, blockSize);
194 theEncryptResult.FillZ(theEncryptResult.MaxLength());
195 theEncryptResult.SetLength(0);
197 TPtrC8 theEncryptInput(iInput->Mid(index, blockSize));
198 iEncryptor->Process(theEncryptInput, theEncryptResult);
200 if (iOutput->Mid(index, blockSize) == theEncryptResult)
203 break; // No point doing any more
208 if (*iOutput==*iEResult)
213 while (index <= (iEResult->Size()- blockSize))
215 TPtr8 theDecryptResult((TUint8*)&(iDResult->operator[](index)), blockSize, blockSize);
216 theDecryptResult.FillZ(theDecryptResult.MaxLength());
217 theDecryptResult.SetLength(0);
219 TPtrC8 theDecryptInput(iEResult->Mid(index, blockSize));
220 iDecryptor->Process(theDecryptInput, theDecryptResult);
222 if(iInput->Mid(index, blockSize) != theDecryptResult)
225 break; // No point doing any more
231 if (*iInput!=*iDResult)
238 // Now, if input is longer than a single block, repeat passing all the data
239 if ((TUint)iInput->Size() > blockSize)
241 TPtr8 theEncryptResult(iEResult->Des());
242 theEncryptResult.FillZ(theEncryptResult.MaxLength());
243 theEncryptResult.SetLength(0);
245 TPtrC8 theInput(*iInput);
246 iEncryptor->Process(theInput, theEncryptResult);
248 if (*iOutput!=*iEResult)
254 TPtr8 theDecryptResult(iDResult->Des());
255 theDecryptResult.FillZ(theDecryptResult.MaxLength());
256 theDecryptResult.SetLength(0);
258 iDecryptor->Process(*iEResult, theDecryptResult);
259 if (*iInput!=*iDResult)