How ECDSA signs a hash on an elliptic curve

Short answer: ECDSA signs with the same two-value shape as DSA, on an elliptic curve. The fragment uses y^2 = x^3 + 2x + 2 over the field of 17 elements. The point (5, 1) has order 19. The private scalar is 7, the message stand-in is 9, and the nonce scalar is 3. r is the x-coordinate of kG, reduced modulo 19. s is k^(-1) (z + r d) modulo 19. The signature is 10 1.


What the problem actually asks

ECDSA replaces the multiplicative subgroup with the group of points on a curve. Addition uses the chord-and-tangent rule. The point at infinity is the identity, written here as None. The order of the base point is the modulus of the signature arithmetic, and it is not the field prime. Here the field prime is 17 and the order is 19. The curve is a demonstration. A deployment uses a named curve with a large prime order and a hash in place of the integer 9.


What the algorithm guarantees

Nineteen times the base point is the identity, so the order claim is checked. Verification multiplies the base point by z s^(-1) and the public point by r s^(-1), adds those points, and compares the x-coordinate modulo the order with r. The fragment’s signature passes that check. A 17-element field does not hide the private scalar. The check shows the equations.


The working steps

  1. Publish the curve, the base point G, its order n, and the public point dG.
  2. Draw a nonce scalar k and set r to the x-coordinate of kG, reduced modulo n.
  3. Set s = k^(-1) (z + r d) mod n.
  4. Verify by adding (z s^(-1)) G and (r s^(-1)) times the public point, and compare the x-coordinate with r.

Approaches that look simpler and fail

Approach Why it fails on a toy curve, or with a repeated nonce
Deploy the field of 17 elements The group has nineteen points. A deployment uses a large prime order.
Reduce the signature modulo the field prime The signature modulus is the order of the base point. Here that order is 19, not 17.
Reuse the nonce scalar The ephemeral scalar is part of the secret. Each signature draws a new one.
Hash after signing the raw message integer z is a hash reduced modulo the order. The integer 9 only stands in for that hash.

DSA is the same signature in a multiplicative subgroup. Ed25519 is a different signature scheme on a twisted Edwards curve.


A working example

This Python fragment signs the integer 9 on the curve y^2 = x^3 + 2x + 2 over the field of 17 elements and checks the signature. It prints 10 1.

def _curve_demo() -> tuple[int, int, int, int, tuple[int, int], int]:
    # y^2 = x^3 + 2x + 2 over F_17. Generator (5, 1) has order 19.
    return 17, 2, 2, 19, (5, 1), 7

def _ec_add(p, a, P, Q):
    if P is None:
        return Q
    if Q is None:
        return P
    x1, y1 = P
    x2, y2 = Q
    if x1 == x2 and (y1 + y2) % p == 0:
        return None
    if P == Q:
        lam = (3 * x1 * x1 + a) * pow(2 * y1, -1, p) % p
    else:
        lam = (y2 - y1) * pow(x2 - x1, -1, p) % p
    x3 = (lam * lam - x1 - x2) % p
    y3 = (lam * (x1 - x3) - y1) % p
    return x3, y3

def _ec_mul(p, a, k, point):
    result = None
    addend = point
    while k:
        if k & 1:
            result = _ec_add(p, a, result, addend)
        addend = _ec_add(p, a, addend, addend)
        k >>= 1
    return result

p, a, _b, n, g, d = _curve_demo()
z, k = 9, 3
r = _ec_mul(p, a, k, g)[0] % n
s = pow(k, -1, n) * (z + r * d) % n
public = _ec_mul(p, a, d, g)
w = pow(s, -1, n)
point = _ec_add(p, a, _ec_mul(p, a, (z * w) % n, g), _ec_mul(p, a, (r * w) % n, public))
assert point[0] % n == r and _ec_mul(p, a, n, g) is None
print(r, s)

Where it is used

*ECDSA* on secp256k1 signs Bitcoin transactions, and ECDSA on P-256 signs a large share of TLS certificates and SSH keys. The signed integer is a hash modulo the group order. Ed25519 is a different signature on an Edwards curve.


When you can drop this algorithm

Drop this curve for any signature. Keep ECDSA where the curve is a published large curve, each signature draws a fresh nonce, and the signed integer is a hash modulo the group order.


Why this stays published

We publish this so a search for ECDSA returns the curve signature and the check on the x-coordinate. ECDSA signs with a fresh curve scalar and checks the signature by adding two scalar multiples and reading the x-coordinate.

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

Leave a Reply

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