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 FSecCryptoSha2Hmac.h
20 * @brief This is the header file for the %Sha2Hmac class.
22 * This header file contains the declarations of the %Sha2Hmac class.
24 #ifndef _FSEC_CRYPTO_SHA2_HMAC_H_
25 #define _FSEC_CRYPTO_SHA2_HMAC_H_
27 #include <FSecCryptoIHmac.h>
32 namespace Tizen { namespace Security { namespace Crypto
37 * @brief This class implements the SHA-2 HMAC algorithm.
41 * The %Sha2Hmac class implements the SHA-2 HMAC algorithm. @n
43 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/hashing.htm">Hashing</a>.
45 * @see Tizen::Security::Crypto::IHmac
46 * @see Tizen::Security::Crypto::Md5Hmac
47 * @see Tizen::Security::Crypto::Sha1Hmac
49 class _OSP_EXPORT_ Sha2Hmac
50 : public virtual IHmac
51 , public Tizen::Base::Object
56 * This is the default constructor for this class.
63 * This destructor overrides Tizen::Base::Object::~Object().
67 virtual ~Sha2Hmac(void);
70 * Sets the HMAC algorithm.
74 * @return An error code
75 * @param[in] algorithm The name of the HMAC algorithm @n
76 * For example, "HMACSHA2/224", "HMACSHA2/256", "HMACSHA2/384", or "HMACSHA2/512".
77 * @exception E_SUCCESS The method is successful.
78 * @exception E_UNSUPPORTED_ALGORITHM The algorithm is not supported.
80 virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
83 * Sets the secret key.
87 * @return An error code
88 * @param[in] key An instance of ISecretKey
89 * @exception E_SUCCESS The method is successful.
90 * @exception E_INVALID_ARG The specified @c key is invalid.
91 * @exception E_OUT_OF_MEMORY The memory is insufficient.
93 virtual result SetKey(const Tizen::Security::ISecretKey& key);
96 * Gets the HMAC with the given input.
100 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
101 * else @c null if an error occurs
102 * @param[in] input An instance of Tizen::Base::ByteBuffer
103 * @exception E_SUCCESS The method is successful.
104 * @exception E_INVALID_ARG The input Tizen::Base::ByteBuffer is empty or contains invalid data.
105 * @exception E_OUT_OF_MEMORY The memory is insufficient.
106 * @exception E_KEY_NOT_FOUND The specified key is not found.
107 * @exception E_SYSTEM A system error has occurred. @n
108 * The method has failed to operate with the OpenSSL library, or
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 a 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 a 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 A system error has occurred. @n
139 * The method has failed to operate with the OpenSSL library, or
140 * the Tizen::Base::ByteBuffer operation has failed.
142 virtual result Update(const Tizen::Base::ByteBuffer& input);
145 * Finalizes a multiple-part HMAC operation.
149 * @return A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
150 * else @c null if an error occurs
151 * @exception E_SUCCESS The method is successful.
152 * @exception E_OUT_OF_MEMORY The memory is insufficient.
153 * @exception E_SYSTEM A system error has occurred. @n
154 * The method has failed to operate with the OpenSSL library, or
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* FinalizeN(void);
163 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
167 Sha2Hmac(const Sha2Hmac& rhs);
170 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
174 Sha2Hmac& operator =(const Sha2Hmac& rhs);
177 hmac_ctx_st* __pSha2HmacCtx;
178 Tizen::Base::ByteBuffer __keyBytes;
179 const env_md_st* __pAlgorithm;
181 class _Sha2HmacImpl* __pSha2HmacImpl;
182 friend class _Sha2HmacImpl;
186 } } } //Tizen::Security:Crypto
188 #endif //_FSEC_CRYPTO_SHA2_HMAC_H_