sl@0: /* sl@0: * Copyright (c) 2005-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: */ sl@0: sl@0: #include 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: #include "securityerr.h" sl@0: sl@0: using namespace SoftwareCrypto; sl@0: sl@0: CRandomImpl* CRandomImpl::NewL(void) sl@0: { sl@0: CRandomImpl* self = new(ELeave)CRandomImpl(); sl@0: return self; sl@0: } sl@0: sl@0: CRandomImpl* CRandomImpl::NewLC(void) sl@0: { sl@0: CRandomImpl* self = NewL(); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: void CRandomImpl::GenerateRandomBytesL(TDes8& aDestination) sl@0: { sl@0: // Call the Math library to populate the buffer with random data. sl@0: TRAPD(err, Math::RandomL(aDestination)); sl@0: if(err != KErrNone) sl@0: { sl@0: // As the end users are interested only in the security aspect of the output but not sl@0: // the internal states, accordingly translate the kernel side error code if required. sl@0: err = (err == KErrNotReady) ? KErrNotSecure : err; sl@0: User::Leave(err); sl@0: } sl@0: } sl@0: sl@0: CRandomImpl::CRandomImpl(void) sl@0: { 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: CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL() 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: const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL() sl@0: { sl@0: return CRandomImpl::CreateExtendedCharacteristicsL(); 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: } 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: // Methods which are not supported can be excluded from the coverage. sl@0: #ifdef _BullseyeCoverage sl@0: #pragma suppress_warnings on sl@0: #pragma BullseyeCoverage off sl@0: #pragma suppress_warnings off sl@0: #endif sl@0: sl@0: TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/) sl@0: { sl@0: return NULL; sl@0: }