SmartSnippets DA1459x SDK
hw_hash.h
Go to the documentation of this file.
1 
42 #ifndef HW_HASH_H_
43 #define HW_HASH_H_
44 
45 #if dg_configUSE_HW_HASH
46 
47 #include "hw_aes_hash.h"
48 
52 typedef enum {
53  HW_HASH_ERROR_INVALID_INPUT_DATA_LEN = -2,
54  HW_HASH_ERROR_CRYPTO_ENGINE_LOCKED = -1,
55  HW_HASH_ERROR_NONE = 0
57 
61 typedef enum {
64 } HW_HASH_TYPE;
65 
69 typedef enum {
73 
91 typedef struct {
94  uint32_t input_data_len;
95  uint32_t output_data_len;
96  uint32_t input_data_addr;
97  uint32_t output_data_addr;
100 
108 __STATIC_INLINE void hw_hash_set_type(HW_HASH_TYPE hash_type)
109 {
110  ASSERT_WARNING((hash_type >= HW_HASH_TYPE_SHA_256_224) && (hash_type <= HW_HASH_TYPE_SHA_256));
111  uint8_t crypto_alg = hash_type & REG_MSK(AES_HASH, CRYPTO_CTRL_REG, CRYPTO_ALG);
112  uint32_t crypto_ctrl_reg = AES_HASH->CRYPTO_CTRL_REG;
113 
114  REG_SET_FIELD(AES_HASH, CRYPTO_CTRL_REG, CRYPTO_HASH_SEL, crypto_ctrl_reg, 1);
115  REG_SET_FIELD(AES_HASH, CRYPTO_CTRL_REG, CRYPTO_ALG, crypto_ctrl_reg, crypto_alg);
116 
117  AES_HASH->CRYPTO_CTRL_REG = crypto_ctrl_reg;
118 }
119 
133 __STATIC_INLINE void hw_hash_set_output_data_len(HW_HASH_TYPE hash_type, uint8_t output_data_len)
134 {
135  __RETAINED_CONST_INIT static const uint8_t out_len_max[] = {
138  };
139 
140  if (output_data_len > out_len_max[hash_type]) {
141  ASSERT_WARNING(0);
142  output_data_len = out_len_max[hash_type];
143  }
144 
145  REG_SETF(AES_HASH, CRYPTO_CTRL_REG, CRYPTO_HASH_OUT_LEN, (output_data_len - 1));
146 }
147 
161 
190 
191 #endif /* dg_configUSE_HW_HASH */
192 
193 #endif /* HW_HASH_H_ */
194 
HW_HASH_OUTPUT_LEN_MAX_SHA_256
Definition: hw_hash.h:71
REG_SETF
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
HW_HASH_OUTPUT_LEN_MAX_SHA_256_224
Definition: hw_hash.h:70
hw_hash_config_t::output_data_addr
uint32_t output_data_addr
Definition: hw_hash.h:97
hw_hash_config_t::input_data_len
uint32_t input_data_len
Definition: hw_hash.h:94
hw_hash_config_t::output_data_len
uint32_t output_data_len
Definition: hw_hash.h:95
hw_hash_init
HW_HASH_ERROR hw_hash_init(const hw_hash_config_t *hash_cfg)
HASH engine initialization function.
HW_HASH_TYPE
HW_HASH_TYPE
HASH Type.
Definition: hw_hash.h:61
__RETAINED_CONST_INIT
#define __RETAINED_CONST_INIT
Constant data retained memory attribute.
Definition: sdk_defs.h:329
hw_aes_hash.h
Definition of API for the AES/HASH Engine Low Level Driver.
hw_hash_set_output_data_len
__STATIC_INLINE void hw_hash_set_output_data_len(HW_HASH_TYPE hash_type, uint8_t output_data_len)
Set HASH output length.
Definition: hw_hash.h:133
hw_hash_config_t::callback
hw_aes_hash_cb callback
Definition: hw_hash.h:98
REG_MSK
#define REG_MSK(base, reg, field)
Access register field mask.
Definition: sdk_defs.h:583
HW_HASH_TYPE_SHA_256
Definition: hw_hash.h:63
hw_aes_hash_cb
void(* hw_aes_hash_cb)(uint32_t status)
AES/Hash callback.
Definition: hw_aes_hash.h:168
hw_hash_config_t
HASH engine configuration structure.
Definition: hw_hash.h:91
hw_hash_set_type
__STATIC_INLINE void hw_hash_set_type(HW_HASH_TYPE hash_type)
Set HASH type.
Definition: hw_hash.h:108
hw_hash_check_input_data_len_restrictions
bool hw_hash_check_input_data_len_restrictions(void)
Check if the restrictions of the input data length are fulfilled.
REG_SET_FIELD
#define REG_SET_FIELD(base, reg, field, var, val)
Set register field value.
Definition: sdk_defs.h:626
HW_HASH_OUTPUT_LENGTH_MAX
HW_HASH_OUTPUT_LENGTH_MAX
The maximum allowed output length of the HASH engine in bytes for all supported HASH types.
Definition: hw_hash.h:69
hw_hash_config_t::wait_more_input
bool wait_more_input
Definition: hw_hash.h:93
HW_HASH_ERROR
HW_HASH_ERROR
HASH engine error codes.
Definition: hw_hash.h:52
hw_hash_config_t::type
HW_HASH_TYPE type
Definition: hw_hash.h:92
hw_hash_config_t::input_data_addr
uint32_t input_data_addr
Definition: hw_hash.h:96
HW_HASH_TYPE_SHA_256_224
Definition: hw_hash.h:62