os/security/crypto/weakcryptospi/test/tplugins/src/tplugin02/pluginentry.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tplugins/src/tplugin02/pluginentry.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,381 @@
     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 +* plugin entry implementation
    1.19 +* plugin entry implementation
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +/**
    1.25 + @file
    1.26 +*/
    1.27 +
    1.28 +#include "pluginentry.h"
    1.29 +#include <cryptospi/keypair.h>
    1.30 +#include "pluginconfig.h" 
    1.31 +#include "md5impl.h"
    1.32 +#include "hmacimpl.h"
    1.33 +#include <cryptospi/keys.h>
    1.34 +#include "desimpl.h"
    1.35 +#include "desextendimpl.h"
    1.36 +#include "rsaimpl.h"
    1.37 +#include "rsakeypairgenimpl.h"
    1.38 +#include "randomimpl.h"
    1.39 +#include "rsasignerimpl.h"
    1.40 +#include "dhimpl.h"
    1.41 +#include "dhkeypairgenimpl.h"
    1.42 +#include <cryptospi/cryptospidef.h>	
    1.43 +
    1.44 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
    1.45 +#include "rijndaelimpl.h"
    1.46 +#include "macimpl.h"
    1.47 +
    1.48 +#endif
    1.49 +
    1.50 +using namespace SoftwareCrypto;
    1.51 +
    1.52 +EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins)
    1.53 +	{
    1.54 +	const TCharacteristics** ptr(0);
    1.55 +	switch (aInterface.iUid)
    1.56 +		{
    1.57 +	case KSymmetricCipherInterface:
    1.58 +		{
    1.59 +		aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*);
    1.60 +		ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0];			
    1.61 +		}
    1.62 +		break;
    1.63 +
    1.64 +	case KAsymmetricCipherInterface:
    1.65 +		{
    1.66 +		aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*);
    1.67 +		ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0];			
    1.68 +		}
    1.69 +		break;
    1.70 +		
    1.71 +	case KHashInterface:
    1.72 +		{
    1.73 +		aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
    1.74 +		ptr = (const TCharacteristics**) &KHashCharacteristics[0];			
    1.75 +		}
    1.76 +		break;
    1.77 +
    1.78 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
    1.79 +	case KMacInterface:
    1.80 +		{
    1.81 +		aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*);
    1.82 +		ptr = (const TCharacteristics**) &KMacCharacteristics[0];
    1.83 +		}
    1.84 +		break;
    1.85 +#endif
    1.86 +
    1.87 +	case KRandomInterface:
    1.88 +		{
    1.89 +		aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
    1.90 +		ptr= (const TCharacteristics**) &KRandomCharacteristics[0];			
    1.91 +		}
    1.92 +		break;
    1.93 +		
    1.94 +	case KKeypairGeneratorInterface:
    1.95 +		{
    1.96 +		aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*);
    1.97 +		ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0];			
    1.98 +		}
    1.99 +		break;
   1.100 +		
   1.101 +	case KSignerInterface:
   1.102 +		{
   1.103 +		aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
   1.104 +		ptr = (const TCharacteristics**) &KSignerCharacteristics[0];
   1.105 +		}
   1.106 +		break;
   1.107 +		
   1.108 +	case KKeyAgreementInterface:
   1.109 +		{
   1.110 +		aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*);
   1.111 +		ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0];
   1.112 +		}
   1.113 +		break;
   1.114 +
   1.115 +	default:;
   1.116 +		}
   1.117 +		
   1.118 +	return ptr;
   1.119 +	}
   1.120 +
   1.121 +
   1.122 +EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt)
   1.123 +	{
   1.124 +	switch (aImplementationUid.iUid)
   1.125 +		{
   1.126 +		case KTestPlugin02Md5_1:
   1.127 +			{
   1.128 +			aExt = CMD5Impl::CreateExtendedCharacteristicsL();	
   1.129 +			}
   1.130 +		    break;
   1.131 +	   
   1.132 +		case KTestPlugin02Random_1:
   1.133 +		case KTestPlugin02Random_2:
   1.134 +			{
   1.135 +			aExt = CRandomImpl::CreateExtendedCharacteristicsL();	
   1.136 +			}
   1.137 +		   	break;
   1.138 +
   1.139 +		case KTestPlugin02Des_1:
   1.140 +			{
   1.141 +			aExt = CDesExtendImpl::CreateExtendedCharacteristicsL();	
   1.142 +			}
   1.143 +		   	break;
   1.144 +	   
   1.145 +		case KTestPlugin02Des_2:
   1.146 +			{
   1.147 +			aExt = CDesImpl::CreateExtendedCharacteristicsL();	
   1.148 +			}
   1.149 +		   	break;
   1.150 +	
   1.151 +		case KTestPlugin02Rsa_1:   
   1.152 +		case KTestPlugin02Rsa_2:
   1.153 +			{
   1.154 +			aExt = CRSAImpl::CreateExtendedCharacteristicsL();	
   1.155 +			}
   1.156 +		    break;
   1.157 + 
   1.158 +	 	case KTestPlugin02RsaKeyGen_1:
   1.159 +		 	{
   1.160 +		 	aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL();	
   1.161 +		 	}
   1.162 +		   	break;
   1.163 +	   
   1.164 +		case KTestPlugin02DHKeyGen_1:
   1.165 +			{
   1.166 +			aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();	
   1.167 +			}
   1.168 +		   	break;
   1.169 +	   
   1.170 +		case KTestPlugin02RsaSigner_1:
   1.171 +			{
   1.172 +			aExt = CRSASignerImpl::CreateExtendedCharacteristicsL();	
   1.173 +			}
   1.174 +		   	break;
   1.175 +	   
   1.176 +		case KTestPlugin02DHKeyAgree_1:
   1.177 +			{
   1.178 +			aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();	
   1.179 +			}
   1.180 +		  	break;
   1.181 +			
   1.182 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   1.183 +		case KTestPlugin02XcbcMac96:
   1.184 +		case KTestPlugin02XcbcPrf128:
   1.185 +		case KTestPlugin02Aes:
   1.186 +			{
   1.187 +			aExt = CRijndaelImpl::CreateExtendedCharacteristicsL();
   1.188 +			}
   1.189 +			break;
   1.190 +#endif
   1.191 +		default:
   1.192 +			{
   1.193 +			User::Leave(KErrNotSupported);	
   1.194 +			}
   1.195 +		}
   1.196 +	}
   1.197 +
   1.198 +	
   1.199 +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin,
   1.200 +														TUid aImplementationId,
   1.201 +														const CKey& aKey,
   1.202 +														TUid aCryptoMode,
   1.203 +														TUid aPaddingMode,
   1.204 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.205 +	{
   1.206 +	switch (aImplementationId.iUid)
   1.207 +		{
   1.208 +
   1.209 +		case KTestPlugin02Rsa_1:
   1.210 +		case KTestPlugin02Rsa_2:
   1.211 +			{
   1.212 +			aPlugin = CRSAImpl::NewL(aImplementationId, aKey, aCryptoMode, aPaddingMode);
   1.213 +			}
   1.214 +			break;
   1.215 +		
   1.216 +		default:
   1.217 +			User::Leave(KErrNotFound);
   1.218 +		}	
   1.219 +	}
   1.220 +	
   1.221 +														
   1.222 +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin,
   1.223 +														TUid aImplementationId,
   1.224 +														const CKey& aKey,
   1.225 +														TUid aPaddingMode,
   1.226 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.227 +	{
   1.228 +	switch (aImplementationId.iUid)
   1.229 +		{
   1.230 +		case KTestPlugin02RsaSigner_1:
   1.231 +			{
   1.232 +			aPlugin = CRSASignerImpl::NewL(aImplementationId, aKey, aPaddingMode);
   1.233 +			}	
   1.234 +			break;
   1.235 +
   1.236 +		default:
   1.237 +			User::Leave(KErrNotFound);
   1.238 +			}
   1.239 +	}
   1.240 +														
   1.241 +																								
   1.242 +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& /*aPlugin*/,
   1.243 +															TUid /*aImplementationId*/,
   1.244 +															const CKey& /*aKey*/,
   1.245 +															TUid /*aPaddingMode*/,
   1.246 +															const CCryptoParams* /*aAlgorithmParams*/)
   1.247 +	{
   1.248 +	User::Leave(KErrNotFound);
   1.249 +	}																
   1.250 +
   1.251 +
   1.252 +EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
   1.253 +											TUid aImplementationId,
   1.254 +											TUid aOperationMode,
   1.255 +											const CKey* aKey,
   1.256 +											const CCryptoParams* /*aAlgorithmParams*/)
   1.257 +	{
   1.258 +	aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey);
   1.259 +	}
   1.260 +
   1.261 +
   1.262 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   1.263 +EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
   1.264 +											TUid aImplementationId,
   1.265 +											const CCryptoParams* /*aAlgorithmParams*/)
   1.266 +	{
   1.267 +	aPlugin=CSoftwareHash::NewL(aImplementationId);
   1.268 +	}
   1.269 +
   1.270 +
   1.271 +EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin,
   1.272 +											const TUid aImplementationId,
   1.273 +											const CKey& aKey,
   1.274 +											const CCryptoParams* aAlgorithmParams)
   1.275 +	{
   1.276 +	aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams);
   1.277 +	}
   1.278 +#endif
   1.279 +
   1.280 +
   1.281 +EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin,
   1.282 +														TUid aImplementationId,
   1.283 +														const CKey& aPrivateKey,
   1.284 +														const CCryptoParams* aAlgorithmParams)
   1.285 +	{
   1.286 +	// create requested key agreement implementation in this plugin
   1.287 +	switch (aImplementationId.iUid)
   1.288 +		{
   1.289 +		case KTestPlugin02DHKeyAgree_1:
   1.290 +			{
   1.291 +			aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams);
   1.292 +			}
   1.293 +			break;
   1.294 +
   1.295 +		default:
   1.296 +			User::Leave(KErrNotFound);
   1.297 +		}	
   1.298 +	}
   1.299 +	
   1.300 +														
   1.301 +EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin,
   1.302 +														TUid aImplementationId,
   1.303 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.304 +	{
   1.305 +	//create requested key pair generator implementation in this plugin
   1.306 +	switch (aImplementationId.iUid)
   1.307 +		{
   1.308 +			
   1.309 +		case KTestPlugin02RsaKeyGen_1:
   1.310 +			{
   1.311 +			aPlugin = CRSAKeyPairGenImpl::NewL(aImplementationId);
   1.312 +			}
   1.313 +			break;
   1.314 +			
   1.315 +		case KTestPlugin02DHKeyGen_1:
   1.316 +			{
   1.317 +			aPlugin = CDHKeyPairGenImpl::NewL(aImplementationId);
   1.318 +			}
   1.319 +			break;
   1.320 +			
   1.321 +		default:
   1.322 +			User::Leave(KErrNotFound);
   1.323 +			}	
   1.324 +	}
   1.325 +	
   1.326 +														
   1.327 +EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin,
   1.328 +												TUid aImplementationId,
   1.329 +												const CCryptoParams* /*aAlgorithmParams*/)
   1.330 +	{
   1.331 +	
   1.332 +	switch (aImplementationId.iUid)
   1.333 +		{
   1.334 +		
   1.335 +		case KTestPlugin02Random_1:
   1.336 +		case KTestPlugin02Random_2:
   1.337 +			{
   1.338 +			aPlugin=CRandomImpl::NewL(aImplementationId);
   1.339 +			}	
   1.340 +			break;
   1.341 +
   1.342 +		default:
   1.343 +			User::Leave(KErrNotFound);
   1.344 +		}
   1.345 +	}	
   1.346 +
   1.347 +
   1.348 +EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin,
   1.349 +														TUid aImplementationId,
   1.350 +														const CKey& aKey,
   1.351 +														TUid aCryptoMode,
   1.352 +														TUid aOperationMode,
   1.353 +														TUid aPadding,
   1.354 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.355 +	{
   1.356 +
   1.357 +	switch (aImplementationId.iUid)
   1.358 +		{
   1.359 +		case KTestPlugin02Des_1:
   1.360 +			{
   1.361 +			aPlugin=CDesExtendImpl::NewL(aImplementationId, aKey, aCryptoMode, aOperationMode, aPadding);
   1.362 +			}	
   1.363 +			break;
   1.364 +		
   1.365 +		case KTestPlugin02Des_2:
   1.366 +			{
   1.367 +			aPlugin=CDesImpl::NewL(aImplementationId, aKey, aCryptoMode, aOperationMode, aPadding);
   1.368 +			}	
   1.369 +			break;
   1.370 +
   1.371 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
   1.372 +		case KTestPlugin02Aes:
   1.373 +			{
   1.374 +			aPlugin=CRijndaelImpl::NewL(aKey, aCryptoMode, aOperationMode, aPadding, KTestPlugin02AesUid);
   1.375 +			}
   1.376 +			break;
   1.377 +#endif
   1.378 +
   1.379 +		default:
   1.380 +			User::Leave(KErrNotFound);
   1.381 +		}
   1.382 +	
   1.383 +	}
   1.384 +