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 * Sets 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 name of 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 A specified input parameter is invalid, or the specified @c opMode does not contain a valid value for the cipher operation.
84 * @remarks If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
85 * 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 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
89 * Sets a symmetric key for encryption or decryption.
93 * @return An error code
94 * @param[in] key An instance of ISecretKey
95 * @exception E_SUCCESS The method is successful.
96 * @exception E_INVALID_ARG The specified @c key is invalid.
97 * @exception E_OUT_OF_MEMORY The memory is insufficient.
99 virtual result SetKey(const Tizen::Security::ISecretKey& key);
102 * Sets the initial vector.
106 * @return An error code
107 * @param[in] initialVector The initial vector
108 * @exception E_SUCCESS The method is successful.
109 * @exception E_INVALID_ARG The specified input parameter is invalid.
110 * @exception E_OUT_OF_MEMORY The memory is insufficient.
112 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
115 * Encrypts the data (single-part).
118 * @pre Before calling this method, a secret key and an initial vector should be set using SetKey() and SetInitialVector().
119 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
120 * else @c null if an error occurs
121 * @param[in] input An instance of Tizen::Base::ByteBuffer
122 * @exception E_SUCCESS The method is successful.
123 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
124 * @exception E_OUT_OF_MEMORY The memory is insufficient.
125 * @exception E_KEY_NOT_FOUND The specified key is not found.
126 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
127 * @exception E_OVERFLOW This operation has caused the memory to overflow.
128 * @exception E_SYSTEM A system error has occurred. @n
129 * The method has failed to operate with the openssl library, or
130 * the Tizen::Base::ByteBuffer operation has failed.
131 * @remarks The specific error code can be accessed using the GetLastResult() method.
133 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
136 * Decrypts the data (single-part).
139 * @pre Before calling this method, a secret key and an initial vector should be set using SetKey() and SetInitialVector().
140 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
141 * else @c null if an error occurs
142 * @param[in] input An instance of Tizen::Base::ByteBuffer
143 * @exception E_SUCCESS The method is successful.
144 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
145 * @exception E_OUT_OF_MEMORY The memory is insufficient.
146 * @exception E_KEY_NOT_FOUND The specified key is not found.
147 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
148 * @exception E_OVERFLOW This operation has caused the memory to overflow.
149 * @exception E_SYSTEM A system error has occurred. @n
150 * The method has failed to operate with the openssl library, or
151 * the Tizen::Base::ByteBuffer operation has failed.
152 * @remarks The specific error code can be accessed using the GetLastResult() method.
154 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
157 * Initializes a multiple-part encryption or decryption operation.
160 * @pre Before calling this method, a secret key and an initial vector should be set using SetKey() and SetInitialVector().
161 * @return An error code
162 * @exception E_SUCCESS The method is successful.
163 * @exception E_OUT_OF_MEMORY The memory is insufficient.
164 * @exception E_KEY_NOT_FOUND The specified key is not found.
165 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
166 * @exception E_SYSTEM A system error has occurred. @n
167 * The method has failed to operate with the openssl library.
169 virtual result Initialize(void);
172 * Updates a multiple-part encryption or decryption operation.
176 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
177 * else @c null if an error occurs
178 * @param[in] input An instance of Tizen::Base::ByteBuffer
179 * @exception E_SUCCESS The method is successful.
180 * @exception E_OUT_OF_MEMORY The memory is insufficient.
181 * @exception E_OVERFLOW This operation has caused the memory to overflow.
182 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
183 * @exception E_SYSTEM A system error has occurred. @n
184 * The method has failed to operate with the openssl library, or
185 * the Tizen::Base::ByteBuffer operation has failed.
186 * @remarks The specific error code can be accessed using the GetLastResult() method.
188 virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
191 * Finalizes a multiple-part encryption or decryption operation.
195 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
196 * else @c null if an error occurs
197 * @exception E_SUCCESS The method is successful.
198 * @exception E_OUT_OF_MEMORY The memory is insufficient.
199 * @exception E_OVERFLOW This operation has caused the memory to overflow.
200 * @exception E_SYSTEM A system error has occurred. @n
201 * The method has failed to operate with the openssl library, or
202 * the Tizen::Base::ByteBuffer operation has failed.
203 * @remarks The specific error code can be accessed using the GetLastResult() method.
205 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
212 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
213 * else @c null if an error occurs
214 * @param[in] secretKey The secret key to wrap
216 * - This operation is not supported in the %DesEdeCipher class.
217 * Therefore, this method always returns @c null.
218 * - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
220 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
223 * Unwraps a previously wrapped key.
227 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
228 * else @c null if an error occurs
229 * @param[in] wrappedKey The wrapped key to unwrap
231 * - This operation is not supported in the %DesEdeCipher class.
232 * Therefore, this method always returns @c null.
233 * - The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
235 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
240 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
244 DesEdeCipher(const DesEdeCipher& rhs);
247 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
251 DesEdeCipher& operator =(const DesEdeCipher& rhs);
254 _SymmetricCipher* __pSymmetricCipher;
255 const evp_cipher_st* __pCipherAlgorithm;
256 Tizen::Base::String __cipherAlgorithm;
258 class _DesEdeCipherImpl* __pDesEdeCipherImpl;
259 friend class _DesEdeCipherImpl;
263 } } } //Tizen::Security::Crypto
265 #endif //_FSEC_CRYPTO_DES_EDE_CIPHER_H_