New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate safe IVs #51086
Merged
Merged
Generate safe IVs #51086
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IVs should never be re-used when using CTR. The previous implementation had a 50% probability to generate an IV that was already used after 65536 generations. This happens because std::mt19937 is seeded using a 32bit integer and returns a 32 bits integer. Because of the birthday problem, collisions have a 50% chance after only 2^16 IV's generations. CH uses one IV per file and, for most use cases, 65k files are not as many as they seem. Also, the initial entropy is gathered using std::random_device which is "best-effort" and it's allowed by the standard to return a fixed sequence of numbers.
alexey-milovidov
added
the
pr-must-backport
Pull request should be backported intentionally. Use this label with great care!
label
Jun 16, 2023
robot-clickhouse
added a commit
that referenced
this pull request
Jun 16, 2023
robot-clickhouse
added a commit
that referenced
this pull request
Jun 16, 2023
robot-clickhouse
added a commit
that referenced
this pull request
Jun 16, 2023
robot-clickhouse
added a commit
that referenced
this pull request
Jun 16, 2023
robot-ch-test-poll3
added
the
pr-backports-created
Backport PRs are successfully created, it won't be processed by CI script anymore
label
Jun 16, 2023
alexey-milovidov
added a commit
that referenced
this pull request
Jun 16, 2023
Backport #51086 to 23.3: Generate safe IVs
alexey-milovidov
added a commit
that referenced
this pull request
Jun 16, 2023
Backport #51086 to 23.4: Generate safe IVs
alexey-milovidov
added a commit
that referenced
this pull request
Jun 16, 2023
Backport #51086 to 23.5: Generate safe IVs
alexey-milovidov
added a commit
that referenced
this pull request
Jun 16, 2023
Backport #51086 to 22.8: Generate safe IVs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
pr-backports-created
Backport PRs are successfully created, it won't be processed by CI script anymore
pr-backports-created-cloud
pr-must-backport
Pull request should be backported intentionally. Use this label with great care!
pr-must-backport-cloud
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.
IVs should never be re-used when using CTR.
The previous implementation had a 50% probability to generate an IV that was already used after 65536 generations. This happens because std::mt19937 is seeded using a 32bit integer and returns a 32 bits integer.
Because of the birthday problem, collisions have a 50% chance after only 2^16 IV's generations.
CH uses one IV per file and, for most use cases, 65k files are not as many as they seem.
Also, the initial entropy is gathered using std::random_device which is "best-effort" and it's allowed by the standard to return a fixed sequence of numbers.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fixed not-so-random IV generation for CTR disk encryption.
@alexey-milovidov