MD5, SHA1, SHA224, SHA256 hash produces wrong result for data exactly 56 bytes

Issue #1453 resolved
Miku AuahDark created an issue

One example is this code

return love.data.encode("string", "hex", love.data.hash("md5", "The quick brown fox jumps over the lazy dogj_nj_0552.png"))

The returned digest string is wrong. At first I thought it was kikito's MD5 fault (I use that for LOVE 0.10.2 and earlier as fallback), but after I used online MD5 calculator, it's LOVE hash that produces wrong result. From input above, LOVE returns eea6f72a99f71529f222b07e7d255a55 but the correct one is 3f11a3bdaa89ec42351cabe333184839. Note that string The quick brown fox jumps over the lazy dogj_nj_0552.png is exactly 56 bytes long. Appending anything or subtracting one character from it produces correct hash, so it's only produces wrong hash if the size is exactly 56 bytes long.

EDIT: SHA1, SHA224, and SHA256 seems affected by this problem too.

EDIT2: SHA384 and SHA512 are affected, but with data that is exactly 112 bytes long instead of 56.

Comments (3)

  1. Log in to comment