@@ -60,16 +60,19 @@ MINISKETCH_API uint32_t minisketch_implementation_max(void);
6060 */
6161MINISKETCH_API int minisketch_implementation_supported (uint32_t bits, uint32_t implementation);
6262
63- /* * Construct a sketch for a given element size, implementation and capacity .
63+ /* * Construct a sketch for a given element size, implementation, capacity, and RNG seed .
6464 *
6565 * If the combination of `bits` and `implementation` is unavailable, or when
6666 * OOM occurs, NULL is returned. If minisketch_implementation_supported
6767 * returns 1 for the specified bits and implementation, this will always succeed
6868 * (except when allocation fails).
6969 *
70+ * To protect against bad performance on maliciously-created sketches, it is
71+ * to use strong randomness for the provided seed value.
72+ *
7073 * If the result is not NULL, it must be destroyed using minisketch_destroy.
7174 */
72- MINISKETCH_API minisketch* minisketch_create (uint32_t bits, uint32_t implementation, size_t capacity);
75+ MINISKETCH_API minisketch* minisketch_create (uint32_t bits, uint32_t implementation, size_t capacity, uint64_t seed );
7376
7477/* * Get the element size of a sketch in bits. */
7578MINISKETCH_API uint32_t minisketch_bits (const minisketch* sketch);
@@ -82,14 +85,11 @@ MINISKETCH_API uint32_t minisketch_implementation(const minisketch* sketch);
8285
8386/* * Set the seed for randomizing algorithm choices to a fixed value.
8487 *
85- * By default, sketches are initialized with a random seed. This is important
86- * to avoid scenarios where an attacker could force worst-case behavior.
87- *
88- * This function initializes the seed to a user-provided value (any 64-bit
89- * integer is acceptable, regardless of field size).
88+ * This is equivalent to recreating the sketch with a different RNG seed.
9089 *
9190 * When seed is -1, a fixed internal value with predictable behavior is
92- * used. It is only intended for testing.
91+ * used. It is only intended for testing. Note that minisketch_create does
92+ * assign special meaning to seed = -1.
9393 */
9494MINISKETCH_API void minisketch_set_seed (minisketch* sketch, uint64_t seed);
9595
@@ -263,16 +263,16 @@ class Minisketch
263263 * ImplementationSupported(), or OOM occurs internally, an invalid Minisketch
264264 * object will be constructed. Use operator bool() to check that this isn't the
265265 * case before performing any other operations. */
266- Minisketch (uint32_t bits, uint32_t implementation, size_t capacity) noexcept
266+ Minisketch (uint32_t bits, uint32_t implementation, size_t capacity, uint64_t seed ) noexcept
267267 {
268- m_minisketch = std::unique_ptr<minisketch, Deleter>(minisketch_create (bits, implementation, capacity));
268+ m_minisketch = std::unique_ptr<minisketch, Deleter>(minisketch_create (bits, implementation, capacity, seed ));
269269 }
270270
271271 /* * Create a Minisketch object sufficiently large for the specified number of elements at given fpbits.
272272 * It may construct an invalid object, which you may need to check for. */
273- static Minisketch CreateFP (uint32_t bits, uint32_t implementation, size_t max_elements, uint32_t fpbits) noexcept
273+ static Minisketch CreateFP (uint32_t bits, uint32_t implementation, size_t max_elements, uint32_t fpbits, uint64_t seed ) noexcept
274274 {
275- return Minisketch (bits, implementation, ComputeCapacity (bits, max_elements, fpbits));
275+ return Minisketch (bits, implementation, ComputeCapacity (bits, max_elements, fpbits), seed );
276276 }
277277
278278 /* * Return the field size for a (valid) Minisketch object. */
0 commit comments