sl@0: /* sl@0: * Copyright (c) 2003-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 "tdhvector.h" sl@0: #include sl@0: #include "performancetest.h" sl@0: sl@0: CTestAction* CDHVector::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CDHVector::NewLC(aFs, aConsole, sl@0: aOut, aTestActionSpec); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CDHVector::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CDHVector* self = new(ELeave) CDHVector(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CDHVector::~CDHVector() sl@0: { sl@0: delete iN; sl@0: delete iG; sl@0: } sl@0: sl@0: CDHVector::CDHVector(RFs& /*aFs*/, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CVectorTest(aConsole, aOut) sl@0: { sl@0: } sl@0: sl@0: void CDHVector::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CVectorTest::ConstructL(aTestActionSpec); sl@0: sl@0: iN = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: iG = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: sl@0: } sl@0: sl@0: sl@0: void CDHVector::DoPerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: iN1 = RInteger::NewL(*iN); sl@0: iN2 = RInteger::NewL(*iN); sl@0: iG1 = RInteger::NewL(*iG); sl@0: iG2 = RInteger::NewL(*iG); sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: iActionState = CTestAction::EAction; sl@0: } sl@0: sl@0: void CDHVector::DoPerformanceTestActionL() sl@0: { sl@0: iResult = ETrue; sl@0: __UHEAP_MARK; sl@0: sl@0: CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1); sl@0: CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2); sl@0: CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey()); sl@0: sl@0: TTimeIntervalMicroSeconds agreeTime(0); sl@0: TTime start, end; sl@0: TTimeIntervalSeconds diff(0); sl@0: const TTimeIntervalSeconds KIterationTime(iPerfTestIterations); sl@0: sl@0: TInt index = 0; sl@0: sl@0: start.UniversalTime(); sl@0: sl@0: while (diff < KIterationTime) sl@0: { sl@0: delete const_cast(dh1->AgreeL(keyPair2->PublicKey())); sl@0: end.UniversalTime(); sl@0: end.SecondsFrom(start, diff); sl@0: index++; sl@0: } sl@0: end.UniversalTime(); sl@0: sl@0: agreeTime = end.MicroSecondsFrom(start); sl@0: sl@0: CleanupStack::PopAndDestroy(dh1); sl@0: CleanupStack::PopAndDestroy(keyPair2); sl@0: CleanupStack::PopAndDestroy(keyPair1); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if (iResult) sl@0: { sl@0: TReal rate = I64REAL(agreeTime.Int64()) / index; sl@0: TReal agreetime = I64REAL(agreeTime.Int64()); sl@0: TBuf<256> buf; sl@0: _LIT(KEncryptTime, "\tKey Agreements: %f us/agreement (%i in %f us)\r\n"); sl@0: buf.Format(KEncryptTime, rate, index, agreetime); sl@0: iOut.writeString(buf); sl@0: } sl@0: else sl@0: { sl@0: _LIT(KNoTimingInfo, "\tTest Failed! No benchmark data\n"); sl@0: iOut.writeString(KNoTimingInfo); sl@0: } sl@0: } sl@0: sl@0: void CDHVector::DoPerformActionL() sl@0: { sl@0: iResult = ETrue; sl@0: __UHEAP_MARK; sl@0: sl@0: CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1); sl@0: CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2); sl@0: CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey()); sl@0: CDH* dh2 = CDH::NewLC(keyPair2->PrivateKey()); sl@0: const HBufC8* key1 = dh1->AgreeL(keyPair2->PublicKey()); sl@0: CleanupStack::PushL(const_cast(key1)); sl@0: const HBufC8* key2 = dh2->AgreeL(keyPair1->PublicKey()); sl@0: sl@0: if(*key1 != *key2) sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: sl@0: delete const_cast(key2); sl@0: CleanupStack::PopAndDestroy(const_cast(key1)); sl@0: CleanupStack::PopAndDestroy(dh2); sl@0: CleanupStack::PopAndDestroy(dh1); sl@0: CleanupStack::PopAndDestroy(keyPair2); sl@0: CleanupStack::PopAndDestroy(keyPair1); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: