tor  master
Macros | Typedefs | Functions
di_ops.h File Reference

Headers for di_ops.c. More...

#include "orconfig.h"
#include "torint.h"
Include dependency graph for di_ops.h:
This graph shows which files directly or indirectly include this file:

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 struct di_digest256_map_t di_digest256_map_t
 
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.

Macro Definition Documentation

◆ dimap_free

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

◆ 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.

Typedef Documentation

◆ di_digest256_map_t

A type for a map from DIGEST256_LEN-byte blobs to void*, such that data lookups take an amount of time proportional only to the size of the map, and not to the position or presence of the item in the map.

Not efficient for large maps!

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function: