Beautified source code of appfw/inc
[platform/framework/native/appfw.git] / inc / FSecCryptoSha2Hmac.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FSecCryptoSha2Hmac.h
19  * @brief       This is the header file for the %Sha2Hmac class.
20  *
21  * This header file contains the declarations of the %Sha2Hmac class.
22  */
23 #ifndef _FSEC_CRYPTO_SHA2_HMAC_H_
24 #define _FSEC_CRYPTO_SHA2_HMAC_H_
25
26 #include <FSecCryptoIHmac.h>
27
28 struct env_md_st;
29 struct hmac_ctx_st;
30
31 namespace Tizen { namespace Security { namespace Crypto
32 {
33
34 /**
35  *      @class  Sha2Hmac
36  *      @brief  This class implements the SHA-2 HMAC algorithm.
37  *
38  *      @since  2.0
39  *
40  *      The %Sha2Hmac class implements the SHA-2 HMAC algorithm. @n
41  *
42  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/hashing.htm">Hashing</a>.
43  *
44  *      @see            Tizen::Security::Crypto::IHmac
45  *      @see            Tizen::Security::Crypto::Md5Hmac
46  *      @see            Tizen::Security::Crypto::Sha1Hmac
47  */
48 class _OSP_EXPORT_ Sha2Hmac
49         : public virtual IHmac
50         , public Tizen::Base::Object
51 {
52
53 public:
54         /**
55          *      This is the default constructor for this class.
56          *
57          *      @since  2.0
58          */
59         Sha2Hmac(void);
60
61         /**
62          *      This destructor overrides Tizen::Base::Object::~Object().
63          *
64          *      @since          2.0
65          */
66         virtual ~Sha2Hmac(void);
67
68         /**
69          *      Sets the HMAC algorithm.
70          *
71          *      @since          2.0
72          *
73          *      @return         An error code
74          *      @param[in]      algorithm                               The name of the HMAC algorithm @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.
78          */
79         virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
80
81         /**
82          *      Sets the secret key.
83          *
84          *      @since          2.0
85          *
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.
91          */
92         virtual result SetKey(const Tizen::Security::ISecretKey& key);
93
94         /**
95          *      Gets the HMAC with the given input.
96          *
97          *      @since          2.0
98          *
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                                A system error has occurred. @n
107          *                                                                              The method has failed to operate with the OpenSSL library, or
108          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
109          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
110          */
111         virtual Tizen::Base::ByteBuffer* GetHmacN(const Tizen::Base::ByteBuffer& input) const;
112
113         /**
114          * Initializes a multiple-part HMAC operation.
115          *
116          *      @since          2.0
117          *
118          *      @return         An error code
119          *      @exception      E_SUCCESS                               The method is successful.
120          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
121          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
122          *      @exception      E_SYSTEM                                A system error has occurred. @n
123          *                                                                              The method has failed to operate with the OpenSSL library.
124          */
125         virtual result Initialize(void);
126
127         /**
128          *      Updates a multiple-part HMAC operation while processing another part of the data.
129          *
130          *      @since          2.0
131          *
132          *      @return         An error code
133          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
134          *      @exception      E_SUCCESS                               The method is successful.
135          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
136          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
137          *      @exception      E_SYSTEM                                A system error has occurred. @n
138          *                                                                              The method has failed to operate with the OpenSSL library, or
139          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
140          */
141         virtual result Update(const Tizen::Base::ByteBuffer& input);
142
143         /**
144          * Finalizes a multiple-part HMAC operation.
145          *
146          *      @since          2.0
147          *
148          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
149          *                              else @c null if an error occurs
150          *      @exception      E_SUCCESS                               The method is successful.
151          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
152          *      @exception      E_SYSTEM                                A system error has occurred. @n
153          *                                                                              The method has failed to operate with the OpenSSL library, or
154          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
155          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
156          */
157         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
158
159 private:
160
161         //
162         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
163         //
164         // @since 2.0
165         //
166         Sha2Hmac(const Sha2Hmac& rhs);
167
168         //
169         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
170         //
171         // @since 2.0
172         //
173         Sha2Hmac& operator =(const Sha2Hmac& rhs);
174
175 private:
176         hmac_ctx_st* __pSha2HmacCtx;
177         Tizen::Base::ByteBuffer __keyBytes;
178         const env_md_st* __pAlgorithm;
179
180         class _Sha2HmacImpl* __pSha2HmacImpl;
181         friend class _Sha2HmacImpl;
182
183 }; //Sha2Hmac
184
185 } } } //Tizen::Security:Crypto
186
187 #endif //_FSEC_CRYPTO_SHA2_HMAC_H_