os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptodriver.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @internalComponent
sl@0
    22
 @released
sl@0
    23
*/
sl@0
    24
#ifndef CRYPTODRIVER_H
sl@0
    25
#define CRYPTODRIVER_H
sl@0
    26
sl@0
    27
#include <e32cmn.h>
sl@0
    28
#include <e32ver.h>
sl@0
    29
#ifndef __KERNEL_MODE__
sl@0
    30
#include <e32std.h>
sl@0
    31
#endif
sl@0
    32
sl@0
    33
/**
sl@0
    34
User interface for crypto hw
sl@0
    35
*/
sl@0
    36
class RCryptoDriver : public RBusLogicalChannel
sl@0
    37
    {
sl@0
    38
public:
sl@0
    39
    /**
sl@0
    40
    Structure for holding driver capabilities information
sl@0
    41
    */
sl@0
    42
    class TCaps
sl@0
    43
        {
sl@0
    44
    public:
sl@0
    45
        TVersion iVersion;
sl@0
    46
        };
sl@0
    47
sl@0
    48
    /**
sl@0
    49
    Structure for holding driver configuration data
sl@0
    50
    */
sl@0
    51
    class TConfig
sl@0
    52
        {
sl@0
    53
    public:
sl@0
    54
        TInt iFakeDriverSetting;
sl@0
    55
        };
sl@0
    56
    /**
sl@0
    57
    Typedef used for passing TConfig structure to GetConfig and SetConfig APIs
sl@0
    58
    */
sl@0
    59
    typedef TPckgBuf<TConfig> TConfigBuf;
sl@0
    60
sl@0
    61
    /**
sl@0
    62
    Structure for holding h/w version information
sl@0
    63
    */
sl@0
    64
    class THwVersions
sl@0
    65
        {
sl@0
    66
    public:
sl@0
    67
		TUint32 iRngHwVersion; 		///< RNG h/w version number
sl@0
    68
		TUint32 iDes3DesHwVersion; 	///< 3DES h/w version number
sl@0
    69
		TUint32 iSha1Md5HwVersion; 	///< SHA1 h/w version number
sl@0
    70
		TUint32 iAesHwVersion; 		///< AES h/w version number
sl@0
    71
		TUint32 iPkaHwVersion; 		///< PKA h/w version number
sl@0
    72
        };
sl@0
    73
    typedef TPckgBuf<THwVersions> THwVersionsBuf;
sl@0
    74
sl@0
    75
public:
sl@0
    76
    IMPORT_C TInt Open();
sl@0
    77
    IMPORT_C TInt GetHwVersions(THwVersionsBuf& aHwVersionsBuf);
sl@0
    78
sl@0
    79
    IMPORT_C TInt GetConfig(TConfigBuf& aConfig);
sl@0
    80
    IMPORT_C TInt SetConfig(const TConfigBuf& aConfig);
sl@0
    81
sl@0
    82
    inline static const TDesC& Name();
sl@0
    83
    inline static TVersion VersionRequired();
sl@0
    84
sl@0
    85
	/**
sl@0
    86
	   Fill buffer with random data
sl@0
    87
	   Only one "random" request may be pending at any time.
sl@0
    88
sl@0
    89
	   @param aStatus 	The request to be signalled when the data has been received.
sl@0
    90
	   					The result value will be set to KErrNone on success;
sl@0
    91
						or set to one of the system wide error codes when an error occurs.
sl@0
    92
sl@0
    93
	   @param aData 	Fills the descriptor up to its current length with
sl@0
    94
	   					random data. Any existing contents are lost.
sl@0
    95
	*/
sl@0
    96
	IMPORT_C void Random(TRequestStatus& aStatus, TDes8& aDestination);
sl@0
    97
	/**
sl@0
    98
	   Causes the current Random request to cancel synchronously.
sl@0
    99
	*/
sl@0
   100
    IMPORT_C void RandomCancel();
sl@0
   101
sl@0
   102
	enum TChainingMode {EEcbMode, ECbcMode, ECntrMode};
sl@0
   103
	/**
sl@0
   104
	   @param aEncrypt ETrue for encryption
sl@0
   105
	   @param aMode See TChainingMode
sl@0
   106
	   @param aKey 	Must be one of the following lengths - 128, 192 or 256 bits (16, 24 or 32 bytes).
sl@0
   107
	   @param aIV Initialisation Vector, Length must be, 0 for ECB mode, or 16 bytes (all other mdoes)
sl@0
   108
	*/ 
sl@0
   109
	IMPORT_C TInt SetAesConfig(TBool aEncrypt, TChainingMode aMode, const TDesC8& aKey, const TDesC8& aIV);
sl@0
   110
sl@0
   111
	/**
sl@0
   112
	   Any length of data may be written, but the h/w will only
sl@0
   113
	   process the data in multiples of 16 bytes. Any remainder will
sl@0
   114
	   be buffered pending future writes.
sl@0
   115
sl@0
   116
	   Padding is NOT done by this function.
sl@0
   117
	   
sl@0
   118
	   Output 
sl@0
   119
	   
sl@0
   120
	   @param aStatus
sl@0
   121
	   @param aBuffer
sl@0
   122
	*/ 
sl@0
   123
	IMPORT_C void AesWrite(TRequestStatus& aStatus, TDesC8& aBuffer);
sl@0
   124
sl@0
   125
	/**
sl@0
   126
	   Causes the current "to hw" requests to cancel synchronously.
sl@0
   127
	*/
sl@0
   128
    IMPORT_C void AesCancelWrite();
sl@0
   129
sl@0
   130
	/**
sl@0
   131
	   The destination buffer is overwritten. This call will block
sl@0
   132
	   until the specified number of bytes have been read (the max
sl@0
   133
	   length of aBuffer).
sl@0
   134
sl@0
   135
	   The length is not required to be a multiple of the block size
sl@0
   136
	   (16 bytes), but note that written data is only processed in
sl@0
   137
	   multiples of the block size.
sl@0
   138
sl@0
   139
	   Data is appended to the supplied buffer.
sl@0
   140
	   
sl@0
   141
	   @param aStatus
sl@0
   142
	   @param aBuffer
sl@0
   143
	   @param aLength
sl@0
   144
	*/ 
sl@0
   145
	IMPORT_C void AesRead(TRequestStatus& aStatus, TDes8& aBuffer, TUint32 aLenth);
sl@0
   146
sl@0
   147
	/**
sl@0
   148
	   Causes the current "from hw" requests to cancel synchronously.
sl@0
   149
	*/
sl@0
   150
    IMPORT_C void AesCancelRead();
sl@0
   151
sl@0
   152
sl@0
   153
private:
sl@0
   154
    /**
sl@0
   155
    Enumeration of Control messages.
sl@0
   156
    */
sl@0
   157
    enum TControl
sl@0
   158
        {
sl@0
   159
		EGetHwVersions,
sl@0
   160
		EAesSetConfig,
sl@0
   161
        EGetConfig,
sl@0
   162
        ESetConfig
sl@0
   163
        };
sl@0
   164
sl@0
   165
    /**
sl@0
   166
    Enumeration of Request messages.
sl@0
   167
    */
sl@0
   168
    enum TRequest
sl@0
   169
        {
sl@0
   170
		ERandom,
sl@0
   171
		EAesWrite,
sl@0
   172
		EAesRead,
sl@0
   173
        ENumRequests,
sl@0
   174
        EAllRequests = (1<<ENumRequests)-1
sl@0
   175
        };
sl@0
   176
sl@0
   177
    /**
sl@0
   178
    Structure for holding driver configuration data
sl@0
   179
    */
sl@0
   180
    class TAesConfig
sl@0
   181
        {
sl@0
   182
    public:
sl@0
   183
		TBool iEncrypt;
sl@0
   184
		TChainingMode iMode;
sl@0
   185
		const TDesC8 *iKey;
sl@0
   186
		const TDesC8 *iIV;
sl@0
   187
        };
sl@0
   188
    typedef TPckgBuf<TAesConfig> TAesConfigBuf;
sl@0
   189
sl@0
   190
    // Kernel side LDD channel is a friend
sl@0
   191
    friend class DCryptoLddChannel;
sl@0
   192
    friend class DLddChanAes;
sl@0
   193
    };
sl@0
   194
sl@0
   195
sl@0
   196
/**
sl@0
   197
  Returns the driver's name
sl@0
   198
*/
sl@0
   199
inline const TDesC& RCryptoDriver::Name()
sl@0
   200
    {
sl@0
   201
    _LIT(KDriver1Name,"crypto");
sl@0
   202
    return KDriver1Name;
sl@0
   203
    }
sl@0
   204
sl@0
   205
/**
sl@0
   206
  Returns the version number of the driver
sl@0
   207
*/
sl@0
   208
inline TVersion RCryptoDriver::VersionRequired()
sl@0
   209
    {
sl@0
   210
    const TInt KMajorVersionNumber=1;
sl@0
   211
    const TInt KMinorVersionNumber=0;
sl@0
   212
    const TInt KBuildVersionNumber=KE32BuildVersionNumber;
sl@0
   213
    return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   214
    }
sl@0
   215
sl@0
   216
sl@0
   217
#endif