First public contribution.
2 * Copyright (c) 2003-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 "tdhvector.h"
21 #include "performancetest.h"
23 CTestAction* CDHVector::NewL(RFs& aFs,
24 CConsoleBase& aConsole,
26 const TTestActionSpec& aTestActionSpec)
28 CTestAction* self = CDHVector::NewLC(aFs, aConsole,
29 aOut, aTestActionSpec);
34 CTestAction* CDHVector::NewLC(RFs& aFs,
35 CConsoleBase& aConsole,
37 const TTestActionSpec& aTestActionSpec)
39 CDHVector* self = new(ELeave) CDHVector(aFs, aConsole, aOut);
40 CleanupStack::PushL(self);
41 self->ConstructL(aTestActionSpec);
45 CDHVector::~CDHVector()
51 CDHVector::CDHVector(RFs& /*aFs*/,
52 CConsoleBase& aConsole,
54 : CVectorTest(aConsole, aOut)
58 void CDHVector::ConstructL(const TTestActionSpec& aTestActionSpec)
60 CVectorTest::ConstructL(aTestActionSpec);
62 iN = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<n>"));
63 iG = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<g>"));
68 void CDHVector::DoPerformPrerequisite(TRequestStatus& aStatus)
70 iN1 = RInteger::NewL(*iN);
71 iN2 = RInteger::NewL(*iN);
72 iG1 = RInteger::NewL(*iG);
73 iG2 = RInteger::NewL(*iG);
74 TRequestStatus* status = &aStatus;
75 User::RequestComplete(status, KErrNone);
76 iActionState = CTestAction::EAction;
79 void CDHVector::DoPerformanceTestActionL()
84 CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1);
85 CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2);
86 CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey());
88 TTimeIntervalMicroSeconds agreeTime(0);
90 TTimeIntervalSeconds diff(0);
91 const TTimeIntervalSeconds KIterationTime(iPerfTestIterations);
95 start.UniversalTime();
97 while (diff < KIterationTime)
99 delete const_cast<HBufC8*>(dh1->AgreeL(keyPair2->PublicKey()));
101 end.SecondsFrom(start, diff);
106 agreeTime = end.MicroSecondsFrom(start);
108 CleanupStack::PopAndDestroy(dh1);
109 CleanupStack::PopAndDestroy(keyPair2);
110 CleanupStack::PopAndDestroy(keyPair1);
116 TReal rate = I64REAL(agreeTime.Int64()) / index;
117 TReal agreetime = I64REAL(agreeTime.Int64());
119 _LIT(KEncryptTime, "\tKey Agreements: %f us/agreement (%i in %f us)\r\n");
120 buf.Format(KEncryptTime, rate, index, agreetime);
121 iOut.writeString(buf);
125 _LIT(KNoTimingInfo, "\tTest Failed! No benchmark data\n");
126 iOut.writeString(KNoTimingInfo);
130 void CDHVector::DoPerformActionL()
135 CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1);
136 CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2);
137 CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey());
138 CDH* dh2 = CDH::NewLC(keyPair2->PrivateKey());
139 const HBufC8* key1 = dh1->AgreeL(keyPair2->PublicKey());
140 CleanupStack::PushL(const_cast<HBufC8*>(key1));
141 const HBufC8* key2 = dh2->AgreeL(keyPair1->PublicKey());
148 delete const_cast<HBufC8*>(key2);
149 CleanupStack::PopAndDestroy(const_cast<HBufC8*>(key1));
150 CleanupStack::PopAndDestroy(dh2);
151 CleanupStack::PopAndDestroy(dh1);
152 CleanupStack::PopAndDestroy(keyPair2);
153 CleanupStack::PopAndDestroy(keyPair1);