1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharshashstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,206 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalTechnology
1.25 +*/
1.26 +
1.27 +#include "plugincharshashstep.h"
1.28 +#include "plugincharschecker.h"
1.29 +
1.30 +#include <cryptospi/cryptohashapi.h>
1.31 +#include <cryptospi/keys.h>
1.32 +
1.33 +using namespace CryptoSpi;
1.34 +
1.35 +CPluginCharsHashStep::~CPluginCharsHashStep()
1.36 + {
1.37 + }
1.38 +
1.39 +CPluginCharsHashStep::CPluginCharsHashStep()
1.40 + {
1.41 + SetTestStepName(KPluginCharsHashStep);
1.42 + }
1.43 +
1.44 +TVerdict CPluginCharsHashStep::doTestStepPreambleL()
1.45 + {
1.46 + SetTestStepResult(EPass);
1.47 + return TestStepResult();
1.48 + }
1.49 +
1.50 +TVerdict CPluginCharsHashStep::doTestStepL()
1.51 + {
1.52 +
1.53 + INFO_PRINTF1(_L("Plugin Characteristics - Hash Chracteristics"));
1.54 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.55 +
1.56 + if (TestStepResult()==EPass)
1.57 + {
1.58 +
1.59 + //Assume faliure, unless all is successful
1.60 + SetTestStepResult(EFail);
1.61 +
1.62 + TVariantPtrC algorithmUid;
1.63 + TVariantPtrC operationMode;
1.64 + TVariantPtrC invalidOperationMode;
1.65 +
1.66 + //Each of the individual parameters required to create the Hash object
1.67 + //are read in from the specified INI configuration file
1.68 + if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
1.69 + !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
1.70 + !GetStringFromConfig(ConfigSection(),KConfigInvalidOperationMode,invalidOperationMode))
1.71 + {
1.72 + ERR_PRINTF1(_L("** .INI Error: Hash Arguments Not Located **"));
1.73 + SetTestStepResult(EFail);
1.74 + }
1.75 + else
1.76 + {
1.77 + CHash* hashImpl = NULL;
1.78 +
1.79 + TRAPD_LOG(err,CHashFactory::CreateHashL(hashImpl,
1.80 + algorithmUid,
1.81 + operationMode,
1.82 + NULL,
1.83 + NULL));
1.84 +
1.85 + if(hashImpl && (err == KErrNone))
1.86 + {
1.87 + CleanupStack::PushL(hashImpl);
1.88 +
1.89 + INFO_PRINTF1(_L("** Successfully Loaded Hash Object **"));
1.90 +
1.91 + //Define a pointer of type TCharacteristics in order to store the hash
1.92 + //cryptographic object's characterisctics
1.93 + const TCharacteristics* chars(NULL);
1.94 +
1.95 + //Retrieve the characteristics for the hash implementation object
1.96 + TRAP_LOG(err, hashImpl->GetCharacteristicsL(chars));
1.97 +
1.98 + //Static cast the characteristics to type THashCharacteristics
1.99 + const THashCharacteristics* hashChars = static_cast<const THashCharacteristics*>(chars);
1.100 +
1.101 + //Retrieve all the Common characteristics that are required for all test cases
1.102 + TVariantPtrC exInterfaceUid;
1.103 + TVariantPtrC exAlgorithmUid;
1.104 + TVariantPtrC exImplementationUid;
1.105 + TVariantPtrC exCreatorName;
1.106 + TBool exFIPSApproved;
1.107 + TBool exHardwareSupported;
1.108 + TInt exMaxConcurrencySupported;
1.109 + TVariantPtrC exAlgorithmName;
1.110 + TInt exLatency;
1.111 + TInt exThroughput;
1.112 +
1.113 + //Retrieve all the Hash characteristics that are required for all test cases
1.114 + TInt exHashBlockSize;
1.115 + TInt exHashOutputSize;
1.116 + TVariantPtrC exHashOperationModes;
1.117 + TInt exHashOperationModeNum;
1.118 +
1.119 + if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
1.120 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
1.121 + !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
1.122 + !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
1.123 + !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
1.124 + !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
1.125 + !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
1.126 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
1.127 + !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
1.128 + !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
1.129 + !GetIntFromConfig(ConfigSection(),KConfigExBlockSize,exHashBlockSize) ||
1.130 + !GetIntFromConfig(ConfigSection(),KConfigExOutputSize,exHashOutputSize) ||
1.131 + !GetStringFromConfig(ConfigSection(),KConfigExOperationModes,exHashOperationModes) ||
1.132 + !GetIntFromConfig(ConfigSection(),KConfigExOperationModeNum,exHashOperationModeNum))
1.133 + {
1.134 + ERR_PRINTF1(_L("** .INI Error: Expected Hash/Common Characteristic Arguments Not Located **"));
1.135 + SetTestStepResult(EFail);
1.136 + }
1.137 + else
1.138 + {
1.139 + INFO_PRINTF1(_L("** Checking Hash/Common Characteristics.... **"));
1.140 +
1.141 + CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
1.142 +
1.143 + //Retrieve the Common Characteristics from THashCharacteristics
1.144 + const TCommonCharacteristics* hashCommonChars = &hashChars->cmn;
1.145 +
1.146 + TPtrC errorMessage;
1.147 +
1.148 + //Perform Hash/Common Characteristic Checks
1.149 + if(pluginCheck->checkCommonCharacteristics(hashCommonChars,
1.150 + exInterfaceUid,
1.151 + exAlgorithmUid,
1.152 + exImplementationUid,
1.153 + exCreatorName,
1.154 + exFIPSApproved,
1.155 + exHardwareSupported,
1.156 + exMaxConcurrencySupported,
1.157 + exAlgorithmName,
1.158 + exLatency,
1.159 + exThroughput,
1.160 + errorMessage) &&
1.161 + pluginCheck->checkHashCharacteristics(hashChars,
1.162 + exHashBlockSize,
1.163 + exHashOutputSize,
1.164 + exHashOperationModes,
1.165 + exHashOperationModeNum,
1.166 + errorMessage))
1.167 + {
1.168 + INFO_PRINTF1(_L("Hash/Common characteristics successfully match expected values..."));
1.169 +
1.170 + if(hashChars->IsOperationModeSupported(operationMode) && !hashChars->IsOperationModeSupported(invalidOperationMode))
1.171 + {
1.172 +
1.173 + INFO_PRINTF1(_L("Successful Operation Mode Supported Tests...."));
1.174 +
1.175 + INFO_PRINTF1(_L("** PASS: Hash/Common Characteristics Tests Successful **"));
1.176 +
1.177 + SetTestStepResult(EPass);
1.178 + }
1.179 + else
1.180 + {
1.181 + ERR_PRINTF1(_L("** FAIL: Unexpected 'Operation' Mode Supported Results"));
1.182 + }
1.183 + }
1.184 + else
1.185 + {
1.186 + ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
1.187 + }
1.188 +
1.189 + CleanupStack::PopAndDestroy(pluginCheck);
1.190 + }
1.191 +
1.192 + CleanupStack::PopAndDestroy(hashImpl);
1.193 + }
1.194 + else
1.195 + {
1.196 + ERR_PRINTF1(_L("** Error: Loading Hash Object **"));
1.197 + }
1.198 + }
1.199 +
1.200 + }
1.201 +
1.202 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.203 + return TestStepResult();
1.204 + }
1.205 +
1.206 +TVerdict CPluginCharsHashStep::doTestStepPostambleL()
1.207 + {
1.208 + return TestStepResult();
1.209 + }