crypto/weakcryptospi/test/tplugins/src/tplugin02/pluginentry.cpp
changeset 8 35751d3474b7
child 43 2f10d260163b
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * plugin entry implementation
       
    16 * plugin entry implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "pluginentry.h"
       
    26 #include "keypair.h"
       
    27 #include "pluginconfig.h" 
       
    28 #include "md5impl.h"
       
    29 #include "hmacimpl.h"
       
    30 #include "keys.h"
       
    31 #include "desimpl.h"
       
    32 #include "desextendimpl.h"
       
    33 #include "rsaimpl.h"
       
    34 #include "rsakeypairgenimpl.h"
       
    35 #include "randomimpl.h"
       
    36 #include "rsasignerimpl.h"
       
    37 #include "dhimpl.h"
       
    38 #include "dhkeypairgenimpl.h"
       
    39 #include <cryptospi/cryptospidef.h>	
       
    40 
       
    41 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
       
    42 #include "rijndaelimpl.h"
       
    43 #include "macimpl.h"
       
    44 
       
    45 #endif
       
    46 
       
    47 using namespace SoftwareCrypto;
       
    48 
       
    49 EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins)
       
    50 	{
       
    51 	const TCharacteristics** ptr(0);
       
    52 	switch (aInterface.iUid)
       
    53 		{
       
    54 	case KSymmetricCipherInterface:
       
    55 		{
       
    56 		aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*);
       
    57 		ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0];			
       
    58 		}
       
    59 		break;
       
    60 
       
    61 	case KAsymmetricCipherInterface:
       
    62 		{
       
    63 		aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*);
       
    64 		ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0];			
       
    65 		}
       
    66 		break;
       
    67 		
       
    68 	case KHashInterface:
       
    69 		{
       
    70 		aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
       
    71 		ptr = (const TCharacteristics**) &KHashCharacteristics[0];			
       
    72 		}
       
    73 		break;
       
    74 
       
    75 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
       
    76 	case KMacInterface:
       
    77 		{
       
    78 		aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*);
       
    79 		ptr = (const TCharacteristics**) &KMacCharacteristics[0];
       
    80 		}
       
    81 		break;
       
    82 #endif
       
    83 
       
    84 	case KRandomInterface:
       
    85 		{
       
    86 		aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
       
    87 		ptr= (const TCharacteristics**) &KRandomCharacteristics[0];			
       
    88 		}
       
    89 		break;
       
    90 		
       
    91 	case KKeypairGeneratorInterface:
       
    92 		{
       
    93 		aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*);
       
    94 		ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0];			
       
    95 		}
       
    96 		break;
       
    97 		
       
    98 	case KSignerInterface:
       
    99 		{
       
   100 		aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
       
   101 		ptr = (const TCharacteristics**) &KSignerCharacteristics[0];
       
   102 		}
       
   103 		break;
       
   104 		
       
   105 	case KKeyAgreementInterface:
       
   106 		{
       
   107 		aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*);
       
   108 		ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0];
       
   109 		}
       
   110 		break;
       
   111 
       
   112 	default:;
       
   113 		}
       
   114 		
       
   115 	return ptr;
       
   116 	}
       
   117 
       
   118 
       
   119 EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt)
       
   120 	{
       
   121 	switch (aImplementationUid.iUid)
       
   122 		{
       
   123 		case KTestPlugin02Md5_1:
       
   124 			{
       
   125 			aExt = CMD5Impl::CreateExtendedCharacteristicsL();	
       
   126 			}
       
   127 		    break;
       
   128 	   
       
   129 		case KTestPlugin02Random_1:
       
   130 		case KTestPlugin02Random_2:
       
   131 			{
       
   132 			aExt = CRandomImpl::CreateExtendedCharacteristicsL();	
       
   133 			}
       
   134 		   	break;
       
   135 
       
   136 		case KTestPlugin02Des_1:
       
   137 			{
       
   138 			aExt = CDesExtendImpl::CreateExtendedCharacteristicsL();	
       
   139 			}
       
   140 		   	break;
       
   141 	   
       
   142 		case KTestPlugin02Des_2:
       
   143 			{
       
   144 			aExt = CDesImpl::CreateExtendedCharacteristicsL();	
       
   145 			}
       
   146 		   	break;
       
   147 	
       
   148 		case KTestPlugin02Rsa_1:   
       
   149 		case KTestPlugin02Rsa_2:
       
   150 			{
       
   151 			aExt = CRSAImpl::CreateExtendedCharacteristicsL();	
       
   152 			}
       
   153 		    break;
       
   154  
       
   155 	 	case KTestPlugin02RsaKeyGen_1:
       
   156 		 	{
       
   157 		 	aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL();	
       
   158 		 	}
       
   159 		   	break;
       
   160 	   
       
   161 		case KTestPlugin02DHKeyGen_1:
       
   162 			{
       
   163 			aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();	
       
   164 			}
       
   165 		   	break;
       
   166 	   
       
   167 		case KTestPlugin02RsaSigner_1:
       
   168 			{
       
   169 			aExt = CRSASignerImpl::CreateExtendedCharacteristicsL();	
       
   170 			}
       
   171 		   	break;
       
   172 	   
       
   173 		case KTestPlugin02DHKeyAgree_1:
       
   174 			{
       
   175 			aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();	
       
   176 			}
       
   177 		  	break;
       
   178 			
       
   179 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
       
   180 		case KTestPlugin02XcbcMac96:
       
   181 		case KTestPlugin02XcbcPrf128:
       
   182 		case KTestPlugin02Aes:
       
   183 			{
       
   184 			aExt = CRijndaelImpl::CreateExtendedCharacteristicsL();
       
   185 			}
       
   186 			break;
       
   187 #endif
       
   188 		default:
       
   189 			{
       
   190 			User::Leave(KErrNotSupported);	
       
   191 			}
       
   192 		}
       
   193 	}
       
   194 
       
   195 	
       
   196 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin,
       
   197 														TUid aImplementationId,
       
   198 														const CKey& aKey,
       
   199 														TUid aCryptoMode,
       
   200 														TUid aPaddingMode,
       
   201 														const CCryptoParams* /*aAlgorithmParams*/)
       
   202 	{
       
   203 	switch (aImplementationId.iUid)
       
   204 		{
       
   205 
       
   206 		case KTestPlugin02Rsa_1:
       
   207 		case KTestPlugin02Rsa_2:
       
   208 			{
       
   209 			aPlugin = CRSAImpl::NewL(aImplementationId, aKey, aCryptoMode, aPaddingMode);
       
   210 			}
       
   211 			break;
       
   212 		
       
   213 		default:
       
   214 			User::Leave(KErrNotFound);
       
   215 		}	
       
   216 	}
       
   217 	
       
   218 														
       
   219 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin,
       
   220 														TUid aImplementationId,
       
   221 														const CKey& aKey,
       
   222 														TUid aPaddingMode,
       
   223 														const CCryptoParams* /*aAlgorithmParams*/)
       
   224 	{
       
   225 	switch (aImplementationId.iUid)
       
   226 		{
       
   227 		case KTestPlugin02RsaSigner_1:
       
   228 			{
       
   229 			aPlugin = CRSASignerImpl::NewL(aImplementationId, aKey, aPaddingMode);
       
   230 			}	
       
   231 			break;
       
   232 
       
   233 		default:
       
   234 			User::Leave(KErrNotFound);
       
   235 			}
       
   236 	}
       
   237 														
       
   238 																								
       
   239 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& /*aPlugin*/,
       
   240 															TUid /*aImplementationId*/,
       
   241 															const CKey& /*aKey*/,
       
   242 															TUid /*aPaddingMode*/,
       
   243 															const CCryptoParams* /*aAlgorithmParams*/)
       
   244 	{
       
   245 	User::Leave(KErrNotFound);
       
   246 	}																
       
   247 
       
   248 
       
   249 EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
       
   250 											TUid aImplementationId,
       
   251 											TUid aOperationMode,
       
   252 											const CKey* aKey,
       
   253 											const CCryptoParams* /*aAlgorithmParams*/)
       
   254 	{
       
   255 	aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey);
       
   256 	}
       
   257 
       
   258 
       
   259 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
       
   260 EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
       
   261 											TUid aImplementationId,
       
   262 											const CCryptoParams* /*aAlgorithmParams*/)
       
   263 	{
       
   264 	aPlugin=CSoftwareHash::NewL(aImplementationId);
       
   265 	}
       
   266 
       
   267 
       
   268 EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin,
       
   269 											const TUid aImplementationId,
       
   270 											const CKey& aKey,
       
   271 											const CCryptoParams* aAlgorithmParams)
       
   272 	{
       
   273 	aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams);
       
   274 	}
       
   275 #endif
       
   276 
       
   277 
       
   278 EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin,
       
   279 														TUid aImplementationId,
       
   280 														const CKey& aPrivateKey,
       
   281 														const CCryptoParams* aAlgorithmParams)
       
   282 	{
       
   283 	// create requested key agreement implementation in this plugin
       
   284 	switch (aImplementationId.iUid)
       
   285 		{
       
   286 		case KTestPlugin02DHKeyAgree_1:
       
   287 			{
       
   288 			aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams);
       
   289 			}
       
   290 			break;
       
   291 
       
   292 		default:
       
   293 			User::Leave(KErrNotFound);
       
   294 		}	
       
   295 	}
       
   296 	
       
   297 														
       
   298 EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin,
       
   299 														TUid aImplementationId,
       
   300 														const CCryptoParams* /*aAlgorithmParams*/)
       
   301 	{
       
   302 	//create requested key pair generator implementation in this plugin
       
   303 	switch (aImplementationId.iUid)
       
   304 		{
       
   305 			
       
   306 		case KTestPlugin02RsaKeyGen_1:
       
   307 			{
       
   308 			aPlugin = CRSAKeyPairGenImpl::NewL(aImplementationId);
       
   309 			}
       
   310 			break;
       
   311 			
       
   312 		case KTestPlugin02DHKeyGen_1:
       
   313 			{
       
   314 			aPlugin = CDHKeyPairGenImpl::NewL(aImplementationId);
       
   315 			}
       
   316 			break;
       
   317 			
       
   318 		default:
       
   319 			User::Leave(KErrNotFound);
       
   320 			}	
       
   321 	}
       
   322 	
       
   323 														
       
   324 EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin,
       
   325 												TUid aImplementationId,
       
   326 												const CCryptoParams* /*aAlgorithmParams*/)
       
   327 	{
       
   328 	
       
   329 	switch (aImplementationId.iUid)
       
   330 		{
       
   331 		
       
   332 		case KTestPlugin02Random_1:
       
   333 		case KTestPlugin02Random_2:
       
   334 			{
       
   335 			aPlugin=CRandomImpl::NewL(aImplementationId);
       
   336 			}	
       
   337 			break;
       
   338 
       
   339 		default:
       
   340 			User::Leave(KErrNotFound);
       
   341 		}
       
   342 	}	
       
   343 
       
   344 
       
   345 EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin,
       
   346 														TUid aImplementationId,
       
   347 														const CKey& aKey,
       
   348 														TUid aCryptoMode,
       
   349 														TUid aOperationMode,
       
   350 														TUid aPadding,
       
   351 														const CCryptoParams* /*aAlgorithmParams*/)
       
   352 	{
       
   353 
       
   354 	switch (aImplementationId.iUid)
       
   355 		{
       
   356 		case KTestPlugin02Des_1:
       
   357 			{
       
   358 			aPlugin=CDesExtendImpl::NewL(aImplementationId, aKey, aCryptoMode, aOperationMode, aPadding);
       
   359 			}	
       
   360 			break;
       
   361 		
       
   362 		case KTestPlugin02Des_2:
       
   363 			{
       
   364 			aPlugin=CDesImpl::NewL(aImplementationId, aKey, aCryptoMode, aOperationMode, aPadding);
       
   365 			}	
       
   366 			break;
       
   367 
       
   368 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
       
   369 		case KTestPlugin02Aes:
       
   370 			{
       
   371 			aPlugin=CRijndaelImpl::NewL(aKey, aCryptoMode, aOperationMode, aPadding, KTestPlugin02AesUid);
       
   372 			}
       
   373 			break;
       
   374 #endif
       
   375 
       
   376 		default:
       
   377 			User::Leave(KErrNotFound);
       
   378 		}
       
   379 	
       
   380 	}
       
   381