Skip to content
The Round Constants
step 1/5

Reading — step 1 of 5

Read

~1 min readThe Compression Function

The Round Constants

SHA-256 has 64 round constants K[0..63], each a 32-bit word. They come from:

K[i] = first 32 bits of fractional part of cube root of i-th prime

Using "magic" numbers from prime cube roots is the standard cryptographic trick: it's "nothing-up-my-sleeve" — anyone can verify the constants weren't picked to insert a backdoor.

The full table starts:

K[0]  = 0x428a2f98    (cube root of 2)
K[1]  = 0x71374491    (cube root of 3)
K[2]  = 0xb5c0fbcf    (cube root of 5)
K[3]  = 0xe9b5dba5    (cube root of 7)
...
K[63] = 0xc67178f2    (cube root of 311)

The eight initial hash values H[0..7] are similarly:

H[i] = first 32 bits of fractional part of square root of i-th prime
H[0] = 0x6a09e667    (sqrt of 2)
H[1] = 0xbb67ae85    (sqrt of 3)
...
H[7] = 0x5be0cd19    (sqrt of 19)

You hardcode these once and reuse for every hash.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…