sl@0: /* sl@0: * Copyright (c) 2007-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: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: #include sl@0: #include sl@0: sl@0: #include "randomimpl.h" sl@0: #include "pluginentry.h" sl@0: #include "pluginconfig.h" sl@0: sl@0: using namespace HwCrypto; sl@0: sl@0: _LIT(KLddFileName,"cryptoldd.ldd"); sl@0: _LIT(KPddFileName,"crypto.h4.pdd"); sl@0: sl@0: sl@0: CRandomImpl* CRandomImpl::NewL() sl@0: { sl@0: CRandomImpl* self = NewLC(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CRandomImpl* CRandomImpl::NewLC() sl@0: { sl@0: CRandomImpl* self = new(ELeave)CRandomImpl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: void CRandomImpl::ConstructL() sl@0: { sl@0: // RDebug::Printf("CRandomImpl::ConstructL"); sl@0: // Load PDD sl@0: TInt r = User::LoadPhysicalDevice(KPddFileName); sl@0: if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r); sl@0: sl@0: // Load LDD sl@0: r = User::LoadLogicalDevice(KLddFileName); sl@0: if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r); sl@0: sl@0: // Open driver handle sl@0: User::LeaveIfError(iCryptoDriver.Open()); sl@0: } sl@0: sl@0: sl@0: void CRandomImpl::GenerateRandomBytesL(TDes8& aDest) sl@0: { sl@0: TRequestStatus status; sl@0: iCryptoDriver.Random(status, aDest); sl@0: User::WaitForRequest(status); sl@0: User::LeaveIfError(status.Int()); sl@0: } sl@0: sl@0: CRandomImpl::CRandomImpl() sl@0: { sl@0: } sl@0: sl@0: sl@0: const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL() sl@0: { sl@0: return StaticGetExtendedCharacteristicsL(); sl@0: } sl@0: sl@0: CExtendedCharacteristics* CRandomImpl::StaticGetExtendedCharacteristicsL() 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: void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics) sl@0: { sl@0: TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*); sl@0: for (TInt i = 0; i < randomNum; i++) sl@0: { sl@0: if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid) sl@0: { sl@0: aPluginCharacteristics = KRandomCharacteristics[i]; sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/) sl@0: { sl@0: return NULL; sl@0: } sl@0: sl@0: TUid CRandomImpl::ImplementationUid() const sl@0: { sl@0: return KCryptoPluginRandomUid; sl@0: } sl@0: sl@0: CRandomImpl::~CRandomImpl() sl@0: { sl@0: iCryptoDriver.Close(); sl@0: // RDebug::Printf("CRandomImpl::~CRandomImpl"); sl@0: } sl@0: sl@0: void CRandomImpl::Close() sl@0: { sl@0: delete this; sl@0: } sl@0: sl@0: // All crypto plugins must implement this, to reset sl@0: // hardware if required. Do nothing in this version sl@0: void CRandomImpl::Reset() sl@0: { sl@0: } sl@0: sl@0: // End of file