Overview of SHA2

Posted Jan. 4 2022 by Tarek.

The SHA2 algorithm contains the following variants:

  • SHA224
  • SHA256
  • SHA384
  • SHA512
  • SHA-512/224
  • SHA-512/256

Each variant defines a BLOCK_SIZE and NUM_ROUNDS amongst other constants. All variants contain three main phases.

1. Initialization

A set of hash values are initialized to predefined constants. The number and values of those hashes depend on the algorithm variant. Similarly each variant has a specific number of rounds NUM_ROUNDS, and there is a list of constants predefined for each round.

2. Processing

Incoming data are broken into fixed-size chunks of size BLOCK_SIZE. Each chunk gets operated on and ends up updating all hash values. If size of the last chunk is not a multiple of BLOCK_SIZE, it does not get processed for now.

3. Sum

If the is any remaining unprocessed data, it gets padded to match the BLOCK_SIZE and we process as chunk.

All hash values are concatenated and this becomes the hash output.