Skip to main content

What Is SHA-2?

SHA-256 and SHA-512 are among the best-known cryptographic hash functions today. However, they are not independent algorithms, but part of a common family: SHA-2.

So SHA-2 is not a single hash function. The name refers to a family of several related hash functions with different output lengths and, in part, different internal structures.

SHA-2 includes:

  • SHA-224
  • SHA-256
  • SHA-384
  • SHA-512
  • SHA-512/224
  • SHA-512/256

The variants pursue fundamentally the same cryptographic goals, but differ in, among other things, hash length, word size, block size, and number of compression rounds.

SHA-2
│
┌───────────────┴───────────────┐
│ │
32-bit 64-bit
│ │
512-bit blocks 1024-bit blocks
64 rounds 80 rounds
│ │
┌──────┴──────┐ ┌─────────────┼─────────────┐
│ │ │ │ │
SHA-224 SHA-256 SHA-384 SHA-512 SHA-512/t
│
┌──────┴──────┐
│ │
SHA-512/224 SHA-512/256

What Does SHA Stand For?​

SHA stands for Secure Hash Algorithm.

The SHA families comprise various cryptographic hash functions standardized by the US National Institute of Standards and Technology (NIST).

SHA-1, SHA-2, and SHA-3 should not simply be understood as different output lengths of the same algorithm.

They are different generations, or families, of cryptographic hash functions.

SHA-2 was added to the Secure Hash Standard in 2002 with SHA-256, SHA-384, and SHA-512. SHA-224 followed later. The variants SHA-512/224 and SHA-512/256, which are also standardized today, subsequently extended the family with further output lengths.

Which Hash Functions Belong to SHA-2?​

The SHA-2 family can be roughly divided into two groups.

The first group works internally with 32-bit words:

  • SHA-224
  • SHA-256

The second group works with 64-bit words:

  • SHA-384
  • SHA-512
  • SHA-512/224
  • SHA-512/256

This distinction is more important than the names initially suggest.

SHA-224 is closely related to SHA-256 internally. SHA-384, on the other hand, is based on the same basic structure as SHA-512.

The SHA-2 Variants Compared​

AlgorithmHash lengthWord sizeBlock sizeRounds
SHA-224224 bits32 bits512 bits64
SHA-256256 bits32 bits512 bits64
SHA-384384 bits64 bits1024 bits80
SHA-512512 bits64 bits1024 bits80
SHA-512/224224 bits64 bits1024 bits80
SHA-512/256256 bits64 bits1024 bits80

This already reveals an important property of the family:

The length of the finished hash value does not automatically tell you how the algorithm works internally.

SHA-256 and SHA-512/256, for example, both produce a hash value of 256 bits. Internally, however, they use different word and block sizes.

SHA-224 and SHA-256​

SHA-224 and SHA-256 form the 32-bit side of the SHA-2 family.

Both algorithms:

  • work with 32-bit words,
  • process messages in 512-bit blocks,
  • generate a message schedule with 64 words,
  • and perform 64 compression rounds per message block.

Nevertheless, SHA-224 is not simply SHA-256 with 32 bits removed from the finished hash value afterward.

SHA-224 uses different initial hash values and then produces an output of 224 bits.

SHA-256, by contrast, delivers 256 bits.

You can try out directly how different SHA-224 and a SHA-256 hash truncated to 224 bits actually turn out for the same input in What Is SHA-224?.

If you want to understand how these algorithms are built, SHA-256 is a good starting point. In How Does SHA-256 Work?, we take a closer look at padding, the message schedule, and the compression function, among other things.

With SHA-256 Step by Step, you can also follow the complete process with your own input in the browser.

SHA-384 and SHA-512​

SHA-384 and SHA-512 belong to the 64-bit side of the family.

They work with:

  • 64-bit words,
  • 1024-bit message blocks,
  • a message schedule with 80 words,
  • and 80 compression rounds per message block.

Here, too, SHA-384 is not simply an ordinary SHA-512 hash whose output is truncated afterward.

SHA-384 has its own initial hash values and produces an output of 384 bits.

SHA-512, by contrast, produces the complete 512-bit hash value.

You can try out directly how different SHA-384 and a SHA-512 hash truncated to 384 bits actually turn out for the same input in What Is SHA-384?.

In What Is SHA-512?, we take a closer look at this variant.

If you want to see the differences from the 32-bit structure directly, you can compare the same input with both algorithms in SHA-256 vs. SHA-512 – What Is the Difference?.

What Are SHA-512/224 and SHA-512/256?​

The names SHA-512/224 and SHA-512/256 look somewhat unusual at first.

The part before the slash describes the underlying SHA-512-based structure. The part after it gives the length of the resulting hash value.

