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 * @brief HMAC event callback definition
105 */
106 typedef void (*app_hmac_evt_handler_t)(app_hmac_evt_t *p_evt);
107
108 /**@brief App hmac state types. */
109 typedef enum
110 {
111 APP_HMAC_INVALID = 0,
112 APP_HMAC_ACTIVITY,
113 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
114 APP_HMAC_SLEEP,
115 #endif
116 } app_hmac_state_t;
117
118 /**
119 *@brief HMAC event structure definition.
120 */
121 typedef struct
122 {
123 app_hmac_evt_handler_t evt_handler; /**< Hmac event callback. */
124 hmac_handle_t handle; /**< Hmac handle Structure. */
125 app_hmac_type_t use_type; /**< Specifies the operation mode of I2C. */
126 app_hmac_state_t hmac_state; /**< App hmac state types. */
127 bool start_flag; /**< Hmac start flag. */
128 }hmac_env_t;
129
130 /**
131 * @brief HMAC parameters structure definition
132 */
133 typedef struct
134 {
135 app_hmac_type_t use_type; /**< Specifies the operation mode of I2C.*/
136 hmac_init_t init; /**< Hmac operation parameters */
137 hmac_env_t hmac_env; /**< Hmac event structure */
138 } app_hmac_params_t;
139
140 /** @} */
141
142 /* Exported functions --------------------------------------------------------*/
143 /** @addtogroup HAL_APP_HMAC_DRIVER_FUNCTIONS Functions
144 * @{
145 */
146 /**
147 ****************************************************************************************
148 * @brief Initialize the APP HMAC DRIVER according to the specified parameters
149 * in the app_hmac_params_t and app_hmac_evt_handler_t.
150 * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
151 * is set, you can't use interrupt mode.
152 *
153 * @param[in] p_params: Pointer to app_hmac_params_t parameter which contains the
154 * configuration information for the specified HMAC module.
155 * @param[in] evt_handler: HMAC user callback function.
156 *
157 * @return Result of initialization.
158 ****************************************************************************************
159 */
160 uint16_t app_hmac_init(app_hmac_params_t *p_params, app_hmac_evt_handler_t evt_handler);
161
162 /**
163 ****************************************************************************************
164 * @brief De-initialize the APP HMAC DRIVER peripheral.
165 *
166 * @return Result of De-initialization.
167 ****************************************************************************************
168 */
169 uint16_t app_hmac_deinit(void);
170
171 /**
172 ****************************************************************************************
173 * @brief Update p_user_hash parameters.
174 *
175 * @param[in] p_user_hash: Pointer to p_user_hash.
176 *
177 * @return Result of initialization.
178 ****************************************************************************************
179 */
180 uint16_t app_hmac_user_hash(uint32_t *p_user_hash);
181
182 /**
183 ****************************************************************************************
184 * @brief xxx in blocking mode in SHA256/HMAC mode.
185 *
186 * @param[in] p_message: Pointer to message buffer
187 * @param[in] number: Amount of data
188 * @param[out] p_digest: Pointer to digest buffer
189 * @param[in] timeout: Timeout duration
190 *
191 * @return Result of initialization.
192 ****************************************************************************************
193 */
194 uint16_t app_hmac_sha256_sync(uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
195
196 /**
197 ****************************************************************************************
198 * @brief xxx in non-blocking mode in SHA256/HMAC mode.
199 *
200 * @param[in] p_message: Pointer to message buffer
201 * @param[in] number: Amount of data
202 * @param[out] p_digest: Pointer to digest buffer
203 *
204 * @return Result of initialization.
205 ****************************************************************************************
206 */
207 uint16_t app_hmac_sha256_async(uint32_t *p_message, uint32_t number, uint32_t *p_digest);
208
209 /**
210 ****************************************************************************************
211 * @brief Return the hmac handle.
212 *
213 * @return Pointer to the hmac handle.
214 ****************************************************************************************
215 */
216 hmac_handle_t *app_hmac_get_handle(void);
217
218 /** @} */
219
220 #endif
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif
227
228 /** @} */
229 /** @} */
230 /** @} */
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
Hmac event structure
Definition: app_hmac.h:137
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
DMA operation mode
Definition: app_hmac.h:77
app_hmac_params_t::init
hmac_init_t init
Hmac operation parameters
Definition: app_hmac.h:136
app_hmac_evt_t::type
app_hmac_evt_type_t type
Type of event.
Definition: app_hmac.h:99
APP_HMAC_TYPE_POLLING
@ APP_HMAC_TYPE_POLLING
Polling operation mode
Definition: app_hmac.h:76
hmac_env_t::hmac_state
app_hmac_state_t hmac_state
App hmac state types.
Definition: app_hmac.h:126
app_hmac_user_hash
uint16_t app_hmac_user_hash(uint32_t *p_user_hash)
Update p_user_hash parameters.
hmac_env_t::use_type
app_hmac_type_t use_type
Specifies the operation mode of I2C.
Definition: app_hmac.h:125
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
Error reported by HMAC peripheral.
Definition: app_hmac.h:86
hmac_env_t::handle
hmac_handle_t handle
Hmac handle Structure.
Definition: app_hmac.h:124
APP_HMAC_TYPE_INTERRUPT
@ APP_HMAC_TYPE_INTERRUPT
Interrupt operation mode.
Definition: app_hmac.h:75
hmac_env_t::evt_handler
app_hmac_evt_handler_t evt_handler
Hmac event callback.
Definition: app_hmac.h:123
APP_HMAC_TYPE_MAX
@ APP_HMAC_TYPE_MAX
Only for check parameter, not used as input parameters.
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.
APP_HMAC_INVALID
@ APP_HMAC_INVALID
Definition: app_hmac.h:111
APP_HMAC_ACTIVITY
@ APP_HMAC_ACTIVITY
Definition: app_hmac.h:112
hmac_env_t
HMAC event structure definition.
Definition: app_hmac.h:122
_hmac_handle
HMAC handle Structure definition.
Definition: gr55xx_hal_hmac.h:128
app_hmac_params_t::use_type
app_hmac_type_t use_type
Specifies the operation mode of I2C.
Definition: app_hmac.h:135
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
HMAC Error code .
Definition: app_hmac.h:100
APP_HMAC_EVT_DONE
@ APP_HMAC_EVT_DONE
HMAC operation completed.
Definition: app_hmac.h:87
hmac_env_t::start_flag
bool start_flag
Hmac start flag.
Definition: app_hmac.h:127
app_hmac_state_t
app_hmac_state_t
App hmac state types.
Definition: app_hmac.h:110
app_hmac_params_t
HMAC parameters structure definition.
Definition: app_hmac.h:134
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
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:106