os/security/crypto/weakcrypto/test/tsymmetric/tperformancetest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "tperformancetest.h"
sl@0
    20
#include "symmetric.h"
sl@0
    21
#include <t_output.h>
sl@0
    22
sl@0
    23
#ifndef _DEBUG
sl@0
    24
_LIT(KPerfEFormat, "\tPerformance (encryption) : %f us/iteration (%i iterations in %iL us)\r\n");
sl@0
    25
_LIT(KPerfDFormat, "\tPerformance (decryption) : %f us/iteration (%i iterations in %iL us)\r\n");
sl@0
    26
_LIT(KTotalFormat, "\tPerformance (total) : %f us/iteration (%i iterations in %iL us)\r\n");
sl@0
    27
_LIT(KPerfThroughput, "\tThroughput (total): %f MB/s\r\n");
sl@0
    28
_LIT(KPerfThroughputAfterSetup, "\tThroughput after setup: %f MB/s\r\n");
sl@0
    29
_LIT(KPerfEncryptorCreate, "\tPerformance (encryptor create) : %f us/iteration (%i iterations in %iL us)\r\n");
sl@0
    30
_LIT(KPerfDecryptorCreate, "\tPerformance (decryptor create) : %f us/iteration (%i iterations in %iL us)\r\n");
sl@0
    31
_LIT(KDataSize,"\tData input size : %i B\r\n");
sl@0
    32
#endif
sl@0
    33
sl@0
    34
CTestAction* CPerformanceTest::NewL(RFs& aFs,
sl@0
    35
									   CConsoleBase& aConsole,
sl@0
    36
									   Output& aOut, 
sl@0
    37
									   const TTestActionSpec& aTestActionSpec)
sl@0
    38
	{
sl@0
    39
	CTestAction* self = CPerformanceTest::NewLC(aFs, aConsole,
sl@0
    40
		aOut, aTestActionSpec);
sl@0
    41
	CleanupStack::Pop();
sl@0
    42
	return self;
sl@0
    43
	}
sl@0
    44
sl@0
    45
CTestAction* CPerformanceTest::NewLC(RFs& aFs,
sl@0
    46
										CConsoleBase& aConsole,
sl@0
    47
										Output& aOut, 
sl@0
    48
										const TTestActionSpec& aTestActionSpec)
sl@0
    49
	{
sl@0
    50
	CPerformanceTest* self = new(ELeave) CPerformanceTest(aFs, aConsole, aOut);
sl@0
    51
	CleanupStack::PushL(self);
sl@0
    52
	self->ConstructL(aTestActionSpec);
sl@0
    53
	return self;
sl@0
    54
	}
sl@0
    55
sl@0
    56
CPerformanceTest::~CPerformanceTest()
sl@0
    57
{
sl@0
    58
	delete iEncryptor;
sl@0
    59
	delete iDecryptor;
sl@0
    60
}
sl@0
    61
sl@0
    62
CPerformanceTest::CPerformanceTest(RFs& aFs, 
sl@0
    63
								 CConsoleBase& aConsole,
sl@0
    64
								 Output& aOut)
sl@0
    65
								 
sl@0
    66
: CCryptoTestAction(aFs, aConsole, aOut)
sl@0
    67
{}
sl@0
    68
sl@0
    69
