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 "tactionincremental.h"
20 #include "symmetric.h"
22 #include "securityerr.h"
24 CTestAction* CActionIncremental::NewL(RFs& aFs,
25 CConsoleBase& aConsole,
27 const TTestActionSpec& aTestActionSpec)
29 CTestAction* self = CActionIncremental::NewLC(aFs, aConsole,
30 aOut, aTestActionSpec);
35 CTestAction* CActionIncremental::NewLC(RFs& aFs,
36 CConsoleBase& aConsole,
38 const TTestActionSpec& aTestActionSpec)
40 CActionIncremental* self = new(ELeave) CActionIncremental(aFs, aConsole, aOut);
41 CleanupStack::PushL(self);
42 self->ConstructL(aTestActionSpec);
46 CActionIncremental::~CActionIncremental()
50 CActionIncremental::CActionIncremental(RFs& aFs,
51 CConsoleBase& aConsole,
53 : CCryptoTestAction(aFs, aConsole, aOut)
56 void CActionIncremental::DoPerformPostrequisiteL()
71 void CActionIncremental::DoPerformPrerequisiteL()
76 TPtrC8 incremental = Input::ParseElement(*iBody, KIncrementalStart, KIncrementalEnd, pos, err);
78 DoInputParseL(incremental);
80 CBlockTransformation* encryptor = NULL;
81 CBlockTransformation* decryptor = NULL;
90 //If the test is weak key test
91 if(iExpectedWeakResult == KErrWeakKey)
93 //we expect to leave with KErrWeakKey reason
94 if(CDES::IsWeakKey(iKey->Des()))
96 User::Leave(KErrWeakKey);
98 else //test is unsuccessful, leave with a different reason
100 User::Leave(KErrGeneral);
103 encryptor = CDESEncryptor::NewLC(iKey->Des());
104 decryptor = CDESDecryptor::NewL(iKey->Des());
105 CleanupStack::Pop(encryptor);
110 CBlockTransformation* desEncryptor = NULL;
111 CBlockTransformation* desDecryptor = NULL;
113 if(iExpectedWeakResult == KErrWeakKey)
115 if(CDES::IsWeakKey(iKey->Des()))
117 User::Leave(KErrWeakKey);
121 User::Leave(KErrGeneral);
125 desEncryptor = CDESEncryptor::NewLC(iKey->Des());
126 desDecryptor = CDESDecryptor::NewLC(iKey->Des());
128 encryptor = CModeCBCEncryptor::NewL(desEncryptor, iIV->Des());
129 CleanupStack::PushL(encryptor);
130 decryptor = CModeCBCDecryptor::NewL(desDecryptor, iIV->Des());
131 CleanupStack::Pop(3);
136 encryptor = C3DESEncryptor::NewLC(iKey->Des());
137 decryptor = C3DESDecryptor::NewL(iKey->Des());
138 CleanupStack::Pop(encryptor);
143 CBlockTransformation* the3DESencryptor = NULL;
144 CBlockTransformation* the3DESdecryptor = NULL;
146 the3DESencryptor = C3DESEncryptor::NewLC(iKey->Des());
147 the3DESdecryptor = C3DESDecryptor::NewLC(iKey->Des());
149 encryptor = CModeCBCEncryptor::NewL(the3DESencryptor, iIV->Des());
150 CleanupStack::PushL(encryptor);
151 decryptor = CModeCBCDecryptor::NewL(the3DESdecryptor, iIV->Des());
152 CleanupStack::Pop(3);
157 encryptor = CAESEncryptor::NewLC(iKey->Des());
158 decryptor = CAESDecryptor::NewL(iKey->Des());
159 CleanupStack::Pop(encryptor);
164 encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
165 decryptor = CRC2Decryptor::NewL(iKey->Des(), iEffectiveKeyLen);
166 CleanupStack::Pop(encryptor);
171 encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
172 decryptor = CRC2Decryptor::NewL(iKey->Des(), iEffectiveKeyLen);
173 CleanupStack::Pop(encryptor);
178 iEncryptor = CARC4::NewL(*iKey, 0);
179 iDecryptor = CARC4::NewL(*iKey, 0);
184 iEncryptor = CNullCipher::NewL();
185 iDecryptor = CNullCipher::NewL();
190 User::Leave(KErrNotSupported);
193 CleanupStack::PushL(encryptor);
194 CleanupStack::PushL(decryptor);
195 if(!iEncryptor && !iDecryptor)
197 CPaddingSSLv3* dPadding = CPaddingSSLv3::NewLC(decryptor->BlockSize());
198 CPaddingSSLv3* ePadding = CPaddingSSLv3::NewLC(encryptor->BlockSize());
199 iEncryptor = CBufferedEncryptor::NewL(encryptor, ePadding);
200 CleanupStack::Pop(ePadding);
201 iDecryptor = CBufferedDecryptor::NewL(decryptor, dPadding);
202 CleanupStack::Pop(dPadding);
204 TInt desEBlockSize = encryptor->BlockSize();
205 TInt desDBlockSize = decryptor->BlockSize();
206 TInt bufEBlockSize = iEncryptor->BlockSize();
207 TInt bufDBlockSize = iDecryptor->BlockSize();
208 if ((desEBlockSize/desDBlockSize) != (bufEBlockSize/bufDBlockSize))
213 TInt desEKeySize = encryptor->KeySize();
214 TInt desDKeySize = decryptor->KeySize();
215 if (desEKeySize != desDKeySize)
224 TInt encryptorKeySize = iEncryptor->KeySize();
225 TInt decryptorKeySize = iDecryptor->KeySize();
226 if (encryptorKeySize != decryptorKeySize)
231 CleanupStack::Pop(2, encryptor);
233 iEResult = HBufC8::NewMaxL(iEncryptor->MaxFinalOutputLength(iInput->Length()));
234 iDResult = HBufC8::NewMaxL(iDecryptor->MaxFinalOutputLength(iEResult->Size()));
237 void CActionIncremental::DoPerformActionL()
239 TRAPD(res, DoDoPerformActionL())
240 if(res == KErrNoMemory)
247 void CActionIncremental::DoDoPerformActionL()
250 TPtr8 eResultActual = iEResult->Des();
251 eResultActual.FillZ(eResultActual.MaxLength());
252 eResultActual.SetLength(0);
254 TPtr8 dResultActual = iDResult->Des();
255 dResultActual.FillZ(dResultActual.MaxLength());
256 dResultActual.SetLength(0);
258 TInt len = iInput->Length();
259 for(TInt i=1; i<len; i++)
263 {// encryption in blocks of size i
264 iEncryptor->Process(iInput->Mid(j,i), eResultActual);
267 iEncryptor->ProcessFinalL(iInput->Mid(j), eResultActual);
270 for(; (j+(len-i))<len; j+=(len-i))
271 {// Decryption in blocks of size (len - i)
272 iDecryptor->Process(eResultActual.Mid(j, len-i), dResultActual);
275 iDecryptor->ProcessFinalL(eResultActual.Mid(j), dResultActual);
277 if(dResultActual != *iInput)
282 eResultActual.FillZ(eResultActual.MaxLength());
283 dResultActual.FillZ(dResultActual.MaxLength());
284 eResultActual.SetLength(0);
285 dResultActual.SetLength(0);