Skip to content

fix(hash): correct random() length handling and harden helpers#102

Merged
benkhalife merged 2 commits into
masterfrom
hash-fix-random-length-bug-and-harden-helpers
Jun 16, 2026
Merged

fix(hash): correct random() length handling and harden helpers#102
benkhalife merged 2 commits into
masterfrom
hash-fix-random-length-bug-and-harden-helpers

Conversation

@benkhalife

Copy link
Copy Markdown
Member

random() returned at most a hash digest's worth of hex and threw a TypeError on odd lengths under strict types. Rewrite it to emit exactly the requested number of hex characters from random_bytes() for any positive length, drop the unused algorithm parameter, and reject non-positive lengths. Reduce token() to a wrapper over random().

Reimplement salted() with HMAC to remove length-extension and salt/data boundary weaknesses, and document md5()/sha1() as checksum-only.

BREAKING CHANGE: Hash::random() no longer accepts an algorithm argument.

random() returned at most a hash digest's worth of hex and threw a
TypeError on odd lengths under strict types. Rewrite it to emit exactly
the requested number of hex characters from random_bytes() for any
positive length, drop the unused algorithm parameter, and reject
non-positive lengths. Reduce token() to a wrapper over random().

Reimplement salted() with HMAC to remove length-extension and
salt/data boundary weaknesses, and document md5()/sha1() as
checksum-only.

BREAKING CHANGE: Hash::random() no longer accepts an algorithm argument.
@benkhalife benkhalife linked an issue Jun 16, 2026 that may be closed by this pull request
@benkhalife
benkhalife merged commit 6e319bb into master Jun 16, 2026
1 check passed
@benkhalife
benkhalife deleted the hash-fix-random-length-bug-and-harden-helpers branch June 21, 2026 12:26
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.

Hash: fix random() length bug and harden helpers

1 participant