InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Follow publication

Breaking Down : SHA-256 Algorithm

Aditya Anand
InfoSec Write-ups
Published in
7 min readNov 27, 2019

Let’s begin!

1. Append : Padding bits

M + P + 64 = n x 512i.e M = length of original message
P = padded bits

2. Append : Length bits

3. Initialize the buffers

a = 0x6a09e667
b = 0xbb67ae85
c = 0x3c6ef372
d = 0xa54ff53a
e = 0x510e527f
f = 0x9b05688c
g = 0x1f83d9ab
h = 0x5be0cd19
Courtesy - SHA-2 Wikipedia

4. Compression Function

W(i) = Wⁱ⁻¹⁶ + σ⁰ + Wⁱ⁻⁷ + σ¹where, 
σ⁰ =
(Wⁱ⁻¹⁵ ROTR⁷(x)) XOR (Wⁱ⁻¹⁵ ROTR¹⁸(x)) XOR (Wⁱ⁻¹⁵ SHR³(x))
σ¹ =
(Wⁱ⁻² ROTR¹⁷(x)) XOR (Wⁱ⁻² ROTR¹⁹(x)) XOR (Wⁱ⁻² SHR¹⁰(x))
ROTRⁿ(x) = Circular right rotation of 'x' by 'n' bits
SHRⁿ(x) = Circular right shift of 'x' by 'n' bits
Depiction of a single “round”
Ch(E, F, G) = (E AND F) XOR ((NOT E) AND G)
Ma(A, B, C) = (A AND B) XOR (A AND C) XOR (B AND C)
∑(A) = (A >>> 2) XOR (A >>> 13) XOR (A >>> 22)
∑(E) = (E >>> 6) XOR (E >>> 11) XOR (E >>> 25)
+ = addition modulo 2³²

5. Output

Conclusion

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Responses (1)

Write a response

Hello Aditya - This was a very lucid and crisp explanation of the SHA256 algorithm. I landed up here in a quest to understand SHA256 while studying Blockchain Fundas. I will share this link with my friends and colleagues who've just started in Blockchains. Writeup and the summary at tail end is much appreciated!

--