API参考
载入中...
搜索中...
未找到
crypt_entropy.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_ENTROPY_H
17#define CRYPT_ENTROPY_H
18
19#include "hitls_build.h"
20#ifdef HITLS_CRYPTO_ENTROPY
21
22#include <stdint.h>
23#include <stdbool.h>
24#include "crypt_types.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
61#ifdef HITLS_CRYPTO_ENTROPY_SYS
62typedef struct ES_Entropy ENTROPY_EntropySource;
63
64typedef struct {
65 uint32_t algId;
66 void *md;
67} ENTROPY_CFPara;
68
69/* Entropy source model APIs provided by HiTLS. */
70
71/* Creating an entropy source. */
72ENTROPY_EntropySource *ENTROPY_EsNew(void);
73
74/* release entropy source. */
75void ENTROPY_EsFree(ENTROPY_EntropySource *ctx);
76
77/* Initialize Entropy Source. */
78int32_t ENTROPY_EsInit(ENTROPY_EntropySource *ctx);
79
80/* Deinitialize the entropy source. */
81void ENTROPY_EsDeinit(ENTROPY_EntropySource *ctx);
82
83/* Interface for Setting the Entropy Source. */
84int32_t ENTROPY_EsCtrl(ENTROPY_EntropySource *ctx, int32_t cmd, void *data, uint32_t len);
85
86/* Obtaining Entropy Data. */
87uint32_t ENTROPY_EsEntropyGet(ENTROPY_EntropySource *ctx, uint8_t *data, uint32_t len);
88
89/* Collect entropy data. */
90int32_t ENTROPY_EsEntropyGather(ENTROPY_EntropySource *es);
91#endif
92
93typedef struct EntropySeedPool ENTROPY_SeedPool;
94
95
96typedef uint32_t (*EntropyGet)(void *ctx, uint8_t *buf, uint32_t bufLen);
97
98/* create seed-pool handles */
99ENTROPY_SeedPool *ENTROPY_SeedPoolNew(bool isCreateNullPool);
100
101/* Adding an entropy source */
102int32_t ENTROPY_SeedPoolAddEs(ENTROPY_SeedPool *pool, const CRYPT_EAL_EsPara *para);
103
104/* Interface for releasing the seed pool */
105void ENTROPY_SeedPoolFree(ENTROPY_SeedPool *pool);
106
107/* Interface for collecting entropy data */
108uint32_t ENTROPY_SeedPoolCollect(ENTROPY_SeedPool *pool, bool isNpesUsed, uint32_t needEntropy,
109 uint8_t *data, uint32_t *len);
110
111/* Check whether the seed pool contains physical or non-physical entropy sources. */
112bool ENTROPY_SeedPoolCheckState(ENTROPY_SeedPool *seedPool, bool isNpesUsed);
113
114/* Obtains the minimum entropy of the entropy source. */
115uint32_t ENTROPY_SeedPoolGetMinEntropy(ENTROPY_SeedPool *seedPool);
116
117typedef int32_t (*ExternalConditioningFunction)(uint32_t algId, uint8_t *in, uint32_t inLen, uint8_t *out,
118 uint32_t *outLen);
119
120typedef struct EcfCtx {
121 uint32_t algId;
122 uint32_t outLen;
123 ExternalConditioningFunction conFunc;
124} ENTROPY_ECFCtx;
125
137int32_t ENTROPY_GetFullEntropyInput(void *ctx, ENTROPY_SeedPool *pool, bool isNpesUsed, uint32_t needEntropy,
138 uint8_t *data, uint32_t len);
139
140#ifdef __cplusplus
141}
142#endif
143
144#endif // HITLS_CRYPTO_ENTROPY
145
146#endif // CRYPT_ENTROPY_H
定义 crypt_types.h:236