ECDSA

What is ECDSA?

ECDSA is a cryptographic algorithm used for digital signatures based on elliptic curve cryptography (ECC). It’s widely used in secure systems like:

  • Bitcoin and Ethereum
  • TLS (HTTPS)
  • JWTs
  • Secure messaging (e.g. Signal)

It’s a more efficient version of DSA (Digital Signature Algorithm) using elliptic curves — providing strong security with smaller keys.


🧠 What is it used for?

ECDSA is used to:

  • ✅ Sign data (e.g., a transaction, message, or file)
  • ✅ Verify that the data came from a particular private key (authenticity)
  • ✅ Detect if the data was changed (integrity)

📦 Key components

  1. Elliptic Curve
    • A mathematical curve over a finite field, e.g., secp256k1 (used in Bitcoin), or P-256.
    • Public/private key pairs are points on this curve.
  2. Private key (d)
    • A random scalar (integer)
    • Must be kept secret
  3. Public key (Q = d * G)
    • A point on the curve derived from the private key and base point G
  4. Base point (G)
    • A publicly known generator point on the curve

✍️ Signing (ECDSA Sign)

To sign a message:

  1. Hash the message to get a digest z (e.g. using SHA-256)
  2. Choose a random nonce k (must be unique for each signature!)
  3. Compute R = k * G (a point on the curve)
  4. Let r = R.x mod n (where n is the curve order)
  5. Compute s = k⁻¹ * (z + r * d) mod n

The signature is the pair (r, s).

⚠️ If k is reused, the private key d can be recovered! (This happened to Sony in 2010.)


✅ Verifying (ECDSA Verify)

Given a message msg, signature (r, s), and public key Q, you:

  1. Hash the message: z = HASH(msg)
  2. Compute w = s⁻¹ mod n
  3. Compute u1 = z * w mod n and u2 = r * w mod n
  4. Compute point R = u1 * G + u2 * Q
  5. Signature is valid if R.x mod n == r

🔁 Summary

StepMath operationPurpose
KeyGenQ = d * GCreate public key
Signr = (k * G).x, s = k⁻¹(z + r * d) mod nSign message
VerifyR = u1 * G + u2 * Q, check R.x == rVerify message

Leave a Reply

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