os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharssymmetriccipherstep.cpp
Update contrib.
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include "plugincharssymmetriccipherstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/cryptosymmetriccipherapi.h>
28 #include <cryptospi/keys.h>
30 using namespace CryptoSpi;
32 CPluginCharsSymmetricCipherStep::~CPluginCharsSymmetricCipherStep()
36 CPluginCharsSymmetricCipherStep::CPluginCharsSymmetricCipherStep()
38 SetTestStepName(KPluginCharsSymmetricCipherStep);
41 TVerdict CPluginCharsSymmetricCipherStep::doTestStepPreambleL()
43 SetTestStepResult(EPass);
44 return TestStepResult();
47 TVerdict CPluginCharsSymmetricCipherStep::doTestStepL()
50 INFO_PRINTF1(_L("Plugin Characteristics - Symmetric Cipher Chracteristics"));
51 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
53 if (TestStepResult()==EPass)
56 //Assume faliure, unless all is successful
57 SetTestStepResult(EFail);
61 TVariantPtrC algorithmUid;
62 TVariantPtrC cryptoMode;
63 TVariantPtrC operationMode;
64 TVariantPtrC paddingMode;
65 TVariantPtrC invalidOperationMode;
66 TVariantPtrC invalidPaddingMode;
68 //Each of the individual parameters required to create the Symmetric Cipher object
69 //are read in from the specified INI configuration file
70 if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
71 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
72 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
73 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
74 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
75 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
76 !GetStringFromConfig(ConfigSection(),KConfigInvalidOperationMode,invalidOperationMode) ||
77 !GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode))
79 ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
80 SetTestStepResult(EFail);
84 //Convert encryption key to an 8 Bit Descriptor
85 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
86 TPtr8 keyStrPtr = keyStr->Des();
88 keyStrPtr.Copy(encryptKey);
90 //Create an new CryptoParams object to encapsulate the key type and secret key string
91 CCryptoParams* keyParams = CCryptoParams::NewL();
92 CleanupStack::PushL(keyParams);
93 keyParams->AddL(*keyStr,keyType);
96 TKeyProperty keyProperty;
97 CKey* key=CKey::NewL(keyProperty,*keyParams);
98 CleanupStack::PushL(key);
100 CSymmetricCipher* symmetricCipherImpl = NULL;
102 TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
112 if(symmetricCipherImpl && (err == KErrNone))
115 CleanupStack::PushL(symmetricCipherImpl);
117 INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
119 //Define a pointer of type TCharacteristics in order to store the symmetric cipher
120 //encryption object's characterisctics
121 const TCharacteristics* chars(NULL);
123 //Retrieve the characteristics for the symmetric cipher implementation object
124 TRAP_LOG(err, symmetricCipherImpl->GetCharacteristicsL(chars));
126 //Static cast the characteristics to type TSymmetricCipherCharacteristics
127 const TSymmetricCipherCharacteristics* symmetricChars = static_cast<const TSymmetricCipherCharacteristics*>(chars);
129 //Retrieve all the Common characteristics that are required for all test cases
130 TVariantPtrC exInterfaceUid;
131 TVariantPtrC exAlgorithmUid;
132 TVariantPtrC exImplementationUid;
133 TVariantPtrC exCreatorName;
134 TBool exFIPSApproved;
135 TBool exHardwareSupported;
136 TInt exMaxConcurrencySupported;
137 TVariantPtrC exAlgorithmName;
141 //Retrieve all the Symmetric Cipher characteristics that are required for all test cases
142 TInt exSymmetricMaxKeyLength;
143 TInt exSymmetricBlockSize;
144 TVariantPtrC exSymmetricPaddingModes;
145 TInt exSymmetricPaddingModeNum;
146 TVariantPtrC exSymmetricOperationModes;
147 TInt exSymmetricOperationModeNum;
148 TInt exSymmetricKeySupportMode;
150 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
151 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
152 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
153 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
154 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
155 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
156 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
157 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
158 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
159 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
160 !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exSymmetricMaxKeyLength) ||
161 !GetIntFromConfig(ConfigSection(),KConfigExBlockSize,exSymmetricBlockSize) ||
162 !GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exSymmetricPaddingModes) ||
163 !GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exSymmetricPaddingModeNum) ||
164 !GetStringFromConfig(ConfigSection(),KConfigExOperationModes,exSymmetricOperationModes) ||
165 !GetIntFromConfig(ConfigSection(),KConfigExOperationModeNum,exSymmetricOperationModeNum) ||
166 !GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exSymmetricKeySupportMode))
168 ERR_PRINTF1(_L("** .INI Error: Expected Symmetric Cipher/Common Characteristics Not Located **"));
169 SetTestStepResult(EFail);
174 INFO_PRINTF1(_L("** Checking Symmetric Cipher/Common Characteristics.... **"));
176 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
178 //Retrieve the Common Characteristics from TSymmetricCipherCharacteristics
179 const TCommonCharacteristics* symCommonChars = &symmetricChars->cmn;
183 //Perform Symmetric Cipher/Common Characteristic Checks
184 if(pluginCheck->checkCommonCharacteristics(symCommonChars,
191 exMaxConcurrencySupported,
196 pluginCheck->checkSymmetricCharacteristics(symmetricChars,
197 exSymmetricMaxKeyLength,
198 exSymmetricBlockSize,
199 exSymmetricPaddingModes,
200 exSymmetricPaddingModeNum,
201 exSymmetricOperationModes,
202 exSymmetricOperationModeNum,
203 exSymmetricKeySupportMode,
206 INFO_PRINTF1(_L("Symmetric Cipher/Common characteristics successfully match expected values...."));
208 if(symmetricChars->IsOperationModeSupported(operationMode) && !symmetricChars->IsOperationModeSupported(invalidOperationMode))
211 INFO_PRINTF1(_L("Successful Operation Mode Supported Tests...."));
213 if(symmetricChars->IsPaddingModeSupported(paddingMode) && !symmetricChars->IsPaddingModeSupported(invalidPaddingMode))
215 INFO_PRINTF1(_L("Successful Padding Mode Supported Tests...."));
217 INFO_PRINTF1(_L("** PASS: Symmetric Cipher/Common Characteristics Tests Successful **"));
219 SetTestStepResult(EPass);
223 ERR_PRINTF1(_L("** FAIL: Unexpected 'Operation' Mode Supported Results"));
228 ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results"));
234 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
237 CleanupStack::PopAndDestroy(pluginCheck);
240 CleanupStack::PopAndDestroy(symmetricCipherImpl);
244 ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err);
247 CleanupStack::PopAndDestroy(3,keyStr);
251 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
252 return TestStepResult();
255 TVerdict CPluginCharsSymmetricCipherStep::doTestStepPostambleL()
257 return TestStepResult();