Update contrib.
2 * Copyright (c) 2007-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 * crypto plugins loader implementation
16 * crypto spi state implementation
25 #include <cryptospi/cryptocharacteristics.h>
26 #include <cryptospi/cryptospidef.h>
27 #include "cryptospiutil.h"
28 #include <cryptospi/extendedcharacteristics.h>
31 using namespace CryptoSpi;
35 // Implementation of CCharacteristics
37 CCharacteristics::CCharacteristics()
41 CCharacteristics::~CCharacteristics()
44 iAlgorithmName.Close();
47 void CCharacteristics::InternalizeL(RReadStream& aStream)
49 iInterfaceUid=aStream.ReadInt32L();
50 iAlgorithmUid=aStream.ReadInt32L();
51 iImplementationUid=aStream.ReadInt32L();
52 iCreatorName.CreateL(aStream, KMaxFileName);
53 iIsFIPSApproved=aStream.ReadInt8L();
54 iIsHardwareSupported=aStream.ReadInt8L();
55 iMaxConcurrencySupported=aStream.ReadUint32L();
56 iAlgorithmName.CreateL(aStream, KMaxFileName);
57 iLatency=aStream.ReadInt32L();
58 iThroughput=aStream.ReadInt32L();
62 // Implementation of CHashCharacteristics
64 CHashCharacteristics* CHashCharacteristics::NewL()
66 CHashCharacteristics* self=CHashCharacteristics::NewLC();
67 CleanupStack::Pop(self);
71 CHashCharacteristics* CHashCharacteristics::NewLC()
73 CHashCharacteristics* self=new(ELeave) CHashCharacteristics();
74 CleanupStack::PushL(self);
78 CHashCharacteristics::~CHashCharacteristics()
80 iSupportedOperationModes.Close();
83 CHashCharacteristics::CHashCharacteristics()
87 void CHashCharacteristics::InternalizeL(RReadStream& aStream)
89 CCharacteristics::InternalizeL(aStream);
90 iBlockSize=aStream.ReadUint32L();
91 iOutputSize=aStream.ReadUint32L();
92 TUint32 count=aStream.ReadUint32L();
93 for (TUint i=0;i<count;i++)
95 TInt32 mode=aStream.ReadInt32L();
96 iSupportedOperationModes.AppendL(mode);
100 TBool CHashCharacteristics::IsOperationModeSupported(TUid aOperationMode) const
102 // Sanity check to catch incorrect casts of characteristics classes
103 ASSERT(iInterfaceUid == KHashInterface);
105 TInt count(iSupportedOperationModes.Count());
106 TBool supported(EFalse);
108 for (TInt i = 0; i < count; ++i)
110 if (iSupportedOperationModes[i] == aOperationMode.iUid)
120 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
122 // Implementation of CMacCharacteristics
124 CMacCharacteristics* CMacCharacteristics::NewL()
126 CMacCharacteristics* self=CMacCharacteristics::NewLC();
127 CleanupStack::Pop(self);
131 CMacCharacteristics* CMacCharacteristics::NewLC()
133 CMacCharacteristics* self=new(ELeave) CMacCharacteristics();
134 CleanupStack::PushL(self);
138 CMacCharacteristics::~CMacCharacteristics()
140 delete iAlgorithmChar;
143 CMacCharacteristics::CMacCharacteristics()
147 void CMacCharacteristics::InternalizeL(RReadStream& aStream)
149 CCharacteristics::InternalizeL(aStream);
150 iMacMode = aStream.ReadUint32L();
151 if(iMacMode == KHmacMode)
153 iAlgorithmChar = CHashCharacteristics::NewL();
155 else if (iMacMode == KSymmetricCipherMode)
157 iAlgorithmChar = CSymmetricCipherCharacteristics::NewL();
159 User::LeaveIfNull(iAlgorithmChar);
160 iAlgorithmChar->InternalizeL(aStream);
164 // Implementation of CRandomCharacteristics
166 CRandomCharacteristics* CRandomCharacteristics::NewL()
168 CRandomCharacteristics* self=CRandomCharacteristics::NewLC();
169 CleanupStack::Pop(self);
173 CRandomCharacteristics* CRandomCharacteristics::NewLC()
175 CRandomCharacteristics* self=new(ELeave) CRandomCharacteristics();
176 CleanupStack::PushL(self);
180 CRandomCharacteristics::~CRandomCharacteristics()
184 CRandomCharacteristics::CRandomCharacteristics()
188 void CRandomCharacteristics::InternalizeL(RReadStream& aStream)
190 CCharacteristics::InternalizeL(aStream);
191 iBlockingMode=aStream.ReadUint32L();
195 // Implementation of CSymmetricCipherCharacteristics
197 CSymmetricCipherCharacteristics* CSymmetricCipherCharacteristics::NewL()
199 CSymmetricCipherCharacteristics* self=CSymmetricCipherCharacteristics::NewLC();
200 CleanupStack::Pop(self);
204 CSymmetricCipherCharacteristics* CSymmetricCipherCharacteristics::NewLC()
206 CSymmetricCipherCharacteristics* self=new(ELeave) CSymmetricCipherCharacteristics();
207 CleanupStack::PushL(self);
211 CSymmetricCipherCharacteristics::~CSymmetricCipherCharacteristics()
213 iSupportedPaddingModes.Close();
214 iSupportedOperationModes.Close();
217 CSymmetricCipherCharacteristics::CSymmetricCipherCharacteristics()
221 void CSymmetricCipherCharacteristics::InternalizeL(RReadStream& aStream)
223 CCharacteristics::InternalizeL(aStream);
224 iMaximumKeyLength=aStream.ReadUint32L();
225 iBlockSize=aStream.ReadUint32L();
226 TUint32 count=aStream.ReadUint32L();
227 for (TUint i=0;i<count;i++)
229 TInt32 mode=aStream.ReadInt32L();
230 iSupportedPaddingModes.AppendL(mode);
233 count=aStream.ReadUint32L();
234 for (TUint j=0;j<count;j++)
236 TInt32 mode=aStream.ReadInt32L();
237 iSupportedOperationModes.AppendL(mode);
239 iKeySupportMode=aStream.ReadInt32L();
242 TBool CSymmetricCipherCharacteristics::IsOperationModeSupported(TUid aOperationMode) const
244 // Sanity check to catch incorrect casts of characteristics classes
245 ASSERT(iInterfaceUid == KSymmetricCipherInterface);
247 TBool supported(EFalse);
248 TInt count(iSupportedOperationModes.Count());
250 for (TInt i = 0; i < count; ++i)
252 if (iSupportedOperationModes[i] == aOperationMode.iUid)
261 TBool CSymmetricCipherCharacteristics::IsPaddingModeSupported(TUid aPaddingMode) const
263 // Sanity check to catch incorrect casts of characteristics classes
264 ASSERT(iInterfaceUid == KSymmetricCipherInterface);
266 TBool supported(EFalse);
267 TInt count(iSupportedPaddingModes.Count());
269 for (TInt i = 0; i < count; ++i)
271 if (iSupportedPaddingModes[i] == aPaddingMode.iUid)
281 // Implementation of CAsymmetricCipherCharacteristics
283 CAsymmetricCipherCharacteristics* CAsymmetricCipherCharacteristics::NewL()
285 CAsymmetricCipherCharacteristics* self=CAsymmetricCipherCharacteristics::NewLC();
286 CleanupStack::Pop(self);
290 CAsymmetricCipherCharacteristics* CAsymmetricCipherCharacteristics::NewLC()
292 CAsymmetricCipherCharacteristics* self=new(ELeave) CAsymmetricCipherCharacteristics();
293 CleanupStack::PushL(self);
297 CAsymmetricCipherCharacteristics::~CAsymmetricCipherCharacteristics()
299 iSupportedPaddingModes.Close();
302 CAsymmetricCipherCharacteristics::CAsymmetricCipherCharacteristics()
306 void CAsymmetricCipherCharacteristics::InternalizeL(RReadStream& aStream)
308 CCharacteristics::InternalizeL(aStream);
309 iMaximumKeyLength=aStream.ReadUint32L();
310 TUint32 count=aStream.ReadUint32L();
312 for (TUint i=0;i<count;i++)
314 TInt32 mode=aStream.ReadInt32L();
315 iSupportedPaddingModes.AppendL(mode);
317 iKeySupportMode=aStream.ReadInt32L();
320 TBool CAsymmetricCipherCharacteristics::IsPaddingModeSupported(TUid aPaddingMode) const
322 // Sanity check to catch incorrect casts of characteristics classes
323 ASSERT(iInterfaceUid == KAsymmetricCipherInterface);
325 TBool supported(EFalse);
326 TInt count(iSupportedPaddingModes.Count());
328 for (TInt i = 0; i < count; ++i)
330 if (iSupportedPaddingModes[i] == aPaddingMode.iUid)
340 // Implementation of CAsymmetricSignatureCharacteristics
342 CAsymmetricSignatureCharacteristics* CAsymmetricSignatureCharacteristics::NewL()
344 CAsymmetricSignatureCharacteristics* self=CAsymmetricSignatureCharacteristics::NewLC();
345 CleanupStack::Pop(self);
349 CAsymmetricSignatureCharacteristics* CAsymmetricSignatureCharacteristics::NewLC()
351 CAsymmetricSignatureCharacteristics* self=new(ELeave) CAsymmetricSignatureCharacteristics();
352 CleanupStack::PushL(self);
356 CAsymmetricSignatureCharacteristics::~CAsymmetricSignatureCharacteristics()
358 iSupportedPaddingModes.Close();
361 CAsymmetricSignatureCharacteristics::CAsymmetricSignatureCharacteristics()
365 void CAsymmetricSignatureCharacteristics::InternalizeL(RReadStream& aStream)
367 CCharacteristics::InternalizeL(aStream);
368 iMaximumKeyLength=aStream.ReadUint32L();
369 TUint32 count=aStream.ReadUint32L();
370 for (TUint i=0;i<count;i++)
372 TInt32 mode=aStream.ReadInt32L();
373 iSupportedPaddingModes.AppendL(mode);
375 iKeySupportMode=aStream.ReadInt32L();
378 TBool CAsymmetricSignatureCharacteristics::IsPaddingModeSupported(TUid aPaddingMode) const
380 // Sanity check to catch incorrect casts of characteristics classes
381 ASSERT(iInterfaceUid == KSignerInterface || iInterfaceUid == KVerifierInterface);
383 TBool supported(EFalse);
384 TInt count(iSupportedPaddingModes.Count());
386 for (TInt i = 0; i < count; ++i)
388 if (iSupportedPaddingModes[i] == aPaddingMode.iUid)
398 // Implementation of CKeyAgreementCharacteristics
400 CKeyAgreementCharacteristics* CKeyAgreementCharacteristics::NewL()
402 CKeyAgreementCharacteristics* self=CKeyAgreementCharacteristics::NewLC();
403 CleanupStack::Pop(self);
407 CKeyAgreementCharacteristics* CKeyAgreementCharacteristics::NewLC()
409 CKeyAgreementCharacteristics* self=new(ELeave) CKeyAgreementCharacteristics();
410 CleanupStack::PushL(self);
414 CKeyAgreementCharacteristics::~CKeyAgreementCharacteristics()
418 CKeyAgreementCharacteristics::CKeyAgreementCharacteristics()
422 void CKeyAgreementCharacteristics::InternalizeL(RReadStream& aStream)
424 CCharacteristics::InternalizeL(aStream);
428 // Implementation of CKeypairGeneratorCharacteristics
430 CKeypairGeneratorCharacteristics* CKeypairGeneratorCharacteristics::NewL()
432 CKeypairGeneratorCharacteristics* self=CKeypairGeneratorCharacteristics::NewLC();
433 CleanupStack::Pop(self);
437 CKeypairGeneratorCharacteristics* CKeypairGeneratorCharacteristics::NewLC()
439 CKeypairGeneratorCharacteristics* self=new(ELeave) CKeypairGeneratorCharacteristics();
440 CleanupStack::PushL(self);
444 CKeypairGeneratorCharacteristics::~CKeypairGeneratorCharacteristics()
448 CKeypairGeneratorCharacteristics::CKeypairGeneratorCharacteristics()
452 void CKeypairGeneratorCharacteristics::InternalizeL(RReadStream& aStream)
454 CCharacteristics::InternalizeL(aStream);
455 iMaximumKeyLength=aStream.ReadUint32L();
459 // Implementation of CCharacteristicsAndPluginName
461 CCharacteristicsAndPluginName* CCharacteristicsAndPluginName::NewL(TInt32 aInterface)
463 CCharacteristicsAndPluginName* self=CCharacteristicsAndPluginName::NewLC(aInterface);
464 CleanupStack::Pop(self);
468 CCharacteristicsAndPluginName* CCharacteristicsAndPluginName::NewLC(TInt32 aInterface)
470 CCharacteristicsAndPluginName* self=new(ELeave) CCharacteristicsAndPluginName();
471 CleanupStack::PushL(self);
472 self->ConstructL(aInterface);
476 CCharacteristicsAndPluginName::CCharacteristicsAndPluginName()
480 CCharacteristicsAndPluginName::~CCharacteristicsAndPluginName()
482 delete iCharacteristic;
483 if (iExtendedCharacteristic)
485 delete iExtendedCharacteristic;
489 void CCharacteristicsAndPluginName::ConstructL(TInt32 aInterface)
491 iCharacteristic=CryptoSpiUtil::CreateCharacteristicsL(aInterface);
494 void CCharacteristicsAndPluginName::InternalizeL(RReadStream& aStream)
496 iCharacteristic->InternalizeL(aStream);
497 TInt index=aStream.ReadInt8L();
498 CryptoSpiUtil::DllIndexToName(index, iDllName);