Update contrib.
2 * Copyright (c) 2002-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 "tmontgomeryvector.h"
22 #include "../../source/bigint/mont.h"
24 CTestAction* CMontgomeryVector::NewL(RFs& aFs, CConsoleBase& aConsole,
25 Output& aOut, const TTestActionSpec& aTestActionSpec)
27 CTestAction* self = CMontgomeryVector::NewLC(aFs, aConsole,
28 aOut, aTestActionSpec);
33 CTestAction* CMontgomeryVector::NewLC(RFs& aFs, CConsoleBase& aConsole,
34 Output& aOut, const TTestActionSpec& aTestActionSpec)
36 CMontgomeryVector* self = new(ELeave) CMontgomeryVector(aFs, aConsole, aOut);
37 CleanupStack::PushL(self);
38 self->ConstructL(aTestActionSpec);
42 CMontgomeryVector::~CMontgomeryVector()
51 CMontgomeryVector::CMontgomeryVector(RFs& aFs, CConsoleBase& aConsole,
52 Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
56 void CMontgomeryVector::ConstructL(const TTestActionSpec& aTestActionSpec)
58 CTestAction::ConstructL(aTestActionSpec);
59 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
60 iBody->Des().Copy(aTestActionSpec.iActionBody);
62 iA = Input::ParseElementHexL(*iBody, _L8("<a>"));
63 iB = Input::ParseElementHexL(*iBody, _L8("<b>"));
64 iModulus = Input::ParseElementHexL(*iBody, _L8("<modulus>"));
65 iAns = Input::ParseElementHexL(*iBody, _L8("<ans>"));
66 TPtrC8 op = Input::ParseElement(*iBody, _L8("<op>"));
67 if( op == _L8("multiply") )
71 else if( op == _L8("square") )
75 else if( op == _L8("reduce") )
79 else if( op == _L8("exponentiate") )
85 User::Panic(_L("tmontgomeryvector"), 1);
89 void CMontgomeryVector::DoPerformPrerequisite(TRequestStatus& aStatus)
91 TRequestStatus* status = &aStatus;
92 User::RequestComplete(status, KErrNone);
93 iActionState = CTestAction::EAction;
96 void CMontgomeryVector::DoPerformPostrequisite(TRequestStatus& aStatus)
98 TRequestStatus* status = &aStatus;
100 User::RequestComplete(status, KErrNone);
103 void CMontgomeryVector::DoReportAction(void)
107 void CMontgomeryVector::DoCheckResult(TInt)
111 void CMontgomeryVector::PerformAction(TRequestStatus& aStatus)
114 TRequestStatus* status = &aStatus;
117 RInteger a = RInteger::NewL(*iA);
118 CleanupStack::PushL(a);
119 RInteger b = RInteger::NewL(*iB);
120 CleanupStack::PushL(b);
121 RInteger modulus = RInteger::NewL(*iModulus);
122 CleanupStack::PushL(modulus);
123 RInteger ans = RInteger::NewL(*iAns);
124 CleanupStack::PushL(ans);
125 CMontgomeryStructure* mont = CMontgomeryStructure::NewL(modulus);
126 CleanupStack::PushL(mont);
127 //we don't own out at any point, it remains the propery of mont
128 const TInteger* out = 0;
132 out = &(mont->MultiplyL(a, b));
135 out = &(mont->SquareL(a));
138 out = &(mont->ReduceL(a));
141 out = &(mont->ExponentiateL(a, b));
144 User::Panic(_L("tbasicmathsvector"), 2);
152 CleanupStack::PopAndDestroy(mont);
153 CleanupStack::PopAndDestroy(4); //ans, modulus, b,a
155 User::RequestComplete(status, KErrNone);
156 iActionState = CTestAction::EPostrequisite;