72
|
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 "tdsaprimegen.h"
|
|
20 |
#include "t_input.h"
|
|
21 |
#include <asymmetric.h>
|
|
22 |
#include <random.h>
|
|
23 |
#include <padding.h>
|
|
24 |
#include <bigint.h>
|
|
25 |
#include "tbrokenrandom.h"
|
|
26 |
|
|
27 |
CTestAction* CDSAPrimeGen::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
|
|
28 |
const TTestActionSpec& aTestActionSpec)
|
|
29 |
{
|
|
30 |
CTestAction* self = CDSAPrimeGen::NewLC(aFs, aConsole,
|
|
31 |
aOut, aTestActionSpec);
|
|
32 |
CleanupStack::Pop();
|
|
33 |
return self;
|
|
34 |
}
|
|
35 |
|
|
36 |
CTestAction* CDSAPrimeGen::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
|
|
37 |
const TTestActionSpec& aTestActionSpec)
|
|
38 |
{
|
|
39 |
CDSAPrimeGen* self = new(ELeave) CDSAPrimeGen(aFs, aConsole, aOut);
|
|
40 |
CleanupStack::PushL(self);
|
|
41 |
self->ConstructL(aTestActionSpec);
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
CDSAPrimeGen::~CDSAPrimeGen()
|
|
46 |
{
|
|
47 |
delete iBody;
|
|
48 |
iP.Close();
|
|
49 |
iQ.Close();
|
|
50 |
delete const_cast<CDSAPrimeCertificate*>(iPrimeCert);
|
|
51 |
}
|
|
52 |
|
|
53 |
CDSAPrimeGen::CDSAPrimeGen(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
|
54 |
: CTestAction(aConsole, aOut), iFs(aFs)
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
void CDSAPrimeGen::ConstructL(const TTestActionSpec& aTestActionSpec)
|
|
59 |
{
|
|
60 |
CTestAction::ConstructL(aTestActionSpec);
|
|
61 |
iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
|
|
62 |
iBody->Des().Copy(aTestActionSpec.iActionBody);
|
|
63 |
|
|
64 |
|
|
65 |
iKeyBits = Input::ParseIntElement(*iBody, _L8("<keybits>"), _L8("</keybits>"));
|
|
66 |
|
|
67 |
HBufC8* p = Input::ParseElementHexL(*iBody, _L8("<p>"));
|
|
68 |
CleanupStack::PushL(p);
|
|
69 |
iP = RInteger::NewL(*p);
|
|
70 |
CleanupStack::PopAndDestroy(p);
|
|
71 |
|
|
72 |
HBufC8* q = Input::ParseElementHexL(*iBody, _L8("<q>"));
|
|
73 |
CleanupStack::PushL(q);
|
|
74 |
iQ = RInteger::NewL(*q);
|
|
75 |
CleanupStack::PopAndDestroy(q);
|
|
76 |
|
|
77 |
TUint counter = Input::ParseIntElement(*iBody, _L8("<c>"), _L8("</c>"));
|
|
78 |
HBufC8* seed = Input::ParseElementHexL(*iBody, _L8("<seed>"));
|
|
79 |
CleanupStack::PushL(seed);
|
|
80 |
iPrimeCert = CDSAPrimeCertificate::NewL(*seed, counter);
|
|
81 |
CleanupStack::PopAndDestroy(seed);
|
|
82 |
}
|
|
83 |
|
|
84 |
void CDSAPrimeGen::DoPerformPrerequisite(TRequestStatus& aStatus)
|
|
85 |
{
|
|
86 |
TRequestStatus* status = &aStatus;
|
|
87 |
User::RequestComplete(status, KErrNone);
|
|
88 |
iActionState = CTestAction::EAction;
|
|
89 |
}
|
|
90 |
|
|
91 |
void CDSAPrimeGen::DoPerformPostrequisite(TRequestStatus& aStatus)
|
|
92 |
{
|
|
93 |
TRequestStatus* status = &aStatus;
|
|
94 |
|
|
95 |
iFinished = ETrue;
|
|
96 |
User::RequestComplete(status, KErrNone);
|
|
97 |
}
|
|
98 |
|
|
99 |
void CDSAPrimeGen::DoReportAction(void)
|
|
100 |
{
|
|
101 |
}
|
|
102 |
|
|
103 |
void CDSAPrimeGen::DoCheckResult(TInt)
|
|
104 |
{
|
|
105 |
if (iResult)
|
|
106 |
iConsole.Printf(_L("."));
|
|
107 |
else
|
|
108 |
iConsole.Printf(_L("X"));
|
|
109 |
}
|
|
110 |
|
|
111 |
void CDSAPrimeGen::PerformAction(TRequestStatus& aStatus)
|
|
112 |
{
|
|
113 |
__UHEAP_MARK;
|
|
114 |
TRequestStatus* status = &aStatus;
|
|
115 |
iResult = EFalse;
|
|
116 |
|
|
117 |
CRandomSetSource* rng = new(ELeave)CRandomSetSource(iPrimeCert->Seed());
|
|
118 |
SetThreadRandomLC(rng);
|
|
119 |
CDSAKeyPair* dsaPair = CDSAKeyPair::NewLC(iKeyBits);
|
|
120 |
|
|
121 |
//this is more or less just calling the prime generation routine over again
|
|
122 |
//but it does test if ValidatePrimesL and the NewLC generate the same primes
|
|
123 |
iResult = dsaPair->PublicKey().ValidatePrimesL(*iPrimeCert);
|
|
124 |
|
|
125 |
//we've already checked that the ValidatePrime + NewLC give same results
|
|
126 |
//this now checks against the vectors in the test scripts
|
|
127 |
if(iP != dsaPair->PublicKey().P() ||
|
|
128 |
iQ != dsaPair->PublicKey().Q() ||
|
|
129 |
iP != dsaPair->PrivateKey().P() ||
|
|
130 |
iQ != dsaPair->PrivateKey().Q() )
|
|
131 |
{
|
|
132 |
iResult = EFalse;
|
|
133 |
}
|
|
134 |
|
|
135 |
CleanupStack::PopAndDestroy(dsaPair);
|
|
136 |
CleanupStack::PopAndDestroy(); //SetThreadRandomLC
|
|
137 |
User::RequestComplete(status, KErrNone);
|
|
138 |
iActionState = CTestAction::EPostrequisite;
|
|
139 |
__UHEAP_MARKEND;
|
|
140 |
}
|
|
141 |
|