os/security/cryptoplugins/cryptospiplugins/source/softwarecrypto/randomimpl.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 CRandomImpl* CRandomImpl::NewL(void)
    35 	{
    36 	CRandomImpl* self = new(ELeave)CRandomImpl();
    37 	return self;
    38 	}
    39 
    40 CRandomImpl* CRandomImpl::NewLC(void)
    41 	{
    42 	CRandomImpl* self = NewL();
    43 	CleanupStack::PushL(self);
    44 	return self;
    45 	}
    46 
    47 void CRandomImpl::GenerateRandomBytesL(TDes8& aDestination)
    48 	{
    49 	// Call the Math library to populate the buffer with random data.	
    50 	TRAPD(err, Math::RandomL(aDestination));	
    51 	if(err != KErrNone)
    52 	    {
    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;
    56 	    User::Leave(err);
    57 	    }
    58 	}
    59 
    60 CRandomImpl::CRandomImpl(void)
    61 	{
    62 	}
    63 
    64 void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
    65 	{
    66 	TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
    67 	for (TInt i = 0; i < randomNum; i++)
    68 		{
    69 		if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
    70 			{
    71 			aPluginCharacteristics = KRandomCharacteristics[i];
    72 			break;
    73 			}
    74 		}
    75 	}
    76 
    77 CExtendedCharacteristics* CRandomImpl::CreateExtendedCharacteristicsL()
    78 	{
    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);
    82 	}
    83 
    84 const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL()
    85 	{
    86 	return CRandomImpl::CreateExtendedCharacteristicsL();
    87 	}
    88 
    89 TUid CRandomImpl::ImplementationUid() const
    90 	{
    91 	return KCryptoPluginRandomUid;
    92 	}
    93 
    94 CRandomImpl::~CRandomImpl()
    95 	{
    96 	}
    97 
    98 void CRandomImpl::Close()
    99 	{
   100 	delete this;
   101 	}
   102 
   103 // All crypto plugins must implement this, to reset
   104 // hardware if required. Do nothing in this version
   105 void CRandomImpl::Reset()
   106 	{
   107 	}
   108 
   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
   114 #endif
   115 
   116 TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/)
   117 	{
   118 	return NULL;
   119 	}