Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / inc / FSecCryptoSkipJackCipher.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        FSecCryptoSkipJackCipher.h
19  * @brief       This is the header file for the %SkipJackCipher class.
20  *
21  * This header file contains the declarations of the %SkipJackCipher class.
22  */
23 #ifndef _FSEC_CRYPTO_SKIPJACK_CIPHER_H_
24 #define _FSEC_CRYPTO_SKIPJACK_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       SkipJackCipher
37  * @brief       This class provides methods for encryption and decryption using the Skipjack algorithm.
38  *
39  * @since   2.0
40  *
41  * The %SkipJackCipher class provides a symmetric cipher using the Skipjack algorithm. @n
42  * This class allows to set appropriate values for the requested  mode or key bit or padding scheme and the cipher operation (::CIPHER_ENCRYPT or ::CIPHER_DECRYPT) parameters.
43  *
44  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
45  *
46  * @see         ISymmetricCipher
47  * @see         DesCipher
48  * @see         DesEdeCipher
49  */
50 class _OSP_EXPORT_ SkipJackCipher
51         : public virtual ISymmetricCipher
52         , public Tizen::Base::Object
53 {
54
55 public:
56         /**
57          * The object is not fully constructed after this constructor is called. For full construction, @n
58          * the Construct() method must be called right after calling this constructor.
59          *
60          * @since               2.0
61          */
62         SkipJackCipher(void);
63
64         /**
65          * This destructor overrides Tizen::Base::Object::~Object().
66          *
67          * @since               2.0
68          */
69         virtual ~SkipJackCipher(void);
70
71         /**
72          * Constructs and initializes this instance of %SkipJackCipher with the specified parameters.
73          *
74          * @since               2.0
75          *
76          * @return              An error code
77          * @param[in]   transformation                  The requested mode or padding scheme @n
78          *                                                                              As the default key size of the Skipjack cipher is 80 bits, there is no need to mention it explicitly.
79          *                                                                              For example, "CBC/PKCS7PADDING" or "ECB/NOPADDING".
80          * @param[in]   opMode                                  The cipher operation mode @n
81          *                                                                              The only valid values for %SkipJackCipher 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                   The specified @c opMode contains invalid 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, 
87          *                              then the result obtained is @c null and an exception is returned.
88          */
89
90         virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
91
92         /**
93          * Sets the symmetric key for encryption or decryption.
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 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, set a secret key and an initial vector 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 input Tizen::Base::ByteBuffer is empty or contains invalid data.
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                                Either of the following conditions has occurred:
133          *                                                                              - A system error has occurred.
134          *                                                                              - The method has failed to operate with the OpenSSL library.
135          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
136          * @remarks             The specific error code can be accessed using the GetLastResult() method.
137          */
138         virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
139
140         /**
141          * Decrypts the data (single-part).
142          *
143          * @since               2.0
144          * @pre                 Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
145          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
146          *                              else @c null if an error occurs
147          * @param[in]   input                                   An instance of Tizen::Base::ByteBuffer
148          * @exception   E_SUCCESS                               The method is successful.
149          * @exception   E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
150          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
151          * @exception   E_KEY_NOT_FOUND                 The specified key is not found.
152          * @exception   E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
153          * @exception   E_OVERFLOW                              This operation has caused the memory to overflow.
154          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
155          *                                                                              - A system error has occurred.
156          *                                                                              - The method has failed to operate with the OpenSSL library.
157          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
158          * @remarks             The specific error code can be accessed using the GetLastResult() method.
159          */
160         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
161
162         /**
163          * Initializes the instance of %SkipJackCipher for the multiple-part encryption or decryption.
164          *
165          * @since               2.0
166          * @pre                 Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
167          * @return              An error code
168          * @exception   E_SUCCESS                               The method is successful.
169          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
170          * @exception   E_KEY_NOT_FOUND                 The specified key is not found.
171          * @exception   E_INVALID_OPERATION             The specified cipher operation mode for this method is invalid.
172          *      @exception      E_SYSTEM                                Either of the following conditions has occurred:
173          *                                                                              - A system error has occurred.
174          *                                                                              - The method has failed to operate with the OpenSSL library.
175          */
176         virtual result Initialize(void);
177
178         /**
179          * Updates the multiple-part encryption or decryption operation.
180          *
181          * @since               2.0
182          *
183          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
184          *                              else @c null if an error occurs
185          * @param[in]   input                                   An instance of Tizen::Base::ByteBuffer
186          * @exception   E_SUCCESS                               The method is successful.
187          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
188          * @exception   E_OVERFLOW                              This operation has caused the memory to overflow.
189          * @exception   E_INVALID_ARG                   The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
190          * @exception   E_SYSTEM                                Either of the following conditions has occurred:
191          *                                                                              - A system error has occurred.
192          *                                                                              - The method has failed to operate with the OpenSSL library.
193          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
194          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
195          */
196         virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
197
198         /**
199          * Finalizes the multiple-part encryption or decryption operation.
200          *
201          * @since               2.0
202          *
203          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
204          *                              else @c null if an error occurs
205          * @exception   E_SUCCESS                               The method is successful.
206          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
207          * @exception   E_OVERFLOW                              This operation has caused the memory to overflow.
208          * @exception   E_SYSTEM                                Either of the following conditions has occurred:
209          *                                                                              - A system error has occurred.
210          *                                                                              - The method has failed to operate with the OpenSSL library.
211          *                                                                              - The Tizen::Base::ByteBuffer operation has failed.
212          * @remarks             The specific error code can be accessed using the GetLastResult() method.
213          */
214         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
215
216         /**
217          * Wraps a key.
218          *
219          * @since               2.0
220          *
221          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
222          *                              else @c null if an error occurs
223          * @param[in]   secretKey                               The secret key to wrap
224          * @remarks             
225          *                      - This operation is not supported in %SkipJackCipher. Therefore, this method always returns @c null.
226          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
227          */
228         virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
229
230         /**
231          * Unwraps a previously wrapped key.
232          *
233          * @since               2.0
234          *
235          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
236          *                              else @c null if an error occurs
237          * @param[in]   wrappedKey                      The wrapped key to unwrap
238          * @remarks             
239          *                      - This operation is not supported in %SkipJackCipher. Therefore, this method always returns @c null.
240          *                      - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
241          */
242         virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
243
244 private:
245
246         //
247         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
248         //
249         // @since 2.0
250         //
251         SkipJackCipher(const SkipJackCipher& rhs);
252
253         //
254         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
255         //
256         // @since 2.0
257         //
258         SkipJackCipher& operator =(const SkipJackCipher& rhs);
259
260 private:
261         _SymmetricCipher* __pSymmetricCipher;
262         const evp_cipher_st* __pCipherAlgorithm;
263         Tizen::Base::String __cipherAlgorithm;
264
265         class _SkipJackCipherImpl* __pSkipJackCipherImpl;
266         friend class _SkipJackCipherImpl;
267
268 }; //SkipJackCipher
269
270 } } } //Tizen::Security::Crypto
271
272 #endif //_FSEC_CRYPTO_SKIPJACK_CIPHER_H_