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 "gr55xx_hal.h"
56 #include "app_drv_error.h"
57 #ifdef ENV_USE_FREERTOS
58 #include "app_rtos_cfg.h"
59 #endif
60 
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #ifdef HAL_HMAC_MODULE_ENABLED
67 
68 /** @addtogroup APP_HMAC_ENUM Enumerations
69  * @{
70  */
71 
72 /**
73  * @brief HMAC operating mode Enumerations definition
74  */
75 typedef enum
76 {
77  APP_HMAC_TYPE_INTERRUPT, /**< Interrupt operation mode */
78  APP_HMAC_TYPE_POLLING, /**< Polling operation mode */
79  APP_HMAC_TYPE_DMA, /**< DMA operation mode */
80  APP_HMAC_TYPE_MAX /**< Only for check parameter, not used as input parameters. */
82 
83 /**
84  * @brief HMAC event Enumerations definition
85  */
86 typedef enum
87 {
88  APP_HMAC_EVT_ERROR, /**< Error reported by HMAC peripheral. */
89  APP_HMAC_EVT_DONE /**< HMAC operation completed. */
91 /** @} */
92 
93 /** @addtogroup APP_HMAC_STRUCTURES Structures
94  * @{
95  */
96 /**
97  * @brief HMAC parameters structure definition
98  */
99 typedef struct
100 {
101  app_hmac_type_t use_type; /**< Specifies the operation mode of I2C. */
102  hmac_init_t init; /**< HMAC operation parameters */
104 
105 /**
106  * @brief HMAC event structure definition
107  */
108 typedef struct
109 {
110  app_hmac_evt_type_t type; /**< Type of event. */
111  uint32_t error_code; /**< HMAC Error code . */
113 
114 /**
115  * @brief HMAC event callback definition
116  */
117 typedef void (*app_hmac_evt_handler_t)(app_hmac_evt_t *p_evt);
118 
119 /** @} */
120 
121 /* Exported functions --------------------------------------------------------*/
122 /** @addtogroup HAL_APP_HMAC_DRIVER_FUNCTIONS Functions
123  * @{
124  */
125 /**
126  ****************************************************************************************
127  * @brief Initialize the APP HMAC DRIVER according to the specified parameters
128  * in the app_hmac_params_t and app_hmac_evt_handler_t.
129  * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
130  * is set, you can't use interrupt mode.
131  *
132  * @param[in] p_params: Pointer to app_hmac_params_t parameter which contains the
133  * configuration information for the specified HMAC module.
134  * @param[in] evt_handler: HMAC user callback function.
135  *
136  * @return Result of initialization.
137  ****************************************************************************************
138  */
139 uint16_t app_hmac_init(app_hmac_params_t *p_params, app_hmac_evt_handler_t evt_handler);
140 
141 /**
142  ****************************************************************************************
143  * @brief De-initialize the APP HMAC DRIVER peripheral.
144  *
145  * @return Result of De-initialization.
146  ****************************************************************************************
147  */
148 uint16_t app_hmac_deinit(void);
149 
150 /**
151  ****************************************************************************************
152  * @brief Update p_user_hash parameters.
153  *
154  * @param[in] p_user_hash: Pointer to p_user_hash.
155  *
156  * @return Result of initialization.
157  ****************************************************************************************
158  */
159 uint16_t app_hmac_user_hash(uint32_t *p_user_hash);
160 
161 /**
162  ****************************************************************************************
163  * @brief xxx in blocking mode in SHA256/HMAC mode.
164  *
165  * @param[in] p_message: Pointer to message buffer
166  * @param[in] number: Amount of data
167  * @param[out] p_digest: Pointer to digest buffer
168  * @param[in] timeout: Timeout duration
169  *
170  * @return Result of initialization.
171  ****************************************************************************************
172  */
173 uint16_t app_hmac_sha256_sync(uint32_t *p_message, uint32_t number, uint32_t *p_digest, uint32_t timeout);
174 
175 /**
176  ****************************************************************************************
177  * @brief xxx in non-blocking mode in SHA256/HMAC mode.
178  *
179  * @param[in] p_message: Pointer to message buffer
180  * @param[in] number: Amount of data
181  * @param[out] p_digest: Pointer to digest buffer
182  *
183  * @return Result of initialization.
184  ****************************************************************************************
185  */
186 uint16_t app_hmac_sha256_async(uint32_t *p_message, uint32_t number, uint32_t *p_digest);
187 
188 /**
189  ****************************************************************************************
190  * @brief Return the hmac handle.
191  *
192  * @return Pointer to the hmac handle.
193  ****************************************************************************************
194  */
196 
197 #ifdef ENV_RTOS_USE_SEMP
198 /**
199  ****************************************************************************************
200  * @brief [RTOS] xxx in blocking mode in SHA256/HMAC mode.
201  *
202  * @param[in] p_message: Pointer to message buffer
203  * @param[in] number: Amount of data
204  * @param[out] p_digest: Pointer to digest buffer
205  *
206  * @return Result of initialization.
207  ****************************************************************************************
208  */
209 uint16_t app_hmac_sha256_sem_sync(uint32_t *p_message, uint32_t number, uint32_t *p_digest);
210 #endif
211 
212 /** @} */
213 
214 #endif
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif
221 
222 /** @} */
223 /** @} */
224 /** @} */
app_hmac_evt_type_t
app_hmac_evt_type_t
HMAC event Enumerations definition.
Definition: app_hmac.h:87
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:109
_hmac_init
HMAC init Structure definition.
Definition: gr55xx_hal_hmac.h:103
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:79
app_hmac_params_t::init
hmac_init_t init
HMAC operation parameters
Definition: app_hmac.h:102
app_hmac_evt_t::type
app_hmac_evt_type_t type
Type of event.
Definition: app_hmac.h:110
APP_HMAC_TYPE_POLLING
@ APP_HMAC_TYPE_POLLING
Polling operation mode
Definition: app_hmac.h:78
app_hmac_user_hash
uint16_t app_hmac_user_hash(uint32_t *p_user_hash)
Update p_user_hash parameters.
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:88
APP_HMAC_TYPE_INTERRUPT
@ APP_HMAC_TYPE_INTERRUPT
Interrupt operation mode.
Definition: app_hmac.h:77
APP_HMAC_TYPE_MAX
@ APP_HMAC_TYPE_MAX
Only for check parameter, not used as input parameters.
Definition: app_hmac.h:80
app_hmac_get_handle
hmac_handle_t * app_hmac_get_handle(void)
Return the hmac handle.
_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:101
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_hmac_type_t
app_hmac_type_t
HMAC operating mode Enumerations definition.
Definition: app_hmac.h:76
app_hmac_evt_t::error_code
uint32_t error_code
HMAC Error code .
Definition: app_hmac.h:111
APP_HMAC_EVT_DONE
@ APP_HMAC_EVT_DONE
HMAC operation completed.
Definition: app_hmac.h:89
app_hmac_params_t
HMAC parameters structure definition.
Definition: app_hmac.h:100
app_rtos_cfg.h
Header file of app rtos config code.
app_drv_error.h
Header file of app driver error 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:117