48#ifdef HAVE_SYS_TYPES_H
57#ifdef NOINHERIT_CAN_FAIL
62#define PID_FIELD_LEN sizeof(pid_t)
64#define PID_FIELD_LEN 0
69#define SEED_LEN (CRYPTO_FAST_RNG_SEED_LEN)
78#define BUFLEN (MAPLEN - 2*sizeof(uint16_t) - SEED_LEN - PID_FIELD_LEN)
83#define RESEED_AFTER 16
87#define KEY_LEN (CRYPTO_FAST_RNG_SEED_LEN - CIPHER_IV_LEN)
90#define KEY_BITS (KEY_LEN * 8)
93CTASSERT(KEY_BITS == 128 || KEY_BITS == 192 || KEY_BITS == 256);
126CTASSERT(
sizeof(
struct cbuf_t) == BUFLEN+SEED_LEN);
140 uint8_t seed[SEED_LEN];
143 memwipe(seed, 0,
sizeof(seed));
166 memcpy(result->buf.
seed, seed, SEED_LEN);
176 result->owner = getpid();
184 "We failed to create a non-inheritable memory region, even "
185 "though we believed such a failure to be impossible! This is "
186 "probably a bug in Tor support for your platform; please report "
209static inline crypto_cipher_t *
226 uint8_t seedbuf[SEED_LEN];
256 tor_assert_unreached();
262 memset(&rng->buf, 0,
sizeof(rng->buf));
264 crypto_cipher_free(c);
310 size_t bytes_to_yield = n;
312 while (bytes_to_yield) {
316 const size_t to_copy = MIN(rng->
bytes_left, bytes_to_yield);
319 uint8_t *copy_from = rng->buf.
bytes +
321 memcpy(out, copy_from, to_copy);
322 memset(copy_from, 0, to_copy);
325 bytes_to_yield -= to_copy;
336 if (PREDICT_UNLIKELY(n > BUFLEN)) {
341 uint8_t seed[SEED_LEN];
346 crypto_cipher_free(c);
347 memwipe(seed, 0,
sizeof(seed));
354#if defined(TOR_UNIT_TESTS)
358crypto_fast_rng_get_bytes_used_per_stream(
void)
381 if (PREDICT_UNLIKELY(rng == NULL)) {
399 crypto_fast_rng_free(rng);
Macro definitions for MIN, MAX, and CLAMP.
void * tor_threadlocal_get(tor_threadlocal_t *threadlocal)
void tor_threadlocal_destroy(tor_threadlocal_t *threadlocal)
void tor_threadlocal_set(tor_threadlocal_t *threadlocal, void *value)
int tor_threadlocal_init(tor_threadlocal_t *threadlocal)
void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *buf, size_t len)
crypto_cipher_t * crypto_cipher_new_with_iv_and_bits(const uint8_t *key, const uint8_t *iv, int bits)
Headers for crypto_cipher.c.
void crypto_xof_squeeze_bytes(crypto_xof_t *xof, uint8_t *out, size_t len)
crypto_xof_t * crypto_xof_new(void)
void crypto_xof_add_bytes(crypto_xof_t *xof, const uint8_t *data, size_t len)
Headers for crypto_digest.c.
#define crypto_xof_free(xof)
void crypto_strongest_rand(uint8_t *out, size_t out_len)
Common functions for using (pseudo-)random number generators.
crypto_fast_rng_t * get_thread_fast_rng(void)
static tor_threadlocal_t thread_rng
static void crypto_fast_rng_add_entopy(crypto_fast_rng_t *rng)
crypto_fast_rng_t * crypto_fast_rng_new_from_seed(const uint8_t *seed)
static void crypto_fast_rng_getbytes_impl(crypto_fast_rng_t *rng, uint8_t *out, const size_t n)
void crypto_fast_rng_free_(crypto_fast_rng_t *rng)
void destroy_thread_fast_rng(void)
void crypto_rand_fast_init(void)
static void crypto_fast_rng_refill(crypto_fast_rng_t *rng)
void crypto_rand_fast_shutdown(void)
static crypto_cipher_t * cipher_from_seed(const uint8_t *seed)
void crypto_fast_rng_getbytes(crypto_fast_rng_t *rng, uint8_t *out, size_t n)
crypto_fast_rng_t * crypto_fast_rng_new(void)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
Compile-time assertions: CTASSERT(expression).
CTASSERT(NUMBER_SECOND_GUARDS< 20)
void tor_munmap_anonymous(void *mapping, size_t sz)
void * tor_mmap_anonymous(size_t sz, unsigned flags, inherit_res_t *inherit_result_out)
#define ANONMAP_NOINHERIT
Macros to manage assertions, fatal and non-fatal.