os/security/crypto/weakcryptospi/test/dumpcryptoplugin/dumpprocessor.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalComponent
    22 */
    23 
    24 #include <cryptospi/cryptospidef.h>
    25 #include <bacline.h>
    26 #include <cryptospi/cryptocharacteristics.h>
    27 #include <cryptospi/cryptospistateapi.h>
    28 #include "dumpprocessor.h"
    29 #include <cryptospi/cryptoparams.h>
    30 #include <cryptospi/extendedcharacteristics.h>
    31 #include <e32cons.h>
    32 #include <f32file.h>
    33 
    34 using namespace CryptoSpi;
    35 
    36 //
    37 //The name of characteristics log file
    38 //
    39 _LIT(KLogStartMessage, "DumpCryptoSpiTool");
    40 const TInt KMaxLineLength = 1024;
    41 _LIT8(KNewLine8, "\r\n");
    42 
    43 //
    44 //Characteristic Heads
    45 //
    46 _LIT(KLogHashCharacteristicHead, "[HashCharacteristic]");
    47 _LIT(KLogRandomCharacteristicHead, "[RandomCharacteristic]");
    48 _LIT(KLogSymmetricCipherCharacteristicHead, "[SymmetricCipherCharacteristic]");
    49 _LIT(KLogAsymmetricCipherCharacteristicHead, "[AsymmetricCipherCharacteristic]");
    50 _LIT(KLogSignerCharacteristicHead, "[SignerCharacteristic]");
    51 _LIT(KLogVerifierCharacteristicHead, "[VerifierCharacteristic]");
    52 _LIT(KLogKeyAgreementCharacteristicHead, "[KeyAgreementCharacteristic]");
    53 _LIT(KLogKeypairGeneratorCharacteristicHead, "[KeypairGeneratorCharacteristic]");
    54 _LIT(KLogUnknownCharacteristicHead, "[UnknownCharacteristic]");
    55 
    56 //
    57 //bool and unknow
    58 //
    59 _LIT(KLogBoolTrue, "True");
    60 _LIT(KLogBoolFalse, "False");
    61 _LIT(KLogUnknown, "Unknown");
    62 
    63 //Common Characteristics
    64 _LIT(KLogInterfaceName, "	InterfaceName = %S");
    65 _LIT(KLogAlgorithmUid, "	AlgorithmUid = 0x%x");
    66 _LIT(KLogImplementationUid, "	ImplementationUid = 0x%x");
    67 _LIT(KLogCreatorName, "	CreatorName = %S");
    68 _LIT(KLogFIPSApproved, "	FIPSApproved = %S");
    69 _LIT(KLogHardwareImplementation, "	HardwareImplementation = %S");
    70 _LIT(KLogAlgorithmName, "	AlgorithmName = %S");
    71 _LIT(KLogMaxConcurrency, "	MaxConcurrency = %d");
    72 _LIT(KLogLatency, "	Latency = %d");
    73 _LIT(KLogThroughput, "	Throughput = %d");
    74 
    75 //Hash Characteristics
    76 _LIT(KLogBlockSize, "	BlockSize = %d");
    77 _LIT(KLogOutputSize, "	OutputSize = %d");
    78 
    79 //Random Characteristics
    80 _LIT(KLogBlockMode, "	BlockMode = %d");
    81 
    82 //Symmetric Cipher Characteristics
    83 _LIT(KLogMaximumKeyLength, "	MaximumKeyLength = %d");
    84 _LIT(KLogKeySupportMode, "	KeySupportMode = %d");
    85 
    86 //Plugin Dll Name
    87 _LIT(KDllName, "	PluginDllName = %S");
    88 
    89 //Extended characteristics
    90 _LIT(KLogExtendedCharacteristicInt, "	Ext[0x%x] = 0x%x");
    91 _LIT(KLogExtendedCharacteristicDes, "	Ext[0x%x] = %S");
    92 _LIT8(KLogExtendedCharacteristicDes8, "	Ext[0x%x] = %S");
    93 
    94 //padding modes definitions	
    95 _LIT(KLogPaddingModes1, "	SupportedPaddingModes_%d = %S");
    96 _LIT(KLogPaddingModeNone, "NoneMode");
    97 _LIT(KLogPaddingModeSSLv3, "SSLv3Mode");
    98 _LIT(KLogPaddingModePKCS7, "PKCS7Mode");
    99 _LIT(KLogPaddingModePkcs1_v1_5_Encryption, "Pkcs1_v1_5_EncryptionMode");
   100 _LIT(KLogPaddingModePkcs1_v1_5_Signature, "Pkcs1_v1_5_SignatureMode");
   101 
   102 //Symmetric cipher operation modes definitions
   103 _LIT(KLogOperationModeNone, "NoneMode");
   104 _LIT(KLogOperationModeECB, "ECBMode");
   105 _LIT(KLogOperationModeCBC, "CBCMode");
   106 _LIT(KLogOperationModeOFB, "OFBMode");
   107 _LIT(KLogOperationModeCFB, "CFBMode");
   108 _LIT(KLogOperationModeCTR, "CTRMode");
   109 
   110 //Hash modes definitions
   111 _LIT(KLogOperationModes1, "	SupportedOperationModes_%d = %S");
   112 _LIT(KLogOperationModeHash, "HashMode");
   113 _LIT(KLogOperationModeHmac, "HmacMode");
   114 
   115 //Help text
   116 _LIT(KUsage, "Usage: dumpcryptoplugin [switches] \n");
   117 _LIT(KHelpInterface, "-interface/-i <interface name>	Dump characteristics for the interface, which can be\n");
   118 _LIT(KHelpInterface1, "				hash,random,symcipher,asymcipher,signer,verifier,\n");
   119 _LIT(KHelpInterface2, "				keypairgen,keyagree,asynchash,asyncrandom,asyncsymcipher\n");
   120 _LIT(KHelpInterface3, "				asyncsigner,asyncverifier,asynckeypairgen,asynckeyagree.\n");
   121 _LIT(KHelpAlgorithm, "-algorithm/-al <algorithm name>	Dump characteristics for the algorithm, which can be\n");
   122 _LIT(KHelpAlgorithm1, "				md2,md4,md5,sha1,des,3des,rc2,aes,rc4,rsacipher,rsasigner\n");
   123 _LIT(KHelpAlgorithm2, "				rsaverifier,rsakeypair,dsasigner,dsaverifier,dsakeypair\n");
   124 _LIT(KHelpAlgorithm3, "				dhkeypair,dhkeyagree.\n");
   125 _LIT(KHelpAll, "-all/-a				Dump all the characteristics of all the inplementations.\n");
   126 _LIT(KHelpExtended, "-extended/-e			Dump the extended characteristics as well.\n");
   127 _LIT(KHelpDll, "-dll/-d	<filename>		Only dump the characteristics for the given plugin Dll.\n");
   128 _LIT(KHelpOutput, "-out/-o	<drive:><path><filename>Output file name.\n");
   129 _LIT(KHelpHelp, "-help/-h			Help\n");
   130 
   131 _LIT(KProgessStatus, "Progressing\n");
   132 _LIT(KFileStatus, "Dump to %S");
   133 _LIT(KInvalidArgument, "Invalid Argument:");
   134 _LIT(KArgument, " %S");
   135 
   136 
   137 //
   138 //Implementation of CDumpToolParameters
   139 //
   140 CDumpToolParameters* CDumpToolParameters::NewLC()
   141 	{
   142 	CDumpToolParameters* self=new(ELeave) CDumpToolParameters();
   143 	CleanupStack::PushL(self);
   144 	return self;		
   145 	}
   146 	
   147 CDumpToolParameters::~CDumpToolParameters()
   148 	{
   149 	iOptions.Close();
   150 	iInvalidOptions.ResetAndDestroy();
   151 	}
   152 	
   153 CDumpToolParameters::CDumpToolParameters()
   154 	{
   155 	}
   156 
   157 TBool CDumpToolParameters::FindOption(TOption aOption) const
   158 	{
   159 	TBool found=EFalse;
   160 	TInt count=iOptions.Count();
   161 	for (TInt i=0;i<count;i++)
   162 		{
   163 		if (aOption==iOptions[i])
   164 			{
   165 			found=ETrue;
   166 			break;	
   167 			}
   168 		}
   169 	return found;
   170 	}
   171 	
   172 //
   173 //Implementation of CDumpToolProcessor
   174 //
   175 CDumpToolProcessor* CDumpToolProcessor::NewLC(const CDumpToolParameters& aParams, CConsoleBase* aConsole)
   176 	{
   177 	CDumpToolProcessor* self=new(ELeave) CDumpToolProcessor(aParams, aConsole);
   178 	CleanupStack::PushL(self);
   179 	self->ConstructL();
   180 	return self;		
   181 	}
   182 
   183 CDumpToolProcessor::~CDumpToolProcessor()
   184 	{
   185 	iLogFile.Close();
   186 	iFs.Close();
   187 	iCharacters.ResetAndDestroy();	
   188 	}
   189 
   190 CDumpToolProcessor::CDumpToolProcessor(const CDumpToolParameters& aParams, CConsoleBase* aConsole)
   191 : iInputParams(aParams), iConsole(aConsole)
   192 	{
   193 	}
   194 
   195 void CDumpToolProcessor::ConstructL()
   196 	{
   197 	User::LeaveIfError(iFs.Connect());
   198 		
   199 	if (iInputParams.iDumpFileName.CompareF(KNullDesC)==0)
   200 		{
   201 		TUint driveCh(RFs::GetSystemDriveChar());
   202 
   203 		_LIT(KDumpFileNameFmt, "%c:\\dumpcrypoplugin.txt");
   204 		iDumpFileName.Format(KDumpFileNameFmt, driveCh);
   205 		}
   206 	else
   207 		{
   208 		TInt pos=iInputParams.iDumpFileName.LocateReverseF('\\');
   209 		TFileName path=iInputParams.iDumpFileName.Left(pos+1);
   210 		TInt ret=iFs.MkDirAll(path);
   211 		if (ret!=KErrNone && ret!=KErrAlreadyExists)
   212 			{
   213 			User::LeaveIfError(ret);	
   214 			}
   215 		iDumpFileName=iInputParams.iDumpFileName;
   216 		}
   217 	
   218 	User::LeaveIfError(iLogFile.Replace(iFs, iDumpFileName, EFileWrite | EFileShareExclusive));
   219 	TBool extended=EFalse;
   220 	if (iInputParams.FindOption(CDumpToolParameters::EOptionExtendedCharacteristic))
   221 		{
   222 		extended=ETrue;
   223 		}
   224 	CCryptoSpiStateApi::EnumerateCharacteristicsL(iCharacters, iInputParams.iInterface, extended);
   225 	}
   226 	
   227 void CDumpToolProcessor::ProcessL()
   228 	{
   229 	if (iInputParams.FindOption(CDumpToolParameters::EOptionHelp))
   230 		{
   231 		DisplayHelp();
   232 		return;	
   233 		}
   234 	
   235 	if (iInputParams.iInvalidOptions.Count()!=0 )
   236 		{
   237 		DisplayInvalidOptions();
   238 		return;
   239 		}
   240 	
   241 	LogL(KLogStartMessage);
   242 	TInt count=iCharacters.Count();
   243 	iConsole->Printf(KProgessStatus);
   244 	for (TInt i=0;i<count;i++)
   245 		{
   246 		if (iInputParams.iAlgorithm!=0 
   247 			&& iInputParams.iAlgorithm!=iCharacters[i]->iCharacteristic->iAlgorithmUid)
   248 			{
   249 			continue;
   250 			}
   251 		
   252 		if (iInputParams.iDllName.Compare(KNullDesC)!=0
   253 			&&iInputParams.iDllName.Compare(iCharacters[i]->iDllName)!=0)
   254 			{
   255 			continue;
   256 			}
   257 		OutputCharcteristicsAndDllL(*iCharacters[i]);
   258 		}
   259 	iConsole->Printf(KFileStatus, &iDumpFileName);
   260 	}
   261 
   262 void CDumpToolProcessor::OutputCharacteristicHeadL(TInt32 aInterfaceUid)
   263 	{
   264 	LogL(KNewLine8);
   265 	switch (aInterfaceUid)
   266 		{
   267 	case KHashInterface:
   268 	case KAsyncHashInterface:
   269 		LogL(KLogHashCharacteristicHead);
   270 		break;
   271 
   272 	case KRandomInterface:
   273 	case KAsyncRandomInterface:
   274 		LogL(KLogRandomCharacteristicHead);
   275 		break;
   276 		
   277 	case KSymmetricCipherInterface:
   278 	case KAsyncSymmetricCipherInterface:
   279 		LogL(KLogSymmetricCipherCharacteristicHead);
   280 		break;
   281 		
   282 	case KAsymmetricCipherInterface:
   283 	case KAsyncAsymmetricCipherInterface:
   284 		LogL(KLogAsymmetricCipherCharacteristicHead);
   285 		break;
   286 		
   287 	case KSignerInterface:
   288 	case KAsyncSignerInterface:
   289 		LogL(KLogSignerCharacteristicHead);
   290 		break;
   291 		
   292 	case KVerifierInterface:
   293 	case KAsyncVerifierInterface:
   294 		LogL(KLogVerifierCharacteristicHead);
   295 		break;
   296 		
   297 	case KKeyAgreementInterface:
   298 	case KAsyncKeyAgreementInterface:
   299 		LogL(KLogKeyAgreementCharacteristicHead);
   300 		break;
   301 		
   302 	case KKeypairGeneratorInterface:
   303 	case KAsyncKeypairGeneratorInterface:
   304 		LogL(KLogKeypairGeneratorCharacteristicHead);
   305 		break;
   306 		
   307 	default:
   308 		LogL(KLogUnknownCharacteristicHead);
   309 		}
   310 	}
   311 
   312 
   313 void CDumpToolProcessor::OutputInterfaceNameL(TInt32 aInterfaceUid)
   314 	{
   315 	switch (aInterfaceUid)
   316 		{
   317 	case KHashInterface:
   318 		LogL(KLogInterfaceName, &KHash);
   319 		break;
   320 		
   321 	case KAsyncHashInterface:
   322 		LogL(KLogInterfaceName, &KAsyncHash);
   323 		break;
   324 
   325 	case KRandomInterface:
   326 		LogL(KLogInterfaceName, &KRandom);
   327 		break;
   328 	
   329 	case KAsyncRandomInterface:
   330 		LogL(KLogInterfaceName, &KAsyncRandom);
   331 		break;
   332 		
   333 	case KSymmetricCipherInterface:
   334 		LogL(KLogInterfaceName, &KSymmetricCipher);
   335 		break;
   336 	
   337 	case KAsyncSymmetricCipherInterface:
   338 		LogL(KLogInterfaceName, &KAsyncSymmetricCipher);
   339 		break;
   340 		
   341 	case KAsymmetricCipherInterface:
   342 		LogL(KLogInterfaceName, &KAsymmetricCipher);
   343 		break;
   344 	
   345 	case KAsyncAsymmetricCipherInterface:
   346 		LogL(KLogInterfaceName, &KAsyncAsymmetricCipher);
   347 		break;
   348 		
   349 	case KSignerInterface:
   350 		LogL(KLogInterfaceName, &KSigner);
   351 		break;
   352 	
   353 	case KAsyncSignerInterface:
   354 		LogL(KLogInterfaceName, &KAsyncSigner);
   355 		break;
   356 		
   357 	case KVerifierInterface:
   358 		LogL(KLogInterfaceName, &KVerifier);
   359 		break;
   360 	
   361 	case KAsyncVerifierInterface:
   362 		LogL(KLogInterfaceName, &KAsyncVerifier);
   363 		break;
   364 		
   365 	case KKeyAgreementInterface:
   366 		LogL(KLogInterfaceName, &KKeyAgreement);
   367 		break;
   368 	
   369 	case KAsyncKeyAgreementInterface:
   370 		LogL(KLogInterfaceName, &KAsyncKeyAgreement);
   371 		break;
   372 		
   373 	case KKeypairGeneratorInterface:
   374 		LogL(KLogInterfaceName, &KKeyPairGenerator);
   375 		break;
   376 	
   377 	case KAsyncKeypairGeneratorInterface:
   378 		LogL(KLogInterfaceName, &KAsyncKeyPairGenerator);
   379 		break;
   380 		
   381 	default:
   382 		LogL(KLogInterfaceName, &KLogUnknown);
   383 		}		
   384 	}
   385 
   386 void CDumpToolProcessor::OutputAlgorithmNameL(TInt32 aAlgorithmUid)
   387 	{
   388 	switch (aAlgorithmUid)
   389 		{
   390 	case KAlgorithmHashMd2:
   391 		LogL(KLogAlgorithmName, &KMd2);
   392 		break;
   393 	case KAlgorithmHashMd4:
   394 		LogL(KLogAlgorithmName, &KMd4);
   395 		break;		
   396 	case KAlgorithmHashMd5:
   397 		LogL(KLogAlgorithmName, &KMd5);
   398 		break;
   399 	case KAlgorithmHashSha1:
   400 		LogL(KLogAlgorithmName, &KSha1);
   401 		break;
   402 	case KAlgorithmCipherDes:
   403 		LogL(KLogAlgorithmName, &KDes);	
   404 		break;
   405 	case KAlgorithmCipher3Des:
   406 		LogL(KLogAlgorithmName, &K3Des);	
   407 		break;
   408 	case KAlgorithmCipherRc2:
   409 		LogL(KLogAlgorithmName, &KRC2);	
   410 		break;
   411 	case KAlgorithmCipherAes:
   412 		LogL(KLogAlgorithmName, &KAes);	
   413 		break;
   414 	case KAlgorithmCipherArc4:
   415 		LogL(KLogAlgorithmName, &KRC4);	
   416 		break;
   417 	case KAlgorithmCipherRsa:
   418 		LogL(KLogAlgorithmName, &KRsaCipher);	
   419 		break;
   420 	case KAlgorithmSignerRsa:
   421 		LogL(KLogAlgorithmName, &KRsaSigner);	
   422 		break;
   423 	case KAlgorithmVerifierRsa:
   424 		LogL(KLogAlgorithmName, &KRsaVerifier);	
   425 		break;
   426 	case KAlgorithmRSAKeyPairGenerator:
   427 		LogL(KLogAlgorithmName, &KRsaKeyPair);	
   428 		break;
   429 	case KAlgorithmSignerDsa:
   430 		LogL(KLogAlgorithmName, &KDsaSigner);	
   431 		break;
   432 	case KAlgorithmVerifierDsa:
   433 		LogL(KLogAlgorithmName, &KDsaVerifier);	
   434 		break;
   435 	case KAlgorithmDSAKeyPairGenerator:
   436 		LogL(KLogAlgorithmName, &KDsaKeyPair);	
   437 		break;
   438 	case KAlgorithmDHKeyPairGenerator:
   439 		LogL(KLogAlgorithmName, &KDhKeyPair);	
   440 		break;
   441 	case KAlgorithmKeyAgreementDH:
   442 		LogL(KLogAlgorithmName, &KDhKeyAgreement);	
   443 		break;
   444 	default:;
   445 		}
   446 	}
   447 
   448 void CDumpToolProcessor::OutputHashOperationModeL(TInt aIndex, TInt32 aOperationMode)
   449 	{
   450 	switch(aOperationMode)
   451 		{
   452 	case KHashMode:
   453 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeHash);
   454 		break;
   455 	case KHmacMode:
   456 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeHmac);
   457 		break;
   458 	default:;
   459 		}
   460 	}
   461 
   462 void CDumpToolProcessor::OutputSymmetricOperationModeL(TInt aIndex, TInt32 aOperationMode)
   463 	{
   464 	switch(aOperationMode)
   465 		{
   466 	case KOperationModeNone:
   467 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeNone);
   468 		break;
   469 	case KOperationModeECB:
   470 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeECB);
   471 		break;
   472 	case KOperationModeCBC:
   473 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeCBC);
   474 		break;
   475 	case KOperationModeOFB:
   476 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeOFB);
   477 		break;
   478 	case KOperationModeCFB:
   479 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeCFB);
   480 		break;
   481 	case KOperationModeCTR:
   482 		LogL(KLogOperationModes1, aIndex, &KLogOperationModeCTR);
   483 		break;		
   484 	default:;
   485 		}	
   486 	}
   487 
   488 void CDumpToolProcessor::OutputPaddingModeL(TInt aIndex, TInt32 aPaddingMode)
   489 	{
   490 	switch(aPaddingMode)
   491 		{
   492 	case KPaddingModeNone:
   493 		LogL(KLogPaddingModes1, aIndex, &KLogPaddingModeNone);
   494 		break;
   495 	case KPaddingModeSSLv3:
   496 		LogL(KLogPaddingModes1, aIndex, &KLogPaddingModeSSLv3);
   497 		break;
   498 	case KPaddingModePKCS7:
   499 		LogL(KLogPaddingModes1, aIndex, &KLogPaddingModePKCS7);
   500 		break;
   501 	case KPaddingModePkcs1_v1_5_Encryption:
   502 		LogL(KLogPaddingModes1, aIndex, &KLogPaddingModePkcs1_v1_5_Encryption);
   503 		break;
   504 	case KPaddingModePkcs1_v1_5_Signature:
   505 		LogL(KLogPaddingModes1, aIndex, &KLogPaddingModePkcs1_v1_5_Signature);
   506 		break;
   507 	default:;
   508 		}		
   509 	}
   510 
   511 void CDumpToolProcessor::OutputSpecificCharacteristicL(const CCharacteristics& aCharacter)
   512 	{
   513 	switch (aCharacter.iInterfaceUid)
   514 		{
   515 	case KHashInterface:
   516 	case KAsyncHashInterface:
   517 		{
   518 		const CHashCharacteristics& sCharacter=static_cast<const CHashCharacteristics&>(aCharacter);
   519 		LogL(KLogBlockSize, sCharacter.iBlockSize);
   520 		LogL(KLogOutputSize, sCharacter.iOutputSize);
   521 		TInt count=sCharacter.iSupportedOperationModes.Count();
   522 		for (TInt i=0;i<count;i++)
   523 			{
   524 			OutputHashOperationModeL(i, sCharacter.iSupportedOperationModes[i]);
   525 			}			
   526 		}
   527 		break;
   528 
   529 	case KRandomInterface:
   530 	case KAsyncRandomInterface:
   531 		{
   532 		const CRandomCharacteristics& sCharacter=static_cast<const CRandomCharacteristics&>(aCharacter);
   533 		LogL(KLogBlockMode, sCharacter.iBlockingMode);			
   534 		}
   535 		break;
   536 		
   537 	case KSymmetricCipherInterface:
   538 	case KAsyncSymmetricCipherInterface:
   539 		{
   540 		const CSymmetricCipherCharacteristics& sCharacter=static_cast<const CSymmetricCipherCharacteristics&>(aCharacter);
   541 		LogL(KLogMaximumKeyLength, sCharacter.iMaximumKeyLength);
   542 		LogL(KLogBlockSize, sCharacter.iBlockSize);
   543 		TInt count=sCharacter.iSupportedPaddingModes.Count();
   544 		for (TInt i=0;i<count;i++)
   545 			{
   546 			OutputPaddingModeL(i, sCharacter.iSupportedPaddingModes[i]);
   547 			}			
   548 		count=sCharacter.iSupportedOperationModes.Count();
   549 		for (TInt i=0;i<count;i++)
   550 			{
   551 			OutputSymmetricOperationModeL(i, sCharacter.iSupportedOperationModes[i]);
   552 			}
   553 		LogL(KLogKeySupportMode, sCharacter.iKeySupportMode);
   554 		}
   555 		break;
   556 		
   557 	case KAsymmetricCipherInterface:
   558 	case KAsyncAsymmetricCipherInterface:
   559 		{
   560 		const CAsymmetricCipherCharacteristics& sCharacter=static_cast<const CAsymmetricCipherCharacteristics&>(aCharacter);
   561 		LogL(KLogMaximumKeyLength, sCharacter.iMaximumKeyLength);
   562 		TInt count=sCharacter.iSupportedPaddingModes.Count();
   563 		for (TInt i=0;i<count;i++)
   564 			{
   565 			OutputPaddingModeL(i, sCharacter.iSupportedPaddingModes[i]);
   566 			}			
   567 		LogL(KLogKeySupportMode, sCharacter.iKeySupportMode);	
   568 		}
   569 		break;
   570 		
   571 	case KSignerInterface:
   572 	case KAsyncSignerInterface:
   573 	case KVerifierInterface:
   574 	case KAsyncVerifierInterface:
   575 		{
   576 		const CAsymmetricSignatureCharacteristics& sCharacter=static_cast<const CAsymmetricSignatureCharacteristics&>(aCharacter);
   577 		LogL(KLogMaximumKeyLength, sCharacter.iMaximumKeyLength);
   578 		TInt count=sCharacter.iSupportedPaddingModes.Count();
   579 		for (TInt i=0;i<count;i++)
   580 			{
   581 			OutputPaddingModeL(i, sCharacter.iSupportedPaddingModes[i]);
   582 			}			
   583 		LogL(KLogKeySupportMode, sCharacter.iKeySupportMode);	
   584 		}	
   585 		break;
   586 		
   587 	case KKeypairGeneratorInterface:
   588 	case KAsyncKeypairGeneratorInterface:
   589 		{
   590 		const CKeypairGeneratorCharacteristics& sCharacter=static_cast<const CKeypairGeneratorCharacteristics&>(aCharacter);
   591 		LogL(KLogMaximumKeyLength, sCharacter.iMaximumKeyLength);			
   592 		}
   593 		break;
   594 		
   595 	case KKeyAgreementInterface:
   596 	case KAsyncKeyAgreementInterface:
   597 	default:
   598 		;
   599 		}
   600 	}
   601 
   602 void CDumpToolProcessor::OutputExtendedCharacteristicL(const CExtendedCharacteristics& aCharacter)
   603 	{
   604 	CExtendedCharacteristics& character=const_cast<CExtendedCharacteristics&>(aCharacter);
   605 	const CCryptoParams* params=character.ListExtendedCharacteristics();
   606 	const RPointerArray<CCryptoParam>& list=params->GetParams();
   607 	TInt count=list.Count();
   608 	for (TInt i=0;i<count;i++)
   609 		{
   610 		TInt type=list[i]->Type();
   611 		switch (type)
   612 			{
   613 		case CCryptoParam::EInt:
   614 			LogL(KLogExtendedCharacteristicInt, list[i]->Uid().iUid, ((CCryptoIntParam*)list[i])->Value());
   615 			break;
   616 		case CCryptoParam::EBigInt:
   617 			{
   618 			const TInteger& bigInt=((CCryptoBigIntParam*)list[i])->Value();
   619 			HBufC8* buf8=bigInt.BufferLC();
   620 			LogL(KLogExtendedCharacteristicDes8, list[i]->Uid().iUid, buf8);
   621 			CleanupStack::PopAndDestroy(buf8);				
   622 			}
   623 			break;
   624 		case CCryptoParam::EDesC8:
   625 			LogL(KLogExtendedCharacteristicDes8, list[i]->Uid().iUid, ((CCryptoIntParam*)list[i])->Value());
   626 			break;
   627 		case CCryptoParam::EDesC16:
   628 			LogL(KLogExtendedCharacteristicDes, list[i]->Uid().iUid, ((CCryptoIntParam*)list[i])->Value());
   629 			break;
   630 		default:;
   631 			}
   632 		}
   633 	}
   634 
   635 void CDumpToolProcessor::OutputCharcteristicsAndDllL(const CCharacteristicsAndPluginName& aElement)
   636 	{
   637 	//Output Head
   638 	OutputCharacteristicHeadL(aElement.iCharacteristic->iInterfaceUid);
   639 	
   640 	//Start of Common Characteristics output
   641 	//Output Interface name
   642 	OutputInterfaceNameL(aElement.iCharacteristic->iInterfaceUid);
   643 	
   644 	//Output Algorithm Uid
   645 	LogL(KLogAlgorithmUid, aElement.iCharacteristic->iAlgorithmUid);
   646 	
   647 	//Output Implementation Uid
   648 	LogL(KLogImplementationUid, aElement.iCharacteristic->iImplementationUid);
   649 	
   650 	//Output Creator's name
   651 	TFileName name=aElement.iCharacteristic->iCreatorName;
   652 	LogL(KLogCreatorName, &name);
   653 	
   654 	//Output FIPS Approved Flag
   655 	if (aElement.iCharacteristic->iIsFIPSApproved)
   656 		{
   657 		LogL(KLogFIPSApproved, &KLogBoolTrue);
   658 		}
   659 	else
   660 		{
   661 		LogL(KLogFIPSApproved, &KLogBoolFalse);
   662 		}
   663 		
   664 	//Output Hardware supported flag
   665 	if (aElement.iCharacteristic->iIsHardwareSupported)
   666 		{
   667 		LogL(KLogHardwareImplementation, &KLogBoolTrue);			
   668 		}
   669 	else
   670 		{
   671 		LogL(KLogHardwareImplementation, &KLogBoolFalse);		
   672 		}
   673 		
   674 	//Output Max concurrency supported
   675 	LogL(KLogMaxConcurrency, aElement.iCharacteristic->iMaxConcurrencySupported);
   676 	
   677 	//Output Algorithm Name
   678 	name=aElement.iCharacteristic->iAlgorithmName;
   679 	LogL(KLogAlgorithmName, &name);
   680 	
   681 	//Output Latency
   682 	LogL(KLogLatency, aElement.iCharacteristic->iLatency);
   683 	
   684 	//Output throughput
   685 	LogL(KLogThroughput, aElement.iCharacteristic->iThroughput);
   686 	//end of Common Characteristics output
   687 	
   688 	//Output Specific Characteristic
   689 	OutputSpecificCharacteristicL(*aElement.iCharacteristic);
   690 	
   691 	//Output extended characteristics
   692 	if (aElement.iExtendedCharacteristic)
   693 		{
   694 		OutputExtendedCharacteristicL(*aElement.iExtendedCharacteristic);
   695 		}
   696 	
   697 	//Output the name of the plugin dll, which contains this implementation
   698 	LogL(KDllName, &aElement.iDllName);	
   699 	}
   700 	
   701 void CDumpToolProcessor::LogL(TRefByValue<const TDesC8> aFmt, ...)
   702 	{
   703 	TBuf8<KMaxLineLength> buf;
   704 	VA_LIST args;
   705 	VA_START(args, aFmt);
   706 	buf.AppendFormatList(aFmt, args);
   707 	VA_END(args);
   708 
   709 	User::LeaveIfError(iLogFile.Write(buf));
   710 	User::LeaveIfError(iLogFile.Write(KNewLine8));
   711 	User::LeaveIfError(iLogFile.Flush());
   712 	}
   713 	
   714 void CDumpToolProcessor::LogL(TRefByValue<const TDesC> aFmt, ...)
   715 	{
   716 	TBuf<KMaxLineLength> buf;
   717 	VA_LIST args;
   718 	VA_START(args, aFmt);
   719 	buf.AppendFormatList(aFmt, args);
   720 	VA_END(args);
   721 
   722 	TBuf8<KMaxLineLength> buf8;
   723 	buf8.Copy(buf);
   724 	User::LeaveIfError(iLogFile.Write(buf8));
   725 	User::LeaveIfError(iLogFile.Write(KNewLine8));
   726 	User::LeaveIfError(iLogFile.Flush());
   727 	}
   728 
   729 /**
   730 Display usage information
   731 */
   732 void CDumpToolProcessor::DisplayHelp()
   733 	{
   734 	iConsole->Printf(KUsage);
   735 	iConsole->Printf(KHelpInterface);
   736 	iConsole->Printf(KHelpInterface1);
   737 	iConsole->Printf(KHelpInterface2);
   738 	iConsole->Printf(KHelpInterface3);
   739 	iConsole->Printf(KHelpAlgorithm);
   740 	iConsole->Printf(KHelpAlgorithm1);
   741 	iConsole->Printf(KHelpAlgorithm2);
   742 	iConsole->Printf(KHelpAlgorithm3);
   743 	iConsole->Printf(KHelpAll);
   744 	iConsole->Printf(KHelpExtended);
   745 	iConsole->Printf(KHelpDll);
   746 	iConsole->Printf(KHelpOutput);
   747 	iConsole->Printf(KHelpHelp);
   748 	iConsole->Printf(KNewLine);
   749 	iConsole->Printf(KPressAnyKey);
   750 	iConsole->Getch();
   751 			
   752 	}
   753 
   754 
   755 void CDumpToolProcessor::DisplayInvalidOptions()
   756 	{
   757 	iConsole->Printf(KInvalidArgument);
   758 	TInt count=iInputParams.iInvalidOptions.Count();
   759 	for (TInt i=0;i<count;i++)
   760 		{
   761 		iConsole->Printf(KArgument, iInputParams.iInvalidOptions[i]);	
   762 		}
   763 	iConsole->Printf(KNewLine);
   764 	iConsole->Printf(KPressAnyKey);
   765 	iConsole->Getch();
   766 	
   767 	}
   768 	
   769 
   770