Skip to content
Key Pair Generation
step 1/5

Reading — step 1 of 5

Read

~1 min readECDSA Algorithm

Key Pair Generation

Generate an ECDSA key pair:

python

d is the private key (a 256-bit integer in [1, n-1]). Q = dG is the public key (a point on the curve).

CRITICAL: use a CSPRNG. Not random.random(). Not the time. secrets.randbits (Python's CSPRNG) or os.urandom.

The private key must NEVER leak. Anyone with d can sign as you.

Storage:

  • Hardware: HSM, secure enclave (iPhone), Trezor, Ledger.
  • Software: encrypted file, sealed with a passphrase.
  • Memory: zero out as soon as possible after use.

Public key formats:

  • Uncompressed: 04 || x (32B) || y (32B) → 65 bytes.
  • Compressed: 02/03 || x → 33 bytes.

Bitcoin addresses:

  • Hash160(pubkey) = RIPEMD160(SHA256(pubkey))
  • Base58Check encode = address.

Address derivation hides the public key until you spend (the spend reveals it). Defense-in-depth if ECDSA is ever broken — addresses with no spends remain unbroken.

Address derivation is hash-based, but the underlying ownership is ECC.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…