Skip to content

Keep truncation offset within MD5 digest - #45

Open
JayOfTheKeyboard wants to merge 1 commit into
dim13:masterfrom
JayOfTheKeyboard:md5-truncation-bounds
Open

JayOfTheKeyboard wants to merge 1 commit into
dim13:masterfrom
JayOfTheKeyboard:md5-truncation-bounds

Conversation

@JayOfTheKeyboard

Copy link
Copy Markdown

Fixes #44

An MD5 digest is 16 bytes, so a truncation offset of 13 to 15 read past the end and Evaluate panicked with index out of range. This clamps the offset to len(hashed)-4. Offsets up to 12 give the same codes as before, and SHA1/256/512 are unchanged.

TestEvaluateMD5 covers offsets 1 and 12 to 15 with HOTP. The expected codes come from Python's hmac, not from this code. Without the fix the test panics. go test, go vet and go fix -diff are clean.

An MD5 digest is 16 bytes, so a dynamic truncation offset of 13 to 15
read past its end and Evaluate panicked with index out of range. Clamp
the offset so 4 bytes are always available. Offsets that worked before
give the same codes.
@dim13

dim13 commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thank you for pointing out the issue, but I'd rather sunset MD5 entirely. It has never been seen in the wild, nor is it mentioned in any RFC.

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.

Evaluate panics on MD5 entries

2 participants