How Ed25519 signs a message on an Edwards curve

Short answer: Ed25519 signs a message on the twisted Edwards curve related to Curve25519. SHA-512 of the 32-byte secret splits into a clamped scalar and a prefix. The public key is the base point times that scalar. The nonce is SHA-512 of the prefix and the message, reduced modulo the group order. The signature is the nonce point, followed by the nonce plus the challenge times the scalar, modulo the group order. RFC 8032 test 1 is the empty message.


What the problem actually asks

Ed25519 is not ECDSA with a different curve. The nonce comes from the secret prefix and the message, so the signer does not draw a fresh random scalar for each signature. The base point has y-coordinate 4/5, and the x-coordinate is the even root recovered from the curve equation. The group order is 2^252 + 27742317777372353535851937790883648493. SHA-512 is the hash. The fragment signs. The check against the published test vector is the acceptance test for this secret and the empty message.


What the algorithm guarantees

For the RFC 8032 secret and the empty message, the 64-byte signature matches the published vector. The scalar is clamped by clearing the low three bits, clearing the top two bits of the last byte, and setting bit 254. The challenge is SHA-512 of the nonce point, the public key, and the message. A different message produces a different nonce and a different challenge. The public key is derived from the secret. It is not a second input.


The working steps

  1. Hash the 32-byte secret with SHA-512. Clamp the first 32 bytes to obtain the scalar. Keep the last 32 bytes as the prefix.
  2. Multiply the base point by the scalar and encode the public key.
  3. Set r to SHA-512 of the prefix and the message, reduced modulo the group order, and encode R = rB.
  4. Set k to SHA-512 of R, the public key, and the message, reduced modulo the order. The signature is R followed by (r + k * scalar) mod L.

Approaches that look simpler and fail

Approach Why it fails when it is treated as ECDSA
Draw a random nonce the way ECDSA does Ed25519 derives the nonce from the prefix and the message. A separate random nonce is a different scheme.
Pack the public key as a separate x-coordinate and y-coordinate The 32-byte key is the y-coordinate, with the sign of x stored in the high bit of the last byte.
Hash the message with SHA-256 and sign that digest as a raw integer The message enters SHA-512 together with the prefix and again with the public key. A prehashed SHA-256 integer is a different input.
Accept a signature without checking it against the public key The fragment reproduces the RFC signing vector. Verification recomputes the challenge and the linear combination.

ECDSA on the toy Weierstrass curve is the two-scalar signature. Ed25519 is the Edwards signature with a derived nonce.


A working example

This Python fragment signs the empty message with the RFC 8032 test secret. It prints e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b.

import hashlib

def _ed_recover_x(y: int, sign: int) -> int:
    p = 2**255 - 19
    d = (-121665 * pow(121666, -1, p)) % p
    y2 = y * y % p
    u = (y2 - 1) % p
    v = (d * y2 + 1) % p
    x = pow(u * pow(v, -1, p), (p + 3) // 8, p)
    if (v * x * x - u) % p != 0:
        x = x * pow(2, (p - 1) // 4, p) % p
    if x % 2 != sign:
        x = p - x
    return x

def _ed_add(P, Q, p, d):
    x1, y1 = P
    x2, y2 = Q
    denx = (1 + d * x1 * x2 * y1 * y2) % p
    deny = (1 - d * x1 * x2 * y1 * y2) % p
    x3 = (x1 * y2 + y1 * x2) * pow(denx, -1, p) % p
    y3 = (y1 * y2 + x1 * x2) * pow(deny, -1, p) % p
    return x3, y3

def _ed_mul(bx, by, scalar, p, d):
    result = (0, 1)
    addend = (bx, by)
    while scalar:
        if scalar & 1:
            result = _ed_add(result, addend, p, d)
        addend = _ed_add(addend, addend, p, d)
        scalar >>= 1
    return result

def _ed_pack(y: int, x: int) -> bytes:
    out = bytearray(y.to_bytes(32, "little"))
    out[31] |= (x & 1) << 7
    return bytes(out)

def ed25519_sign(secret: bytes, message: bytes) -> bytes:
    p = 2**255 - 19
    L = 2**252 + 27742317777372353535851937790883648493
    d = (-121665 * pow(121666, -1, p)) % p
    digest = hashlib.sha512(secret).digest()
    a = bytearray(digest[:32])
    a[0] &= 248
    a[31] &= 63
    a[31] |= 64
    scalar = int.from_bytes(a, "little")
    prefix = digest[32:]
    by = (4 * pow(5, -1, p)) % p
    bx = _ed_recover_x(by, 0)
    ax, ay = _ed_mul(bx, by, scalar, p, d)
    public = _ed_pack(ay, ax)
    r = int.from_bytes(hashlib.sha512(prefix + message).digest(), "little") % L
    rx, ry = _ed_mul(bx, by, r, p, d)
    R = _ed_pack(ry, rx)
    k = int.from_bytes(hashlib.sha512(R + public + message).digest(), "little") % L
    s = (r + k * scalar) % L
    return R + s.to_bytes(32, "little")

secret = bytes.fromhex("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60")
signature = ed25519_sign(secret, b"")
assert signature.hex() == "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"
print(signature.hex())

Where it is used

OpenSSH and a long list of new signature APIs use Ed25519. The secret is 32 bytes, the signature is 64, and the nonce comes from the message rather than from a separate random draw. ECDSA is the Weierstrass signature those keys replaced.


When you can drop this algorithm

Drop a signer that substitutes a random ECDSA nonce or a different clamp. Keep Ed25519 where the 32-byte secret is random, the message is the raw message, and verification uses the derived public key.


Why this stays published

We publish this so a search for Ed25519 returns the clamped scalar, the derived nonce, and the RFC 8032 empty-message signature. Ed25519 derives both the signing scalar and the nonce from SHA-512, and the signature is a point plus a linear combination modulo the group order.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *