app_hmac.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_hmac.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of HMAC app library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @defgroup APP_HMAC HMAC
47 * @brief HMAC APP module driver.
48 * @{
49 */
50
51
52 #ifndef _APP_HMAC_H_
53 #define _APP_HMAC_H_
54
55 #include "grx_hal.h"
56 #include "app_drv_error.h"
57 #include "app_drv_config.h"
58 #include "stdbool.h"
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 #ifdef HAL_HMAC_MODULE_ENABLED
65
66 /** @addtogroup APP_HMAC_ENUM Enumerations
67 * @{
68 */
69
70 /**
71 * @brief HMAC operating mode Enumerations definition
72 */
73 typedef enum
74 {
75 APP_HMAC_TYPE_INTERRUPT, /**< Interrupt operation mode. */
76 APP_HMAC_TYPE_POLLING, /**< Polling operation mode. */
77 APP_HMAC_TYPE_DMA, /**< DMA operation mode. */
78 APP_HMAC_TYPE_MAX /**< Only for check parameter, not used as input parameters. */
79 } app_hmac_type_t;
80
81 /**
82 * @brief HMAC event Enumerations definition
83 */
84 typedef enum
85 {
86 APP_HMAC_EVT_ERROR, /**< Error reported by HMAC peripheral. */
87 APP_HMAC_EVT_DONE /**< HMAC operation completed. */
88 } app_hmac_evt_type_t;
89 /** @} */
90
91 /** @addtogroup APP_HMAC_STRUCTURES Structures
92 * @{
93 */
94 /**
95 * @brief HMAC event structure definition
96 */
97 typedef struct
98 {
99 app_hmac_evt_type_t type; /**< Type of event. */
100 uint32_t error_code; /**< HMAC Error code. */
101 } app_hmac_evt_t;
102
103 /** @} */
104
105 /** @addtogroup APP_HMAC_TYPEDEFS Type definitions
106 * @{
107 */
108 /**
109 * @brief HMAC event callback definition
110 */
111 typedef void (*app_hmac_evt_handler_t)(app_hmac_evt_t *p_evt);
112
113 /** @} */
114
115 /** @addtogroup APP_HMAC_ENUM Enumerations
116 * @{
117 */
118 /**@brief App hmac state types. */
119 typedef enum
120 {
121 APP_HMAC_INVALID = 0,
122 APP_HMAC_ACTIVITY,
123 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
124 APP_HMAC_SLEEP,
125 #endif
126 } app_hmac_state_t;
127
128 /** @} */
129
130 /** @addtogroup APP_HMAC_STRUCTURES Structures
131 * @{
132 */
133 /**
134 *@brief HMAC event structure definition.
135 */
136 typedef struct
137 {
138 app_hmac_evt_handler_t evt_handler; /**< Hmac event callback. */
139 hmac_handle_t handle; /**< Hmac handle Structure. */
140 app_hmac_type_t use_type; /**< Specifies the operation mode of I2C. */
141 app_hmac_state_t hmac_state; /**< App hmac state types. */
142 bool start_flag; /**< Hmac start flag. */
143 }hmac_env_t;
144
145 /**
146 * @brief HMAC parameters structure definition
147 */
148 typedef struct
149 {
150 app_hmac_type_t use_type; /**< Specifies the operation mode of I2C.*/
151 hmac_init_t init; /**< Hmac operation parameters */
152 hmac_env_t hmac_env; /**< Hmac event structure */
153 } app_hmac_params_t;
154
155 /** @} */
156
157 /* Exported functions --------------------------------------------------------*/
158 /** @addtogroup HAL_APP_HMAC_DRIVER_FUNCTIONS Functions
159 * @{
160 */
161 /**
162 ****************************************************************************************
163 * @brief Initialize the APP HMAC DRIVER according to the specified parameters
164 * in the app_hmac_params_t and app_hmac_evt_handler_t.
165 * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
166 * is set, you can't use interrupt mode.
167 *
168 * @param[in] p_params: Pointer to app_hmac_params_t parameter which contains the
169 * configuration information for the specified HMAC module.
170 * @param[in] evt_handler: HMAC user callback function.
171 *
172 * @return Result of initialization.
173 ****************************************************************************************
174 */
175 uint16_t app_hmac_init(app_hmac_params_t *p_params, app_hmac_evt_handler_t evt_handler);
176
177 /**
178 ****************************************************************************************
179 * @brief De-initialize the APP HMAC DRIVER peripheral.
180 *
181 * @return Result of De-initialization.
182 ****************************************************************************************
183 */
184 uint16_t app_hmac_deinit(void);
185
186 /**
187 ****************************************************************************************
188 * @brief Update p_user_hash parameters.
189 *
190 * @param[in] p_user_hash: Pointer to p_user_hash.
191 *
192 * @return Result of initialization.
193 ****************************************************************************************
194 */
195 uint16_t app_hmac_user_hash(uint32_t *p_user_hash);
196
197 /**
198 ****************************************************************************************
199 * @brief xxx in blocking mode in SHA256/HMAC mode.
200 *
201 * @param[in] p_message: Pointer to message buffer
202 * @param[in] number: Amount of data
203 * @param[out] p_digest: Pointer to digest buffer
204 * @param[in] timeout: Timeout duration
205 *
206 * @return Result of initialization.
207 ****************************************************************************************
208 */
209 uint16_t app_hmac_sha256_sync(uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
210
211 /**
212 ****************************************************************************************
213 * @brief xxx in non-blocking mode in SHA256/HMAC mode.
214 *
215 * @param[in] p_message: Pointer to message buffer
216 * @param[in] number: Amount of data
217 * @param[out] p_digest: Pointer to digest buffer
218 *
219 * @return Result of initialization.
220 ****************************************************************************************
221 */
222 uint16_t app_hmac_sha256_async(uint32_t *p_message, uint32_t number, uint32_t *p_digest);
223
224 /**
225 ****************************************************************************************
226 * @brief Return the hmac handle.
227 *
228 * @return Pointer to the hmac handle.
229 ****************************************************************************************
230 */
231 hmac_handle_t *app_hmac_get_handle(void);
232
233 /** @} */
234
235 #endif
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif
242
243 /** @} */
244 /** @} */
245 /** @} */
app_hmac_evt_type_t
app_hmac_evt_type_t
HMAC event Enumerations definition.
Definition: app_hmac.h:85
app_hmac_init
uint16_t app_hmac_init(app_hmac_params_t *p_params, app_hmac_evt_handler_t evt_handler)
Initialize the APP HMAC DRIVER according to the specified parameters in the app_hmac_params_t and app...
app_hmac_evt_t
HMAC event structure definition.
Definition: app_hmac.h:98
_hmac_init
HMAC init Structure definition.
Definition: gr55xx_hal_hmac.h:103
app_hmac_params_t::hmac_env
hmac_env_t hmac_env
Definition: app_hmac.h:152
app_hmac_sha256_async
uint16_t app_hmac_sha256_async(uint32_t *p_message, uint32_t number, uint32_t *p_digest)
xxx in non-blocking mode in SHA256/HMAC mode.
APP_HMAC_TYPE_DMA
@ APP_HMAC_TYPE_DMA
Definition: app_hmac.h:77
app_hmac_params_t::init
hmac_init_t init
Definition: app_hmac.h:151
app_hmac_evt_t::type
app_hmac_evt_type_t type
Definition: app_hmac.h:99
APP_HMAC_TYPE_POLLING
@ APP_HMAC_TYPE_POLLING
Definition: app_hmac.h:76
hmac_env_t::hmac_state
app_hmac_state_t hmac_state
Definition: app_hmac.h:141
app_hmac_user_hash
uint16_t app_hmac_user_hash(uint32_t *p_user_hash)
Update p_user_hash parameters.
app_hmac_state_t
app_hmac_state_t
App hmac state types.
Definition: app_hmac.h:120
hmac_env_t::use_type
app_hmac_type_t use_type
Definition: app_hmac.h:140
app_hmac_deinit
uint16_t app_hmac_deinit(void)
De-initialize the APP HMAC DRIVER peripheral.
app_hmac_sha256_sync
uint16_t app_hmac_sha256_sync(uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout)
xxx in blocking mode in SHA256/HMAC mode.
APP_HMAC_EVT_ERROR
@ APP_HMAC_EVT_ERROR
Definition: app_hmac.h:86
hmac_env_t::handle
hmac_handle_t handle
Definition: app_hmac.h:139
APP_HMAC_TYPE_INTERRUPT
@ APP_HMAC_TYPE_INTERRUPT
Definition: app_hmac.h:75
hmac_env_t::evt_handler
app_hmac_evt_handler_t evt_handler
Definition: app_hmac.h:138
APP_HMAC_TYPE_MAX
@ APP_HMAC_TYPE_MAX
Definition: app_hmac.h:78
app_hmac_get_handle
hmac_handle_t * app_hmac_get_handle(void)
Return the hmac handle.
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
hmac_env_t
HMAC event structure definition.
Definition: app_hmac.h:137
_hmac_handle
HMAC handle Structure definition.
Definition: gr55xx_hal_hmac.h:126
app_hmac_params_t::use_type
app_hmac_type_t use_type
Definition: app_hmac.h:150
app_hmac_type_t
app_hmac_type_t
HMAC operating mode Enumerations definition.
Definition: app_hmac.h:74
app_hmac_evt_t::error_code
uint32_t error_code
Definition: app_hmac.h:100
app_hmac_evt_handler_t
void(* app_hmac_evt_handler_t)(app_hmac_evt_t *p_evt)
HMAC event callback definition.
Definition: app_hmac.h:111
APP_HMAC_EVT_DONE
@ APP_HMAC_EVT_DONE
Definition: app_hmac.h:87
hmac_env_t::start_flag
bool start_flag
Definition: app_hmac.h:142
APP_HMAC_INVALID
@ APP_HMAC_INVALID
Definition: app_hmac.h:121
app_hmac_params_t
HMAC parameters structure definition.
Definition: app_hmac.h:149
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
APP_HMAC_ACTIVITY
@ APP_HMAC_ACTIVITY
Definition: app_hmac.h:122