opyebEd25519Lab

Ed25519 signing and verification, step by step

Signatures · 8 min read

In one line: Follow the RFC 8032 signing procedure to see why the signature is deterministic and why verification fails on a single changed bit.

An Ed25519 signature is 64 bytes: R in the first 32 and S in the last 32, produced by two different calculations. Following the order explains why verification is so strict.

1. From seed to scalar and prefix

h      = SHA-512(seed)          // 64 bytes
a      = clamp(h[0..32])        // scalar
prefix = h[32..64]              // used for the nonce
A      = encode([a]B)           // 32-byte public key

Clamping clears the low three bits, clears the top bit and sets the second-highest bit. That pins the scalar to a range and removes small-subgroup tricks.

2. Producing R and S

r = SHA-512(prefix ‖ M) mod L
R = encode([r]B)
k = SHA-512(R ‖ A ‖ M) mod L
S = (r + k·a) mod L
signature = R ‖ S           // 32 + 32 = 64 bytes

The critical detail: the nonce r is a hash of the prefix and message, not a random number. Unlike ECDSA, the same key and message always produce the same signature, and the classic disaster of a broken random generator leaking a private key is structurally impossible.

3. Verification recomputes a point

k' = SHA-512(R ‖ A ‖ M) mod L
R' = [S]B - [k']A
R' == R ?

The verifier has no private key. It computes R' from the public key, the signature and the message, then compares the re-encoded point with R. If R is not a valid curve point or S is out of range, verification fails before any comparison.

4. Why verification fails

CauseSymptom
One message bit differsFailure
R or S alteredFailure
S ≥ L (out of range)Failure (canonical check)
Different public keyFailure
Message decoded differentlyFailure even though the text looks the same — check UTF-8, hex, Base64

The last row is the common one in practice. Sign "Hello" as UTF-8 and verify it interpreted as hex, and the bytes are entirely different. Failure is not proof of tampering. Match the input format first.

5. Determinism is useful

Same input, same output makes testing easy. RFC 8032 vectors assume it, and comparing a signature character by character is the fastest way to check an implementation. Sign a vector's seed and message in panel ② and compare against the expected value in panel ⑤.

seed      9d61b19d…7f60
message   (empty string)
signature e5564300…7a100b

6. The tamper test

The tamper button in panel ③ flips one bit in the final signature byte. Verification must fail immediately. If it does not, something is wrong with the input format or the implementation — which is itself a useful signal.

Making a key yourself shows the format differences immediately.

Open Ed25519Lab

Frequently asked questions

Why is an Ed25519 signature always the same?

The nonce comes from SHA-512(prefix‖M) instead of a random source, so an identical message gives an identical nonce and signature. That is a designed property, not nonce reuse.

What if the signature is not 64 bytes?

Verification fails. 128 hex characters or 86 Base64url characters is the valid length; anything else is a format error.

References

Read next

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)