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 FSecCryptoSha2Hmac.h
19 * @brief This is the header file for the %Sha2Hmac class.
21 * This header file contains the declarations of the %Sha2Hmac class.
23 #ifndef _FSEC_CRYPTO_SHA2_HMAC_H_
24 #define _FSEC_CRYPTO_SHA2_HMAC_H_
26 #include <FSecCryptoIHmac.h>
31 namespace Tizen { namespace Security { namespace Crypto
36 * @brief This class implements the SHA-2 HMAC algorithm.
40 * The %Sha2Hmac class implements the SHA-2 HMAC algorithm. @n
42 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/hashing.htm">Hashing</a>.
44 * @see Tizen::Security::Crypto::IHmac
45 * @see Tizen::Security::Crypto::Md5Hmac
46 * @see Tizen::Security::Crypto::Sha1Hmac
48 class _OSP_EXPORT_ Sha2Hmac
49 : public virtual IHmac
50 , public Tizen::Base::Object
55 * This is the default constructor for this class.
62 * This destructor overrides Tizen::Base::Object::~Object().
66 virtual ~Sha2Hmac(void);
69 * Sets the HMAC algorithm.
73 * @return An error code
74 * @param[in] algorithm The HMAC algorithm name @n
75 * For example, "HMACSHA2/224", "HMACSHA2/256", "HMACSHA2/384", or "HMACSHA2/512".
76 * @exception E_SUCCESS The method is successful.
77 * @exception E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
79 virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
82 * Sets the secret key.
86 * @return An error code
87 * @param[in] key An instance of ISecretKey
88 * @exception E_SUCCESS The method is successful.
89 * @exception E_INVALID_ARG The specified @c key is invalid.
90 * @exception E_OUT_OF_MEMORY The memory is insufficient.
92 virtual result SetKey(const Tizen::Security::ISecretKey& key);
95 * Gets the HMAC for the specified input.
99 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
100 * else @c null if an error occurs
101 * @param[in] input An instance of Tizen::Base::ByteBuffer
102 * @exception E_SUCCESS The method is successful.
103 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
104 * @exception E_OUT_OF_MEMORY The memory is insufficient.
105 * @exception E_KEY_NOT_FOUND The specified key is not found.
106 * @exception E_SYSTEM Either of the following conditions has occurred:
107 * - A system error has occurred.
108 * - The method has failed to operate with the OpenSSL library.
109 * - The Tizen::Base::ByteBuffer operation has failed.
110 * @remarks The specific error code can be accessed using the GetLastResult() method.
112 virtual Tizen::Base::ByteBuffer* GetHmacN(const Tizen::Base::ByteBuffer& input) const;
115 * Initializes the multiple-part HMAC operation.
119 * @return An error code
120 * @exception E_SUCCESS The method is successful.
121 * @exception E_OUT_OF_MEMORY The memory is insufficient.
122 * @exception E_KEY_NOT_FOUND The specified key is not found.
123 * @exception E_SYSTEM A system error has occurred. @n
124 * The method has failed to operate with the OpenSSL library.
126 virtual result Initialize(void);
129 * Updates the multiple-part HMAC operation while processing another part of the data.
133 * @return An error code
134 * @param[in] input An instance of Tizen::Base::ByteBuffer
135 * @exception E_SUCCESS The method is successful.
136 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
137 * @exception E_OUT_OF_MEMORY The memory is insufficient.
138 * @exception E_SYSTEM Either of the following conditions has occurred:
139 * - A system error has occurred.
140 * - The method has failed to operate with the OpenSSL library.
141 * - The Tizen::Base::ByteBuffer operation has failed.
143 virtual result Update(const Tizen::Base::ByteBuffer& input);
146 * Finalizes the multiple-part HMAC operation.
150 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
151 * else @c null if an error occurs
152 * @exception E_SUCCESS The method is successful.
153 * @exception E_OUT_OF_MEMORY The memory is insufficient.
154 * @exception E_SYSTEM Either of the following conditions has occurred:
155 * - A system error has occurred.
156 * - The method has failed to operate with the OpenSSL library.
157 * - The Tizen::Base::ByteBuffer operation has failed.
158 * @remarks The specific error code can be accessed using the GetLastResult() method.
160 virtual Tizen::Base::ByteBuffer* FinalizeN(void);
165 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
169 Sha2Hmac(const Sha2Hmac& rhs);
172 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
176 Sha2Hmac& operator =(const Sha2Hmac& rhs);
179 hmac_ctx_st* __pSha2HmacCtx;
180 Tizen::Base::ByteBuffer __keyBytes;
181 const env_md_st* __pAlgorithm;
183 class _Sha2HmacImpl* __pSha2HmacImpl;
184 friend class _Sha2HmacImpl;
188 } } } //Tizen::Security:Crypto
190 #endif //_FSEC_CRYPTO_SHA2_HMAC_H_