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 FSecCryptoAesCipher.h
19 * @brief This is the header file for the %AesCipher class.
21 * This header file contains the declarations of the %AesCipher class.
23 #ifndef _FSEC_CRYPTO_AES_CIPHER_H_
24 #define _FSEC_CRYPTO_AES_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 Advanced Encryption Standard (AES) method.
41 * The %AesCipher class provides a symmetric cipher using the Advanced Encryption Standard (AES) method.
42 * This class allows to set appropriate values for the requested mode/key bit/padding scheme and cipher operation mode (::CIPHER_ENCRYPT, ::CIPHER_DECRYPT,
43 * ::CIPHER_WRAP, or ::CIPHER_UNWRAP) parameters. @n
45 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
47 * @see ISymmetricCipher
51 class _OSP_EXPORT_ AesCipher
52 : public virtual ISymmetricCipher
53 , public Tizen::Base::Object
58 * The object is not fully constructed after this constructor is called. @n
59 * For full construction, the Construct() method must be called right after calling this constructor.
66 * This destructor overrides Tizen::Base::Object::~Object().
70 virtual ~AesCipher(void);
73 * Initializes this instance of %AesCipher with the specified parameters.
77 * @return An error code
78 * @param[in] transformation The requested mode/key bit/padding scheme @n
79 * For example, "CBC/128/NOPADDING" or "CBC/192/NOPADDING".
80 * @param[in] opMode The cipher operation mode @n
81 * For example, @c CIPHER_ENCRYPT, @c CIPHER_DECRYPT, @c CIPHER_WRAP, or @c CIPHER_UNWRAP.
82 * @exception E_SUCCESS The method is successful.
83 * @exception E_OUT_OF_MEMORY The memory is insufficient.
84 * @exception E_INVALID_ARG Either of the following conditions has occurred:
85 * - A specified input parameter is invalid.
86 * - The specified @c opMode does not contain a valid value for the cipher operation.
87 * @remarks If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
88 * For example, if @c opMode is set to @c CIPHER_ENCRYPT, @c CIPHER_WRAP, or @c CIPHER_UNWRAP and the DecryptN()
89 * method is used, then the result obtained is @c null and an exception is returned.
91 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
94 * Sets the symmetric key for encryption or decryption.
98 * @return An error code
99 * @param[in] key An instance of ISecretKey
100 * @exception E_SUCCESS The method is successful.
101 * @exception E_INVALID_ARG The specified @c key is invalid.
102 * @exception E_OUT_OF_MEMORY The memory is insufficient.
104 virtual result SetKey(const Tizen::Security::ISecretKey& key);
107 * Sets the specified initial vector.
111 * @return An error code
112 * @param[in] initialVector The initial vector
113 * @exception E_SUCCESS The method is successful.
114 * @exception E_INVALID_ARG The specified input parameter is invalid.
115 * @exception E_OUT_OF_MEMORY The memory is insufficient.
117 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
120 * Encrypts the specified data (single-part).
123 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
125 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
126 * else @c null if an error occurs
127 * @param[in] input An instance of Tizen::Base::ByteBuffer
128 * @exception E_SUCCESS The method is successful.
129 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
130 * @exception E_OUT_OF_MEMORY The memory is insufficient.
131 * @exception E_KEY_NOT_FOUND The specified key is not found.
132 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
133 * @exception E_OVERFLOW This operation has caused the memory to overflow.
134 * @exception E_SYSTEM Either of the following conditions has occurred:
135 * - A system error has occurred.
136 * - The method has failed to operate with the openssl library.
137 * - The Tizen::Base::ByteBuffer operation has failed.
138 * @remarks The specific error code can be accessed using the GetLastResult() method.
140 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
143 * Decrypts the data (single-part).
146 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
147 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
148 * else @c null if an error occurs
149 * @param[in] input An instance of Tizen::Base::ByteBuffer
150 * @exception E_SUCCESS The method is successful.
151 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
152 * @exception E_OUT_OF_MEMORY The memory is insufficient.
153 * @exception E_KEY_NOT_FOUND The specified key is not found.
154 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
155 * @exception E_OVERFLOW This operation has caused the memory to overflow.
156 * @exception E_SYSTEM Either of the following conditions has occurred:
157 * - A system error has occurred.
158 * - The method has failed to operate with the openssl library.
159 * - The Tizen::Base::ByteBuffer operation has failed.
160 * @remarks The specific error code can be accessed using the GetLastResult() method.
162 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
165 * Initializes the instance of %AesCipher for the multiple-part encryption or decryption.
169 * @return An error code
170 * @exception E_SUCCESS The method is successful.
171 * @exception E_OUT_OF_MEMORY The memory is insufficient.
172 * @exception E_KEY_NOT_FOUND The specified key is not found.
173 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
174 * @exception E_SYSTEM Either of the following conditions has occurred:
175 * - A system error has occurred.
176 * - The method has failed to operate with the openssl library.
178 virtual result Initialize(void);
181 * Updates the multiple-part encryption or decryption operation.
185 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
186 * else @c null if an error occurs
187 * @param[in] input An instance of Tizen::Base::ByteBuffer
188 * @exception E_SUCCESS The method is successful.
189 * @exception E_OUT_OF_MEMORY The memory is insufficient.
190 * @exception E_OVERFLOW This operation has caused the memory to overflow.
191 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
192 * @exception E_SYSTEM Either of the following conditions has occurred:
193 * - A system error has occurred.
194 * - The method has failed to operate with the openssl library.
195 * - The Tizen::Base::ByteBuffer operation has failed.
196 * @remarks The specific error code can be accessed using the GetLastResult() method.
198 virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
201 * Finalizes the multiple-part encryption or decryption operation.
205 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
206 * else @c null if an error occurs
207 * @exception E_SUCCESS The method is successful.
208 * @exception E_OUT_OF_MEMORY The memory is insufficient.
209 * @exception E_OVERFLOW This operation has caused the memory to overflow.
210 * @exception E_SYSTEM Either of the following conditions has occurred:
211 * - A system error has occurred.
212 * - The method has failed to operate with the openssl library.
213 * - The Tizen::Base::ByteBuffer operation has failed.
214 * @remarks The specific error code can be accessed using the GetLastResult() method.
216 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
222 * @pre Before calling this method, set a secret key using SetKey().
223 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
224 * else @c null if an error occurs
225 * @param[in] secretKey The secret key to wrap
226 * @exception E_SUCCESS The method is successful.
227 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
228 * @exception E_OUT_OF_MEMORY The memory is insufficient.
229 * @exception E_KEY_NOT_FOUND The specified key is not found.
230 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
231 * @exception E_UNSUPPORTED_ALGORITHM The specified cipher algorithm for this method is invalid.
232 * @exception E_SYSTEM Either of the following conditions has occurred:
233 * - A system error has occurred.
234 * - The method has failed to operate with the openssl library.
235 * @remarks The specific error code can be accessed using the GetLastResult() method.
237 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
240 * Unwraps a previously wrapped key.
243 * @pre Before calling this method, set a secret key using SetKey().
244 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
245 * else @c null if an error occurs
246 * @param[in] wrappedKey The wrapped key to unwrap
247 * @exception E_SUCCESS The method is successful.
248 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid.
249 * @exception E_OUT_OF_MEMORY The memory is insufficient.
250 * @exception E_KEY_NOT_FOUND The specified key is not found.
251 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
252 * @exception E_UNSUPPORTED_ALGORITHM The specified cipher algorithm for this method is invalid.
253 * @exception E_SYSTEM Either of the following conditions has occurred:
254 * - A system error has occurred.
255 * - The method has failed to operate with the openssl library.
256 * @remarks The specific error code can be accessed using the GetLastResult() method.
258 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
263 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
267 AesCipher(const AesCipher& rhs);
270 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
274 AesCipher& operator =(const AesCipher& rhs);
277 _SymmetricCipher* __pSymmetricCipher;
278 const evp_cipher_st* __pCipherAlgorithm;
279 Tizen::Base::String __cipherAlgorithm;
281 class _AesCipherImpl* __pAesCipherImpl;
282 friend class _AesCipherImpl;
286 } } } //Tizen::Security:Crypto
288 #endif //_FSEC_CRYPTO_AES_CIPHER_H_