Boost PC performance: How more available memory can improve productivity
Bitcoin Addresses
1. Bitcoin Addresses
How they are generated from public keys
(a step-by-step guide)
Ash Moran
aviewfromafar.net
ash@ashleymoran.net
2. Anatomy of an Address
1kqHKEYYC8CQPxyV53nCju4Lk2ufpQqA2
address
prefix
Base58Check encoding of
the cryptographic hash
of something
(indicated by the prefix)
4. What’s Base58?
Represents numbers (eg decimal, base ten, numbers
using the digits 0-9) using 58 characters
Uses 1-9, most of A-Z and a-z, except:
No letter capital i (I), lowercase L (l), O or 0
Like hexadecimal, but with more digits
11. Hashing
A hash function takes a value in
eg “This is my message”
Returns a fixed length number out
eg 1129729371291755845
Generates a different number if the input changes even
slightly
“This it my message” => 3763820994290329705
12. Cryptographic hashing
Like hashing but designed so it’s very very hard to figure out the message from the hash.
hash_function(“This is my message”) => hash_value – EASY!
hash_value => <?what was the message?> – HARD!
Bitcoin uses SHA256 and RIPEMD-160 hash functions
SHA256(“This is my message”) =>
3311b7c0bd91b6c73a38212de8ade31c51910f17480ad212ed2b9798a35b7747
SHA256(“This it my message”) =>
26a9911800b6115eb7ee508f60a2fd6479d45155a8aef1b1a35eb3173a512063
RIPEMD160(“This is my message”) =>
bdb6824f7b28e7dd9b9d6b457142547064435937
13. Base58 version of a hash
RIPEMD160(“This is my message”) =>
bdb6824f7b28e7dd9b9d6b457142547064435937
hex:
bdb6824f7b28e7dd9b9d6b457142547064435937
decimal:
1083069342955023797228115257453753838398332950839
Base58(1083069342955023797228115257453753838398332
950839) =>
3eJ7uPEgX8h56UJmTNmqwTvHs9H8
15. Public/private key signing
Problem: Alice wants to send Bob a message and
want anybody to be able to verify that the message
came from her. She wants to make sure nobody can
forge her signature on the message.
16. Elliptic Curve Cryptography
See the excellent guide
A (relatively easy to understand) primer on elliptic curve cryptography
by Nick Sullivan
17. Elliptic Curve Cryptography
Private key: a random 256-bit (32-byte) integer
Public key: an (x, y) point on the curve, either:
the number 4, followed by 256-bit x and y coordinates
(old uncompressed 65-byte format)
[4, x, y]
the number 2 or 3 followed by a 256-bit x coordinate
(new compressed 33-byte format)
[2, x, y] or [3, x, y]
22. Bitcoin pubkey address
Take the pubkey with header byte, e.g. [4, x, y]
Run it through the SHA256 hash function
pubkey_hash_step_1 = SHA256([4, x, y])
Run it through the RIPEMD160 hash function
pubkey_hash = RIPEMD160(pubkey_hash_step_1)
Add a byte to the start to indicate which network it’s for (Bitcoin 00,
Namecoin 34, Bitcoin testnet 6f)
plain_binary_address = [00, pubkey_hash]
TBC…
23. Checksum generation
Take the plain binary address, and run it through the SHA256 function
twice:
plain_address_hash = SHA256(SHA256(plain_binary_address))
Take the first four bytes of this hash as a checksum:
checksum = first_4_bytes(plain_binary_address)
Add the checksum onto the end to give the binary_address:
binary_address = [00, pubkey_hash, checksum]
Base58 encode the result:
bitcoin_address = Base58(binary_address)
Now we have the result, eg “16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM”