Tor 0.4.9.1-alpha-dev
di_ops.h
Go to the documentation of this file.
1/* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4/* See LICENSE for licensing information */
5
6/**
7 * \file di_ops.h
8 * \brief Headers for di_ops.c
9 **/
10
11#ifndef TOR_DI_OPS_H
12#define TOR_DI_OPS_H
13
14#include "orconfig.h"
15#include "lib/cc/torint.h"
16
17int tor_memcmp(const void *a, const void *b, size_t sz);
18int tor_memeq(const void *a, const void *b, size_t sz);
19/** Perform a constant-time comparison of the <b>sz</b> bytes at <b>a</b> and
20 * <b>b</b>, yielding true if they are different, and false otherwise. */
21#define tor_memneq(a,b,sz) (!tor_memeq((a),(b),(sz)))
22
23/** Alias for the platform's memcmp() function. This function is
24 * <em>not</em> data-independent: we define this alias so that we can
25 * mark cases where we are deliberately using a data-dependent memcmp()
26 * implementation.
27 */
28#define fast_memcmp(a,b,c) (memcmp((a),(b),(c)))
29/** Alias for the platform's memcmp() function, for use in testing equality.
30 *
31 * This function is <em>not</em> data-independent: we define this alias so
32 * that we can mark cases where we are deliberately using a data-dependent
33 * memcmp() implementation.
34 */
35#define fast_memeq(a,b,c) (0==memcmp((a),(b),(c)))
36/** Alias for the platform's memcmp() function, for use in testing inequality.
37 *
38 * This function is <em>not</em> data-independent: we define this alias so
39 * that we can mark cases where we are deliberately using a data-dependent
40 * memcmp() implementation.
41 */
42#define fast_memneq(a,b,c) (0!=memcmp((a),(b),(c)))
43
44int safe_mem_is_zero(const void *mem, size_t sz);
45
46/** A type for a map from DIGEST256_LEN-byte blobs to void*, such that
47 * data lookups take an amount of time proportional only to the size
48 * of the map, and not to the position or presence of the item in the map.
49 *
50 * Not efficient for large maps! */
52/**
53 * Type for a function used to free members of a di_digest256_map_t.
54 **/
55typedef void (*dimap_free_fn)(void *);
56
58/**
59 * @copydoc dimap_free_
60 *
61 * Additionally, set the pointer <b>map</b> to NULL.
62 **/
63#define dimap_free(map, free_fn) \
64 do { \
65 dimap_free_((map), (free_fn)); \
66 (map) = NULL; \
67 } while (0)
69 const uint8_t *key, void *val);
70void *dimap_search(const di_digest256_map_t *map, const uint8_t *key,
71 void *dflt_val);
72int select_array_member_cumulative_timei(const uint64_t *entries,
73 int n_entries,
74 uint64_t total, uint64_t rand_val);
75
76void memcpy_if_true_timei(bool s, void *dest, const void *src, size_t n);
77
78#endif /* !defined(TOR_DI_OPS_H) */
void dimap_add_entry(di_digest256_map_t **map, const uint8_t *key, void *val)
Definition: di_ops.c:176
void memcpy_if_true_timei(bool s, void *dest, const void *src, size_t n)
Definition: di_ops.c:296
void(* dimap_free_fn)(void *)
Definition: di_ops.h:55
int tor_memeq(const void *a, const void *b, size_t sz)
Definition: di_ops.c:107
int select_array_member_cumulative_timei(const uint64_t *entries, int n_entries, uint64_t total, uint64_t rand_val)
Definition: di_ops.c:259
int safe_mem_is_zero(const void *mem, size_t sz)
Definition: di_ops.c:224
void dimap_free_(di_digest256_map_t *map, dimap_free_fn free_fn)
Definition: di_ops.c:159
int tor_memcmp(const void *a, const void *b, size_t sz)
Definition: di_ops.c:31
void * dimap_search(const di_digest256_map_t *map, const uint8_t *key, void *dflt_val)
Definition: di_ops.c:200
uint8_t key[32]
Definition: di_ops.c:151
Integer definitions used throughout Tor.