bip39/
lib.rs

1// Rust Bitcoin Library
2// Written in 2020 by
3//	 Steven Roose <steven@stevenroose.org>
4// To the extent possible under law, the author(s) have dedicated all
5// copyright and related and neighboring rights to this software to
6// the public domain worldwide. This software is distributed without
7// any warranty.
8//
9// You should have received a copy of the CC0 Public Domain Dedication
10// along with this software.
11// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
12//
13
14//! # BIP39 Mnemonic Codes
15//!
16//! We currently don't implement seed generation from the phrase.
17//!
18//! https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
19//!
20
21#![deny(non_upper_case_globals)]
22#![deny(non_camel_case_types)]
23#![deny(non_snake_case)]
24#![deny(unused_mut)]
25#![deny(dead_code)]
26#![deny(unused_imports)]
27#![deny(missing_docs)]
28#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
29
30#[cfg(any(test, feature = "std"))]
31pub extern crate core;
32
33extern crate bitcoin_hashes;
34extern crate rand_core;
35
36#[cfg(feature = "std")]
37extern crate unicode_normalization;
38
39#[cfg(feature = "rand")]
40extern crate rand;
41#[cfg(feature = "serde")]
42pub extern crate serde;
43
44use core::{fmt, str};
45
46#[cfg(feature = "std")]
47use std::borrow::Cow;
48#[cfg(feature = "std")]
49use std::error;
50
51use bitcoin_hashes::{sha256, Hash};
52
53#[cfg(feature = "std")]
54use unicode_normalization::UnicodeNormalization;
55
56#[cfg(feature = "zeroize")]
57extern crate zeroize;
58#[cfg(feature = "zeroize")]
59use zeroize::Zeroize;
60
61#[macro_use]
62mod internal_macros;
63mod language;
64mod pbkdf2;
65
66pub use language::Language;
67
68/// The minimum number of words in a mnemonic.
69#[allow(unused)]
70const MIN_NB_WORDS: usize = 12;
71
72/// The maximum number of words in a mnemonic.
73const MAX_NB_WORDS: usize = 24;
74
75/// The index used to indicate the mnemonic ended.
76const EOF: u16 = u16::max_value();
77
78/// A structured used in the [Error::AmbiguousLanguages] variant that iterates
79/// over the possible languages.
80#[derive(Debug, Clone, PartialEq, Eq, Copy)]
81pub struct AmbiguousLanguages([bool; language::MAX_NB_LANGUAGES]);
82
83impl AmbiguousLanguages {
84	/// Presents the possible languages in the form of a slice of booleans
85	/// that correspond to the occurrences in [Language::all()].
86	pub fn as_bools(&self) -> &[bool; language::MAX_NB_LANGUAGES] {
87		&self.0
88	}
89
90	/// An iterator over the possible languages.
91	pub fn iter(&self) -> impl Iterator<Item = Language> + '_ {
92		Language::all().iter().enumerate().filter(move |(i, _)| self.0[*i]).map(|(_, l)| *l)
93	}
94
95	/// Returns a vector of the possible languages.
96	#[cfg(feature = "std")]
97	pub fn to_vec(&self) -> Vec<Language> {
98		self.iter().collect()
99	}
100}
101
102/// A BIP39 error.
103#[derive(Debug, Clone, PartialEq, Eq, Copy)]
104pub enum Error {
105	/// Mnemonic has a word count that is not a multiple of 6.
106	BadWordCount(usize),
107	/// Mnemonic contains an unknown word.
108	/// Error contains the index of the word.
109	/// Use `mnemonic.split_whitespace().get(i)` to get the word.
110	UnknownWord(usize),
111	/// Entropy was not a multiple of 32 bits or between 128-256n bits in length.
112	BadEntropyBitCount(usize),
113	/// The mnemonic has an invalid checksum.
114	InvalidChecksum,
115	/// The mnemonic can be interpreted as multiple languages.
116	/// Use the helper methods of the inner struct to inspect
117	/// which languages are possible.
118	AmbiguousLanguages(AmbiguousLanguages),
119}
120
121impl fmt::Display for Error {
122	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
123		match *self {
124			Error::BadWordCount(c) => {
125				write!(f, "mnemonic has a word count that is not a multiple of 6: {}", c,)
126			}
127			Error::UnknownWord(i) => write!(f, "mnemonic contains an unknown word (word {})", i,),
128			Error::BadEntropyBitCount(c) => write!(
129				f,
130				"entropy was not between 128-256 bits or not a multiple of 32 bits: {} bits",
131				c,
132			),
133			Error::InvalidChecksum => write!(f, "the mnemonic has an invalid checksum"),
134			Error::AmbiguousLanguages(a) => {
135				write!(f, "ambiguous word list: ")?;
136				for (i, lang) in a.iter().enumerate() {
137					if i == 0 {
138						write!(f, "{}", lang)?;
139					} else {
140						write!(f, ", {}", lang)?;
141					}
142				}
143				Ok(())
144			}
145		}
146	}
147}
148
149#[cfg(feature = "std")]
150impl error::Error for Error {}
151
152/// A mnemonic code.
153///
154/// The [core::str::FromStr] implementation will try to determine the language of the
155/// mnemonic from all the supported languages. (Languages have to be explicitly enabled using
156/// the Cargo features.)
157///
158/// Supported number of words are 12, 18 and 24.
159#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
160#[cfg_attr(feature = "zeroize", derive(Zeroize), zeroize(drop))]
161pub struct Mnemonic {
162	/// The language the mnemonic.
163	lang: Language,
164	/// The indiced of the words.
165	/// Mnemonics with less than the max nb of words are terminated with EOF.
166	words: [u16; MAX_NB_WORDS],
167}
168
169#[cfg(feature = "zeroize")]
170impl zeroize::DefaultIsZeroes for Language {}
171
172serde_string_impl!(Mnemonic, "a BIP-39 Mnemonic Code");
173
174impl Mnemonic {
175	/// Ensure the content of the [Cow] is normalized UTF8.
176	/// Performing this on a [Cow] means that all allocations for normalization
177	/// can be avoided for languages without special UTF8 characters.
178	#[inline]
179	#[cfg(feature = "std")]
180	fn normalize_utf8_cow<'a>(cow: &mut Cow<'a, str>) {
181		let is_nfkd = unicode_normalization::is_nfkd_quick(cow.as_ref().chars());
182		if is_nfkd != unicode_normalization::IsNormalized::Yes {
183			*cow = Cow::Owned(cow.as_ref().nfkd().to_string());
184		}
185	}
186
187	/// Create a new [Mnemonic] in the specified language from the given entropy.
188	/// Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.
189	pub fn from_entropy_in(language: Language, entropy: &[u8]) -> Result<Mnemonic, Error> {
190		const MAX_ENTROPY_BITS: usize = 256;
191		const MIN_ENTROPY_BITS: usize = 128;
192		const MAX_CHECKSUM_BITS: usize = 8;
193
194		let nb_bytes = entropy.len();
195		let nb_bits = nb_bytes * 8;
196
197		if nb_bits % 32 != 0 {
198			return Err(Error::BadEntropyBitCount(nb_bits));
199		}
200		if nb_bits < MIN_ENTROPY_BITS || nb_bits > MAX_ENTROPY_BITS {
201			return Err(Error::BadEntropyBitCount(nb_bits));
202		}
203
204		let check = sha256::Hash::hash(&entropy);
205		let mut bits = [false; MAX_ENTROPY_BITS + MAX_CHECKSUM_BITS];
206		for i in 0..nb_bytes {
207			for j in 0..8 {
208				bits[i * 8 + j] = (entropy[i] & (1 << (7 - j))) > 0;
209			}
210		}
211		for i in 0..nb_bytes / 4 {
212			bits[8 * nb_bytes + i] = (check[i / 8] & (1 << (7 - (i % 8)))) > 0;
213		}
214
215		let mut words = [EOF; MAX_NB_WORDS];
216		let nb_words = nb_bytes * 3 / 4;
217		for i in 0..nb_words {
218			let mut idx = 0;
219			for j in 0..11 {
220				if bits[i * 11 + j] {
221					idx += 1 << (10 - j);
222				}
223			}
224			words[i] = idx;
225		}
226
227		Ok(Mnemonic {
228			lang: language,
229			words: words,
230		})
231	}
232
233	/// Create a new English [Mnemonic] from the given entropy.
234	/// Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.
235	pub fn from_entropy(entropy: &[u8]) -> Result<Mnemonic, Error> {
236		Mnemonic::from_entropy_in(Language::English, entropy)
237	}
238
239	/// Generate a new [Mnemonic] in the given language
240	/// with the given randomness source.
241	/// For the different supported word counts, see documentation on [Mnemonic].
242	///
243	/// Example:
244	///
245	/// ```
246	/// extern crate rand;
247	/// extern crate bip39;
248	///
249	/// use bip39::{Mnemonic, Language};
250	///
251	/// let mut rng = rand::thread_rng();
252	/// let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();
253	/// ```
254	pub fn generate_in_with<R>(
255		rng: &mut R,
256		language: Language,
257		word_count: usize,
258	) -> Result<Mnemonic, Error>
259	where
260		R: rand_core::RngCore + rand_core::CryptoRng,
261	{
262		if word_count < MIN_NB_WORDS || word_count % 6 != 0 || word_count > MAX_NB_WORDS {
263			return Err(Error::BadWordCount(word_count));
264		}
265
266		let entropy_bytes = (word_count / 3) * 4;
267		let mut entropy = [0u8; (MAX_NB_WORDS / 3) * 4];
268		rand_core::RngCore::fill_bytes(rng, &mut entropy[0..entropy_bytes]);
269		Mnemonic::from_entropy_in(language, &entropy[0..entropy_bytes])
270	}
271
272	/// Generate a new [Mnemonic] in the given language.
273	/// For the different supported word counts, see documentation on [Mnemonic].
274	///
275	/// Example:
276	///
277	/// ```
278	/// extern crate bip39;
279	///
280	/// use bip39::{Mnemonic, Language};
281	///
282	/// let m = Mnemonic::generate_in(Language::English, 24).unwrap();
283	/// ```
284	#[cfg(feature = "rand")]
285	pub fn generate_in(language: Language, word_count: usize) -> Result<Mnemonic, Error> {
286		Mnemonic::generate_in_with(&mut rand::thread_rng(), language, word_count)
287	}
288
289	/// Generate a new [Mnemonic] in English.
290	/// For the different supported word counts, see documentation on [Mnemonic].
291	///
292	/// Example:
293	///
294	/// ```
295	/// extern crate bip39;
296	///
297	/// use bip39::{Mnemonic,};
298	///
299	/// let m = Mnemonic::generate(24).unwrap();
300	/// ```
301	#[cfg(feature = "rand")]
302	pub fn generate(word_count: usize) -> Result<Mnemonic, Error> {
303		Mnemonic::generate_in(Language::English, word_count)
304	}
305
306	/// Get the language of the [Mnemonic].
307	pub fn language(&self) -> Language {
308		self.lang
309	}
310
311	/// Get an iterator over the words.
312	pub fn word_iter(&self) -> impl Iterator<Item = &'static str> + Clone + '_ {
313		let list = self.lang.word_list();
314		self.words.iter().take_while(|w| **w != EOF).map(move |w| list[*w as usize])
315	}
316
317	/// Determine the language of the mnemonic as a word iterator.
318	/// See documentation on [Mnemonic::language_of] for more info.
319	fn language_of_iter<'a, W: Iterator<Item = &'a str>>(words: W) -> Result<Language, Error> {
320		let mut words = words.peekable();
321		let langs = Language::all();
322		{
323			// Start scope to drop first_word so that words can be reborrowed later.
324			let first_word = words.peek().ok_or(Error::BadWordCount(0))?;
325			if first_word.len() == 0 {
326				return Err(Error::BadWordCount(0));
327			}
328
329			// We first try find the first word in wordlists that
330			// have guaranteed unique words.
331			for language in langs.iter().filter(|l| l.unique_words()) {
332				if language.find_word(first_word).is_some() {
333					return Ok(*language);
334				}
335			}
336		}
337
338		// If that didn't work, we start with all possible languages
339		// (those without unique words), and eliminate until there is
340		// just one left.
341		let mut possible = [false; language::MAX_NB_LANGUAGES];
342		for (i, lang) in langs.iter().enumerate() {
343			// To start, only consider lists that don't have unique words.
344			// Those were considered above.
345			possible[i] = !lang.unique_words();
346		}
347		for (idx, word) in words.enumerate() {
348			// Scrap languages that don't have this word.
349			for (i, lang) in langs.iter().enumerate() {
350				possible[i] &= lang.find_word(word).is_some();
351			}
352
353			// Get an iterator over remaining possible languages.
354			let mut iter = possible.iter().zip(langs.iter()).filter(|(p, _)| **p).map(|(_, l)| l);
355
356			match iter.next() {
357				// If all languages were eliminated, it's an invalid word.
358				None => return Err(Error::UnknownWord(idx)),
359				// If not, see if there is a second one remaining.
360				Some(remaining) => {
361					if iter.next().is_none() {
362						// No second remaining, we found our language.
363						return Ok(*remaining);
364					}
365				}
366			}
367		}
368
369		return Err(Error::AmbiguousLanguages(AmbiguousLanguages(possible)));
370	}
371
372	/// Determine the language of the mnemonic.
373	///
374	/// NOTE: This method only guarantees that the returned language is the
375	/// correct language on the assumption that the mnemonic is valid.
376	/// It does not itself validate the mnemonic.
377	///
378	/// Some word lists don't guarantee that their words don't occur in other
379	/// word lists. In the extremely unlikely case that a word list can be
380	/// interpreted in multiple languages, an [Error::AmbiguousLanguages] is
381	/// returned, containing the possible languages.
382	pub fn language_of<S: AsRef<str>>(mnemonic: S) -> Result<Language, Error> {
383		Mnemonic::language_of_iter(mnemonic.as_ref().split_whitespace())
384	}
385
386	/// Parse a mnemonic in normalized UTF8 in the given language.
387	pub fn parse_in_normalized(language: Language, s: &str) -> Result<Mnemonic, Error> {
388		let nb_words = s.split_whitespace().count();
389		if nb_words < MIN_NB_WORDS || nb_words % 6 != 0 || nb_words > MAX_NB_WORDS {
390			return Err(Error::BadWordCount(nb_words));
391		}
392
393		// Here we will store the eventual words.
394		let mut words = [EOF; MAX_NB_WORDS];
395
396		// And here we keep track of the bits to calculate and validate the checksum.
397		// We only use `nb_words * 11` elements in this array.
398		let mut bits = [false; MAX_NB_WORDS * 11];
399
400		for (i, word) in s.split_whitespace().enumerate() {
401			let idx = language.find_word(word).ok_or(Error::UnknownWord(i))?;
402
403			words[i] = idx;
404
405			for j in 0..11 {
406				bits[i * 11 + j] = idx >> (10 - j) & 1 == 1;
407			}
408		}
409
410		// Verify the checksum.
411		// We only use `nb_words / 3 * 4` elements in this array.
412		let mut entropy = [0u8; MAX_NB_WORDS / 3 * 4];
413		let nb_bytes_entropy = nb_words / 3 * 4;
414		for i in 0..nb_bytes_entropy {
415			for j in 0..8 {
416				if bits[i * 8 + j] {
417					entropy[i] += 1 << (7 - j);
418				}
419			}
420		}
421		let check = sha256::Hash::hash(&entropy[0..nb_bytes_entropy]);
422		for i in 0..nb_bytes_entropy / 4 {
423			if bits[8 * nb_bytes_entropy + i] != ((check[i / 8] & (1 << (7 - (i % 8)))) > 0) {
424				return Err(Error::InvalidChecksum);
425			}
426		}
427
428		Ok(Mnemonic {
429			lang: language,
430			words: words,
431		})
432	}
433
434	/// Parse a mnemonic in normalized UTF8.
435	pub fn parse_normalized(s: &str) -> Result<Mnemonic, Error> {
436		let lang = Mnemonic::language_of(s)?;
437		Mnemonic::parse_in_normalized(lang, s)
438	}
439
440	/// Parse a mnemonic in the given language.
441	#[cfg(feature = "std")]
442	pub fn parse_in<'a, S: Into<Cow<'a, str>>>(
443		language: Language,
444		s: S,
445	) -> Result<Mnemonic, Error> {
446		let mut cow = s.into();
447		Mnemonic::normalize_utf8_cow(&mut cow);
448		Ok(Mnemonic::parse_in_normalized(language, cow.as_ref())?)
449	}
450
451	/// Parse a mnemonic and detect the language from the enabled languages.
452	#[cfg(feature = "std")]
453	pub fn parse<'a, S: Into<Cow<'a, str>>>(s: S) -> Result<Mnemonic, Error> {
454		let mut cow = s.into();
455		Mnemonic::normalize_utf8_cow(&mut cow);
456
457		let language = if Language::all().len() == 1 {
458			Language::all()[0]
459		} else {
460			Mnemonic::language_of(cow.as_ref())?
461		};
462
463		Ok(Mnemonic::parse_in_normalized(language, cow.as_ref())?)
464	}
465
466	/// Get the number of words in the mnemonic.
467	pub fn word_count(&self) -> usize {
468		self.words.iter().take_while(|w| **w != EOF).count()
469	}
470
471	/// Convert to seed bytes with a passphrase in normalized UTF8.
472	pub fn to_seed_normalized(&self, normalized_passphrase: &str) -> [u8; 64] {
473		const PBKDF2_ROUNDS: usize = 2048;
474		const PBKDF2_BYTES: usize = 64;
475
476		let mut seed = [0u8; PBKDF2_BYTES];
477		pbkdf2::pbkdf2(
478			self.word_iter(),
479			normalized_passphrase.as_bytes(),
480			PBKDF2_ROUNDS,
481			&mut seed,
482		);
483		seed
484	}
485
486	/// Convert to seed bytes.
487	#[cfg(feature = "std")]
488	pub fn to_seed<'a, P: Into<Cow<'a, str>>>(&self, passphrase: P) -> [u8; 64] {
489		let normalized_passphrase = {
490			let mut cow = passphrase.into();
491			Mnemonic::normalize_utf8_cow(&mut cow);
492			cow
493		};
494		self.to_seed_normalized(normalized_passphrase.as_ref())
495	}
496
497	/// Convert the mnemonic back to the entropy used to generate it.
498	/// The return value is a byte array and the size.
499	/// Use [Mnemonic::to_entropy] (needs `std`) to get a [Vec<u8>].
500	pub fn to_entropy_array(&self) -> ([u8; 33], usize) {
501		// We unwrap errors here because this method can only be called on
502		// values that were already previously validated.
503
504		let language = Mnemonic::language_of_iter(self.word_iter()).unwrap();
505
506		// Preallocate enough space for the longest possible word list
507		let mut entropy = [0; 33];
508		let mut cursor = 0;
509		let mut offset = 0;
510		let mut remainder = 0;
511
512		let nb_words = self.word_count();
513		for word in self.word_iter() {
514			let idx = language.find_word(word).expect("invalid mnemonic");
515
516			remainder |= ((idx as u32) << (32 - 11)) >> offset;
517			offset += 11;
518
519			while offset >= 8 {
520				entropy[cursor] = (remainder >> 24) as u8;
521				cursor += 1;
522				remainder <<= 8;
523				offset -= 8;
524			}
525		}
526
527		if offset != 0 {
528			entropy[cursor] = (remainder >> 24) as u8;
529		}
530
531		let entropy_bytes = (nb_words / 3) * 4;
532		(entropy, entropy_bytes)
533	}
534
535	/// Convert the mnemonic back to the entropy used to generate it.
536	#[cfg(feature = "std")]
537	pub fn to_entropy(&self) -> Vec<u8> {
538		let (arr, len) = self.to_entropy_array();
539		arr[0..len].to_vec()
540	}
541}
542
543impl fmt::Display for Mnemonic {
544	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
545		for (i, word) in self.word_iter().enumerate() {
546			if i > 0 {
547				f.write_str(" ")?;
548			}
549			f.write_str(word)?;
550		}
551		Ok(())
552	}
553}
554
555impl str::FromStr for Mnemonic {
556	type Err = Error;
557
558	fn from_str(s: &str) -> Result<Mnemonic, Error> {
559		#[cfg(feature = "std")]
560		{
561			Mnemonic::parse(s)
562		}
563		#[cfg(not(feature = "std"))]
564		{
565			Mnemonic::parse_normalized(s)
566		}
567	}
568}
569
570#[cfg(test)]
571mod tests {
572	use super::*;
573
574	use bitcoin_hashes::hex::FromHex;
575
576	#[cfg(feature = "rand")]
577	#[test]
578	fn test_language_of() {
579		for lang in Language::all() {
580			let m = Mnemonic::generate_in(*lang, 24).unwrap();
581			assert_eq!(*lang, Mnemonic::language_of_iter(m.word_iter()).unwrap());
582			assert_eq!(
583				*lang,
584				Mnemonic::language_of_iter(m.to_string().split_whitespace()).unwrap()
585			);
586			assert_eq!(*lang, Mnemonic::language_of(m.to_string()).unwrap());
587			assert_eq!(*lang, Mnemonic::language_of(&m.to_string()).unwrap());
588		}
589	}
590
591	#[cfg(feature = "std")]
592	#[test]
593	fn test_ambiguous_languages() {
594		let mut present = [false; language::MAX_NB_LANGUAGES];
595		let mut present_vec = Vec::new();
596		let mut alternate = true;
597		for i in 0..Language::all().len() {
598			present[i] = alternate;
599			if alternate {
600				present_vec.push(Language::all()[i]);
601			}
602			alternate = !alternate;
603		}
604		let amb = AmbiguousLanguages(present);
605		assert_eq!(amb.to_vec(), present_vec);
606		assert_eq!(amb.iter().collect::<Vec<_>>(), present_vec);
607	}
608
609	#[cfg(feature = "rand")]
610	#[test]
611	fn test_generate() {
612		let _ = Mnemonic::generate(24).unwrap();
613		let _ = Mnemonic::generate_in(Language::English, 24).unwrap();
614		let _ = Mnemonic::generate_in_with(&mut rand::thread_rng(), Language::English, 24).unwrap();
615	}
616
617	#[test]
618	fn test_vectors_english() {
619		// These vectors are tuples of
620		// (entropy, mnemonic, seed)
621		let test_vectors = [
622			(
623				"00000000000000000000000000000000",
624				"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
625				"c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04",
626			),
627			(
628				"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
629				"legal winner thank year wave sausage worth useful legal winner thank yellow",
630				"2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607",
631			),
632			(
633				"80808080808080808080808080808080",
634				"letter advice cage absurd amount doctor acoustic avoid letter advice cage above",
635				"d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8",
636			),
637			(
638				"ffffffffffffffffffffffffffffffff",
639				"zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong",
640				"ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069",
641			),
642			(
643				"000000000000000000000000000000000000000000000000",
644				"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent",
645				"035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa",
646			),
647			(
648				"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
649				"legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will",
650				"f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd",
651			),
652			(
653				"808080808080808080808080808080808080808080808080",
654				"letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always",
655				"107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65",
656			),
657			(
658				"ffffffffffffffffffffffffffffffffffffffffffffffff",
659				"zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when",
660				"0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528",
661			),
662			(
663				"0000000000000000000000000000000000000000000000000000000000000000",
664				"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art",
665				"bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8",
666			),
667			(
668				"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
669				"legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title",
670				"bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87",
671			),
672			(
673				"8080808080808080808080808080808080808080808080808080808080808080",
674				"letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless",
675				"c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f",
676			),
677			(
678				"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
679				"zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote",
680				"dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad",
681			),
682			(
683				"9e885d952ad362caeb4efe34a8e91bd2",
684				"ozone drill grab fiber curtain grace pudding thank cruise elder eight picnic",
685				"274ddc525802f7c828d8ef7ddbcdc5304e87ac3535913611fbbfa986d0c9e5476c91689f9c8a54fd55bd38606aa6a8595ad213d4c9c9f9aca3fb217069a41028",
686			),
687			(
688				"6610b25967cdcca9d59875f5cb50b0ea75433311869e930b",
689				"gravity machine north sort system female filter attitude volume fold club stay feature office ecology stable narrow fog",
690				"628c3827a8823298ee685db84f55caa34b5cc195a778e52d45f59bcf75aba68e4d7590e101dc414bc1bbd5737666fbbef35d1f1903953b66624f910feef245ac",
691			),
692			(
693				"68a79eaca2324873eacc50cb9c6eca8cc68ea5d936f98787c60c7ebc74e6ce7c",
694				"hamster diagram private dutch cause delay private meat slide toddler razor book happy fancy gospel tennis maple dilemma loan word shrug inflict delay length",
695				"64c87cde7e12ecf6704ab95bb1408bef047c22db4cc7491c4271d170a1b213d20b385bc1588d9c7b38f1b39d415665b8a9030c9ec653d75e65f847d8fc1fc440",
696			),
697			(
698				"c0ba5a8e914111210f2bd131f3d5e08d",
699				"scheme spot photo card baby mountain device kick cradle pact join borrow",
700				"ea725895aaae8d4c1cf682c1bfd2d358d52ed9f0f0591131b559e2724bb234fca05aa9c02c57407e04ee9dc3b454aa63fbff483a8b11de949624b9f1831a9612",
701			),
702			(
703				"6d9be1ee6ebd27a258115aad99b7317b9c8d28b6d76431c3",
704				"horn tenant knee talent sponsor spell gate clip pulse soap slush warm silver nephew swap uncle crack brave",
705				"fd579828af3da1d32544ce4db5c73d53fc8acc4ddb1e3b251a31179cdb71e853c56d2fcb11aed39898ce6c34b10b5382772db8796e52837b54468aeb312cfc3d",
706			),
707			(
708				"9f6a2878b2520799a44ef18bc7df394e7061a224d2c33cd015b157d746869863",
709				"panda eyebrow bullet gorilla call smoke muffin taste mesh discover soft ostrich alcohol speed nation flash devote level hobby quick inner drive ghost inside",
710				"72be8e052fc4919d2adf28d5306b5474b0069df35b02303de8c1729c9538dbb6fc2d731d5f832193cd9fb6aeecbc469594a70e3dd50811b5067f3b88b28c3e8d",
711			),
712			(
713				"23db8160a31d3e0dca3688ed941adbf3",
714				"cat swing flag economy stadium alone churn speed unique patch report train",
715				"deb5f45449e615feff5640f2e49f933ff51895de3b4381832b3139941c57b59205a42480c52175b6efcffaa58a2503887c1e8b363a707256bdd2b587b46541f5",
716			),
717			(
718				"8197a4a47f0425faeaa69deebc05ca29c0a5b5cc76ceacc0",
719				"light rule cinnamon wrap drastic word pride squirrel upgrade then income fatal apart sustain crack supply proud access",
720				"4cbdff1ca2db800fd61cae72a57475fdc6bab03e441fd63f96dabd1f183ef5b782925f00105f318309a7e9c3ea6967c7801e46c8a58082674c860a37b93eda02",
721			),
722			(
723				"066dca1a2bb7e8a1db2832148ce9933eea0f3ac9548d793112d9a95c9407efad",
724				"all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt reform",
725				"26e975ec644423f4a4c4f4215ef09b4bd7ef924e85d1d17c4cf3f136c2863cf6df0a475045652c57eb5fb41513ca2a2d67722b77e954b4b3fc11f7590449191d",
726			),
727			(
728				"f30f8c1da665478f49b001d94c5fc452",
729				"vessel ladder alter error federal sibling chat ability sun glass valve picture",
730				"2aaa9242daafcee6aa9d7269f17d4efe271e1b9a529178d7dc139cd18747090bf9d60295d0ce74309a78852a9caadf0af48aae1c6253839624076224374bc63f",
731			),
732			(
733				"c10ec20dc3cd9f652c7fac2f1230f7a3c828389a14392f05",
734				"scissors invite lock maple supreme raw rapid void congress muscle digital elegant little brisk hair mango congress clump",
735				"7b4a10be9d98e6cba265566db7f136718e1398c71cb581e1b2f464cac1ceedf4f3e274dc270003c670ad8d02c4558b2f8e39edea2775c9e232c7cb798b069e88",
736			),
737			(
738				"f585c11aec520db57dd353c69554b21a89b20fb0650966fa0a9d6f74fd989d8f",
739				"void come effort suffer camp survey warrior heavy shoot primary clutch crush open amazing screen patrol group space point ten exist slush involve unfold",
740				"01f5bced59dec48e362f2c45b5de68b9fd6c92c6634f44d6d40aab69056506f0e35524a518034ddc1192e1dacd32c1ed3eaa3c3b131c88ed8e7e54c49a5d0998",
741			)
742		];
743
744		for vector in &test_vectors {
745			let entropy = Vec::<u8>::from_hex(&vector.0).unwrap();
746			let mnemonic_str = vector.1;
747			let seed = Vec::<u8>::from_hex(&vector.2).unwrap();
748
749			let mnemonic = Mnemonic::from_entropy(&entropy).unwrap();
750
751			assert_eq!(
752				mnemonic,
753				Mnemonic::parse_in_normalized(Language::English, mnemonic_str).unwrap(),
754				"failed vector: {}",
755				mnemonic_str
756			);
757			assert_eq!(
758				mnemonic,
759				Mnemonic::parse_normalized(mnemonic_str).unwrap(),
760				"failed vector: {}",
761				mnemonic_str
762			);
763			assert_eq!(
764				&seed[..],
765				&mnemonic.to_seed_normalized("TREZOR")[..],
766				"failed vector: {}",
767				mnemonic_str
768			);
769
770			#[cfg(features = "std")]
771			{
772				assert_eq!(&mnemonic.to_string(), mnemonic_str, "failed vector: {}", mnemonic_str);
773				assert_eq!(
774					mnemonic,
775					Mnemonic::parse_in(Language::English, mnemonic_str).unwrap(),
776					"failed vector: {}",
777					mnemonic_str
778				);
779				assert_eq!(
780					mnemonic,
781					Mnemonic::parse(mnemonic_str).unwrap(),
782					"failed vector: {}",
783					mnemonic_str
784				);
785				assert_eq!(
786					&seed[..],
787					&mnemonic.to_seed("TREZOR")[..],
788					"failed vector: {}",
789					mnemonic_str
790				);
791				assert_eq!(&entropy, &mnemonic.to_entropy(), "failed vector: {}", mnemonic_str);
792				assert_eq!(
793					&entropy,
794					&mnemonic.to_entropy_array().0[0..entropy.len()],
795					"failed vector: {}",
796					mnemonic_str
797				);
798			}
799		}
800	}
801
802	#[test]
803	fn test_invalid_engish() {
804		// correct phrase:
805		// "letter advice cage absurd amount doctor acoustic avoid letter advice cage above"
806
807		assert_eq!(
808			Mnemonic::parse_normalized(
809				"getter advice cage absurd amount doctor acoustic avoid letter advice cage above",
810			),
811			Err(Error::UnknownWord(0))
812		);
813
814		assert_eq!(
815			Mnemonic::parse_normalized(
816				"letter advice cagex absurd amount doctor acoustic avoid letter advice cage above",
817			),
818			Err(Error::UnknownWord(2))
819		);
820
821		assert_eq!(
822			Mnemonic::parse_normalized(
823				"advice cage absurd amount doctor acoustic avoid letter advice cage above",
824			),
825			Err(Error::BadWordCount(11))
826		);
827
828		assert_eq!(
829			Mnemonic::parse_normalized(
830				"primary advice cage absurd amount doctor acoustic avoid letter advice cage above",
831			),
832			Err(Error::InvalidChecksum)
833		);
834	}
835
836	#[test]
837	fn test_invalid_entropy() {
838		//between 128 and 256 bits, but not divisible by 32
839		assert_eq!(Mnemonic::from_entropy(&vec![b'x'; 17]), Err(Error::BadEntropyBitCount(136)));
840
841		//less than 128 bits
842		assert_eq!(Mnemonic::from_entropy(&vec![b'x'; 4]), Err(Error::BadEntropyBitCount(32)));
843
844		//greater than 256 bits
845		assert_eq!(Mnemonic::from_entropy(&vec![b'x'; 36]), Err(Error::BadEntropyBitCount(288)));
846	}
847
848	#[cfg(all(feature = "japanese", feature = "std"))]
849	#[test]
850	fn test_vectors_japanese() {
851		//! Test some Japanese language test vectors.
852		//! For these test vectors, we seem to generate different mnemonic phrases than the test
853		//! vectors expect us to. However, our generated seeds are correct and tiny-bip39,
854		//! an alternative implementation of bip39 also does not fulfill the test vectors.
855
856		// These vectors are tuples of
857		// (entropy, mnemonic, passphrase, seed)
858		let vectors = [
859			(
860				"00000000000000000000000000000000",
861				"あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あおぞら",
862				"㍍ガバヴァぱばぐゞちぢ十人十色",
863				"a262d6fb6122ecf45be09c50492b31f92e9beb7d9a845987a02cefda57a15f9c467a17872029a9e92299b5cbdf306e3a0ee620245cbd508959b6cb7ca637bd55",
864			),
865			(
866				"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
867				"そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかめ",
868				"㍍ガバヴァぱばぐゞちぢ十人十色",
869				"aee025cbe6ca256862f889e48110a6a382365142f7d16f2b9545285b3af64e542143a577e9c144e101a6bdca18f8d97ec3366ebf5b088b1c1af9bc31346e60d9",
870			),
871			(
872				"80808080808080808080808080808080",
873				"そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あかちゃん",
874				"㍍ガバヴァぱばぐゞちぢ十人十色",
875				"e51736736ebdf77eda23fa17e31475fa1d9509c78f1deb6b4aacfbd760a7e2ad769c714352c95143b5c1241985bcb407df36d64e75dd5a2b78ca5d2ba82a3544",
876			),
877			(
878				"ffffffffffffffffffffffffffffffff",
879				"われる われる われる われる われる われる われる われる われる われる われる ろんぶん",
880				"㍍ガバヴァぱばぐゞちぢ十人十色",
881				"4cd2ef49b479af5e1efbbd1e0bdc117f6a29b1010211df4f78e2ed40082865793e57949236c43b9fe591ec70e5bb4298b8b71dc4b267bb96ed4ed282c8f7761c",
882			),
883			(
884				"000000000000000000000000000000000000000000000000",
885				"あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あらいぐま",
886				"㍍ガバヴァぱばぐゞちぢ十人十色",
887				"d99e8f1ce2d4288d30b9c815ae981edd923c01aa4ffdc5dee1ab5fe0d4a3e13966023324d119105aff266dac32e5cd11431eeca23bbd7202ff423f30d6776d69",
888			),
889			(
890				"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
891				"そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れいぎ",
892				"㍍ガバヴァぱばぐゞちぢ十人十色",
893				"eaaf171efa5de4838c758a93d6c86d2677d4ccda4a064a7136344e975f91fe61340ec8a615464b461d67baaf12b62ab5e742f944c7bd4ab6c341fbafba435716",
894			),
895			(
896				"808080808080808080808080808080808080808080808080",
897				"そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら いきなり",
898				"㍍ガバヴァぱばぐゞちぢ十人十色",
899				"aec0f8d3167a10683374c222e6e632f2940c0826587ea0a73ac5d0493b6a632590179a6538287641a9fc9df8e6f24e01bf1be548e1f74fd7407ccd72ecebe425",
900			),
901			(
902				"ffffffffffffffffffffffffffffffffffffffffffffffff",
903				"われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる りんご",
904				"㍍ガバヴァぱばぐゞちぢ十人十色",
905				"f0f738128a65b8d1854d68de50ed97ac1831fc3a978c569e415bbcb431a6a671d4377e3b56abd518daa861676c4da75a19ccb41e00c37d086941e471a4374b95",
906			),
907			(
908				"0000000000000000000000000000000000000000000000000000000000000000",
909				"あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん いってい",
910				"㍍ガバヴァぱばぐゞちぢ十人十色",
911				"23f500eec4a563bf90cfda87b3e590b211b959985c555d17e88f46f7183590cd5793458b094a4dccc8f05807ec7bd2d19ce269e20568936a751f6f1ec7c14ddd",
912			),
913			(
914				"7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f",
915				"そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん まんきつ",
916				"㍍ガバヴァぱばぐゞちぢ十人十色",
917				"cd354a40aa2e241e8f306b3b752781b70dfd1c69190e510bc1297a9c5738e833bcdc179e81707d57263fb7564466f73d30bf979725ff783fb3eb4baa86560b05",
918			),
919			(
920				"8080808080808080808080808080808080808080808080808080808080808080",
921				"そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる うめる",
922				"㍍ガバヴァぱばぐゞちぢ十人十色",
923				"6b7cd1b2cdfeeef8615077cadd6a0625f417f287652991c80206dbd82db17bf317d5c50a80bd9edd836b39daa1b6973359944c46d3fcc0129198dc7dc5cd0e68",
924			),
925			(
926				"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
927				"われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる らいう",
928				"㍍ガバヴァぱばぐゞちぢ十人十色",
929				"a44ba7054ac2f9226929d56505a51e13acdaa8a9097923ca07ea465c4c7e294c038f3f4e7e4b373726ba0057191aced6e48ac8d183f3a11569c426f0de414623",
930			),
931			(
932				"77c2b00716cec7213839159e404db50d",
933				"せまい うちがわ あずき かろう めずらしい だんち ますく おさめる ていぼう あたる すあな えしゃく",
934				"㍍ガバヴァぱばぐゞちぢ十人十色",
935				"344cef9efc37d0cb36d89def03d09144dd51167923487eec42c487f7428908546fa31a3c26b7391a2b3afe7db81b9f8c5007336b58e269ea0bd10749a87e0193",
936			),
937			(
938				"b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b",
939				"ぬすむ ふっかつ うどん こうりつ しつじ りょうり おたがい せもたれ あつめる いちりゅう はんしゃ ごますり そんけい たいちょう らしんばん ぶんせき やすみ ほいく",
940				"㍍ガバヴァぱばぐゞちぢ十人十色",
941				"b14e7d35904cb8569af0d6a016cee7066335a21c1c67891b01b83033cadb3e8a034a726e3909139ecd8b2eb9e9b05245684558f329b38480e262c1d6bc20ecc4",
942			),
943			(
944				"3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982",
945				"くのう てぬぐい そんかい すろっと ちきゅう ほあん とさか はくしゅ ひびく みえる そざい てんすう たんぴん くしょう すいようび みけん きさらぎ げざん ふくざつ あつかう はやい くろう おやゆび こすう",
946				"㍍ガバヴァぱばぐゞちぢ十人十色",
947				"32e78dce2aff5db25aa7a4a32b493b5d10b4089923f3320c8b287a77e512455443298351beb3f7eb2390c4662a2e566eec5217e1a37467af43b46668d515e41b",
948			),
949			(
950				"0460ef47585604c5660618db2e6a7e7f",
951				"あみもの いきおい ふいうち にげる ざんしょ じかん ついか はたん ほあん すんぽう てちがい わかめ",
952				"㍍ガバヴァぱばぐゞちぢ十人十色",
953				"0acf902cd391e30f3f5cb0605d72a4c849342f62bd6a360298c7013d714d7e58ddf9c7fdf141d0949f17a2c9c37ced1d8cb2edabab97c4199b142c829850154b",
954			),
955			(
956				"72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f",
957				"すろっと にくしみ なやむ たとえる へいこう すくう きない けってい とくべつ ねっしん いたみ せんせい おくりがな まかい とくい けあな いきおい そそぐ",
958				"㍍ガバヴァぱばぐゞちぢ十人十色",
959				"9869e220bec09b6f0c0011f46e1f9032b269f096344028f5006a6e69ea5b0b8afabbb6944a23e11ebd021f182dd056d96e4e3657df241ca40babda532d364f73",
960			),
961			(
962				"2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416",
963				"かほご きうい ゆたか みすえる もらう がっこう よそう ずっと ときどき したうけ にんか はっこう つみき すうじつ よけい くげん もくてき まわり せめる げざい にげる にんたい たんそく ほそく",
964				"㍍ガバヴァぱばぐゞちぢ十人十色",
965				"713b7e70c9fbc18c831bfd1f03302422822c3727a93a5efb9659bec6ad8d6f2c1b5c8ed8b0b77775feaf606e9d1cc0a84ac416a85514ad59f5541ff5e0382481",
966			),
967			(
968				"eaebabb2383351fd31d703840b32e9e2",
969				"めいえん さのう めだつ すてる きぬごし ろんぱ はんこ まける たいおう さかいし ねんいり はぶらし",
970				"㍍ガバヴァぱばぐゞちぢ十人十色",
971				"06e1d5289a97bcc95cb4a6360719131a786aba057d8efd603a547bd254261c2a97fcd3e8a4e766d5416437e956b388336d36c7ad2dba4ee6796f0249b10ee961",
972			),
973			(
974				"7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78",
975				"せんぱい おしえる ぐんかん もらう きあい きぼう やおや いせえび のいず じゅしん よゆう きみつ さといも ちんもく ちわわ しんせいじ とめる はちみつ",
976				"㍍ガバヴァぱばぐゞちぢ十人十色",
977				"1fef28785d08cbf41d7a20a3a6891043395779ed74503a5652760ee8c24dfe60972105ee71d5168071a35ab7b5bd2f8831f75488078a90f0926c8e9171b2bc4a",
978			),
979			(
980				"4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef",
981				"こころ いどう きあつ そうがんきょう へいあん せつりつ ごうせい はいち いびき きこく あんい おちつく きこえる けんとう たいこ すすめる はっけん ていど はんおん いんさつ うなぎ しねま れいぼう みつかる",
982				"㍍ガバヴァぱばぐゞちぢ十人十色",
983				"43de99b502e152d4c198542624511db3007c8f8f126a30818e856b2d8a20400d29e7a7e3fdd21f909e23be5e3c8d9aee3a739b0b65041ff0b8637276703f65c2",
984			),
985			(
986				"18ab19a9f54a9274f03e5209a2ac8a91",
987				"うりきれ さいせい じゆう むろん とどける ぐうたら はいれつ ひけつ いずれ うちあわせ おさめる おたく",
988				"㍍ガバヴァぱばぐゞちぢ十人十色",
989				"3d711f075ee44d8b535bb4561ad76d7d5350ea0b1f5d2eac054e869ff7963cdce9581097a477d697a2a9433a0c6884bea10a2193647677977c9820dd0921cbde",
990			),
991			(
992				"18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4",
993				"うりきれ うねる せっさたくま きもち めんきょ へいたく たまご ぜっく びじゅつかん さんそ むせる せいじ ねくたい しはらい せおう ねんど たんまつ がいけん",
994				"㍍ガバヴァぱばぐゞちぢ十人十色",
995				"753ec9e333e616e9471482b4b70a18d413241f1e335c65cd7996f32b66cf95546612c51dcf12ead6f805f9ee3d965846b894ae99b24204954be80810d292fcdd",
996			),
997			(
998				"15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419",
999				"うちゅう ふそく ひしょ がちょう うけもつ めいそう みかん そざい いばる うけとる さんま さこつ おうさま ぱんつ しひょう めした たはつ いちぶ つうじょう てさぎょう きつね みすえる いりぐち かめれおん",
1000				"㍍ガバヴァぱばぐゞちぢ十人十色",
1001				"346b7321d8c04f6f37b49fdf062a2fddc8e1bf8f1d33171b65074531ec546d1d3469974beccb1a09263440fc92e1042580a557fdce314e27ee4eabb25fa5e5fe",
1002			)
1003		];
1004
1005		for vector in &vectors {
1006			let entropy = Vec::<u8>::from_hex(&vector.0).unwrap();
1007			let mnemonic_str = vector.1;
1008			let passphrase = vector.2;
1009			let seed = Vec::<u8>::from_hex(&vector.3).unwrap();
1010
1011			let mnemonic = Mnemonic::from_entropy_in(Language::Japanese, &entropy).unwrap();
1012
1013			assert_eq!(seed, &mnemonic.to_seed(passphrase)[..], "failed vector: {}", mnemonic_str);
1014			let rt = Mnemonic::parse_in(Language::Japanese, mnemonic.to_string())
1015				.expect(&format!("vector: {}", mnemonic_str));
1016			assert_eq!(seed, &rt.to_seed(passphrase)[..]);
1017
1018			let mnemonic = Mnemonic::parse_in(Language::Japanese, mnemonic_str)
1019				.expect(&format!("vector: {}", mnemonic_str));
1020			assert_eq!(seed, &mnemonic.to_seed(passphrase)[..], "failed vector: {}", mnemonic_str);
1021		}
1022	}
1023}