Skip to content

Latest commit

 

History

History

2020-minimd5

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

MD5 with integers

Just a tiny MD5 checksum utility. Prints hash string of data from stdin. Work same as (openssl md5 | cut -d' ' -f2) command.

My objectives

  1. reduce code size as much as possible
  2. avoid warnings from GCC/CLANG -Wall -Wextra -pedantic
  3. portable (regardless of register size and endianness)
  4. fit code in a round shape
  5. no macro defines
  6. no floating-point arithmetics

Notes

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.

Bonus

  • 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.