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