os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/randomimpl.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-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  @internalComponent
    22  @released
    23 */
    24 #include <e32std.h>
    25 #include <e32debug.h>
    26 
    27 #include "randomimpl.h"
    28 #include "pluginentry.h"
    29 #include "pluginconfig.h"
    30 
    31 using namespace HwCrypto;
    32 
    33 _LIT(KLddFileName,"cryptoldd.ldd");
    34 _LIT(KPddFileName,"crypto.h4.pdd");
    35 
    36 
    37 CRandomImpl* CRandomImpl::NewL()
    38 	{
    39 	CRandomImpl* self = NewLC();
    40 	CleanupStack::Pop(self);
    41 	return self;
    42 	}
    43 
    44 CRandomImpl* CRandomImpl::NewLC()
    45 	{
    46 	CRandomImpl* self = new(ELeave)CRandomImpl();
    47 	CleanupStack::PushL(self);
    48 	self->ConstructL();
    49 	return self;
    50 	}
    51 
    52 void CRandomImpl::ConstructL()
    53 	{
    54 	//	RDebug::Printf("CRandomImpl::ConstructL");
    55 	// Load PDD
    56     TInt r = User::LoadPhysicalDevice(KPddFileName);
    57 	if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
    58 
    59 	// Load LDD
    60     r = User::LoadLogicalDevice(KLddFileName);
    61 	if((r != KErrNone) && (r != KErrAlreadyExists)) User::Leave(r);
    62 
    63 	// Open driver handle
    64 	User::LeaveIfError(iCryptoDriver.Open());
    65 	}
    66 
    67 
    68 void CRandomImpl::GenerateRandomBytesL(TDes8& aDest)
    69 	{
    70     TRequestStatus status;
    71 	iCryptoDriver.Random(status, aDest);
    72 	User::WaitForRequest(status);
    73 	User::LeaveIfError(status.Int());
    74 	}
    75 
    76 CRandomImpl::CRandomImpl()
    77 	{
    78 	}
    79 
    80 
    81 const CExtendedCharacteristics* CRandomImpl::GetExtendedCharacteristicsL()
    82 	{
    83 	return StaticGetExtendedCharacteristicsL();
    84 	}
    85 
    86 CExtendedCharacteristics* CRandomImpl::StaticGetExtendedCharacteristicsL()
    87 	{
    88 	// All Symbian software plug-ins have unlimited concurrency, cannot be reserved
    89 	// for exclusive use and are not CERTIFIED to be standards compliant.
    90 	return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
    91 	}
    92 
    93 void CRandomImpl::GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics)
    94 	{
    95 	TInt randomNum = sizeof(KRandomCharacteristics)/sizeof(TRandomCharacteristics*);
    96 	for (TInt i = 0; i < randomNum; i++)
    97 		{
    98 		if (KRandomCharacteristics[i]->cmn.iImplementationUID == ImplementationUid().iUid)
    99 			{
   100 			aPluginCharacteristics = KRandomCharacteristics[i];
   101 			break;
   102 			}
   103 		}
   104 	}
   105 	
   106 TAny* CRandomImpl::GetExtension(TUid /*aExtensionId*/)
   107 	{
   108 	return NULL;
   109 	}
   110 
   111 TUid CRandomImpl::ImplementationUid() const
   112 	{
   113 	return KCryptoPluginRandomUid;
   114 	}
   115 
   116 CRandomImpl::~CRandomImpl()
   117 	{
   118 	iCryptoDriver.Close();
   119 	//	RDebug::Printf("CRandomImpl::~CRandomImpl");
   120 	}
   121 
   122 void CRandomImpl::Close()
   123 	{
   124 	delete this;
   125 	}
   126 
   127 // All crypto plugins must implement this, to reset
   128 // hardware if required. Do nothing in this version
   129 void CRandomImpl::Reset()
   130 	{
   131 	}
   132 
   133 // End of file