Skip to content
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

New encoding includes a version byte and enforced zero padding #6

Merged
merged 13 commits into from
Feb 20, 2024

Conversation

bobg
Copy link
Owner

@bobg bobg commented Feb 11, 2024

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 a KeyStore 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.

Copy link

Modver result

This report was generated by Modver,
a Go package and command that helps you obey semantic versioning rules in your Go module.

This PR requires (at least) an increase in your module's minor version number.

minimum Go version changed from 1.20 to 1.21
  Minor

@bobg bobg changed the title Add checksums to encoded ids and check them upon decoding New encoding includes a version byte and enforced zero padding Feb 19, 2024
@bobg bobg merged commit 415aa62 into master Feb 20, 2024
1 check passed
@bobg bobg deleted the bobg/checksum branch February 20, 2024 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vulnerability related to random padding
1 participant