sl@0: /* sl@0: * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "tmontgomeryvector.h" sl@0: #include "t_input.h" sl@0: #include sl@0: #include "../../source/bigint/mont.h" sl@0: sl@0: CTestAction* CMontgomeryVector::NewL(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut, const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CMontgomeryVector::NewLC(aFs, aConsole, sl@0: aOut, aTestActionSpec); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CMontgomeryVector::NewLC(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut, const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CMontgomeryVector* self = new(ELeave) CMontgomeryVector(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CMontgomeryVector::~CMontgomeryVector() sl@0: { sl@0: delete iBody; sl@0: delete iA; sl@0: delete iB; sl@0: delete iModulus; sl@0: delete iAns; sl@0: } sl@0: sl@0: CMontgomeryVector::CMontgomeryVector(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs) sl@0: { sl@0: } sl@0: sl@0: void CMontgomeryVector::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction::ConstructL(aTestActionSpec); sl@0: iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); sl@0: iBody->Des().Copy(aTestActionSpec.iActionBody); sl@0: sl@0: iA = Input::ParseElementHexL(*iBody, _L8("")); sl@0: iB = Input::ParseElementHexL(*iBody, _L8("")); sl@0: iModulus = Input::ParseElementHexL(*iBody, _L8("")); sl@0: iAns = Input::ParseElementHexL(*iBody, _L8("")); sl@0: TPtrC8 op = Input::ParseElement(*iBody, _L8("")); sl@0: if( op == _L8("multiply") ) sl@0: { sl@0: iOp = EMultiply; sl@0: } sl@0: else if( op == _L8("square") ) sl@0: { sl@0: iOp = ESquare; sl@0: } sl@0: else if( op == _L8("reduce") ) sl@0: { sl@0: iOp = EReduce; sl@0: } sl@0: else if( op == _L8("exponentiate") ) sl@0: { sl@0: iOp = EExponentiate; sl@0: } sl@0: else sl@0: { sl@0: User::Panic(_L("tmontgomeryvector"), 1); sl@0: } sl@0: } sl@0: sl@0: void CMontgomeryVector::DoPerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: iActionState = CTestAction::EAction; sl@0: } sl@0: sl@0: void CMontgomeryVector::DoPerformPostrequisite(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: iFinished = ETrue; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: void CMontgomeryVector::DoReportAction(void) sl@0: { sl@0: } sl@0: sl@0: void CMontgomeryVector::DoCheckResult(TInt) sl@0: { sl@0: } sl@0: sl@0: void CMontgomeryVector::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: __UHEAP_MARK; sl@0: TRequestStatus* status = &aStatus; sl@0: iResult = ETrue; sl@0: sl@0: RInteger a = RInteger::NewL(*iA); sl@0: CleanupStack::PushL(a); sl@0: RInteger b = RInteger::NewL(*iB); sl@0: CleanupStack::PushL(b); sl@0: RInteger modulus = RInteger::NewL(*iModulus); sl@0: CleanupStack::PushL(modulus); sl@0: RInteger ans = RInteger::NewL(*iAns); sl@0: CleanupStack::PushL(ans); sl@0: CMontgomeryStructure* mont = CMontgomeryStructure::NewL(modulus); sl@0: CleanupStack::PushL(mont); sl@0: //we don't own out at any point, it remains the propery of mont sl@0: const TInteger* out = 0; sl@0: switch(iOp) sl@0: { sl@0: case EMultiply: sl@0: out = &(mont->MultiplyL(a, b)); sl@0: break; sl@0: case ESquare: sl@0: out = &(mont->SquareL(a)); sl@0: break; sl@0: case EReduce: sl@0: out = &(mont->ReduceL(a)); sl@0: break; sl@0: case EExponentiate: sl@0: out = &(mont->ExponentiateL(a, b)); sl@0: break; sl@0: default: sl@0: User::Panic(_L("tbasicmathsvector"), 2); sl@0: break; sl@0: } sl@0: sl@0: if( *out != ans ) sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: CleanupStack::PopAndDestroy(mont); sl@0: CleanupStack::PopAndDestroy(4); //ans, modulus, b,a sl@0: sl@0: User::RequestComplete(status, KErrNone); sl@0: iActionState = CTestAction::EPostrequisite; sl@0: __UHEAP_MARKEND; sl@0: } sl@0: