os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharskeyagreestep.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharskeyagreestep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,214 @@
     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 "plugincharskeyagreestep.h"
    1.28 +#include "plugincharschecker.h"
    1.29 +
    1.30 +#include <cryptospi/keypair.h>
    1.31 +#include <cryptospi/cryptokeypairgeneratorapi.h>
    1.32 +#include <cryptospi/cryptokeyagreementapi.h>
    1.33 +
    1.34 +using namespace CryptoSpi;
    1.35 +
    1.36 +CPluginCharsKeyAgreeStep::~CPluginCharsKeyAgreeStep()
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +CPluginCharsKeyAgreeStep::CPluginCharsKeyAgreeStep()
    1.41 +	{
    1.42 +	SetTestStepName(KPluginCharsKeyAgreeStep);
    1.43 +	}
    1.44 +
    1.45 +TVerdict CPluginCharsKeyAgreeStep::doTestStepPreambleL()
    1.46 +	{
    1.47 +	SetTestStepResult(EPass);
    1.48 +	return TestStepResult();
    1.49 +	}
    1.50 +				
    1.51 +TVerdict CPluginCharsKeyAgreeStep::doTestStepL()
    1.52 +	{
    1.53 +	
    1.54 +	INFO_PRINTF1(_L("Plugin Characteristics - Key Agreement Chracteristics"));
    1.55 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    1.56 +		
    1.57 +	if (TestStepResult()==EPass)
    1.58 +		{
    1.59 +		
    1.60 +		//Assume faliure, unless all is successful
    1.61 +		SetTestStepResult(EFail);
    1.62 +		
    1.63 +		TVariantPtrC algorithmUid;
    1.64 +		
    1.65 +		//Each of the individual parameters required to create the Key Agreement object
    1.66 +		//are read in from the specified INI configuration file					
    1.67 +		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
    1.68 +			{
    1.69 +			ERR_PRINTF1(_L("** .INI Error: Key Agreement Object Arguments Not Located **"));
    1.70 +			SetTestStepResult(EFail);
    1.71 +			}
    1.72 +		else
    1.73 +			{
    1.74 +			INFO_PRINTF1(_L("Creating Primes and Base Integers...")); 
    1.75 +	 		 
    1.76 +			RInteger DH_N = RInteger::NewPrimeL(64);
    1.77 +			CleanupClosePushL(DH_N);
    1.78 +			
    1.79 +			RInteger DH_N_MinusOne = RInteger::NewL(DH_N);
    1.80 +			CleanupClosePushL(DH_N_MinusOne);
    1.81 +			DH_N_MinusOne-=1;
    1.82 +			
    1.83 +			RInteger DH_G = RInteger::NewRandomL(TInteger::Two(), DH_N_MinusOne);	
    1.84 +			CleanupClosePushL(DH_G);
    1.85 +			
    1.86 +			CCryptoParams* keyParams = CCryptoParams::NewLC(); 
    1.87 +						
    1.88 +			TRAPD_LOG(err,keyParams->AddL(DH_N, KDhKeyParameterNUid));
    1.89 +			TRAP_LOG(err,keyParams->AddL(DH_G, KDhKeyParameterGUid));
    1.90 +			
    1.91 +			//****************************************************
    1.92 +			//Create Key Pair and Key Pair Generator Objects
    1.93 +   			CKeyPair* keyPair = NULL;
    1.94 +			CKeyPairGenerator * keypairImpl = NULL;
    1.95 +			
    1.96 +			INFO_PRINTF1(_L("Generating Key Pair..."));
    1.97 +			
    1.98 +			// create a key pair generator implementation interface
    1.99 +			TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
   1.100 +																			KDHKeyPairGeneratorUid, 
   1.101 +																			keyParams));								
   1.102 +			CleanupStack::PushL(keypairImpl);
   1.103 +
   1.104 +			// Create a Key Pair	
   1.105 +			TRAP_LOG(err,keypairImpl->GenerateKeyPairL(NULL, *keyParams, keyPair));
   1.106 +			
   1.107 +			CleanupStack::PushL(keyPair);
   1.108 +			
   1.109 +			//*****************************************************
   1.110 +			
   1.111 +			CKeyAgreement* keyAgreementImpl = NULL;	
   1.112 +				
   1.113 +			TRAP(err,CKeyAgreementFactory::CreateKeyAgreementL(keyAgreementImpl,
   1.114 +																algorithmUid,
   1.115 +																keyPair->PrivateKey(),
   1.116 +																keyParams));
   1.117 +			
   1.118 +			if(keyAgreementImpl && (err == KErrNone))
   1.119 +				{
   1.120 +				
   1.121 +				CleanupStack::PushL(keyAgreementImpl);
   1.122 +				
   1.123 +				INFO_PRINTF1(_L("** Successfully Loaded Key Agreement Object **"));
   1.124 +				
   1.125 +				//Define a pointer of type TCharacteristics in order to store the key agreement
   1.126 +				//object's characterisctics	
   1.127 +				const TCharacteristics* chars(NULL);
   1.128 +							
   1.129 +				//Retrieve the characteristics for the key agreement signer implementation object
   1.130 +				TRAP_LOG(err, keyAgreementImpl->GetCharacteristicsL(chars));
   1.131 +				
   1.132 +				//Static cast the characteristics to type TKeyAgreementCharacteristics
   1.133 +				const TKeyAgreementCharacteristics* keyagreeChars = static_cast<const TKeyAgreementCharacteristics*>(chars);
   1.134 +
   1.135 +				//Retrieve all the Common characteristics that are required for the test
   1.136 +				TVariantPtrC exInterfaceUid;
   1.137 +				TVariantPtrC exAlgorithmUid;
   1.138 +				TVariantPtrC exImplementationUid;
   1.139 +				TVariantPtrC exCreatorName;
   1.140 +				TBool exFIPSApproved;
   1.141 +				TBool exHardwareSupported;
   1.142 +				TInt exMaxConcurrencySupported;
   1.143 +				TVariantPtrC exAlgorithmName;
   1.144 +				TInt exLatency;
   1.145 +				TInt exThroughput;
   1.146 +				
   1.147 +				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
   1.148 +					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
   1.149 +					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
   1.150 +					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
   1.151 +					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
   1.152 +					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
   1.153 +					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
   1.154 +					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
   1.155 +					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
   1.156 +					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput))
   1.157 +					{
   1.158 +					ERR_PRINTF1(_L("** .INI Error: Expected Key Agreement/Common Characteristics Not Located **"));
   1.159 +					SetTestStepResult(EFail);
   1.160 +					}
   1.161 +				else
   1.162 +					{
   1.163 +			
   1.164 +					INFO_PRINTF1(_L("** Checking Key Agreement/Common Characteristics.... **"));
   1.165 +					
   1.166 +					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
   1.167 +					
   1.168 +					//Retrieve the Common Characteristics from TKeyAgreementCharacteristics 
   1.169 +					const TCommonCharacteristics* keyagreeCommonChars = &keyagreeChars->cmn;
   1.170 +					
   1.171 +					TPtrC errorMessage;
   1.172 +					
   1.173 +					//Perform Key Agreement/Common Characteristic Checks
   1.174 +					if(pluginCheck->checkCommonCharacteristics(keyagreeCommonChars,
   1.175 +																exInterfaceUid,
   1.176 +																exAlgorithmUid,
   1.177 +																exImplementationUid,
   1.178 +																exCreatorName,
   1.179 +																exFIPSApproved,
   1.180 +																exHardwareSupported,
   1.181 +																exMaxConcurrencySupported,
   1.182 +																exAlgorithmName,
   1.183 +																exLatency,
   1.184 +																exThroughput,
   1.185 +																errorMessage))
   1.186 +						{
   1.187 +						INFO_PRINTF1(_L("** PASS : Key Agreement/Common characteristics successfully match expected values **"));
   1.188 +						SetTestStepResult(EPass);	
   1.189 +						}
   1.190 +					else
   1.191 +						{
   1.192 +						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
   1.193 +						}
   1.194 +					
   1.195 +					CleanupStack::PopAndDestroy(pluginCheck);
   1.196 +					}
   1.197 +				
   1.198 +				CleanupStack::PopAndDestroy(keyAgreementImpl);
   1.199 +				}
   1.200 +			else
   1.201 +				{
   1.202 +				ERR_PRINTF2(_L("*** FAIL: Failed to Create Key Agreement Object - %d ***"), err);	
   1.203 +				}
   1.204 +				
   1.205 +			CleanupStack::PopAndDestroy(6,&DH_N);
   1.206 +			}
   1.207 +		
   1.208 +		}
   1.209 +		
   1.210 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
   1.211 +	return TestStepResult();
   1.212 +	}
   1.213 +
   1.214 +TVerdict CPluginCharsKeyAgreeStep::doTestStepPostambleL()
   1.215 +	{
   1.216 +	return TestStepResult();
   1.217 +	}