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 "tdsaprimegen.h"
21 #include <asymmetric.h>
25 #include "tbrokenrandom.h"
27 CTestAction* CDSAPrimeGen::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
28 const TTestActionSpec& aTestActionSpec)
30 CTestAction* self = CDSAPrimeGen::NewLC(aFs, aConsole,
31 aOut, aTestActionSpec);
36 CTestAction* CDSAPrimeGen::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
37 const TTestActionSpec& aTestActionSpec)
39 CDSAPrimeGen* self = new(ELeave) CDSAPrimeGen(aFs, aConsole, aOut);
40 CleanupStack::PushL(self);
41 self->ConstructL(aTestActionSpec);
45 CDSAPrimeGen::~CDSAPrimeGen()
50 delete const_cast<CDSAPrimeCertificate*>(iPrimeCert);
53 CDSAPrimeGen::CDSAPrimeGen(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
54 : CTestAction(aConsole, aOut), iFs(aFs)
58 void CDSAPrimeGen::ConstructL(const TTestActionSpec& aTestActionSpec)
60 CTestAction::ConstructL(aTestActionSpec);
61 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
62 iBody->Des().Copy(aTestActionSpec.iActionBody);
65 iKeyBits = Input::ParseIntElement(*iBody, _L8("<keybits>"), _L8("</keybits>"));
67 HBufC8* p = Input::ParseElementHexL(*iBody, _L8("<p>"));
68 CleanupStack::PushL(p);
69 iP = RInteger::NewL(*p);
70 CleanupStack::PopAndDestroy(p);
72 HBufC8* q = Input::ParseElementHexL(*iBody, _L8("<q>"));
73 CleanupStack::PushL(q);
74 iQ = RInteger::NewL(*q);
75 CleanupStack::PopAndDestroy(q);
77 TUint counter = Input::ParseIntElement(*iBody, _L8("<c>"), _L8("</c>"));
78 HBufC8* seed = Input::ParseElementHexL(*iBody, _L8("<seed>"));
79 CleanupStack::PushL(seed);
80 iPrimeCert = CDSAPrimeCertificate::NewL(*seed, counter);
81 CleanupStack::PopAndDestroy(seed);
84 void CDSAPrimeGen::DoPerformPrerequisite(TRequestStatus& aStatus)
86 TRequestStatus* status = &aStatus;
87 User::RequestComplete(status, KErrNone);
88 iActionState = CTestAction::EAction;
91 void CDSAPrimeGen::DoPerformPostrequisite(TRequestStatus& aStatus)
93 TRequestStatus* status = &aStatus;
96 User::RequestComplete(status, KErrNone);
99 void CDSAPrimeGen::DoReportAction(void)
103 void CDSAPrimeGen::DoCheckResult(TInt)
106 iConsole.Printf(_L("."));
108 iConsole.Printf(_L("X"));
111 void CDSAPrimeGen::PerformAction(TRequestStatus& aStatus)
114 TRequestStatus* status = &aStatus;
117 CRandomSetSource* rng = new(ELeave)CRandomSetSource(iPrimeCert->Seed());
118 SetThreadRandomLC(rng);
119 CDSAKeyPair* dsaPair = CDSAKeyPair::NewLC(iKeyBits);
121 //this is more or less just calling the prime generation routine over again
122 //but it does test if ValidatePrimesL and the NewLC generate the same primes
123 iResult = dsaPair->PublicKey().ValidatePrimesL(*iPrimeCert);
125 //we've already checked that the ValidatePrime + NewLC give same results
126 //this now checks against the vectors in the test scripts
127 if(iP != dsaPair->PublicKey().P() ||
128 iQ != dsaPair->PublicKey().Q() ||
129 iP != dsaPair->PrivateKey().P() ||
130 iQ != dsaPair->PrivateKey().Q() )
135 CleanupStack::PopAndDestroy(dsaPair);
136 CleanupStack::PopAndDestroy(); //SetThreadRandomLC
137 User::RequestComplete(status, KErrNone);
138 iActionState = CTestAction::EPostrequisite;