sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FSecCryptoDesEdeCipher.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                FSecCryptoDesEdeCipher.h
20  * @brief               This is the header file for the %DesEdeCipher class.
21  *
22  * This header file contains the declarations of the %DesEdeCipher class.
23  */
24 #ifndef _FSEC_CRYPTO_DES_EDE_CIPHER_H_
25 #define _FSEC_CRYPTO_DES_EDE_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          DesEdeCipher
38  *      @brief          This class provides methods for encryption and decryption using the Data Encryption Standard in the Encrypt-Decrypt-Encrypt (DES-EDE) mode.
39  *
40  *      @since       2.0
41  *
42  *      The %DesEdeCipher class provides symmetric cipher using the Data Encryption Standard in the Encrypt-Decrypt-Encrypt (DES-EDE) mode.
43  *      Sets appropriate values for the requested mode/key bit/padding scheme and cipher operation (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    DesCipher
49  *      @see    AesCipher
50  */
51 class _OSP_EXPORT_ DesEdeCipher
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         DesEdeCipher(void);
64
65         /**
66          *      This destructor overrides Tizen::Base::Object::~Object().
67          *
68          *      @since          2.0
69          */
70         virtual ~DesEdeCipher(void);
71
72         /**
73          *      Initializes this instance of %DesEdeCipher with the specified parameters.
74          *
75          *      @since          2.0
76          *
77          *      @return         An error code
78          *      @param[in]      transformation                  The name of 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 %DesEdeCipher 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                   A specified input parameter is invalid, or the specified @c opMode does not contain a valid value for the cipher operation.
85          *      @remarks        If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
86          *                              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.
87          */
88         virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
89         /**
90          *      Sets a symmetric key for encryption or decryption.
91          *
92          *      @since          2.0
93          *
94          *      @return         An error code
95          *      @param[in]      key                                             An instance of ISecretKey
96          *      @exception      E_SUCCESS                               The method is successful.
97          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
98          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
99          */
100         virtual result SetKey(const Tizen::Security::ISecretKey& key);
101
102         /**
103          *      Sets the initial vector.
104          *
105          *      @since          2.0
106          *
107          *      @return         An error code
108          *      @param[in]      initialVector                   The initial vector
109          *      @exception      E_SUCCESS                               The method is successful.
110          *      @exception      E_INVALID_ARG                   The specified input parameter is invalid.
111          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
112          */
113         virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
114
115         /**
116          *      Encrypts the data (single-part).
117          *
118          *      @since          2.0
119          *
120          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
121          *                              else @c null if an error occurs
122          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
123          *      @exception      E_SUCCESS                               The method is successful.
124          *      @exception      E_INVALID_ARG                   The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
125          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
126          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
127          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
128          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
129          *      @exception      E_SYSTEM                                A system error has occurred. @n
130          *                                                                              The method has failed to operate with the openssl library, or
131          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
132          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
133          *      @remarks        A secret key and an initial vector are set before calling this method.
134          */
135         virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
136
137         /**
138          *      Decrypts the data (single-part).
139          *
140          *      @since          2.0
141          *
142          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
143          *                              else @c null if an error occurs
144          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
145          *      @exception      E_SUCCESS                               The method is successful.
146          *      @exception      E_INVALID_ARG                   The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
147          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
148          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
149          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
150          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
151          *      @exception      E_SYSTEM                                A system error has occurred. @n
152          *                                                                              The method has failed to operate with the openssl library, or
153          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
154          *  @remarks    The specific error code can be accessed using the GetLastResult() method.
155          * @remarks     A secret key and an initial vector are set before calling this method.
156          */
157         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
158
159         /**
160          *      Initializes a multiple-part encryption or decryption operation.
161          *
162          *      @since          2.0
163          *
164          *      @return         An error code
165          *      @exception      E_SUCCESS                               The method is successful.
166          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
167          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
168          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
169          *      @exception      E_SYSTEM                                A system error has occurred. @n
170          *                                                                              The method has failed to operate with the openssl library.
171          *      @remarks        A secret key and an initial vector are set before calling this method.
172          */
173         virtual result Initialize(void);
174
175         /**
176          *      Updates a multiple-part encryption or decryption operation.
177          *
178          *      @since          2.0
179          *
180          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
181          *                              else @c null if an error occurs
182          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
183          *      @exception      E_SUCCESS                               The method is successful.
184          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
185          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
186          *      @exception      E_INVALID_ARG                   The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
187          *      @exception      E_SYSTEM                                A system error has occurred. @n
188          *                                                                              The method has failed to operate with the openssl library, or
189          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
190          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
191          */
192         virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
193
194         /**
195          *      Finalizes a multiple-part encryption or decryption operation.
196          *
197          *      @since          2.0
198          *
199          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
200          *                              else @c null if an error occurs
201          *      @exception      E_SUCCESS                               The method is successful.
202          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
203          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
204          *      @exception      E_SYSTEM                                A system error has occurred. @n
205          *                                                                              The method has failed to operate with the openssl library, or
206          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
207          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
208          */
209         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
210
211         /**
212          *      Wraps a key.
213          *
214          *      @since          2.0
215          *
216          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
217          *                              else @c null if an error occurs
218          *      @param[in]      secretKey                               The secret key to wrap
219          *      @remarks        This operation is not supported in the %DesEdeCipher class.
220          *                              Therefore, this method always returns @c null.
221          *      @remarks        The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
222          */
223         virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
224
225         /**
226          *      Unwraps a previously wrapped key.
227          *
228          *      @since          2.0
229          *
230          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
231          *                              else @c null if an error occurs
232          *      @param[in]      wrappedKey                              The wrapped key to unwrap
233          *      @remarks        This operation is not supported in the %DesEdeCipher class.
234          *                              Therefore, this method always returns @c null.
235          *      @remarks        The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
236          */
237         virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
238
239 private:
240
241         //
242         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
243         //
244         // @since 2.0
245         //
246         DesEdeCipher(const DesEdeCipher& rhs);
247
248         //
249         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
250         //
251         // @since 2.0
252         //
253         DesEdeCipher& operator =(const DesEdeCipher& rhs);
254
255 private:
256         _SymmetricCipher* __pSymmetricCipher;
257         const evp_cipher_st* __pCipherAlgorithm;
258         Tizen::Base::String __cipherAlgorithm;
259
260         class _DesEdeCipherImpl* __pDesEdeCipherImpl;
261         friend class _DesEdeCipherImpl;
262
263 }; //DesEdeCipher
264
265 } } } //Tizen::Security::Crypto
266
267 #endif //_FSEC_CRYPTO_DES_EDE_CIPHER_H_