Turn an entropy value into a list of word indexes.
(bip39-entropy-to-word-indexes entropy) → indexes
First, we create a checksum of the entropy
by taking the first
The numer of word indexes (i.e. the length of the result)
is the value
We also prove a validation theorem
(disabled by default for the same reason as the other one)
showing all the possible values of
The maximum numer of word indexes is 24.
Function:
(defun bip39-entropy-to-word-indexes (entropy) (declare (xargs :guard (bip39-entropyp entropy))) (b* ((entropy (bip39-entropy-fix entropy)) (entropy-bytes (bits=>bebytes entropy)) (hash-bytes (sha-256-bytes entropy-bytes)) (hash (bebytes=>bits hash-bytes)) (checksum (take (/ (len entropy) 32) hash)) (all-bits (append entropy checksum))) (bits=>beubyte11s all-bits)))
Theorem:
(defthm ubyte11-listp-of-bip39-entropy-to-word-indexes (b* ((indexes (bip39-entropy-to-word-indexes entropy))) (ubyte11-listp indexes)) :rule-classes :rewrite)
Theorem:
(defthm len-of-bip39-entropy-to-word-indexes (equal (len (bip39-entropy-to-word-indexes entropy)) (b* ((ent (len (bip39-entropy-fix entropy))) (cs (/ ent 32)) (ent+cs (+ ent cs)) (ms (/ ent+cs 11))) ms)))
Theorem:
(defthm values-of-len-of-bip39-entropy-to-word-indexes (equal (len (bip39-entropy-to-word-indexes entropy)) (case (len (bip39-entropy-fix entropy)) (128 12) (160 15) (192 18) (224 21) (256 24))))
Theorem:
(defthm bip39-entropy-to-word-indexes-upper-bound (<= (len (bip39-entropy-to-word-indexes entropy)) 24) :rule-classes :linear)
Theorem:
(defthm bip39-entropy-to-word-indexes-of-bip39-entropy-fix-entropy (equal (bip39-entropy-to-word-indexes (bip39-entropy-fix entropy)) (bip39-entropy-to-word-indexes entropy)))
Theorem:
(defthm bip39-entropy-to-word-indexes-bip39-entropy-equiv-congruence-on-entropy (implies (bip39-entropy-equiv entropy entropy-equiv) (equal (bip39-entropy-to-word-indexes entropy) (bip39-entropy-to-word-indexes entropy-equiv))) :rule-classes :congruence)