1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/store/INC/S32CRYPT.H Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,279 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#if !defined(__S32CRYPT_H__)
1.20 +#define __S32CRYPT_H__
1.21 +#if !defined(__S32BUF_H__)
1.22 +#include <s32buf.h>
1.23 +#endif
1.24 +#if !defined(__S32STOR_H__)
1.25 +#include <s32stor.h>
1.26 +#endif
1.27 +
1.28 +class CPBEncryptor;
1.29 +class CPBDecryptor;
1.30 +class CPBEncryptionBase;
1.31 +class CPBEncryptSet;
1.32 +
1.33 +const TInt KEncryptionFilterBufSize=160;
1.34 +
1.35 +/**
1.36 + * @publishedPartner
1.37 + * @released
1.38 + * Base class used in the derivation of TEncryptFilter and TDecryptFilter.
1.39 +
1.40 +It has no user accessible functions.
1.41 +
1.42 +@see TEncryptFilter
1.43 +@see TDecryptFilter
1.44 +*/
1.45 +class TSecureFilter : public TStreamFilter
1.46 + {
1.47 +protected:
1.48 + TSecureFilter();
1.49 + void Set(MStreamBuf* aHost,TInt aMode=EWrite);
1.50 +protected:
1.51 + IMPORT_C TInt Capacity(TInt aMaxLength);
1.52 + IMPORT_C TInt FilterL(TAny* aPtr,TInt aMaxLength,const TUint8*& aFrom,const TUint8* anEnd);
1.53 + IMPORT_C void DoSynchL();
1.54 + TInt EmitL(const TDesC8& aDes);
1.55 +private:
1.56 + virtual TInt CryptL(TDes8& aTarget,const TDesC8& aSource) =0;
1.57 + virtual void CompleteL(TDes8& aTarget,const TDesC8& aSource) =0;
1.58 +private:
1.59 + TBuf8<KEncryptionFilterBufSize> iIn;
1.60 + TPtrC8 iOut;
1.61 + TUint8 iBuf[KEncryptionFilterBufSize];
1.62 + };
1.63 +
1.64 +/**
1.65 + * @publishedPartner
1.66 + * @released
1.67 + * An encrypting filter.
1.68 +
1.69 +An object of this type is used by REncryptStream to encrypt stream data as
1.70 +it is written to a target stream.
1.71 +
1.72 +Encryption itself is performed by an instance of a class implementing the
1.73 +CPBEncryptor interface.
1.74 +
1.75 +@see REncryptStream
1.76 +@see CPBEncryptor
1.77 +*/
1.78 +class TEncryptFilter : public TSecureFilter
1.79 + {
1.80 +public:
1.81 + IMPORT_C TEncryptFilter();
1.82 +// New function, recommended
1.83 + IMPORT_C void SetL(MStreamBuf* aHost,CPBEncryptor* aKey,TInt aMode=EWrite);
1.84 +protected:
1.85 + IMPORT_C void DoRelease();
1.86 +private:
1.87 + IMPORT_C TInt CryptL(TDes8& aTarget,const TDesC8& aSource);
1.88 + IMPORT_C void CompleteL(TDes8& aTarget,const TDesC8& aSource);
1.89 +private:
1.90 + CPBEncryptor* iKey;
1.91 + };
1.92 +
1.93 +/**
1.94 + * @publishedPartner
1.95 + * @released
1.96 + * A decrypting filter.
1.97 +
1.98 +An object of this type is used by RDecryptStream to decrypt stream data as
1.99 +it is read from a source stream.
1.100 +
1.101 +Decryption itself is performed by an instance of a class implementing the
1.102 +CPBDecryptor interface.
1.103 +
1.104 +@see RDecryptStream
1.105 +@see CSecureStore
1.106 +@see CPBDecryptor
1.107 +*/
1.108 +class TDecryptFilter : public TSecureFilter
1.109 + {
1.110 +public:
1.111 + IMPORT_C TDecryptFilter();
1.112 +// New function, recommended
1.113 + IMPORT_C void SetL(MStreamBuf* aHost,CPBDecryptor* aKey,TInt aMode=ERead);
1.114 +protected:
1.115 + IMPORT_C void DoRelease();
1.116 +private:
1.117 + IMPORT_C TInt CryptL(TDes8& aTarget,const TDesC8& aSource);
1.118 + IMPORT_C void CompleteL(TDes8& aTarget,const TDesC8& aSource);
1.119 +private:
1.120 + CPBDecryptor* iKey;
1.121 + };
1.122 +
1.123 +/**
1.124 + * @publishedPartner
1.125 + * @released
1.126 + * Supports the decrypting of a stream.
1.127 +
1.128 +The stream to be decrypted is a stream represented by an existing RReadStream
1.129 +object. In effect, RDecryptStream forms a layer over the RReadStream object,
1.130 +either using its source stream buffer or taking complete ownership of the
1.131 +source stream buffer.
1.132 +
1.133 +Decryption of streamed data is supported using the TDecryptFilter class derived
1.134 +from TStreamFilter. Decryption itself is performed by an instance of a class
1.135 +implementing the CPBEncryptionBase interface.
1.136 +
1.137 +@see TDecryptFilter
1.138 +@see TStreamFilter
1.139 +@see CPBEncryptionBase
1.140 +*/
1.141 +class RDecryptStream : public RReadStream
1.142 + {
1.143 +public:
1.144 + /** Constructs an empty decrypting stream object.
1.145 +
1.146 + Call OpenL() or OpenLC() to use a source stream owned by an existing read
1.147 + stream interface object, a RReadStream.
1.148 +
1.149 + Call AttachL() or AttachLC() to use and take ownership of a source stream
1.150 + owned by an existing read stream interface object. */
1.151 + RDecryptStream() {}
1.152 +public: // Original functions, now deprecated
1.153 +public: // New functions, using Password Based Encryption
1.154 + IMPORT_C void OpenL(RReadStream& aHost,const CPBEncryptionBase& aKey);
1.155 + IMPORT_C void OpenLC(RReadStream& aHost,const CPBEncryptionBase& aKey);
1.156 + IMPORT_C void AttachL(RReadStream& aHost,const CPBEncryptionBase& aKey);
1.157 + IMPORT_C void AttachLC(RReadStream& aHost,const CPBEncryptionBase& aKey);
1.158 +private:
1.159 + TDecryptFilter iFilter;
1.160 + };
1.161 +
1.162 +/**
1.163 + * @publishedPartner
1.164 + * @released
1.165 + * Supports the encryption of a stream.
1.166 +
1.167 +The stream to be encrypted is a stream represented by an existing RWriteStream
1.168 +object. In effect, REncryptStream forms a layer over the RWriteStream object,
1.169 +either using its target stream buffer or taking complete ownership of the
1.170 +target stream buffer.
1.171 +
1.172 +Encryption of streamed data is supported using the TEncryptFilter class derived
1.173 +from TStreamFilter. Encryption itself is performed by an instance of a class
1.174 +implementing the CPBEncryptionBase interface.
1.175 +
1.176 +@see TEncryptFilter
1.177 +@see TStreamFilter
1.178 +@see CPBEncryptionBase
1.179 +*/
1.180 +class REncryptStream : public RWriteStream
1.181 + {
1.182 +public:
1.183 + /** Constructs an empty encrypting stream object.
1.184 +
1.185 + Call OpenL() or OpenLC() to use a target stream owned by an existing write
1.186 + stream interface object, a RWriteStream.
1.187 +
1.188 + Call AttachL() or AttachLC() to use and take ownership of a target stream
1.189 + owned by an existing write stream interface object. */
1.190 + REncryptStream() {}
1.191 + inline REncryptStream(const MExternalizer<TStreamRef>& anExter);
1.192 +public: // Original functions, now deprecated
1.193 +public: // New functions, using Password Based Encryption
1.194 + IMPORT_C void OpenL(RWriteStream& aHost,const CPBEncryptionBase& aKey);
1.195 + IMPORT_C void OpenLC(RWriteStream& aHost,const CPBEncryptionBase& aKey);
1.196 + IMPORT_C void AttachL(RWriteStream& aHost,const CPBEncryptionBase& aKey);
1.197 + IMPORT_C void AttachLC(RWriteStream& aHost,const CPBEncryptionBase& aKey);
1.198 +private:
1.199 + TEncryptFilter iFilter;
1.200 + };
1.201 +//
1.202 +
1.203 +
1.204 +class HEncryptFilter;
1.205 +
1.206 +/**
1.207 +@publishedPartner
1.208 +@released
1.209 +A stream store whose streams are encrypted.
1.210 +
1.211 +The secure store is layered over another stream store which acts as the host
1.212 +for the encrypted streams. This stream store is not owned by the secure store,
1.213 +which means that it is possible to to use the secure store to store only a
1.214 +portion of the streams in encrypted form.
1.215 +
1.216 +Access to the streams in this store is via the normal RStoreWriteStream and
1.217 +RStoreReadStream classes. Internally, TEncryptFilter and TDecryptFilter objects
1.218 +are attached to the streams from the host store in order to do the encryption
1.219 +and decryption.
1.220 +
1.221 +@see RStoreWriteStream
1.222 +@see RStoreReadStream
1.223 +@see TEncryptFilter
1.224 +@see TDecryptFilter
1.225 +*/
1.226 +class CSecureStore : public CStreamStore
1.227 + {
1.228 +public:// Original functions, now deprecated
1.229 +public:// New functions using PBE
1.230 + IMPORT_C static CSecureStore* NewL(CStreamStore& aHost,const CPBEncryptSet& aKey);
1.231 + IMPORT_C static CSecureStore* NewLC(CStreamStore& aHost,const CPBEncryptSet& aKey);
1.232 + CSecureStore(CStreamStore& aHost,const CPBEncryptSet& aKey);
1.233 +protected:
1.234 + IMPORT_C MStreamBuf* DoReadL(TStreamId anId) const;
1.235 + IMPORT_C MStreamBuf* DoCreateL(TStreamId& anId);
1.236 + IMPORT_C TStreamId DoExtendL();
1.237 + IMPORT_C void DoDeleteL(TStreamId anId);
1.238 + IMPORT_C MStreamBuf* DoWriteL(TStreamId anId);
1.239 + IMPORT_C MStreamBuf* DoReplaceL(TStreamId anId);
1.240 + IMPORT_C void DoCommitL();
1.241 + IMPORT_C void DoRevertL();
1.242 +private:
1.243 + inline CStreamStore& Host();
1.244 + inline const CStreamStore& Host() const;
1.245 + inline const CPBEncryptSet& PBEKey() const;
1.246 + void setEncryptFilterL(HEncryptFilter& aFilter, RStoreWriteStream& aStream);
1.247 +private:
1.248 + CStreamStore* iHost;
1.249 + const CPBEncryptSet& iKey;
1.250 + };
1.251 +
1.252 +//
1.253 +
1.254 +/**
1.255 + * @publishedPartner
1.256 + * @released
1.257 + * Uses an encrypted store to implement the page pool interface MPagePool.
1.258 +
1.259 +A secure store page pool uses a cache to store pages in-memory and to cache
1.260 +frequently accessed pages. You should provide a cache object (CPageCache)
1.261 +to the pool for this purpose.
1.262 +
1.263 +@see CPageCache
1.264 +*/
1.265 +class RSecureStorePagePool : public RStorePagePool
1.266 + {
1.267 +public:// Original functions, now deprecated
1.268 +public:// New functions using PBE
1.269 + IMPORT_C RSecureStorePagePool(const CPBEncryptSet& aKey);
1.270 + IMPORT_C RSecureStorePagePool(CPageCache& aCache, const CPBEncryptSet& aKey);
1.271 +protected:
1.272 + IMPORT_C TPageRef ExtendL(const TAny* aPage,TPageReclamation aReclamation);
1.273 + IMPORT_C void WriteL(TPageRef aRef,const TAny* aPage,TPageChange aChange);
1.274 + IMPORT_C void ReadL(TPageRef aRef,TAny* aPage);
1.275 + IMPORT_C void DoDeleteL(TPageRef aRef);
1.276 +private:
1.277 + const CPBEncryptSet& iKey;
1.278 + };
1.279 +
1.280 +
1.281 +#include <s32crypt.inl>
1.282 +#endif