os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptodriver.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptodriver.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,217 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-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 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @internalComponent
    1.25 + @released
    1.26 +*/
    1.27 +#ifndef CRYPTODRIVER_H
    1.28 +#define CRYPTODRIVER_H
    1.29 +
    1.30 +#include <e32cmn.h>
    1.31 +#include <e32ver.h>
    1.32 +#ifndef __KERNEL_MODE__
    1.33 +#include <e32std.h>
    1.34 +#endif
    1.35 +
    1.36 +/**
    1.37 +User interface for crypto hw
    1.38 +*/
    1.39 +class RCryptoDriver : public RBusLogicalChannel
    1.40 +    {
    1.41 +public:
    1.42 +    /**
    1.43 +    Structure for holding driver capabilities information
    1.44 +    */
    1.45 +    class TCaps
    1.46 +        {
    1.47 +    public:
    1.48 +        TVersion iVersion;
    1.49 +        };
    1.50 +
    1.51 +    /**
    1.52 +    Structure for holding driver configuration data
    1.53 +    */
    1.54 +    class TConfig
    1.55 +        {
    1.56 +    public:
    1.57 +        TInt iFakeDriverSetting;
    1.58 +        };
    1.59 +    /**
    1.60 +    Typedef used for passing TConfig structure to GetConfig and SetConfig APIs
    1.61 +    */
    1.62 +    typedef TPckgBuf<TConfig> TConfigBuf;
    1.63 +
    1.64 +    /**
    1.65 +    Structure for holding h/w version information
    1.66 +    */
    1.67 +    class THwVersions
    1.68 +        {
    1.69 +    public:
    1.70 +		TUint32 iRngHwVersion; 		///< RNG h/w version number
    1.71 +		TUint32 iDes3DesHwVersion; 	///< 3DES h/w version number
    1.72 +		TUint32 iSha1Md5HwVersion; 	///< SHA1 h/w version number
    1.73 +		TUint32 iAesHwVersion; 		///< AES h/w version number
    1.74 +		TUint32 iPkaHwVersion; 		///< PKA h/w version number
    1.75 +        };
    1.76 +    typedef TPckgBuf<THwVersions> THwVersionsBuf;
    1.77 +
    1.78 +public:
    1.79 +    IMPORT_C TInt Open();
    1.80 +    IMPORT_C TInt GetHwVersions(THwVersionsBuf& aHwVersionsBuf);
    1.81 +
    1.82 +    IMPORT_C TInt GetConfig(TConfigBuf& aConfig);
    1.83 +    IMPORT_C TInt SetConfig(const TConfigBuf& aConfig);
    1.84 +
    1.85 +    inline static const TDesC& Name();
    1.86 +    inline static TVersion VersionRequired();
    1.87 +
    1.88 +	/**
    1.89 +	   Fill buffer with random data
    1.90 +	   Only one "random" request may be pending at any time.
    1.91 +
    1.92 +	   @param aStatus 	The request to be signalled when the data has been received.
    1.93 +	   					The result value will be set to KErrNone on success;
    1.94 +						or set to one of the system wide error codes when an error occurs.
    1.95 +
    1.96 +	   @param aData 	Fills the descriptor up to its current length with
    1.97 +	   					random data. Any existing contents are lost.
    1.98 +	*/
    1.99 +	IMPORT_C void Random(TRequestStatus& aStatus, TDes8& aDestination);
   1.100 +	/**
   1.101 +	   Causes the current Random request to cancel synchronously.
   1.102 +	*/
   1.103 +    IMPORT_C void RandomCancel();
   1.104 +
   1.105 +	enum TChainingMode {EEcbMode, ECbcMode, ECntrMode};
   1.106 +	/**
   1.107 +	   @param aEncrypt ETrue for encryption
   1.108 +	   @param aMode See TChainingMode
   1.109 +	   @param aKey 	Must be one of the following lengths - 128, 192 or 256 bits (16, 24 or 32 bytes).
   1.110 +	   @param aIV Initialisation Vector, Length must be, 0 for ECB mode, or 16 bytes (all other mdoes)
   1.111 +	*/ 
   1.112 +	IMPORT_C TInt SetAesConfig(TBool aEncrypt, TChainingMode aMode, const TDesC8& aKey, const TDesC8& aIV);
   1.113 +
   1.114 +	/**
   1.115 +	   Any length of data may be written, but the h/w will only
   1.116 +	   process the data in multiples of 16 bytes. Any remainder will
   1.117 +	   be buffered pending future writes.
   1.118 +
   1.119 +	   Padding is NOT done by this function.
   1.120 +	   
   1.121 +	   Output 
   1.122 +	   
   1.123 +	   @param aStatus
   1.124 +	   @param aBuffer
   1.125 +	*/ 
   1.126 +	IMPORT_C void AesWrite(TRequestStatus& aStatus, TDesC8& aBuffer);
   1.127 +
   1.128 +	/**
   1.129 +	   Causes the current "to hw" requests to cancel synchronously.
   1.130 +	*/
   1.131 +    IMPORT_C void AesCancelWrite();
   1.132 +
   1.133 +	/**
   1.134 +	   The destination buffer is overwritten. This call will block
   1.135 +	   until the specified number of bytes have been read (the max
   1.136 +	   length of aBuffer).
   1.137 +
   1.138 +	   The length is not required to be a multiple of the block size
   1.139 +	   (16 bytes), but note that written data is only processed in
   1.140 +	   multiples of the block size.
   1.141 +
   1.142 +	   Data is appended to the supplied buffer.
   1.143 +	   
   1.144 +	   @param aStatus
   1.145 +	   @param aBuffer
   1.146 +	   @param aLength
   1.147 +	*/ 
   1.148 +	IMPORT_C void AesRead(TRequestStatus& aStatus, TDes8& aBuffer, TUint32 aLenth);
   1.149 +
   1.150 +	/**
   1.151 +	   Causes the current "from hw" requests to cancel synchronously.
   1.152 +	*/
   1.153 +    IMPORT_C void AesCancelRead();
   1.154 +
   1.155 +
   1.156 +private:
   1.157 +    /**
   1.158 +    Enumeration of Control messages.
   1.159 +    */
   1.160 +    enum TControl
   1.161 +        {
   1.162 +		EGetHwVersions,
   1.163 +		EAesSetConfig,
   1.164 +        EGetConfig,
   1.165 +        ESetConfig
   1.166 +        };
   1.167 +
   1.168 +    /**
   1.169 +    Enumeration of Request messages.
   1.170 +    */
   1.171 +    enum TRequest
   1.172 +        {
   1.173 +		ERandom,
   1.174 +		EAesWrite,
   1.175 +		EAesRead,
   1.176 +        ENumRequests,
   1.177 +        EAllRequests = (1<<ENumRequests)-1
   1.178 +        };
   1.179 +
   1.180 +    /**
   1.181 +    Structure for holding driver configuration data
   1.182 +    */
   1.183 +    class TAesConfig
   1.184 +        {
   1.185 +    public:
   1.186 +		TBool iEncrypt;
   1.187 +		TChainingMode iMode;
   1.188 +		const TDesC8 *iKey;
   1.189 +		const TDesC8 *iIV;
   1.190 +        };
   1.191 +    typedef TPckgBuf<TAesConfig> TAesConfigBuf;
   1.192 +
   1.193 +    // Kernel side LDD channel is a friend
   1.194 +    friend class DCryptoLddChannel;
   1.195 +    friend class DLddChanAes;
   1.196 +    };
   1.197 +
   1.198 +
   1.199 +/**
   1.200 +  Returns the driver's name
   1.201 +*/
   1.202 +inline const TDesC& RCryptoDriver::Name()
   1.203 +    {
   1.204 +    _LIT(KDriver1Name,"crypto");
   1.205 +    return KDriver1Name;
   1.206 +    }
   1.207 +
   1.208 +/**
   1.209 +  Returns the version number of the driver
   1.210 +*/
   1.211 +inline TVersion RCryptoDriver::VersionRequired()
   1.212 +    {
   1.213 +    const TInt KMajorVersionNumber=1;
   1.214 +    const TInt KMinorVersionNumber=0;
   1.215 +    const TInt KBuildVersionNumber=KE32BuildVersionNumber;
   1.216 +    return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
   1.217 +    }
   1.218 +
   1.219 +
   1.220 +#endif