* This file is part of the openHiTLS project.
*
* openHiTLS is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#ifndef ES_NOISE_SOURCE_H
#define ES_NOISE_SOURCE_H
#include "hitls_build.h"
#if defined(HITLS_CRYPTO_ENTROPY) && defined(HITLS_CRYPTO_ENTROPY_SYS)
#include <stdint.h>
#include "bsl_list.h"
#include "es_health_test.h"
#include "crypt_types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
bool enableTest;
bool autoTest;
bool isEnable;
bool isInit;
char *name;
void *para;
void *usrdata;
void *(*init)(void *para);
int32_t (*read)(void *usrdata, uint32_t timeout, uint8_t *buf, uint32_t bufLen);
void (*deinit)(void *usrdata);
uint32_t minEntropy;
ES_HealthTest state;
} ES_NoiseSource;
BslList *ES_NsListCreat(void);
int32_t ES_NsListInit(BslList *nsList, bool enableTest);
void ES_NsListDeinit(BslList *nsList);
void ES_NsListFree(BslList *nsList);
* @brief add ns
*
* @param nsList [IN] noise source list
* @param name [IN] Noise source name, which must be unique.
* @param autoTest [IN] Whether the noise source automatically performs the health test.
* @param minEntropy [IN] minimum entropy, bit entropy contained in a byte.
* @param method [IN] noise source callback Interface.
* @param para [IN] noise source health test parameter.
*
* @return CRYPT_SUCCESS succeeded.
* For other error codes, see crypt_error.h.
*/
int32_t ES_NsAdd(BslList *nsList, const char *name, bool autoTest, uint32_t minEntropy,
const CRYPT_EAL_NsMethod *method, const CRYPT_EAL_NsTestPara *para);
* @brief remove ns
*
* @param nsList [IN] noise source list
* @param name [IN] Noise source name, which must be unique.
*
* @return CRYPT_SUCCESS succeeded.
* For other error codes, see crypt_error.h.
*/
int32_t ES_NsRemove(BslList *nsList, const char *name);
* @brief Read the raw noise data.
*
* @param ns [IN] noise source handle
* @param buf [IN] the raw noise data buffer.
* @param bufLen [IN] the length of the raw noise data.
*
* @return CRYPT_SUCCESS succeeded.
* For other error codes, see crypt_error.h.
*/
int32_t ES_NsRead(ES_NoiseSource *ns, uint8_t *buf, uint32_t bufLen);
* @brief Obtains the minimum value of the minimum entropy.
*
* @param nsList [IN] noise source list
*
* @return CRYPT_SUCCESS succeeded.
* For other error codes, see crypt_error.h.
*/
uint32_t ES_NsListGetMinEntropy(BslList *nsList);
ES_NoiseSource *ES_CpuJitterGetCtx(void);
ES_NoiseSource *ES_TimeStampGetCtx(void);
#ifdef __cplusplus
}
#endif
#endif
#endif