|
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 CRYPTODRIVER_H |
|
25 #define CRYPTODRIVER_H |
|
26 |
|
27 #include <e32cmn.h> |
|
28 #include <e32ver.h> |
|
29 #ifndef __KERNEL_MODE__ |
|
30 #include <e32std.h> |
|
31 #endif |
|
32 |
|
33 /** |
|
34 User interface for crypto hw |
|
35 */ |
|
36 class RCryptoDriver : public RBusLogicalChannel |
|
37 { |
|
38 public: |
|
39 /** |
|
40 Structure for holding driver capabilities information |
|
41 */ |
|
42 class TCaps |
|
43 { |
|
44 public: |
|
45 TVersion iVersion; |
|
46 }; |
|
47 |
|
48 /** |
|
49 Structure for holding driver configuration data |
|
50 */ |
|
51 class TConfig |
|
52 { |
|
53 public: |
|
54 TInt iFakeDriverSetting; |
|
55 }; |
|
56 /** |
|
57 Typedef used for passing TConfig structure to GetConfig and SetConfig APIs |
|
58 */ |
|
59 typedef TPckgBuf<TConfig> TConfigBuf; |
|
60 |
|
61 /** |
|
62 Structure for holding h/w version information |
|
63 */ |
|
64 class THwVersions |
|
65 { |
|
66 public: |
|
67 TUint32 iRngHwVersion; ///< RNG h/w version number |
|
68 TUint32 iDes3DesHwVersion; ///< 3DES h/w version number |
|
69 TUint32 iSha1Md5HwVersion; ///< SHA1 h/w version number |
|
70 TUint32 iAesHwVersion; ///< AES h/w version number |
|
71 TUint32 iPkaHwVersion; ///< PKA h/w version number |
|
72 }; |
|
73 typedef TPckgBuf<THwVersions> THwVersionsBuf; |
|
74 |
|
75 public: |
|
76 IMPORT_C TInt Open(); |
|
77 IMPORT_C TInt GetHwVersions(THwVersionsBuf& aHwVersionsBuf); |
|
78 |
|
79 IMPORT_C TInt GetConfig(TConfigBuf& aConfig); |
|
80 IMPORT_C TInt SetConfig(const TConfigBuf& aConfig); |
|
81 |
|
82 inline static const TDesC& Name(); |
|
83 inline static TVersion VersionRequired(); |
|
84 |
|
85 /** |
|
86 Fill buffer with random data |
|
87 Only one "random" request may be pending at any time. |
|
88 |
|
89 @param aStatus The request to be signalled when the data has been received. |
|
90 The result value will be set to KErrNone on success; |
|
91 or set to one of the system wide error codes when an error occurs. |
|
92 |
|
93 @param aData Fills the descriptor up to its current length with |
|
94 random data. Any existing contents are lost. |
|
95 */ |
|
96 IMPORT_C void Random(TRequestStatus& aStatus, TDes8& aDestination); |
|
97 /** |
|
98 Causes the current Random request to cancel synchronously. |
|
99 */ |
|
100 IMPORT_C void RandomCancel(); |
|
101 |
|
102 enum TChainingMode {EEcbMode, ECbcMode, ECntrMode}; |
|
103 /** |
|
104 @param aEncrypt ETrue for encryption |
|
105 @param aMode See TChainingMode |
|
106 @param aKey Must be one of the following lengths - 128, 192 or 256 bits (16, 24 or 32 bytes). |
|
107 @param aIV Initialisation Vector, Length must be, 0 for ECB mode, or 16 bytes (all other mdoes) |
|
108 */ |
|
109 IMPORT_C TInt SetAesConfig(TBool aEncrypt, TChainingMode aMode, const TDesC8& aKey, const TDesC8& aIV); |
|
110 |
|
111 /** |
|
112 Any length of data may be written, but the h/w will only |
|
113 process the data in multiples of 16 bytes. Any remainder will |
|
114 be buffered pending future writes. |
|
115 |
|
116 Padding is NOT done by this function. |
|
117 |
|
118 Output |
|
119 |
|
120 @param aStatus |
|
121 @param aBuffer |
|
122 */ |
|
123 IMPORT_C void AesWrite(TRequestStatus& aStatus, TDesC8& aBuffer); |
|
124 |
|
125 /** |
|
126 Causes the current "to hw" requests to cancel synchronously. |
|
127 */ |
|
128 IMPORT_C void AesCancelWrite(); |
|
129 |
|
130 /** |
|
131 The destination buffer is overwritten. This call will block |
|
132 until the specified number of bytes have been read (the max |
|
133 length of aBuffer). |
|
134 |
|
135 The length is not required to be a multiple of the block size |
|
136 (16 bytes), but note that written data is only processed in |
|
137 multiples of the block size. |
|
138 |
|
139 Data is appended to the supplied buffer. |
|
140 |
|
141 @param aStatus |
|
142 @param aBuffer |
|
143 @param aLength |
|
144 */ |
|
145 IMPORT_C void AesRead(TRequestStatus& aStatus, TDes8& aBuffer, TUint32 aLenth); |
|
146 |
|
147 /** |
|
148 Causes the current "from hw" requests to cancel synchronously. |
|
149 */ |
|
150 IMPORT_C void AesCancelRead(); |
|
151 |
|
152 |
|
153 private: |
|
154 /** |
|
155 Enumeration of Control messages. |
|
156 */ |
|
157 enum TControl |
|
158 { |
|
159 EGetHwVersions, |
|
160 EAesSetConfig, |
|
161 EGetConfig, |
|
162 ESetConfig |
|
163 }; |
|
164 |
|
165 /** |
|
166 Enumeration of Request messages. |
|
167 */ |
|
168 enum TRequest |
|
169 { |
|
170 ERandom, |
|
171 EAesWrite, |
|
172 EAesRead, |
|
173 ENumRequests, |
|
174 EAllRequests = (1<<ENumRequests)-1 |
|
175 }; |
|
176 |
|
177 /** |
|
178 Structure for holding driver configuration data |
|
179 */ |
|
180 class TAesConfig |
|
181 { |
|
182 public: |
|
183 TBool iEncrypt; |
|
184 TChainingMode iMode; |
|
185 const TDesC8 *iKey; |
|
186 const TDesC8 *iIV; |
|
187 }; |
|
188 typedef TPckgBuf<TAesConfig> TAesConfigBuf; |
|
189 |
|
190 // Kernel side LDD channel is a friend |
|
191 friend class DCryptoLddChannel; |
|
192 friend class DLddChanAes; |
|
193 }; |
|
194 |
|
195 |
|
196 /** |
|
197 Returns the driver's name |
|
198 */ |
|
199 inline const TDesC& RCryptoDriver::Name() |
|
200 { |
|
201 _LIT(KDriver1Name,"crypto"); |
|
202 return KDriver1Name; |
|
203 } |
|
204 |
|
205 /** |
|
206 Returns the version number of the driver |
|
207 */ |
|
208 inline TVersion RCryptoDriver::VersionRequired() |
|
209 { |
|
210 const TInt KMajorVersionNumber=1; |
|
211 const TInt KMinorVersionNumber=0; |
|
212 const TInt KBuildVersionNumber=KE32BuildVersionNumber; |
|
213 return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
214 } |
|
215 |
|
216 |
|
217 #endif |