epoc32/include/cryptospi/cryptorandomapi.h
branchSymbian3
changeset 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/cryptospi/cryptorandomapi.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-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 +* crypto random application interface
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @publishedAll
    1.26 + @released
    1.27 +*/
    1.28 +
    1.29 +#ifndef __CRYPTOAPI_RANDOMAPI_H__
    1.30 +#define __CRYPTOAPI_RANDOMAPI_H__
    1.31 +
    1.32 +#include <cryptospi/cryptobaseapi.h>
    1.33 +
    1.34 +namespace CryptoSpi
    1.35 +	{
    1.36 +	class MRandom;
    1.37 +	class MAsyncRandom;
    1.38 +	class CCryptoParams;
    1.39 +	/**
    1.40 +	Synchronous Random API, which wraps a synchronous Random plugin implementation
    1.41 +	*/
    1.42 +	NONSHARABLE_CLASS(CRandom) : public CCryptoBase
    1.43 +		{
    1.44 +	public:
    1.45 +		/**
    1.46 +		 * @internalComponent
    1.47 +		 * 
    1.48 +		 * Create a CRandom instance from the given MRandom instance
    1.49 +		 * @param aRandom	The random plugin instance
    1.50 +		 * @return A pointer to a CRandom instance
    1.51 +		 **/
    1.52 +		static CRandom* NewL(MRandom* aRandom, TInt aHandle);
    1.53 +
    1.54 +		/**
    1.55 +		Destructor
    1.56 +		*/
    1.57 +		IMPORT_C ~CRandom();
    1.58 +
    1.59 +		/**
    1.60 +		 * Generate enough random bytes to fill the supplied descriptor
    1.61 +		 * If there is not enough entropy available, or another error
    1.62 +		 * occurs (e.g. out of memory) then this method may leave.
    1.63 +		 * @param aDest	The returned generated random bytes filling the descriptor
    1.64 +		 */
    1.65 +		IMPORT_C void GenerateRandomBytesL(TDes8& aDest);
    1.66 +
    1.67 +	private:
    1.68 +		
    1.69 +		/**
    1.70 +		Constructor
    1.71 +		*/
    1.72 +		CRandom(MRandom* aRandom, TInt aHandle);
    1.73 +		
    1.74 +		};
    1.75 +
    1.76 +
    1.77 +	/**
    1.78 +	Asynchronous Random API, which wraps an asynchronous Random plugin implementation
    1.79 +	*/
    1.80 +
    1.81 +	NONSHARABLE_CLASS(CAsyncRandom) : public CCryptoBase
    1.82 +		{
    1.83 +	public:
    1.84 +		/**
    1.85 +		 * @internalComponent
    1.86 +		 * 
    1.87 +		 * Create a CRandom instance from the given MRandom instance
    1.88 +		 * @param aAsyncRandom		The async random plugin instance
    1.89 +		 * @return A pointer to a CAsyncRandom instance
    1.90 +		 **/
    1.91 +		static CAsyncRandom* NewL(MAsyncRandom* aAsyncRandom, TInt aHandle);
    1.92 +
    1.93 +		/**
    1.94 +		Destructor
    1.95 +		*/
    1.96 +		IMPORT_C ~CAsyncRandom();
    1.97 +
    1.98 +		/**
    1.99 +		 * Generate enough random bytes to fill the supplied descriptor
   1.100 +		 * If there is not enough entropy available, or another error
   1.101 +		 * occurs (e.g. out of memory) then this method may leave.
   1.102 +		 * @param aDest  The returned generated random bytes filling the descriptor
   1.103 +		 * @param aStatus
   1.104 +		 */
   1.105 +		IMPORT_C void GenerateRandomBytesL(TDes8& aDest, TRequestStatus& aStatus);
   1.106 +
   1.107 +	private:
   1.108 +		
   1.109 +		/**
   1.110 +		Constructor
   1.111 +		*/
   1.112 +		CAsyncRandom(MAsyncRandom* aAsyncRandom, TInt aHandle);
   1.113 +		
   1.114 +		};
   1.115 +
   1.116 +
   1.117 +	/**
   1.118 +	the Factory to create synchronous and asynchronous hash instance 
   1.119 +	*/
   1.120 +	class CRandomFactory
   1.121 +		{
   1.122 +
   1.123 +	public:
   1.124 +		/**
   1.125 +		Creates a new instance of a Random object.
   1.126 +
   1.127 +		@param aRandom A reference to a pointer that should be set to point to the new CRandom object.
   1.128 +		@param aAlgorithmUid The algorithm to use
   1.129 +		@param aAlgorithmParams Parameters that are specific this algorithm.
   1.130 +		@return KErrNone if successful; otherwise, a system wide error code.
   1.131 +		*/
   1.132 +		IMPORT_C static void CreateRandomL(CRandom*& aRandom,
   1.133 +										TUid aAlgorithmUid,
   1.134 +										const CCryptoParams* aAlgorithmParams);
   1.135 +
   1.136 +		/**
   1.137 +		Creates a new asynchronous instance of a Random object.
   1.138 +
   1.139 +		@param aAsyncRandom A reference to a pointer that should be set to point to the new CAsyncRandom object.
   1.140 +		@param aAlgorithmUid The algorithm to use
   1.141 +		@param aAlgorithmParams Parameters that are specific this particular algorithm.
   1.142 +		@return KErrNone if successful; otherwise, a system wide error code.
   1.143 +		*/
   1.144 +		IMPORT_C static void CreateAsyncRandomL(CAsyncRandom*& aAsyncRandom,
   1.145 +											TUid aAlgorithmUid,
   1.146 +											const CCryptoParams* aAlgorithmParams);
   1.147 +
   1.148 +		};
   1.149 +	}
   1.150 +
   1.151 +#endif //__CRYPTOAPI_RANDOMAPI_H__