crypto/weakcryptospi/test/tcryptospi/src/plugincharshashstep.cpp
changeset 8 35751d3474b7
child 43 2f10d260163b
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     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  @internalTechnology
       
    22 */
       
    23  
       
    24 #include "plugincharshashstep.h"
       
    25 #include "plugincharschecker.h"
       
    26 
       
    27 #include <cryptospi/cryptohashapi.h>
       
    28 #include "keys.h"
       
    29 
       
    30 using namespace CryptoSpi;
       
    31 
       
    32 CPluginCharsHashStep::~CPluginCharsHashStep()
       
    33 	{
       
    34 	}
       
    35 
       
    36 CPluginCharsHashStep::CPluginCharsHashStep()
       
    37 	{
       
    38 	SetTestStepName(KPluginCharsHashStep);
       
    39 	}
       
    40 
       
    41 TVerdict CPluginCharsHashStep::doTestStepPreambleL()
       
    42 	{
       
    43 	SetTestStepResult(EPass);
       
    44 	return TestStepResult();
       
    45 	}
       
    46 				
       
    47 TVerdict CPluginCharsHashStep::doTestStepL()
       
    48 	{
       
    49 	
       
    50 	INFO_PRINTF1(_L("Plugin Characteristics - Hash Chracteristics"));
       
    51 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
    52 		
       
    53 	if (TestStepResult()==EPass)
       
    54 		{
       
    55 		
       
    56 		//Assume faliure, unless all is successful
       
    57 		SetTestStepResult(EFail);
       
    58 		
       
    59 		TVariantPtrC algorithmUid;
       
    60 		TVariantPtrC operationMode;
       
    61 		TVariantPtrC invalidOperationMode;
       
    62 		
       
    63 		//Each of the individual parameters required to create the Hash object
       
    64 		//are read in from the specified INI configuration file	
       
    65 		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
    66 			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
       
    67 			!GetStringFromConfig(ConfigSection(),KConfigInvalidOperationMode,invalidOperationMode))
       
    68 			{
       
    69 			ERR_PRINTF1(_L("** .INI Error: Hash Arguments Not Located **"));
       
    70 			SetTestStepResult(EFail);
       
    71 			}
       
    72 		else
       
    73 			{
       
    74 			CHash* hashImpl = NULL;
       
    75 			
       
    76 			TRAPD_LOG(err,CHashFactory::CreateHashL(hashImpl,
       
    77 													algorithmUid,
       
    78 													operationMode,
       
    79 													NULL,
       
    80 													NULL));
       
    81 			
       
    82 			if(hashImpl && (err == KErrNone))
       
    83 				{
       
    84 				CleanupStack::PushL(hashImpl);
       
    85 				
       
    86 				INFO_PRINTF1(_L("** Successfully Loaded Hash Object **"));
       
    87 				
       
    88 				//Define a pointer of type TCharacteristics in order to store the hash
       
    89 				//cryptographic object's characterisctics	
       
    90 				const TCharacteristics* chars(NULL);
       
    91 				
       
    92 				//Retrieve the characteristics for the hash implementation object
       
    93 				TRAP_LOG(err, hashImpl->GetCharacteristicsL(chars));
       
    94 							
       
    95 				//Static cast the characteristics to type THashCharacteristics
       
    96 				const THashCharacteristics* hashChars = static_cast<const THashCharacteristics*>(chars);
       
    97 				
       
    98 				//Retrieve all the Common characteristics that are required for all test cases
       
    99 				TVariantPtrC exInterfaceUid;
       
   100 				TVariantPtrC exAlgorithmUid;
       
   101 				TVariantPtrC exImplementationUid;
       
   102 				TVariantPtrC exCreatorName;
       
   103 				TBool exFIPSApproved;
       
   104 				TBool exHardwareSupported;
       
   105 				TInt exMaxConcurrencySupported;
       
   106 				TVariantPtrC exAlgorithmName;
       
   107 				TInt exLatency;
       
   108 				TInt exThroughput;
       
   109 				
       
   110 				//Retrieve all the Hash characteristics that are required for all test cases
       
   111 				TInt exHashBlockSize;
       
   112 				TInt exHashOutputSize;
       
   113 				TVariantPtrC exHashOperationModes;
       
   114 				TInt exHashOperationModeNum;
       
   115 				
       
   116 				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
       
   117 					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
       
   118 					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
       
   119 					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
       
   120 					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
       
   121 					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
       
   122 					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
       
   123 					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
       
   124 					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
       
   125 					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
       
   126 					!GetIntFromConfig(ConfigSection(),KConfigExBlockSize,exHashBlockSize) ||
       
   127 					!GetIntFromConfig(ConfigSection(),KConfigExOutputSize,exHashOutputSize)  ||
       
   128 					!GetStringFromConfig(ConfigSection(),KConfigExOperationModes,exHashOperationModes) ||
       
   129 					!GetIntFromConfig(ConfigSection(),KConfigExOperationModeNum,exHashOperationModeNum))
       
   130 					{
       
   131 					ERR_PRINTF1(_L("** .INI Error: Expected Hash/Common Characteristic Arguments Not Located **"));
       
   132 					SetTestStepResult(EFail);
       
   133 					}
       
   134 				else
       
   135 					{
       
   136 					INFO_PRINTF1(_L("** Checking Hash/Common Characteristics.... **"));
       
   137 					
       
   138 					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
       
   139 					
       
   140 					//Retrieve the Common Characteristics from THashCharacteristics 
       
   141 					const TCommonCharacteristics* hashCommonChars = &hashChars->cmn;
       
   142 					
       
   143 					TPtrC errorMessage;
       
   144 
       
   145 					//Perform Hash/Common Characteristic Checks
       
   146 					if(pluginCheck->checkCommonCharacteristics(hashCommonChars,
       
   147 												exInterfaceUid,
       
   148 												exAlgorithmUid,
       
   149 												exImplementationUid,
       
   150 												exCreatorName,
       
   151 												exFIPSApproved,
       
   152 												exHardwareSupported,
       
   153 												exMaxConcurrencySupported,
       
   154 												exAlgorithmName,
       
   155 												exLatency,
       
   156 												exThroughput,
       
   157 												errorMessage) &&
       
   158 						pluginCheck->checkHashCharacteristics(hashChars,
       
   159 												exHashBlockSize,
       
   160 												exHashOutputSize,
       
   161 												exHashOperationModes,
       
   162 												exHashOperationModeNum,
       
   163 												errorMessage))
       
   164 						{
       
   165 						INFO_PRINTF1(_L("Hash/Common characteristics successfully match expected values..."));
       
   166 						
       
   167 						if(hashChars->IsOperationModeSupported(operationMode) && !hashChars->IsOperationModeSupported(invalidOperationMode))
       
   168 							{
       
   169 							
       
   170 							INFO_PRINTF1(_L("Successful Operation Mode Supported Tests...."));
       
   171 							
       
   172 							INFO_PRINTF1(_L("** PASS: Hash/Common Characteristics Tests Successful **"));
       
   173 
       
   174 							SetTestStepResult(EPass);
       
   175 							}
       
   176 						else
       
   177 							{
       
   178 							ERR_PRINTF1(_L("** FAIL: Unexpected 'Operation' Mode Supported Results"));
       
   179 							}		
       
   180 						}
       
   181 					else
       
   182 						{
       
   183 						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
       
   184 						}
       
   185 
       
   186 					CleanupStack::PopAndDestroy(pluginCheck);
       
   187 					}
       
   188 						
       
   189 				CleanupStack::PopAndDestroy(hashImpl);	
       
   190 				}
       
   191 			else
       
   192 				{
       
   193 				ERR_PRINTF1(_L("** Error: Loading Hash Object **"));
       
   194 				}
       
   195 			} 		
       
   196 		
       
   197 		}
       
   198 		
       
   199 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
       
   200 	return TestStepResult();
       
   201 	}
       
   202 
       
   203 TVerdict CPluginCharsHashStep::doTestStepPostambleL()
       
   204 	{
       
   205 	return TestStepResult();
       
   206 	}