sl@0: /* sl@0: * Copyright (c) 2003-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 "tdhvector.h" sl@0: #include "t_input.h" sl@0: #include "performancetest.h" sl@0: sl@0: enum TActionMode {EMode1 = 1, EMode2 = 2, EMode3 = 3, EMode4 = 4}; sl@0: sl@0: CTestAction* CDHVector::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CDHVector::NewLC(aFs, aConsole, sl@0: aOut, aTestActionSpec); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CDHVector::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CDHVector* self = new(ELeave) CDHVector(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CDHVector::~CDHVector() sl@0: { sl@0: delete iN; sl@0: delete iG; sl@0: delete iX; sl@0: sl@0: if (iActionMode != EMode2) sl@0: { sl@0: iX1.Close(); sl@0: iX2.Close(); sl@0: } sl@0: sl@0: if (iActionMode == EMode3) sl@0: { sl@0: delete iNd; sl@0: delete iGd; sl@0: iN2.Close(); sl@0: iG2.Close(); sl@0: } sl@0: sl@0: if (iActionMode == EMode4) sl@0: { sl@0: iN1.Close(); sl@0: iG1.Close(); sl@0: iN2.Close(); sl@0: iG2.Close(); sl@0: } sl@0: } sl@0: sl@0: CDHVector::CDHVector(RFs& /*aFs*/, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CVectorTest(aConsole, aOut) sl@0: { sl@0: } sl@0: sl@0: void CDHVector::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CVectorTest::ConstructL(aTestActionSpec); sl@0: sl@0: iActionMode = Input::ParseIntElement(aTestActionSpec.iActionBody, _L8(""), _L8("")); sl@0: sl@0: iN = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: iG = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: sl@0: if(iActionMode == EMode2 || iActionMode == EMode4) sl@0: { sl@0: iX = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: } sl@0: else if(iActionMode == EMode3) sl@0: { sl@0: iNd = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: iGd = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("")); sl@0: } sl@0: } sl@0: sl@0: void CDHVector::DoPerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: iN1 = RInteger::NewL(*iN); sl@0: iN2 = RInteger::NewL(*iN); sl@0: iG1 = RInteger::NewL(*iG); sl@0: iG2 = RInteger::NewL(*iG); sl@0: sl@0: if(iActionMode == EMode2 || iActionMode == EMode4) sl@0: { sl@0: iX1 = RInteger::NewL(*iX); sl@0: iX2 = RInteger::NewL(*iX); sl@0: } sl@0: else if(iActionMode == EMode3) sl@0: { sl@0: iN3 = RInteger::NewL(*iNd); sl@0: iG3 = RInteger::NewL(*iGd); sl@0: } 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 CDHVector::DoPerformanceTestActionL() sl@0: { sl@0: iResult = ETrue; sl@0: __UHEAP_MARK; sl@0: sl@0: CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1); sl@0: CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2); sl@0: CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey()); sl@0: sl@0: TTimeIntervalMicroSeconds agreeTime(0); sl@0: TTime start, end; sl@0: TTimeIntervalSeconds diff(0); sl@0: const TTimeIntervalSeconds KIterationTime(iPerfTestIterations); sl@0: sl@0: TInt index = 0; sl@0: sl@0: start.UniversalTime(); sl@0: sl@0: while (diff < KIterationTime) sl@0: { sl@0: delete const_cast(dh1->AgreeL(keyPair2->PublicKey())); sl@0: end.UniversalTime(); sl@0: end.SecondsFrom(start, diff); sl@0: index++; sl@0: } sl@0: end.UniversalTime(); sl@0: sl@0: agreeTime = end.MicroSecondsFrom(start); sl@0: sl@0: CleanupStack::PopAndDestroy(dh1); sl@0: CleanupStack::PopAndDestroy(keyPair2); sl@0: CleanupStack::PopAndDestroy(keyPair1); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if (iResult) sl@0: { sl@0: TReal rate = I64REAL(agreeTime.Int64()) / index; sl@0: TReal agreetime = I64REAL(agreeTime.Int64()); sl@0: TBuf<256> buf; sl@0: _LIT(KEncryptTime, "\tKey Agreements\t%f"); sl@0: buf.Format(KEncryptTime, rate); sl@0: iOut.writeString(buf); sl@0: } sl@0: else sl@0: { sl@0: _LIT(KNoTimingInfo, "\tTest Failed! No benchmark data\n"); sl@0: iOut.writeString(KNoTimingInfo); sl@0: } sl@0: } sl@0: sl@0: void CDHVector::DoPerformActionL() sl@0: { sl@0: iResult = ETrue; sl@0: __UHEAP_MARK; sl@0: sl@0: switch (iActionMode) sl@0: { sl@0: // Test for successful keypair generation with N and G sl@0: case EMode1: sl@0: { sl@0: CDHKeyPair* keyPair1 = CDHKeyPair::NewL(iN1, iG1); sl@0: CleanupStack::PushL(keyPair1); sl@0: CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2); sl@0: CDH* dh1 = CDH::NewL(keyPair1->PrivateKey()); sl@0: CleanupStack::PushL(dh1); sl@0: CDH* dh2 = CDH::NewLC(keyPair2->PrivateKey()); sl@0: const HBufC8* key1 = dh1->AgreeL(keyPair2->PublicKey()); sl@0: CleanupStack::PushL(const_cast(key1)); sl@0: const HBufC8* key2 = dh2->AgreeL(keyPair1->PublicKey()); sl@0: CleanupStack::PushL(const_cast(key2)); sl@0: if(*key1 != *key2) sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: CleanupStack::PopAndDestroy(2, const_cast(key1)); sl@0: CleanupStack::PopAndDestroy(4, keyPair1); sl@0: } sl@0: break; sl@0: sl@0: // Test for successful keypair generation with N , G and X sl@0: case EMode2: sl@0: { sl@0: CDHKeyPair* keyPair1 = CDHKeyPair::NewL(iN1, iG1, iX1); sl@0: CleanupStack::PushL(keyPair1); sl@0: CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN2, iG2, iX2); sl@0: CDH* dh1 = CDH::NewL(keyPair1->PrivateKey()); sl@0: CleanupStack::PushL(dh1); sl@0: CDH* dh2 = CDH::NewLC(keyPair2->PrivateKey()); sl@0: const HBufC8* key1 = dh1->AgreeL(keyPair2->PublicKey()); sl@0: CleanupStack::PushL(const_cast(key1)); sl@0: const HBufC8* key2 = dh2->AgreeL(keyPair1->PublicKey()); sl@0: CleanupStack::PushL(const_cast(key2)); sl@0: if(*key1 != *key2) sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: CleanupStack::PopAndDestroy(2, const_cast(key1)); sl@0: CleanupStack::PopAndDestroy(4, keyPair1); sl@0: } sl@0: break; sl@0: sl@0: // Test for mis matching N & G key pair. sl@0: case EMode3: sl@0: { sl@0: CDHKeyPair* keyPair1 = CDHKeyPair::NewLC(iN1, iG1); sl@0: CDHKeyPair* keyPair2 = CDHKeyPair::NewLC(iN3, iG3); sl@0: CDH* dh1 = CDH::NewLC(keyPair1->PrivateKey()); sl@0: HBufC8* key1 = NULL; sl@0: TRAPD(err, key1 = dh1->AgreeL(keyPair2->PublicKey())); sl@0: if (err != KErrArgument) sl@0: { sl@0: iResult = EFalse; sl@0: delete key1; sl@0: } sl@0: CleanupStack::PopAndDestroy(3, keyPair1); sl@0: } sl@0: break; sl@0: sl@0: // Test for wromg values of G and X sl@0: case EMode4: sl@0: { sl@0: CDHKeyPair* keyPair1 = NULL; sl@0: TRAPD(err, keyPair1 = CDHKeyPair::NewLC(iN1, iG1, iX1)); sl@0: if (err != KErrArgument) sl@0: { sl@0: iResult = EFalse; sl@0: delete keyPair1; sl@0: } sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: