First public contribution.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * plugin entry implementation
16 * plugin entry implementation
25 #include "pluginentry.h"
27 #include "pluginconfig.h"
38 #include "randomimpl.h"
39 #include "rijndaelimpl.h"
40 #include "randomimpl.h"
43 #include "dhkeypairgenimpl.h"
44 #include "rsakeypairgenimpl.h"
45 #include "dsakeypairgenimpl.h"
46 #include "dsasignerimpl.h"
47 #include "dsaverifyimpl.h"
48 #include "rsasignerimpl.h"
49 #include "rsaverifyimpl.h"
50 #include <cryptospi/cryptospidef.h>
52 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
57 using namespace SoftwareCrypto;
59 EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins)
61 const TCharacteristics** ptr(0);
62 switch (aInterface.iUid)
66 aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*);
67 ptr = (const TCharacteristics**) &KHashCharacteristics[0];
71 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
75 aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*);
76 ptr = (const TCharacteristics**) &KMacCharacteristics[0];
82 case KRandomInterface:
84 aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
85 ptr= (const TCharacteristics**) &KRandomCharacteristics[0];
89 case KSymmetricCipherInterface:
91 aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*);
92 ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0];
96 case KAsymmetricCipherInterface:
98 aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*);
99 ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0];
103 case KSignerInterface:
105 aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
106 ptr = (const TCharacteristics**) &KSignerCharacteristics[0];
110 case KVerifierInterface:
112 aNumPlugins=sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*);
113 ptr = (const TCharacteristics**) &KVerifierCharacteristics[0];
117 case KKeyAgreementInterface:
119 aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*);
120 ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0];
124 case KKeypairGeneratorInterface:
126 aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*);
127 ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0];
131 case KKeyGeneratorInterface:
140 EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt)
142 switch (aImplementationUid.iUid)
145 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
146 case KCryptoPluginMacHashMd2:
149 case KCryptoPluginMd2:
150 aExt = CMD2Impl::CreateExtendedCharacteristicsL();
153 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
154 case KCryptoPluginMacHashMd5:
157 case KCryptoPluginMd5:
158 aExt = CMD5Impl::CreateExtendedCharacteristicsL();
161 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
162 case KCryptoPluginMacHashSha1:
165 case KCryptoPluginSha1:
166 aExt = CSHA1Impl::CreateExtendedCharacteristicsL();
169 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
170 case KCryptoPluginMacHashMd4:
173 case KCryptoPluginMd4:
174 aExt = CMD4Impl::CreateExtendedCharacteristicsL();
176 case KCryptoPluginRandom:
177 aExt = CRandomImpl::CreateExtendedCharacteristicsL();
179 case KCryptoPluginDes:
180 aExt = CDesImpl::CreateExtendedCharacteristicsL();
182 case KCryptoPlugin3Des:
183 aExt = C3DesImpl::CreateExtendedCharacteristicsL();
185 case KCryptoPluginRc2:
186 aExt = CRc2Impl::CreateExtendedCharacteristicsL();
188 case KCryptoPluginArc4:
189 aExt = CArc4Impl::CreateExtendedCharacteristicsL();
192 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
193 case KCryptoPluginMacAesXcbcMac96:
194 case KCryptoPluginMacAesXcbcPrf128:
197 case KCryptoPluginAes:
198 aExt = CRijndaelImpl::CreateExtendedCharacteristicsL();
200 case KCryptoPluginRsaCipher:
201 aExt = CRSAImpl::CreateExtendedCharacteristicsL();
203 case KCryptoPluginRsaSigner:
204 aExt = CRSASignerImpl::CreateExtendedCharacteristicsL();
206 case KCryptoPluginDsaSigner:
207 aExt = CDSASignerImpl::CreateExtendedCharacteristicsL();
209 case KCryptoPluginRsaVerifier:
210 aExt = CRSAVerifierImpl::CreateExtendedCharacteristicsL();
212 case KCryptoPluginDsaVerifier:
213 aExt = CDSAVerifierImpl::CreateExtendedCharacteristicsL();
215 case KCryptoPluginDhKeyAgreement:
216 aExt = CDHImpl::CreateExtendedCharacteristicsL();
218 case KCryptoPluginDhKeyPairGen:
219 aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL();
221 case KCryptoPluginRsaKeyPairGen:
222 aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL();
224 case KCryptoPluginDsaKeyPairGen:
225 aExt = CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL();
228 User::Leave(KErrNotSupported);
232 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin,
233 TUid aImplementationId,
237 const CCryptoParams* /*aAlgorithmParams*/)
239 switch (aImplementationId.iUid)
241 case KCryptoPluginRsaCipher:
243 aPlugin = CRSAImpl::NewL(aKey, aCryptoMode, aPaddingMode);
248 User::Leave(KErrNotFound);
252 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin,
253 TUid aImplementationId,
256 const CCryptoParams* /*aAlgorithmParams*/)
258 switch (aImplementationId.iUid)
260 case KCryptoPluginRsaSigner:
262 aPlugin = CRSASignerImpl::NewL(aKey, aPaddingMode);
266 case KCryptoPluginDsaSigner:
268 aPlugin = CDSASignerImpl::NewL(aKey);
273 User::Leave(KErrNotFound);
277 EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& aPlugin,
278 TUid aImplementationId,
281 const CCryptoParams* /*aAlgorithmParams*/)
283 switch (aImplementationId.iUid)
285 case KCryptoPluginRsaVerifier:
286 aPlugin = CRSAVerifierImpl::NewL(aKey, aPaddingMode);
289 case KCryptoPluginDsaVerifier:
291 aPlugin = CDSAVerifierImpl::NewL(aKey);
296 User::Leave(KErrNotFound);
300 EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
301 TUid aImplementationId,
304 const CCryptoParams* /*aAlgorithmParams*/)
306 aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey);
309 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
311 EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin,
312 TUid aImplementationId,
313 const CCryptoParams* /*aAlgorithmParams*/)
315 aPlugin=CSoftwareHash::NewL(aImplementationId);
318 EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin,
319 const TUid aImplementationId,
321 const CCryptoParams* aAlgorithmParams)
323 aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams);
328 EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin,
329 TUid aImplementationId,
330 const CKey& aPrivateKey,
331 const CCryptoParams* aAlgorithmParams)
333 // create requested key agreement implementation in this plugin
334 switch (aImplementationId.iUid)
336 case KCryptoPluginDhKeyAgreement:
338 aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams);
343 User::Leave(KErrNotFound);
347 EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin,
348 TUid aImplementationId,
349 const CCryptoParams* /*aAlgorithmParams*/)
351 // create requested key pair generator implementation in this plugin
352 switch (aImplementationId.iUid)
354 case KCryptoPluginDhKeyPairGen:
356 aPlugin = CDHKeyPairGenImpl::NewL();
360 case KCryptoPluginRsaKeyPairGen:
362 aPlugin = CRSAKeyPairGenImpl::NewL();
366 case KCryptoPluginDsaKeyPairGen:
368 aPlugin = CDSAKeyPairGenImpl::NewL();
373 User::Leave(KErrNotFound);
377 EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin,
378 TUid /*aImplementationId*/,
379 const CCryptoParams* /*aAlgorithmParams*/)
381 aPlugin=CRandomImpl::NewL();
384 EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin,
385 TUid aImplementationId,
390 const CCryptoParams* aAlgorithmParams)
392 switch (aImplementationId.iUid)
394 case KCryptoPluginAes:
396 aPlugin=CRijndaelImpl::NewL(
397 aKey, aCryptoMode, aOperationMode, aPadding);
400 case KCryptoPluginDes:
402 aPlugin=CDesImpl::NewL(
403 aKey, aCryptoMode, aOperationMode, aPadding);
406 case KCryptoPlugin3Des:
408 aPlugin=C3DesImpl::NewL(
409 aKey, aCryptoMode, aOperationMode, aPadding);
412 case KCryptoPluginRc2:
414 TInt effectiveKeyLenBits(CRc2Impl::KDefaultEffectiveKeyLenBits);
416 if (aAlgorithmParams && aAlgorithmParams->IsPresent(KRC2EffectiveKeyLenBits))
418 effectiveKeyLenBits = aAlgorithmParams->GetTIntL(KRC2EffectiveKeyLenBits);
419 if (effectiveKeyLenBits < 0)
421 User::Leave(KErrArgument);
424 aPlugin=CRc2Impl::NewL(
425 aKey, aCryptoMode, aOperationMode, aPadding, effectiveKeyLenBits);
429 case KCryptoPluginArc4:
431 TInt discardBytes(CArc4Impl::KDefaultDiscardBytes);
432 if (aAlgorithmParams && aAlgorithmParams->IsPresent(KARC4DiscardBytes))
434 discardBytes = aAlgorithmParams->GetTIntL(KARC4DiscardBytes);
435 if (discardBytes < 0)
437 User::Leave(KErrArgument);
440 aPlugin=CArc4Impl::NewL(aKey, discardBytes);
445 User::Leave(KErrNotFound);