sl@0: /* sl@0: * Copyright (c) 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: * sl@0: */ sl@0: sl@0: sl@0: #include "dummyeccimpl.h" sl@0: sl@0: #include sl@0: #include sl@0: #include "keys.h" sl@0: #include sl@0: #include "pluginconfig.h" sl@0: #include "cryptospihai.h" sl@0: sl@0: using namespace DummyEccHwCrypto; sl@0: using namespace CryptoSpiHai; sl@0: sl@0: /** sl@0: * These are just randomly selected numbers. There is no logic behind sl@0: * their values. sl@0: */ sl@0: const TInt KMaxOutputLength = 50; sl@0: const TInt KMaxInputLength = 50; sl@0: sl@0: CDummyECCCipherImpl* CDummyECCCipherImpl::NewL(const CKey& aKey, sl@0: TUid aCryptoMode, TUid aPaddingMode) sl@0: { sl@0: CDummyECCCipherImpl* self = CDummyECCCipherImpl::NewLC(aKey, aCryptoMode, sl@0: aPaddingMode); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CDummyECCCipherImpl* CDummyECCCipherImpl::NewLC(const CKey& aKey, sl@0: TUid aCryptoMode, TUid aPaddingMode) sl@0: { sl@0: CDummyECCCipherImpl* self = new (ELeave) CDummyECCCipherImpl(aCryptoMode, sl@0: aPaddingMode); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aKey); sl@0: return self; sl@0: } sl@0: sl@0: CDummyECCCipherImpl::CDummyECCCipherImpl(TUid aCryptoMode, TUid aPaddingMode) : sl@0: iCryptoMode(aCryptoMode), iPaddingMode(aPaddingMode) sl@0: { sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::ConstructL(const CKey& aKey) sl@0: { sl@0: SetKeyL(aKey); sl@0: } sl@0: sl@0: // MPlugin Interface Start sl@0: void CDummyECCCipherImpl::Close() sl@0: { sl@0: delete this; sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::Reset() sl@0: { sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::GetCharacteristicsL( sl@0: const TCharacteristics*& aPluginCharacteristics) sl@0: { sl@0: TInt numCiphers = sizeof(KAsymmetricCipherCharacteristics) sl@0: / sizeof(TAsymmetricCipherCharacteristics*); sl@0: TInt32 implUid = ImplementationUid().iUid; sl@0: for (TInt i = 0; i < numCiphers; ++i) sl@0: { sl@0: if (KAsymmetricCipherCharacteristics[i]->cmn.iImplementationUID sl@0: == implUid) sl@0: { sl@0: aPluginCharacteristics = KAsymmetricCipherCharacteristics[i]; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: const CExtendedCharacteristics* CDummyECCCipherImpl::GetExtendedCharacteristicsL() sl@0: { sl@0: // All Symbian software plug-ins have unlimited concurrency, cannot be reserved sl@0: // for exclusive use and are not CERTIFIED to be standards compliant. sl@0: return CExtendedCharacteristics::NewL(KMaxTInt, EFalse); sl@0: } sl@0: sl@0: TAny* CDummyECCCipherImpl::GetExtension(TUid /* aExtensionId */) sl@0: { sl@0: return 0; sl@0: } sl@0: // End of MPlugin Interface sl@0: sl@0: // MAsymmetricCipherBase Interface sl@0: void CDummyECCCipherImpl::SetKeyL(const CKey& aKey) sl@0: { sl@0: // delete any previous key and recreate the key sl@0: delete iKey; sl@0: iKey = NULL; sl@0: iKey = CKey::NewL(aKey); sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::SetCryptoModeL(TUid aCryptoMode) sl@0: { sl@0: switch (aCryptoMode.iUid) sl@0: { sl@0: case KCryptoModeEncrypt: sl@0: case KCryptoModeDecrypt: sl@0: break; sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: iCryptoMode = aCryptoMode; sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::SetPaddingModeL(TUid /* aPaddingMode */) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: TInt CDummyECCCipherImpl::GetMaximumInputLengthL() const sl@0: { sl@0: return KMaxInputLength; sl@0: } sl@0: sl@0: TInt CDummyECCCipherImpl::GetMaximumOutputLengthL() const sl@0: { sl@0: return KMaxOutputLength; sl@0: } sl@0: // End of MAsymmetricCipherBase Interface sl@0: sl@0: // MAsymmetricCipher Interface sl@0: void CDummyECCCipherImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: if (iCryptoMode.iUid == KCryptoModeEncrypt) sl@0: { sl@0: EncryptL(aInput, aOutput); sl@0: } sl@0: else sl@0: { sl@0: DecryptL(aInput, aOutput); sl@0: } sl@0: } sl@0: sl@0: TUid CDummyECCCipherImpl::ImplementationUid() const sl@0: { sl@0: return KCryptoPluginEccCipherUid; sl@0: } sl@0: sl@0: CDummyECCCipherImpl::~CDummyECCCipherImpl() sl@0: { sl@0: delete iKey; sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::EncryptL(const TDesC8& /* aInput */, TDes8& /* aOuput */) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: void CDummyECCCipherImpl::DecryptL(const TDesC8& aInput, TDes8& aOutput) sl@0: { sl@0: if (iKey->IsPresent(KPassedHandleToKeyUid)) sl@0: { sl@0: const TInt& keyHandle = iKey->GetTIntL(KPassedHandleToKeyUid); sl@0: sl@0: // Invoke the Spi HAI to perform the operation sl@0: CCryptoSpiHai::DecryptL(keyHandle, aInput, aOutput); sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: } sl@0: // End of file sl@0: sl@0: