What Is SHA-512?
SHA-512 is a cryptographic hash function from the SHA-2 family. It processes data of any permitted length and produces a hash value with a fixed length of 512 bits from it.
That corresponds to:
512 bits
=
64 bytes
=
128 hex characters
SHA-512 is closely related to SHA-256. Both algorithms use many of the same basic ideas. Nevertheless, SHA-512 is not simply a version of SHA-256 with a hash value twice as long.
Internally, SHA-512 works with 1024-bit blocks, 64-bit words, and 80 compression rounds.
If you want to compare the two algorithms directly, I explain the differences in detail in SHA-256 vs. SHA-512 – What Is the Difference?.
In this article, we take a closer look at SHA-512 itself.
What Does a SHA-512 Hash Look Like?
Regardless of how large the input is, SHA-512 always produces a hash value of 512 bits.
That can be a few characters:
Hello
a longer text, or a large file.
The result always has:
512 bits
=
64 bytes
=
128 hex characters
The 128 hex characters result from the fact that one hex character represents four bits:
512 / 4 = 128
So the length of the hash value doesn't depend on the length of the input.
Try SHA-512 Yourself
This property is easiest to observe with an input of your own.
Enter your name, a sentence, or any other text and calculate the SHA-512 hash.
Then change just a single character.
You'll notice that it's not just a small part of the hash value that changes. Instead, the new hash looks completely different.
This behavior is related to the avalanche effect, which I explain in more detail in an article of its own.
How Does SHA-512 Work in Principle?
The process can initially be represented in a greatly simplified way:
Input
↓
Bytes
↓
Padding
↓
1024-bit blocks
↓
16 × 64-bit words
↓
80-word message schedule
↓
80 compression rounds
↓
Feed-forward
↓
512-bit hash
If you've already read How Does SHA-256 Work? or SHA-256 Step by Step, this structure will probably look familiar.
That's no coincidence.
SHA-256 and SHA-512 both belong to the SHA-2 family and use related design principles.
The sizes they work with, however, differ considerably.
SHA-512 Works With 1024-Bit Blocks
Before SHA-512 begins with the actual compression function, the message is prepared and divided into blocks.
A SHA-512 block has:
1024 bits
=
128 bytes
For comparison:
SHA-256 → 512-bit blocks
SHA-512 → 1024-bit blocks
So SHA-512 processes twice as many bits per block as SHA-256.
That doesn't mean, however, that SHA-512 is automatically twice as fast or twice as slow. The actual performance depends, among other things, on the processor architecture and the implementation.
The Padding in SHA-512
So that a message fits into the required blocks, it is extended before the actual processing.
The basic principle looks like this:
[ message ][ 1 ][ zeros ][ message length ]
First, a 1 bit is appended.
After that come as many 0 bits as are needed so that there is still room at the end for the encoded original message length.
In SHA-512, this length field is:
128 bits
long.
This, too, distinguishes SHA-512 from SHA-256:
SHA-256 → 64-bit length field
SHA-512 → 128-bit length field
FIPS 180-4 specifies SHA-512 for messages with a length of less than 2¹²⁸ bits.
After padding, the total length of the message is a multiple of 1024 bits.
From 1024 Bits to 16 Words
A 1024-bit message block is then split into 16 words:
1024 / 16 = 64
Each of these words therefore has:
64 bits
We obtain:
W₀
W₁
W₂
...
W₁₅
of 64 bits each.
This is exactly where one of the most important structural differences from SHA-256 lies.
SHA-256 works with:
16 × 32-bit words
SHA-512, by contrast, with:
16 × 64-bit words
This difference runs through almost the entire rest of the calculation.
From 16 to 80 Words
The original 16 words aren't yet enough for all the compression rounds.
SHA-512 therefore generates a so-called message schedule from them.
From:
W₀ ... W₁₅
come:
W₀ ... W₇₉
The first 16 words come directly from the respective message block.
The remaining 64 words are computed from them.
In simplified form, SHA-512 uses the following for this from W₁₆ onward:
Wₜ =
σ₁(Wₜ₋₂)
+ Wₜ₋₇
+ σ₀(Wₜ₋₁₅)
+ Wₜ₋₁₆
mod 2⁶⁴
The functions σ₀ and σ₁ combine rotations and shifts of the 64-bit words.
The main thing to note here is:
SHA-256 → 64 schedule words × 32 bits
SHA-512 → 80 schedule words × 64 bits
In the SHA-256 vs. SHA-512 comparison, you can use your own input to observe how different these words look in the two algorithms.
The Internal State
SHA-512 works with eight internal 64-bit values.
They are often referred to as:
a b c d e f g h
At the start of a hashing operation, eight initial hash values defined by the standard are used.
For SHA-512, they are:
H₀ = 6a09e667f3bcc908
H₁ = bb67ae8584caa73b
H₂ = 3c6ef372fe94f82b
H₃ = a54ff53a5f1d36f1
H₄ = 510e527fade682d1
H₅ = 9b05688c2b3e6c1f
H₆ = 1f83d9abfb41bd6b
H₇ = 5be0cd19137e2179
These values don't depend on your input.
They are part of the definition of SHA-512.
Why Do the Initial Hash Values Look Familiar?
If you've previously worked extensively with SHA-256, the first hex digits may look familiar to you.
SHA-256 begins, for example, with:
6a09e667
bb67ae85
3c6ef372
a54ff53a
...
SHA-512 begins with:
6a09e667f3bcc908
bb67ae8584caa73b
3c6ef372fe94f82b
a54ff53a5f1d36f1
...
That is due to how the initial hash values are defined within the SHA-2 family.
FIPS 180-4 derives the SHA-512 initial hash values from the first 64 bits of the fractional parts of the square roots of the first eight prime numbers.
For SHA-256, 32-bit values are used accordingly.
So the similarity is no coincidence.
80 Compression Rounds
After the message schedule has been generated, the actual compression function begins.
For each 1024-bit block, SHA-512 performs:
80 rounds
For comparison:
SHA-256 → 64 rounds
SHA-512 → 80 rounds
In each round, the following are used, among other things:
Wₜ
the current word from the message schedule,
Kₜ
a constant defined for the round,
and the eight working variables:
a b c d e f g h
SHA-512 has a total of 80 such 64-bit round constants.
What Happens in a Round?
The structure closely resembles that of SHA-256.
For each round, two temporary values are calculated:
T₁ =
h
+ Σ₁(e)
+ Ch(e,f,g)
+ Kₜ
+ Wₜ
mod 2⁶⁴
and:
T₂ =
Σ₀(a)
+ Maj(a,b,c)
mod 2⁶⁴
Then the working variables are updated.
You may already know the functions Ch and Maj from SHA-256.
SHA-512 also uses these logical functions.
The Σ and σ functions, however, work with rotations and shifts defined for the 64-bit structure of SHA-512.
That is exactly why it would be wrong to regard SHA-512 merely as SHA-256 with more rounds.
The 64-Bit Architecture
The word size is one of the most important properties of SHA-512.
Almost everywhere, we encounter:
64 bits
The working variables have 64 bits.
The schedule words have 64 bits.
The round constants have 64 bits.
And the additions are performed:
mod 2⁶⁴
That means: only the lower 64 bits of an addition result are carried forward.
This architecture fundamentally distinguishes SHA-512 from the 32-bit structure of SHA-256.
Where Do the Round Constants Come From?
SHA-512 uses 80 constants:
K₀ ... K₇₉
FIPS 180-4 defines them as the first 64 bits of the fractional parts of the cube roots of the first 80 prime numbers.
The first constant is, for example:
K₀ = 428a2f98d728ae22
These constants are fixed.
They depend neither on the message nor on the hash value produced.
That means:
same SHA-512 implementation
→
same initial values
→
same round constants
The input, by contrast, influences the message schedule and thus the values processed through the 80 rounds.
The Feed-Forward Step
After round 79, the processing of a block isn't quite complete yet.
The eight resulting working variables are added to the previous hash values:
H₀ = H₀ + a
H₁ = H₁ + b
H₂ = H₂ + c
H₃ = H₃ + d
H₄ = H₄ + e
H₅ = H₅ + f
H₆ = H₆ + g
H₇ = H₇ + h
each modulo 2⁶⁴.
If the message consists of further 1024-bit blocks, this new state serves as the starting point for the next block.
In this way, the entire message is processed block by block.
How Does the 512-Bit Hash Arise From This?
After the last message block has been processed, there are still eight hash values:
H₀ H₁ H₂ H₃ H₄ H₅ H₆ H₇
Each of them has:
64 bits
They are joined one after another:
H₀ || H₁ || H₂ || H₃ || H₄ || H₅ || H₆ || H₇
That gives:
8 × 64 bits
=
512 bits
This is the final SHA-512 hash.
How Secure Is SHA-512?
When it comes to the security of a hash function, different properties have to be considered separately.
For SHA-512, NIST lists an expected preimage-resistance strength of 512 bits and a collision-resistance strength of 256 bits.
Why do these values differ?
For a generic preimage attack, the order of magnitude for an ideal 512-bit hash is:
2⁵¹²
When searching for arbitrary collisions, by contrast, the birthday effect comes into play.
The order of magnitude is therefore:
2²⁵⁶
That is still an astronomically large number.
I explain in more detail why the security strength roughly halves for collisions in The Birthday Paradox, How Does a Birthday Attack Work?, and What Is Collision Resistance?.
Can You Reverse SHA-512?
SHA-512 has no decryption step.
From:
Data
↓
SHA-512
↓
Hash
there is no corresponding operation:
Hash
↓
"decrypt SHA-512"
↓
original data
That doesn't mean, however, that an original input stays secret under all circumstances.
If the possible input space is small, an attacker can try candidates, hash them, and compare them with the known hash value.
That is exactly why the statement:
"Hashes can't be reversed."
is somewhat too simplistic on its own.
I explain what preimage resistance actually means and what role the possible input space plays in What Is Preimage Resistance? and Can You Reverse a Hash?.
Is SHA-512 More Secure Than SHA-256?
SHA-512 has higher generic security strengths against preimage and collision attacks than SHA-256.
In simplified terms:
| Property | SHA-256 | SHA-512 |
|---|---|---|
| Hash length | 256 bits | 512 bits |
| Collision resistance | 128 bits | 256 bits |
| Preimage resistance | 256 bits | 512 bits |
It doesn't follow from this, however, that:
SHA-512 is secure
SHA-256 is insecure
SHA-256 itself already offers a very high cryptographic security strength and remains among the SHA-2 algorithms approved by NIST.
Which variant makes sense depends on the specific use case.
If you want to compare the two algorithms more closely, you'll find the technical differences and an interactive comparison in SHA-256 vs. SHA-512 – What Is the Difference?.
Is SHA-512 Slower Than SHA-256?
That can't be derived from the hash length alone.
SHA-512 does have to perform:
80
compression rounds instead of:
64
At the same time, however, SHA-512 processes 1024 bits per block and uses 64-bit words.
On platforms that can execute 64-bit operations efficiently, this structure can have advantages.
Implementation details and possible hardware acceleration come on top of that.
A general statement such as:
SHA-512 is twice as long and therefore twice as slow.
would therefore be wrong.
If performance matters for a specific application, it should be measured with the implementation actually used on the target platform.
Should You Use SHA-512 for Passwords?
Not simply directly.
SHA-512 is a general-purpose cryptographic hash function and is designed to process data efficiently.
This very speed is problematic for password storage.
If an attacker has a password hash, you want to prevent them from being able to try an extremely large number of password candidates per second.
For storing passwords, suitable password-hashing schemes are therefore used, which employ, among other things, a salt and a configurable cost factor.
A longer hash value therefore doesn't automatically make SHA-512 a suitable password-hashing scheme.
I cover this topic in detail later in the Password Security section.
SHA-512 Is Not Alone
SHA-512 belongs to a group of closely related algorithms within SHA-2.
These include in particular:
SHA-384
SHA-512
SHA-512/224
SHA-512/256
These algorithms use the 64-bit-based SHA-512 structure, but differ in, among other things, their initial hash values and output lengths.
Particularly interesting is:
SHA-512/256
Like SHA-256, this algorithm produces a 256-bit hash, but internally works with the SHA-512 structure.
That makes it clear once again:
The length of the hash value alone doesn't describe the structure of a hash algorithm.
We've already taken a closer look at SHA-384; SHA-512/224 and SHA-512/256 follow in What Are SHA-512/224 and SHA-512/256?.
The Key Takeaways
SHA-512 is a cryptographic hash function from the SHA-2 family.
The most important properties are:
- SHA-512 produces a 512-bit hash.
- That corresponds to 64 bytes or 128 hex characters.
- SHA-512 processes 1024-bit blocks.
- A block is first split into 16 × 64-bit words.
- The message schedule extends these to 80 words.
- SHA-512 performs 80 compression rounds per block.
- The internal calculations work predominantly with 64-bit words.
- Additions are performed modulo
2⁶⁴. - The padding uses a 128-bit length field.
- NIST lists 512 bits of preimage resistance and 256 bits of collision resistance for SHA-512.
- SHA-512 is not simply SHA-256 with a longer hash value.
- SHA-512 should not simply be used directly for password storage.
In simplified form, the process can be summarized like this:
Input
↓
Padding
↓
1024-bit blocks
↓
16 × 64-bit words
↓
80-word message schedule
↓
80 compression rounds
↓
Feed-forward
↓
512-bit hash
Where To Go From Here
Now we know the most important properties and the basic structure of SHA-512.
Next, we can dive deeper into the calculation:
How Does SHA-512 Work?
There, we look more closely at, among other things:
- how the padding is calculated,
- how the first 16 words arise from the block,
- how
W₁₆throughW₇₉are calculated, - how the 64-bit σ and Σ functions work,
- what happens during one of the 80 rounds,
- and how the finished hash finally arises from it.
After that, we can play through SHA-512 — just like SHA-256 — step by step with an input of your own.
Sources and Standards
-
National Institute of Standards and Technology (NIST), FIPS 180-4 – Secure Hash Standard (SHS) Normative specification of SHA-512 and the other algorithms of the SHA-2 family. Includes padding, initial hash values, functions, constants, message schedule, and compression function.
-
National Institute of Standards and Technology (NIST), Hash Functions Overview of the hash functions approved by NIST and of their collision, preimage, and second-preimage security strengths.
-
National Institute of Standards and Technology (NIST), Cryptographic Algorithm Validation Program: Secure Hashing Information on validating implementations of the SHA algorithms.