1 /* Copyright (c) 2018-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
6 * \brief Implementation for a set of digests
10 #include "lib/container/bloomfilt.h"
11 #include "lib/crypt_ops/crypto_rand.h"
12 #include "lib/defs/digest_sizes.h"
13 #include "lib/crypt_ops/digestset.h"
14 #include "ext/siphash.h"
16 /* Wrap our hash function to have the signature that the bloom filter
19 bloomfilt_digest_hash(const struct sipkey
*key
,
22 return siphash24(item
, DIGEST_LEN
, key
);
26 * Allocate and return an digestset, suitable for holding up to
27 * <b>max_guess</b> distinct values.
30 digestset_new(int max_guess
)
32 uint8_t k
[BLOOMFILT_KEY_LEN
];
33 crypto_rand((void*)k
, sizeof(k
));
34 return bloomfilt_new(max_guess
, bloomfilt_digest_hash
, k
);
38 * Add <b>digest</b> to <b>set</b>.
40 * All future queries for <b>digest</b> in set will return true. Removing
41 * items is not possible.
44 digestset_add(digestset_t
*set
, const char *digest
)
46 bloomfilt_add(set
, digest
);
50 * Return true if <b>digest</b> is a member of <b>set</b>. (And probably,
51 * return false if <b>digest</b> is not a member of set.)
54 digestset_probably_contains(const digestset_t
*set
,
57 return bloomfilt_probably_contains(set
, digest
);