BIP39 (Deterministic Key Generation) - Phrase to seedBIP39 is a Deterministic Key Generation method and it is used to derive encryption keys for a known seed. This seed can be generated from a series of human readable string of random words. This page generates a seed from a 12 world phrase. |
Outline
BIP39 is a Deterministic Key Generation method and it is used to derive encryption keys for a known seed. This seed can be a series of human readable string of random words. In the BIP39 standard there are 2,048 words, and if each phrase has 12 worlds, then there are \(2048^{12}\) different permutation - giving \(2^{132}\) different bit values (or 132 bits) . The first few words are [list]:
abandon ability able about above absent absorb abstract absurd abuse access accident account accuse achieve
Code
The code is:
package main import ( "encoding/hex" "fmt" "github.com/tyler-smith/go-bip39" "os" ) func main() { mnemonic := "all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt reform" password:="BILL" argCount := len(os.Args[1:]) if (argCount>0) { mnemonic= (os.Args[1])} res:=bip39.IsMnemonicValid(mnemonic) seed := bip39.NewSeed(mnemonic, password) fmt.Println("Phrase:",mnemonic) fmt.Println("Password:",password) fmt.Println("\nValid mnemonic:",res) fmt.Println("Seed:",hex.EncodeToString(seed))
A sample run is:
Phrase: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon cactus Password: BILL Valid mnemonic: true Seed: d184a269b4ea26dec12ed35e432e7d687a3b2b767a74e6b01b4009f991eda6dfbcc5f98e31409db7560a5640698094dcc190a0532f1360972e4cf3a8b594f936
For this we basically take the phrase, and then “mnemonic”+password as the salt, and perform 2,048 iterations for PBKDF2 for a SHA-512 output (512 bits). Now we will test this with Python:
import passlib.hash; string = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon cactus" salt="mnemonicBILL" from passlib.utils.pbkdf2 import get_prf,pbkdf2 s2 = pbkdf2(string, salt, 2048, keylen=64, prf='hmac-sha512') print s2.encode('hex')
When we run this we get:
d184a269b4ea26dec12ed35e432e7d687a3b2b767a74e6b01b4009f991eda6dfbcc5f98e31409db7560a5640698094dcc190a0532f1360972e4cf3a8b594f936
and which is the same the previous run in Golang.