Just a tiny MD5 checksum utility. Prints hash string of data from stdin.
Work same as (openssl md5 | cut -d' ' -f2)
command.
- reduce code size as much as possible
- avoid warnings from GCC/CLANG
-Wall -Wextra -pedantic
- portable (regardless of register size and endianness)
- fit code in a round shape
- no macro defines
- no floating-point arithmetics
The main difficulty of making MD5 code smaller is a 64x4 bytes long table with constants. Which will take more than 512 bytes in text hex encoding. This table is a results of a sine function, so can be generated dynamically, but merging floating-point arithmetics with precise integer calculations is not a great idea, because can make portability issues.
Attempts to satisfy CLANG -Weverything
will ruin comma magic, that is so great for obfuscation, so I don't want to care about that.
Probably, should work correctly on any machines, but I have nothing exotic (like BE or not 32/64) to try it.
Added a macro hack to make stdin work in binary mode under Windows (tested under mingw64), otherwise the hashes can be incorrect.
-
prog.extra.c
the same with the sine function (so smaller), and in different shapes. -
prog.x86_64.asm
contains same program, but written on assembly for x86_64 Linux, for the sake of less executable size. Which is 500 bytes long (where 120 is for ELF headers) after compilation. Algorithm details is slightly differ (like constants packing), just to make smaller binary code. It's interesting to compare density of binary code and obfuscated C. -
prog.x86.asm
and for x86, although the headers are smaller, but the binary code is larger due to fewer registers and lack of 64-bit multiply.