sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: #ifndef __CRYPTOH4AES__ sl@0: #define __CRYPTOH4AES__ sl@0: #include "cryptojobs.h" sl@0: #include sl@0: sl@0: #define FAKE_DMA FakeDma sl@0: sl@0: //#define TDFC_WRAPPER sl@0: sl@0: #ifdef TDFC_WRAPPER sl@0: class TDfcWrapper : public TDfc sl@0: { sl@0: public: sl@0: TDfcWrapper(const TDfcWrapper &aOrig); sl@0: TDfcWrapper(TDfcFn aFunction, TAny* aPtr, TInt aPriority); sl@0: void Enque(); sl@0: private: sl@0: TDfcWrapper &operator=(const TDfcWrapper &aRHS); sl@0: void BaseEnque(); sl@0: static void DfcWrapperFunc(TAny* aPtr); sl@0: TDfcFn iRealFunction; sl@0: TAny *iRealPtr; sl@0: }; sl@0: #endif sl@0: sl@0: class DCryptoH4Chan; sl@0: class DLddChanAes; sl@0: class CryptoH4JobAes : public CryptoJobAes sl@0: { sl@0: public: sl@0: CryptoH4JobAes(DLddChanAes &aLddChanAes); sl@0: ~CryptoH4JobAes(); sl@0: sl@0: void SetDfcQ(TDfcQue *aDfcQue); sl@0: sl@0: virtual TUint8 *GetKeyBuffer(); // Max 32 bytes long (256bits) sl@0: virtual TUint8 *GetIVBuffer(); // 16 bytes long sl@0: virtual TUint32 MaxBytes() const; sl@0: virtual TUint8 *GetIOBuffer(); // MaxBytes() long sl@0: sl@0: virtual void GetToPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore); sl@0: virtual void BytesWrittenToPdd(TUint32 aBytes); sl@0: sl@0: virtual void GetFromPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore); sl@0: virtual void BytesReadFromPdd(TUint32 aBytes); sl@0: sl@0: // Must be called after setting the IV (if used) sl@0: virtual TInt SetDetails(DCryptoJobScheduler *aJobScheduler, sl@0: MCryptoJobCallbacks *aCallbacks, sl@0: TBool aEncrypt, sl@0: TInt aKeyLength, sl@0: RCryptoDriver::TChainingMode aMode); sl@0: virtual void NotifyReadRequestLength(TUint32 aReadRequestLength); sl@0: virtual void HwPerfCheck(); sl@0: sl@0: private: sl@0: // Implementations of virtual base class methods to support DCryptoJobScheduler sl@0: virtual void DoSlice(TBool aFirstSlice); sl@0: virtual TBool DoSaveState(); sl@0: virtual void DoRestoreState(); sl@0: virtual void DoReleaseHw(); sl@0: sl@0: void MaybeSetupWriteDmaToHw(); sl@0: #ifdef FAKE_DMA sl@0: void FakeDma(); sl@0: #endif sl@0: sl@0: DLddChanAes &iLddChanAes; sl@0: sl@0: // Details of job sl@0: TBool iEncrypt; sl@0: RCryptoDriver::TChainingMode iMode; sl@0: sl@0: TUint32 iKeyLengthBytes; sl@0: TUint32 iKey[8]; // 128, 192 or 256 bits sl@0: TUint32 iIV[4]; // 128 bits sl@0: TUint32 iSavedState[4]; // Used for CBC chaining sl@0: sl@0: TUint32 iReadRequestLength; sl@0: sl@0: // The AES data buffer sl@0: // TUint32 iAesBuffer[2*4+4]; // Temporary buffer 8 = 2x16 bytes blocks, +4 space (which never gets used) sl@0: TUint32 iAesBuffer[400*4+4]; // Temporary buffer 8 = 2x16 bytes blocks, +4 space (which never gets used) sl@0: // There are 4 indexes into the above buffer, and after converting sl@0: // all to bytes indexes, and allowing for wrapping the following sl@0: // condition should always hold iSwReadIndex <= iHwWriteIndex <= sl@0: // iHwReadIndex <= iSwWriteByteOffset sl@0: TInt32 iSwWriteByteOffset; sl@0: TInt32 iHwReadIndex; sl@0: TInt32 iHwWriteIndex; sl@0: TInt32 iSwReadByteOffset; sl@0: sl@0: TBool iHwRunning; sl@0: TInt iDmaToHwPending; sl@0: TInt iDmaFromHwPending; sl@0: sl@0: #ifdef FAKE_DMA sl@0: TInt iFakeDmaToHwQueued; sl@0: TInt iFakeDmaFromHwQueued; sl@0: #endif sl@0: sl@0: void SetupHw(TBool aUseSavedState); sl@0: void SetupDma(TUint32 aPtr, TBool aToHw); sl@0: void StopHw(); sl@0: static void DmaComplete(DDmaRequest::TResult aResult, TAny *aPtr); sl@0: sl@0: static void DmaToHwCompleteDfc(TAny* aPtr); sl@0: void DoDmaToHwCompleteDfc(); sl@0: #ifdef TDFC_WRAPPER sl@0: TDfcWrapper iDmaToHwCompleteDfc; sl@0: #else sl@0: TDfc iDmaToHwCompleteDfc; sl@0: #endif sl@0: sl@0: void CheckIndexes() const; sl@0: void CompareIndexes(const char *aName, TInt32 aP1, TInt32 aP2) const; sl@0: sl@0: static void DmaFromHwCompleteDfc(TAny* aPtr); sl@0: void DoDmaFromHwCompleteDfc(); sl@0: #ifdef TDFC_WRAPPER sl@0: TDfcWrapper iDmaFromHwCompleteDfc; sl@0: #else sl@0: TDfc iDmaFromHwCompleteDfc; sl@0: #endif sl@0: }; sl@0: #endif