SHA-2
Adapted from Wikipedia · Discoverer experience
SHA-2, which stands for Secure Hash Algorithm 2, is a group of special math tools made to keep information safe. These tools were created by the United States National Security Agency and shared with the world in 2001. They help protect important data like passwords and secret messages by turning them into mixed-up codes that are hard to guess.
SHA-2 is an updated version of an older tool called SHA-1. It includes six different ways to create these safety codes, and the codes can be different lengths, like 224, 256, 384, or 512 bits. Two of the most used versions are SHA-256 and SHA-512. These two work in very similar ways but use different secret rules to make sure the codes stay safe.
These safety tools were first shared as an official United States standard by the National Institute of Standards and Technology. They were patented in the United States, but anyone can use them without paying extra fees. Even though some clever people have found small weaknesses, SHA-2 is still widely used to keep information safe today.
Hash standard
When the United States government released a new security rule in 2001, they added three new ways to protect information. These are called SHA-256, SHA-384, and SHA-512. These methods were created to make sure important data stays safe.
Over the years, more rules were added to keep these methods strong. In 2004, another method called SHA-224 was added. Later, in 2012, two more methods, SHA-512/224 and SHA-512/256, were created to make things even safer. Today, these methods help keep many things secure, from online information to important documents.
Main article: Secure Hash Standard
NIST hash function competition
Applications
Further information: Cryptographic hash function § Applications
The SHA-2 hash function is used in many important security tools and systems, like TLS, SSL, PGP, SSH, S/MIME, and IPsec. It helps keep information safe when we use the internet or send messages.
SHA-256 is used to check that software from Debian is real and unchanged, and it helps make sure emails are genuine with DKIM. SHA-512 is used to protect important video records from the International Criminal Tribunal of the Rwandan genocide. Both SHA-256 and SHA-512 help keep internet addresses secure with DNSSEC. Most computer systems that use Linux use SHA-2 to protect passwords.
Many cryptocurrencies, like Bitcoin, use SHA-256 to check that money transfers are real and fair. In mobile networks like 4G and 5G, SHA-256 is used to create special codes that keep our calls and data safe.
Cryptanalysis and validation
For a hash function, finding a message that matches a specific code can sometimes be done by trying every possibility, which is called a preimage attack. Another challenge is finding two different messages that produce the same code, known as a collision attack.
Some uses of cryptographic hashes, like storing passwords, are less affected by collision attacks. To create a password that works for a user, you would still need to access the original password's code. While secure password hashes help, they cannot stop attacks on very simple passwords.
In document signing, an attacker would need to create two documents—one harmless and one harmful—and get the owner to sign the harmless one. This was possible in the past with older security methods.
Researchers have found new ways to challenge SHA-2, but these are not strong enough to break the full system completely.
Official validation
Main article: Cryptographic Module Validation Program
Official checks ensure that security tools follow strict standards. As of December 2013, many versions of SHA-256 and SHA-512 have been officially checked and approved.
Test vectors
Here are some special numbers called "hashes" that help check if information is correct. These are created from empty messages or simple sentences.
Even a tiny change in the message, like adding a period, changes the hash a lot. This makes it very hard to trick the system.
Pseudocode
The SHA-256 algorithm is a way to take any message and turn it into a fixed-length string of numbers, called a hash. It follows a series of steps to mix and change the bits of the message.
First, the message is prepared by adding a single '1' bit, followed by some '0' bits, and then the length of the original message in bits. This makes the total length a multiple of 512 bits.
The message is then split into 512-bit chunks. For each chunk, the algorithm creates a list of 64 numbers and uses them to update eight working values. After processing all chunks, the final hash is created by combining these eight values together.
SHA-224 is similar to SHA-256 but uses different starting values and leaves out one of the final values in the output. SHA-512 works like SHA-256 but uses larger chunks, more steps, and 64-bit numbers instead of 32-bit numbers. Other versions like SHA-384 and SHA-512/t have their own specific changes to the starting values or output length.
Comparison of SHA functions
Further information: Merkle–Damgård construction
The table below shows how different SHA functions work inside, called the "internal state," after processing each block of data.
In the table, "Rot" means turning bits in a special way without carrying over numbers, and "Shr" means moving bits to the right. All these methods use adding numbers in a special way called modular addition, except for SHA-3.
The performance numbers for computers using x86 were tested on both 32-bit and 64-bit processors. SHA-256 works best on 32-bit computers but can run faster on 64-bit computers with special code. SHA-512 works much better on 64-bit computers than on 32-bit ones.
These tests were done by the University of Illinois at Chicago using two different computer systems. The speeds shown are for processing a piece of data that is 4,096 bytes long.
| CPU architecture | Frequency | Algorithm | Word size (bits) | Cycles/byte x86 | MiB/s x86 | Cycles/byte x86-64 | MiB/s x86-64 |
|---|---|---|---|---|---|---|---|
| Intel Ivy Bridge | 3.5 GHz | SHA-256 | 32 | 16.80 | 199 | 13.05 | 256 |
| SHA-512 | 64 | 43.66 | 76 | 8.48 | 394 | ||
| AMD Piledriver APU | 3.8 GHz | SHA-256 | 32 | 22.87 | 158 | 18.47 | 196 |
| SHA-512 | 64 | 88.36 | 41 | 12.43 | 292 |
Implementations
Many tools and programs can use SHA-2 for keeping information safe. Some of these tools include Botan, Bouncy Castle, Cryptlib, Crypto++, Libgcrypt, Mbed TLS, libsodium, Nettle, LibreSSL, OpenSSL, GnuTLS, and wolfSSL.
Some computers have special features that make SHA-2 work faster. These include Intel SHA extensions on certain Intel and AMD processors, VIA PadLock, ARMv8 Cryptography Extensions, IBM z/Architecture since 2005, and IBM Power ISA since version 2.07.
Related articles
This article is a child-friendly adaptation of the Wikipedia article on SHA-2, available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.
Safekipedia