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 FSecCryptoRc2Cipher.h
19 * @brief This is the header file for the %Rc2Cipher class.
21 * This header file contains the declarations of the %Rc2Cipher class.
23 #ifndef _FSEC_CRYPTO_RC2_CIPHER_H_
24 #define _FSEC_CRYPTO_RC2_CIPHER_H_
26 #include <FSecCryptoISymmetricCipher.h>
30 namespace Tizen { namespace Security { namespace Crypto
33 class _SymmetricCipher;
36 * @brief This class provides methods for encryption and decryption using the RC2 algorithm.
40 * The %Rc2Cipher class provides a symmetric cipher using the RC2 algorithm.
41 * It sets appropriate values for the requested mode/key bit/padding scheme and cipher operation (CIPHER_ENCRYPT or CIPHER_DECRYPT) parameters. @n
43 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/ciphers.htm">Ciphers</a>.
45 * @see ISymmetricCipher
49 class _OSP_EXPORT_ Rc2Cipher
50 : public virtual ISymmetricCipher
51 , public Tizen::Base::Object
56 * The object is not fully constructed after this constructor is called. For full construction, @n
57 * the Construct() method must be called right after calling this constructor.
64 * This destructor overrides Tizen::Base::Object::~Object().
68 virtual ~Rc2Cipher(void);
71 * Constructs and initializes this instance of %Rc2Cipher with the specified parameters.
75 * @return An error code
76 * @param[in] transformation The name of the requested mode/padding scheme @n
77 * The RC2 support variable length key ranges from 8 bits to 128 bits, in steps of 8 bits.
78 * The key bits are not required to be mentioned in the transformation.
79 * There are four valid transformations for RC2, "CBC/NOPADDING",
80 * "CBC/PKCS7PADDING", "ECB/PKCS7PADDING", and "ECB/NOPADDING".
81 * @param[in] opMode The cipher operation mode @n
82 * The valid values for %Rc2Cipher are @c CIPHER_ENCRYPT and @c CIPHER_DECRYPT.
83 * @exception E_SUCCESS The method is successful.
84 * @exception E_OUT_OF_MEMORY The memory is insufficient.
85 * @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.
86 * @remarks If @c opMode is not matching the actual operation, the result of the operation is @c null and an exception is returned. @n
87 * 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.
89 virtual result Construct(const Tizen::Base::String& transformation, enum CipherOperation opMode);
92 * Sets a symmetric key for encryption or decryption. @n
93 * The variable length key ranges from 8 bits to 128 bits, in steps of 8 bits.
97 * @return An error code
98 * @param[in] key An instance of ISecretKey
99 * @exception E_SUCCESS The method is successful.
100 * @exception E_INVALID_ARG The specified @c key is invalid.
101 * @exception E_OUT_OF_MEMORY The memory is insufficient.
103 virtual result SetKey(const Tizen::Security::ISecretKey& key);
106 * Sets the initial vector.
110 * @return An error code
111 * @param[in] initialVector The initial vector
112 * @exception E_SUCCESS The method is successful.
113 * @exception E_INVALID_ARG The specified input parameter is invalid.
114 * @exception E_OUT_OF_MEMORY The memory is insufficient.
116 virtual result SetInitialVector(const Tizen::Base::ByteBuffer& initialVector);
119 * Encrypts the data (single-part).
123 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
124 * else @c null if an error occurs
125 * @param[in] input An instance of Tizen::Base::ByteBuffer
126 * @exception E_SUCCESS The method is successful.
127 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
128 * @exception E_OUT_OF_MEMORY The memory is insufficient.
129 * @exception E_KEY_NOT_FOUND The specified key is not found.
130 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
131 * @exception E_OVERFLOW This operation has caused the memory to overflow.
132 * @exception E_SYSTEM A system error has occurred. @n
133 * The method has failed to operate with the OpenSSL library, or
134 * the Tizen::Base::ByteBuffer operation has failed.
135 * @remarks The specific error code can be accessed using the GetLastResult() method.
136 * @remarks A secret key and an initial vector are set before calling this method.
138 virtual Tizen::Base::ByteBuffer* EncryptN(const Tizen::Base::ByteBuffer& input);
141 * Decrypts the data (single-part).
145 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
146 * else @c null if an error occurs
147 * @param[in] input An instance of Tizen::Base::ByteBuffer
148 * @exception E_SUCCESS The method is successful.
149 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
150 * @exception E_OUT_OF_MEMORY The memory is insufficient.
151 * @exception E_KEY_NOT_FOUND The specified key is not found.
152 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
153 * @exception E_OVERFLOW This operation has caused the memory to overflow.
154 * @exception E_SYSTEM A system error has occurred. @n
155 * The method has failed to operate with the OpenSSL library, or
156 * the Tizen::Base::ByteBuffer operation has failed.
157 * @remarks The specific error code can be accessed using the GetLastResult() method.
158 * @remarks A secret key and an initial vector are set before calling this method.
160 virtual Tizen::Base::ByteBuffer* DecryptN(const Tizen::Base::ByteBuffer& input);
163 * Initializes a multiple-part encryption or decryption operation.
167 * @return An error code
168 * @exception E_SUCCESS The method is successful.
169 * @exception E_OUT_OF_MEMORY The memory is insufficient.
170 * @exception E_KEY_NOT_FOUND The specified key is not found.
171 * @exception E_INVALID_OPERATION The specified cipher operation mode for this method is invalid.
172 * @exception E_SYSTEM A system error has occurred. @n
173 * The method has failed to operate with the OpenSSL library.
174 * @remarks A secret key and an initial vector are set before calling this method.
176 virtual result Initialize(void);
179 * Updates a multiple-part encryption or decryption operation.
183 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
184 * else @c null if an error occurs
185 * @param[in] input An instance of Tizen::Base::ByteBuffer
186 * @exception E_SUCCESS The method is successful.
187 * @exception E_OUT_OF_MEMORY The memory is insufficient.
188 * @exception E_OVERFLOW This operation has caused the memory to overflow.
189 * @exception E_INVALID_ARG The specified instance of Tizen::Base::ByteBuffer is invalid or empty.
190 * @exception E_SYSTEM A system error has occurred. @n
191 * The method has failed to operate with the OpenSSL library, or
192 * the Tizen::Base::ByteBuffer operation has failed.
193 * @remarks The specific error code can be accessed using the GetLastResult() method.
195 virtual Tizen::Base::ByteBuffer* UpdateN(const Tizen::Base::ByteBuffer& input);
198 * Finalizes a 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 A system error has occurred. @n
208 * The method has failed to operate with the OpenSSL library, or
209 * the Tizen::Base::ByteBuffer operation has failed.
210 * @remarks The specific error code can be accessed using the GetLastResult() method.
212 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
219 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
220 * else @c null if an error occurs
221 * @param[in] secretKey The secret key to wrap
222 * @remarks This operation is not supported in the %Rc2Cipher class.
223 * Therefore, this method always returns @c null.
224 * @remarks The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
226 virtual Tizen::Base::ByteBuffer* WrapN(const Tizen::Base::ByteBuffer& secretKey);
229 * Unwraps a previously wrapped key.
233 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
234 * else @c null if an error occurs
235 * @param[in] wrappedKey The wrapped key to unwrap
236 * @remarks This operation is not supported in the %Rc2Cipher class.
237 * Therefore, this method always returns @c null.
238 * @remarks The @c E_UNSUPPORTED_ALGORITHM exception is returned using the GetLastResult() method.
240 virtual Tizen::Base::ByteBuffer* UnwrapN(const Tizen::Base::ByteBuffer& wrappedKey);
245 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
249 Rc2Cipher(const Rc2Cipher& rhs);
252 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
256 Rc2Cipher& operator =(const Rc2Cipher& rhs);
259 _SymmetricCipher* __pSymmetricCipher;
260 const evp_cipher_st* __pCipherAlgorithm;
261 Tizen::Base::String __cipherAlgorithm;
263 class _Rc2CipherImpl* __pRc2CipherImpl;
264 friend class _Rc2CipherImpl;
268 } } } //Tizen::Security::Crypto
270 #endif //_FSEC_CRYPTO_RC2_CIPHER_H_