Merge "Apply millisecond of DateTime for Calendar" into tizen_2.1
[platform/framework/native/appfw.git] / inc / FSecCryptoSkipJackCipher.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        FSecCryptoSkipJackCipher.h
20  * @brief       This is the header file for the %SkipJackCipher class.
21  *
22  * This header file contains the declarations of the %SkipJackCipher class.
23  */
24 #ifndef _FSEC_CRYPTO_SKIPJACK_CIPHER_H_
25 #define _FSEC_CRYPTO_SKIPJACK_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       SkipJackCipher
38  * @brief       This class provides methods for encryption and decryption using the Skipjack algorithm.
39  *
40  * @since   2.0
41  *
42  * The %SkipJackCipher class provides a symmetric cipher using the Skipjack algorithm. Appropriate values have to be set for the requested mode or key bit or
43  * padding scheme and the 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         DesEdeCipher
50  */
51 class _OSP_EXPORT_ SkipJackCipher
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         SkipJackCipher(void);
64
65         /**
66          * This destructor overrides Tizen::Base::Object::~Object().
67          *
68          * @since               2.0
69          */
70         virtual ~SkipJackCipher(void);
71
72         /**
73          * Constructs and initializes this instance of %SkipJackCipher 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 or padding scheme @n
79          *                                                                              As the default key size of the Skipjack cipher is 80 bits, there is no need to mention it explicitly.
80          *                                                                              For example, "CBC/PKCS7PADDING" or "ECB/NOPADDING".
81          * @param[in]   opMode                                  The cipher operation mode @n
82          *                                                                              The only valid values for %SkipJackCipher 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                   The specified @c opMode contains invalid 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
90         virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
91
92         /**
93          * Sets a 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          *
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                                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          * @remarks             A secret key and an initial vector are set before calling this 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          *
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                                A system error has occurred. @n
155          *                                                                              The method has failed to operate with the OpenSSL library, or
156          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
157          * @remarks             The specific error code can be accessed using the GetLastResult() method.
158          * @remarks             A secret key and an initial vector are set before calling this method.
159          */
160         virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
161
162         /**
163          * Initializes a multiple-part encryption or decryption operation.
164          *
165          * @since               2.0
166          *
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                                A system error has occurred. @n
173          *                                                                              The method has failed to operate with the OpenSSL library.
174          * @remarks             A secret key and an initial vector are set before calling this method.
175          */
176         virtual result Initialize(void);
177
178         /**
179          * Updates a 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                                A system error has occurred. @n
191          *                                                                              The method has failed to operate with the OpenSSL library, or
192          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
193          * @remarks             The specific error code can be accessed using the GetLastResult() method.
194          */
195         virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
196
197         /**
198          * Finalizes a multiple-part encryption or decryption operation.
199          *
200          * @since               2.0
201          *
202          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
203          *                              else @c null if an error occurs
204          * @exception   E_SUCCESS                               The method is successful.
205          * @exception   E_OUT_OF_MEMORY                 The memory is insufficient.
206          * @exception   E_OVERFLOW                              This operation has caused the memory to overflow.
207          *      @exception      E_SYSTEM                                A system error has occurred. @n
208          *                                                                              The method has failed to operate with the OpenSSL library, or
209          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
210          * @remarks             The specific error code can be accessed using the GetLastResult() method.
211          */
212         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
213
214         /**
215          * Wraps the specified key.
216          *
217          * @since                       2.0
218          *
219          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
220          *                              else @c null if an error occurs
221          * @param[in]   secretKey                               The secret key to wrap
222          * @remarks             This operation is not supported in %SkipJackCipher. Therefore, this method always returns @c null.
223          * @remarks             The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
224          */
225         virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
226
227         /**
228          * Unwraps the specified wrapped key.
229          *
230          * @since               2.0
231          *
232          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
233          *                                      else @c null if an error occurs
234          * @param[in]   wrappedKey                      The wrapped key to unwrap
235          * @remarks             This operation is not supported in %SkipJackCipher. Therefore, this method always returns @c null. @n
236          * @remarks             The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
237          */
238         virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
239
240 private:
241
242         //
243         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
244         //
245         // @since 2.0
246         //
247         SkipJackCipher(const SkipJackCipher& rhs);
248
249         //
250         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
251         //
252         // @since 2.0
253         //
254         SkipJackCipher& operator =(const SkipJackCipher& rhs);
255
256 private:
257         _SymmetricCipher* __pSymmetricCipher;
258         const evp_cipher_st* __pCipherAlgorithm;
259         Tizen::Base::String __cipherAlgorithm;
260
261         class _SkipJackCipherImpl* __pSkipJackCipherImpl;
262         friend class _SkipJackCipherImpl;
263
264 }; //SkipJackCipher
265
266 } } } //Tizen::Security::Crypto
267
268 #endif //_FSEC_CRYPTO_SKIPJACK_CIPHER_H_