Secure digest functions

Sahani Rajapakshe
3 min readJul 29, 2020

MD5

MD5 was most popular and widely used hash function for quite some years.

MD5 is quite fast than other versions of message digest which takes the plain text of 512 bit blocks which is further divided into 16 blocks, each of 32 bit and produces the 128 bit message digest which is a set of four blocks, each of 32 bits. MD5 produces the message digest through five steps .

As we all know that MD5 produces an output of 128-bit hash value. This encryption of input of any size into hash values undergoes 5 steps and each step has its a predefined task.

Computation of the MD5 digest value is performed in separate stages that process each 512-bit block of data along with the value computed in the preceding stage. The first stage begins with the message digest values initialized using consecutive hexadecimal numerical values. Each stage includes four message digest passes which manipulate values in the current data block and values processed from the previous block. The final value computed from the last block becomes the MD5 digest for that block.

For example-

Message — ‘web Assignment’

After encrypted with MD5

Result — ‘ aebfa01e3d15866827ee47ee3d16d08d ’

how it works,

Step1: Append Padding Bits

  • Padding means adding extra bits to the original message. In MD5 original message is padded such that its length in bits is congruent to 448 modulo 512. Padding is done such that the total bits are 64 less being a multiple of 512 bits length.
  • Padding is done even if the length of the original message is already congruent to 448 modulo 512. In padding bits, the only first bit is 1 and the rest of the bits are 0.

Step 2: Append Length

After padding, 64 bits are inserted at the end which is used to record the length of the original input. Modulo 2⁶⁴. At this point, the resulting message has a length multiple of 512 bits.

Step 3: Initialize MD buffer

A four-word buffer (A, B, C, D) is used to compute the values for the message digest. Here A, B, C, D are 32- bit registers and are initialized in the following way.

Step 4: Processing message in 16-word block

MD5 uses the auxiliary functions which take the input as three 32-bit number and produces a 32-bit output. These functions use logical operators like OR, XOR, NOR

The content of four buffers are mixed with the input using this auxiliary buffer and 16 rounds are performed using 16 basic operations.

Output-

After all, rounds have performed the buffer A, B, C, D contains the MD5 output starting with lower bit A and ending with higher bit D.

SHA-1

Secure Hash Algorithms, also known as SHA, are a family of cryptographic functions designed to keep data secured. This hash value is known as a message digest. It works by transforming the data using a hash function: an algorithm that consists of bitwise operations, modular additions, and compression functions.

For Example,

plain text — ‘web assignment’

After encrypt with SHA-1

Result - b587b6c5e4473ee7cb498dbad314dd963a71e012

SHA1 vs MD5

  • MD5 has fewer complex algorithms which make it faster than SHA1.
  • SHA1 has a more complex algorithm which makes is more secure than MD5.
  • SHA1 is far secure than MD5.
  • MD5 was more popular then SHA1 but in the last decade it losing its popularity.

--

--

Sahani Rajapakshe

I would say I’m… Someone who is modest, hard-working and consistently sets firm goals for myself. Then, once I’ve defined my benchmarks, I take the necessary st