sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "tdsaprimegen.h" sl@0: #include "t_input.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "tbrokenrandom.h" sl@0: sl@0: CTestAction* CDSAPrimeGen::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CDSAPrimeGen::NewLC(aFs, aConsole, sl@0: aOut, aTestActionSpec); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CDSAPrimeGen::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CDSAPrimeGen* self = new(ELeave) CDSAPrimeGen(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CDSAPrimeGen::~CDSAPrimeGen() sl@0: { sl@0: delete iBody; sl@0: iP.Close(); sl@0: iQ.Close(); sl@0: delete const_cast(iPrimeCert); sl@0: } sl@0: sl@0: CDSAPrimeGen::CDSAPrimeGen(RFs& aFs, CConsoleBase& aConsole, Output& aOut) sl@0: : CTestAction(aConsole, aOut), iFs(aFs) sl@0: { sl@0: } sl@0: sl@0: void CDSAPrimeGen::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction::ConstructL(aTestActionSpec); sl@0: iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); sl@0: iBody->Des().Copy(aTestActionSpec.iActionBody); sl@0: sl@0: sl@0: iKeyBits = Input::ParseIntElement(*iBody, _L8(""), _L8("")); sl@0: sl@0: HBufC8* p = Input::ParseElementHexL(*iBody, _L8("

")); sl@0: CleanupStack::PushL(p); sl@0: iP = RInteger::NewL(*p); sl@0: CleanupStack::PopAndDestroy(p); sl@0: sl@0: HBufC8* q = Input::ParseElementHexL(*iBody, _L8("")); sl@0: CleanupStack::PushL(q); sl@0: iQ = RInteger::NewL(*q); sl@0: CleanupStack::PopAndDestroy(q); sl@0: sl@0: TUint counter = Input::ParseIntElement(*iBody, _L8(""), _L8("")); sl@0: HBufC8* seed = Input::ParseElementHexL(*iBody, _L8("")); sl@0: CleanupStack::PushL(seed); sl@0: iPrimeCert = CDSAPrimeCertificate::NewL(*seed, counter); sl@0: CleanupStack::PopAndDestroy(seed); sl@0: } sl@0: sl@0: void CDSAPrimeGen::DoPerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: iActionState = CTestAction::EAction; sl@0: } sl@0: sl@0: void CDSAPrimeGen::DoPerformPostrequisite(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: sl@0: iFinished = ETrue; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: void CDSAPrimeGen::DoReportAction(void) sl@0: { sl@0: } sl@0: sl@0: void CDSAPrimeGen::DoCheckResult(TInt) sl@0: { sl@0: if (iResult) sl@0: iConsole.Printf(_L(".")); sl@0: else sl@0: iConsole.Printf(_L("X")); sl@0: } sl@0: sl@0: void CDSAPrimeGen::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: __UHEAP_MARK; sl@0: TRequestStatus* status = &aStatus; sl@0: iResult = EFalse; sl@0: sl@0: CRandomSetSource* rng = new(ELeave)CRandomSetSource(iPrimeCert->Seed()); sl@0: SetThreadRandomLC(rng); sl@0: CDSAKeyPair* dsaPair = CDSAKeyPair::NewLC(iKeyBits); sl@0: sl@0: //this is more or less just calling the prime generation routine over again sl@0: //but it does test if ValidatePrimesL and the NewLC generate the same primes sl@0: iResult = dsaPair->PublicKey().ValidatePrimesL(*iPrimeCert); sl@0: sl@0: //we've already checked that the ValidatePrime + NewLC give same results sl@0: //this now checks against the vectors in the test scripts sl@0: if(iP != dsaPair->PublicKey().P() || sl@0: iQ != dsaPair->PublicKey().Q() || sl@0: iP != dsaPair->PrivateKey().P() || sl@0: iQ != dsaPair->PrivateKey().Q() ) sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(dsaPair); sl@0: CleanupStack::PopAndDestroy(); //SetThreadRandomLC sl@0: User::RequestComplete(status, KErrNone); sl@0: iActionState = CTestAction::EPostrequisite; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: