Apply reviewed doxygen header
[platform/framework/native/appfw.git] / inc / FSecCryptoDesCipher.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  *      @file           FSecCryptoDesCipher.h
19  *      @brief          This is the header file for the %DesCipher class.
20  *
21  *      This header file contains the declarations of the %DesCipher class.
22  */
23 #ifndef _FSEC_CRYPTO_DES_CIPHER_H_
24 #define _FSEC_CRYPTO_DES_CIPHER_H_
25
26 #include <FSecCryptoISymmetricCipher.h>
27
28 struct evp_cipher_st;
29
30
31 namespace Tizen { namespace Security { namespace Crypto
32 {
33
34 class _SymmetricCipher;
35 /**
36  *      @class          DesCipher
37  *      @brief          This class provides methods for encryption and decryption using the Data Encryption Standard (DES) method.
38  *
39  *      @since          2.0
40  *
41  *      The %DesCipher class provides a symmetric cipher using the Data Encryption Standard (DES) method.
42  *      This class allows to set appropriate values for the requested mode/key bit/padding scheme and cipher operation mode
43  * (::CIPHER_ENCRYPT or ::CIPHER_DECRYPT) parameters. @n
44  *
45  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
46  *
47  *      @see    ISymmetricCipher
48  *      @see    AesCipher
49  *      @see    DesEdeCipher
50  */
51 class _OSP_EXPORT_ DesCipher
52         : public virtual ISymmetricCipher
53         , public Tizen::Base::Object
54 {
55
56 public:
57         /**
58          *      The object is not fully constructed after this constructor is called. For full construction, @n
59          *      the Construct() method must be called right after calling this constructor.
60          *
61          * @since               2.0
62          */
63         DesCipher(void);
64
65         /**
66          *      This destructor overrides Tizen::Base::Object::~Object().
67          *
68          * @since               2.0
69          */
70         virtual ~DesCipher(void);
71
72         /**
73          *      Initializes this instance of %DesCipher with the specified parameters.
74          *
75          *      @since          2.0
76          *
77          *      @return         An error code
78          *      @param[in]      transformation                          The requested mode/key bit/padding scheme @n
79          *                                                                                      For example, "CBC/NOPADDING" or "CBC/PKCS7PADDING".
80          *      @param[in]      opMode                                          The cipher operation mode @n
81          *                                                                                      The valid values for %DesCipher are @c CIPHER_ENCRYPT and @c CIPHER_DECRYPT.
82          *      @exception      E_SUCCESS                                       The method is successful.
83          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
84          *      @exception      E_INVALID_ARG                           Either of the following conditions has occurred:
85          *                                                                                      - A specified input parameter is invalid.
86          *                                                                                      - The specified @c opMode does not contain a valid value for the cipher operation.
87          *      @remarks        If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
88          *                              For example, if @c opMode is set to @c CIPHER_ENCRYPT, @c CIPHER_WRAP, or @c CIPHER_UNWRAP and the DecryptN() 
89          *                              method is used, then the result obtained is @c null and an exception is returned.
90          */
91         virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
92
93         /**
94          *      Sets the symmetric key for encryption or decryption.
95          *
96          *      @since          2.0
97          *
98          *      @return         An error code
99          *      @param[in]      key                                                     An instance of ISecretKey
100          *      @exception      E_SUCCESS                                       The method is successful.
101          *      @exception      E_INVALID_ARG                           The specified @c key is invalid.
102          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
103          */
104         virtual result SetKey(const Tizen::Security::ISecretKey& key);
105
106         /**
107          *      Sets the initial vector.
108          *
109          *      @since          2.0
110          *
111          *      @return         An error code
112          *      @param[in]      initialVector                           The initial vector
113          *      @exception      E_SUCCESS                                       The method is successful.
114          *      @exception      E_INVALID_ARG                           The specified input parameter is invalid.
115          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
116          */
117         virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
118
119         /**
120          *      Encrypts the data (single-part).
121          *
122          *      @since          2.0
123          *      @pre            Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
124          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
125          *                              else @c null if an error occurs
126          *      @param[in]      input                                           An instance of Tizen::Base::ByteBuffer
127          *      @exception      E_SUCCESS                                       The method is successful.
128          *      @exception      E_INVALID_ARG                           The specified Tizen::Base::ByteBuffer instance is invalid or empty.
129          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
130          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
131          *      @exception      E_INVALID_OPERATION                     The specified cipher operation mode for this method is invalid.
132          *      @exception      E_OVERFLOW                                      This operation has caused the memory to overflow.
133          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
134          *                                                                                      - A system error has occurred.
135          *                                                                                      - The method has failed to operate with the OpenSSL library.
136          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
137          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
138          */
139         virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
140
141         /**
142          *      Decrypts the data (single-part).
143          *
144          *      @since          2.0
145          *      @pre            Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
146          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
147          *                              else @c null if an error occurs
148          *      @param[in]      input                                           An instance of Tizen::Base::ByteBuffer
149          *      @exception      E_SUCCESS                                       The method is successful.
150          *      @exception      E_INVALID_ARG                           The specified Tizen::Base::ByteBuffer instance is invalid or empty.
151          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
152          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
153          *      @exception      E_INVALID_OPERATION                     The specified cipher operation mode for this method is invalid.
154          *      @exception      E_OVERFLOW                                      This operation has caused the memory to overflow.
155          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
156          *                                                                                      - A system error has occurred.
157          *                                                                                      - The method has failed to operate with the OpenSSL library.
158          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
159          *      @remarks                The specific error code can be accessed using the GetLastResult() method.
160          */
161         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
162
163         /**
164          *      Initializes the instance of %DesCipher for the multiple-part encryption or decryption.
165          *
166          *      @since          2.0
167          *      @pre            Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
168          *      @return         An error code
169          *      @exception      E_SUCCESS                                       The method is successful.
170          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
171          *      @exception      E_KEY_NOT_FOUND                         The specified key is not found.
172          *      @exception      E_INVALID_OPERATION                     The specified cipher operation mode for this method is invalid.
173          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
174          *                                                                                      - A system error has occurred.
175          *                                                                                      - The method has failed to operate with the openssl library.
176          */
177         virtual result Initialize(void);
178
179         /**
180          *      Updates the multiple-part encryption or decryption operation.
181          *
182          *      @since          2.0
183          *
184          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
185          *                              else @c null if an error occurs
186          *      @param[in]      input                                           An instance of Tizen::Base::ByteBuffer
187          *      @exception      E_SUCCESS                                       The method is successful.
188          *      @exception      E_OUT_OF_MEMORY                         The memory is insufficient.
189          *      @exception      E_OVERFLOW                                      This operation has caused the memory to overflow.
190          *      @exception      E_INVALID_ARG                           The specified Tizen::Base::ByteBuffer instance is invalid or empty.
191          *      @exception      E_SYSTEM                                        Either of the following conditions has occurred:
192          *                                                                                      - A system error has occurred.
193          *                                                                                      - The method has failed to operate with the OpenSSL library.
194          *                                                                                      - The Tizen::Base::ByteBuffer operation has failed.
195          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
196          */
197         virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
198
199         /**
200          *      Finalizes the multiple-part encryption or decryption operation.
201          *
202          *      @since          2.0
203          *
204          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
205          *                              else @c null if an error occurs
206          *      @exception      E_SUCCESS                               The method is successful.
207          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
208          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
209          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
210          *                                                                              - A system error has occurred
211          *                                                                              - The method has failed to operate with the OpenSSL library.
212          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
213          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
214          */
215         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
216
217         /**
218          *      Wraps a key.
219          *
220          *      @since          2.0
221          *
222          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
223          *                              else @c null if an error occurs
224          *      @param[in]      secretKey                               The secret key to wrap
225          *      @remarks        
226          *                      - This operation is not supported in the %DesCipher class.
227          *                      Therefore, this method always returns @c null.
228          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
229          */
230         virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
231
232         /**
233          *      Unwraps a previously wrapped key.
234          *
235          *      @since          2.0
236          *
237          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
238          *                              else @c null if an error occurs
239          *      @param[in]      wrappedKey                              The wrapped key to unwrap
240          *      @remarks        
241          *                      - This operation is not supported in the %DesCipher class.
242          *                      Therefore, this method always returns @c null.
243          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
244          */
245         virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
246
247 private:
248
249         //
250         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
251         //
252         // @since 2.0
253         //
254         DesCipher(const DesCipher& rhs);
255
256         //
257         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
258         //
259         // @since 2.0
260         //
261         DesCipher& operator =(const DesCipher& rhs);
262
263 private:
264         _SymmetricCipher* __pSymmetricCipher;
265         const evp_cipher_st* __pCipherAlgorithm;
266         Tizen::Base::String __cipherAlgorithm;
267
268         class _DesCipherImpl* __pDesCipherImpl;
269         friend class _DesCipherImpl;
270
271 }; //DesCipher
272
273 } } } //Tizen::Security::Crypto
274
275 #endif //_FSEC_CRYPTO_DES_CIPHER_H_