Apply reviewed doxygen header
[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. @n
41  *      This class allows to set 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 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                   Either of the following conditions has occurred:
86          *                                                                              - A specified input parameter is invalid.
87          *                                                                              - The specified @c opMode does not contain a valid value for the cipher operation.
88          *      @remarks                If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
89          *                              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 
90          *                              result obtained is @c null and an exception is returned.
91          */
92         virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
93
94         /**
95          *      Sets the symmetric key for encryption or decryption. @n
96          *      The variable length key ranges from 8 bits to 128 bits, in steps of 8 bits.
97          *
98          *      @since          2.0
99          *
100          *      @return         An error code
101          *      @param[in]      key                                             An instance of ISecretKey
102          *      @exception      E_SUCCESS                               The method is successful.
103          *      @exception      E_INVALID_ARG                   The specified @c key is invalid.
104          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
105          */
106         virtual result SetKey(const Tizen::Security::ISecretKey& key);
107
108         /**
109          *      Sets the initial vector.
110          *
111          *      @since          2.0
112          *
113          *      @return         An error code
114          *      @param[in]      initialVector                   The initial vector
115          *      @exception      E_SUCCESS                               The method is successful.
116          *      @exception      E_INVALID_ARG                   The specified input parameter is invalid.
117          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
118          */
119         virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
120
121         /**
122          *      Encrypts the data (single-part).
123          *
124          *      @since          2.0
125          *      @pre            Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
126          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
127          *                              else @c null if an error occurs
128          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
129          *      @exception      E_SUCCESS                               The method is successful.
130          *      @exception      E_INVALID_ARG                   The specified Tizen::Base::ByteBuffer instance is invalid or empty.
131          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
132          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
133          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
134          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
135          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
136          *                                                                              - A system error has occurred.
137          *                                                                              - The method has failed to operate with the OpenSSL library.
138          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
139          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
140          */
141         virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
142
143         /**
144          *      Decrypts the data (single-part).
145          *
146          *      @since          2.0
147          *      @pre            Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
148          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
149          *                              else @c null if an error occurs
150          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
151          *      @exception      E_SUCCESS                               The method is successful.
152          *      @exception      E_INVALID_ARG                   The specified Tizen::Base::ByteBuffer instance is invalid or empty.
153          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
154          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
155          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
156          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
157          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
158          *                                                                              - A system error has occurred.
159          *                                                                              - The method has failed to operate with the OpenSSL library.
160          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
161          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
162          */
163         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
164
165         /**
166          *      Initializes the instance of %Rc2Cipher for the multiple-part encryption or decryption.
167          *
168          *      @since          2.0
169          *      @pre            Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
170          *      @return         An error code
171          *      @exception      E_SUCCESS                               The method is successful.
172          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
173          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
174          *      @exception      E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
175          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
176          *                                                                              - A system error has occurred.
177          *                                                                              - The method has failed to operate with the OpenSSL library.
178          */
179         virtual result Initialize(void);
180
181         /**
182          *      Updates the multiple-part encryption or decryption operation.
183          *
184          *      @since          2.0
185          *
186          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
187          *                              else @c null if an error occurs
188          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
189          *      @exception      E_SUCCESS                               The method is successful.
190          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
191          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
192          *      @exception      E_INVALID_ARG                   The specified Tizen::Base::ByteBuffer instance is invalid or empty.
193          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
194          *                                                                              - A system error has occurred.
195          *                                                                              - The method has failed to operate with the OpenSSL library.
196          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
197          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
198          */
199         virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
200
201         /**
202          *      Finalizes the multiple-part encryption or decryption operation.
203          *
204          *      @since          2.0
205          *
206          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
207          *                              else @c null if an error occurs
208          *      @exception      E_SUCCESS                               The method is successful.
209          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
210          *      @exception      E_OVERFLOW                              This operation has caused the memory to overflow.
211          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
212          *                                                                              - A system error has occurred.
213          *                                                                              - The method has failed to operate with the OpenSSL library.
214          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
215          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
216          */
217         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
218
219         /**
220          *      Wraps a key.
221          *
222          *      @since          2.0
223          *
224          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
225          *                              else @c null if an error occurs
226          *      @param[in]      secretKey                               The secret key to wrap
227          *      @remarks        
228          *                      - This operation is not supported in the %Rc2Cipher class.
229          *                      Therefore, this method always returns @c null.
230          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
231          */
232         virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
233
234         /**
235          *      Unwraps a previously wrapped key.
236          *
237          *      @since          2.0
238          *
239          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
240          *                              else @c null if an error occurs
241          *      @param[in]      wrappedKey                              The wrapped key to unwrap
242          *      @remarks        
243          *                      - This operation is not supported in the %Rc2Cipher class.
244          *                      Therefore, this method always returns @c null.
245          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
246          */
247         virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
248
249 private:
250
251         //
252         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
253         //
254         // @since 2.0
255         //
256         Rc2Cipher(const Rc2Cipher& rhs);
257
258         //
259         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
260         //
261         // @since 2.0
262         //
263         Rc2Cipher& operator =(const Rc2Cipher& rhs);
264
265 private:
266         _SymmetricCipher* __pSymmetricCipher;
267         const evp_cipher_st* __pCipherAlgorithm;
268         Tizen::Base::String __cipherAlgorithm;
269
270         class _Rc2CipherImpl* __pRc2CipherImpl;
271         friend class _Rc2CipherImpl;
272
273 }; //Rc2Cipher
274
275 } } } //Tizen::Security::Crypto
276
277 #endif //_FSEC_CRYPTO_RC2_CIPHER_H_