Merge "[Pkcs] Fixed the TC's failure" into tizen_2.1
[platform/framework/native/appfw.git] / inc / FSecCryptoSha2Hmac.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FSecCryptoSha2Hmac.h
20  * @brief       This is the header file for the %Sha2Hmac class.
21  *
22  * This header file contains the declarations of the %Sha2Hmac class.
23  */
24 #ifndef _FSEC_CRYPTO_SHA2_HMAC_H_
25 #define _FSEC_CRYPTO_SHA2_HMAC_H_
26
27 #include <FSecCryptoIHmac.h>
28
29 struct env_md_st;
30 struct hmac_ctx_st;
31
32 namespace Tizen { namespace Security { namespace Crypto
33 {
34
35 /**
36  *      @class  Sha2Hmac
37  *      @brief  This class implements the SHA-2 HMAC algorithm.
38  *
39  *      @since  2.0
40  *
41  *      The %Sha2Hmac class implements the SHA-2 HMAC algorithm. @n
42  *
43  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/hashing.htm">Hashing</a>.
44  *
45  *      @see            Tizen::Security::Crypto::IHmac
46  *      @see            Tizen::Security::Crypto::Md5Hmac
47  *      @see            Tizen::Security::Crypto::Sha1Hmac
48  */
49 class _OSP_EXPORT_ Sha2Hmac
50         : public virtual IHmac
51         , public Tizen::Base::Object
52 {
53
54 public:
55         /**
56          *      This is the default constructor for this class.
57          *
58          *      @since  2.0
59          */
60         Sha2Hmac(void);
61
62         /**
63          *      This destructor overrides Tizen::Base::Object::~Object().
64          *
65          *      @since          2.0
66          */
67         virtual ~Sha2Hmac(void);
68
69         /**
70          *      Sets the HMAC algorithm.
71          *
72          *      @since          2.0
73          *
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.
79          */
80         virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
81
82         /**
83          *      Sets the secret key.
84          *
85          *      @since          2.0
86          *
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.
92          */
93         virtual result SetKey(const Tizen::Security::ISecretKey& key);
94
95         /**
96          *      Gets the HMAC with the given input.
97          *
98          *      @since          2.0
99          *
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.
111          */
112         virtual Tizen::Base::ByteBuffer* GetHmacN(const Tizen::Base::ByteBuffer& input) const;
113
114         /**
115          * Initializes the multiple-part HMAC operation.
116          *
117          *      @since          2.0
118          *
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.
125          */
126         virtual result Initialize(void);
127
128         /**
129          *      Updates a multiple-part HMAC operation while processing another part of the data.
130          *
131          *      @since          2.0
132          *
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.
141          */
142         virtual result Update(const Tizen::Base::ByteBuffer& input);
143
144         /**
145          * Finalizes a multiple-part HMAC operation.
146          *
147          *      @since          2.0
148          *
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.
157          */
158         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
159
160 private:
161
162         //
163         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
164         //
165         // @since 2.0
166         //
167         Sha2Hmac(const Sha2Hmac& rhs);
168
169         //
170         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
171         //
172         // @since 2.0
173         //
174         Sha2Hmac& operator =(const Sha2Hmac& rhs);
175
176 private:
177         hmac_ctx_st* __pSha2HmacCtx;
178         Tizen::Base::ByteBuffer __keyBytes;
179         const env_md_st* __pAlgorithm;
180
181         class _Sha2HmacImpl* __pSha2HmacImpl;
182         friend class _Sha2HmacImpl;
183
184 }; //Sha2Hmac
185
186 } } } //Tizen::Security:Crypto
187
188 #endif //_FSEC_CRYPTO_SHA2_HMAC_H_