2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FSecCryptoAesCipher.h
20 * @brief This is the header file for the %AesCipher class.
22 * This header file contains the declarations of the %AesCipher class.
24 #ifndef _FSEC_CRYPTO_AES_CIPHER_H_
25 #define _FSEC_CRYPTO_AES_CIPHER_H_
27 #include <FSecCryptoISymmetricCipher.h>
32 namespace Tizen { namespace Security { namespace Crypto
35 class _SymmetricCipher;
38 * @brief This class provides methods for encryption and decryption using the Advanced Encryption Standard (AES) method.
42 * The %AesCipher class provides a symmetric cipher using the Advanced Encryption Standard (AES) method.
43 * Set appropriate values for the requested mode/key bit/padding scheme and cipher operation mode (CIPHER_ENCRYPT, CIPHER_DECRYPT, 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. For full construction, @n
59 * 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 name of 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 A specified input parameter is invalid, or the specified @c opMode does not contain a valid 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.
88 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
91 * Sets a symmetric key for encryption or decryption.
95 * @return An error code
96 * @param[in] key An instance of ISecretKey
97 * @exception E_SUCCESS The method is successful.
98 * @exception E_INVALID_ARG The specified @c key is invalid.
99 * @exception E_OUT_OF_MEMORY The memory is insufficient.
101 virtual result SetKey(const Tizen::Security::ISecretKey& key);
104 * Sets the initial vector.
108 * @return An error code
109 * @param[in] initialVector The initial vector
110 * @exception E_SUCCESS The method is successful.
111 * @exception E_INVALID_ARG The specified input parameter is invalid.
112 * @exception E_OUT_OF_MEMORY The memory is insufficient.
114 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
117 * Encrypts the data (single-part).
121 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
122 * else @c null if an error occurs
123 * @param[in] input An instance of Tizen::Base::ByteBuffer
124 * @exception E_SUCCESS The method is successful.
125 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
126 * @exception E_OUT_OF_MEMORY The memory is insufficient.
127 * @exception E_KEY_NOT_FOUND The specified key is not found.
128 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
129 * @exception E_OVERFLOW This operation has caused the memory to overflow.
130 * @exception E_SYSTEM A system error has occurred. @n
131 * The method has failed to operate with the openssl library, or
132 * the Tizen::Base::ByteBuffer operation has failed.
133 * @remarks The specific error code can be accessed using the GetLastResult() method.
134 * @remarks A secret key and an initial vector are set before calling this method.
136 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
139 * Decrypts the data (single-part).
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 specified instance of Tizen::Base::ByteBuffer is invalid or empty.
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 * @remarks A secret key and an initial vector are set before calling this method.
158 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
161 * Initializes a multiple-part encryption or decryption operation.
165 * @return An error code
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_OUT_OF_MEMORY The memory is insufficient.
168 * @exception E_KEY_NOT_FOUND The specified key is not found.
169 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
170 * @exception E_SYSTEM A system error has occurred. @n
171 * The method has failed to operate with the openssl library.
173 virtual result Initialize(void);
176 * Updates a multiple-part encryption or decryption operation.
180 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
181 * else @c null if an error occurs
182 * @param[in] input An instance of Tizen::Base::ByteBuffer
183 * @exception E_SUCCESS The method is successful.
184 * @exception E_OUT_OF_MEMORY The memory is insufficient.
185 * @exception E_OVERFLOW This operation has caused the memory to overflow.
186 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
187 * @exception E_SYSTEM A system error has occurred. @n
188 * The method has failed to operate with the openssl library, or
189 * the Tizen::Base::ByteBuffer operation has failed.
190 * @remarks The specific error code can be accessed using the GetLastResult() method.
192 virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
195 * Finalizes a multiple-part encryption or decryption operation.
199 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
200 * else @c null if an error occurs
201 * @exception E_SUCCESS The method is successful.
202 * @exception E_OUT_OF_MEMORY The memory is insufficient.
203 * @exception E_OVERFLOW This operation has caused the memory to overflow.
204 * @exception E_SYSTEM A system error has occurred. @n
205 * The method has failed to operate with the openssl library, or
206 * the Tizen::Base::ByteBuffer operation has failed.
207 * @remarks The specific error code can be accessed using the GetLastResult() method.
209 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
216 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
217 * else @c null if an error occurs
218 * @param[in] secretKey The secret key to wrap
219 * @exception E_SUCCESS The method is successful.
220 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
221 * @exception E_OUT_OF_MEMORY The memory is insufficient.
222 * @exception E_KEY_NOT_FOUND The specified key is not found.
223 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
224 * @exception E_UNSUPPORTED_ALGORITHM The specified cipher algorithm for this method is invalid.
225 * @exception E_SYSTEM A system error has occurred. @n
226 * The method has failed to operate with the openssl library.
227 * @remarks The specific error code can be accessed using the GetLastResult() method.
228 * @remarks A key is set using SetKey() before calling this method.
230 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
233 * Unwraps a previously wrapped key.
237 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
238 * else @c null if an error occurs
239 * @param[in] wrappedKey The wrapped key to unwrap
240 * @exception E_SUCCESS The method is successful.
241 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid.
242 * @exception E_OUT_OF_MEMORY The memory is insufficient.
243 * @exception E_KEY_NOT_FOUND The specified key is not found.
244 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
245 * @exception E_UNSUPPORTED_ALGORITHM The specified cipher algorithm for this method is invalid.
246 * @exception E_SYSTEM A system error has occurred. @n
247 * The method has failed to operate with the openssl library.
248 * @remarks The specific error code can be accessed using the GetLastResult() method.
249 * @remarks A key is set using SetKey() before calling this method.
251 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
256 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
260 AesCipher(const AesCipher& rhs);
263 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
267 AesCipher& operator =(const AesCipher& rhs);
270 _SymmetricCipher* __pSymmetricCipher;
271 const evp_cipher_st* __pCipherAlgorithm;
272 Tizen::Base::String __cipherAlgorithm;
274 class _AesCipherImpl* __pAesCipherImpl;
275 friend class _AesCipherImpl;
279 } } } //Tizen::Security:Crypto
281 #endif //_FSEC_CRYPTO_AES_CIPHER_H_