os/security/crypto/weakcryptospi/test/tplugins/src/randomimpl.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21 */
    22 
    23 #include <e32std.h>
    24 #include <e32math.h>
    25 #include <e32debug.h>
    26 
    27 #include "randomimpl.h"
    28 #include "pluginentry.h"
    29 #include "pluginconfig.h"
    30 #include "securityerr.h"
    31 
    32 using namespace SoftwareCrypto;
    33 
    34 
    35 CRandomImpl* CRandomImpl::NewL(TUid aImplementationUid)
    36 	{
    37 	CRandomImpl* self = new(ELeave)CRandomImpl(aImplementationUid);
    38 	return self;
    39 	}
    40 
    41 CRandomImpl* CRandomImpl::NewLC(TUid aImplementationUid)
    42 	{
    43 	CRandomImpl* self = NewL(aImplementationUid);
    44 	CleanupStack::PushL(self);
    45 	return self;
    46 	}
    47 
    48 void CRandomImpl::GenerateRandomBytesL(TDes8& aDestination)
    49 	{	
    50     // Call the Math library to populate the buffer with random data.   
    51     TRAPD(err, Math::RandomL(aDestination));    
    52     if(err != KErrNone)
    53         {
    54         // As the end users are interested only in the security aspect of the output but not 
    55         // the internal states, accordingly translate the kernel side error code if required.
    56         err = (err == KErrNotReady) ? KErrNotSecure : err;
    57         
    58         User::Leave(err);
    59         }
    60 	}
    61 
    62 CRandomImpl::CRandomImpl(TUid aImplementationUid) : iImplementationUid(aImplementationUid)
    63 	{
    64 	}
    65 
    66 void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
    67 	{
    68 	TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
    69 	for (TInt i = 0; i < randomNum; i++)
    70 		{
    71 		if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
    72 			{
    73 			aPluginCharacteristics = KRandomCharacteristics[i];
    74 			break;
    75 			}
    76 		}
    77 	}
    78 	
    79 TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/)
    80 	{
    81 	return NULL;
    82 	}
    83 	
    84 CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL()
    85 	{
    86 	// All Symbian software plug-ins have unlimited concurrency, cannot be reserved
    87 	// for exclusive use and are not CERTIFIED to be standards compliant.
    88 	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
    89 	}
    90 
    91 const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL()
    92 	{
    93 	return CRandomImpl::CreateExtendedCharacteristicsL();
    94 	}
    95 
    96 TUid CRandomImpl::ImplementationUid() const
    97 	{
    98 	return iImplementationUid;
    99 	}
   100 
   101 CRandomImpl::~CRandomImpl()
   102 	{
   103 	}
   104 
   105 void CRandomImpl::Close()
   106 	{
   107 	delete this;
   108 	}
   109 
   110 // All crypto plugins must implement this, to reset
   111 // hardware if required. Do nothing in this version
   112 void CRandomImpl::Reset()
   113 	{
   114 	}