• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef CRYPT_UTIL_RAND_H
17 #define CRYPT_UTIL_RAND_H
18 
19 #include "hitls_build.h"
20 #if defined(HITLS_CRYPTO_DRBG) || defined(HITLS_CRYPTO_CURVE25519) || \
21     defined(HITLS_CRYPTO_RSA) || defined(HITLS_CRYPTO_BN_RAND)
22 
23 #include <stdint.h>
24 #include "crypt_eal_rand.h"
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /**
30  * @brief   Random number registration
31  *
32  * @param   func [IN] Interface for obtaining random numbers
33  */
34 void CRYPT_RandRegist(CRYPT_EAL_RandFunc func);
35 
36 /**
37  * @brief   Generate a random number
38  *
39  * @param   rand [OUT] buffer of random number
40  * @param   randLen [IN] length of random number
41  *
42  * @retval  CRYPT_SUCCESS           A random number is generated successfully.
43  * @retval  CRYPT_NO_REGIST_RAND    The random number function is not registered.
44  * @retval  Error returned when the registered random number fails during the generate.
45  */
46 int32_t CRYPT_Rand(uint8_t *rand, uint32_t randLen);
47 
48 /**
49  * @brief   Random number registration
50  *
51  * @param   func [IN] Interface for obtaining random numbers
52  */
53 void CRYPT_RandRegistEx(CRYPT_EAL_RandFuncEx func);
54 
55 
56 /**
57  * @brief   Generate a random number
58  *
59  * @param   libCtx [IN] Library context
60  * @param   rand [OUT] buffer of random number
61  * @param   randLen [IN] length of random number
62  *
63  * @retval  CRYPT_SUCCESS           A random number is generated successfully.
64  * @retval  CRYPT_NO_REGIST_RAND    The random number function is not registered.
65  * @retval  Error returned when the registered random number fails during the generate.
66  */
67 int32_t CRYPT_RandEx(void *libCtx, uint8_t *rand, uint32_t randLen);
68 
69 #if defined(HITLS_CRYPTO_EAL)
70 #ifdef HITLS_CRYPTO_ENTROPY
71 /**
72  * @brief Global seed-drbg lock initialization
73  *
74  * @param ctx handle of ctx
75  */
76 int32_t EAL_SeedDrbgLockInit(void);
77 
78 /**
79  * @brief Global seed-drbg lock deinitialization
80  *
81  * @param ctx handle of ctx
82  */
83 void EAL_SeedDrbgLockDeInit(void);
84 #endif
85 #endif
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif
92 
93 #endif