| 1 | /* @title: Entropy Pool */ |
|---|---|
| 2 | #pragma once |
| 3 | #include <math/units.h> |
| 4 | #include <stdint.h> |
| 5 | #include <sync/spinlock.h> |
| 6 | |
| 7 | #define ENTROPY_POOL_SIZE 64 // 512 bits |
| 8 | #define ENTROPY_MAX_BITS to_bits(ENTROPY_POOL_SIZE) |
| 9 | |
| 10 | struct entropy_pool { |
| 11 | uint8_t buffer[ENTROPY_POOL_SIZE]; // Raw pool data |
| 12 | uint64_t write_pos; // Circular buffer write position |
| 13 | uint64_t entropy_bits; // Estimated entropy in bits |
| 14 | struct spinlock lock; // To protect concurrent access |
| 15 | }; |
| 16 | |
| 17 | void entropy_pool_init(struct entropy_pool *pool); |
| 18 | void entropy_pool_add(struct entropy_pool *pool, const uint8_t *data, |
| 19 | uint64_t len, uint64_t entropy_bits); |
| 20 | void entropy_pool_decrease(struct entropy_pool *pool, uint64_t bits); |
| 21 | void entropy_pool_seed(struct entropy_pool *pool); |
| 22 | void entropy_pool_reseed(struct entropy_pool *pool); |
| 23 |