Add to retry to read DUID.
[platform/framework/native/appfw.git] / inc / FSecCryptoMd5Hmac.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                FSecCryptoMd5Hmac.h
19  * @brief               This is the header file for the %Md5Hmac class.
20  *
21  * This header file contains the declarations of the %Md5Hmac class.
22  */
23 #ifndef _FSEC_CRYPTO_MD5_HMAC_H_
24 #define _FSEC_CRYPTO_MD5_HMAC_H_
25
26 #include <FSecCryptoIHmac.h>
27
28 struct hmac_ctx_st;
29
30
31 namespace Tizen { namespace Security { namespace Crypto
32 {
33
34 /**
35  *      @class          Md5Hmac
36  *      @brief          This class implements the MD5 HMAC algorithm.
37  *
38  *      @since          2.0
39  *
40  *  The %Md5Hmac class implements the basic hash procedure to encrypt messages using the Hash Message Authentication Code (HMAC) algorithm, which provides a hash with a secret key. @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  IHmac
45  *  @see  Sha1Hmac
46  *  @see  Sha2Hmac
47  */
48 class _OSP_EXPORT_ Md5Hmac
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         Md5Hmac(void);
60
61         /**
62          *      This destructor overrides Tizen::Base::Object::~Object().
63          *
64          * @since               2.0
65          */
66         virtual ~Md5Hmac(void);
67
68         /**
69          *      Sets the HMAC algorithm. @n
70          *      The %SetAlgorithm() method is not supported by this class. Do not call this method.
71          *      If this method is called, it returns @c E_UNSUPPORTED_ALGORITHM.
72          *
73          *      @since          2.0
74          *
75          *      @return         An error code
76          *      @param[in]      algorithm                                       The name of the HMAC algorithm @n
77          *                                                                                      For example, "HMACSHA2/224", "HMACSHA2/256", "HMACSHA2/384", or "HMACSHA2/512".
78          *      @exception      E_SUCCESS                                       The method is successful.
79          *      @exception      E_UNSUPPORTED_ALGORITHM         The algorithm is not supported.
80          *  @remarks    Do not call this method. It is not supported.
81          */
82         virtual result SetAlgorithm(const Tizen::Base::String& algorithm);
83
84         /**
85          *      Sets the secret key.
86          *
87          * @since               2.0
88          *
89          *      @return         An error code
90          *      @param[in]      key                                             An instance of ISecretKey
91          *      @exception      E_SUCCESS                               The method is successful.
92          *      @exception      E_INVALID_ARG                   The specified key is invalid.
93          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
94          */
95         virtual result SetKey(const Tizen::Security::ISecretKey& key);
96
97         /**
98          *      Gets the HMAC with the specified input.
99          *
100          *      @since          2.0
101          *
102          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
103          *                              else @c null if an error occurs
104          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
105          *      @exception      E_SUCCESS                               The method is successful.
106          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
107          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
108          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
109          *      @exception      E_SYSTEM                                A system error has occurred. @n
110          *                                                                              The method has failed to operate with the OpenSSL library, or
111          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
112          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
113          */
114         virtual Tizen::Base::ByteBuffer* GetHmacN(const Tizen::Base::ByteBuffer& input) const;
115
116         /**
117          *      Initializes a multiple-part HMAC operation.
118          *
119          *      @since          2.0
120          *
121          *      @return         An error code
122          *      @exception      E_SUCCESS                               The method is successful.
123          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
124          *      @exception      E_KEY_NOT_FOUND                 The specified key is not found.
125          *      @exception      E_SYSTEM                                A system error has occurred. @n
126          *                                                                              The method has failed to operate with the OpenSSL library.
127          */
128         virtual result Initialize(void);
129
130         /**
131          *      Updates a multiple-part HMAC operation while processing another data part.
132          *
133          *      @since          2.0
134          *
135          *      @return         An error code
136          *      @param[in]      input                                   An instance of Tizen::Base::ByteBuffer
137          *      @exception      E_SUCCESS                               The method is successful.
138          *      @exception      E_INVALID_ARG                   The input Tizen::Base::ByteBuffer is empty or contains invalid data.
139          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
140          *      @exception      E_SYSTEM                                A system error has occurred. @n
141          *                                                                              The method has failed to operate with the OpenSSL library, or
142          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
143          */
144         virtual result Update(const Tizen::Base::ByteBuffer& input);
145
146         /**
147          *      Finalizes a multiple-part HMAC operation.
148          *
149          *      @since          2.0
150          *
151          *      @return         A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
152          *                              else @c null if an error occurs
153          *      @exception      E_SUCCESS                               The method is successful.
154          *      @exception      E_OUT_OF_MEMORY                 The memory is insufficient.
155          *      @exception      E_SYSTEM                                A system error has occurred. @n
156          *                                                                              The method has failed to operate with the OpenSSL library, or
157          *                                                                              the Tizen::Base::ByteBuffer operation has failed.
158          *      @remarks        The specific error code can be accessed using the GetLastResult() method.
159          */
160         virtual Tizen::Base::ByteBuffer* FinalizeN(void);
161
162 private:
163
164         //
165         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
166         //
167         // @since 2.0
168         //
169         Md5Hmac(const Md5Hmac& rhs);
170
171         //
172         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
173         //
174         // @since 2.0
175         //
176         Md5Hmac& operator =(const Md5Hmac& rhs);
177
178 private:
179         hmac_ctx_st* __pMd5HmacCtx;
180         Tizen::Base::ByteBuffer __keyBytes;
181
182         class _Md5HmacImpl* __pMd5HmacImpl;
183         friend class _Md5HmacImpl;
184
185 }; //Md5Hmac
186
187 } } } //Tizen::Security::Crypto
188
189 #endif //_FSEC_CRYPTO_MD5_HMAC_H_