12. Digital Signatures
Proving authorship without sharing secrets
A handwritten signature proves you wrote something. A digital signature does the same thing, but it's mathematically unforgeable. Only the signer's private key can produce it, but anyone with their public key can verify it. Unlike encryption (which hides content), signatures prove identity and integrity — they answer "who sent this?" and "was it modified?"
The Problem Signatures Solve
A digital signature provides three properties that no symmetric cipher can:
- Authentication — proves who sent the message. Only the holder of the private key could have produced the signature.
- Integrity — proves the message wasn't altered. Any change to the message invalidates the signature.
- Non-repudiation — the signer can't later deny signing. Since only they hold the private key, the signature is proof of authorship.
Encryption
Hides content from eavesdroppers.
Goal: confidentiality.
Encrypt with public key, decrypt with private key.
Signatures
Proves who sent the message and that it wasn't altered.
Goal: authentication + integrity.
Sign with private key, verify with public key.
How Signing Works
-
Hash the message
Run the message through a hash function (e.g., SHA-256) to get a fixed-size digest. A 10 KB email and a 4 GB file both produce a 256-bit hash.
-
Encrypt the digest with your private key
This encrypted hash is the signature. Only your private key can produce it.
-
Send the message + signature
The message is sent in the clear (signatures don't encrypt). The signature travels alongside it.
-
Verifier checks the signature
The recipient hashes the message independently, decrypts the signature with your public key, and compares the two hashes. If they match, the signature is valid.
Why sign the hash, not the message?
Public-key operations (RSA, ECDSA) are slow — orders of magnitude slower than hashing. A SHA-256 hash is always 32 bytes regardless of input size. By signing the hash instead of the raw message, we keep the expensive public-key math fixed at a tiny input, while the fast hash function handles the bulk data.
RSA Signatures
RSA signing is the textbook example. It uses the same key pair as RSA encryption, but the operations are reversed: sign with the private key, verify with the public key.
Worked example with small numbers
Key generation (same as RSA encryption):
p = 61, q = 53
n = 61 × 53 = 3233
φ(n) = 60 × 52 = 3120
e = 17 (public exponent)
d = 2753 (private exponent, since 17 × 2753 ≡ 1 mod 3120)
Public key: (n=3233, e=17)
Private key: (n=3233, d=2753)
Suppose the message hash (simplified) = 1234
Signing:
s = hash^d mod n
s = 1234^2753 mod 3233
s = 1465
Verifying:
hash' = s^e mod n
hash' = 1465^17 mod 3233
hash' = 1234
hash' == hash? 1234 == 1234 ✓ Signature valid!
The private exponent d is the only value that could produce a signature s whose e-th power recovers the original hash. Forging a signature requires knowing d, which requires factoring n.
ECDSA: Elliptic Curve Signatures
ECDSA (Elliptic Curve Digital Signature Algorithm) is the most widely deployed signature scheme today. It powers Bitcoin transactions, TLS certificates, and code signing on every major platform. The key advantage: equivalent security with much smaller signatures and keys than RSA.
ECDSA signing in brief
Key pair:
Private key: d (random integer)
Public key: Q = d × G (a point on the curve)
Signing message m:
- Compute hash h = SHA-256(m)
- Pick a random nonce k
- Compute point R = k × G
- r = R.x mod n (x-coordinate of R)
- s = k⁻¹ × (h + r·d) mod n
- Signature = (r, s)
Verifying:
- Compute h = SHA-256(m)
- Compute u₁ = h·s⁻¹ mod n, u₂ = r·s⁻¹ mod n
- Compute P = u₁×G + u₂×Q
- Valid if P.x ≡ r (mod n)
The nonce k must be secret and unique
If the nonce k is ever reused or predictable, the private key can be recovered algebraically from two signatures. This is not a theoretical concern — it's what broke the PlayStation 3's code signing in 2010. Sony used a fixed k for every signature, allowing hackers to compute the private key and sign arbitrary code. The same flaw has drained cryptocurrency wallets when k values were generated from weak random number generators.
EdDSA and Ed25519
ECDSA's dependence on a random nonce is a landmine. EdDSA (Edwards-curve Digital Signature Algorithm) eliminates it entirely with a simple design change: the nonce is derived deterministically from the message and the private key. No randomness needed at signing time means no nonce-reuse vulnerability.
Ed25519 at a glance
Curve: Curve25519 (in twisted Edwards form)
Key size: 256-bit private key, 256-bit public key
Signature: 512 bits (64 bytes)
Nonce: Deterministic — H(private_key_seed || message)
Speed: ~70,000 signatures/sec on a laptop
Verification: ~25,000 verifications/sec
Signing:
- Derive nonce r = SHA-512(key_seed || message) ← deterministic!
- Compute R = r × G
- Compute S = r + SHA-512(R || public_key || message) × private_key
- Signature = (R, S)
Same message + same key always produces the same signature.
No random number generator involved.
Ed25519 is now the default key type in OpenSSH, and is used by Signal, WireGuard, age encryption, and many modern systems. If you're choosing a signature scheme for a new project, Ed25519 is the standard recommendation.
Certificates: Signatures All the Way Down
A certificate is a public key bundled with an identity (like a domain name), signed by a Certificate Authority (CA). Your browser trusts approximately 150 root CAs. The entire web PKI is built on digital signatures.
-
Root CA signs an intermediate CA's certificate
The root CA's private key creates a signature over the intermediate's public key and identity.
-
Intermediate CA signs the website's certificate
The intermediate's private key signs the website's public key + domain name.
-
Your browser verifies the chain
When you visit https://example.com, the server sends its certificate chain. Your browser verifies each signature back to a trusted root CA already installed on your device.
Certificate chain in practice
Root CA (trusted, pre-installed)
└── signs → Intermediate CA certificate
└── signs → example.com certificate
└── contains example.com's public key
Browser checks:
- Is example.com's cert signed by Intermediate CA? ✓
- Is Intermediate CA's cert signed by Root CA? ✓
- Is Root CA in my trusted store? ✓
→ Connection is trusted.
Code Signing
Operating system vendors require signed applications. When you install software, the OS verifies the developer's signature before allowing execution. This protects against tampering (modified binaries) and identifies the author so that malicious developers can be traced and blocked.
Signed does not mean safe
A signed binary doesn't mean the code is trustworthy — it means the author is identified and the code hasn't been modified since signing. Malware authors can (and do) obtain valid code-signing certificates. The signature tells you who wrote it, not whether it's safe.
Real-World Usage
| Application | Signature scheme |
|---|---|
| TLS certificates | ECDSA (P-256) or RSA |
| SSH authentication | Ed25519 (recommended), RSA (legacy) |
| Git commits | GPG (RSA/EdDSA) or SSH signatures |
| Code signing (macOS, Windows) | RSA or ECDSA |
| Bitcoin transactions | ECDSA (secp256k1), Schnorr (Taproot) |
| Ethereum transactions | ECDSA (secp256k1) |
| PDF signing | RSA or ECDSA |
| Email (S/MIME, PGP) | RSA or ECDSA |
Signature Sizes Compared
| Scheme | Signature size | Key size |
|---|---|---|
| RSA-2048 | 256 bytes | 256 bytes (public) |
| RSA-4096 | 512 bytes | 512 bytes (public) |
| ECDSA P-256 | 64 bytes | 32 bytes (public) |
| Ed25519 | 64 bytes | 32 bytes (public) |
ECDSA and Ed25519 signatures are 4–8x smaller than RSA for equivalent security. This matters in bandwidth-constrained environments: every TLS handshake, every Bitcoin transaction, every certificate chain benefits from smaller signatures.
Try It Yourself — Sign & Verify
Type a message and watch the RSA signing process step by step: hash the message, sign the hash with the private key, then verify with the public key. Uses toy RSA with p=61, q=53 for readable numbers.
Tamper Detection
The message below was signed above. Try changing it — even one character — and watch the signature verification fail. An attacker cannot fix the signature without the private key.
Certificate Chain Visualizer
Every HTTPS connection relies on a chain of digital signatures. The root CA signs the intermediate, the intermediate signs the website’s certificate. Your browser verifies each signature back to a trusted root.
Key Takeaways
- Digital signatures prove authentication, integrity, and non-repudiation — things encryption alone cannot provide
- We sign the hash of a message, not the message itself, because public-key operations are slow
- RSA signatures work by encrypting a hash with the private key; anyone can verify with the public key
- ECDSA provides the same security as RSA with much smaller keys and signatures, but requires a unique random nonce per signature
- Ed25519 eliminates the nonce-reuse vulnerability by deriving the nonce deterministically — it is the modern default
- Certificates are signatures all the way down: a chain of trust from your browser's root CAs to the website you're visiting
- A valid signature proves identity and integrity, not safety — signed code can still be malicious
Digital signatures are the foundation that makes TLS, code distribution, and cryptocurrency work. When your browser verifies a certificate, when Git checks a signed commit, when your phone validates an app update — the same math is running underneath. Combined with the key exchange (Diffie-Hellman) and symmetric encryption (AES) covered earlier in this series, signatures complete the trio of primitives that secure nearly all communication on the internet.