sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * plugin entry implementation sl@0: * plugin entry implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "pluginentry.h" sl@0: #include "keypair.h" sl@0: #include "pluginconfig.h" sl@0: #include "md2impl.h" sl@0: #include "md5impl.h" sl@0: #include "md4impl.h" sl@0: #include "sha1impl.h" sl@0: #include "hmacimpl.h" sl@0: #include "keys.h" sl@0: #include "3desimpl.h" sl@0: #include "desimpl.h" sl@0: #include "rc2impl.h" sl@0: #include "arc4impl.h" sl@0: #include "randomimpl.h" sl@0: #include "rijndaelimpl.h" sl@0: #include "randomimpl.h" sl@0: #include "rsaimpl.h" sl@0: #include "dhimpl.h" sl@0: #include "dhkeypairgenimpl.h" sl@0: #include "rsakeypairgenimpl.h" sl@0: #include "dsakeypairgenimpl.h" sl@0: #include "dsasignerimpl.h" sl@0: #include "dsaverifyimpl.h" sl@0: #include "rsasignerimpl.h" sl@0: #include "rsaverifyimpl.h" sl@0: #include sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: #include "macimpl.h" sl@0: #endif sl@0: sl@0: sl@0: using namespace SoftwareCrypto; sl@0: sl@0: EXPORT_C const TCharacteristics** CCryptoPluginEntry::Enumerate(TUid aInterface, TInt& aNumPlugins) sl@0: { sl@0: const TCharacteristics** ptr(0); sl@0: switch (aInterface.iUid) sl@0: { sl@0: case KHashInterface: sl@0: { sl@0: aNumPlugins=sizeof(KHashCharacteristics)/sizeof(THashCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KHashCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: sl@0: case KMacInterface: sl@0: { sl@0: aNumPlugins=sizeof(KMacCharacteristics)/sizeof(TMacCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KMacCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: #endif sl@0: sl@0: case KRandomInterface: sl@0: { sl@0: aNumPlugins=sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*); sl@0: ptr= (const TCharacteristics**) &KRandomCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KSymmetricCipherInterface: sl@0: { sl@0: aNumPlugins=sizeof(KSymmetricCipherCharacteristics)/sizeof(TSymmetricCipherCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KSymmetricCipherCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KAsymmetricCipherInterface: sl@0: { sl@0: aNumPlugins=sizeof(KAsymmetricCipherCharacteristics)/sizeof(TAsymmetricCipherCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KAsymmetricCipherCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KSignerInterface: sl@0: { sl@0: aNumPlugins=sizeof(KSignerCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KSignerCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KVerifierInterface: sl@0: { sl@0: aNumPlugins=sizeof(KVerifierCharacteristics)/sizeof(TAsymmetricSignatureCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KVerifierCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KKeyAgreementInterface: sl@0: { sl@0: aNumPlugins=sizeof(KKeyAgreementCharacteristics)/sizeof(TKeyAgreementCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KKeyAgreementCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KKeypairGeneratorInterface: sl@0: { sl@0: aNumPlugins=sizeof(KKeyPairGeneratorCharacteristics)/sizeof(TAsymmetricKeypairGeneratorCharacteristics*); sl@0: ptr = (const TCharacteristics**) &KKeyPairGeneratorCharacteristics[0]; sl@0: } sl@0: break; sl@0: sl@0: case KKeyGeneratorInterface: sl@0: break; sl@0: sl@0: default:; sl@0: } sl@0: sl@0: return ptr; sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::GetExtendedCharacteristicsL(TUid aImplementationUid, CExtendedCharacteristics*& aExt) sl@0: { sl@0: switch (aImplementationUid.iUid) sl@0: { sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: case KCryptoPluginMacHashMd2: sl@0: #endif sl@0: sl@0: case KCryptoPluginMd2: sl@0: aExt = CMD2Impl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: case KCryptoPluginMacHashMd5: sl@0: #endif sl@0: sl@0: case KCryptoPluginMd5: sl@0: aExt = CMD5Impl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: case KCryptoPluginMacHashSha1: sl@0: #endif sl@0: sl@0: case KCryptoPluginSha1: sl@0: aExt = CSHA1Impl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: case KCryptoPluginMacHashMd4: sl@0: #endif sl@0: sl@0: case KCryptoPluginMd4: sl@0: aExt = CMD4Impl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginRandom: sl@0: aExt = CRandomImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginDes: sl@0: aExt = CDesImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPlugin3Des: sl@0: aExt = C3DesImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginRc2: sl@0: aExt = CRc2Impl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginArc4: sl@0: aExt = CArc4Impl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: case KCryptoPluginMacAesXcbcMac96: sl@0: case KCryptoPluginMacAesXcbcPrf128: sl@0: #endif sl@0: sl@0: case KCryptoPluginAes: sl@0: aExt = CRijndaelImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginRsaCipher: sl@0: aExt = CRSAImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginRsaSigner: sl@0: aExt = CRSASignerImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginDsaSigner: sl@0: aExt = CDSASignerImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginRsaVerifier: sl@0: aExt = CRSAVerifierImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginDsaVerifier: sl@0: aExt = CDSAVerifierImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginDhKeyAgreement: sl@0: aExt = CDHImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginDhKeyPairGen: sl@0: aExt = CDHKeyPairGenImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginRsaKeyPairGen: sl@0: aExt = CRSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: case KCryptoPluginDsaKeyPairGen: sl@0: aExt = CDSAKeyPairGenImpl::CreateExtendedCharacteristicsL(); sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateAsymmetricCipherL(MAsymmetricCipher*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CKey& aKey, sl@0: TUid aCryptoMode, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: switch (aImplementationId.iUid) sl@0: { sl@0: case KCryptoPluginRsaCipher: sl@0: { sl@0: aPlugin = CRSAImpl::NewL(aKey, aCryptoMode, aPaddingMode); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateAsymmetricSignerL(MSigner*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CKey& aKey, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: switch (aImplementationId.iUid) sl@0: { sl@0: case KCryptoPluginRsaSigner: sl@0: { sl@0: aPlugin = CRSASignerImpl::NewL(aKey, aPaddingMode); sl@0: } sl@0: break; sl@0: sl@0: case KCryptoPluginDsaSigner: sl@0: { sl@0: aPlugin = CDSASignerImpl::NewL(aKey); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateAsymmetricVerifierL(MVerifier*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CKey& aKey, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: switch (aImplementationId.iUid) sl@0: { sl@0: case KCryptoPluginRsaVerifier: sl@0: aPlugin = CRSAVerifierImpl::NewL(aKey, aPaddingMode); sl@0: break; sl@0: sl@0: case KCryptoPluginDsaVerifier: sl@0: { sl@0: aPlugin = CDSAVerifierImpl::NewL(aKey); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin, sl@0: TUid aImplementationId, sl@0: TUid aOperationMode, sl@0: const CKey* aKey, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: aPlugin=CSoftwareHash::NewL(aImplementationId, aOperationMode, aKey); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateHashL(MHash*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: aPlugin=CSoftwareHash::NewL(aImplementationId); sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateMacL(MMac*& aPlugin, sl@0: const TUid aImplementationId, sl@0: const CKey& aKey, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: aPlugin=CMacImpl::NewL(aKey, aImplementationId, aAlgorithmParams); sl@0: } sl@0: sl@0: #endif sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateKeyAgreementL(MKeyAgreement*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CKey& aPrivateKey, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: // create requested key agreement implementation in this plugin sl@0: switch (aImplementationId.iUid) sl@0: { sl@0: case KCryptoPluginDhKeyAgreement: sl@0: { sl@0: aPlugin = CDHImpl::NewL(aPrivateKey, aAlgorithmParams); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateKeyPairGeneratorL(MKeyPairGenerator*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: // create requested key pair generator implementation in this plugin sl@0: switch (aImplementationId.iUid) sl@0: { sl@0: case KCryptoPluginDhKeyPairGen: sl@0: { sl@0: aPlugin = CDHKeyPairGenImpl::NewL(); sl@0: } sl@0: break; sl@0: sl@0: case KCryptoPluginRsaKeyPairGen: sl@0: { sl@0: aPlugin = CRSAKeyPairGenImpl::NewL(); sl@0: } sl@0: break; sl@0: sl@0: case KCryptoPluginDsaKeyPairGen: sl@0: { sl@0: aPlugin = CDSAKeyPairGenImpl::NewL(); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateRandomL(MRandom*& aPlugin, sl@0: TUid /*aImplementationId*/, sl@0: const CCryptoParams* /*aAlgorithmParams*/) sl@0: { sl@0: aPlugin=CRandomImpl::NewL(); sl@0: } sl@0: sl@0: EXPORT_C void CCryptoPluginEntry::CreateSymmetricCipherL(MSymmetricCipher*& aPlugin, sl@0: TUid aImplementationId, sl@0: const CKey& aKey, sl@0: TUid aCryptoMode, sl@0: TUid aOperationMode, sl@0: TUid aPadding, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: switch (aImplementationId.iUid) sl@0: { sl@0: case KCryptoPluginAes: sl@0: { sl@0: aPlugin=CRijndaelImpl::NewL( sl@0: aKey, aCryptoMode, aOperationMode, aPadding); sl@0: } sl@0: break; sl@0: case KCryptoPluginDes: sl@0: { sl@0: aPlugin=CDesImpl::NewL( sl@0: aKey, aCryptoMode, aOperationMode, aPadding); sl@0: } sl@0: break; sl@0: case KCryptoPlugin3Des: sl@0: { sl@0: aPlugin=C3DesImpl::NewL( sl@0: aKey, aCryptoMode, aOperationMode, aPadding); sl@0: } sl@0: break; sl@0: case KCryptoPluginRc2: sl@0: { sl@0: TInt effectiveKeyLenBits(CRc2Impl::KDefaultEffectiveKeyLenBits); sl@0: sl@0: if (aAlgorithmParams && aAlgorithmParams->IsPresent(KRC2EffectiveKeyLenBits)) sl@0: { sl@0: effectiveKeyLenBits = aAlgorithmParams->GetTIntL(KRC2EffectiveKeyLenBits); sl@0: if (effectiveKeyLenBits < 0) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: } sl@0: aPlugin=CRc2Impl::NewL( sl@0: aKey, aCryptoMode, aOperationMode, aPadding, effectiveKeyLenBits); sl@0: } sl@0: break; sl@0: sl@0: case KCryptoPluginArc4: sl@0: { sl@0: TInt discardBytes(CArc4Impl::KDefaultDiscardBytes); sl@0: if (aAlgorithmParams && aAlgorithmParams->IsPresent(KARC4DiscardBytes)) sl@0: { sl@0: discardBytes = aAlgorithmParams->GetTIntL(KARC4DiscardBytes); sl@0: if (discardBytes < 0) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: } sl@0: aPlugin=CArc4Impl::NewL(aKey, discardBytes); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: