Skip to content
Back to the catalog
Project hash-functionsSecurityIntermediateBeta

SHA-256 and HMAC from scratch

Rotations, padding and the compression block. Sign and verify messages without touching a crypto library.

Build it in your language

The tester treats your program as a black box: any language works. These are just the most convenient ones for this project.

Guide language

The stage guides read in this language. Only languages this project is fully translated into show up here; the interface language does not change.

What this project is about

A cryptographic hash is a function that shows up everywhere — passwords, signatures, blockchains, file integrity — and that almost nobody has seen from the inside. Inside, it's rotations and additions, nothing more.

You'll implement SHA-256 from the padding to the compression block, check your output against the official test vectors, and use it to build HMAC and sign real tokens.

Roadmap

7 stages across 3 phases. Every stage comes with its guide and its tests: you move on when they pass.

  1. Phase 12 stages

    Preparing the message

    Padding, length in bits, and splitting into 512-bit blocks.

    1. 01SHA-256 padding
    2. 02Blocks and words
  2. Phase 23 stages

    The heart of the hash

    Message schedule, the 64 rounds, and validation against the NIST vectors.

    1. 01Message schedule
    2. 02One compression round
    3. 03Complete digest
  3. Phase 32 stages

    Putting it to use

    HMAC-SHA256, and signing and verifying tokens in constant time.

    1. 01HMAC-SHA256
    2. 02Signed tokens

Before you start

A standards-conformant SHA-256 implementation (padding, message schedule and the 64 compression rounds), validated against the NIST vectors, plus HMAC-SHA256 on top and a utility that signs and verifies tokens with constant-time comparison.

  • bittorrent
    Beta

    A BitTorrent client

    Bencode, trackers and the peer-to-peer protocol. Download a real file by talking to real peers.

    Advanced12 stages~20 hNetworking
    bencodep2pprotocolos+1

    Go · Python · Java

  • git
    Beta

    Build your own Git

    Blobs, trees and commits. Discover that Git is a content-addressed object store, and little else.

    Advanced12 stages~18 hTooling
    hashingzlibdag+1

    Go · Python · Rust