How SHA-2 Works Step-By-Step (SHA-256)

July 8, 2020 by Lane Wagner

SHA-2 (Secure Hash Algorithm 2), of which SHA-256 is a part, is one of the most popular hashing algorithms out there. In this article, we are going to break down each step of the algorithm as simple as we can and work through a real-life example by hand.

SHA-2 is known for its security (it hasn’t broken down like SHA-1), and its speed. In cases where keys are not being generated, such as mining Bitcoin, a fast hash algorithm like SHA-2 often reigns supreme.

What Is a Hash Function?

If you want to read more about hash functions in general, do so here. That said, in order to move forward let’s recap three of the main purposes of a hash function:

  • To scramble data deterministically
  • To accepts input of any length and output a fixed-length result
  • To irreversibly manipulate data. The input can’t be derived from the output

SHA-2 vs SHA-256

SHA-2 is an algorithm, a generalized idea of how to hash data. SHA-256 sets additional constants that define the SHA-2 algorithm’s behavior. One such constant is the output size. “256” and “512” refer to their respective output digest sizes in bits.

Let’s step through an example of SHA-256.

SHA-256 “hello world”; Step 1 – Pre-Processing

  • Convert “hello world” to binary:
01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111
01110010 01101100 01100100
  • Append a single 1:
01101000 01100101 01101100 01101100 01101111 00100000 01110111 01101111
01110010 01101100 01100100 1

#algorithms #cryptography #hash functions #security #cybersecurity #infosec #secops #sha-256

How SHA-2 Works Step-By-Step (SHA-256)
45.15 GEEK