Skip to content
0:00 / 0:00

#sha-256#hashfunctions#bitcoin

How Does SHA-256 Work?

learnmeabitcoin

8.1K subscribers • 1 video on Hallway

YouTube

Intermediate. Assumes working knowledge.

374K views6 years ago3 recommendations

SecurityComputer scienceCryptographyAlgorithms

An animated, step-by-step explanation of the SHA-256 hash function, covering padding, message schedules, and compression operations.

An explanation of how SHA-256 works, with animations of the operations used inside the hash function. I'm not a cryptographer though, so I can't explain the reasons behind the design (at the moment). - Introduction ↳ - Bitcoin Mining - Basic Operations - Functions - Constants - Hash Computation ↳ - Message ↳ - Padding ↳ - Message Blocks ↳ - Message Schedule ↳ - Compression ↳ - Final Hash Value Source code for animations (and text guide): github.com/in3rsha/sha256-animation Official specification: nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf ==== FAQs: ==== === What setup are you using for your computer? === * Operating System = Ubuntu (Xubuntu) * Desktop Environment = XFCE * Appearance Style = Arc-Dark * Appearance Icons = Papirus-Dark * Window Manager Style = Numix * Wallpaper = A simple gradient from dark grey to grey. * Shell = zsh (using zsh-autosuggestions) * Terminal Font = Hack Regular === How do you work out the constants? === The constants are created using the first 32 bits from the fractional part of the cube roots of prime numbers. For example, the first constant is the cube root of the first prime number (2), so: ∛2 = 1.2599210498948732 The fractional part of this is: = 0.2599210498948732 However, we want 32 bits' worth of this fractional part. To get these 32 bits, we multiply the fraction by 2^32: = 1116352408.8404646 The integer part of this is our 32-bit constant, which we can convert to binary: = 1116352408 = 0b01000010100010100010111110011000 Here's some code showing how it works: github.com/in3rsha/sha256-animation/blob/master/constants.rb === How does the padding work if my message is X bits in length? === Lets say we have a message that is exactly 448 bits. We always need to include the `1` separator and the 64 bit message size in the padding, which takes the message+padding up to 513 bits. This exceeds the 512 bit message block size we're after, so we pad with 511 zeros to take us up to 1024 bits (the next multiple of 512). The zeros go between the separator and the size, like so: [message] [separator] {zeros} [size] So in other words, if your message and the initial padding takes you beyond the size of a message block, you pad all the way up to the next multiple of 512.

Why it's here

3 people recommend this

What people say. Highly recommended as an exceptionally clear visual explanation of SHA-256, sufficient for viewers to implement the algorithm themselves.

7373737373on Hacker News • Recommends

On “The SHA-256 Project: learn how hash functions work by implementing one yourself”

I found this video to be an excellent explanation and sufficient to implement the algorithm: link to this video Code: link This site contains a nice visualization: link

1_playeron Hacker News • Recommends

On “Show HN: SHA-256 Animation”

Here's the author doing an in-depth explanation of how SHA-256 works using this code: link to this video I'm halfway through, but looks very well done, thanks!

oconnor663on Hacker News • Recommends

On “Show HN: SHA-256 explained step-by-step visually”

Oh this is great. When we taught SHA-256 last semester, we linked to this YouTube video: link to this video . Next time we do it, we'll probably link to both. Having several different ways to visualize the same thing is very helpful, and I like that this one moves quickly. A couple of details missing from this visualization are how you pad a message to be a multiple of the block size, and how you chain blocks together to form a longer message. In the pseudocode at link , that's the "Pre-processing (Padding)" part and the "for each chunk" loop just below it. I get why you'd want to leave those things out, since they're not really the interesting part, and the screen is already pretty packed as it is.…

u/vitorstraggiottiin r/C_Programming • Mentions

…ode: https://github.com/vitorstraggiotti/easySHA256.git You can clone and just run `$ make` and then `$ ./test text.txt` i compared my result with this site: https://emn178.github.io/online-tools/sha256\_checksum.html those are the sources that i used to make that library: https://qvault.io/cryptography/how-sha-2-works-step-by-step-sha-256/ [video…

newscrackeron Hacker News • Mentions

On “Show HN: SHA-256 Animation”

This looks great, though it requires quite sometime to go through it (and figure out what could possibly be understood by someone with knowledge of programming and bit wise operators, and what can just be skipped because it’s something only cryptographers can understand). If someone were to make a slower video explaining it with all the sections from this dissection, that’d be even more awesome. Edit: Seems like the author created a video for this — link to this video (thanks to 1_player’s comment at link ) On a tangent, here’s an animation (by someone else) explaining AES encryption — link (thanks to harrigan’s comment at link )