Login
Ethereum: BIP39 Manual Passphrase Calculations – How Valid Are Multiple Checksums?
Introduction
Mnemonic phrases are an essential part of the Ethereum public key format, allowing users to securely manage their private keys and access their funds. The BIP39 (Bitcoin Improvement Proposal 39) standard provides a framework for generating mnemonic phrases that can be used to derive multiple checksums, ensuring the secure storage and transmission of sensitive information.
Generating Checksums
In BIP39, each word in a passphrase is associated with a specific checksum value. These checksum values are generated using a rolling hash function that takes the previous checksum value(s) into account to create the next one. The process involves:
- Initialization
: The first 12 words of the passphrase are used as the initial checksum.
- Rolling hash: For each subsequent word, the previous checksum values are used to generate a new checksum value using a rolling hash function.
- Checksum update: The newly generated checksum is updated by concatenating it with the current password (one character) and adding the previous 4 checksum values.
Calculating multiple checksums
To illustrate how multiple checksums work, let’s look at an example passphrase: “Hello World Bitcoin” (12 words). If we divide the list of 2048 words into groups of 16 words each, we get 32 groups:
| Group | Words |
| — | — |
| 1 | H L E W O R L D B I T C O N T |
| 2 | … | | | | | | | | | |
| 3 | … | | | | | | | | | | |
Calculating checksums for each group
For each group, we will calculate checksum values using a rolling hash function:
- 1. group: initial checksum
- group2: update the checksum value with the previous 4 values and concatenate with the password “H”
- group3: update the checksum value with the previous 4 values and concatenate with the password “L”
Using a programming language like Python, we can simulate a rolling hash function to calculate the checksums for each group:
import hashlib
def generate_checksum(group_words):
Initialize the checksum with the initial list of wordschecksum = b'
Calculate the checksum for each groupin the range i (0, len (group_words), 16):
group_words = list_words[i:i+16]
Update the checksum value using the rolling hash functionnew_checksum = hashlib.rollsum(group_words)
Concatenate the new checksum with the password and add the previous 4 valueschecksum += hashlib.sha1(new_checksum).digest()[:4]
return checksum
Generate checksums for each groupwordlist = b'Hello World Bitcoin'.encode()
checksums = generate_checksum(wordlist)
print (checksums)
Sample Output
Running the above code will output a list of 32 checksum values that can be concatenated with passwords to produce multiple valid Ethereum public keys.
Finally, understanding how multiple checksums work in BIP39 is crucial for generating secure mnemonics. By calculating the checksum values for each group, we can ensure that our mnemonics can be used to produce multiple valid Ethereum public keys, providing an additional layer of security against unauthorized access to sensitive information.