os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/pluginentry.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 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 "keypair.h"
sl@0
    27
#include "pluginconfig.h"
sl@0
    28
#include "md2impl.h"
sl@0
    29
#include "md5impl.h"
sl@0
    30
#include "md4impl.h"
sl@0
    31
#include "sha1impl.h"
sl@0
    32
#include "hmacimpl.h"
sl@0
    33
#include "keys.h"
sl@0
    34
#include "3desimpl.h"
sl@0
    35
#include "desimpl.h"
sl@0
    36
#include "rc2impl.h"
sl@0
    37
#include "arc4impl.h"
sl@0
    38
#include "randomimpl.h"
sl@0
    39
#include "rijndaelimpl.h"
sl@0
    40
#include "randomimpl.h"
sl@0
    41
#include "rsaimpl.h"
sl@0
    42
#include "dhimpl.h"
sl@0
    43
#include "dhkeypairgenimpl.h"
sl@0
    44
#include "rsakeypairgenimpl.h"
sl@0
    45
#include "dsakeypairgenimpl.h"
sl@0
    46
#include "dsasignerimpl.h"
sl@0
    47
#include "dsaverifyimpl.h"
sl@0
    48
#include "rsasignerimpl.h"
sl@0
    49
#include "rsaverifyimpl.h"
sl@0
    50
#include <cryptospi/cryptospidef.h>
sl@0
    51
sl@0
    52
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
    53
	#include "macimpl.h"
sl@0
    54
#endif
sl@0
    55
sl@0
    56
sl@0
    57
using namespace SoftwareCrypto;
sl@0
    58
sl@0
    59
EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins)
sl@0
    60
	{
sl@0
    61
	const TCharacteristics** ptr(0);
sl@0
    62
	switch (aInterface.iUid)
sl@0
    63
		{
sl@0
    64
	case KHashInterface:
sl@0
    65
		{
sl@0
    66
		aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
sl@0
    67
		ptr = (const TCharacteristics**) &KHashCharacteristics[0];
sl@0
    68
		}
sl@0
    69
		break;
sl@0
    70
		
sl@0
    71
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT		
sl@0
    72
		
sl@0
    73
	case KMacInterface:
sl@0
    74
		{
sl@0
    75
		aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*);
sl@0
    76
		ptr = (const TCharacteristics**) &KMacCharacteristics[0];
sl@0
    77
		}
sl@0
    78
		break;
sl@0
    79
		
sl@0
    80
#endif
sl@0
    81
		
sl@0
    82
	case KRandomInterface:
sl@0
    83
		{
sl@0
    84
		aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
sl@0
    85
		ptr= (const TCharacteristics**) &KRandomCharacteristics[0];
sl@0
    86
		}
sl@0
    87
		break;
sl@0
    88
sl@0
    89
	case KSymmetricCipherInterface:
sl@0
    90
		{
sl@0
    91
		aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*);
sl@0
    92
		ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0];
sl@0
    93
		}
sl@0
    94
		break;
sl@0
    95
sl@0
    96
	case KAsymmetricCipherInterface:
sl@0
    97
		{
sl@0
    98
		aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*);
sl@0
    99
		ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0];
sl@0
   100
		}
sl@0
   101
		break;
sl@0
   102
sl@0
   103
	case KSignerInterface:
sl@0
   104
		{
sl@0
   105
		aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
sl@0
   106
		ptr = (const TCharacteristics**) &KSignerCharacteristics[0];
sl@0
   107
		}
sl@0
   108
		break;
sl@0
   109
sl@0
   110
	case KVerifierInterface:
sl@0
   111
		{
sl@0
   112
		aNumPlugins=sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
sl@0
   113
		ptr = (const TCharacteristics**) &KVerifierCharacteristics[0];
sl@0
   114
		}
sl@0
   115
		break;
sl@0
   116
sl@0
   117
	case KKeyAgreementInterface:
sl@0
   118
		{
sl@0
   119
		aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*);
sl@0
   120
		ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0];
sl@0
   121
		}
sl@0
   122
		break;
sl@0
   123
sl@0
   124
	case KKeypairGeneratorInterface:
sl@0
   125
		{
sl@0
   126
		aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*);
sl@0
   127
		ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0];
sl@0
   128
		}
sl@0
   129
		break;
sl@0
   130
sl@0
   131
	case KKeyGeneratorInterface:
sl@0
   132
		break;
sl@0
   133
		
sl@0
   134
	default:;
sl@0
   135
		}
sl@0
   136
		
sl@0
   137
	return ptr;
sl@0
   138
	}
sl@0
   139
sl@0
   140
EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt)
sl@0
   141
	{
sl@0
   142
	switch (aImplementationUid.iUid)
sl@0
   143
		{
sl@0
   144
		
sl@0
   145
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
   146
	case KCryptoPluginMacHashMd2:   
sl@0
   147
#endif
sl@0
   148
	
sl@0
   149
	case KCryptoPluginMd2:
sl@0
   150
	   aExt = CMD2Impl::CreateExtendedCharacteristicsL();
sl@0
   151
	   break;
sl@0
   152
	   
sl@0
   153
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
   154
	case KCryptoPluginMacHashMd5:   
sl@0
   155
#endif
sl@0
   156
	
sl@0
   157
	case KCryptoPluginMd5:
sl@0
   158
	   aExt = CMD5Impl::CreateExtendedCharacteristicsL();
sl@0
   159
	   break;
sl@0
   160
	   
sl@0
   161
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
   162
	case KCryptoPluginMacHashSha1:   
sl@0
   163
#endif
sl@0
   164
	
sl@0
   165
	case KCryptoPluginSha1:
sl@0
   166
	   aExt = CSHA1Impl::CreateExtendedCharacteristicsL();
sl@0
   167
	   break;
sl@0
   168
	   
sl@0
   169
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
   170
	case KCryptoPluginMacHashMd4:   
sl@0
   171
#endif
sl@0
   172
	
sl@0
   173
	case KCryptoPluginMd4:
sl@0
   174
	   aExt = CMD4Impl::CreateExtendedCharacteristicsL();
sl@0
   175
	   break;
sl@0
   176
	case KCryptoPluginRandom:
sl@0
   177
	   aExt = CRandomImpl::CreateExtendedCharacteristicsL();
sl@0
   178
	   break;
sl@0
   179
	case KCryptoPluginDes:
sl@0
   180
	   aExt = CDesImpl::CreateExtendedCharacteristicsL();
sl@0
   181
	   break;
sl@0
   182
	case KCryptoPlugin3Des:
sl@0
   183
	   aExt = C3DesImpl::CreateExtendedCharacteristicsL();
sl@0
   184
	   break;
sl@0
   185
	case KCryptoPluginRc2:
sl@0
   186
	   aExt = CRc2Impl::CreateExtendedCharacteristicsL();
sl@0
   187
	   break;
sl@0
   188
	case KCryptoPluginArc4:
sl@0
   189
	   aExt = CArc4Impl::CreateExtendedCharacteristicsL();
sl@0
   190
	   break;
sl@0
   191
	   
sl@0
   192
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
   193
	case KCryptoPluginMacAesXcbcMac96:   
sl@0
   194
	case KCryptoPluginMacAesXcbcPrf128:
sl@0
   195
#endif	
sl@0
   196
	
sl@0
   197
	case KCryptoPluginAes:
sl@0
   198
	   aExt = CRijndaelImpl::CreateExtendedCharacteristicsL();
sl@0
   199
	   break;
sl@0
   200
	case KCryptoPluginRsaCipher:
sl@0
   201
	   aExt = CRSAImpl::CreateExtendedCharacteristicsL();
sl@0
   202
	   break;
sl@0
   203
	case KCryptoPluginRsaSigner:
sl@0
   204
	   aExt = CRSASignerImpl::CreateExtendedCharacteristicsL();
sl@0
   205
	   break;
sl@0
   206
	case KCryptoPluginDsaSigner:
sl@0
   207
	   aExt = CDSASignerImpl::CreateExtendedCharacteristicsL();
sl@0
   208
	   break;
sl@0
   209
	case KCryptoPluginRsaVerifier:
sl@0
   210
	   aExt = CRSAVerifierImpl::CreateExtendedCharacteristicsL();
sl@0
   211
	   break;
sl@0
   212
	case KCryptoPluginDsaVerifier:
sl@0
   213
	   aExt = CDSAVerifierImpl::CreateExtendedCharacteristicsL();
sl@0
   214
	   break;
sl@0
   215
	case KCryptoPluginDhKeyAgreement:
sl@0
   216
	   aExt = CDHImpl::CreateExtendedCharacteristicsL();
sl@0
   217
	   break;
sl@0
   218
	case KCryptoPluginDhKeyPairGen:
sl@0
   219
	   aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();
sl@0
   220
	   break;
sl@0
   221
	case KCryptoPluginRsaKeyPairGen:
sl@0
   222
	   aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL();
sl@0
   223
	   break;
sl@0
   224
	case KCryptoPluginDsaKeyPairGen:
sl@0
   225
	   aExt = CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL();
sl@0
   226
	   break;
sl@0
   227
	default:
sl@0
   228
		User::Leave(KErrNotSupported);
sl@0
   229
		}
sl@0
   230
	}
sl@0
   231
	
sl@0
   232
EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin,
sl@0
   233
														TUid aImplementationId,
sl@0
   234
														const CKey& aKey,
sl@0
   235
														TUid aCryptoMode,
sl@0
   236
														TUid aPaddingMode,
sl@0
   237
														const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   238
	{
sl@0
   239
	switch (aImplementationId.iUid)
sl@0
   240
		{
sl@0
   241
	case KCryptoPluginRsaCipher:
sl@0
   242
		{
sl@0
   243
		aPlugin = CRSAImpl::NewL(aKey, aCryptoMode, aPaddingMode);
sl@0
   244
		}
sl@0
   245
		break;
sl@0
   246
		
sl@0
   247
	default:
sl@0
   248
		User::Leave(KErrNotFound);
sl@0
   249
		}
sl@0
   250
	}
sl@0
   251
	
sl@0
   252
EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin,
sl@0
   253
														TUid aImplementationId,
sl@0
   254
														const CKey& aKey,
sl@0
   255
														TUid aPaddingMode,
sl@0
   256
														const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   257
	{
sl@0
   258
	switch (aImplementationId.iUid)
sl@0
   259
		{
sl@0
   260
	case KCryptoPluginRsaSigner:
sl@0
   261
		{
sl@0
   262
		aPlugin = CRSASignerImpl::NewL(aKey, aPaddingMode);
sl@0
   263
		}	
sl@0
   264
		break;
sl@0
   265
sl@0
   266
	case KCryptoPluginDsaSigner:
sl@0
   267
		{
sl@0
   268
		aPlugin = CDSASignerImpl::NewL(aKey);
sl@0
   269
		}	
sl@0
   270
		break;
sl@0
   271
sl@0
   272
	default:
sl@0
   273
		User::Leave(KErrNotFound);
sl@0
   274
		}
sl@0
   275
	}
sl@0
   276
	
sl@0
   277
EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& aPlugin,
sl@0
   278
															TUid aImplementationId,
sl@0
   279
															const CKey& aKey,
sl@0
   280
															TUid aPaddingMode,
sl@0
   281
															const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   282
	{
sl@0
   283
	switch (aImplementationId.iUid)
sl@0
   284
		{
sl@0
   285
	case KCryptoPluginRsaVerifier:
sl@0
   286
		aPlugin = CRSAVerifierImpl::NewL(aKey, aPaddingMode);
sl@0
   287
		break;
sl@0
   288
	
sl@0
   289
	case KCryptoPluginDsaVerifier:
sl@0
   290
		{
sl@0
   291
		aPlugin = CDSAVerifierImpl::NewL(aKey);
sl@0
   292
		}	
sl@0
   293
		break;
sl@0
   294
		
sl@0
   295
	default:
sl@0
   296
		User::Leave(KErrNotFound);
sl@0
   297
		}
sl@0
   298
	}
sl@0
   299
sl@0
   300
EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
sl@0
   301
											TUid aImplementationId,
sl@0
   302
											TUid aOperationMode,
sl@0
   303
											const CKey* aKey,
sl@0
   304
											const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   305
	{
sl@0
   306
	aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey);
sl@0
   307
	}
sl@0
   308
sl@0
   309
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT	
sl@0
   310
sl@0
   311
EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
sl@0
   312
											TUid aImplementationId,
sl@0
   313
											const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   314
	{
sl@0
   315
	aPlugin=CSoftwareHash::NewL(aImplementationId);
sl@0
   316
	}
sl@0
   317
sl@0
   318
EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin,
sl@0
   319
											const TUid aImplementationId,
sl@0
   320
											const CKey& aKey,
sl@0
   321
											const CCryptoParams* aAlgorithmParams)
sl@0
   322
	{
sl@0
   323
	aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams);
sl@0
   324
	}
sl@0
   325
sl@0
   326
#endif
sl@0
   327
sl@0
   328
EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin,
sl@0
   329
														TUid aImplementationId,
sl@0
   330
														const CKey& aPrivateKey,
sl@0
   331
														const CCryptoParams* aAlgorithmParams)
sl@0
   332
	{
sl@0
   333
	// create requested key agreement implementation in this plugin
sl@0
   334
	switch (aImplementationId.iUid)
sl@0
   335
		{
sl@0
   336
	case KCryptoPluginDhKeyAgreement:
sl@0
   337
		{
sl@0
   338
		aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams);
sl@0
   339
		}
sl@0
   340
		break;
sl@0
   341
sl@0
   342
	default:
sl@0
   343
		User::Leave(KErrNotFound);
sl@0
   344
		}
sl@0
   345
	}
sl@0
   346
sl@0
   347
EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin,
sl@0
   348
														TUid aImplementationId,
