di_ops.h 2.0 KB

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