How Does SHA-256 Work?

preview_player
Показать описание
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).

00:00 - Introduction
↳ 02:20 - Bitcoin Mining
05:05 - Basic Operations
08:27 - Functions
10:58 - Constants
12:23 - Hash Computation
↳ 12:41 - Message
↳ 13:19 - Padding
↳ 14:24 - Message Blocks
↳ 14:58 - Message Schedule
↳ 17:42 - Compression
↳ 22:30 - Final Hash Value

====
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

=== 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.
Рекомендации по теме
Комментарии
Автор

Other people: *creates animation*
This awesome guy: *creates several programs*
The dedication and presentation is really commendable!

je.mengullo
Автор

Best video on SHA-256 I have ever seen. Bravo!

BB-sdsm
Автор

this is the best 23 minutes ive ever spent on youtube. Thanks for making the source available.

gngn
Автор

When "lengthy introductions" are that interesting, I have no problem with it!

kebman
Автор

This video is totaly underrated, I have searched for something like this for so long.

hytago
Автор

Wow, this is such a good intro! I love the detail you went into for everything. This is one of the few explanations where all the building blocks are set down and built upon -- no moments of WTF where did that come from? Or what even is that? It's all just crystal clear, super grateful, thanks :)

Tina-biri
Автор

It wasn't the intention of the video but your explanation of how mining works was one of the best I've seen. Really easy to follow

brunovaz
Автор

There needs to be more people like you when it comes to explaining how these hash functions (and block ciphers) work, cause most of my research into this specific hash function and a few block ciphers, have little to no info on how they actually work on the inside. I can only imagine how long it took to code all of those separate programs to show exactly what was going on with each step, and it was the most helpful thing imaginable. Literally coded my own implementation thanks to this, so cheers mate.

shadowkitty
Автор

This is probably the best video on SHA-256 you can find online. Absolutely well done

ThisIsAYoutubeAccountAsd
Автор

This guy makes one of the best videos out there about the hashing function, a presentation better than university professors, and still out here after 2 years responding on comments, icant say anything except thank you, and you're one of the nicest people ever.

amrkhaled
Автор

This is one of the most clear and simple explanations I found after weeks of searching. Awesome dude.

codewithk
Автор

My graduation project is about hash functions. I'm currently working on understanding SHA-2. This video helped me a lot! Thank you very much, kind sir!

altairezio
Автор

Wow. This is amazing. The hard work and the way you showed everying is awesome. Thanks

abhinavaryal
Автор

This is fantastic, thank you so much! Really clear, no bits left out or alluded to, everything was explained in depth but not so complicated or convoluted that it made the overall gist hard to follow. Genuinely a gold standard for teaching!~

VeeTheGator
Автор

Just found your series about two weeks ago, was bummed that it had been so long since you did any videos. Your walk throughs are thorough yet simple, very easy to follow along. Am glad to see new content, please if you have the time continue with more and possibly updating existing content

johnnygood
Автор

I was going to build this so I could understand the SHA256 better. But you've already done it! Thanks for sharing!

fzigunov
Автор

The introduction was so cool! It must have taken a long time to put in all the /b’s :)

kevinchen
Автор

This video must be preserved under FIPS journals. Excellent video!

TON-vzpe
Автор

Perfect! Everything explained as clear as water. Thank you a lot!

erenenadream
Автор

Amazing demonstration, seeing all the data types really helps a lot, and I love the calm narrated style.

thomasschellekens