First public contribution.
2 * Copyright (c) 2005-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"
30 #include "securityerr.h"
32 using namespace SoftwareCrypto;
34 CRandomImpl* CRandomImpl::NewL(void)
36 CRandomImpl* self = new(ELeave)CRandomImpl();
40 CRandomImpl* CRandomImpl::NewLC(void)
42 CRandomImpl* self = NewL();
43 CleanupStack::PushL(self);
47 void CRandomImpl::GenerateRandomBytesL(TDes8& aDestination)
49 // Call the Math library to populate the buffer with random data.
50 TRAPD(err, Math::RandomL(aDestination));
53 // As the end users are interested only in the security aspect of the output but not
54 // the internal states, accordingly translate the kernel side error code if required.
55 err = (err == KErrNotReady) ? KErrNotSecure : err;
60 CRandomImpl::CRandomImpl(void)
64 void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
66 TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
67 for (TInt i = 0; i < randomNum; i++)
69 if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
71 aPluginCharacteristics = KRandomCharacteristics[i];
77 CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL()
79 // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
80 // for exclusive use and are not CERTIFIED to be standards compliant.
81 return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
84 const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL()
86 return CRandomImpl::CreateExtendedCharacteristicsL();
89 TUid CRandomImpl::ImplementationUid() const
91 return KCryptoPluginRandomUid;
94 CRandomImpl::~CRandomImpl()
98 void CRandomImpl::Close()
103 // All crypto plugins must implement this, to reset
104 // hardware if required. Do nothing in this version
105 void CRandomImpl::Reset()
109 // Methods which are not supported can be excluded from the coverage.
110 #ifdef _BullseyeCoverage
111 #pragma suppress_warnings on
112 #pragma BullseyeCoverage off
113 #pragma suppress_warnings off
116 TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/)