crypto/weakcrypto/test/tasymmetric/trsasignfb.cpp
author hgs
Thu, 12 Aug 2010 21:07:10 +0530
changeset 90 8c545fea2798
parent 72 de46a57f75fb
permissions -rw-r--r--
201031_01
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     1
/*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     3
* All rights reserved.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     8
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
     9
* Initial Contributors:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    11
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    12
* Contributors:
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    13
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    14
* Description: 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    15
*
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    16
*/
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    17
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    18
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    19
#include "trsasignfb.h"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    20
#include "t_input.h"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    21
#include <asymmetric.h>
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    22
#include <padding.h>
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    23
#include <bigint.h>
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    24
#include "performancetest.h"
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    25
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    26
_LIT8(KInputStart, "<input>");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    27
_LIT8(KKeyBitsStart, "<keybits>");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    28
_LIT8(KKeyBitsEnd, "</keybits>");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    29
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    30
CRSASignFB::~CRSASignFB()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    31
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    32
	delete iBody;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    33
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    34
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    35
CRSASignFB::CRSASignFB(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    36
	: CTestAction(aConsole, aOut), iFs(aFs), iPerfTestIterations(100)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    37
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    38
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    39
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    40
CTestAction* CRSASignFB::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    41
	const TTestActionSpec& aTestActionSpec)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    42
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    43
	CTestAction* self = CRSASignFB::NewLC(aFs, aConsole,
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    44
		aOut, aTestActionSpec);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    45
	CleanupStack::Pop();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    46
	return self;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    47
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    48
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    49
CTestAction* CRSASignFB::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    50
	const TTestActionSpec& aTestActionSpec)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    51
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    52
	CRSASignFB* self = new(ELeave) CRSASignFB(aFs, aConsole, aOut);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    53
	CleanupStack::PushL(self);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    54
	self->ConstructL(aTestActionSpec);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    55
	return self;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    56
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    57
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    58
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    59
TRSAPrivateKeyType CRSASignFB::TypeOfCrypto()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    60
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    61
	return iCryptoType;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    62
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    63
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    64
void CRSASignFB::ConstructL(const TTestActionSpec& aTestActionSpec)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    65
{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    66
	CTestAction::ConstructL(aTestActionSpec);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    67
	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    68
	iBody->Des().Copy(aTestActionSpec.iActionBody);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    69
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    70
	if (CPerformance::PerformanceTester()->IsTestingPerformance())
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    71
	{//	Number of test iterations
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    72
		TPtrC8 itsPtr = Input::ParseElement(aTestActionSpec.iActionBody, KIterationsStart, KIterationsEnd);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    73
		if (itsPtr!=KNullDesC8)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    74
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    75
			TLex8 lex;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    76
			lex.Assign(itsPtr);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    77
			User::LeaveIfError(lex.Val(iPerfTestIterations));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    78
			if (iPerfTestIterations > KMaxIterations)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    79
				User::Panic(_L("AsymmetricPerformance.exe"), KErrArgument);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    80
			
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    81
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    82
		TPtrC8 cryptoPtr = Input::ParseElement(aTestActionSpec.iActionBody, KTypeOfCryptoStart, KTypeOfCryptoEnd);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    83
		if (cryptoPtr.CompareF(KRSAStandard) == 0)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    84
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    85
			iCryptoType = EStandard;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    86
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    87
		else if (cryptoPtr.CompareF(KRSAStandardCRT) == 0)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    88
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    89
			iCryptoType = EStandardCRT;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    90
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    91
		else
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    92
			{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    93
			User::Panic(_L("AsymmetricPerformance.exe"), KErrArgument);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    94
			}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    95
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    96
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    97
	TPtrC8 keyBitsPtr = Input::ParseElement(*iBody, KKeyBitsStart, KKeyBitsEnd); 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    98
	if (keyBitsPtr!=KNullDesC8)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
    99
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   100
		TLex8 lex;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   101
		lex.Assign(keyBitsPtr);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   102
		User::LeaveIfError(lex.Val(iKeyBits));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   103
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   104
}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   105
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   106
void CRSASignFB::DoPerformPrerequisite(TRequestStatus& aStatus)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   107
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   108
	TRequestStatus* status = &aStatus;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   109
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   110
	HBufC8* input = Input::ParseElementHexL(*iBody, KInputStart);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   111
	CleanupStack::PushL(input);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   112
	iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   113
	iSigInput->Update(*input);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   114
	iInput = iSigInput->Final().AllocL();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   115
	CleanupStack::PopAndDestroy(input);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   116
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   117
	User::RequestComplete(status, KErrNone);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   118
	iActionState = CTestAction::EAction;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   119
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   120
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   121
void CRSASignFB::DoPerformPostrequisite(TRequestStatus& aStatus)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   122
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   123
	TRequestStatus* status = &aStatus;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   124
	delete iInput;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   125
	delete iSigInput;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   126
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   127
	iFinished = ETrue;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   128
	User::RequestComplete(status, iActionResult);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   129
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   130
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   131
void CRSASignFB::DoReportAction(void)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   132
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   133
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   134
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   135
void CRSASignFB::DoCheckResult(TInt)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   136
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   137
	if (iResult)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   138
		iConsole.Printf(_L("."));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   139
	else
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   140
		iConsole.Printf(_L("X"));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   141
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   142
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   143
void CRSASignFB::Hex(HBufC8& aString)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   144
    {
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   145
    TPtr8 ptr=aString.Des();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   146
    if (aString.Length()%2)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   147
        {
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   148
        ptr.SetLength(0);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   149
        return;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   150
        }
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   151
    TInt i;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   152
    for (i=0;i<aString.Length();i+=2)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   153
        {
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   154
        TUint8 tmp;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   155
        tmp=(TUint8)(aString[i]-(aString[i]>'9'?('A'-10):'0'));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   156
        tmp*=16;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   157
        tmp|=(TUint8)(aString[i+1]-(aString[i+1]>'9'?('A'-10):'0'));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   158
        ptr[i/2]=tmp;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   159
        }
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   160
    ptr.SetLength(aString.Length()/2);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   161
    }
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   162
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   163
void CRSASignFB::PerformAction(TRequestStatus& aStatus)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   164
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   165
	TRequestStatus* status = &aStatus;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   166
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   167
	if (CPerformance::PerformanceTester()->IsTestingPerformance())
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   168
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   169
		iConsole.Printf(_L(">"));	//	Indicates start of test
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   170
		TRAP(iActionResult, DoPerformanceTestActionL());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   171
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   172
	else
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   173
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   174
		TRAP(iActionResult, DoPerformActionL());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   175
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   176
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   177
	if (iActionResult==KErrNoMemory)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   178
		User::Leave(iActionResult);	//	For OOM testing
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   179
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   180
	User::RequestComplete(status, iActionResult);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   181
	iActionState = CTestAction::EPostrequisite;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   182
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   183
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   184
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   185
void CRSASignFB::DoPerformanceTestActionL()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   186
{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   187
	__UHEAP_MARK;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   188
	iResult = EFalse;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   189
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   190
	TTimeIntervalMicroSeconds keyCreateTime(0);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   191
	TTimeIntervalMicroSeconds signTime(0);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   192
	TTimeIntervalMicroSeconds verifyTime(0);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   193
	TTime start, end;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   194
	TTimeIntervalSeconds diff(0);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   195
	const TTimeIntervalSeconds KIterationTime(iPerfTestIterations);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   196
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   197
	//	Time key pair creation
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   198
	CRSAKeyPair *rsaPair = NULL;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   199
	TUint noRSAPairs = 0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   200
	start.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   201
	while (diff < KIterationTime)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   202
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   203
       rsaPair = CRSAKeyPair::NewLC(iKeyBits, TypeOfCrypto());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   204
       CleanupStack::PopAndDestroy();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   205
       noRSAPairs++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   206
	   end.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   207
	   end.SecondsFrom(start, diff);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   208
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   209
	end.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   210
	keyCreateTime = end.MicroSecondsFrom(start);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   211
	TReal keycreatetime = I64REAL(keyCreateTime.Int64());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   212
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   213
	rsaPair=CRSAKeyPair::NewLC(iKeyBits, TypeOfCrypto()); // Create one keypair for operations
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   214
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   215
	CRSAPKCS1v15Signer* signer = CRSAPKCS1v15Signer::NewL(rsaPair->PrivateKey());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   216
	CleanupStack::PushL(signer);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   217
	CRSAPKCS1v15Verifier* verifier = CRSAPKCS1v15Verifier::NewL(rsaPair->PublicKey());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   218
	CleanupStack::PushL(verifier);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   219
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   220
	const CRSASignature  *testSig;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   221
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   222
	//	Time signing
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   223
	diff = 0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   224
	TInt noSignings = 0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   225
	start.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   226
	while (diff < KIterationTime)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   227
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   228
		testSig = signer->SignL(*iInput);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   229
		delete testSig;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   230
		noSignings++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   231
		end.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   232
		end.SecondsFrom(start, diff);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   233
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   234
	end.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   235
	signTime = end.MicroSecondsFrom(start);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   236
	TReal signtime = I64REAL(signTime.Int64());	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   237
	//	Time verification
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   238
	TInt noVerifies = 0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   239
	diff = 0;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   240
	testSig = signer->SignL(*iInput);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   241
	CleanupStack::PushL(const_cast<CRSASignature*>(testSig));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   242
	start.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   243
	while (diff < KIterationTime)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   244
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   245
		iResult = verifier->VerifyL(*iInput, *testSig);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   246
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   247
		// do as many verfies as possible 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   248
		if (!iResult)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   249
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   250
		   break;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   251
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   252
		noVerifies++;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   253
		end.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   254
		end.SecondsFrom(start, diff);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   255
	}	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   256
	end.UniversalTime();
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   257
	verifyTime = end.MicroSecondsFrom(start);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   258
    TReal verifytime = I64REAL(verifyTime.Int64());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   259
	CleanupStack::PopAndDestroy(4);	//	verifier,signer,testSig,rsaPairs
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   260
	__UHEAP_MARKEND;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   261
		 
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   262
	if (iResult)
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   263
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   264
		TBuf<256> buf;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   265
		TReal rate = I64REAL(keyCreateTime.Int64()) / noRSAPairs;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   266
		
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   267
		_LIT(KKeyCreateTime, "\n\tKeyCreate: %f us/key creation (no creations: %i in %f us)\r\n");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   268
 		buf.Format(KKeyCreateTime, rate, noRSAPairs, keycreatetime);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   269
		iOut.writeString(buf);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   270
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   271
		rate = I64REAL(signTime.Int64()) / noSignings;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   272
		_LIT(KSignTime, "\tSigning: %f us/signing (no signings: %i in %f us)\r\n");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   273
  		buf.Format(KSignTime, rate, noSignings, signtime);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   274
		iOut.writeString(buf);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   275
		
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   276
		rate = I64REAL(verifyTime.Int64()) / noVerifies;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   277
		_LIT(KVerifyTime, "\tVerifying: %f us/verify (no verfies: %i in %f us)\r\n");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   278
 		buf.Format(KVerifyTime, rate, noVerifies, verifytime);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   279
		iOut.writeString(buf);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   280
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   281
	else
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   282
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   283
		_LIT(KNoTimingInfo, "\tTest Failed! No benchmark data\n");
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   284
		iOut.writeString(KNoTimingInfo);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   285
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   286
}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   287
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   288
void CRSASignFB::DoPerformActionL()
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   289
	{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   290
	__UHEAP_MARK;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   291
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   292
	iResult = EFalse;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   293
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   294
	CRSAKeyPair* rsaPair = CRSAKeyPair::NewLC(512, TypeOfCrypto());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   295
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   296
	CRSAPKCS1v15Signer* signer = CRSAPKCS1v15Signer::NewL(rsaPair->PrivateKey());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   297
	CleanupStack::PushL(signer);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   298
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   299
	CRSAPKCS1v15Verifier* verifier = CRSAPKCS1v15Verifier::NewL(rsaPair->PublicKey());
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   300
	CleanupStack::PushL(verifier);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   301
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   302
	const CRSASignature* signature = signer->SignL(*iInput);
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   303
	CleanupStack::PushL(const_cast<CRSASignature*>(signature));
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   304
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   305
	if(verifier->VerifyL(*iInput, *signature))
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   306
		{
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   307
		iResult = ETrue;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   308
		}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   309
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   310
	CleanupStack::PopAndDestroy(4, rsaPair); //signature, verifier, signer, rsaPair
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   311
	
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   312
	__UHEAP_MARKEND;
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   313
	}
de46a57f75fb 201023_02
hgs
parents:
diff changeset
   314