os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptoh4aes.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.
     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 #ifndef __CRYPTOH4AES__
    25 #define __CRYPTOH4AES__
    26 #include "cryptojobs.h"
    27 #include <drivers/dma.h>
    28 
    29 #define FAKE_DMA FakeDma
    30 
    31 //#define TDFC_WRAPPER
    32 
    33 #ifdef TDFC_WRAPPER
    34 class TDfcWrapper : public TDfc
    35 	{
    36 public:
    37 	TDfcWrapper(const TDfcWrapper &aOrig);
    38 	TDfcWrapper(TDfcFn aFunction, TAny* aPtr, TInt aPriority);
    39 	void Enque();
    40 private:
    41 	TDfcWrapper &operator=(const TDfcWrapper &aRHS);
    42 	void BaseEnque();
    43     static void DfcWrapperFunc(TAny* aPtr);
    44 	TDfcFn iRealFunction;
    45 	TAny *iRealPtr;
    46 	};
    47 #endif
    48 
    49 class DCryptoH4Chan;
    50 class DLddChanAes;
    51 class CryptoH4JobAes : public CryptoJobAes
    52 	{
    53 public:
    54 	CryptoH4JobAes(DLddChanAes &aLddChanAes);
    55 	~CryptoH4JobAes();
    56 
    57 	void SetDfcQ(TDfcQue *aDfcQue);
    58 
    59 	virtual TUint8 *GetKeyBuffer(); // Max 32 bytes long (256bits)
    60 	virtual TUint8 *GetIVBuffer(); // 16 bytes long
    61 	virtual TUint32 MaxBytes() const;
    62 	virtual TUint8 *GetIOBuffer(); // MaxBytes() long
    63 
    64 	virtual void GetToPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore);
    65 	virtual void BytesWrittenToPdd(TUint32 aBytes);
    66 
    67 	virtual void GetFromPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore);
    68 	virtual void BytesReadFromPdd(TUint32 aBytes);
    69 
    70 	// Must be called after setting the IV (if used)
    71 	virtual TInt SetDetails(DCryptoJobScheduler *aJobScheduler, 
    72 							MCryptoJobCallbacks *aCallbacks,
    73 							TBool aEncrypt, 
    74 							TInt aKeyLength,
    75 							RCryptoDriver::TChainingMode aMode);
    76 	virtual void NotifyReadRequestLength(TUint32 aReadRequestLength);
    77 	virtual void HwPerfCheck();
    78 	
    79 private:	
    80 	// Implementations of virtual base class methods to support DCryptoJobScheduler
    81 	virtual void DoSlice(TBool aFirstSlice);
    82 	virtual TBool DoSaveState();
    83 	virtual void DoRestoreState();
    84 	virtual void DoReleaseHw();
    85 
    86 	void MaybeSetupWriteDmaToHw();
    87 #ifdef FAKE_DMA
    88 	void FakeDma();
    89 #endif
    90 
    91 	DLddChanAes &iLddChanAes;
    92 	
    93 	// Details of job
    94 	TBool iEncrypt;
    95 	RCryptoDriver::TChainingMode iMode;
    96 
    97 	TUint32 iKeyLengthBytes;
    98 	TUint32 iKey[8]; // 128, 192 or 256 bits
    99 	TUint32 iIV[4]; // 128 bits
   100 	TUint32 iSavedState[4]; // Used for CBC chaining
   101 
   102 	TUint32 iReadRequestLength;
   103 
   104 	// The AES data buffer
   105 	//	TUint32 iAesBuffer[2*4+4]; // Temporary buffer 8 = 2x16 bytes blocks, +4 space (which never gets used)
   106 	TUint32 iAesBuffer[400*4+4]; // Temporary buffer 8 = 2x16 bytes blocks, +4 space (which never gets used)
   107 	// There are 4 indexes into the above buffer, and after converting
   108 	// all to bytes indexes, and allowing for wrapping the following
   109 	// condition should always hold iSwReadIndex <= iHwWriteIndex <=
   110 	// iHwReadIndex <= iSwWriteByteOffset
   111 	TInt32 iSwWriteByteOffset;
   112 	TInt32 iHwReadIndex;
   113 	TInt32 iHwWriteIndex;
   114 	TInt32 iSwReadByteOffset;
   115 
   116 	TBool iHwRunning;
   117 	TInt iDmaToHwPending;
   118 	TInt iDmaFromHwPending;
   119 
   120 #ifdef FAKE_DMA
   121 	TInt iFakeDmaToHwQueued;
   122 	TInt iFakeDmaFromHwQueued;
   123 #endif
   124 	
   125 	void SetupHw(TBool aUseSavedState);
   126 	void SetupDma(TUint32 aPtr, TBool aToHw);
   127 	void StopHw();
   128 	static void DmaComplete(DDmaRequest::TResult aResult, TAny *aPtr);
   129 
   130     static void DmaToHwCompleteDfc(TAny* aPtr);
   131 	void DoDmaToHwCompleteDfc();
   132 #ifdef TDFC_WRAPPER
   133 	TDfcWrapper iDmaToHwCompleteDfc;
   134 #else
   135     TDfc iDmaToHwCompleteDfc;	
   136 #endif
   137 
   138 	void CheckIndexes() const;
   139 	void CompareIndexes(const char *aName, TInt32 aP1, TInt32 aP2) const;
   140 
   141     static void DmaFromHwCompleteDfc(TAny* aPtr);
   142 	void DoDmaFromHwCompleteDfc();
   143 #ifdef TDFC_WRAPPER
   144     TDfcWrapper iDmaFromHwCompleteDfc;	
   145 #else
   146     TDfc iDmaFromHwCompleteDfc;	
   147 #endif
   148 	};
   149 #endif