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