os/security/crypto/weakcryptospi/test/tplugins/src/randomimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tplugins/src/randomimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,114 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 +*/
    1.25 +
    1.26 +#include <e32std.h>
    1.27 +#include <e32math.h>
    1.28 +#include <e32debug.h>
    1.29 +
    1.30 +#include "randomimpl.h"
    1.31 +#include "pluginentry.h"
    1.32 +#include "pluginconfig.h"
    1.33 +#include "securityerr.h"
    1.34 +
    1.35 +using namespace SoftwareCrypto;
    1.36 +
    1.37 +
    1.38 +CRandomImpl* CRandomImpl::NewL(TUid aImplementationUid)
    1.39 +	{
    1.40 +	CRandomImpl* self = new(ELeave)CRandomImpl(aImplementationUid);
    1.41 +	return self;
    1.42 +	}
    1.43 +
    1.44 +CRandomImpl* CRandomImpl::NewLC(TUid aImplementationUid)
    1.45 +	{
    1.46 +	CRandomImpl* self = NewL(aImplementationUid);
    1.47 +	CleanupStack::PushL(self);
    1.48 +	return self;
    1.49 +	}
    1.50 +
    1.51 +void CRandomImpl::GenerateRandomBytesL(TDes8& aDestination)
    1.52 +	{	
    1.53 +    // Call the Math library to populate the buffer with random data.   
    1.54 +    TRAPD(err, Math::RandomL(aDestination));    
    1.55 +    if(err != KErrNone)
    1.56 +        {
    1.57 +        // As the end users are interested only in the security aspect of the output but not 
    1.58 +        // the internal states, accordingly translate the kernel side error code if required.
    1.59 +        err = (err == KErrNotReady) ? KErrNotSecure : err;
    1.60 +        
    1.61 +        User::Leave(err);
    1.62 +        }
    1.63 +	}
    1.64 +
    1.65 +CRandomImpl::CRandomImpl(TUid aImplementationUid) : iImplementationUid(aImplementationUid)
    1.66 +	{
    1.67 +	}
    1.68 +
    1.69 +void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
    1.70 +	{
    1.71 +	TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
    1.72 +	for (TInt i = 0; i < randomNum; i++)
    1.73 +		{
    1.74 +		if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
    1.75 +			{
    1.76 +			aPluginCharacteristics = KRandomCharacteristics[i];
    1.77 +			break;
    1.78 +			}
    1.79 +		}
    1.80 +	}
    1.81 +	
    1.82 +TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/)
    1.83 +	{
    1.84 +	return NULL;
    1.85 +	}
    1.86 +	
    1.87 +CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL()
    1.88 +	{
    1.89 +	// All Symbian software plug-ins have unlimited concurrency, cannot be reserved
    1.90 +	// for exclusive use and are not CERTIFIED to be standards compliant.
    1.91 +	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
    1.92 +	}
    1.93 +
    1.94 +const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL()
    1.95 +	{
    1.96 +	return CRandomImpl::CreateExtendedCharacteristicsL();
    1.97 +	}
    1.98 +
    1.99 +TUid CRandomImpl::ImplementationUid() const
   1.100 +	{
   1.101 +	return iImplementationUid;
   1.102 +	}
   1.103 +
   1.104 +CRandomImpl::~CRandomImpl()
   1.105 +	{
   1.106 +	}
   1.107 +
   1.108 +void CRandomImpl::Close()
   1.109 +	{
   1.110 +	delete this;
   1.111 +	}
   1.112 +
   1.113 +// All crypto plugins must implement this, to reset
   1.114 +// hardware if required. Do nothing in this version
   1.115 +void CRandomImpl::Reset()
   1.116 +	{
   1.117 +	}