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