First public contribution.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #ifndef __CRYPTOH4AES__
25 #define __CRYPTOH4AES__
26 #include "cryptojobs.h"
27 #include <drivers/dma.h>
29 #define FAKE_DMA FakeDma
31 //#define TDFC_WRAPPER
34 class TDfcWrapper : public TDfc
37 TDfcWrapper(const TDfcWrapper &aOrig);
38 TDfcWrapper(TDfcFn aFunction, TAny* aPtr, TInt aPriority);
41 TDfcWrapper &operator=(const TDfcWrapper &aRHS);
43 static void DfcWrapperFunc(TAny* aPtr);
51 class CryptoH4JobAes : public CryptoJobAes
54 CryptoH4JobAes(DLddChanAes &aLddChanAes);
57 void SetDfcQ(TDfcQue *aDfcQue);
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
64 virtual void GetToPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore);
65 virtual void BytesWrittenToPdd(TUint32 aBytes);
67 virtual void GetFromPddBuffer(TUint8 * &aBuf, TUint32 &aBufLen, TBool &aMore);
68 virtual void BytesReadFromPdd(TUint32 aBytes);
70 // Must be called after setting the IV (if used)
71 virtual TInt SetDetails(DCryptoJobScheduler *aJobScheduler,
72 MCryptoJobCallbacks *aCallbacks,
75 RCryptoDriver::TChainingMode aMode);
76 virtual void NotifyReadRequestLength(TUint32 aReadRequestLength);
77 virtual void HwPerfCheck();
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();
86 void MaybeSetupWriteDmaToHw();
91 DLddChanAes &iLddChanAes;
95 RCryptoDriver::TChainingMode iMode;
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
102 TUint32 iReadRequestLength;
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;
113 TInt32 iHwWriteIndex;
114 TInt32 iSwReadByteOffset;
117 TInt iDmaToHwPending;
118 TInt iDmaFromHwPending;
121 TInt iFakeDmaToHwQueued;
122 TInt iFakeDmaFromHwQueued;
125 void SetupHw(TBool aUseSavedState);
126 void SetupDma(TUint32 aPtr, TBool aToHw);
128 static void DmaComplete(DDmaRequest::TResult aResult, TAny *aPtr);
130 static void DmaToHwCompleteDfc(TAny* aPtr);
131 void DoDmaToHwCompleteDfc();
133 TDfcWrapper iDmaToHwCompleteDfc;
135 TDfc iDmaToHwCompleteDfc;
138 void CheckIndexes() const;
139 void CompareIndexes(const char *aName, TInt32 aP1, TInt32 aP2) const;
141 static void DmaFromHwCompleteDfc(TAny* aPtr);
142 void DoDmaFromHwCompleteDfc();
144 TDfcWrapper iDmaFromHwCompleteDfc;
146 TDfc iDmaFromHwCompleteDfc;