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 "tdsavector.h"
20 #include "tvectorutils.h"
23 #include "tbrokenrandom.h"
25 const TInt KSha1HashLength = 20;
26 ////////////////////////////////////////////////////////////////////////////////
28 ////////////////////////////////////////////////////////////////////////////////
30 CTestAction* CDSASignVector::NewL(RFs& aFs,
31 CConsoleBase& aConsole,
33 const TTestActionSpec& aTestActionSpec)
35 CTestAction* self = CDSASignVector::NewLC(aFs, aConsole, aOut, aTestActionSpec);
40 CTestAction* CDSASignVector::NewLC(RFs& aFs,
41 CConsoleBase& aConsole,
43 const TTestActionSpec& aTestActionSpec)
45 CDSASignVector* self = new(ELeave) CDSASignVector(aFs, aConsole, aOut);
46 CleanupStack::PushL(self);
47 self->ConstructL(aTestActionSpec);
51 CDSASignVector::~CDSASignVector()
59 CDSASignVector::CDSASignVector(RFs& /*aFs*/,
60 CConsoleBase& aConsole,
62 : CVectorTest(aConsole, aOut)
66 void CDSASignVector::ConstructL(const TTestActionSpec& aTestActionSpec)
68 CVectorTest::ConstructL(aTestActionSpec);
70 iPrivKey = VectorUtils::ReadDSAPrivateKeyL(aTestActionSpec.iActionBody);
72 iMessage.Set(Input::ParseElement(aTestActionSpec.iActionBody, _L8("<m>")));
73 iK = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<k>"));
75 iSignature = VectorUtils::ReadDSASignatureL(aTestActionSpec.iActionBody);
76 iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1);
77 iSigInput->Update(iMessage);
80 void CDSASignVector::DoPerformActionL()
84 CRandomSetSource* random = new(ELeave)CRandomSetSource(*iK);
85 SetThreadRandomLC(random);
87 CDSASigner* signer = CDSASigner::NewLC(*iPrivKey);
88 const CDSASignature* testSig = signer->SignL(iSigInput->Final());
89 iResult = (*testSig == *iSignature);
91 CleanupStack::PopAndDestroy(signer);
93 CDSASigner* signer1 = CDSASigner::NewL(*iPrivKey);
94 CleanupStack::PushL(signer1);
95 if (signer1->MaxInputLength() != KSha1HashLength)
99 CleanupStack::PopAndDestroy(signer1);
100 CleanupStack::PopAndDestroy(); //SetThreadRandomLC
105 void CDSASignVector::DoPerformanceTestActionL()
110 void CDSASignVector::DoCheckResult(TInt /*aError*/)
112 // If using Keith's fixed up testframework for testing failures, iResult will
113 // have already been corrected for a deliberate fail result.
114 // If not using Keith's testframework iResult is still a fail result at this
115 // point, so now's the time to adjust for deliberate failure.
118 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
120 if( iResult == EFalse )
122 iConsole.Printf(_L("X"));
126 iConsole.Printf(_L("."));
130 ////////////////////////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////////////////////////
134 CTestAction* CDSAVerifyVector::NewL(RFs& aFs,
135 CConsoleBase& aConsole,
137 const TTestActionSpec& aTestActionSpec)
139 CTestAction* self = CDSAVerifyVector::NewLC(aFs, aConsole, aOut, aTestActionSpec);
144 CTestAction* CDSAVerifyVector::NewLC(RFs& aFs,
145 CConsoleBase& aConsole,
147 const TTestActionSpec& aTestActionSpec)
149 CDSAVerifyVector* self = new(ELeave) CDSAVerifyVector(aFs, aConsole, aOut);
150 CleanupStack::PushL(self);
151 self->ConstructL(aTestActionSpec);
155 CDSAVerifyVector::~CDSAVerifyVector()
163 CDSAVerifyVector::CDSAVerifyVector(RFs& /*aFs*/,
164 CConsoleBase& aConsole,
166 : CVectorTest(aConsole, aOut)
170 void CDSAVerifyVector::ConstructL(const TTestActionSpec& aTestActionSpec)
172 CVectorTest::ConstructL(aTestActionSpec);
174 iPubKey = VectorUtils::ReadDSAPublicKeyL(aTestActionSpec.iActionBody);
176 TPtrC8 message(Input::ParseElement(aTestActionSpec.iActionBody, _L8("<m>")));
177 if (message.Length()==0)
178 iMessage = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<hexm>"));
180 iMessage = message.AllocL();
182 iSignature = VectorUtils::ReadDSASignatureL(aTestActionSpec.iActionBody);
183 iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1);
184 iSigInput->Update(*iMessage);
187 void CDSAVerifyVector::DoPerformActionL()
191 CDSAVerifier* verifier = CDSAVerifier::NewLC(*iPubKey);
192 iResult = verifier->VerifyL(iSigInput->Final(), *iSignature);
194 CleanupStack::PopAndDestroy(verifier);
198 void CDSAVerifyVector::DoPerformanceTestActionL()
203 void CDSAVerifyVector::DoCheckResult(TInt /*aError*/)
205 // If using Keith's fixed up testframework for testing failures, iResult will
206 // have already been corrected for a deliberate fail result.
207 // If not using Keith's testframework iResult is still a fail result at this
208 // point, so now's the time to adjust for deliberate failure.
211 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
213 if( iResult == EFalse )
215 iConsole.Printf(_L("X"));
219 iConsole.Printf(_L("."));