mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-04-19 14:00:19 +02:00
Signed-off-by: Tavi <tavi@divested.dev> Co-authored-by: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
31 lines
873 B
C
31 lines
873 B
C
#ifndef RANDOM_H
|
|
#define RANDOM_H
|
|
|
|
#include "chacha.h"
|
|
#include "util.h"
|
|
|
|
#define RANDOM_CACHE_SIZE 256U
|
|
#define RANDOM_RESEED_SIZE (256U * 1024)
|
|
|
|
struct random_state {
|
|
unsigned index;
|
|
unsigned reseed;
|
|
chacha_ctx ctx;
|
|
u8 cache[RANDOM_CACHE_SIZE];
|
|
};
|
|
|
|
void random_state_init(struct random_state *state);
|
|
void random_state_init_from_random_state(struct random_state *state, struct random_state *source);
|
|
void get_random_bytes(struct random_state *state, void *buf, size_t size);
|
|
u16 get_random_u16(struct random_state *state);
|
|
u16 get_random_u16_uniform(struct random_state *state, u16 bound);
|
|
u64 get_random_u64(struct random_state *state);
|
|
u64 get_random_u64_uniform(struct random_state *state, u64 bound);
|
|
|
|
#if CONFIG_BLOCK_OPS_CHECK_SIZE && !defined(HAS_ARM_MTE)
|
|
#define h_memcpy_internal musl_memcpy
|
|
#else
|
|
#define h_memcpy_internal memcpy
|
|
#endif
|
|
|
|
#endif
|