|
1 /* |
|
2 * Copyright (c) 1998-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 "tdsavector.h" |
|
20 #include "tvectorutils.h" |
|
21 #include "t_input.h" |
|
22 #include <bigint.h> |
|
23 #include "tbrokenrandom.h" |
|
24 |
|
25 const TInt KSha1HashLength = 20; |
|
26 //////////////////////////////////////////////////////////////////////////////// |
|
27 // CDSASignVector |
|
28 //////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
30 CTestAction* CDSASignVector::NewL(RFs& aFs, |
|
31 CConsoleBase& aConsole, |
|
32 Output& aOut, |
|
33 const TTestActionSpec& aTestActionSpec) |
|
34 { |
|
35 CTestAction* self = CDSASignVector::NewLC(aFs, aConsole, aOut, aTestActionSpec); |
|
36 CleanupStack::Pop(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CTestAction* CDSASignVector::NewLC(RFs& aFs, |
|
41 CConsoleBase& aConsole, |
|
42 Output& aOut, |
|
43 const TTestActionSpec& aTestActionSpec) |
|
44 { |
|
45 CDSASignVector* self = new(ELeave) CDSASignVector(aFs, aConsole, aOut); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aTestActionSpec); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CDSASignVector::~CDSASignVector() |
|
52 { |
|
53 delete iPrivKey; |
|
54 delete iSignature; |
|
55 delete iK; |
|
56 delete iSigInput; |
|
57 } |
|
58 |
|
59 CDSASignVector::CDSASignVector(RFs& /*aFs*/, |
|
60 CConsoleBase& aConsole, |
|
61 Output& aOut) |
|
62 : CVectorTest(aConsole, aOut) |
|
63 { |
|
64 } |
|
65 |
|
66 void CDSASignVector::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
67 { |
|
68 CVectorTest::ConstructL(aTestActionSpec); |
|
69 |
|
70 iPrivKey = VectorUtils::ReadDSAPrivateKeyL(aTestActionSpec.iActionBody); |
|
71 |
|
72 iMessage.Set(Input::ParseElement(aTestActionSpec.iActionBody, _L8("<m>"))); |
|
73 iK = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<k>")); |
|
74 |
|
75 iSignature = VectorUtils::ReadDSASignatureL(aTestActionSpec.iActionBody); |
|
76 iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1); |
|
77 iSigInput->Update(iMessage); |
|
78 } |
|
79 |
|
80 void CDSASignVector::DoPerformActionL() |
|
81 { |
|
82 __UHEAP_MARK; |
|
83 |
|
84 CRandomSetSource* random = new(ELeave)CRandomSetSource(*iK); |
|
85 SetThreadRandomLC(random); |
|
86 |
|
87 CDSASigner* signer = CDSASigner::NewLC(*iPrivKey); |
|
88 const CDSASignature* testSig = signer->SignL(iSigInput->Final()); |
|
89 iResult = (*testSig == *iSignature); |
|
90 delete testSig; |
|
91 CleanupStack::PopAndDestroy(signer); |
|
92 |
|
93 CDSASigner* signer1 = CDSASigner::NewL(*iPrivKey); |
|
94 CleanupStack::PushL(signer1); |
|
95 if (signer1->MaxInputLength() != KSha1HashLength) |
|
96 { |
|
97 iResult = EFalse; |
|
98 } |
|
99 CleanupStack::PopAndDestroy(signer1); |
|
100 CleanupStack::PopAndDestroy(); //SetThreadRandomLC |
|
101 |
|
102 __UHEAP_MARKEND; |
|
103 } |
|
104 |
|
105 void CDSASignVector::DoPerformanceTestActionL() |
|
106 { |
|
107 iResult = ETrue; |
|
108 } |
|
109 |
|
110 void CDSASignVector::DoCheckResult(TInt /*aError*/) |
|
111 { |
|
112 // If using Keith's fixed up testframework for testing failures, iResult will |
|
113 // have already been corrected for a deliberate fail result. |
|
114 // If not using Keith's testframework iResult is still a fail result at this |
|
115 // point, so now's the time to adjust for deliberate failure. |
|
116 |
|
117 if (!iResult) |
|
118 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult); |
|
119 |
|
120 if( iResult == EFalse ) |
|
121 { |
|
122 iConsole.Printf(_L("X")); |
|
123 } |
|
124 else |
|
125 { |
|
126 iConsole.Printf(_L(".")); |
|
127 } |
|
128 } |
|
129 |
|
130 //////////////////////////////////////////////////////////////////////////////// |
|
131 // CDSAVerifyVector |
|
132 //////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
134 CTestAction* CDSAVerifyVector::NewL(RFs& aFs, |
|
135 CConsoleBase& aConsole, |
|
136 Output& aOut, |
|
137 const TTestActionSpec& aTestActionSpec) |
|
138 { |
|
139 CTestAction* self = CDSAVerifyVector::NewLC(aFs, aConsole, aOut, aTestActionSpec); |
|
140 CleanupStack::Pop(); |
|
141 return self; |
|
142 } |
|
143 |
|
144 CTestAction* CDSAVerifyVector::NewLC(RFs& aFs, |
|
145 CConsoleBase& aConsole, |
|
146 Output& aOut, |
|
147 const TTestActionSpec& aTestActionSpec) |
|
148 { |
|
149 CDSAVerifyVector* self = new(ELeave) CDSAVerifyVector(aFs, aConsole, aOut); |
|
150 CleanupStack::PushL(self); |
|
151 self->ConstructL(aTestActionSpec); |
|
152 return self; |
|
153 } |
|
154 |
|
155 CDSAVerifyVector::~CDSAVerifyVector() |
|
156 { |
|
157 delete iPubKey; |
|
158 delete iSignature; |
|
159 delete iMessage; |
|
160 delete iSigInput; |
|
161 } |
|
162 |
|
163 CDSAVerifyVector::CDSAVerifyVector(RFs& /*aFs*/, |
|
164 CConsoleBase& aConsole, |
|
165 Output& aOut) |
|
166 : CVectorTest(aConsole, aOut) |
|
167 { |
|
168 } |
|
169 |
|
170 void CDSAVerifyVector::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
171 { |
|
172 CVectorTest::ConstructL(aTestActionSpec); |
|
173 |
|
174 iPubKey = VectorUtils::ReadDSAPublicKeyL(aTestActionSpec.iActionBody); |
|
175 |
|
176 TPtrC8 message(Input::ParseElement(aTestActionSpec.iActionBody, _L8("<m>"))); |
|
177 if (message.Length()==0) |
|
178 iMessage = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<hexm>")); |
|
179 else |
|
180 iMessage = message.AllocL(); |
|
181 |
|
182 iSignature = VectorUtils::ReadDSASignatureL(aTestActionSpec.iActionBody); |
|
183 iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1); |
|
184 iSigInput->Update(*iMessage); |
|
185 } |
|
186 |
|
187 void CDSAVerifyVector::DoPerformActionL() |
|
188 { |
|
189 __UHEAP_MARK; |
|
190 |
|
191 CDSAVerifier* verifier = CDSAVerifier::NewLC(*iPubKey); |
|
192 iResult = verifier->VerifyL(iSigInput->Final(), *iSignature); |
|
193 |
|
194 CleanupStack::PopAndDestroy(verifier); |
|
195 __UHEAP_MARKEND; |
|
196 } |
|
197 |
|
198 void CDSAVerifyVector::DoPerformanceTestActionL() |
|
199 { |
|
200 iResult = ETrue; |
|
201 } |
|
202 |
|
203 void CDSAVerifyVector::DoCheckResult(TInt /*aError*/) |
|
204 { |
|
205 // If using Keith's fixed up testframework for testing failures, iResult will |
|
206 // have already been corrected for a deliberate fail result. |
|
207 // If not using Keith's testframework iResult is still a fail result at this |
|
208 // point, so now's the time to adjust for deliberate failure. |
|
209 |
|
210 if (!iResult) |
|
211 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult); |
|
212 |
|
213 if( iResult == EFalse ) |
|
214 { |
|
215 iConsole.Printf(_L("X")); |
|
216 } |
|
217 else |
|
218 { |
|
219 iConsole.Printf(_L(".")); |
|
220 } |
|
221 } |