So SHA-512/224 produces a hash value of 224 bits.

SHA-512/256 produces a hash value of 256 bits.

Both, however, use the 64-bit structure of the SHA-512 family with 1024-bit blocks and 80 compression rounds.

These variants, too, are not simply SHA-512 with a hash value truncated afterward. For SHA-512/t, dedicated initial hash values are generated using a procedure defined in the standard.

This leads to an initially surprising situation:

SHA-256 and SHA-512/256 both produce 256-bit hash values, but they are different hash functions.

That is exactly why the hash length alone isn't enough to describe an algorithm.

You can find out exactly how the SHA-512/t IV generation function works, and try out directly how different SHA-512/224, SHA-512/256, and a correspondingly truncated SHA-512 hash actually turn out for the same input, in What Are SHA-512/224 and SHA-512/256?.

Why Are There So Many SHA-2 Variants?​

Different applications can have different requirements for hash length, security strength, performance, or the platform used.

A longer output, for example, requires more storage space or transmission bandwidth. At the same time, the output length affects certain cryptographic security properties.

The internal word size can also play a role.

SHA-256 works with 32-bit words, while SHA-512 and its related variants use 64-bit words. On platforms with efficient 64-bit arithmetic, this can affect performance.

The various SHA-2 variants therefore enable different combinations of internal structure and desired hash length.

Does a Longer Hash Automatically Mean More Security?​

Not quite.

The length of a hash value does influence the generic security strength against certain attacks. Which security strength is relevant, however, depends on which property is being considered.

For an idealized hash function with n bits of output, the effort for a generic preimage attack is roughly on the order of:

2^n

For finding a collision, by contrast, the generic effort, due to the birthday effect, is roughly:

2^(n/2)

For SHA-256, in idealized terms, this means roughly:

Preimage: 2^256
Collision: 2^128

A 512-bit output therefore doesn't simply mean "twice as secure" as a 256-bit output across the board.

Which number is relevant depends on the security property being considered and the specific use case.

You can find more on this in How Secure Are 128, 256, and 512 Bits?

Is SHA-2 Still Secure Today?​

The SHA-2 family remains relevant for numerous cryptographic applications and is used in current standards.

However, that doesn't mean every use of SHA-2 is automatically secure.

Context is always decisive.

One example is passwords.

SHA-256 and SHA-512 are general-purpose cryptographic hash functions that are deliberately fast to compute. This very speed is problematic for storing passwords directly, because it lets attackers try a very large number of password candidates.

For password storage, dedicated password-hashing schemes with a salt and a suitable cost factor are therefore used.

So the question isn't just:

Is SHA-2 secure?

But rather:

Is this hash function suitable for this specific use case?

SHA-2 Is Not SHA-3​

Despite the name, SHA-3 is not simply an improved version of SHA-2 with larger hash values.

SHA-3 is based on a fundamentally different construction.

The SHA-3 family includes, among others:

  • SHA3-224
  • SHA3-256
  • SHA3-384
  • SHA3-512

Here, too, the numbers describe the respective output length. However, a SHA3-256 hash is not the same as a SHA-256 hash.

SHA-2 and SHA-3 are different hash families, both of which are standardized.

We'll therefore look at SHA-3 later as a topic of its own.

Which SHA-2 Variant Should I Know?​

If you want to understand how SHA-2 works in general, I would start with SHA-256.

SHA-256 already uses all the essential concepts that matter for understanding the family:

With the SHA-256 Explorer, you can follow these steps with any input of your own.

After that, SHA-512 is particularly interesting, because it makes it easy to see how the second major structure within the SHA-2 family is built.

SHA-224, SHA-384, and SHA-512/224 and SHA-512/256 then make much more sense: they are not entirely new constructions, but variants within these two fundamental structures.

The Key Takeaways​

SHA-2 is not a single hash function, but a family of cryptographic hash functions.

The family includes SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256.

SHA-224 and SHA-256 use a 32-bit structure with 512-bit blocks and 64 compression rounds.

SHA-384, SHA-512, SHA-512/224, and SHA-512/256 use a 64-bit structure with 1024-bit blocks and 80 compression rounds.

The hash length alone therefore doesn't describe the internal structure of a hash function. SHA-256 and SHA-512/256, for example, both produce 256 bits but are based on different structures.

If you really want to understand SHA-2, SHA-256 is the best place to start. After that, SHA-512 shows the second fundamental structure of the family.

Sources​

  1. National Institute of Standards and Technology (NIST), FIPS PUB 180-4 – Secure Hash Standard (SHS).
  2. National Institute of Standards and Technology (NIST), Secure Hashing.
  3. National Institute of Standards and Technology (NIST), FIPS PUB 202 – SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions.