Tor  0.4.3.0-alpha-dev
Macros | Typedefs | Functions
di_ops.h File Reference

Headers for di_ops.c. More...

#include "orconfig.h"
#include "lib/cc/torint.h"

Go to the source code of this file.

Macros

#define tor_memneq(a, b, sz)   (!tor_memeq((a),(b),(sz)))
 
#define fast_memcmp(a, b, c)   (memcmp((a),(b),(c)))
 
#define fast_memeq(a, b, c)   (0==memcmp((a),(b),(c)))
 
#define fast_memneq(a, b, c)   (0!=memcmp((a),(b),(c)))
 
#define dimap_free(map, free_fn)
 

Typedefs

typedef void(* dimap_free_fn) (void *)
 

Functions

int tor_memcmp (const void *a, const void *b, size_t sz)
 
int tor_memeq (const void *a, const void *b, size_t sz)
 
int safe_mem_is_zero (const void *mem, size_t sz)
 
void dimap_free_ (di_digest256_map_t *map, dimap_free_fn free_fn)
 
void dimap_add_entry (di_digest256_map_t **map, const uint8_t *key, void *val)
 
void * dimap_search (const di_digest256_map_t *map, const uint8_t *key, void *dflt_val)
 
int select_array_member_cumulative_timei (const uint64_t *entries, int n_entries, uint64_t total, uint64_t rand_val)
 

Detailed Description

Headers for di_ops.c.

Definition in file di_ops.h.

Macro Definition Documentation

◆ dimap_free

#define dimap_free (   map,
  free_fn 
)
Value:
do { \
dimap_free_((map), (free_fn)); \
(map) = NULL; \
} while (0)

Release all storage held in map, calling free_fn on each value as we go.

Additionally, set the pointer map to NULL.

Definition at line 63 of file di_ops.h.

◆ fast_memcmp

#define fast_memcmp (   a,
  b,
 
)    (memcmp((a),(b),(c)))

Alias for the platform's memcmp() function. This function is not data-independent: we define this alias so that we can mark cases where we are deliberately using a data-dependent memcmp() implementation.

Definition at line 28 of file di_ops.h.

◆ fast_memeq

#define fast_memeq (   a,
  b,
 
)    (0==memcmp((a),(b),(c)))

Alias for the platform's memcmp() function, for use in testing equality.

This function is not data-independent: we define this alias so that we can mark cases where we are deliberately using a data-dependent memcmp() implementation.

Definition at line 35 of file di_ops.h.

◆ fast_memneq

#define fast_memneq (   a,
  b,
 
)    (0!=memcmp((a),(b),(c)))

Alias for the platform's memcmp() function, for use in testing inequality.

This function is not data-independent: we define this alias so that we can mark cases where we are deliberately using a data-dependent memcmp() implementation.

Definition at line 42 of file di_ops.h.

◆ tor_memneq

#define tor_memneq (   a,
  b,
  sz 
)    (!tor_memeq((a),(b),(sz)))

Perform a constant-time comparison of the sz bytes at a and b, yielding true if they are different, and false otherwise.

Definition at line 21 of file di_ops.h.

Typedef Documentation

◆ dimap_free_fn

typedef void(* dimap_free_fn) (void *)

Type for a function used to free members of a di_digest256_map_t.

Definition at line 55 of file di_ops.h.

Function Documentation

◆ dimap_add_entry()

void dimap_add_entry ( di_digest256_map_t **  map,
const uint8_t *  key,
void *  val 
)

Adjust the map at *map, adding an entry for key -> val, where key is a DIGEST256_LEN-byte key.

The caller MUST NOT add a key that already appears in the map.

Definition at line 176 of file di_ops.c.

Referenced by construct_ntor_key_map().

◆ dimap_free_()

void dimap_free_ ( di_digest256_map_t map,
dimap_free_fn  free_fn 
)

Release all storage held in map, calling free_fn on each value as we go.

Definition at line 159 of file di_ops.c.

◆ dimap_search()

void* dimap_search ( const di_digest256_map_t map,
const uint8_t *  key,
void *  dflt_val 
)

Search the map at map for an entry whose key is key (a DIGEST256_LEN-byte key) returning the corresponding value if we found one, and returning dflt_val if the key wasn't found.

