bitcoin address generation process

First, let's briefly talk about how a Bitcoin address is calculated. Bitcoin is based on mathematical encryption, and Satoshi Nakamoto used Elliptic Encryption Algorithm (ECDSA) to generate Bitcoin's private and public keys. The public key can be calculated from the private key, and the value of the public key will get the bitcoin address after a series of digital signature operations.
It should be noted that because the Bitcoin address can be calculated from the public key, we often confuse the terms of the public key and the Bitcoin address, but they both refer to a concept. A Bitcoin address is just another format of a public key.
It takes nine steps to get the bitcoin address we use from the bitcoin private key. SHA256 encryption, RIPEMD160 encryption and BASE58 encoding are used in the middle. The bitcoin private key and bitcoin address we finally use are generally the result of BASE58 encoding. The whole process is shown in the figure below.
write picture description here

The first step is to randomly select a 32-byte number with a size between 1 ~ 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4141 as the private key.
18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

The second step is to use the elliptic curve encryption algorithm (ECDSA-secp256k1) to calculate the uncompressed public key corresponding to the private key. (A total of 65 bytes, 1 byte 0x04, 32 bytes are the x coordinate, 32 bytes are the y coordinate) The issue of public key compression and non-compression is explained in another article.

0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B
23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6

The third step is to calculate the SHA-256 hash value of the public key
600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408

The fourth step, take the result of the previous step, calculate the RIPEMD-160 hash value
010966776006953D5567439E5E39F86A0D273BEE

The fifth step, take the result of the previous step and add the address version number (Bitcoin mainnet version number "0x00")
00010966776006953D5567439E5E39F86A0D273BEE

The sixth step, take the result of the previous step and calculate the SHA-256 hash value
445C7A8007A93D8733188288BB320A8FE2DEBD2AE1B47F0F50BC10BAE845C094

The seventh step, take the result of the previous step, and then calculate the SHA-256 hash value (haha)
D61967F63C7DD183914A4AE452C9F6AD5D462CE3D277798075B107615C1A8A30

The eighth step, take the first 4 bytes of the result of the previous step (8-digit hexadecimal)
D61967F6

The ninth step, add these 4 bytes to the result of the fifth step as a check (this is the hexadecimal form of the Bitcoin address).
00010966776006953D5567439E5E39F86A0D273BEED61967F6

The tenth step is to transform the address with base58 notation (this is the most common form of Bitcoin address).
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM

(Note: Some numbers start with "0x", which means that the number uses hexadecimal notation. "0x" itself has no meaning, it is handed down from the C language, and the conventional writing method, such as 0xA is decimal 10. Also, 1 byte = 8 bits binary = 2 bits hex).

The Bitcoin public key we often say refers to the result of the second step in the diagram. HASH160 refers to the result generated by the fourth step of RIPEMD160 signature. Since RIPEMD is also a HASH algorithm, it is collectively referred to as HASH160. And our commonly used bitcoin address is the result of BASE58 encoding.

Bitcoin clients and wallets also accept various Bitcoin address formats, commonly used formats are BASE58 format, WIF compression format, 130-bit and 66-bit public key (Public key) formats. Enter Bibuck's wallet tool and click on the wallet details query page, as shown in the figure below, the 130-bit string in the red box is the original public key calculated by Bitcoin ECDSA, the following is the public key compressed into 66-bit format, the above two are our The commonly used Bitcoin BASE58 address format and Bitcoin address WIF (wallet import format) compression format.

In fact, addresses in various formats are basically universal. After learning the relevant knowledge, we will have a deeper understanding of the Bitcoin system.
The Gobittest website (accessible abroad) provides calculation programs from Bitcoin's original private key to public key to HASH160 and BASE58, which readers can refer to.
write picture description here

Again:
Step 1: Generate a random private key

The private key is a random number, a 32-byte number is randomly selected. The range of this number is a number between 1 ~ 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4141, for convenience In the following calculation, we randomly generate a valid private key:

8F72F6B29E6E225A36B68DFE333C7CE5E55D83249D3D2CD6332671FA445C4DD3

Step 2: Calculate the public key by elliptic curve

After generating the private key, we use the elliptic curve encryption algorithm (ECDSA-secp256k1) to calculate the uncompressed public key corresponding to the private key. The generated public key has a total of 65 bytes, one of which is 0x04, and 32 of which are The X coordinate, the other 32 bytes are the Y coordinate:

Public key PX:
06CCAE7536386DA2C5ADD428B099C7658814CA837F94FADE365D0EC6B1519385

Public key PY:
FF83EC5F2C0C8F016A32134589F7B9E97ACBFEFD2EF12A91FA622B38A1449EEB

Step 3: Calculate the SHA-256 hash of the public key

Combine the above public key addresses to get the standard address:
0406CCAE7536386DA2C5ADD428B099C7658814CA837F94FADE365D0EC6B1519385FF83EC5F2C0C8F016A32134589F7B9E97ACBFEFD2EF12A91FA622B38A1449EEB

Align the SHA-256 hash and get the result:
2572e5f4a8e77ddf5bb35b9e61c61f66455a4a24bcfd6cb190a8e8ff48fc097d

Step 4: Calculate the RIPEMD-160 hash

Take the result of the previous step, perform RIPEMD-160 calculation, and get the result:

0b14f003d63ab31aef5fedde2b504699547dd1f6

Step 5: Add the address version number (Bitcoin mainnet version number "0x00")

Take the result of the previous step and add hexadecimal 00 in front, that is:

000b14f003d63ab31aef5fedde2b504699547dd1f6

Step 6: Calculate the SHA-256 Hash

Take the result of the previous step and perform SHA-256 calculation, you can get:

ddc2270f93cc84cc6869dd373f3c340bbf5cb9a8f5559297cc9e5d947aab2536

Then, calculate the SHA-256 hash value again on the above result, and get:

869ac57b83ccf75ca9da8895823562fffb611e3c297d9c2d4612aeeb32850078

Step 7: Take the first 4 bytes (8-digit hexadecimal) of the result of the previous step

869ac57b

Step 8: Add these 4 bytes to the result of Step 5

As a check digit, load these 4 bytes after the result of the fifth step, and this is the hexadecimal form of the Bitcoin address:

869ac57b000b14f003d63ab31aef5fedde2b504699547dd1f6

Step 9: Convert the address with Base58 encoding

Base58 encode the result of the previous step to get:

1QCXRuoxWo5Bya9NxHaVBArBQYhatHJrU7

This is the traditional Bitcoin wallet address we often see.

The above steps can be simplified as shown in the following figure:

write picture description here

The Bitcoin public key we often say refers to the result generated in the second step in the figure, and HASH160 refers to the result generated by the fourth step RIPEMD160 signature. Since RIPEMD is also a HASH algorithm, it is collectively referred to as HASH160. And our commonly used bitcoin address is the result of BASE58 encoding.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324451506&siteId=291194637