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