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.
42 * It 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_ 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() method is used, then the result obtained is @c null and an exception is returned.
86 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
89 * Sets a symmetric key for encryption or decryption operation. @n
90 * The variable length key ranges from 40 bits to 256 bits, in steps of 8 bits.
94 * @return An error code
95 * @param[in] key An instance of ISecretKey
96 * @exception E_SUCCESS The method is successful.
97 * @exception E_INVALID_ARG The specified @c key is invalid.
98 * @exception E_OUT_OF_MEMORY The memory is insufficient.
100 virtual result SetKey(const Tizen::Security::ISecretKey& key);
103 * Sets the initial vector.
107 * @return An error code
108 * @param[in] initialVector The initial vector
109 * @exception E_SUCCESS The method is successful.
110 * @exception E_INVALID_ARG The specified input parameter is invalid.
111 * @exception E_OUT_OF_MEMORY The memory is insufficient.
113 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
116 * Encrypts the data (single-part).
120 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
121 * else @c null if an error occurs
122 * @param[in] input An instance of Tizen::Base::ByteBuffer
123 * @exception E_SUCCESS The method is successful.
124 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
125 * @exception E_OUT_OF_MEMORY The memory is insufficient.
126 * @exception E_KEY_NOT_FOUND The specified key is not found.
127 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
128 * @exception E_OVERFLOW This operation has caused the memory to overflow.
129 * @exception E_SYSTEM A system error has occurred. @n
130 * The method has failed to operate with the OpenSSL library, or
131 * the Tizen::Base::ByteBuffer operation has failed.
132 * @remarks The specific error code can be accessed using the GetLastResult() method.
133 * @remarks A secret key and an initial vector are set before calling this method.
135 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
138 * Decrypts the data (single-part).
142 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
143 * else @c null if an error occurs
144 * @param[in] input An instance of Tizen::Base::ByteBuffer
145 * @exception E_SUCCESS The method is successful.
146 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
147 * @exception E_OUT_OF_MEMORY The memory is insufficient.
148 * @exception E_KEY_NOT_FOUND The specified key is not found.
149 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
150 * @exception E_OVERFLOW This operation has caused the memory to overflow.
151 * @exception E_SYSTEM A system error has occurred. @n
152 * The method has failed to operate with the OpenSSL library, or
153 * the Tizen::Base::ByteBuffer operation has failed.
154 * @remarks The specific error code can be accessed using the GetLastResult() method.
155 * @remarks A secret key and an initial vector are set before calling this method.
157 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
160 * Initializes a multiple-part encryption or decryption operation.
164 * @return An error code
165 * @exception E_SUCCESS The method is successful.
166 * @exception E_OUT_OF_MEMORY The memory is insufficient.
167 * @exception E_KEY_NOT_FOUND The specified key is not found.
168 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
169 * @exception E_SYSTEM A system error has occurred. @n
170 * The method has failed to operate with the OpenSSL library.
171 * @remarks A secret key and an initial vector are set before calling this method.
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);
196 * Finalizes a multiple-part encryption or decryption operation.
200 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
201 * else @c null if an error occurs
202 * @exception E_SUCCESS The method is successful.
203 * @exception E_OUT_OF_MEMORY The memory is insufficient.
204 * @exception E_OVERFLOW This operation has caused the memory to overflow.
205 * @exception E_SYSTEM A system error has occurred. @n
206 * The method has failed to operate with the OpenSSL library, or
207 * the Tizen::Base::ByteBuffer operation has failed.
208 * @remarks This operation is not required for RC4. Always return @c null if this method is called.
210 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
217 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
218 * else @c null if an error occurs
219 * @param[in] secretKey The secret key to wrap
220 * @remarks This operation is not supported in the %Rc4Cipher class.
221 * Therefore, this method always returns @c null.
222 * @remarks The @c E_UNSUPPORTED_ALGORITHM is returned using the GetLastResult() method.
224 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
227 * Unwraps a previously wrapped key.
231 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
232 * else @c null if an error occurs
233 * @param[in] wrappedKey The wrapped key to unwrap
234 * @remarks This operation is not supported in the %Rc4Cipher class.
235 * Therefore, this method always returns @c null.
236 * @remarks The @c E_UNSUPPORTED_ALGORITHM is returned using the GetLastResult() method.
238 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
243 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
247 Rc4Cipher(const Rc4Cipher& rhs);
250 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
254 Rc4Cipher& operator =(const Rc4Cipher& rhs);
257 _SymmetricCipher* __pSymmetricCipher;
258 const evp_cipher_st* __pCipherAlgorithm;
259 Tizen::Base::String __cipherAlgorithm;
261 class _Rc4CipherImpl* __pRc4CipherImpl;
262 friend class _Rc4CipherImpl;
266 } } } // Tizen::Security::Crypto
268 #endif // _FSEC_CRYPTO_RC4_CIPHER_H_