Move system-server under server/system.
[platform/framework/native/appfw.git] / inc / FSecCryptoRc2Cipher.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                FSecCryptoRc2Cipher.h
19  * @brief               This is the header file for the %Rc2Cipher class.
20  *
21  * This header file contains the declarations of the %Rc2Cipher class.
22  */
23 #ifndef _FSEC_CRYPTO_RC2_CIPHER_H_
24 #define _FSEC_CRYPTO_RC2_CIPHER_H_
25
26 #include <FSecCryptoISymmetricCipher.h>
27
28 struct evp_cipher_st;
29
30 namespace Tizen { namespace Security { namespace Crypto
31 {
32
33 class _SymmetricCipher;
34 /**
35  *      @class          Rc2Cipher
36  *      @brief          This class provides methods for encryption and decryption using the RC2 algorithm.
37  *
38  *      @since          2.0
39  *
40  *      The %Rc2Cipher class provides a symmetric cipher using the RC2 algorithm.
41  *      It sets appropriate values for the requested mode/key bit/padding scheme and cipher operation (CIPHER_ENCRYPT or CIPHER_DECRYPT) parameters. @n
42  *
43  *      For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
44  *
45  *      @see    ISymmetricCipher
46  *  @see        DesCipher
47  *  @see        DesEdeCipher
48  */
49 class _OSP_EXPORT_ Rc2Cipher
50         : public virtual ISymmetricCipher
51         , public Tizen::Base::Object
52 {
53
54 public:
55         /**
56          *      The object is not fully constructed after this constructor is called. For full construction, @n
57          *      the Construct() method must be called right after calling this constructor.
58          *
59          *      @since          2.0
60          */
61         Rc2Cipher(void);
62
63         /**
64          *      This destructor overrides Tizen::Base::Object::~Object().
65          *
66          *      @since          2.0
67          */
68         virtual ~Rc2Cipher(void);
69
70         /**
71          *      Constructs and initializes this instance of %Rc2Cipher with the specified parameters.
72          *
73          *      @since          2.0
74          *
75          *      @return         An error code
76          *      @param[in]      transformation                  The name of the requested mode/padding scheme @n
77          *                                                                              The RC2 support variable length key ranges from 8 bits to 128 bits, in steps of 8 bits.
78          *                                                                              The key bits are not required to be mentioned in the transformation.
79          *                                                                              There are four valid transformations for RC2, "CBC/NOPADDING",
80          *                                                                              "CBC/PKCS7PADDING", "ECB/PKCS7PADDING", and "ECB/NOPADDING".
81          *      @param[in]      opMode                                  The cipher operation mode @n
82          *                                                                              The valid values for %Rc2Cipher 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. @n
93          *  The variable length key ranges from 8 bits to 128 bits, in steps of 8 bits.
94          *
95          *      @since          2.0
96          *
97          *      @return         An error code
98          *      @param[in]      key                                             An instance of ISecretKey
99          *      @exception      E_SUCCESS                               The method is successful.
100          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
101          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
102          */
103         virtual result SetKey(const Tizen::Security::ISecretKey& key);
104
105         /**
106          *      Sets the initial vector.
107          *
108          *      @since          2.0
109          *
110          *      @return         An error code
111          *      @param[in]      initialVector                   The initial vector
112          *      @exception      E_SUCCESS                               The method is successful.
113          *      @exception      E_INVALID_ARG                   The specified input parameter is invalid.
114          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
115          */
116         virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
117
118         /**
119          *      Encrypts the data (single-part).
120          *
121          *      @since          2.0
122          *      @pre                    Before calling this method, a secret key and an initial vector should be set using SetKey() and SetInitialVector().
123          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
124          *                              else @c null if an error occurs
125          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
126          *      @exception      E_SUCCESS                               The method is successful.
127          *      @exception      E_INVALID_ARG                   The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
128          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
129          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
130          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
131          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
132          *      @exception      E_SYSTEM                                A system error has occurred. @n
133          *                                                                              The method has failed to operate with the OpenSSL library, or
134          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
135          *      @remarks                The specific error code can be accessed using the GetLastResult() 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          *      @pre                    Before calling this method, a secret key and an initial vector should be set using SetKey() and SetInitialVector().
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          */
158         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
159
160         /**
161          *      Initializes a multiple-part encryption or decryption operation.
162          *
163          *      @since          2.0
164          *      @pre                    Before calling this method, a secret key and an initial vector should be set using SetKey() and SetInitialVector().
165          *      @return         An error code
166          *      @exception      E_SUCCESS                               The method is successful.
167          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
168          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
169          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
170          *      @exception      E_SYSTEM                                A system error has occurred. @n
171          *                                                                              The method has failed to operate with the OpenSSL library.
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        
220          *                      - This operation is not supported in the %Rc2Cipher class.
221          *                      Therefore, this method always returns @c null.
222          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
223          */
224         virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
225
226         /**
227          *      Unwraps a previously wrapped key.
228          *
229          *      @since          2.0
230          *
231          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
232          *                              else @c null if an error occurs
233          *      @param[in]      wrappedKey                              The wrapped key to unwrap
234          *      @remarks        
235          *                      - This operation is not supported in the %Rc2Cipher class.
236          *                      Therefore, this method always returns @c null.
237          *                      - 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         Rc2Cipher(const Rc2Cipher& 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         Rc2Cipher& operator =(const Rc2Cipher& rhs);
256
257 private:
258         _SymmetricCipher* __pSymmetricCipher;
259         const evp_cipher_st* __pCipherAlgorithm;
260         Tizen::Base::String __cipherAlgorithm;
261
262         class _Rc2CipherImpl* __pRc2CipherImpl;
263         friend class _Rc2CipherImpl;
264
265 }; //Rc2Cipher
266
267 } } } //Tizen::Security::Crypto
268
269 #endif //_FSEC_CRYPTO_RC2_CIPHER_H_