• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: Provides SHA256 header
15  *
16  * Create: 2023-12-13
17 */
18 
19 #ifndef SECURITY_SHA256_H
20 #define SECURITY_SHA256_H
21 
22 #include <stdint.h>
23 #include "errcode.h"
24 
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif
30 #endif
31 
32 /**
33  * @defgroup security_unified_sha256 SHA256
34  * @ingroup  drivers_driver_security_unified
35  * @{
36  */
37 
38 #ifndef SHA256_HASH_SIZE
39 #define SHA256_HASH_SIZE    32
40 #endif
41 
42 /**
43  * @if Eng
44  * @brief  Create a sha256 channel.
45  * @param  [out]  hash_handle Pointer to the created sha256 channel handle.
46  * @retval ERRCODE_SUCC Success.
47  * @retval Other        Failure. For details, see @ref errcode_t
48  * @else
49  * @brief  创建sha256通道。
50  * @param  [out]  hash_handle 指向创建的hash通道句柄的指针。
51  * @retval ERRCODE_SUCC 成功。
52  * @retval Other        失败,参考 @ref errcode_t 。
53  * @endif
54  */
55 errcode_t uapi_drv_cipher_sha256_start(uint32_t *hash_handle);
56 
57 /**
58  * @if Eng
59  * @brief  Sha256 calculation
60  * @note   A sha256 handle must have been created before this API is called.
61            If the uapi_drv_cipher_sha256_finish() API has been called to obtain the digest information,
62            the calculation cannot be performed again. When calculating the abstract of a piece of data,
63            you can invoke this interface at a time.
64            You can also split data into multiple parts and invoke this interface for multiple times.
65            The results obtained by the two methods are the same.
66  * @param  [in]   hash_handle Handle of the created sha256 channel.
67  * @param  [in]   buf Source buffer pointer.
68  * @param  [in]   len Buffer Size.
69  * @retval ERRCODE_SUCC Success.
70  * @retval Other        Failure. For details, see @ref errcode_t
71  * @else
72  * @brief  Sha256计算
73  * @note   调用该接口前必须已经创建了sha256句柄,如已经调用了uapi_drv_cipher_sha256_finish()接口获取摘要信息,
74            则不能再次进行该计算。
75            计算一段数据的摘要时,可以单次调用该接口;也可以将数据拆成多段,多次调用该接口。两种方式得到的结果相同。
76  * @param  [in]   hash_handle 已创建的hash通道句柄。
77  * @param  [in]   buf 源缓冲区指针。
78  * @param  [in]   len 缓冲区大小。
79  * @retval ERRCODE_SUCC 成功。
80  * @retval Other        失败,参考 @ref errcode_t 。
81  * @endif
82  */
83 errcode_t uapi_drv_cipher_sha256_update(uint32_t hash_handle, const uint8_t *buf, uint32_t len);
84 
85 /**
86  * @if Eng
87  * @brief  Sha256 calculation obtains digest information and destroys the handle when the calculation is successful.
88  * @note   The sha256 handle must have been created.
89  * @param  [in]    hash_handle Handle of the created sha256 channel.
90  * @param  [out]   out Pointer to the buffer address for storing the summary information.
91  * @param  [inout] out_len Pointer to the size of the buffer for storing the summary information.
92                            The input is the buffer length, and the output is the actual digest length.
93  * @retval ERRCODE_SUCC Success.
94  * @retval Other        Failure. For details, see @ref errcode_t
95  * @else
96  * @brief  Sha256计算获取摘要信息,并在计算成功的时候销毁hash句柄。
97  * @note   必须已经创建了hash句柄。
98  * @param  [in]    hash_handle 已创建的hash通道句柄
99  * @param  [out]   out 存储摘要信息的缓冲区地址指针。
100  * @param  [inout] out_len 存储摘要信息的缓冲区大小指针。输入为缓冲区长度,输出为实际摘要长度。
101  * @retval ERRCODE_SUCC 成功。
102  * @retval Other        失败,参考 @ref errcode_t 。
103  * @endif
104  */
105 errcode_t uapi_drv_cipher_sha256_finish(uint32_t hash_handle, uint8_t *out, uint32_t *out_len);
106 
107 /**
108  * @if Eng
109  * @brief  Sha256 calculation
110  * @param  [in]    buf Source buffer pointer.
111  * @param  [in]    len Source buffer size.
112  * @param  [out]   out Pointer to the buffer address for storing the summary information.
113  * @param  [inout] out_len Pointer to the size of the buffer for storing the summary information.
114                            The input is the buffer length, and the output is the actual digest length.
115  * @retval ERRCODE_SUCC Success.
116  * @retval Other        Failure. For details, see @ref errcode_t
117  * @else
118  * @brief  Sha256计算
119  * @param  [in]    buf 源缓冲区指针。
120  * @param  [in]    len 缓冲区大小。
121  * @param  [out]   out 存储摘要信息的缓冲区地址指针。
122  * @param  [in]    out_len 存储摘要信息的缓冲区大小指针。
123  * @retval ERRCODE_SUCC 成功。
124  * @retval Other        失败,参考 @ref errcode_t 。
125  * @endif
126  */
127 errcode_t uapi_drv_cipher_sha256(const uint8_t *buf, uint32_t len, uint8_t *out, uint32_t out_len);
128 
129 
130 /**
131  * @}
132  */
133 
134 #ifdef __cplusplus
135 #if __cplusplus
136 }
137 #endif
138 #endif
139 
140 #endif
141