os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/randomimpl.cpp
First public contribution.
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.
27 #include "randomimpl.h"
28 #include "pluginentry.h"
29 #include "pluginconfig.h"
31 using namespace HwCrypto;
33 _LIT(KLddFileName,"cryptoldd.ldd");
34 _LIT(KPddFileName,"crypto.h4.pdd");
37 CRandomImpl* CRandomImpl::NewL()
39 CRandomImpl* self = NewLC();
40 CleanupStack::Pop(self);
44 CRandomImpl* CRandomImpl::NewLC()
46 CRandomImpl* self = new(ELeave)CRandomImpl();
47 CleanupStack::PushL(self);
52 void CRandomImpl::ConstructL()
54 // RDebug::Printf("CRandomImpl::ConstructL");
56 TInt r = User::LoadPhysicalDevice(KPddFileName);
57 if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
60 r = User::LoadLogicalDevice(KLddFileName);
61 if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
64 User::LeaveIfError(iCryptoDriver.Open());
68 void CRandomImpl::GenerateRandomBytesL(TDes8& aDest)
70 TRequestStatus status;
71 iCryptoDriver.Random(status, aDest);
72 User::WaitForRequest(status);
73 User::LeaveIfError(status.Int());
76 CRandomImpl::CRandomImpl()
81 const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL()
83 return StaticGetExtendedCharacteristicsL();
86 CExtendedCharacteristics* CRandomImpl::StaticGetExtendedCharacteristicsL()
88 // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
89 // for exclusive use and are not CERTIFIED to be standards compliant.
90 return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
93 void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
95 TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
96 for (TInt i = 0; i < randomNum; i++)
98 if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
100 aPluginCharacteristics = KRandomCharacteristics[i];
106 TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/)
111 TUid CRandomImpl::ImplementationUid() const
113 return KCryptoPluginRandomUid;
116 CRandomImpl::~CRandomImpl()
118 iCryptoDriver.Close();
119 // RDebug::Printf("CRandomImpl::~CRandomImpl");
122 void CRandomImpl::Close()
127 // All crypto plugins must implement this, to reset
128 // hardware if required. Do nothing in this version
129 void CRandomImpl::Reset()