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