Merge pull request #5452 from guggero/export-aezeed

aezeed: export wordlist and properties
This commit is contained in:
Olaoluwa Osuntokun 2021-06-30 17:58:11 -07:00 committed by GitHub
commit b04efec130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 23 deletions

View File

@ -67,9 +67,9 @@ const (
// the seed. // the seed.
EntropySize = 16 EntropySize = 16
// NummnemonicWords is the number of words that an encoded cipher seed // NumMnemonicWords is the number of words that an encoded cipher seed
// will result in. // will result in.
NummnemonicWords = 24 NumMnemonicWords = 24
// saltSize is the size of the salt we'll generate to use with scrypt // saltSize is the size of the salt we'll generate to use with scrypt
// to generate a key for use within aez from the user's passphrase. The // to generate a key for use within aez from the user's passphrase. The
@ -90,9 +90,9 @@ const (
// aez. // aez.
keyLen = 32 keyLen = 32
// bitsPerWord is the number of bits each word in the wordlist encodes. // BitsPerWord is the number of bits each word in the wordlist encodes.
// We encode our mnemonic using 24 words, so 264 bits (33 bytes). // We encode our mnemonic using 24 words, so 264 bits (33 bytes).
bitsPerWord = 11 BitsPerWord = 11
// saltOffset is the index within an enciphered cipherseed that marks // saltOffset is the index within an enciphered cipherseed that marks
// the start of the salt. // the start of the salt.
@ -337,7 +337,7 @@ func (c *CipherSeed) encipher(pass []byte) ([EncipheredCipherSeedSize]byte, erro
// cipherTextToMnemonic converts the aez ciphertext appended with the salt to a // cipherTextToMnemonic converts the aez ciphertext appended with the salt to a
// 24-word mnemonic pass phrase. // 24-word mnemonic pass phrase.
func cipherTextToMnemonic(cipherText [EncipheredCipherSeedSize]byte) (Mnemonic, error) { func cipherTextToMnemonic(cipherText [EncipheredCipherSeedSize]byte) (Mnemonic, error) {
var words [NummnemonicWords]string var words [NumMnemonicWords]string
// First, we'll convert the ciphertext itself into a bitstream for easy // First, we'll convert the ciphertext itself into a bitstream for easy
// manipulation. // manipulation.
@ -345,13 +345,13 @@ func cipherTextToMnemonic(cipherText [EncipheredCipherSeedSize]byte) (Mnemonic,
// With our bitstream obtained, we'll read 11 bits at a time, then use // With our bitstream obtained, we'll read 11 bits at a time, then use
// that to index into our word list to obtain the next word. // that to index into our word list to obtain the next word.
for i := 0; i < NummnemonicWords; i++ { for i := 0; i < NumMnemonicWords; i++ {
index, err := cipherBits.ReadBits(bitsPerWord) index, err := cipherBits.ReadBits(BitsPerWord)
if err != nil { if err != nil {
return Mnemonic{}, err return Mnemonic{}, err
} }
words[i] = defaultWordList[index] words[i] = DefaultWordList[index]
} }
return words, nil return words, nil
@ -391,7 +391,7 @@ func (c *CipherSeed) BirthdayTime() time.Time {
// Additionally, we also encode the salt used with scrypt to derive the key // Additionally, we also encode the salt used with scrypt to derive the key
// that the cipher text is encrypted with, and the version which tells us how // that the cipher text is encrypted with, and the version which tells us how
// to decipher the seed. // to decipher the seed.
type Mnemonic [NummnemonicWords]string type Mnemonic [NumMnemonicWords]string
// mnemonicToCipherText converts a 24-word mnemonic phrase into a 33 byte // mnemonicToCipherText converts a 24-word mnemonic phrase into a 33 byte
// cipher text. // cipher text.
@ -408,11 +408,11 @@ func mnemonicToCipherText(mnemonic *Mnemonic) [EncipheredCipherSeedSize]byte {
for _, word := range mnemonic { for _, word := range mnemonic {
// Using the reverse word map, we'll locate the index of this // Using the reverse word map, we'll locate the index of this
// word within the word list. // word within the word list.
index := uint64(reverseWordMap[word]) index := uint64(ReverseWordMap[word])
// With the index located, we'll now write this out to the // With the index located, we'll now write this out to the
// bitstream, appending to what's already there. // bitstream, appending to what's already there.
cipherBits.WriteBits(index, bitsPerWord) cipherBits.WriteBits(index, BitsPerWord)
} }
copy(cipherText[:], cipherBits.Bytes()) copy(cipherText[:], cipherBits.Bytes())
@ -505,8 +505,8 @@ func (m *Mnemonic) Decipher(pass []byte) ([DecipheredCipherSeedSize]byte, error)
// Before we attempt to map the mnemonic back to the original // Before we attempt to map the mnemonic back to the original
// ciphertext, we'll ensure that all the word are actually a part of // ciphertext, we'll ensure that all the word are actually a part of
// the current default word list. // the current default word list.
wordDict := make(map[string]struct{}, len(defaultWordList)) wordDict := make(map[string]struct{}, len(DefaultWordList))
for _, word := range defaultWordList { for _, word := range DefaultWordList {
wordDict[word] = struct{}{} wordDict[word] = struct{}{}
} }

View File

@ -16,7 +16,7 @@ type TestVector struct {
entropy [EntropySize]byte entropy [EntropySize]byte
salt [saltSize]byte salt [saltSize]byte
password []byte password []byte
expectedMnemonic [NummnemonicWords]string expectedMnemonic [NumMnemonicWords]string
expectedBirthday uint16 expectedBirthday uint16
} }
@ -37,7 +37,7 @@ var (
entropy: testEntropy, entropy: testEntropy,
salt: testSalt, salt: testSalt,
password: []byte{}, password: []byte{},
expectedMnemonic: [NummnemonicWords]string{ expectedMnemonic: [NumMnemonicWords]string{
"ability", "liquid", "travel", "stem", "barely", "drastic", "ability", "liquid", "travel", "stem", "barely", "drastic",
"pact", "cupboard", "apple", "thrive", "morning", "oak", "pact", "cupboard", "apple", "thrive", "morning", "oak",
"feature", "tissue", "couch", "old", "math", "inform", "feature", "tissue", "couch", "old", "math", "inform",
@ -51,7 +51,7 @@ var (
entropy: testEntropy, entropy: testEntropy,
salt: testSalt, salt: testSalt,
password: []byte("!very_safe_55345_password*"), password: []byte("!very_safe_55345_password*"),
expectedMnemonic: [NummnemonicWords]string{ expectedMnemonic: [NumMnemonicWords]string{
"able", "tree", "stool", "crush", "transfer", "cloud", "able", "tree", "stool", "crush", "transfer", "cloud",
"cross", "three", "profit", "outside", "hen", "citizen", "cross", "three", "profit", "outside", "hen", "citizen",
"plate", "ride", "require", "leg", "siren", "drum", "plate", "ride", "require", "leg", "siren", "drum",

View File

@ -5,20 +5,20 @@ import (
) )
var ( var (
// reverseWordMap maps a word to its position within the default word list. // ReverseWordMap maps a word to its position within the default word list.
reverseWordMap map[string]int ReverseWordMap map[string]int
) )
func init() { func init() {
reverseWordMap = make(map[string]int) ReverseWordMap = make(map[string]int)
for i, v := range defaultWordList { for i, v := range DefaultWordList {
reverseWordMap[v] = i ReverseWordMap[v] = i
} }
} }
// defaultWordList is a slice of the current default word list that's used to // DefaultWordList is a slice of the current default word list that's used to
// encode the enciphered seed into a human readable set of words. // encode the enciphered seed into a human readable set of words.
var defaultWordList = strings.Split(englishWordList, "\n") var DefaultWordList = strings.Split(englishWordList, "\n")
// englishWordList is an English wordlist that's used as part of version 0 of // englishWordList is an English wordlist that's used as part of version 0 of
// the cipherseed scheme. This is the *same* word list that's recommend for use // the cipherseed scheme. This is the *same* word list that's recommend for use