|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #if !defined(__S32CRYPT_H__) |
|
17 #define __S32CRYPT_H__ |
|
18 #if !defined(__S32BUF_H__) |
|
19 #include <s32buf.h> |
|
20 #endif |
|
21 #if !defined(__S32STOR_H__) |
|
22 #include <s32stor.h> |
|
23 #endif |
|
24 |
|
25 class CPBEncryptor; |
|
26 class CPBDecryptor; |
|
27 class CPBEncryptionBase; |
|
28 class CPBEncryptSet; |
|
29 |
|
30 const TInt KEncryptionFilterBufSize=160; |
|
31 |
|
32 /** |
|
33 * @publishedPartner |
|
34 * @released |
|
35 * Base class used in the derivation of TEncryptFilter and TDecryptFilter. |
|
36 |
|
37 It has no user accessible functions. |
|
38 |
|
39 @see TEncryptFilter |
|
40 @see TDecryptFilter |
|
41 */ |
|
42 class TSecureFilter : public TStreamFilter |
|
43 { |
|
44 protected: |
|
45 TSecureFilter(); |
|
46 void Set(MStreamBuf* aHost,TInt aMode=EWrite); |
|
47 protected: |
|
48 IMPORT_C TInt Capacity(TInt aMaxLength); |
|
49 IMPORT_C TInt FilterL(TAny* aPtr,TInt aMaxLength,const TUint8*& aFrom,const TUint8* anEnd); |
|
50 IMPORT_C void DoSynchL(); |
|
51 TInt EmitL(const TDesC8& aDes); |
|
52 private: |
|
53 virtual TInt CryptL(TDes8& aTarget,const TDesC8& aSource) =0; |
|
54 virtual void CompleteL(TDes8& aTarget,const TDesC8& aSource) =0; |
|
55 private: |
|
56 TBuf8<KEncryptionFilterBufSize> iIn; |
|
57 TPtrC8 iOut; |
|
58 TUint8 iBuf[KEncryptionFilterBufSize]; |
|
59 }; |
|
60 |
|
61 /** |
|
62 * @publishedPartner |
|
63 * @released |
|
64 * An encrypting filter. |
|
65 |
|
66 An object of this type is used by REncryptStream to encrypt stream data as |
|
67 it is written to a target stream. |
|
68 |
|
69 Encryption itself is performed by an instance of a class implementing the |
|
70 CPBEncryptor interface. |
|
71 |
|
72 @see REncryptStream |
|
73 @see CPBEncryptor |
|
74 */ |
|
75 class TEncryptFilter : public TSecureFilter |
|
76 { |
|
77 public: |
|
78 IMPORT_C TEncryptFilter(); |
|
79 // New function, recommended |
|
80 IMPORT_C void SetL(MStreamBuf* aHost,CPBEncryptor* aKey,TInt aMode=EWrite); |
|
81 protected: |
|
82 IMPORT_C void DoRelease(); |
|
83 private: |
|
84 IMPORT_C TInt CryptL(TDes8& aTarget,const TDesC8& aSource); |
|
85 IMPORT_C void CompleteL(TDes8& aTarget,const TDesC8& aSource); |
|
86 private: |
|
87 CPBEncryptor* iKey; |
|
88 }; |
|
89 |
|
90 /** |
|
91 * @publishedPartner |
|
92 * @released |
|
93 * A decrypting filter. |
|
94 |
|
95 An object of this type is used by RDecryptStream to decrypt stream data as |
|
96 it is read from a source stream. |
|
97 |
|
98 Decryption itself is performed by an instance of a class implementing the |
|
99 CPBDecryptor interface. |
|
100 |
|
101 @see RDecryptStream |
|
102 @see CSecureStore |
|
103 @see CPBDecryptor |
|
104 */ |
|
105 class TDecryptFilter : public TSecureFilter |
|
106 { |
|
107 public: |
|
108 IMPORT_C TDecryptFilter(); |
|
109 // New function, recommended |
|
110 IMPORT_C void SetL(MStreamBuf* aHost,CPBDecryptor* aKey,TInt aMode=ERead); |
|
111 protected: |
|
112 IMPORT_C void DoRelease(); |
|
113 private: |
|
114 IMPORT_C TInt CryptL(TDes8& aTarget,const TDesC8& aSource); |
|
115 IMPORT_C void CompleteL(TDes8& aTarget,const TDesC8& aSource); |
|
116 private: |
|
117 CPBDecryptor* iKey; |
|
118 }; |
|
119 |
|
120 /** |
|
121 * @publishedPartner |
|
122 * @released |
|
123 * Supports the decrypting of a stream. |
|
124 |
|
125 The stream to be decrypted is a stream represented by an existing RReadStream |
|
126 object. In effect, RDecryptStream forms a layer over the RReadStream object, |
|
127 either using its source stream buffer or taking complete ownership of the |
|
128 source stream buffer. |
|
129 |
|
130 Decryption of streamed data is supported using the TDecryptFilter class derived |
|
131 from TStreamFilter. Decryption itself is performed by an instance of a class |
|
132 implementing the CPBEncryptionBase interface. |
|
133 |
|
134 @see TDecryptFilter |
|
135 @see TStreamFilter |
|
136 @see CPBEncryptionBase |
|
137 */ |
|
138 class RDecryptStream : public RReadStream |
|
139 { |
|
140 public: |
|
141 /** Constructs an empty decrypting stream object. |
|
142 |
|
143 Call OpenL() or OpenLC() to use a source stream owned by an existing read |
|
144 stream interface object, a RReadStream. |
|
145 |
|
146 Call AttachL() or AttachLC() to use and take ownership of a source stream |
|
147 owned by an existing read stream interface object. */ |
|
148 RDecryptStream() {} |
|
149 public: // Original functions, now deprecated |
|
150 public: // New functions, using Password Based Encryption |
|
151 IMPORT_C void OpenL(RReadStream& aHost,const CPBEncryptionBase& aKey); |
|
152 IMPORT_C void OpenLC(RReadStream& aHost,const CPBEncryptionBase& aKey); |
|
153 IMPORT_C void AttachL(RReadStream& aHost,const CPBEncryptionBase& aKey); |
|
154 IMPORT_C void AttachLC(RReadStream& aHost,const CPBEncryptionBase& aKey); |
|
155 private: |
|
156 TDecryptFilter iFilter; |
|
157 }; |
|
158 |
|
159 /** |
|
160 * @publishedPartner |
|
161 * @released |
|
162 * Supports the encryption of a stream. |
|
163 |
|
164 The stream to be encrypted is a stream represented by an existing RWriteStream |
|
165 object. In effect, REncryptStream forms a layer over the RWriteStream object, |
|
166 either using its target stream buffer or taking complete ownership of the |
|
167 target stream buffer. |
|
168 |
|
169 Encryption of streamed data is supported using the TEncryptFilter class derived |
|
170 from TStreamFilter. Encryption itself is performed by an instance of a class |
|
171 implementing the CPBEncryptionBase interface. |
|
172 |
|
173 @see TEncryptFilter |
|
174 @see TStreamFilter |
|
175 @see CPBEncryptionBase |
|
176 */ |
|
177 class REncryptStream : public RWriteStream |
|
178 { |
|
179 public: |
|
180 /** Constructs an empty encrypting stream object. |
|
181 |
|
182 Call OpenL() or OpenLC() to use a target stream owned by an existing write |
|
183 stream interface object, a RWriteStream. |
|
184 |
|
185 Call AttachL() or AttachLC() to use and take ownership of a target stream |
|
186 owned by an existing write stream interface object. */ |
|
187 REncryptStream() {} |
|
188 inline REncryptStream(const MExternalizer<TStreamRef>& anExter); |
|
189 public: // Original functions, now deprecated |
|
190 public: // New functions, using Password Based Encryption |
|
191 IMPORT_C void OpenL(RWriteStream& aHost,const CPBEncryptionBase& aKey); |
|
192 IMPORT_C void OpenLC(RWriteStream& aHost,const CPBEncryptionBase& aKey); |
|
193 IMPORT_C void AttachL(RWriteStream& aHost,const CPBEncryptionBase& aKey); |
|
194 IMPORT_C void AttachLC(RWriteStream& aHost,const CPBEncryptionBase& aKey); |
|
195 private: |
|
196 TEncryptFilter iFilter; |
|
197 }; |
|
198 // |
|
199 |
|
200 |
|
201 class HEncryptFilter; |
|
202 |
|
203 /** |
|
204 @publishedPartner |
|
205 @released |
|
206 A stream store whose streams are encrypted. |
|
207 |
|
208 The secure store is layered over another stream store which acts as the host |
|
209 for the encrypted streams. This stream store is not owned by the secure store, |
|
210 which means that it is possible to to use the secure store to store only a |
|
211 portion of the streams in encrypted form. |
|
212 |
|
213 Access to the streams in this store is via the normal RStoreWriteStream and |
|
214 RStoreReadStream classes. Internally, TEncryptFilter and TDecryptFilter objects |
|
215 are attached to the streams from the host store in order to do the encryption |
|
216 and decryption. |
|
217 |
|
218 @see RStoreWriteStream |
|
219 @see RStoreReadStream |
|
220 @see TEncryptFilter |
|
221 @see TDecryptFilter |
|
222 */ |
|
223 class CSecureStore : public CStreamStore |
|
224 { |
|
225 public:// Original functions, now deprecated |
|
226 public:// New functions using PBE |
|
227 IMPORT_C static CSecureStore* NewL(CStreamStore& aHost,const CPBEncryptSet& aKey); |
|
228 IMPORT_C static CSecureStore* NewLC(CStreamStore& aHost,const CPBEncryptSet& aKey); |
|
229 CSecureStore(CStreamStore& aHost,const CPBEncryptSet& aKey); |
|
230 protected: |
|
231 IMPORT_C MStreamBuf* DoReadL(TStreamId anId) const; |
|
232 IMPORT_C MStreamBuf* DoCreateL(TStreamId& anId); |
|
233 IMPORT_C TStreamId DoExtendL(); |
|
234 IMPORT_C void DoDeleteL(TStreamId anId); |
|
235 IMPORT_C MStreamBuf* DoWriteL(TStreamId anId); |
|
236 IMPORT_C MStreamBuf* DoReplaceL(TStreamId anId); |
|
237 IMPORT_C void DoCommitL(); |
|
238 IMPORT_C void DoRevertL(); |
|
239 private: |
|
240 inline CStreamStore& Host(); |
|
241 inline const CStreamStore& Host() const; |
|
242 inline const CPBEncryptSet& PBEKey() const; |
|
243 void setEncryptFilterL(HEncryptFilter& aFilter, RStoreWriteStream& aStream); |
|
244 private: |
|
245 CStreamStore* iHost; |
|
246 const CPBEncryptSet& iKey; |
|
247 }; |
|
248 |
|
249 // |
|
250 |
|
251 /** |
|
252 * @publishedPartner |
|
253 * @released |
|
254 * Uses an encrypted store to implement the page pool interface MPagePool. |
|
255 |
|
256 A secure store page pool uses a cache to store pages in-memory and to cache |
|
257 frequently accessed pages. You should provide a cache object (CPageCache) |
|
258 to the pool for this purpose. |
|
259 |
|
260 @see CPageCache |
|
261 */ |
|
262 class RSecureStorePagePool : public RStorePagePool |
|
263 { |
|
264 public:// Original functions, now deprecated |
|
265 public:// New functions using PBE |
|
266 IMPORT_C RSecureStorePagePool(const CPBEncryptSet& aKey); |
|
267 IMPORT_C RSecureStorePagePool(CPageCache& aCache, const CPBEncryptSet& aKey); |
|
268 protected: |
|
269 IMPORT_C TPageRef ExtendL(const TAny* aPage,TPageReclamation aReclamation); |
|
270 IMPORT_C void WriteL(TPageRef aRef,const TAny* aPage,TPageChange aChange); |
|
271 IMPORT_C void ReadL(TPageRef aRef,TAny* aPage); |
|
272 IMPORT_C void DoDeleteL(TPageRef aRef); |
|
273 private: |
|
274 const CPBEncryptSet& iKey; |
|
275 }; |
|
276 |
|
277 |
|
278 #include <s32crypt.inl> |
|
279 #endif |