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 FSecCryptoRc4Cipher.h
19 * @brief This is the header file for the %Rc4Cipher class.
21 * This header file contains the declarations of the %Rc4Cipher class.
23 #ifndef _FSEC_CRYPTO_RC4_CIPHER_H_
24 #define _FSEC_CRYPTO_RC4_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 operations using the RC4 algorithm.
41 * The %Rc4Cipher class provides a symmetric cipher using the RC4 algorithm. @n
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_ Rc4Cipher
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 ~Rc4Cipher(void);
72 * Constructs and initializes an instance of %Rc4Cipher with the specified parameters.
76 * @return An error code
77 * @param[in] transformation The only valid value for %Rc4Cipher for transformation is "NONE"
78 * @param[in] opMode The cipher operation mode @n
79 * The valid values for %Rc4Cipher are @c CIPHER_ENCRYPT and @c CIPHER_DECRYPT.
80 * @exception E_SUCCESS The method is successful.
81 * @exception E_OUT_OF_MEMORY The memory is insufficient.
82 * @exception E_INVALID_ARG A specified input parameter is invalid.
83 * @remarks If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
84 * For example, if @c opMode is set to @c CIPHER_ENCRYPT, @c CIPHER_WRAP, or @c CIPHER_UNWRAP and the DecryptN()
85 * 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);
90 * Sets the symmetric key for encryption or decryption operation. @n
91 * The variable length key ranges from 40 bits to 256 bits, in steps of 8 bits.
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).
120 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
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 Tizen::Base::ByteBuffer instance 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 Either of the following conditions has occurred:
131 * - A system error has occurred.
132 * - The method has failed to operate with the OpenSSL library.
133 * - The Tizen::Base::ByteBuffer operation has failed.
134 * @remarks The specific error code can be accessed using the GetLastResult() method.
136 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
139 * Decrypts the data (single-part).
142 * @pre Before calling this method, set a secret key and an initial vector 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 specified Tizen::Base::ByteBuffer instance 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 Either of the following conditions has occurred:
153 * - A system error has occurred.
154 * - The method has failed to operate with the OpenSSL library.
155 * - The Tizen::Base::ByteBuffer operation has failed.
156 * @remarks The specific error code can be accessed using the GetLastResult() method.
158 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
161 * Initializes the instance of %Rc4Cipher for the multiple-part encryption or decryption.
164 * @pre Before calling this method, set a secret key and an initial vector using SetKey() and SetInitialVector().
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 Either of the following conditions has occurred:
171 * - A system error has occurred.
172 * - The method has failed to operate with the OpenSSL library.
174 virtual result Initialize(void);
177 * Updates the multiple-part encryption or decryption operation.
181 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
182 * else @c null if an error occurs
183 * @param[in] input An instance of Tizen::Base::ByteBuffer
184 * @exception E_SUCCESS The method is successful.
185 * @exception E_OUT_OF_MEMORY The memory is insufficient.
186 * @exception E_OVERFLOW This operation has caused the memory to overflow.
187 * @exception E_INVALID_ARG The specified Tizen::Base::ByteBuffer instance is invalid or empty.
188 * @exception E_SYSTEM Either of the following conditions has occurred:
189 * - A system error has occurred.
190 * - The method has failed to operate with the OpenSSL library.
191 * - The Tizen::Base::ByteBuffer operation has failed.
192 * @remarks The specific error code can be accessed using the GetLastResult() method.
194 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 This operation is not required for RC4. Always return @c null if this method is called.
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 %Rc4Cipher class.
225 * Therefore, this method always returns @c null.
226 * - The @c E_UNSUPPORTED_ALGORITHM 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 %Rc4Cipher class.
240 * Therefore, this method always returns @c null.
241 * - The @c E_UNSUPPORTED_ALGORITHM 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 Rc4Cipher(const Rc4Cipher& rhs);
255 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
259 Rc4Cipher& operator =(const Rc4Cipher& rhs);
262 _SymmetricCipher* __pSymmetricCipher;
263 const evp_cipher_st* __pCipherAlgorithm;
264 Tizen::Base::String __cipherAlgorithm;
266 class _Rc4CipherImpl* __pRc4CipherImpl;
267 friend class _Rc4CipherImpl;
271 } } } // Tizen::Security::Crypto
273 #endif // _FSEC_CRYPTO_RC4_CIPHER_H_