2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSecCryptoDesEdeCipher.h
19 * @brief This is the header file for the %DesEdeCipher class.
21 * This header file contains the declarations of the %DesEdeCipher class.
23 #ifndef _FSEC_CRYPTO_DES_EDE_CIPHER_H_
24 #define _FSEC_CRYPTO_DES_EDE_CIPHER_H_
26 #include <FSecCryptoISymmetricCipher.h>
31 namespace Tizen { namespace Security { namespace Crypto
34 class _SymmetricCipher;
37 * @brief This class provides methods for encryption and decryption using the Data Encryption Standard in the Encrypt-Decrypt-Encrypt (DES-EDE) mode.
41 * The %DesEdeCipher class provides symmetric cipher using the Data Encryption Standard in the Encrypt-Decrypt-Encrypt (DES-EDE) mode.
42 * 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
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
46 * @see ISymmetricCipher
50 class _OSP_EXPORT_ DesEdeCipher
51 : public virtual ISymmetricCipher
52 , public Tizen::Base::Object
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.
65 * This destructor overrides Tizen::Base::Object::~Object().
69 virtual ~DesEdeCipher(void);
72 * Initializes this instance of %DesEdeCipher with the specified parameters.
76 * @return An error code
77 * @param[in] transformation The requested mode/key bit/padding scheme @n
78 * For example, "CBC/NOPADDING" or "CBC/PKCS7PADDING".
79 * @param[in] opMode The cipher operation mode @n
80 * The valid values for %DesEdeCipher are @c CIPHER_ENCRYPT and @c CIPHER_DECRYPT.
81 * @exception E_SUCCESS The method is successful.
82 * @exception E_OUT_OF_MEMORY The memory is insufficient.
83 * @exception E_INVALID_ARG Either of the following conditions has occurred:
84 * - A specified input parameter is invalid.
85 * - 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()
88 * method is used, then the result obtained is @c null and an exception is returned.
90 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
92 * Sets the symmetric key for encryption or decryption.
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 @c key is invalid.
100 * @exception E_OUT_OF_MEMORY The memory is insufficient.
102 virtual result SetKey(const Tizen::Security::ISecretKey& key);
105 * Sets the initial vector.
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.
115 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
118 * Encrypts the data (single-part).
121 * @pre Before calling this method, set a secret key and an initial vector 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 specified Tizen::Base::ByteBuffer instance is invalid or empty.
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 Either of the following conditions has occurred:
132 * - A system error has occurred.
133 * - The method has failed to operate with the OpenSSL library.
134 * - The Tizen::Base::ByteBuffer operation has failed.
135 * @remarks The specific error code can be accessed using the GetLastResult() method.
137 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
140 * Decrypts the data (single-part).
143 * @pre Before calling this method, set a secret key and an initial vector 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 Tizen::Base::ByteBuffer instance 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 Either of the following conditions has occurred:
154 * - A system error has occurred.
155 * - The method has failed to operate with the OpenSSL library.
156 * - The Tizen::Base::ByteBuffer operation has failed.
157 * @remarks The specific error code can be accessed using the GetLastResult() method.
159 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
162 * Initializes the instance of %DesEdeCipher for the multiple-part encryption or decryption.
165 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
166 * @return An error code
167 * @exception E_SUCCESS The method is successful.
168 * @exception E_OUT_OF_MEMORY The memory is insufficient.
169 * @exception E_KEY_NOT_FOUND The specified key is not found.
170 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
171 * @exception E_SYSTEM Either of the following conditions has occurred:
172 * - A system error has occurred.
173 * - The method has failed to operate with the openssl library.
175 virtual result Initialize(void);
178 * Updates the multiple-part encryption or decryption operation.
182 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
183 * else @c null if an error occurs
184 * @param[in] input An instance of Tizen::Base::ByteBuffer
185 * @exception E_SUCCESS The method is successful.
186 * @exception E_OUT_OF_MEMORY The memory is insufficient.
187 * @exception E_OVERFLOW This operation has caused the memory to overflow.
188 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
189 * @exception E_SYSTEM Either of the following conditions has occurred:
190 * - A system error has occurred.
191 * - The method has failed to operate with the OpenSSL library.
192 * - The Tizen::Base::ByteBuffer operation has failed.
193 * @remarks The specific error code can be accessed using the GetLastResult() method.
195 virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
198 * Finalizes the multiple-part encryption or decryption operation.
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 Either of the following conditions has occurred:
208 * - A system error has occurred.
209 * - The method has failed to operate with the OpenSSL library.
210 * - The Tizen::Base::ByteBuffer operation has failed.
211 * @remarks The specific error code can be accessed using the GetLastResult() method.
213 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
220 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
221 * else @c null if an error occurs
222 * @param[in] secretKey The secret key to wrap
224 * - This operation is not supported in the %DesEdeCipher class.
225 * Therefore, this method always returns @c null.
226 * - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
228 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
231 * Unwraps a previously wrapped key.
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
239 * - This operation is not supported in the %DesEdeCipher class.
240 * Therefore, this method always returns @c null.
241 * - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
243 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
248 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
252 DesEdeCipher(const DesEdeCipher& rhs);
255 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
259 DesEdeCipher& operator =(const DesEdeCipher& rhs);
262 _SymmetricCipher* __pSymmetricCipher;
263 const evp_cipher_st* __pCipherAlgorithm;
264 Tizen::Base::String __cipherAlgorithm;
266 class _DesEdeCipherImpl* __pDesEdeCipherImpl;
267 friend class _DesEdeCipherImpl;
271 } } } //Tizen::Security::Crypto
273 #endif //_FSEC_CRYPTO_DES_EDE_CIPHER_H_