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 "plugincharskeyagreestep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/keypair.h>
28 #include <cryptospi/cryptokeypairgeneratorapi.h>
29 #include <cryptospi/cryptokeyagreementapi.h>
31 using namespace CryptoSpi;
33 CPluginCharsKeyAgreeStep::~CPluginCharsKeyAgreeStep()
37 CPluginCharsKeyAgreeStep::CPluginCharsKeyAgreeStep()
39 SetTestStepName(KPluginCharsKeyAgreeStep);
42 TVerdict CPluginCharsKeyAgreeStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
48 TVerdict CPluginCharsKeyAgreeStep::doTestStepL()
51 INFO_PRINTF1(_L("Plugin Characteristics - Key Agreement 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;
62 //Each of the individual parameters required to create the Key Agreement object
63 //are read in from the specified INI configuration file
64 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
66 ERR_PRINTF1(_L("** .INI Error: Key Agreement Object Arguments Not Located **"));
67 SetTestStepResult(EFail);
71 INFO_PRINTF1(_L("Creating Primes and Base Integers..."));
73 RInteger DH_N = RInteger::NewPrimeL(64);
74 CleanupClosePushL(DH_N);
76 RInteger DH_N_MinusOne = RInteger::NewL(DH_N);
77 CleanupClosePushL(DH_N_MinusOne);
80 RInteger DH_G = RInteger::NewRandomL(TInteger::Two(), DH_N_MinusOne);
81 CleanupClosePushL(DH_G);
83 CCryptoParams* keyParams = CCryptoParams::NewLC();
85 TRAPD_LOG(err,keyParams->AddL(DH_N, KDhKeyParameterNUid));
86 TRAP_LOG(err,keyParams->AddL(DH_G, KDhKeyParameterGUid));
88 //****************************************************
89 //Create Key Pair and Key Pair Generator Objects
90 CKeyPair* keyPair = NULL;
91 CKeyPairGenerator * keypairImpl = NULL;
93 INFO_PRINTF1(_L("Generating Key Pair..."));
95 // create a key pair generator implementation interface
96 TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
97 KDHKeyPairGeneratorUid,
99 CleanupStack::PushL(keypairImpl);
102 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(NULL, *keyParams, keyPair));
104 CleanupStack::PushL(keyPair);
106 //*****************************************************
108 CKeyAgreement* keyAgreementImpl = NULL;
110 TRAP(err,CKeyAgreementFactory::CreateKeyAgreementL(keyAgreementImpl,
112 keyPair->PrivateKey(),
115 if(keyAgreementImpl && (err == KErrNone))
118 CleanupStack::PushL(keyAgreementImpl);
120 INFO_PRINTF1(_L("** Successfully Loaded Key Agreement Object **"));
122 //Define a pointer of type TCharacteristics in order to store the key agreement
123 //object's characterisctics
124 const TCharacteristics* chars(NULL);
126 //Retrieve the characteristics for the key agreement signer implementation object
127 TRAP_LOG(err, keyAgreementImpl->GetCharacteristicsL(chars));
129 //Static cast the characteristics to type TKeyAgreementCharacteristics
130 const TKeyAgreementCharacteristics* keyagreeChars = static_cast<const TKeyAgreementCharacteristics*>(chars);
132 //Retrieve all the Common characteristics that are required for the test
133 TVariantPtrC exInterfaceUid;
134 TVariantPtrC exAlgorithmUid;
135 TVariantPtrC exImplementationUid;
136 TVariantPtrC exCreatorName;
137 TBool exFIPSApproved;
138 TBool exHardwareSupported;
139 TInt exMaxConcurrencySupported;
140 TVariantPtrC exAlgorithmName;
144 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
145 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
146 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
147 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
148 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
149 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
150 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
151 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
152 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
153 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput))
155 ERR_PRINTF1(_L("** .INI Error: Expected Key Agreement/Common Characteristics Not Located **"));
156 SetTestStepResult(EFail);
161 INFO_PRINTF1(_L("** Checking Key Agreement/Common Characteristics.... **"));
163 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
165 //Retrieve the Common Characteristics from TKeyAgreementCharacteristics
166 const TCommonCharacteristics* keyagreeCommonChars = &keyagreeChars->cmn;
170 //Perform Key Agreement/Common Characteristic Checks
171 if(pluginCheck->checkCommonCharacteristics(keyagreeCommonChars,
178 exMaxConcurrencySupported,
184 INFO_PRINTF1(_L("** PASS : Key Agreement/Common characteristics successfully match expected values **"));
185 SetTestStepResult(EPass);
189 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
192 CleanupStack::PopAndDestroy(pluginCheck);
195 CleanupStack::PopAndDestroy(keyAgreementImpl);
199 ERR_PRINTF2(_L("*** FAIL: Failed to Create Key Agreement Object - %d ***"), err);
202 CleanupStack::PopAndDestroy(6,&DH_N);
207 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
208 return TestStepResult();
211 TVerdict CPluginCharsKeyAgreeStep::doTestStepPostambleL()
213 return TestStepResult();