void CPerformanceTest::DoPerformPrerequisiteL()
sl@0
    70
{
sl@0
    71
#ifndef _DEBUG
sl@0
    72
	TInt err = KErrNone;
sl@0
    73
	TInt pos = 0;
sl@0
    74
	TPtrC8 vector = Input::ParseElement(*iBody, KVectorStart, KVectorEnd, pos, err);
sl@0
    75
sl@0
    76
	DoInputParseL(vector);
sl@0
    77
sl@0
    78
	CBlockTransformation* encryptor = 0;
sl@0
    79
	CBlockTransformation* decryptor = 0;
sl@0
    80
sl@0
    81
	switch (iCipherType)
sl@0
    82
	{
sl@0
    83
		case (EDESECB):
sl@0
    84
		{//	Time the length of time it takes to set up the key schedule,
sl@0
    85
		//	save it and add to encrypt time, to be consistent with old API
sl@0
    86
		//	for comparison purposes (old API does both set up and encrypt/decrypt
sl@0
    87
		//	in a single operation).
sl@0
    88
			TTime startTime;
sl@0
    89
			TTime endTime;
sl@0
    90
			TTimeIntervalSeconds diff(0);
sl@0
    91
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
    92
			
sl@0
    93
			encryptor = CDESEncryptor::NewL(iKey->Des());
sl@0
    94
			iEncryptIterations = 0;
sl@0
    95
			startTime.UniversalTime();	
sl@0
    96
			while (diff < iterationTime)
sl@0
    97
				{
sl@0
    98
				encryptor->Reset();
sl@0
    99
				iEncryptIterations++;
sl@0
   100
				endTime.UniversalTime();
sl@0
   101
				endTime.SecondsFrom(startTime, diff);
sl@0
   102
				}
sl@0
   103
			endTime.UniversalTime();
sl@0
   104
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   105
sl@0
   106
			delete encryptor;
sl@0
   107
			
sl@0
   108
			decryptor = CDESDecryptor::NewL(iKey->Des());
sl@0
   109
			
sl@0
   110
			diff = 0;
sl@0
   111
			iDecryptIterations = 0;
sl@0
   112
			startTime.UniversalTime();	
sl@0
   113
			while (diff < iterationTime)
sl@0
   114
				{
sl@0
   115
				decryptor->Reset();
sl@0
   116
				iDecryptIterations++;
sl@0
   117
				endTime.UniversalTime();
sl@0
   118
				endTime.SecondsFrom(startTime, diff);
sl@0
   119
				}
sl@0
   120
			endTime.UniversalTime();
sl@0
   121
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   122
sl@0
   123
			delete decryptor;
sl@0
   124
sl@0
   125
			encryptor = CDESEncryptor::NewLC(iKey->Des());
sl@0
   126
			decryptor = CDESDecryptor::NewL(iKey->Des());
sl@0
   127
			CleanupStack::Pop(encryptor);
sl@0
   128
		}
sl@0
   129
		break;
sl@0
   130
		case(EDESCBC):
sl@0
   131
		{
sl@0
   132
			CBlockTransformation* desEncryptor = NULL;
sl@0
   133
			CBlockTransformation* desDecryptor = NULL;
sl@0
   134
sl@0
   135
			desEncryptor = CDESEncryptor::NewLC(iKey->Des());								
sl@0
   136
			encryptor = CModeCBCEncryptor::NewL(desEncryptor, iIV->Des());				
sl@0
   137
			
sl@0
   138
			TTime startTime;
sl@0
   139
			TTime endTime;
sl@0
   140
			TTimeIntervalSeconds diff(0);
sl@0
   141
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   142
sl@0
   143
			iEncryptIterations = 0;
sl@0
   144
			startTime.UniversalTime();
sl@0
   145
			while (diff < iterationTime)
sl@0
   146
				{
sl@0
   147
				iEncryptIterations++;
sl@0
   148
				encryptor->Reset();
sl@0
   149
				endTime.UniversalTime();
sl@0
   150
				endTime.SecondsFrom(startTime, diff);
sl@0
   151
				}
sl@0
   152
			endTime.UniversalTime();
sl@0
   153
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   154
sl@0
   155
			CleanupStack::Pop(1);
sl@0
   156
			delete encryptor;
sl@0
   157
sl@0
   158
			desDecryptor = CDESDecryptor::NewLC(iKey->Des());
sl@0
   159
			decryptor = CModeCBCDecryptor::NewL(desDecryptor, iIV->Des());
sl@0
   160
			
sl@0
   161
			diff = 0;
sl@0
   162
			iDecryptIterations = 0;
sl@0
   163
			startTime.UniversalTime();
sl@0
   164
			while (diff < iterationTime)
sl@0
   165
				{
sl@0
   166
				decryptor->Reset();
sl@0
   167
				iDecryptIterations++;
sl@0
   168
				endTime.UniversalTime();
sl@0
   169
				endTime.SecondsFrom(startTime, diff);
sl@0
   170
				}
sl@0
   171
			endTime.UniversalTime();
sl@0
   172
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   173
sl@0
   174
			CleanupStack::Pop(1);
sl@0
   175
			delete decryptor;				
sl@0
   176
sl@0
   177
			desEncryptor = CDESEncryptor::NewLC(iKey->Des());
sl@0
   178
			desDecryptor = CDESDecryptor::NewLC(iKey->Des());
sl@0
   179
			
sl@0
   180
			encryptor = CModeCBCEncryptor::NewL(desEncryptor, iIV->Des());
sl@0
   181
			CleanupStack::PushL(encryptor);
sl@0
   182
			decryptor = CModeCBCDecryptor::NewL(desDecryptor, iIV->Des());					
sl@0
   183
			CleanupStack::Pop(3);
sl@0
   184
		}
sl@0
   185
		break;
sl@0
   186
		case (E3DESECB):
sl@0
   187
		{
sl@0
   188
			encryptor = C3DESEncryptor::NewL(iKey->Des());
sl@0
   189
			TTime startTime;
sl@0
   190
			TTime endTime;
sl@0
   191
			TTimeIntervalSeconds diff(0);
sl@0
   192
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   193
sl@0
   194
			iEncryptIterations = 0;
sl@0
   195
			startTime.UniversalTime();	
sl@0
   196
			while (diff < iterationTime)
sl@0
   197
				{
sl@0
   198
				iEncryptIterations++;
sl@0
   199
				encryptor->Reset();
sl@0
   200
				endTime.UniversalTime();
sl@0
   201
				endTime.SecondsFrom(startTime, diff);
sl@0
   202
				}
sl@0
   203
			endTime.UniversalTime();
sl@0
   204
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   205
sl@0
   206
			delete encryptor;
sl@0
   207
sl@0
   208
			diff = 0;
sl@0
   209
			iDecryptIterations = 0;
sl@0
   210
			decryptor = C3DESDecryptor::NewL(iKey->Des());
sl@0
   211
			startTime.UniversalTime();	
sl@0
   212
			while (diff < iterationTime)
sl@0
   213
				{
sl@0
   214
				decryptor->Reset();
sl@0
   215
				iDecryptIterations++;
sl@0
   216
				endTime.UniversalTime();
sl@0
   217
				endTime.SecondsFrom(startTime, diff);
sl@0
   218
				}
sl@0
   219
			endTime.UniversalTime();
sl@0
   220
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   221
			delete decryptor;
sl@0
   222
sl@0
   223
			encryptor = C3DESEncryptor::NewLC(iKey->Des());
sl@0
   224
			decryptor = C3DESDecryptor::NewL(iKey->Des());
sl@0
   225
			CleanupStack::Pop(encryptor);
sl@0
   226
		}
sl@0
   227
		break;
sl@0
   228
		case (E3DESCBC):
sl@0
   229
		{
sl@0
   230
			CBlockTransformation* the3DESencryptor = NULL;
sl@0
   231
			CBlockTransformation* the3DESdecryptor = NULL;
sl@0
   232
sl@0
   233
			the3DESencryptor = C3DESEncryptor::NewLC(iKey->Des());
sl@0
   234
			encryptor = CModeCBCEncryptor::NewL(the3DESencryptor, iIV->Des());
sl@0
   235
sl@0
   236
			TTime startTime;
sl@0
   237
			TTime endTime;
sl@0
   238
			TTimeIntervalSeconds diff(0);
sl@0
   239
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   240
sl@0
   241
			iEncryptIterations = 0;
sl@0
   242
			startTime.UniversalTime();	
sl@0
   243
			while (diff < iterationTime)
sl@0
   244
				{
sl@0
   245
				iEncryptIterations++;
sl@0
   246
				encryptor->Reset();
sl@0
   247
				endTime.UniversalTime();
sl@0
   248
				endTime.SecondsFrom(startTime, diff);
sl@0
   249
				}
sl@0
   250
			endTime.UniversalTime();
sl@0
   251
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   252
sl@0
   253
			CleanupStack::Pop(1);
sl@0
   254
			delete encryptor;				
sl@0
   255
sl@0
   256
			the3DESdecryptor = C3DESDecryptor::NewLC(iKey->Des());
sl@0
   257
			decryptor = CModeCBCDecryptor::NewL(the3DESdecryptor, iIV->Des());		
sl@0
   258
sl@0
   259
			diff = 0;
sl@0
   260
			iDecryptIterations = 0;
sl@0
   261
			startTime.UniversalTime();	
sl@0
   262
			while (diff < iterationTime)
sl@0
   263
				{
sl@0
   264
				decryptor->Reset();
sl@0
   265
				iDecryptIterations++;
sl@0
   266
				endTime.UniversalTime();
sl@0
   267
				endTime.SecondsFrom(startTime, diff);
sl@0
   268
				}
sl@0
   269
			endTime.UniversalTime();
sl@0
   270
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   271
			CleanupStack::Pop(1);
sl@0
   272
			delete decryptor;
sl@0
   273
sl@0
   274
			the3DESencryptor = C3DESEncryptor::NewLC(iKey->Des());
sl@0
   275
			the3DESdecryptor = C3DESDecryptor::NewLC(iKey->Des());
sl@0
   276
			
sl@0
   277
			encryptor = CModeCBCEncryptor::NewL(the3DESencryptor, iIV->Des());
sl@0
   278
			CleanupStack::PushL(encryptor);
sl@0
   279
			decryptor = CModeCBCDecryptor::NewL(the3DESdecryptor, iIV->Des());		
sl@0
   280
			CleanupStack::Pop(3);
sl@0
   281
		}
sl@0
   282
		break;
sl@0
   283
		case (EAESECB):
sl@0
   284
		{
sl@0
   285
			TTime startTime;
sl@0
   286
			TTime endTime;
sl@0
   287
			TTimeIntervalSeconds diff(0);
sl@0
   288
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   289
sl@0
   290
			iEncryptIterations = 0;
sl@0
   291
			encryptor = CAESEncryptor::NewL(iKey->Des());
sl@0
   292
			startTime.UniversalTime();
sl@0
   293
			while (diff < iterationTime)
sl@0
   294
				{
sl@0
   295
				iEncryptIterations++;
sl@0
   296
				encryptor->Reset();
sl@0
   297
				endTime.UniversalTime();
sl@0
   298
				endTime.SecondsFrom(startTime, diff);
sl@0
   299
				}
sl@0
   300
			endTime.UniversalTime();
sl@0
   301
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   302
			delete encryptor;
sl@0
   303
sl@0
   304
			diff = 0;
sl@0
   305
			iDecryptIterations = 0;
sl@0
   306
			decryptor = CAESDecryptor::NewL(iKey->Des());
sl@0
   307
			startTime.UniversalTime();
sl@0
   308
			while (diff < iterationTime)
sl@0
   309
				{
sl@0
   310
				decryptor->Reset();
sl@0
   311
				iDecryptIterations++;
sl@0
   312
				endTime.UniversalTime();
sl@0
   313
				endTime.SecondsFrom(startTime, diff);
sl@0
   314
				}
sl@0
   315
			endTime.UniversalTime();
sl@0
   316
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   317
			delete decryptor;
sl@0
   318
			
sl@0
   319
			encryptor = CAESEncryptor::NewLC(iKey->Des());
sl@0
   320
			decryptor = CAESDecryptor::NewL(iKey->Des());
sl@0
   321
			CleanupStack::Pop(encryptor);
sl@0
   322
		}
sl@0
   323
		break;	
sl@0
   324
		case (ERC2ECB):
sl@0
   325
		{
sl@0
   326
			TTime startTime;
sl@0
   327
			TTime endTime;
sl@0
   328
			TTimeIntervalSeconds diff(0);
sl@0
   329
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   330
sl@0
   331
			iEncryptIterations = 0;
sl@0
   332
			encryptor = CRC2Encryptor::NewL(iKey->Des(), iEffectiveKeyLen);
sl@0
   333
			startTime.UniversalTime();	
sl@0
   334
			while (diff < iterationTime)
sl@0
   335
				{
sl@0
   336
				iEncryptIterations++;
sl@0
   337
				encryptor->Reset();
sl@0
   338
				endTime.UniversalTime();
sl@0
   339
				endTime.SecondsFrom(startTime, diff);
sl@0
   340
				}
sl@0
   341
			endTime.UniversalTime();
sl@0
   342
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   343
			delete encryptor;
sl@0
   344
			
sl@0
   345
			diff = 0;
sl@0
   346
			decryptor = CRC2Decryptor::NewL(iKey->Des(), iEffectiveKeyLen);
sl@0
   347
			iDecryptIterations = 0;
sl@0
   348
			startTime.UniversalTime();	
sl@0
   349
			while (diff < iterationTime)
sl@0
   350
				{
sl@0
   351
				decryptor->Reset();
sl@0
   352
				iDecryptIterations++;
sl@0
   353
				endTime.UniversalTime();
sl@0
   354
				endTime.SecondsFrom(startTime, diff);
sl@0
   355
				}
sl@0
   356
			endTime.UniversalTime();
sl@0
   357
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   358
			delete decryptor;
sl@0
   359
sl@0
   360
			encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
sl@0
   361
			decryptor = CRC2Decryptor::NewL(iKey->Des(), iEffectiveKeyLen);
sl@0
   362
			CleanupStack::Pop(encryptor);
sl@0
   363
		}
sl@0
   364
		break;
sl@0
   365
		case (ERC2CBC):
sl@0
   366
		{
sl@0
   367
			CBlockTransformation* theRC2encryptor = NULL;
sl@0
   368
			CBlockTransformation* theRC2decryptor = NULL;
sl@0
   369
sl@0
   370
			theRC2encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
sl@0
   371
			encryptor = CModeCBCEncryptor::NewL(theRC2encryptor, iIV->Des());
sl@0
   372
sl@0
   373
			TTime startTime;
sl@0
   374
			TTime endTime;
sl@0
   375
			TTimeIntervalSeconds diff(0);
sl@0
   376
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   377
sl@0
   378
			iEncryptIterations = 0;
sl@0
   379
			startTime.UniversalTime();
sl@0
   380
			while (diff < iterationTime)
sl@0
   381
				{
sl@0
   382
				iEncryptIterations++;
sl@0
   383
				encryptor->Reset();
sl@0
   384
				endTime.UniversalTime();
sl@0
   385
				endTime.SecondsFrom(startTime, diff);
sl@0
   386
				}
sl@0
   387
			endTime.UniversalTime();
sl@0
   388
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   389
			CleanupStack::Pop(1);
sl@0
   390
			delete encryptor;
sl@0
   391
sl@0
   392
			diff = 0;
sl@0
   393
			iDecryptIterations = 0;
sl@0
   394
			theRC2decryptor = CRC2Decryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
sl@0
   395
			decryptor = CModeCBCDecryptor::NewL(theRC2decryptor, iIV->Des());		
sl@0
   396
			startTime.UniversalTime();
sl@0
   397
			while (diff < iterationTime)
sl@0
   398
				{
sl@0
   399
				decryptor->Reset();
sl@0
   400
				iDecryptIterations++;
sl@0
   401
				endTime.UniversalTime();
sl@0
   402
				endTime.SecondsFrom(startTime, diff);
sl@0
   403
				}
sl@0
   404
			endTime.UniversalTime();
sl@0
   405
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   406
			CleanupStack::Pop(1);
sl@0
   407
			delete decryptor;
sl@0
   408
sl@0
   409
			theRC2encryptor = CRC2Encryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
sl@0
   410
			theRC2decryptor = CRC2Decryptor::NewLC(iKey->Des(), iEffectiveKeyLen);
sl@0
   411
			
sl@0
   412
			encryptor = CModeCBCEncryptor::NewL(theRC2encryptor, iIV->Des());
sl@0
   413
			CleanupStack::PushL(encryptor);
sl@0
   414
			decryptor = CModeCBCDecryptor::NewL(theRC2decryptor, iIV->Des());		
sl@0
   415
			CleanupStack::Pop(3);
sl@0
   416
		}
sl@0
   417
		break;
sl@0
   418
		case (ERC4):
sl@0
   419
		{
sl@0
   420
			iEncryptor = CARC4::NewL(*iKey);
sl@0
   421
			TTime startTime;
sl@0
   422
			TTime endTime;
sl@0
   423
			TTimeIntervalSeconds diff(0);
sl@0
   424
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   425
sl@0
   426
			iEncryptIterations = 0;
sl@0
   427
			startTime.UniversalTime();	
sl@0
   428
			while (diff < iterationTime)
sl@0
   429
				{
sl@0
   430
				iEncryptIterations++;
sl@0
   431
				iEncryptor->Reset();
sl@0
   432
				endTime.UniversalTime();
sl@0
   433
				endTime.SecondsFrom(startTime, diff);
sl@0
   434
				}
sl@0
   435
			endTime.UniversalTime();
sl@0
   436
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   437
sl@0
   438
			diff = 0;			
sl@0
   439
			iDecryptIterations = 0;
sl@0
   440
			iDecryptor = CARC4::NewL(*iKey);
sl@0
   441
			startTime.UniversalTime();	
sl@0
   442
			while (diff < iterationTime)
sl@0
   443
				{
sl@0
   444
				iDecryptor->Reset();
sl@0
   445
				iDecryptIterations++;
sl@0
   446
				endTime.UniversalTime();
sl@0
   447
				endTime.SecondsFrom(startTime, diff);
sl@0
   448
				}
sl@0
   449
			endTime.UniversalTime();
sl@0
   450
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   451
		}
sl@0
   452
		break;
sl@0
   453
		case (ECipherNull):
sl@0
   454
		{
sl@0
   455
			iEncryptor = CNullCipher::NewL();
sl@0
   456
			TTime startTime;
sl@0
   457
			TTime endTime;
sl@0
   458
			TTimeIntervalSeconds diff(0);
sl@0
   459
			const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   460
sl@0
   461
			iEncryptIterations = 0;
sl@0
   462
			startTime.UniversalTime();	
sl@0
   463
			while (diff < iterationTime)
sl@0
   464
				{
sl@0
   465
				iEncryptIterations++;
sl@0
   466
				iEncryptor->Reset();
sl@0
   467
				endTime.UniversalTime();
sl@0
   468
				endTime.SecondsFrom(startTime, diff);
sl@0
   469
				}
sl@0
   470
			endTime.UniversalTime();
sl@0
   471
			iEncryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   472
			
sl@0
   473
			diff = 0;
sl@0
   474
			iDecryptIterations = 0;
sl@0
   475
			iDecryptor = CNullCipher::NewL();
sl@0
   476
			startTime.UniversalTime();	
sl@0
   477
			while (diff < iterationTime)
sl@0
   478
				{
sl@0
   479
				iDecryptor->Reset();
sl@0
   480
				iDecryptIterations++;
sl@0
   481
				endTime.UniversalTime();
sl@0
   482
				endTime.SecondsFrom(startTime, diff);
sl@0
   483
				}
sl@0
   484
			endTime.UniversalTime();
sl@0
   485
			iDecryptorCreateTime = endTime.MicroSecondsFrom(startTime);
sl@0
   486
		}
sl@0
   487
		break;
sl@0
   488
			
sl@0
   489
		default:
sl@0
   490
		{
sl@0
   491
			ASSERT(0);
sl@0
   492
			User::Leave(KErrNotSupported);
sl@0
   493
		}
sl@0
   494
	}
sl@0
   495
	
sl@0
   496
	if( encryptor && decryptor )
sl@0
   497
		{
sl@0
   498
		CleanupStack::PushL(encryptor);
sl@0
   499
		CleanupStack::PushL(decryptor);
sl@0
   500
		
sl@0
   501
		CPaddingSSLv3* ePadding = CPaddingSSLv3::NewLC(encryptor->BlockSize());
sl@0
   502
		iEncryptor = CBufferedEncryptor::NewL(encryptor, ePadding);	
sl@0
   503
		CleanupStack::Pop(ePadding);	
sl@0
   504
		
sl@0
   505
		CPaddingSSLv3* dPadding = CPaddingSSLv3::NewLC(decryptor->BlockSize());
sl@0
   506
		iDecryptor = CBufferedDecryptor::NewL(decryptor, dPadding);
sl@0
   507
		CleanupStack::Pop(dPadding);
sl@0
   508
		CleanupStack::Pop(decryptor);
sl@0
   509
		CleanupStack::Pop(encryptor);
sl@0
   510
		}
sl@0
   511
sl@0
   512
	// clear the default input and output fields and fill with random data
sl@0
   513
	// since for performance testing we do not care about validating
sl@0
   514
	// correct output
sl@0
   515
	delete iInput;	
sl@0
   516
	iInput = NULL;
sl@0
   517
	iInput = HBufC8::NewMaxL(iRandDataSize);
sl@0
   518
	TPtr8 tempPtr = iInput->Des();
sl@0
   519
	TRandom::Random(tempPtr);	
sl@0
   520
	TBuf<128> tempbuf;
sl@0
   521
	tempbuf.Format(KDataSize, (iInput->Length()));
sl@0
   522
	iOut.writeString(tempbuf);	
sl@0
   523
	delete iOutput;
sl@0
   524
	iOutput = NULL;
sl@0
   525
	iOutput = HBufC8::NewMaxL(iRandDataSize);
sl@0
   526
	TPtr8 tempPtr2 = iOutput->Des();
sl@0
   527
	TRandom::Random(tempPtr2);	
sl@0
   528
		
sl@0
   529
	iEResult = HBufC8::NewMaxL(iEncryptor->MaxOutputLength(iInput->Length()));
sl@0
   530
	iDResult = HBufC8::NewMaxL(iDecryptor->MaxOutputLength(iEResult->Size()));
sl@0
   531
#endif
sl@0
   532
}
sl@0
   533
