Merge branch 'maint-0.2.4' into release-0.2.4
[tor.git] / src / common / di_ops.h
blobd93534b69b26b67a893b0f85fa3c6d8f816fde28
1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2013, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 /**
7 * \file di_ops.h
8 * \brief Headers for di_ops.c
9 **/
11 #ifndef TOR_DI_OPS_H
12 #define TOR_DI_OPS_H
14 #include "orconfig.h"
15 #include "torint.h"
17 int tor_memcmp(const void *a, const void *b, size_t sz);
18 int tor_memeq(const void *a, const void *b, size_t sz);
19 #define tor_memneq(a,b,sz) (!tor_memeq((a),(b),(sz)))
21 /** Alias for the platform's memcmp() function. This function is
22 * <em>not</em> data-independent: we define this alias so that we can
23 * mark cases where we are deliberately using a data-dependent memcmp()
24 * implementation.
26 #define fast_memcmp(a,b,c) (memcmp((a),(b),(c)))
27 #define fast_memeq(a,b,c) (0==memcmp((a),(b),(c)))
28 #define fast_memneq(a,b,c) (0!=memcmp((a),(b),(c)))
30 int safe_mem_is_zero(const void *mem, size_t sz);
32 /** A type for a map from DIGEST256_LEN-byte blobs to void*, such that
33 * data lookups take an amount of time proportional only to the size
34 * of the map, and not to the position or presence of the item in the map.
36 * Not efficient for large maps! */
37 typedef struct di_digest256_map_t di_digest256_map_t;
38 typedef void (*dimap_free_fn)(void *);
40 void dimap_free(di_digest256_map_t *map, dimap_free_fn free_fn);
41 void dimap_add_entry(di_digest256_map_t **map,
42 const uint8_t *key, void *val);
43 void *dimap_search(const di_digest256_map_t *map, const uint8_t *key,
44 void *dflt_val);
46 #endif