|
1 /* |
|
2 * Copyright (c) 2002-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 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the |
|
16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /** |
|
24 @file |
|
25 @internalAll |
|
26 */ |
|
27 |
|
28 #ifndef __BUFFEREDTRANSFORMATION_H__ |
|
29 #define __BUFFEREDTRANSFORMATION_H__ |
|
30 |
|
31 #include <e32std.h> |
|
32 #include "msymmetriccipher.h" |
|
33 #include "blocktransformation.h" |
|
34 |
|
35 class CPadding; |
|
36 |
|
37 /** |
|
38 * Abstract class, deriving from CSymmetricCipher, encapsulating the buffering |
|
39 * logic for block ciphers. |
|
40 * |
|
41 * It is responsible for feeding complete blocks of plaintext or ciphertext to |
|
42 * the underlying encryptor or decryptor. Since the only difference between |
|
43 * block cipher encryption and decryption is the ProcessFinalL() call, |
|
44 * CBufferedTransformation implements all functions (by buffering and/or |
|
45 * forwarding to the encryptor/decryptor) except ProcessFinalL() and |
|
46 * MaxFinalOutputLength(). |
|
47 * |
|
48 * See the Cryptography api-guide documentation for the rules that this class |
|
49 * and derived classes must follow. |
|
50 * |
|
51 * @publishedPartner |
|
52 * @released |
|
53 */ |
|
54 class CBufferedTransformation : public CSymmetricCipher |
|
55 { |
|
56 public: |
|
57 /** The destructor frees all resources owned by the object, prior to its destruction. */ |
|
58 IMPORT_C virtual ~CBufferedTransformation(); |
|
59 public: |
|
60 /** |
|
61 * Encrypts or decrypts the input using the underlying block cipher, buffering |
|
62 * the input as necessary. |
|
63 * |
|
64 * See the Cryptography api-guide documentation. |
|
65 * |
|
66 * @param aInput The input is appended to the internal buffer (initially empty), |
|
67 * then all whole blocks are encrypted using the underlying block |
|
68 * transformation and written into aOutput. Any leftover bytes will |
|
69 * be buffered. |
|
70 * @param aOutput The resulting processed data appended to aOutput. aOutput must |
|
71 * have at least MaxOutputLength() empty bytes remaining in its length. |
|
72 */ |
|
73 virtual void Process(const TDesC8& aInput, TDes8& aOutput); |
|
74 virtual TInt MaxOutputLength(TInt aInputLength) const; |
|
75 virtual void Reset(); |
|
76 virtual TInt BlockSize() const; |
|
77 virtual TInt KeySize() const; |
|
78 public: |
|
79 /** |
|
80 * Gets the underlying block transform. |
|
81 * |
|
82 * @return A pointer to the CBlockTransformation object |
|
83 */ |
|
84 IMPORT_C CBlockTransformation* BlockTransformer() const; |
|
85 protected: |
|
86 /** @internalAll */ |
|
87 CBufferedTransformation(); |
|
88 /** @internalAll */ |
|
89 void ConstructL(CBlockTransformation* aBT, CPadding* aPadding); |
|
90 protected: |
|
91 /** A block transformation object */ |
|
92 CBlockTransformation* iBT; |
|
93 /** A descriptor which provides a buffer the length of the block size of iBT */ |
|
94 HBufC8* iInputStoreBuf; |
|
95 /** A pointer to iInputStoreBuf */ |
|
96 TPtr8 iInputStore; |
|
97 /** The padding */ |
|
98 CPadding* iPadding; |
|
99 }; |
|
100 |
|
101 /** |
|
102 * Subclass of CBufferedTransformation for buffered encryption. |
|
103 * |
|
104 * Objects of this class are intialised with, and subsequently own, an encryptor |
|
105 * derived from CBlockTransformation and a subclass of CPadding. |
|
106 * |
|
107 * @publishedPartner |
|
108 * @released |
|
109 */ |
|
110 class CBufferedEncryptor : public CBufferedTransformation |
|
111 { |
|
112 public: |
|
113 /** |
|
114 * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding. |
|
115 * |
|
116 * @param aBT Block transformation object (encryptor) |
|
117 * @param aPadding Padding object (deriving from CPadding) |
|
118 * @return A pointer to the new CBufferedEncryptor object |
|
119 */ |
|
120 IMPORT_C static CBufferedEncryptor* NewL(CBlockTransformation* aBT, |
|
121 CPadding* aPadding); |
|
122 |
|
123 /** |
|
124 * Creates a CBufferedEncryptor object taking ownership of aBT and aPadding. |
|
125 * |
|
126 * The returned pointer is put onto the cleanup stack. |
|
127 * |
|
128 * @param aBT Block transformation object (encryptor) |
|
129 * @param aPadding Padding object (deriving from CPadding) |
|
130 * @return A pointer to the new CBufferedEncryptor object |
|
131 */ |
|
132 IMPORT_C static CBufferedEncryptor* NewLC(CBlockTransformation* aBT, |
|
133 CPadding* aPadding); |
|
134 public: |
|
135 /** |
|
136 * Completes an encryption operation using the underlying block transformation, but |
|
137 * first ensuring that input data is block aligned using the previously supplied |
|
138 * CPadding object. |
|
139 * |
|
140 * See the Cryptography api-guide documentation. |
|
141 * |
|
142 * @param aInput The final input data to be processed. |
|
143 * @param aOutput The resulting processed data appended to aOutput. aOutput must |
|
144 * have at least MaxFinalOutputLength() empty bytes remaining in its |
|
145 * length. |
|
146 */ |
|
147 virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); |
|
148 virtual TInt MaxFinalOutputLength(TInt aInputLength) const; |
|
149 protected: |
|
150 /** @internalAll */ |
|
151 CBufferedEncryptor(); |
|
152 }; |
|
153 |
|
154 /** |
|
155 * Subclass of CBufferedTransformation for buffered decryption. |
|
156 * |
|
157 * Objects of this class are intialised with, and subsequently own, a decryptor |
|
158 * derived from CBlockTransformation and a subclass of CPadding. |
|
159 * |
|
160 * @publishedPartner |
|
161 * @released |
|
162 */ |
|
163 class CBufferedDecryptor : public CBufferedTransformation |
|
164 { |
|
165 public: |
|
166 /** |
|
167 * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding. |
|
168 * |
|
169 * @param aBT Block transformation object (decryptor) |
|
170 * @param aPadding Padding object (deriving from CPadding) |
|
171 * @return A pointer to the CBufferedDecryptor object. |
|
172 */ |
|
173 IMPORT_C static CBufferedDecryptor* NewL(CBlockTransformation* aBT, |
|
174 CPadding* aPadding); |
|
175 |
|
176 /** |
|
177 * Creates a CBufferedDecryptor object taking ownership of aBT and aPadding. |
|
178 * |
|
179 * The returned pointer is put onto the cleanup stack. |
|
180 * |
|
181 * @param aBT Block transformation object (decryptor) |
|
182 * @param aPadding Padding object (deriving from CPadding) |
|
183 * @return A pointer to the new CBufferedDecryptor object |
|
184 */ |
|
185 IMPORT_C static CBufferedDecryptor* NewLC(CBlockTransformation* aBT, |
|
186 CPadding* aPadding); |
|
187 public: |
|
188 /** |
|
189 * Completes a decryption operation using the underlying block transformation and |
|
190 * unpads the decrypted data. |
|
191 * |
|
192 * @param aInput The data to be processed and unpadded. |
|
193 * aInput must be a whole number of blocks. |
|
194 * @param aOutput The resulting processed and unpadded data appened to aOutput. |
|
195 * aOutput must have at least MaxFinalOutputLength() empty bytes |
|
196 * remaining in its length. |
|
197 */ |
|
198 virtual void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput); |
|
199 virtual TInt MaxFinalOutputLength(TInt aInputLength) const; |
|
200 protected: |
|
201 /** @internalAll */ |
|
202 CBufferedDecryptor(); |
|
203 }; |
|
204 |
|
205 #endif // __CBUFFEREDTRANSFORMATION_H__ |