sl@0
   534
void CPerformanceTest::DoPerformActionL()
sl@0
   535
{
sl@0
   536
	iResult = ETrue;
sl@0
   537
#ifndef _DEBUG
sl@0
   538
	TBuf<128> buf;
sl@0
   539
	TReal rate = I64REAL(iEncryptorCreateTime.Int64()) / iEncryptIterations;
sl@0
   540
	buf.Format(KPerfEncryptorCreate, rate, iEncryptIterations, iEncryptorCreateTime.Int64());
sl@0
   541
	iOut.writeString(buf);
sl@0
   542
sl@0
   543
	TTime startTime;
sl@0
   544
	TTime endTime;
sl@0
   545
	TTimeIntervalSeconds diff(0);
sl@0
   546
	const TTimeIntervalSeconds iterationTime(iIterationTime);
sl@0
   547
	
sl@0
   548
	iEncryptIterations = 0;
sl@0
   549
	startTime.UniversalTime();
sl@0
   550
	while (diff < iterationTime)
sl@0
   551
		{
sl@0
   552
		TPtr8 iEResultTemp(iEResult->Des());
sl@0
   553
		iEResultTemp.Zero();
sl@0
   554
sl@0
   555
		iEncryptor->Process(*iInput, iEResultTemp);
sl@0
   556
		iEncryptIterations++;
sl@0
   557
		endTime.UniversalTime();
sl@0
   558
		endTime.SecondsFrom(startTime, diff);
sl@0
   559
		}
sl@0
   560
	endTime.UniversalTime();
sl@0
   561
sl@0
   562
	TTimeIntervalMicroSeconds time = endTime.MicroSecondsFrom(startTime);
sl@0
   563
	rate = I64REAL(time.Int64()) / iEncryptIterations;
sl@0
   564
	buf.Format(KPerfEFormat, rate, iEncryptIterations, time.Int64());
sl@0
   565
	iOut.writeString(buf);
sl@0
   566
sl@0
   567
	rate = (static_cast<TReal>(iEncryptIterations) * iInput->Size() * 1000 * 1000) / (I64REAL(time.Int64()) * 1024 * 1024);	// Throughput in MB/s
sl@0
   568
	buf.FillZ();
sl@0
   569
	buf.Zero();
sl@0
   570
	buf.Format(KPerfThroughputAfterSetup, rate);
sl@0
   571
	iOut.writeString(buf);
sl@0
   572
sl@0
   573
	TInt64 totalEncryptTime = time.Int64();
sl@0
   574
	totalEncryptTime+=iEncryptorCreateTime.Int64();
sl@0
   575
	rate = I64REAL(totalEncryptTime) / iEncryptIterations;
sl@0
   576
	buf.FillZ();
sl@0
   577
	buf.Zero();
sl@0
   578
	buf.Format(KTotalFormat, rate, iEncryptIterations, totalEncryptTime);
sl@0
   579
	iOut.writeString(buf);
sl@0
   580
sl@0
   581
	rate = (static_cast<TReal>(iEncryptIterations) * iInput->Size() * 1000 * 1000) / (I64REAL(totalEncryptTime) * 1024 * 1024);	// Throughput in MB/s
sl@0
   582
	buf.Zero();
sl@0
   583
	buf.Format(KPerfThroughput, rate);
sl@0
   584
	iOut.writeString(buf);
sl@0
   585
sl@0
   586
//	Test decryption
sl@0
   587
	rate = I64REAL(iDecryptorCreateTime.Int64()) / iDecryptIterations;
sl@0
   588
	buf.Format(KPerfDecryptorCreate, rate, iDecryptIterations, iDecryptorCreateTime.Int64());
sl@0
   589
	iOut.writeString(buf);
sl@0
   590
	
sl@0
   591
	diff = 0;
sl@0
   592
	iDecryptIterations = 0;
sl@0
   593
	startTime.UniversalTime();	
sl@0
   594
	while (diff < iterationTime)
sl@0
   595
		{
sl@0
   596
		TPtr8 iDResultTemp(iDResult->Des());
sl@0
   597
		iDResultTemp.Zero();
sl@0
   598
		iDecryptor->Process(*iOutput, iDResultTemp);
sl@0
   599
		iDecryptIterations++;
sl@0
   600
		endTime.UniversalTime();
sl@0
   601
		endTime.SecondsFrom(startTime, diff);
sl@0
   602
		}
sl@0
   603
	endTime.UniversalTime();
sl@0
   604
sl@0
   605
	time = endTime.MicroSecondsFrom(startTime);	
sl@0
   606
	rate = I64REAL(time.Int64()) / iDecryptIterations;
sl@0
   607
	buf.FillZ();
sl@0
   608
	buf.Zero();
sl@0
   609
	buf.Format(KPerfDFormat, rate, iDecryptIterations, time.Int64());
sl@0
   610
	iOut.writeString(buf);
sl@0
   611
sl@0
   612
	rate = (static_cast<TReal>(iDecryptIterations) * iInput->Size() * 1000 * 1000) / (I64REAL(time.Int64()) * 1024 * 1024);	// Throughput in MB/s
sl@0
   613
	buf.Zero();
sl@0
   614
	buf.Format(KPerfThroughputAfterSetup, rate);
sl@0
   615
	iOut.writeString(buf);
sl@0
   616
sl@0
   617
	TInt64 totalDecryptTime = time.Int64();
sl@0
   618
	totalDecryptTime+=iDecryptorCreateTime.Int64();
sl@0
   619
	rate = I64REAL(totalDecryptTime) / iDecryptIterations;
sl@0
   620
	buf.FillZ();
sl@0
   621
	buf.Zero();
sl@0
   622
	buf.Format(KTotalFormat, rate, iDecryptIterations, totalDecryptTime);
sl@0
   623
	iOut.writeString(buf);
sl@0
   624
	
sl@0
   625
	rate = (static_cast<TReal>(iDecryptIterations) * iInput->Size() * 1000 * 1000) / (I64REAL(totalDecryptTime) * 1024 * 1024);	// Throughput in MB/s
sl@0
   626
	buf.Zero();
sl@0
   627
	buf.Format(KPerfThroughput, rate);
sl@0
   628
	iOut.writeString(buf);
sl@0
   629
	
sl@0
   630
#endif
sl@0
   631
}
sl@0
   632