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 ES_ENTROPY_POOL_H 17 #define ES_ENTROPY_POOL_H 18 19 #include "hitls_build.h" 20 #if defined(HITLS_CRYPTO_ENTROPY) && defined(HITLS_CRYPTO_ENTROPY_SYS) 21 22 #include <stdint.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 typedef struct { 28 uint8_t *buf; // queue data 29 uint32_t front; // queue head 30 uint32_t rear; // queue tail 31 uint32_t maxSize; // queue capacity + 1 32 } ES_EntropyPool; 33 34 /* Entropy pool initialization. */ 35 ES_EntropyPool *ES_EntropyPoolInit(uint32_t size); 36 37 /* Entropy pool deinitialization. */ 38 void ES_EntropyPoolDeInit(ES_EntropyPool *pool); 39 40 /* Obtains the maximum capacity of the entropy pool. */ 41 int32_t ES_EntropyPoolGetMaxSize(ES_EntropyPool *pool); 42 43 /* Obtains the current data volume of the entropy pool. */ 44 uint32_t ES_EntropyPoolGetCurSize(ES_EntropyPool *pool); 45 46 /* Obtains entropy data from the entropy pool. */ 47 int32_t ES_EntropyPoolPushBytes(ES_EntropyPool *pool, uint8_t *buf, uint32_t bufLen); 48 49 /* Compress entropy data into the entropy pool. */ 50 uint32_t ES_EntropyPoolPopBytes(ES_EntropyPool *pool, uint8_t *data, uint32_t size); 51 52 #ifdef __cplusplus 53 } 54 #endif 55 56 #endif 57 58 #endif