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