os/security/cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/dummyeccimpl.cpp
Update contrib.
2 * Copyright (c) 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.
19 #include "dummyeccimpl.h"
22 #include <cryptospi/cryptospidef.h>
24 #include <cryptospi/plugincharacteristics.h>
25 #include "pluginconfig.h"
26 #include "cryptospihai.h"
28 using namespace DummyEccHwCrypto;
29 using namespace CryptoSpiHai;
32 * These are just randomly selected numbers. There is no logic behind
35 const TInt KMaxOutputLength = 50;
36 const TInt KMaxInputLength = 50;
38 CDummyECCCipherImpl* CDummyECCCipherImpl::NewL(const CKey& aKey,
39 TUid aCryptoMode, TUid aPaddingMode)
41 CDummyECCCipherImpl* self = CDummyECCCipherImpl::NewLC(aKey, aCryptoMode,
43 CleanupStack::Pop(self);
47 CDummyECCCipherImpl* CDummyECCCipherImpl::NewLC(const CKey& aKey,
48 TUid aCryptoMode, TUid aPaddingMode)
50 CDummyECCCipherImpl* self = new (ELeave) CDummyECCCipherImpl(aCryptoMode,
52 CleanupStack::PushL(self);
53 self->ConstructL(aKey);
57 CDummyECCCipherImpl::CDummyECCCipherImpl(TUid aCryptoMode, TUid aPaddingMode) :
58 iCryptoMode(aCryptoMode), iPaddingMode(aPaddingMode)
62 void CDummyECCCipherImpl::ConstructL(const CKey& aKey)
67 // MPlugin Interface Start
68 void CDummyECCCipherImpl::Close()
73 void CDummyECCCipherImpl::Reset()
77 void CDummyECCCipherImpl::GetCharacteristicsL(
78 const TCharacteristics*& aPluginCharacteristics)
80 TInt numCiphers = sizeof(KAsymmetricCipherCharacteristics)
81 / sizeof(TAsymmetricCipherCharacteristics*);
82 TInt32 implUid = ImplementationUid().iUid;
83 for (TInt i = 0; i < numCiphers; ++i)
85 if (KAsymmetricCipherCharacteristics[i]->cmn.iImplementationUID
88 aPluginCharacteristics = KAsymmetricCipherCharacteristics[i];
94 const CExtendedCharacteristics* CDummyECCCipherImpl::GetExtendedCharacteristicsL()
96 // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
97 // for exclusive use and are not CERTIFIED to be standards compliant.
98 return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
101 TAny* CDummyECCCipherImpl::GetExtension(TUid /* aExtensionId */)
105 // End of MPlugin Interface
107 // MAsymmetricCipherBase Interface
108 void CDummyECCCipherImpl::SetKeyL(const CKey& aKey)
110 // delete any previous key and recreate the key
113 iKey = CKey::NewL(aKey);
116 void CDummyECCCipherImpl::SetCryptoModeL(TUid aCryptoMode)
118 switch (aCryptoMode.iUid)
120 case KCryptoModeEncrypt:
121 case KCryptoModeDecrypt:
124 User::Leave(KErrNotSupported);
126 iCryptoMode = aCryptoMode;
129 void CDummyECCCipherImpl::SetPaddingModeL(TUid /* aPaddingMode */)
131 User::Leave(KErrNotSupported);
134 TInt CDummyECCCipherImpl::GetMaximumInputLengthL() const
136 return KMaxInputLength;
139 TInt CDummyECCCipherImpl::GetMaximumOutputLengthL() const
141 return KMaxOutputLength;
143 // End of MAsymmetricCipherBase Interface
145 // MAsymmetricCipher Interface
146 void CDummyECCCipherImpl::ProcessL(const TDesC8& aInput, TDes8& aOutput)
148 if (iCryptoMode.iUid == KCryptoModeEncrypt)
150 EncryptL(aInput, aOutput);
154 DecryptL(aInput, aOutput);
158 TUid CDummyECCCipherImpl::ImplementationUid() const
160 return KCryptoPluginEccCipherUid;
163 CDummyECCCipherImpl::~CDummyECCCipherImpl()
168 void CDummyECCCipherImpl::EncryptL(const TDesC8& /* aInput */, TDes8& /* aOuput */)
170 User::Leave(KErrNotSupported);
173 void CDummyECCCipherImpl::DecryptL(const TDesC8& aInput, TDes8& aOutput)
175 if (iKey->IsPresent(KPassedHandleToKeyUid))
177 const TInt& keyHandle = iKey->GetTIntL(KPassedHandleToKeyUid);
179 // Invoke the Spi HAI to perform the operation
180 CCryptoSpiHai::DecryptL(keyHandle, aInput, aOutput);
184 User::Leave(KErrNotSupported);