• 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  *
15  * Description: Provides trng driver header \n
16  *
17  * History: \n
18  * 2022-08-09, Create file. \n
19  */
20 #ifndef TRNG_H
21 #define TRNG_H
22 
23 #include <stdint.h>
24 #include "errcode.h"
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif
30 #endif
31 
32 /**
33  * @defgroup drivers_driver_trng Trng
34  * @ingroup  drivers_driver
35  * @{
36  */
37 
38 /**
39  * @if Eng
40  * @brief  trng rand buffer updata type
41  * @else
42  * @brief  随机数缓冲区更新类型
43  * @endif
44  */
45 typedef enum {
46     TRNG_RAND_BUF_UPDATA_ALL,
47     TRNG_RAND_BUF_UPDATA_UP_SIDE,
48     TRNG_RAND_BUF_UPDATA_DOWN_SIDE,
49 } trng_rand_buf_updata_t;
50 
51 /**
52  * @if Eng
53  * @brief  obtaining hardware random numbers.
54  * @note   random number of the size of the uint32_t type,generate random numbers of other sizes, which need to be
55            called cyclically.
56  * @param  [in]  randnum Pointer to the buffer where the generated random number is stored
57  * @retval ERRCODE_SUCC Success.
58  * @retval Other        Failure. For details, see @ref errcode_t
59  * @else
60  * @brief  获取硬件随机数
61  * @note   生成uint32_t类型大小的随机数,生成其他大小的随机数,需要循环调用该接口
62  * @param  [in]  randnum 指向存储生成的随机数的缓冲区的指针
63  * @retval ERRCODE_SUCC 成功
64  * @retval Other        失败,参考 @ref errcode_t
65  * @endif
66  */
67 errcode_t uapi_drv_cipher_trng_get_random(uint32_t *randnum);
68 
69 /**
70  * @if Eng
71  * @brief  obtains a hardware random number of a specified size.
72  * @param  [in]  randnum Pointer to the buffer where the generated random number is stored
73  * @param  [in]  size size of the generated random number
74  * @retval ERRCODE_SUCC Success.
75  * @retval Other        Failure. For details, see @ref errcode_t
76  * @else
77  * @brief  获取指定大小的硬件随机数
78  * @param  [in]  randnum 指向存储生成的随机数的缓冲区的指针
79  * @param  [in]  size 生成随机数的大小
80  * @retval ERRCODE_SUCC 成功
81  * @retval Other        失败,参考 @ref errcode_t
82  * @endif
83  */
84 errcode_t uapi_drv_cipher_trng_get_random_bytes(uint8_t *randnum, uint32_t size);
85 
86 /**
87  * @if Eng
88  * @brief  updata the random fuffer in multi-core scenarios
89  * @param  [in]  updata random number buffer update type
90  * @else
91  * @brief  多核场景下随机数缓冲区更新
92  * @param  [in]  updata 随机数缓冲区更新类型
93  * @endif
94  */
95 void uapi_drv_cipher_trng_random_buffer_init(trng_rand_buf_updata_t updata);
96 
97 /**
98  * @if Eng
99  * @brief  register the random ipc update handle in multi-core scenarios
100  * @else
101  * @brief  多核场景下随机数IPC更新句柄注册
102  * @endif
103  */
104 void uapi_drv_cipher_trng_ipc_updata_reigister(void);
105 
106 /**
107  * @}
108  */
109 
110 #ifdef __cplusplus
111 #if __cplusplus
112 }
113 #endif
114 #endif
115 
116 #endif
117