72
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
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".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "tdhvector.h"
|
|
20 |
#include <t_input.h>
|
|
21 |
#include "performancetest.h"
|
|
22 |
|
|
23 |
CTestAction* CDHVector::NewL(RFs& aFs,
|
|
24 |
CConsoleBase& aConsole,
|
|
25 |
Output& aOut,
|
|
26 |
const TTestActionSpec& aTestActionSpec)
|
|
27 |
{
|
|
28 |
CTestAction* self = CDHVector::NewLC(aFs, aConsole,
|
|
29 |
aOut, aTestActionSpec);
|
|
30 |
CleanupStack::Pop();
|
|
31 |
return self;
|
|
32 |
}
|
|
33 |
|
|
34 |
CTestAction* CDHVector::NewLC(RFs& aFs,
|
|
35 |
CConsoleBase& aConsole,
|
|
36 |
Output& aOut,
|
|
37 |
const TTestActionSpec& aTestActionSpec)
|
|
38 |
{
|
|
39 |
CDHVector* self = new(ELeave) CDHVector(aFs, aConsole, aOut);
|
|
40 |
CleanupStack::PushL(self);
|
|
41 |
self->ConstructL(aTestActionSpec);
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
CDHVector::~CDHVector()
|
|
46 |
{
|
|
47 |
delete iN;
|
|
48 |
delete iG;
|
|
49 |
}
|
|
50 |
|
|
51 |
CDHVector::CDHVector(RFs& /*aFs*/,
|
|
52 |
CConsoleBase& aConsole,
|
|
53 |
Output& aOut)
|
|
54 |
: CVectorTest(aConsole, aOut)
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
void CDHVector::ConstructL(const TTestActionSpec& aTestActionSpec)
|
|
59 |
{
|
|
60 |
CVectorTest::ConstructL(aTestActionSpec);
|
|
61 |
|
|
62 |
iN = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<n>"));
|
|
63 |
iG = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<g>"));
|
|
64 |
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
void CDHVector::DoPerformPrerequisite(TRequestStatus& aStatus)
|
|
69 |
{
|
|
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;
|
|
77 |
}
|
|
78 |
|
|
79 |
void CDHVector::DoPerformanceTestActionL()
|
|
80 |
{
|
|
81 |
iResult = ETrue;
|
|
82 |
__UHEAP_MARK;
|
|
83 |
|
|
84 |
CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1);
|
|
85 |
CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2);
|
|
86 |
CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey());
|
|
87 |
|
|
88 |
TTimeIntervalMicroSeconds agreeTime(0);
|
|
89 |
TTime start, end;
|
|
90 |
TTimeIntervalSeconds diff(0);
|
|
91 |
const TTimeIntervalSeconds KIterationTime(iPerfTestIterations);
|
|
92 |
|
|
93 |
TInt index = 0;
|
|
94 |
|
|
95 |
start.UniversalTime();
|
|
96 |
|
|
97 |
while (diff < KIterationTime)
|
|
98 |
{
|
|
99 |
delete const_cast<HBufC8*>(dh1->AgreeL(keyPair2->PublicKey()));
|
|
100 |
end.UniversalTime();
|
|
101 |
end.SecondsFrom(start, diff);
|
|
102 |
index++;
|
|
103 |
}
|
|
104 |
end.UniversalTime();
|
|
105 |
|
|
106 |
agreeTime = end.MicroSecondsFrom(start);
|
|
107 |
|
|
108 |
CleanupStack::PopAndDestroy(dh1);
|
|
109 |
CleanupStack::PopAndDestroy(keyPair2);
|
|
110 |
CleanupStack::PopAndDestroy(keyPair1);
|
|
111 |
|
|
112 |
__UHEAP_MARKEND;
|
|
113 |
|
|
114 |
if (iResult)
|
|
115 |
{
|
|
116 |
TReal rate = I64REAL(agreeTime.Int64()) / index;
|
|
117 |
TReal agreetime = I64REAL(agreeTime.Int64());
|
|
118 |
TBuf<256> buf;
|
|
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);
|
|
122 |
}
|
|
123 |
else
|
|
124 |
{
|
|
125 |
_LIT(KNoTimingInfo, "\tTest Failed! No benchmark data\n");
|
|
126 |
iOut.writeString(KNoTimingInfo);
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
void CDHVector::DoPerformActionL()
|
|
131 |
{
|
|
132 |
iResult = ETrue;
|
|
133 |
__UHEAP_MARK;
|
|
134 |
|
|
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());
|
|
142 |
|
|
143 |
if(*key1 != *key2)
|
|
144 |
{
|
|
145 |
iResult = EFalse;
|
|
146 |
}
|
|
147 |
|
|
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);
|
|
154 |
|
|
155 |
__UHEAP_MARKEND;
|
|
156 |
}
|
|
157 |
|
|
158 |
|