os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsasymmetriccipherstep.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 "plugincharsasymmetriccipherstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/cryptoasymmetriccipherapi.h>
28 #include <cryptospi/cryptokeypairgeneratorapi.h>
29 #include <cryptospi/keypair.h>
31 using namespace CryptoSpi;
33 CPluginCharsAsymmetricCipherStep::~CPluginCharsAsymmetricCipherStep()
37 CPluginCharsAsymmetricCipherStep::CPluginCharsAsymmetricCipherStep()
39 SetTestStepName(KPluginCharsAsymmetricCipherStep);
42 TVerdict CPluginCharsAsymmetricCipherStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
48 TVerdict CPluginCharsAsymmetricCipherStep::doTestStepL()
51 INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Cipher Chracteristics"));
52 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
54 if (TestStepResult()==EPass)
57 //Assume faliure, unless all is successful
58 SetTestStepResult(EFail);
60 TVariantPtrC algorithmUid;
61 TVariantPtrC cryptoMode;
62 TVariantPtrC paddingMode;
63 TVariantPtrC invalidPaddingMode;
65 //Each of the individual parameters required to create the Asymmetric Cipher object
66 //are read in from the specified INI configuration file
67 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
68 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
69 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
70 !GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode))
72 ERR_PRINTF1(_L("** .INI Error: Asymmetric Cipher Arguments Not Located **"));
73 SetTestStepResult(EFail);
77 CCryptoParams* keyParams = CCryptoParams::NewLC();
79 //****************************************************
80 //Create Key Pair and Key Pair Generator Objects
81 CKeyPair* keyPair = NULL;
82 CKeyPairGenerator * keypairImpl = NULL;
84 INFO_PRINTF1(_L("Generating RSA keys"));
86 // create an RSA key pair
87 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
88 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
90 // create a key pair generator implementation interface
91 TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
92 KRSAKeyPairGeneratorUid,
95 CleanupStack::PushL(keypairImpl);
98 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
100 CleanupStack::PushL(keyPair);
102 //*****************************************************
104 CAsymmetricCipher* asymmetricCipherImpl = NULL;
106 TRAP(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL(asymmetricCipherImpl,
108 keyPair->PrivateKey(),
113 if(asymmetricCipherImpl && (err == KErrNone))
116 CleanupStack::PushL(asymmetricCipherImpl);
118 INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Cipher Object **"));
120 //Define a pointer of type TCharacteristics in order to store the asymmetric cipher
121 //encryption object's characterisctics
122 const TCharacteristics* chars(NULL);
124 //Retrieve the characteristics for the asymmetric cipher implementation object
125 TRAP_LOG(err, asymmetricCipherImpl->GetCharacteristicsL(chars));
127 //Static cast the characteristics to type TAsymmetricCipherCharacteristics
128 const TAsymmetricCipherCharacteristics* asymmetricChars = static_cast<const TAsymmetricCipherCharacteristics*>(chars);
130 //Retrieve all the Common characteristics that are required for all test cases
131 TVariantPtrC exInterfaceUid;
132 TVariantPtrC exAlgorithmUid;
133 TVariantPtrC exImplementationUid;
134 TVariantPtrC exCreatorName;
135 TBool exFIPSApproved;
136 TBool exHardwareSupported;
137 TInt exMaxConcurrencySupported;
138 TVariantPtrC exAlgorithmName;
142 //Retrieve all the Asymmetric characteristics that are required for all test cases
143 TInt exAsymmetricMaxKeyLength;
144 TVariantPtrC exAsymmetricPaddingModes;
145 TInt exAsymmetricPaddingModeNum;
146 TInt exAsymmetricKeySupportMode;
148 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
149 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
150 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
151 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
152 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
153 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
154 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
155 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
156 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
157 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
158 !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymmetricMaxKeyLength) ||
159 !GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exAsymmetricPaddingModes) ||
160 !GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exAsymmetricPaddingModeNum) ||
161 !GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exAsymmetricKeySupportMode))
163 ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Cipher/Common Chracteristic Arguments Not Located **"));
164 SetTestStepResult(EFail);
168 INFO_PRINTF1(_L("** Checking Asymmetric Cipher/Common Characteristics.... **"));
170 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
172 //Retrieve the Common Characteristics from TAsymmetricCipherCharacteristics
173 const TCommonCharacteristics* asymCommonChars = &asymmetricChars->cmn;
177 //Perform Asymmetric Cipher/Common Characteristic Checks
178 if(pluginCheck->checkCommonCharacteristics(asymCommonChars,
185 exMaxConcurrencySupported,
190 pluginCheck->checkAsymmetricCharacteristics(asymmetricChars,
191 exAsymmetricMaxKeyLength,
192 exAsymmetricPaddingModes,
193 exAsymmetricPaddingModeNum,
194 exAsymmetricKeySupportMode,
197 INFO_PRINTF1(_L("Asymmetric Cipher/Common characteristics successfully match expected values..."));
199 if(asymmetricChars->IsPaddingModeSupported(paddingMode) && !asymmetricChars->IsPaddingModeSupported(invalidPaddingMode))
201 INFO_PRINTF1(_L("Successful Padding Mode Supported Tests...."));
203 INFO_PRINTF1(_L("** PASS: Asymmetric Cipher/Common Characteristics Tests Successful **"));
205 SetTestStepResult(EPass);
209 ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results"));
214 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
217 CleanupStack::PopAndDestroy(pluginCheck);
220 CleanupStack::PopAndDestroy(asymmetricCipherImpl);
224 ERR_PRINTF1(_L("** Error: Loading Asymmetric Cipher Object **"));
227 CleanupStack::PopAndDestroy(3,keyParams);
232 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
233 return TestStepResult();
236 TVerdict CPluginCharsAsymmetricCipherStep::doTestStepPostambleL()
238 return TestStepResult();