sl@0
   349
														const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   350
	{
sl@0
   351
	// create requested key pair generator implementation in this plugin
sl@0
   352
	switch (aImplementationId.iUid)
sl@0
   353
		{
sl@0
   354
	case KCryptoPluginDhKeyPairGen:
sl@0
   355
		{
sl@0
   356
		aPlugin = CDHKeyPairGenImpl::NewL();
sl@0
   357
		}
sl@0
   358
		break;
sl@0
   359
		
sl@0
   360
	case KCryptoPluginRsaKeyPairGen:
sl@0
   361
		{
sl@0
   362
		aPlugin = CRSAKeyPairGenImpl::NewL();
sl@0
   363
		}
sl@0
   364
		break;
sl@0
   365
		
sl@0
   366
	case KCryptoPluginDsaKeyPairGen:
sl@0
   367
		{
sl@0
   368
		aPlugin = CDSAKeyPairGenImpl::NewL();
sl@0
   369
		}
sl@0
   370
		break;
sl@0
   371
		
sl@0
   372
	default:
sl@0
   373
		User::Leave(KErrNotFound);
sl@0
   374
		}
sl@0
   375
	}
sl@0
   376
	
sl@0
   377
EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin,
sl@0
   378
												TUid /*aImplementationId*/,
sl@0
   379
												const CCryptoParams* /*aAlgorithmParams*/)
sl@0
   380
	{
sl@0
   381
	aPlugin=CRandomImpl::NewL();
sl@0
   382
	}	
sl@0
   383
sl@0
   384
EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin,
sl@0
   385
														TUid aImplementationId,
sl@0
   386
														const CKey& aKey,
sl@0
   387
														TUid aCryptoMode,
sl@0
   388
														TUid aOperationMode,
sl@0
   389
														TUid aPadding,
sl@0
   390
														const CCryptoParams* aAlgorithmParams)
sl@0
   391
	{
sl@0
   392
	switch (aImplementationId.iUid)
sl@0
   393
		{
sl@0
   394
	case KCryptoPluginAes:
sl@0
   395
		{
sl@0
   396
		aPlugin=CRijndaelImpl::NewL(
sl@0
   397
			aKey, aCryptoMode, aOperationMode, aPadding);
sl@0
   398
		}	
sl@0
   399
		break;
sl@0
   400
	case KCryptoPluginDes:
sl@0
   401
		{
sl@0
   402
		aPlugin=CDesImpl::NewL(
sl@0
   403
			aKey, aCryptoMode, aOperationMode, aPadding);
sl@0
   404
		}	
sl@0
   405
		break;
sl@0
   406
	case KCryptoPlugin3Des:
sl@0
   407
		{
sl@0
   408
		aPlugin=C3DesImpl::NewL(
sl@0
   409
			aKey, aCryptoMode, aOperationMode, aPadding);
sl@0
   410
		}	
sl@0
   411
		break;
sl@0
   412
	case KCryptoPluginRc2:
sl@0
   413
		{
sl@0
   414
		TInt effectiveKeyLenBits(CRc2Impl::KDefaultEffectiveKeyLenBits);
sl@0
   415
			
sl@0
   416
		if (aAlgorithmParams && aAlgorithmParams->IsPresent(KRC2EffectiveKeyLenBits))
sl@0
   417
			{
sl@0
   418
			effectiveKeyLenBits = aAlgorithmParams->GetTIntL(KRC2EffectiveKeyLenBits);
sl@0
   419
			if (effectiveKeyLenBits < 0)
sl@0
   420
				{
sl@0
   421
				User::Leave(KErrArgument);
sl@0
   422
				}
sl@0
   423
			}
sl@0
   424
		aPlugin=CRc2Impl::NewL(
sl@0
   425
			aKey, aCryptoMode, aOperationMode, aPadding, effectiveKeyLenBits);
sl@0
   426
		}	
sl@0
   427
		break;				
sl@0
   428
	
sl@0
   429
	case KCryptoPluginArc4:
sl@0
   430
		{
sl@0
   431
		TInt discardBytes(CArc4Impl::KDefaultDiscardBytes);
sl@0
   432
		if (aAlgorithmParams && aAlgorithmParams->IsPresent(KARC4DiscardBytes))
sl@0
   433
			{
sl@0
   434
			discardBytes = aAlgorithmParams->GetTIntL(KARC4DiscardBytes);
sl@0
   435
			if (discardBytes < 0)
sl@0
   436
				{
sl@0
   437
				User::Leave(KErrArgument);
sl@0
   438
				}
sl@0
   439
			}		
sl@0
   440
		aPlugin=CArc4Impl::NewL(aKey, discardBytes);
sl@0
   441
		}
sl@0
   442
		break;
sl@0
   443
		
sl@0
   444
	default:
sl@0
   445
		User::Leave(KErrNotFound);
sl@0
   446
		}
sl@0
   447
	}
sl@0
   448