0Pricing
Cryptology Academy · Lesson

SHA-1 & SHA-2 Family Explained

Understand SHA-1's weakness and how SHA-256 and SHA-512 differ.

SHA-1 & SHA-2 Family Explained is a free Cryptology Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

SHA-1 and SHA-2 are the NSA-designed successors to MD5. SHA-1 is now retired. SHA-256 and SHA-512 remain the industry standard for most applications.

SHA-1 Overview

SHA-1 produces a 160-bit (20-byte) hash. Designed by NSA, published 1995. Example: SHA1('hello') = aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d

SHA-1 Structure

SHA-1 uses 80 rounds grouped in 4 stages of 20 rounds. Each stage uses different logical functions (Ch, Parity, Maj). It extends 16 input words to 80 using XOR and rotations.

SHA-1 Collision: SHAttered (2017)

In 2017, Google and CWI Amsterdam produced the first practical SHA-1 collision (the SHAttered attack). Two PDFs with identical SHA-1 hashes but different content. Cost: ~6500 GPU-years.

SHA-2 Family

SHA-2 includes: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, SHA-512/256. All are Merkle-Damgård. SHA-256 is the most commonly used variant.

SHA-256 Structure

SHA-256 uses 64 rounds on 512-bit blocks. It maintains 8 state words of 32 bits each (a,b,c,d,e,f,g,h). Each round mixes input words using Ch, Maj, Σ0, Σ1 functions.

SHA-256 in Python

import hashlib msg = b'hello' digest = hashlib.sha256(msg).hexdigest() print(digest) # 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

SHA-512 vs SHA-256

SHA-512 uses 80 rounds with 64-bit words, producing 512 bits. It is faster on 64-bit hardware but produces larger digests. Use SHA-512 when 256-bit security level is needed.

SHA-3 (Keccak)

SHA-3 was standardized in 2015 as an alternative design. It uses the sponge construction instead of Merkle-Damgård, making it immune to length-extension attacks.

Length-Extension Attacks on SHA-2

SHA-256(secret || message) is vulnerable: an attacker knowing Hash(message) can compute Hash(message || padding || extra). This is why HMAC uses a double-hash construction.

When to Use Which

SHA-256: general purpose, TLS, certificates, HMAC. SHA-512: higher security margin applications. SHA-3: new protocols without length-extension concerns. Never SHA-1 or MD5 for new designs.

Quick Check

What construction does SHA-3 use that makes it immune to length-extension attacks?

Recap

You understand the SHA family evolution. Next we study the practical applications of hashes: checksums, HMAC, and Git's use of SHA.

Frequently asked questions

Is the “SHA-1 & SHA-2 Family Explained” lesson free?

Yes — the full text of “SHA-1 & SHA-2 Family Explained” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “SHA-1 & SHA-2 Family Explained”?

Understand SHA-1's weakness and how SHA-256 and SHA-512 differ. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SHA-1 & SHA-2 Family Explained” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Makes a Good Hash Function
  2. MD5: History, Uses & Why It Is Broken
  3. SHA-1 & SHA-2 Family Explained
  4. Hash Applications: Checksums, HMAC & Git
← Back to Cryptology Academy