New encoding includes a version byte and enforced zero padding #6
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.
This PR introduces version 2 of the id encoding. It embeds a leading version byte to make it easier to introduce future versions when and if needed.
It also eschews random bits (in the input to the cipher) in favor of zero padding. This is enforced at decoding time, ensuring that exactly one encoded string is valid for a given id and cipher key, instead of millions. This fixes #5.
The new encoding is not backward compatible; however, this change avoids needing a major-version revision in the API by introducing the new interface
Versioner
. If implemented by aKeyStore
and it reports version 2 or greater, then encoding operations produce version-2 strings and decoding operations validate them as such; otherwise the old format is assumed.The sqlite KeyStore implementation (which is also the one used by the
encid
command) keeps existing keystores at version 1 and uses version 2 for new ones.I am deeply indebted to Reddit user u/skeeto for the report in #5 and for guidance in producing this PR.
Note that this improvement, like the rest of the code in this library, does not account for timing attacks.