cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4_plugin/randomimpl.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 12 Oct 2009 10:17:04 +0300
changeset 15 da2ae96f639b
parent 8 35751d3474b7
child 41 9b5a3a9fddf8
permissions -rw-r--r--
Revision: 200941 Kit: 200941

/*
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


/**
 @file
 @internalComponent
 @released
*/
#ifndef __CRYPTOAPI_RANDOMIMPL_H__
#define __CRYPTOAPI_RANDOMIMPL_H__

#include <cryptospi/cryptoplugin.h>
#include <cryptospi/randomplugin.h>
#include "cryptodriver.h"

#ifdef __MARM__
#define __NOTSHARED __declspec(notshared)
#else
#define __NOTSHARED
#endif

namespace HwCrypto
	{
	using namespace CryptoSpi;
	
	//	NONSHARABLE_CLASS(CRandomImpl): public CBase, public MRandom
	class __NOTSHARED CRandomImpl : public CBase, public MRandom
		{
	public:
		// NewL & NewLC
		static CRandomImpl* NewL();
		static CRandomImpl* NewLC();
		
		// From MPlugin
		void Reset();
		void Close();
		void GetCharacteristicsL(const TCharacteristics*& aPluginCharacteristics);
		const CExtendedCharacteristics* GetExtendedCharacteristicsL();
		static CExtendedCharacteristics* StaticGetExtendedCharacteristicsL();


		TAny* GetExtension(TUid aExtensionId);
		TUid ImplementationUid() const;
		
		// From MRandom
		void GenerateRandomBytesL(TDes8& aDest);

	private:
		//Constructor
		CRandomImpl();
		
		//Destructor
		~CRandomImpl();
		
	private:
		void ConstructL();

		TUid iImplementationUid;
		RCryptoDriver iCryptoDriver;
		};

	class RRandomSessionImpl : public RSessionBase
	/**
	 * The client interface to the system random number generator. End
	 * users should use TRandom instead of this interface.
	 *
	 * @internalAll
	 * @released
	 */
		{
	public:
		RRandomSessionImpl();
		
		/**
		 * Fills the provided buffer with secure random data up to its
		 * current length, discarding any current content.
		 *
		 * @param aDestination The buffer in to which to write the random data 
		 */
		TInt GetRandom(TDes8& aDestination);
		
		/**
		 * Opens a new session with the random number server.
		 */
		void ConnectL();
		};
	}

#endif // __CRYPTOAPI_RANDOMIMPL_H__