This operation takes an amount of time dependent only on the length of map, not on the position or presence of key within map.

Definition at line 200 of file di_ops.c.

Referenced by dimap_add_entry().

◆ safe_mem_is_zero()

int safe_mem_is_zero ( const void *  mem,
size_t  sz 
)

Return true iff the sz bytes at mem are all zero. Runs in time independent of the contents of mem.

Definition at line 224 of file di_ops.c.

Referenced by curve25519_public_key_is_ok(), ed25519_public_key_is_zero(), tor_digest256_is_zero(), and tor_digest_is_zero().

◆ select_array_member_cumulative_timei()

int select_array_member_cumulative_timei ( const uint64_t *  entries,
int  n_entries,
uint64_t  total,
uint64_t  rand_val 
)

Given an array of list of n_entries uint64_t values, whose sum is total, find the first i such that the total of all elements 0...i is greater than rand_val.

Try to perform this operation in a constant-time way.

Definition at line 259 of file di_ops.c.

Referenced by choose_array_element_by_weight().

◆ tor_memcmp()

int tor_memcmp ( const void *  a,
const void *  b,
size_t  len 
)

Timing-safe version of memcmp. As memcmp, compare the sz bytes at a with the sz bytes at b, and return less than 0 if the bytes at a lexically precede those at b, 0 if the byte ranges are equal, and greater than zero if the bytes at a lexically follow those at b.

This implementation differs from memcmp in that its timing behavior is not data-dependent: it should return in the same amount of time regardless of the contents of a and b.

Note that if all you care about is equality, this implementation is overkill: it would be better to use tor_memeq() or tor_memneq().

Definition at line 31 of file di_ops.c.

Referenced by compare_digest_to_fetch_hsdir_index(), compare_digest_to_routerstatus_entry(), compare_digest_to_store_first_hsdir_index(), compare_digest_to_store_second_hsdir_index(), compare_digest_to_vote_routerstatus_entry(), compare_digests256_(), compare_digests_(), compare_node_fetch_hsdir_index(), compare_node_store_first_hsdir_index(), compare_node_store_second_hsdir_index(), compare_srvs_(), crypto_pk_cmp_keys(), hs_address_is_valid(), and service_authorized_client_cmp().

◆ tor_memeq()

int tor_memeq ( const void *  a,
const void *  b,
size_t  sz 
)

Timing-safe memory comparison. Return true if the sz bytes at a are the same as the sz bytes at b, and 0 otherwise.

This implementation differs from !memcmp(a,b,sz) in that its timing behavior is not data-dependent: it should return in the same amount of time regardless of the contents of a and b. It differs from !tor_memcmp(a,b,sz) by being faster.

Definition at line 107 of file di_ops.c.

Referenced by authority_cert_get_by_digests(), authority_cert_get_by_sk_digest(), bridge_has_digest(), channel_get_for_extend(), circuit_get_ready_rend_circ_by_rend_data(), decrypt_desc_layer(), digest256map_entries_eq(), digest_list_contains_best_consensus(), digestmap_entries_eq(), dimap_search(), dump_desc_fifo_bump_hash(), ed25519_pubkey_eq(), entry_guard_learned_bridge_identity(), environment_variable_names_equal(), find_bridge_by_digest(), find_intro_circuit(), find_intro_point(), fp_pair_map_entries_eq(), get_bridge_dl_status_by_id(), get_sampled_guard_with_id(), hex_digest_nickname_matches(), hs_ntor_client_rendezvous2_mac_is_good(), hs_purge_hid_serv_from_last_hid_serv_requests(), keypin_check_and_add_impl(), keypin_ents_eq_ed(), memeq_opt(), microdesc_eq_(), rend_service_get_by_pk_digest(), rend_service_get_by_service_id(), router_differences_are_cosmetic(), router_digest_is_me(), router_extrainfo_digest_is_me(), router_get_fallback_dirserver_by_digest(), router_get_trusteddirserver_by_digest(), routerinfo_incompatible_with_extrainfo(), routerstatus_has_changed(), smartlist_contains_digest(), tor_cert_eq(), and trusteddirserver_get_by_v3_auth_digest().