API参考
载入中...
搜索中...
未找到
crypt_drbg.h
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_DRBG_H
17#define CRYPT_DRBG_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_DRBG
21
22#include <stdint.h>
23#include <stdbool.h>
24#include "crypt_types.h"
25#include "crypt_local_types.h"
26#ifdef HITLS_BSL_PARAMS
27#include "bsl_params.h"
28#include "crypt_params_key.h"
29#endif
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35// hlcheck : health testing
36// pr : prediction_resistance
37
38typedef struct DrbgCtx DRBG_Ctx;
39
40#define DRBG_MAX_LEN (0x7ffffff0)
41#define DRBG_MAX_REQUEST (1 << 16)
42
43#ifndef DRBG_MAX_RESEED_INTERVAL
44#define DRBG_MAX_RESEED_INTERVAL (10000)
45#endif
46
47/* Default reseed intervals */
48# define DRBG_RESEED_INTERVAL (1 << 8)
49# define DRBG_TIME_INTERVAL (60 * 60) /* 1 hour */
50
51#ifndef DRBG_MAX_REQUEST_SM3
52#define DRBG_MAX_REQUEST_SM3 (1 << 5)
53#endif
54
55#ifndef DRBG_MAX_REQUEST_SM4
56#define DRBG_MAX_REQUEST_SM4 (1 << 4)
57#endif
58
59#ifndef DRBG_RESEED_INTERVAL_GM1
60#define DRBG_RESEED_INTERVAL_GM1 (1 << 20)
61#endif
62
63#ifndef DRBG_RESEED_TIME_GM1
64#define DRBG_RESEED_TIME_GM1 (600)
65#endif
66
67#ifndef DRBG_RESEED_INTERVAL_GM2
68#define DRBG_RESEED_INTERVAL_GM2 (1 << 10)
69#endif
70
71#ifndef DRBG_RESEED_TIME_GM2
72#define DRBG_RESEED_TIME_GM2 (60)
73#endif
74
75#ifndef HITLS_CRYPTO_DRBG_GM_LEVEL
76#define HITLS_CRYPTO_DRBG_GM_LEVEL 2
77#endif
78
79#ifndef HITLS_CRYPTO_RESEED_INTERVAL_GM
80#if HITLS_CRYPTO_DRBG_GM_LEVEL == 1
81#define HITLS_CRYPTO_RESEED_INTERVAL_GM DRBG_RESEED_INTERVAL_GM1
82#else
83#define HITLS_CRYPTO_RESEED_INTERVAL_GM DRBG_RESEED_INTERVAL_GM2
84#endif
85#endif
86
87#ifdef HITLS_CRYPTO_ENTROPY
88 #ifndef HITLS_SEED_DRBG_INIT_RAND_ALG
89 #ifdef HITLS_CRYPTO_AES
90 #define HITLS_SEED_DRBG_INIT_RAND_ALG CRYPT_RAND_AES256_CTR
91 #else
92 #error "HITLS_SEED_DRBG_INIT_RAND_ALG configuration error."
93 #endif
94 #endif
95#endif
96
97#ifndef HITLS_CRYPTO_DRBG_RESEED_TIME_GM
98#if HITLS_CRYPTO_DRBG_GM_LEVEL == 1
99#define HITLS_CRYPTO_DRBG_RESEED_TIME_GM DRBG_RESEED_TIME_GM1
100#else
101#define HITLS_CRYPTO_DRBG_RESEED_TIME_GM DRBG_RESEED_TIME_GM2
102#endif
103#endif
104
105#define DRBG_HASH_MAX_MDSIZE (64)
106
107typedef struct {
108 CRYPT_RAND_AlgId drbgId;
109 int32_t depId;
110 uint32_t type;
111} DrbgIdMap;
112
126DRBG_Ctx *DRBG_New(void *libCtx, int32_t algId, CRYPT_RandSeedMethod *seedMethod, void *seedCtx);
127
128#ifdef HITLS_BSL_PARAMS
141DRBG_Ctx *DRBG_NewEx(void *libCtx, int32_t algId, BSL_Param *param);
142#endif
143
153void DRBG_Free(DRBG_Ctx *ctx);
154
171int32_t DRBG_Instantiate(DRBG_Ctx *ctx, const uint8_t *person, uint32_t persLen);
172
189int32_t DRBG_Reseed(DRBG_Ctx *ctx, const uint8_t *adin, uint32_t adinLen);
190
210int32_t DRBG_Generate(DRBG_Ctx *ctx,
211 uint8_t *out, uint32_t outLen,
212 const uint8_t *adin, uint32_t adinLen, bool pr);
213
232int32_t DRBG_GenerateBytes(DRBG_Ctx *ctx, uint8_t *out, uint32_t outLen,
233 const uint8_t *adin, uint32_t adinLen);
234
245int32_t DRBG_Uninstantiate(DRBG_Ctx *ctx);
246
258int32_t DRBG_Ctrl(DRBG_Ctx *ctx, int32_t opt, void *val, uint32_t len);
259
269const DrbgIdMap *DRBG_GetIdMap(CRYPT_RAND_AlgId id);
270
271#ifdef __cplusplus
272}
273#endif
274
275#endif // HITLS_CRYPTO_DRBG
276
277#endif // CRYPT_DRBG_H
Parameter identifiers
CRYPT_RAND_AlgId
定义 crypt_algid.h:41
定义 crypt_types.h:587