pull down to refresh

In Part 1, we explained the padding step of SHA-256.

In this part, we move to the next step: the Message Schedule.

┌───────┐    ┌─────────┐    ┌──────────────────┐    ┌──────────────┐    ┌──────┐
│ Input │ -> │ Padding │ -> │ Message Schedule │ -> │ Compression  │ -> │ Hash │
└───────┘    └─────────┘    └──────────────────┘    └──────────────┘    └──────┘
                 ↑                    ↑
             Part 1               Part 2 (current)

Reminder:

After padding, the message becomes a single 512-bit block.

Now this block goes into the message schedule step.

Input ("bitcoin")
        │
        ▼
┌─────────┐ ---> ┌────────────────────────────────────┐ ---> ┌──────────────────┐
│ Padding │ ---> │ 512-bit padded block               │ ---> │ Message Schedule │
└─────────┘ ---> └────────────────────────────────────┘ ---> └──────────────────┘
                 │  01100010011010010111010001100011  │
                 │  01101111011010010110111010000000  │
                 │  00000000000000000000000000000000  │
                 │  00000000000000000000000000000000  │
                 │  00000000000000000000000000000000  │
                 │  00000000000000000000000000000000  │
                 │  00000000000000000000000000000000  │
                 │  00000000000000000000000000111000  │

Step 1: Split Block Into Words

The padded block has:
512 bits total

We split it into:
16 pieces

Each piece is:
32 bits

And each piece is called a word.

So we get: W0, W1, W2, ..., W15

These come directly from the padded message.

w0 = 01100010011010010111010001100011
w1 = 01101111011010010110111010000000
w2 = 00000000000000000000000000000000
w3 = 00000000000000000000000000000000
w4 = 00000000000000000000000000000000
w5 = 00000000000000000000000000000000
w6 = 00000000000000000000000000000000
w7 = 00000000000000000000000000000000
w8 = 00000000000000000000000000000000
w9 = 00000000000000000000000000000000
w10 = 00000000000000000000000000000000
w11 = 00000000000000000000000000000000
w12 = 00000000000000000000000000000000
w13 = 00000000000000000000000000000000
w14 = 00000000000000000000000000000000
w15 = 00000000000000000000000000111000

Step 2: Notice We Need More Words

The compression step needs:

W0 → W63 (64 words total)

But we only have:
W0 → W15

So we must compute 48 additional words:
W16 → W63


Step 3: How New Words Are Built

Each new word is computed from four earlier words

So every new word depends on previous schedule values.

Example for W16:
W16 = W0 + σ0(W1) + W9 + σ1(W14)

We reuse earlier words to generate new ones.


Step 4: Bit Mixing Functions σ0 and σ1

The functions σ0 and σ1 mix bits using rotations and shifts:

σ0(x) = ROTR7(x) XOR ROTR18(x) XOR SHR3(x)
σ1(x) = ROTR17(x) XOR ROTR19(x) XOR SHR10(x)

These operations spread information across bits.

Check https://hashexplained.com/ for more details about σ0 and σ1


Step 5: General Rule for All Remaining Words

All later words are computed using:

W[t] = W[t-16] + σ0(W[t-15]) + W[t-7] + σ1(W[t-2])

Repeat this until: W63 is computed

After computing everything:

w16 = 10111000111111010101100100111010
w17 = 01101111100001000110111010000000
w18 = 00000111100101000011010000110111
w19 = 10111010100010111101101100101001
w20 = 10011100100111001000011000110101
w21 = 10010110110111110100100011100010
w22 = 11010011111110110101101100110100
w23 = 00000110010001100000011110100000
w24 = 00110110010011000111101111010100
w25 = 11001010101110011100011010100001
w26 = 01101101001010001110101000011010
w27 = 01111000010100101111100010101111
w28 = 11111111001101000111100111101101
w29 = 11110111010101111010001011010001
w30 = 00101010010010001001010100001001
w31 = 10001111011111001000110001011111
w32 = 11110010011101011110000100001111
w33 = 00011000001001011011000100010111
w34 = 01111111011011111100100101100011
w35 = 10000001100101111000101001111101
w36 = 10110111010001010010011011101000
w37 = 10011010100011101001110000110100
w38 = 01011100001010001101000100000000
w39 = 01000110110001101000000001111110
w40 = 11101100100100111001011010000111
w41 = 11011110010001001100000111111100
w42 = 10011000001110011100100011000101
w43 = 00000010111100100001110101110100
w44 = 11001100110011111010111001010100
w45 = 11010010111101000111101010001010
w46 = 00100001110010010110110011101000
w47 = 10101000000110100101110010011110
w48 = 10101110000011010100010011011010
w49 = 01010001101000011111101011011010
w50 = 10010110111011100010011010101011
w51 = 10011110110001010100011010101100
w52 = 00111111010010001000101110110010
w53 = 00000111011110011101001110001111
w54 = 10101101001011101000010011001011
w55 = 11000000011101100011000101011000
w56 = 10100011000110001010000000100001
w57 = 00111101111100000111101011100111
w58 = 11101010010000011101101001100000
w59 = 11001111111100000000100000100011
w60 = 10111011111010100100110100011010
w61 = 00010100100010100001100010001111
w62 = 00010000101101010110001110000111
w63 = 10001100001100010110000010100010

At this point, the message schedule is complete.


Next Step

Now the 64 words are ready.

They are passed into the compression function, which produces the final hash state.

┌───────┐    ┌─────────┐    ┌──────────────────┐    ┌──────────────┐    ┌──────┐
│ Input │ -> │ Padding │ -> │ Message Schedule │ -> │ Compression  │ -> │ Hash │
└───────┘    └─────────┘    └──────────────────┘    └──────────────┘    └──────┘
                 ↑                    ↑                     ↑
             Part 1                Part 2               Part 3 (next)

Summary

Padding step ✔
Message schedule ✔
Next: Compression step


Learn More

You can see the message schedule step animated here:

https://hashexplained.com