Notes
Signing
Signing uses the key pair from episode three in the other direction. First the data is hashed. Then the private key computes a signature from that hash. The data and the signature travel together. Notice that the data is not hidden: signing is not encryption, and anyone can read a signed message. What the signature adds is proof. Only the holder of the private key could have produced that value for that exact data.
- 1. hash the data (SHA-256 or similar)
- 2. the private key computes a signature from that hash
- 3. send the data and the signature together
- the data is NOT hidden; a signature is not encryption
- only the private key holder can produce it
Verifying
Verifying needs only the public key. The verifier hashes the data it received and checks the signature against that hash using the public key. The answer is valid or invalid, nothing in between. The public key can check signatures but cannot create them, so it is safe to hand to the whole world. That is the difference from HMAC, where anyone able to verify could also forge, because both sides hold the same secret.
- 1. hash the received data
- 2. check the signature against that hash with the public key
- 3. result: valid or invalid, nothing in between the public key cannot create signatures, only check them
- so verification can be given to the whole world
Run it
Here it is, run. We generated an E D two five five one nine key and signed a release message. The signature is sixty four bytes. Verifying with the public key succeeded. Then we changed one character, version two point four point one to two point four point two, and verified the same signature. The library raised invalid signature. Any change at all, to the data or to the signature, makes verification fail.
key = Ed25519PrivateKey.generate()
msg = b"release v2.4.1 sha256:9f2c..."
sig = key.sign(msg)
len(sig) # 64
key.public_key().verify(sig, msg)
# no error: valid
key.public_key().verify(sig,
b"release v2.4.2 sha256:9f2c...")
# raises InvalidSignature What you get
A valid signature proves three things. Integrity: the data has not changed. Authenticity: it was signed with that private key. And non-repudiation: the signer cannot credibly deny signing it, since nobody else has the key. It does not prove two things. It does not prove that the public key belongs to who you think it does; that needs certificates, the next episode. And it does not prove the content is safe: malware can be perfectly signed.
- Integrity: the data has not changed since signing
- Authenticity: it was signed with that private key
- Non-repudiation: the signer cannot credibly deny it
- it does NOT prove: the key belongs to who you think (that needs PKI), or that the content is safe
Algorithms
Three algorithms matter. RSA with PSS padding signed in a third of a millisecond, verified in twenty four thousandths, and produces a two hundred and fifty six byte signature. ECDSA on P two fifty six signed ten times faster with a signature of about seventy bytes. E D two five five one nine signed in thirty one thousandths of a millisecond with a sixty four byte signature. For new systems, E D two five five one nine is the usual recommendation.
sign verify size RSA-2048 PSS 0.334 ms 0.024 ms 256 B ECDSA P-256 0.035 ms - ~70 B Ed25519 0.031 ms 0.12 ms 64 B # RSA: slow to sign, fast to verify, # big signatures # Ed25519: small, fast, no random # number needed when signing
The ECDSA trap
There is a famous trap in ECDSA. Every signature needs a fresh random number. If the same number is ever used for two signatures, or if it is predictable, the private key can be calculated from the signatures alone. This has happened in real products, including a games console and mobile wallets. E D two five five one nine removes the risk by deriving that value from the key and the message. With RSA, choose PSS padding for new designs.
- ECDSA needs a fresh random number for every signature
- repeat it once, or make it predictable, and the private key can be calculated
- this has happened: a games console, Android wallets
- Ed25519 derives that value from the key and message
- RSA: use PSS, not v1.5
Where you rely on them
You rely on signatures constantly. A TLS server signs the handshake, and certificate authorities sign certificates. Operating system updates, drivers and mobile apps are signed. Package managers verify signed repository metadata. Git supports signed commits and tags. Container images are signed with tools like cosign. JWTs are signed. Email uses DKIM signatures. And SSH keys and passkeys log you in by signing a challenge.
- TLS: the server signs the handshake; CAs sign certs
- OS and app updates, drivers
- apt, dnf, npm provenance
- git: signed commits and tags
- container images: cosign
- JWTs: RS256, ES256, EdDSA
- documents and email: PDF, S/MIME, DKIM
- SSH and passkey logins
How attackers bypass it
Attackers rarely forge signatures. They go around them. They steal a signing key and sign their malware, which has happened to major vendors. They compromise the build system, so malicious code is signed by the official process: that is a supply chain attack. They rely on verification that is skipped or whose errors are ignored. They abuse JWT libraries that accept the algorithm none. Or the verifier trusts any key instead of one specific key.
- steal the signing key, then sign malware (it has happened to big vendors)
- compromise the build, so bad code is signed officially
- verification that is skipped or whose errors are ignored
- JWT "alg: none" or algorithm confusion
- trusting any key at all
Defend
Defenses. Keep signing keys in a hardware module or key management service, never on a developer laptop. Sign in the pipeline using short-lived identities, as Sigstore does. Verify before use, and fail closed: if verification errors, stop. Pin which key or identity is trusted, because a valid signature from the wrong signer is worthless. Fix the list of accepted algorithms. And log every signing operation, so misuse of a key is visible.
- signing keys in an HSM or KMS, never on laptops
- sign in CI with short-lived identity (Sigstore keyless)
- verify before use, and fail closed on any error
- pin WHICH key or identity is trusted, not just "signed"
- fix the allowed algorithms
- log every signing operation
Common mistakes
Mistakes. Checking that a signature is valid but not checking who signed it. Logging a failed verification and continuing anyway. Signing keys kept in pipeline variables or in a repository. Accepting whichever algorithm an incoming token asks for. Signing a hash produced with MD five or SHA one, where collisions make two documents share one signature. And confusing signing with encryption: a signed JWT is readable by anyone.
- verifying the signature but not who signed
- ignoring a failed check
- signing keys in CI variables or a repo
- accepting the algorithm the token asks for
- signing a hash made with MD5 or SHA-1
- confusing signing with encryption
Say it like this
In the interview: the signer hashes the data and signs the hash with a private key. Anyone can verify with the public key. That gives integrity, authenticity and non-repudiation, but not confidentiality. Unlike HMAC, the verifier cannot forge. I would add that a signature is only as good as two things: knowing whose public key it is, which is the job of certificates, and how well the private key is protected.
- "The signer hashes the data
- and signs the hash with a private key. Anyone verifies
- with the public key. That gives integrity, authenticity
- and non-repudiation, not secrecy. Trust still needs
- to know whose key it is, and the key must be protected."