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

Fixes zero padding calculation #3

Merged
merged 2 commits into from
Apr 4, 2019
Merged

Conversation

colinta
Copy link
Contributor

@colinta colinta commented Apr 4, 2019

Per our discussion on Slack. Includes a test that was failing (now passing).

To hunt this down I basically started implementing SHA1 on my own, and then lined it up with your code (which, btw, is way more straightforward than other implementations out there, esp. JS ones). I couldn't figure out the zero padding calculation: 64 - modBy 64 (List.length bytes + 1 + 8), so I just replaced it with the formula I had ended up with: modBy 64 (56 - modBy 64 (byteCount + 1)) and all the tests passed! More verbosely, this calculation is:

bytesLen =
    byteCount + 1

lastChunkLen =
    modBy 64 bytesLen

zeroPadLen =
    modBy 64 (56 - lastLen)
elm-test
elm-test 0.19.0-rev6
--------------------

Running 36 tests. To reproduce these results, run: elm-test --fuzz 100 --seed 67610542048265 /Users/colinta/Code/elm/elm-sha1/tests/Tests.elm


TEST RUN PASSED

Duration: 1761 ms
Passed:   36
Failed:   0

@TSFoster
Copy link
Owner

TSFoster commented Apr 4, 2019

Thank you so much for tracking this down and fixing it while I was asleep (I'm in the UK)! I will get this published ASAP with a note in the README about the issue, and I'll create a PR for romariolopezc/elm-hmac-sha1 bumping the version of this library.

@TSFoster TSFoster merged commit dc3f959 into TSFoster:master Apr 4, 2019
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.

2 participants