os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptoh4aes.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/cryptoh4aes.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,149 @@
     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 __CRYPTOH4AES__
    1.28 +#define __CRYPTOH4AES__
    1.29 +#include "cryptojobs.h"
    1.30 +#include <drivers/dma.h>
    1.31 +
    1.32 +#define FAKE_DMA FakeDma
    1.33 +
    1.34 +//#define TDFC_WRAPPER
    1.35 +
    1.36 +#ifdef TDFC_WRAPPER
    1.37 +class TDfcWrapper : public TDfc
    1.38 +	{
    1.39 +public:
    1.40 +	TDfcWrapper(const TDfcWrapper &aOrig);
    1.41 +	TDfcWrapper(TDfcFn aFunction, TAny* aPtr, TInt aPriority);
    1.42 +	void Enque();
    1.43 +private:
    1.44 +	TDfcWrapper &operator=(const TDfcWrapper &aRHS);
    1.45 +	void BaseEnque();
    1.46 +    static void DfcWrapperFunc(TAny* aPtr);
    1.47 +	TDfcFn iRealFunction;
    1.48 +	TAny *iRealPtr;
    1.49 +	};
    1.50 +#endif
    1.51 +
    1.52 +class DCryptoH4Chan;
    1.53 +class DLddChanAes;
    1.54 +class CryptoH4JobAes : public CryptoJobAes
    1.55 +	{
    1.56 +public:
    1.57 +	CryptoH4JobAes(DLddChanAes &aLddChanAes);
    1.58 +	~CryptoH4JobAes();
    1.59 +
    1.60 +	void SetDfcQ(TDfcQue *aDfcQue);
    1.61 +
    1.62 +	virtual TUint8 *GetKeyBuffer(); // Max 32 bytes long (256bits)
    1.63 +	virtual TUint8 *GetIVBuffer(); // 16 bytes long
    1.64 +	virtual TUint32 MaxBytes() const;
    1.65 +	virtual TUint8 *GetIOBuffer(); // MaxBytes() long
    1.66 +
    1.67 +	virtual void GetToPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore);
    1.68 +	virtual void BytesWrittenToPdd(TUint32 aBytes);
    1.69 +
    1.70 +	virtual void GetFromPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore);
    1.71 +	virtual void BytesReadFromPdd(TUint32 aBytes);
    1.72 +
    1.73 +	// Must be called after setting the IV (if used)
    1.74 +	virtual TInt SetDetails(DCryptoJobScheduler *aJobScheduler, 
    1.75 +							MCryptoJobCallbacks *aCallbacks,
    1.76 +							TBool aEncrypt, 
    1.77 +							TInt aKeyLength,
    1.78 +							RCryptoDriver::TChainingMode aMode);
    1.79 +	virtual void NotifyReadRequestLength(TUint32 aReadRequestLength);
    1.80 +	virtual void HwPerfCheck();
    1.81 +	
    1.82 +private:	
    1.83 +	// Implementations of virtual base class methods to support DCryptoJobScheduler
    1.84 +	virtual void DoSlice(TBool aFirstSlice);
    1.85 +	virtual TBool DoSaveState();
    1.86 +	virtual void DoRestoreState();
    1.87 +	virtual void DoReleaseHw();
    1.88 +
    1.89 +	void MaybeSetupWriteDmaToHw();
    1.90 +#ifdef FAKE_DMA
    1.91 +	void FakeDma();
    1.92 +#endif
    1.93 +
    1.94 +	DLddChanAes &iLddChanAes;
    1.95 +	
    1.96 +	// Details of job
    1.97 +	TBool iEncrypt;
    1.98 +	RCryptoDriver::TChainingMode iMode;
    1.99 +
   1.100 +	TUint32 iKeyLengthBytes;
   1.101 +	TUint32 iKey[8]; // 128, 192 or 256 bits
   1.102 +	TUint32 iIV[4]; // 128 bits
   1.103 +	TUint32 iSavedState[4]; // Used for CBC chaining
   1.104 +
   1.105 +	TUint32 iReadRequestLength;
   1.106 +
   1.107 +	// The AES data buffer
   1.108 +	//	TUint32 iAesBuffer[2*4+4]; // Temporary buffer 8 = 2x16 bytes blocks, +4 space (which never gets used)
   1.109 +	TUint32 iAesBuffer[400*4+4]; // Temporary buffer 8 = 2x16 bytes blocks, +4 space (which never gets used)
   1.110 +	// There are 4 indexes into the above buffer, and after converting
   1.111 +	// all to bytes indexes, and allowing for wrapping the following
   1.112 +	// condition should always hold iSwReadIndex <= iHwWriteIndex <=
   1.113 +	// iHwReadIndex <= iSwWriteByteOffset
   1.114 +	TInt32 iSwWriteByteOffset;
   1.115 +	TInt32 iHwReadIndex;
   1.116 +	TInt32 iHwWriteIndex;
   1.117 +	TInt32 iSwReadByteOffset;
   1.118 +
   1.119 +	TBool iHwRunning;
   1.120 +	TInt iDmaToHwPending;
   1.121 +	TInt iDmaFromHwPending;
   1.122 +
   1.123 +#ifdef FAKE_DMA
   1.124 +	TInt iFakeDmaToHwQueued;
   1.125 +	TInt iFakeDmaFromHwQueued;
   1.126 +#endif
   1.127 +	
   1.128 +	void SetupHw(TBool aUseSavedState);
   1.129 +	void SetupDma(TUint32 aPtr, TBool aToHw);
   1.130 +	void StopHw();
   1.131 +	static void DmaComplete(DDmaRequest::TResult aResult, TAny *aPtr);
   1.132 +
   1.133 +    static void DmaToHwCompleteDfc(TAny* aPtr);
   1.134 +	void DoDmaToHwCompleteDfc();
   1.135 +#ifdef TDFC_WRAPPER
   1.136 +	TDfcWrapper iDmaToHwCompleteDfc;
   1.137 +#else
   1.138 +    TDfc iDmaToHwCompleteDfc;	
   1.139 +#endif
   1.140 +
   1.141 +	void CheckIndexes() const;
   1.142 +	void CompareIndexes(const char *aName, TInt32 aP1, TInt32 aP2) const;
   1.143 +
   1.144 +    static void DmaFromHwCompleteDfc(TAny* aPtr);
   1.145 +	void DoDmaFromHwCompleteDfc();
   1.146 +#ifdef TDFC_WRAPPER
   1.147 +    TDfcWrapper iDmaFromHwCompleteDfc;	
   1.148 +#else
   1.149 +    TDfc iDmaFromHwCompleteDfc;	
   1.150 +#endif
   1.151 +	};
   1.152 +#endif