tor  0.4.2.0-alpha-dev
digestset.c
Go to the documentation of this file.
1 /* Copyright (c) 2018-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
9 #include "orconfig.h"
12 #include "lib/defs/digest_sizes.h"
14 #include "ext/siphash.h"
15 
16 /* Wrap our hash function to have the signature that the bloom filter
17  * needs. */
18 static uint64_t
19 bloomfilt_digest_hash(const struct sipkey *key,
20  const void *item)
21 {
22  return siphash24(item, DIGEST_LEN, key);
23 }
24 
30 digestset_new(int max_guess)
31 {
32  uint8_t k[BLOOMFILT_KEY_LEN];
33  crypto_rand((void*)k, sizeof(k));
34  return bloomfilt_new(max_guess, bloomfilt_digest_hash, k);
35 }
36 
43 void
44 digestset_add(digestset_t *set, const char *digest)
45 {
46  bloomfilt_add(set, digest);
47 }
48 
53 int
55  const char *digest)
56 {
57  return bloomfilt_probably_contains(set, digest);
58 }
Common functions for using (pseudo-)random number generators.
void bloomfilt_add(bloomfilt_t *set, const void *item)
Definition: bloomfilt.c:38
void digestset_add(digestset_t *set, const char *digest)
Definition: digestset.c:44
bloomfilt_t * bloomfilt_new(int max_elements, bloomfilt_hash_fn hashfn, const uint8_t *random_key)
Definition: bloomfilt.c:78
#define BLOOMFILT_KEY_LEN
Definition: bloomfilt.h:26
#define DIGEST_LEN
Definition: digest_sizes.h:20
Header for bloomfilt.c.
Types to handle sets of digests, based on bloom filters.
int digestset_probably_contains(const digestset_t *set, const char *digest)
Definition: digestset.c:54
int bloomfilt_probably_contains(const bloomfilt_t *set, const void *item)
Definition: bloomfilt.c:54
Definitions for common sizes of cryptographic digests.
digestset_t * digestset_new(int max_guess)
Definition: digestset.c:30