1 /* 2 * Copyright (c) 2006-2023, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2019-04-23 tyx the first version 9 */ 10 11 #ifndef __HW_HASH_H__ 12 #define __HW_HASH_H__ 13 14 #include <hwcrypto.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 struct hwcrypto_hash; 21 22 struct hwcrypto_hash_ops 23 { 24 rt_err_t (*update)(struct hwcrypto_hash *hash_ctx, 25 const rt_uint8_t *in, rt_size_t length); /**< Processing a packet of data */ 26 rt_err_t (*finish)(struct hwcrypto_hash *hash_ctx, 27 rt_uint8_t *out, rt_size_t length); /**< Get the final hash value */ 28 }; 29 30 /** 31 * @brief hash context. Hardware driver usage 32 */ 33 struct hwcrypto_hash 34 { 35 struct rt_hwcrypto_ctx parent; /**< Inheritance from hardware crypto context */ 36 const struct hwcrypto_hash_ops *ops; /**< !! Hardware initializes this value when creating context !! */ 37 }; 38 39 /** 40 * @brief Creating hash Context 41 * 42 * @param device Hardware crypto device 43 * @param type Type of hash context 44 * 45 * @return Hash context 46 */ 47 struct rt_hwcrypto_ctx *rt_hwcrypto_hash_create(struct rt_hwcrypto_device *device, 48 hwcrypto_type type); 49 50 /** 51 * @brief Destroy hash Context 52 * 53 * @param ctx Hash context 54 */ 55 void rt_hwcrypto_hash_destroy(struct rt_hwcrypto_ctx *ctx); 56 57 /** 58 * @brief Get the final hash value 59 * 60 * @param ctx Hash context 61 * @param output Hash value buffer 62 * @param length Hash value buffer length 63 * 64 * @return RT_EOK on success. 65 */ 66 rt_err_t rt_hwcrypto_hash_finish(struct rt_hwcrypto_ctx *ctx, rt_uint8_t *output, rt_size_t length); 67 68 /** 69 * @brief Processing a packet of data 70 * 71 * @param ctx Hash context 72 * @param input Data buffer to be Processed 73 * @param length Data Buffer length 74 * 75 * @return RT_EOK on success. 76 */ 77 rt_err_t rt_hwcrypto_hash_update(struct rt_hwcrypto_ctx *ctx, const rt_uint8_t *input, rt_size_t length); 78 79 /** 80 * @brief This function copy hash context 81 * 82 * @param des The destination hash context 83 * @param src The hash context to be copy 84 * 85 * @return RT_EOK on success. 86 */ 87 rt_err_t rt_hwcrypto_hash_cpy(struct rt_hwcrypto_ctx *des, const struct rt_hwcrypto_ctx *src); 88 89 /** 90 * @brief Reset hash context 91 * 92 * @param ctx Hash context 93 */ 94 void rt_hwcrypto_hash_reset(struct rt_hwcrypto_ctx *ctx); 95 96 /** 97 * @brief Setting hash context type 98 * 99 * @param ctx Hash context 100 * @param type Types of settings 101 * 102 * @return RT_EOK on success. 103 */ 104 rt_err_t rt_hwcrypto_hash_set_type(struct rt_hwcrypto_ctx *ctx, hwcrypto_type type); 105 106 #ifdef __cplusplus 107 } 108 #endif 109 110 #endif 111