os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,448 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 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 "keypair.h"
    1.30 +#include "pluginconfig.h"
    1.31 +#include "md2impl.h"
    1.32 +#include "md5impl.h"
    1.33 +#include "md4impl.h"
    1.34 +#include "sha1impl.h"
    1.35 +#include "hmacimpl.h"
    1.36 +#include "keys.h"
    1.37 +#include "3desimpl.h"
    1.38 +#include "desimpl.h"
    1.39 +#include "rc2impl.h"
    1.40 +#include "arc4impl.h"
    1.41 +#include "randomimpl.h"
    1.42 +#include "rijndaelimpl.h"
    1.43 +#include "randomimpl.h"
    1.44 +#include "rsaimpl.h"
    1.45 +#include "dhimpl.h"
    1.46 +#include "dhkeypairgenimpl.h"
    1.47 +#include "rsakeypairgenimpl.h"
    1.48 +#include "dsakeypairgenimpl.h"
    1.49 +#include "dsasignerimpl.h"
    1.50 +#include "dsaverifyimpl.h"
    1.51 +#include "rsasignerimpl.h"
    1.52 +#include "rsaverifyimpl.h"
    1.53 +#include <cryptospi/cryptospidef.h>
    1.54 +
    1.55 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
    1.56 +	#include "macimpl.h"
    1.57 +#endif
    1.58 +
    1.59 +
    1.60 +using namespace SoftwareCrypto;
    1.61 +
    1.62 +EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins)
    1.63 +	{
    1.64 +	const TCharacteristics** ptr(0);
    1.65 +	switch (aInterface.iUid)
    1.66 +		{
    1.67 +	case KHashInterface:
    1.68 +		{
    1.69 +		aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
    1.70 +		ptr = (const TCharacteristics**) &KHashCharacteristics[0];
    1.71 +		}
    1.72 +		break;
    1.73 +		
    1.74 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT		
    1.75 +		
    1.76 +	case KMacInterface:
    1.77 +		{
    1.78 +		aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*);
    1.79 +		ptr = (const TCharacteristics**) &KMacCharacteristics[0];
    1.80 +		}
    1.81 +		break;
    1.82 +		
    1.83 +#endif
    1.84 +		
    1.85 +	case KRandomInterface:
    1.86 +		{
    1.87 +		aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
    1.88 +		ptr= (const TCharacteristics**) &KRandomCharacteristics[0];
    1.89 +		}
    1.90 +		break;
    1.91 +
    1.92 +	case KSymmetricCipherInterface:
    1.93 +		{
    1.94 +		aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*);
    1.95 +		ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0];
    1.96 +		}
    1.97 +		break;
    1.98 +
    1.99 +	case KAsymmetricCipherInterface:
   1.100 +		{
   1.101 +		aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*);
   1.102 +		ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0];
   1.103 +		}
   1.104 +		break;
   1.105 +
   1.106 +	case KSignerInterface:
   1.107 +		{
   1.108 +		aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
   1.109 +		ptr = (const TCharacteristics**) &KSignerCharacteristics[0];
   1.110 +		}
   1.111 +		break;
   1.112 +
   1.113 +	case KVerifierInterface:
   1.114 +		{
   1.115 +		aNumPlugins=sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
   1.116 +		ptr = (const TCharacteristics**) &KVerifierCharacteristics[0];
   1.117 +		}
   1.118 +		break;
   1.119 +
   1.120 +	case KKeyAgreementInterface:
   1.121 +		{
   1.122 +		aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*);
   1.123 +		ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0];
   1.124 +		}
   1.125 +		break;
   1.126 +
   1.127 +	case KKeypairGeneratorInterface:
   1.128 +		{
   1.129 +		aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*);
   1.130 +		ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0];
   1.131 +		}
   1.132 +		break;
   1.133 +
   1.134 +	case KKeyGeneratorInterface:
   1.135 +		break;
   1.136 +		
   1.137 +	default:;
   1.138 +		}
   1.139 +		
   1.140 +	return ptr;
   1.141 +	}
   1.142 +
   1.143 +EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt)
   1.144 +	{
   1.145 +	switch (aImplementationUid.iUid)
   1.146 +		{
   1.147 +		
   1.148 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   1.149 +	case KCryptoPluginMacHashMd2:   
   1.150 +#endif
   1.151 +	
   1.152 +	case KCryptoPluginMd2:
   1.153 +	   aExt = CMD2Impl::CreateExtendedCharacteristicsL();
   1.154 +	   break;
   1.155 +	   
   1.156 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   1.157 +	case KCryptoPluginMacHashMd5:   
   1.158 +#endif
   1.159 +	
   1.160 +	case KCryptoPluginMd5:
   1.161 +	   aExt = CMD5Impl::CreateExtendedCharacteristicsL();
   1.162 +	   break;
   1.163 +	   
   1.164 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   1.165 +	case KCryptoPluginMacHashSha1:   
   1.166 +#endif
   1.167 +	
   1.168 +	case KCryptoPluginSha1:
   1.169 +	   aExt = CSHA1Impl::CreateExtendedCharacteristicsL();
   1.170 +	   break;
   1.171 +	   
   1.172 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   1.173 +	case KCryptoPluginMacHashMd4:   
   1.174 +#endif
   1.175 +	
   1.176 +	case KCryptoPluginMd4:
   1.177 +	   aExt = CMD4Impl::CreateExtendedCharacteristicsL();
   1.178 +	   break;
   1.179 +	case KCryptoPluginRandom:
   1.180 +	   aExt = CRandomImpl::CreateExtendedCharacteristicsL();
   1.181 +	   break;
   1.182 +	case KCryptoPluginDes:
   1.183 +	   aExt = CDesImpl::CreateExtendedCharacteristicsL();
   1.184 +	   break;
   1.185 +	case KCryptoPlugin3Des:
   1.186 +	   aExt = C3DesImpl::CreateExtendedCharacteristicsL();
   1.187 +	   break;
   1.188 +	case KCryptoPluginRc2:
   1.189 +	   aExt = CRc2Impl::CreateExtendedCharacteristicsL();
   1.190 +	   break;
   1.191 +	case KCryptoPluginArc4:
   1.192 +	   aExt = CArc4Impl::CreateExtendedCharacteristicsL();
   1.193 +	   break;
   1.194 +	   
   1.195 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   1.196 +	case KCryptoPluginMacAesXcbcMac96:   
   1.197 +	case KCryptoPluginMacAesXcbcPrf128:
   1.198 +#endif	
   1.199 +	
   1.200 +	case KCryptoPluginAes:
   1.201 +	   aExt = CRijndaelImpl::CreateExtendedCharacteristicsL();
   1.202 +	   break;
   1.203 +	case KCryptoPluginRsaCipher:
   1.204 +	   aExt = CRSAImpl::CreateExtendedCharacteristicsL();
   1.205 +	   break;
   1.206 +	case KCryptoPluginRsaSigner:
   1.207 +	   aExt = CRSASignerImpl::CreateExtendedCharacteristicsL();
   1.208 +	   break;
   1.209 +	case KCryptoPluginDsaSigner:
   1.210 +	   aExt = CDSASignerImpl::CreateExtendedCharacteristicsL();
   1.211 +	   break;
   1.212 +	case KCryptoPluginRsaVerifier:
   1.213 +	   aExt = CRSAVerifierImpl::CreateExtendedCharacteristicsL();
   1.214 +	   break;
   1.215 +	case KCryptoPluginDsaVerifier:
   1.216 +	   aExt = CDSAVerifierImpl::CreateExtendedCharacteristicsL();
   1.217 +	   break;
   1.218 +	case KCryptoPluginDhKeyAgreement:
   1.219 +	   aExt = CDHImpl::CreateExtendedCharacteristicsL();
   1.220 +	   break;
   1.221 +	case KCryptoPluginDhKeyPairGen:
   1.222 +	   aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();
   1.223 +	   break;
   1.224 +	case KCryptoPluginRsaKeyPairGen:
   1.225 +	   aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL();
   1.226 +	   break;
   1.227 +	case KCryptoPluginDsaKeyPairGen:
   1.228 +	   aExt = CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL();
   1.229 +	   break;
   1.230 +	default:
   1.231 +		User::Leave(KErrNotSupported);
   1.232 +		}
   1.233 +	}
   1.234 +	
   1.235 +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin,
   1.236 +														TUid aImplementationId,
   1.237 +														const CKey& aKey,
   1.238 +														TUid aCryptoMode,
   1.239 +														TUid aPaddingMode,
   1.240 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.241 +	{
   1.242 +	switch (aImplementationId.iUid)
   1.243 +		{
   1.244 +	case KCryptoPluginRsaCipher:
   1.245 +		{
   1.246 +		aPlugin = CRSAImpl::NewL(aKey, aCryptoMode, aPaddingMode);
   1.247 +		}
   1.248 +		break;
   1.249 +		
   1.250 +	default:
   1.251 +		User::Leave(KErrNotFound);
   1.252 +		}
   1.253 +	}
   1.254 +	
   1.255 +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin,
   1.256 +														TUid aImplementationId,
   1.257 +														const CKey& aKey,
   1.258 +														TUid aPaddingMode,
   1.259 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.260 +	{
   1.261 +	switch (aImplementationId.iUid)
   1.262 +		{
   1.263 +	case KCryptoPluginRsaSigner:
   1.264 +		{
   1.265 +		aPlugin = CRSASignerImpl::NewL(aKey, aPaddingMode);
   1.266 +		}	
   1.267 +		break;
   1.268 +
   1.269 +	case KCryptoPluginDsaSigner:
   1.270 +		{
   1.271 +		aPlugin = CDSASignerImpl::NewL(aKey);
   1.272 +		}	
   1.273 +		break;
   1.274 +
   1.275 +	default:
   1.276 +		User::Leave(KErrNotFound);
   1.277 +		}
   1.278 +	}
   1.279 +	
   1.280 +EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& aPlugin,
   1.281 +															TUid aImplementationId,
   1.282 +															const CKey& aKey,
   1.283 +															TUid aPaddingMode,
   1.284 +															const CCryptoParams* /*aAlgorithmParams*/)
   1.285 +	{
   1.286 +	switch (aImplementationId.iUid)
   1.287 +		{
   1.288 +	case KCryptoPluginRsaVerifier:
   1.289 +		aPlugin = CRSAVerifierImpl::NewL(aKey, aPaddingMode);
   1.290 +		break;
   1.291 +	
   1.292 +	case KCryptoPluginDsaVerifier:
   1.293 +		{
   1.294 +		aPlugin = CDSAVerifierImpl::NewL(aKey);
   1.295 +		}	
   1.296 +		break;
   1.297 +		
   1.298 +	default:
   1.299 +		User::Leave(KErrNotFound);
   1.300 +		}
   1.301 +	}
   1.302 +
   1.303 +EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
   1.304 +											TUid aImplementationId,
   1.305 +											TUid aOperationMode,
   1.306 +											const CKey* aKey,
   1.307 +											const CCryptoParams* /*aAlgorithmParams*/)
   1.308 +	{
   1.309 +	aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey);
   1.310 +	}
   1.311 +
   1.312 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
   1.313 +
   1.314 +EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
   1.315 +											TUid aImplementationId,
   1.316 +											const CCryptoParams* /*aAlgorithmParams*/)
   1.317 +	{
   1.318 +	aPlugin=CSoftwareHash::NewL(aImplementationId);
   1.319 +	}
   1.320 +
   1.321 +EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin,
   1.322 +											const TUid aImplementationId,
   1.323 +											const CKey& aKey,
   1.324 +											const CCryptoParams* aAlgorithmParams)
   1.325 +	{
   1.326 +	aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams);
   1.327 +	}
   1.328 +
   1.329 +#endif
   1.330 +
   1.331 +EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin,
   1.332 +														TUid aImplementationId,
   1.333 +														const CKey& aPrivateKey,
   1.334 +														const CCryptoParams* aAlgorithmParams)
   1.335 +	{
   1.336 +	// create requested key agreement implementation in this plugin
   1.337 +	switch (aImplementationId.iUid)
   1.338 +		{
   1.339 +	case KCryptoPluginDhKeyAgreement:
   1.340 +		{
   1.341 +		aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams);
   1.342 +		}
   1.343 +		break;
   1.344 +
   1.345 +	default:
   1.346 +		User::Leave(KErrNotFound);
   1.347 +		}
   1.348 +	}
   1.349 +
   1.350 +EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin,
   1.351 +														TUid aImplementationId,
   1.352 +														const CCryptoParams* /*aAlgorithmParams*/)
   1.353 +	{
   1.354 +	// create requested key pair generator implementation in this plugin
   1.355 +	switch (aImplementationId.iUid)
   1.356 +		{
   1.357 +	case KCryptoPluginDhKeyPairGen:
   1.358 +		{
   1.359 +		aPlugin = CDHKeyPairGenImpl::NewL();
   1.360 +		}
   1.361 +		break;
   1.362 +		
   1.363 +	case KCryptoPluginRsaKeyPairGen:
   1.364 +		{
   1.365 +		aPlugin = CRSAKeyPairGenImpl::NewL();
   1.366 +		}
   1.367 +		break;
   1.368 +		
   1.369 +	case KCryptoPluginDsaKeyPairGen:
   1.370 +		{
   1.371 +		aPlugin = CDSAKeyPairGenImpl::NewL();
   1.372 +		}
   1.373 +		break;
   1.374 +		
   1.375 +	default:
   1.376 +		User::Leave(KErrNotFound);
   1.377 +		}
   1.378 +	}
   1.379 +	
   1.380 +EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin,
   1.381 +												TUid /*aImplementationId*/,
   1.382 +												const CCryptoParams* /*aAlgorithmParams*/)
   1.383 +	{
   1.384 +	aPlugin=CRandomImpl::NewL();
   1.385 +	}	
   1.386 +
   1.387 +EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin,
   1.388 +														TUid aImplementationId,
   1.389 +														const CKey& aKey,
   1.390 +														TUid aCryptoMode,
   1.391 +														TUid aOperationMode,
   1.392 +														TUid aPadding,
   1.393 +														const CCryptoParams* aAlgorithmParams)
   1.394 +	{
   1.395 +	switch (aImplementationId.iUid)
   1.396 +		{
   1.397 +	case KCryptoPluginAes:
   1.398 +		{
   1.399 +		aPlugin=CRijndaelImpl::NewL(
   1.400 +			aKey, aCryptoMode, aOperationMode, aPadding);
   1.401 +		}	
   1.402 +		break;
   1.403 +	case KCryptoPluginDes:
   1.404 +		{
   1.405 +		aPlugin=CDesImpl::NewL(
   1.406 +			aKey, aCryptoMode, aOperationMode, aPadding);
   1.407 +		}	
   1.408 +		break;
   1.409 +	case KCryptoPlugin3Des:
   1.410 +		{
   1.411 +		aPlugin=C3DesImpl::NewL(
   1.412 +			aKey, aCryptoMode, aOperationMode, aPadding);
   1.413 +		}	
   1.414 +		break;
   1.415 +	case KCryptoPluginRc2:
   1.416 +		{
   1.417 +		TInt effectiveKeyLenBits(CRc2Impl::KDefaultEffectiveKeyLenBits);
   1.418 +			
   1.419 +		if (aAlgorithmParams && aAlgorithmParams->IsPresent(KRC2EffectiveKeyLenBits))
   1.420 +			{
   1.421 +			effectiveKeyLenBits = aAlgorithmParams->GetTIntL(KRC2EffectiveKeyLenBits);
   1.422 +			if (effectiveKeyLenBits < 0)
   1.423 +				{
   1.424 +				User::Leave(KErrArgument);
   1.425 +				}
   1.426 +			}
   1.427 +		aPlugin=CRc2Impl::NewL(
   1.428 +			aKey, aCryptoMode, aOperationMode, aPadding, effectiveKeyLenBits);
   1.429 +		}	
   1.430 +		break;				
   1.431 +	
   1.432 +	case KCryptoPluginArc4:
   1.433 +		{
   1.434 +		TInt discardBytes(CArc4Impl::KDefaultDiscardBytes);
   1.435 +		if (aAlgorithmParams && aAlgorithmParams->IsPresent(KARC4DiscardBytes))
   1.436 +			{
   1.437 +			discardBytes = aAlgorithmParams->GetTIntL(KARC4DiscardBytes);
   1.438 +			if (discardBytes < 0)
   1.439 +				{
   1.440 +				User::Leave(KErrArgument);
   1.441 +				}
   1.442 +			}		
   1.443 +		aPlugin=CArc4Impl::NewL(aKey, discardBytes);
   1.444 +		}
   1.445 +		break;
   1.446 +		
   1.447 +	default:
   1.448 +		User::Leave(KErrNotFound);
   1.449 +		}
   1.450 +	}
   1.451 +