WS63 SDK 文档
7021f4f@fbb_ws63
ws63 和 ws63e 解决方案的 SDK 文档
载入中...
搜索中...
未找到
crypto_common_macro.h
浏览该文件的文档.
1
9
#ifndef CRYPTO_COMMON_MACRO_H
10
#define CRYPTO_COMMON_MACRO_H
11
12
#define crypto_cpu_to_be32(v) ((((td_u32)(v)) >> 24) | ((((td_u32)(v)) >> 8) & 0xff00) \
13
| ((((td_u32)(v)) << 8) & 0xff0000) | (((td_u32)(v)) << 24))
14
15
#define crypto_max(a, b) ((a) > (b)) ? (a) : (b)
16
#define crypto_min(a, b) ((a) > (b)) ? (b) : (a)
17
18
#ifndef crypto_unused
19
#define crypto_unused(x) (td_void)(x)
20
#endif
21
22
#define crypto_array_size(arr) (sizeof(arr) / sizeof((arr)[0]))
23
24
#define crypto_reg_read(reg_addr) (*(volatile td_u32 *)(uintptr_t)(reg_addr))
25
#define crypto_reg_write(reg_addr, value) (*(volatile td_u32 *)(uintptr_t)(reg_addr) = (value))
26
#define crypto_reg_read_u16(reg_addr) (*(volatile td_u16 *)(uintptr_t)(reg_addr))
27
28
#define crypto_set_bits(src, bit) ((src) |= (1 << (bit)))
29
#define crypto_clear_bits(src, bit) ((src) &= ~(1 << (bit)))
30
/* Error Check. */
31
#define crypto_chk_print(cond, ...) do { \
32
if (cond) { \
33
crypto_log_err(__VA_ARGS__); \
34
} \
35
} while (0)
36
37
#define crypto_chk_return(cond, err_ret, ...) do { \
38
if (cond) { \
39
crypto_log_err(__VA_ARGS__); \
40
return err_ret; \
41
} \
42
} while (0)
43
44
#define crypto_chk_return_void(cond, ...) do { \
45
if (cond) { \
46
crypto_log_err(__VA_ARGS__); \
47
return; \
48
} \
49
} while (0)
50
51
#define crypto_chk_goto(cond, label, ...) do { \
52
if (cond) { \
53
crypto_log_err(__VA_ARGS__); \
54
goto label; \
55
} \
56
} while (0)
57
58
/* Input Params Check. */
59
#define crypto_param_require(cond) do { \
60
if (!(cond)) { \
61
crypto_log_err("Param Check %s failed\n", #cond); \
62
return CRYPTO_FAILURE; \
63
} \
64
} while (0)
65
66
#define crypto_param_check(cond) do { \
67
if (cond) { \
68
crypto_log_err("Param Check %s failed\n", #cond); \
69
return CRYPTO_FAILURE; \
70
} \
71
} while (0)
72
73
#define crypto_chk_goto_with_ret(ret, cond, label, err_ret, fmt, ...) do { \
74
if (cond) { \
75
crypto_log_err(fmt, ##__VA_ARGS__); \
76
ret = err_ret; \
77
goto label; \
78
} \
79
} while (0)
80
81
#if defined(CRYPTO_HAL_FUNC_TRACE_ENABLE)
82
#define crypto_hal_func_enter() crypto_log_trace("%s===>Enter\n", __func__)
83
#define crypto_hal_func_exit() crypto_log_trace("%s<===Exit\n", __func__)
84
#else
85
#define crypto_hal_func_enter()
86
#define crypto_hal_func_exit()
87
#endif
88
89
#if defined(CRYPTO_KAPI_FUNC_TRACE_ENABLE)
90
#define crypto_kapi_func_enter() crypto_log_trace("%s===>Enter\n", __func__)
91
#define crypto_kapi_func_exit() crypto_log_trace("%s<===Exit\n", __func__)
92
#else
93
#define crypto_kapi_func_enter()
94
#define crypto_kapi_func_exit()
95
#endif
96
97
#if defined(CRYPTO_DRV_FUNC_TRACE_ENABLE)
98
#define crypto_drv_func_enter() crypto_print("%s===>Enter\n", __func__)
99
#define crypto_drv_func_exit() crypto_print("%s<===Exit\n", __func__)
100
#else
101
#define crypto_drv_func_enter()
102
#define crypto_drv_func_exit()
103
#endif
104
105
#if defined(CRYPTO_DISPATCH_FUNC_TRACE_ENABLE)
106
#define crypto_dispatch_func_enter() crypto_log_trace("%s===>Enter\n", __func__)
107
#define crypto_dispatch_func_exit() crypto_log_trace("%s<===Exit\n", __func__)
108
#else
109
#define crypto_dispatch_func_enter()
110
#define crypto_dispatch_func_exit()
111
#endif
112
113
#if defined(CRYPTO_UAPI_TRNG_DEBUG_ENABLE)
114
#define crypto_uapi_func_enter() crypto_log_trace("%s ===>Enter\n", __func__)
115
#define crypto_uapi_func_exit() crypto_log_trace("%s <===Exit\n", __func__)
116
#else
117
#define crypto_uapi_func_enter()
118
#define crypto_uapi_func_exit()
119
#endif
120
121
#ifndef crypto_print_func_err
122
#define crypto_print_func_err(_func, _err_code) do { \
123
crypto_log_err("%s failed! error code: 0x%x \r\n", #_func, _err_code); \
124
} while (0)
125
#endif
126
127
#ifndef crypto_chk_func_return
128
#define crypto_chk_func_return(func, ret) do { \
129
if ((ret) != TD_SUCCESS) { \
130
crypto_print_func_err(func, ret); \
131
return ret; \
132
} \
133
} while (0)
134
#endif
135
136
#ifndef crypto_check_param
137
#define crypto_check_param(err_level, module, cond, err_code) do { \
138
if (cond) { \
139
crypto_log_err("pke invalid parameter: %s \r\n", #cond); \
140
return CRYPTO_COMPAT_ERRNO(CRYPTO_ERROR_ENV, err_level, module, err_code); \
141
} \
142
} while (0)
143
#endif
144
145
#ifndef crypto_check_param_null
146
#define crypto_check_param_null(err_level, module, _val) do { \
147
crypto_check_param(err_level, module, ((_val) == TD_NULL), ERROR_PARAM_IS_NULL); \
148
} while (0)
149
#endif
150
151
#endif
src
drivers
drivers
hal
security_unified
hal_cipher
include
common_include
crypto_common_macro.h
由
William Goodspeed
维护 | E-mail: gongzl@stu.hebust.edu.cn | Wechat: a23333344 | ALSO CHECKOUT
WS63FLASH
!
生成于 2025年 一月 4日 星期六 17:47:12 , 为 WS63 SDK 文档使用
1.9.8