Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lamport One-Time Signatures 🔐🧮

CI

A from-scratch implementation of the Lamport one-time signature (OTS) scheme — a hash-based, post-quantum digital signature whose security rests only on the one-wayness of a hash function (here SHA-256), not on factoring or discrete logs. That's what makes hash-based signatures interesting: they remain secure even against a quantum adversary.

Standard-library Python only. No external crypto dependencies.

How Lamport signatures work

  1. Key generation. For each of the 256 bits of a message hash, generate two random secret values — one for a 0 bit, one for a 1 bit (a 2×256 secret key). The public key is the SHA-256 hash of every secret value.
  2. Signing. Hash the message (256 bits). For each bit, reveal the secret value corresponding to that bit's value. The revealed values are the signature.
  3. Verification. Hash each signature element and check it equals the matching public-key entry for that message bit.

The scheme is one-time: signing two different messages with the same key leaks enough secrets to forge, which is exactly why the code and tests focus on a single message per key.

Run it

python src/demo.py
message : b'transfer 100 to alice'
verify(correct message) : True
verify(tampered message): False   <- one flipped byte breaks the signature

Tests

pip install pytest && python -m pytest tests/ -v

Three tests run against fixed test vectors (tests/test_case.py): correct key generation + signing + verification, and that verification fails when either the message or the signature is tampered with.

Why it matters

Lamport signatures are the conceptual foundation of modern stateless hash-based signatures like SPHINCS+, which NIST standardized (as SLH-DSA) for the post-quantum era. This project implements the core idea end to end.

Educational implementation. For production post-quantum signatures, use a vetted library implementing a standardized scheme (SLH-DSA / ML-DSA).

Author

Koushik Chowdary — LinkedIn · GitHub

About

From-scratch Lamport one-time signatures (SHA-256): a hash-based, post-quantum signature scheme, the basis of SPHINCS+/SLH-DSA. Demo + tests against fixed vectors.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages