Updating Unstructured::int_in_range to minimize entropy consumption #222
+241
−57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
int_in_range
now uses individual bits from the stored data when the span of the input range allowsThis mitigates but does not entirely eliminate biasNot actually sure which way this changes the bias after further thought - the non-uniformity is now proportional to how far the range is from the next power of 2, not the next power of 256.int_range_bytes_needed
to query how much data from the buffer is needed for anint_in_range
call to succeed without using dummy values.Unresolved Questions
arbitrary_byte_size
well enough to determine whether using less entropy affects its calculations, so I have left the logic unchanged. Is this correct?int_in_range
to return specific answers given specific entropy and now fail because the calculation has changed. (Unlike e.g.int_in_range_covers_unsigned_range
which tests that all possible answers are reached by some starting entropy without constraining which inputs map to which.) Should these expected values be updated or possibly the assertions removed?Int
and potentially breaking compatibility - while the docs say clients shouldn't implement it, it's not enforced, and I wanted this to be a drop-in replacement. Is it worth making simplifications by adding methods toInt
?int_range_bytes_needed
may preclude completely fixing bias issues in the future - is this a acceptable, or shouldint_range_bytes_needed
be removed?