SECURITY ENGINEERING · PART 4 · CRYPTOGRAPHY IN PRACTICE · SIGNATURES · 51 OF 229

Digital Signatures Explained: Ed25519, ECDSA and RSA

A digital signature proves who produced some data and that it has not changed since. This episode shows how signing and verifying work, real Ed25519 output (a 64-byte signature in 0.03 ms, and a tampered message rejected), how RSA-PSS, ECDSA and Ed25519 compare, where signatures protect you every day (TLS, software updates, git commits, container images, JWTs), and how attackers get around them.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 13

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Private key signs, public key verifies
  • integrity, authenticity, non-repudiation
  • Ed25519 for new systems
  • check who signed

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.

How signing works
  • 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.

How verifying works
  • 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.

sign and verify
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.

A valid signature proves
  • 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.

our measurements
              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.

Why Ed25519 is preferred
  • 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.

Signatures in daily use
  • 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.

Real bypasses
  • 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.

Defenses
  • 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.

Avoid these
  • 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.

In the interview
  • "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."

Interview questions

Q1What is a digital signature?

A value computed from data with a private key that anyone can verify with the corresponding public key. A valid signature shows that the data has not been altered and that it was signed by the holder of that private key.

Q2What is the difference between a digital signature and encryption?

Encryption hides data and uses the recipient's public key to encrypt. A signature does not hide anything; it uses the signer's private key to prove origin and integrity. The two are often combined but solve different problems.

Q3What is the difference between a digital signature and an HMAC?

An HMAC uses one shared secret, so any verifier can also create valid tags and there is no non-repudiation. A signature uses a key pair, so verification can be public while only the private key holder can sign.

Q4What is non-repudiation?

The property that a signer cannot plausibly deny having signed something, because only they hold the private key. It depends on the private key being properly protected and on reliable binding of the public key to an identity.

Q5Ed25519, ECDSA or RSA: which signature algorithm should you use?

Ed25519 for new systems: fast, small 64-byte signatures and deterministic, so it avoids nonce failures. ECDSA P-256 where standards or hardware require it. RSA with PSS and at least 2048 bits for compatibility with older systems.

Q6Why is nonce reuse in ECDSA dangerous?

ECDSA requires a unique secret random value for each signature. If the same value signs two different messages, or the value is predictable, simple algebra on the signatures reveals the private key. Deterministic schemes avoid this.

Q7What is code signing?

Signing software, such as executables, packages, updates or container images, so that systems can verify the publisher and detect tampering before running it. Its security depends on protecting the signing key and the build pipeline.

Q8How can a valid signature still be dangerous?

A signature only proves which key signed the data. If the key was stolen, the build system was compromised, or the verifier does not check that the signer is the expected one, malicious content can carry a perfectly valid signature.