1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsmacstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,198 @@
1.4 +/*
1.5 +* Copyright (c) 2008-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 "plugincharsmacstep.h"
1.28 +#include "plugincharschecker.h"
1.29 +
1.30 +#include <cryptospi/cryptomacapi.h>
1.31 +#include <cryptospi/keys.h>
1.32 +
1.33 +using namespace CryptoSpi;
1.34 +
1.35 +CPluginCharsMacStep::~CPluginCharsMacStep()
1.36 + {
1.37 + }
1.38 +
1.39 +CPluginCharsMacStep::CPluginCharsMacStep()
1.40 + {
1.41 + SetTestStepName(KPluginCharsMacStep);
1.42 + }
1.43 +
1.44 +TVerdict CPluginCharsMacStep::doTestStepPreambleL()
1.45 + {
1.46 + SetTestStepResult(EPass);
1.47 + return TestStepResult();
1.48 + }
1.49 +
1.50 +TVerdict CPluginCharsMacStep::doTestStepL()
1.51 + {
1.52 +
1.53 + INFO_PRINTF1(_L("Plugin Characteristics - Mac Chracteristics"));
1.54 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.55 +
1.56 + if (TestStepResult()==EPass)
1.57 + {
1.58 + //Assume failure, unless all is successful
1.59 + SetTestStepResult(EFail);
1.60 +
1.61 + TVariantPtrC algorithmUid;
1.62 + TPtrC encryptKey;
1.63 + TVariantPtrC keyType;
1.64 +
1.65 + //Each of the individual parameters required to create the Mac object
1.66 + //are read in from the specified INI configuration file
1.67 + if (!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
1.68 + !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
1.69 + !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
1.70 + {
1.71 + ERR_PRINTF1(_L("** .INI Error: Mac Arguments Not Located **"));
1.72 + SetTestStepResult(EFail);
1.73 + }
1.74 + else
1.75 + {
1.76 + CMac* macImpl = NULL;
1.77 +
1.78 + //Convert encryption key to an 8 Bit Descriptor
1.79 + HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
1.80 + TPtr8 keyStrPtr = keyStr->Des();
1.81 +
1.82 + keyStrPtr.Copy(encryptKey);
1.83 +
1.84 + //Create an new CryptoParams object to encapsulate the key type and secret key string
1.85 + CCryptoParams* keyParams = CCryptoParams::NewL();
1.86 + CleanupStack::PushL(keyParams);
1.87 + keyParams->AddL(*keyStr,keyType);
1.88 +
1.89 + //Create Key Object
1.90 + TKeyProperty keyProperty;
1.91 + CKey* key=CKey::NewL(keyProperty,*keyParams);
1.92 + CleanupStack::PushL(key);
1.93 +
1.94 + TRAPD_LOG(err,CMacFactory::CreateMacL(macImpl,
1.95 + algorithmUid,
1.96 + *key,
1.97 + NULL));
1.98 +
1.99 + if (err != KErrNone)
1.100 + {
1.101 + delete macImpl;
1.102 + ERR_PRINTF2(_L("*** FAIL: Failed to Create Mac Object - %d ***"), err);
1.103 + User::Leave(err);
1.104 + }
1.105 +
1.106 + CleanupStack::PushL(macImpl);
1.107 +
1.108 + INFO_PRINTF1(_L("** Successfully Loaded Mac Object **"));
1.109 +
1.110 + //Define a pointer of type TCharacteristics in order to store the hash
1.111 + //cryptographic object's characterisctics
1.112 + const TCharacteristics* chars(NULL);
1.113 +
1.114 + //Retrieve the characteristics for the hash implementation object
1.115 + TRAP_LOG(err, macImpl->GetCharacteristicsL(chars));
1.116 +
1.117 + //Static cast the characteristics to type TMacCharacteristics
1.118 + const TMacCharacteristics* macChars = static_cast<const TMacCharacteristics*>(chars);
1.119 +
1.120 + //Retrieve all the Common characteristics that are required for all test cases
1.121 + TVariantPtrC exInterfaceUid;
1.122 + TVariantPtrC exAlgorithmUid;
1.123 + TVariantPtrC exImplementationUid;
1.124 + TVariantPtrC exCreatorName;
1.125 + TBool exFIPSApproved;
1.126 + TBool exHardwareSupported;
1.127 + TInt exMaxConcurrencySupported;
1.128 + TVariantPtrC exAlgorithmName;
1.129 + TInt exLatency;
1.130 + TInt exThroughput;
1.131 +
1.132 + //Retrieve all the Mac characteristics that are required for all test cases
1.133 + TVariantPtrC exMacMode;
1.134 +
1.135 + if (!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
1.136 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
1.137 + !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
1.138 + !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
1.139 + !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
1.140 + !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
1.141 + !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
1.142 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
1.143 + !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
1.144 + !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
1.145 + !GetStringFromConfig(ConfigSection(),KConfigExMacMode,exMacMode))
1.146 + {
1.147 + ERR_PRINTF1(_L("** .INI Error: Expected Mac/Common Characteristic Arguments Not Located **"));
1.148 + SetTestStepResult(EFail);
1.149 + }
1.150 + else
1.151 + {
1.152 + INFO_PRINTF1(_L("** Checking Mac/Common Characteristics.... **"));
1.153 +
1.154 + CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
1.155 +
1.156 + //Retrieve the Common Characteristics from TMacCharacteristics
1.157 + const TCommonCharacteristics* macCommonChars = &macChars->iMacChar;
1.158 +
1.159 + TPtrC errorMessage;
1.160 +
1.161 + //Perform Mac/Common Characteristic Checks
1.162 + if(pluginCheck->checkCommonCharacteristics(macCommonChars,
1.163 + exInterfaceUid,
1.164 + exAlgorithmUid,
1.165 + exImplementationUid,
1.166 + exCreatorName,
1.167 + exFIPSApproved,
1.168 + exHardwareSupported,
1.169 + exMaxConcurrencySupported,
1.170 + exAlgorithmName,
1.171 + exLatency,
1.172 + exThroughput,
1.173 + errorMessage) &&
1.174 + pluginCheck->checkMacCharacteristics(macChars, exMacMode, errorMessage))
1.175 + {
1.176 + INFO_PRINTF1(_L("Mac/Common characteristics successfully match expected values..."));
1.177 + SetTestStepResult(EPass);
1.178 + }
1.179 + else
1.180 + {
1.181 + ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
1.182 + }
1.183 +
1.184 + CleanupStack::PopAndDestroy(pluginCheck);
1.185 + }
1.186 +
1.187 + CleanupStack::PopAndDestroy(macImpl);
1.188 + CleanupStack::PopAndDestroy(key);
1.189 + CleanupStack::PopAndDestroy(keyParams);
1.190 + CleanupStack::PopAndDestroy(keyStr);
1.191 + }
1.192 + }
1.193 +
1.194 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.195 + return TestStepResult();
1.196 + }
1.197 +
1.198 +TVerdict CPluginCharsMacStep::doTestStepPostambleL()
1.199 + {
1.200 + return TestStepResult();
1.201 + }