From ea0dcff548175c2acacb3f1eeb1dad80ad1a4e90 Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 21 Oct 2021 15:07:13 +0200 Subject: [PATCH] feat(crypto): support all bip39 lengths in mnemonic_to_bits --- crypto/bip39.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crypto/bip39.c b/crypto/bip39.c index 0c5c8d65c..1b2d721c7 100644 --- a/crypto/bip39.c +++ b/crypto/bip39.c @@ -109,8 +109,11 @@ int mnemonic_to_bits(const char *mnemonic, uint8_t *bits) { } n++; - // check number of words - if (n != 12 && n != 18 && n != 24) { + // check that number of words is valid for BIP-39: + // (a) between 128 and 256 bits of initial entropy (12 - 24 words) + // (b) number of bits divisible by 33 (1 checksum bit per 32 input bits) + // - that is, (n * 11) % 33 == 0, so n % 3 == 0 + if (n < 12 || n > 24 || (n % 3)) { return 0; }