Recode MD5 and SHA Hashing Algorithms:
- md5
- sha256
- sha224
- sha384
- sha512
- sha512/224
- sha512/256
See the subject for more details.
Final Score 125/100
First clone this repo.
git clone https://github.com/dfinnis/md5.git; cd md5
Make the binary ft_ssl.
make
Then run ft_ssl with hashing algorithm then filepath as argument.
./ft_ssl md5 test/hello.txt
We can compare our output hash with the MD5 standalone, and openssl.
md5 test/hello.txt
Here is an example running ft_ssl with SHA256. The same works for all SHA family hashes.
./ft_ssl sha256 test/hello.txt
Like openssl, you can run ft_ssl without arguments. It will then prompt for input from stdin, accepting a hashing algorithm. Next input whatever text then press ctrl+D. It will then output the hash for the given text. Here is an example shown against openssl.
./ft_ssl
test.sh compares the output of ft_ssl with the output of openssl / shasum.
It will run some unit tests (files in the test folder), random strings, random strings piped into stdin, and random binary files. It will run these tests for each hashing algorithm emulated, MD5 and SHA family hashes.
./test.sh
ft_ssl
supports the following flags, emulating the behaviour of the MD5 standalone.
-p
echo STDIN to STDOUT and append the checksum to STDOUT-q
quiet mode-r
reverse the format of the output-s
print the sum of the given string
The ideal cryptographic hash function has 5 main properties:
- Deterministic, the same message always results in the same hash
- Quick to compute
- Infeasible to reverse engineer a message from its hash (one-way)
- A small change in message should change the hash extensively
- No two different messages with the same hash value
Though the numbers change, the basic principle is the same for MD5 and SHA family hashes. For MD5:
- Pad the message until length is a multiple of 512 bits
- Initialize 4 buffers
- Process the message 512 bit chunk at a time, adding the result to the hash buffers. For each 512 bit chunk, do 64 rounds of compression (specific bitwise buffer operations)
None! All dependencies are already contained in the repo.
EDUCBA - Introduction to MD5 Algorithm
National Institute of Standards and Technology - Secure Hash Standard
Information Warfare - description of SHA family hash functions