Troubleshooting your MD5 implementation
Introduction
This is a list of MD5 hashes of an empty string ("") computed with various buggy implementations, with descriptions of the bugs.
(The correct hash is d41d8cd98f00b204e9800998ecf8427e.)
Reversed byte order in 32-bit integers
- initial state constants:
d67dfb7e907840deee15560e9657e40f - sine constants:
af9d47553364d9f47b6eb4ba2867777e - unpacking the message into integers:
487f7b22f68312d2c1bbc93b1aea445b - packing the integers into hash:
d98c1dd404b2008f980980e97e42f8ec - both initial state & sines:
97a6a5c2732be6b7e01908d4fc508a35 - both unpacking & packing:
227b7f48d21283f63bc9bbc15b44ea1a - all (initial state, sines, packing & unpacking):
77e9629e06143371ebeef58872a2a66a
Forgot the bit rotation or an addition
68f1aa18c4f40f2e127d4a3a1ef19cbd85e950ba1c2a2ab552571aa19fa59660900d850bf8aa2478bf22ac013911db80ac1d1f03d08ea56eb767ab1f91773174ad4aada3dc19a43f1df86ee9863522a1
Wrong order of bit rotation and additions
16bf63e408d611b7473b6f2bdfa81f3c200bd64b18e70eb87b12380986ad1e5b270846620e2b7a2255caf3aa58328a9232af135b718dbc3e32dbd2f8d8b3be1e829a5cde6dcb2f2527abe5e59260a37887ca40e6cbef09be6c4d03ffbaf6d77089353b2863cddf94911af9eb10d2dd858ec20bc6dfacfc6f306ceb03bcc834b6a16b08603198ebb82e79415822c5177bc04c1fb6228bd95d938dc90c60104db6d2d8723d4b0f4c632931a02fd129fdcdd5f7e51814fe79c75724765102769d15dcd1f5e2222869a4b2f334abdaa9361ee8f46c7d3edb477ed6e7dde3c2b377afee074047c10acd2018701d2fa8d8d517
Wrong precedence of XOR vs. AND/OR
045a33e12fb88967a7eb35a4bd9162441a9714b93e70bfb5b68683723067fb90220e5c21618335b02415830eab9cef0026ea77c119f2b441b885583b8808610528e628a6f2a7e75042dcbe54e19bcbb1291b3a705a88977a25957737e56024d52b21229104500c83511a6b434247bca53719b8e1dc4282dae5a4a3b614476f743c55d6019cc0fefa0e3309c12e48d6d43d47a045652948f7c3bb63051734408b5d7bb1f3cf36e93b7cefebdd936bb3416a985978ac5b3273d60a178345f53d7472efc54eaf7b094f34e96dfed0855b1a8000e254579b10585b83c1c1009781a483f9fa8ee65d5876ca0b5b6e12a6244dad4fb1dff317a70403488d93c8f277beb0444f0f8aad55adb337a57e73c6a1bfbe5894d2c520552a94d93c6bbf96ffcbc63ac266aab86e3634bf7d72c7f36dffc7160a5a0c78e5bd0d31f15939c60183c71d4b400f6f7b910f931ad583715627d0a6f2fd2fb7f06c22200e8e7674c683e4f37f43c04ebe1a4323e6da185fa55de63e5b2b46f589e461bf326ffc8d08ebec4d7375028ac4b7b01bce7be63b738efc40018a3492e9c7ed935ed91cc1ddd2
State of algorithm shuffled incorrectly
14f64bf678f2b950fcb97531eca86420242c7db412579bdffcb97531eca8642027373a84908b6f0e83a54852eca864202b372c6b12579bdffcb97531731e3b1d2ff00738ffffffff878888887431eda845f7ccbd4260425f9ee4e36d122a1cd54aa375120db939987555c138ac85757e4bff3733cb077a1c025c4188625e3c825cc21fb812579bdffcb975311293dec67883280312579bdf70120f6deca8642088b0e5a212579bdf73fba873792f38a08f4e91d640a24a357bc1b612eca8642097ec2cfa54a61e87fcb97531eacdd6869d60223f8744553ffcb97531b7bd95cd9ea7fa2612579bdffcb97531eca86420a3557d5c12579bdf05a85695eca86420ab8773f8571b483c5b840106a9318bfcace1d231878888887431eda8ffffffffaed5854b12579bdffcb97531eca86420b8c7d5aa15970fa61f4674134c0a3108c53910a3d6be8d64fcb97531eca86420dd7a4aa712579bdffcb97531eca86420f2d4968712579bdfa64945898a3cf089
Miscellaneous issues
- forgot to append
0x80to the message:ac1d1f03d08ea56eb767ab1f91773174 - range 0–63 instead of 1–64 in sine constants:
a75646c5368368506ef66450a799875a - degrees instead of radians in sine constants:
1da3aaa59fa0de764774f501a73dd073 - shifted left instead of rotating left:
9a4b397d22a4a8dc97d5951b0f4df0f9 - 8-bit addition instead of 32-bit:
98e800af1dc6345251bbc090ccb5eaa6 - 16-bit addition instead of 32-bit:
a8bb05547769f4d59a50cee3aa0a0aa2 - bit operations for first 16 rounds used for all rounds:
5d3be1a88fe3e9b6c349de8700d978e5