diff --git a/bip-0093.mediawiki b/bip-0093.mediawiki
index cde2e95032..dc56d330e1 100644
--- a/bip-0093.mediawiki
+++ b/bip-0093.mediawiki
@@ -9,6 +9,7 @@
Assigned: 2023-02-13
License: BSD-3-Clause
Discussion: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2023-February/021469.html
+ Version: 0.3.0
==Introduction==
@@ -60,51 +61,66 @@ However, BIP-0039 has no error-correcting ability, cannot sensibly be extended t
We first describe the general checksummed base32'''Why use base32 at all?''' The lack of mixed case makes it more
efficient to read out loud, write, type or to put into QR codes. format called
-''codex32'' and then define a BIP-0032 master seed encoding using it.
+''codex32'' and then define a secret sharing scheme and BIP-0032 master seed encoding using it.
===codex32===
A codex32 string is similar to a bech32 string defined in [https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki BIP-0173].
It reuses the base-32 character set from BIP-0173, and consists of:
-* A human-readable part, which is the string "ms" (or "MS").
-* A separator, which is always "1".
+* A human-readable part, as specified in BIP-0173. It identifies the application, which may impose additional validity requirements.
+* A separator, which is always "1". If the human-readable part contains "1", the last one in the string is the separator.
* A data part which is in turn subdivided into:
-** A threshold parameter, which MUST be a single digit between "2" and "9", or the digit "0".
-*** If the threshold parameter is "0" then the share index, defined below, MUST have a value of "s" (or "S").
-** An identifier consisting of 4 bech32 characters.
-** A share index, which is any bech32 character. Note that a share index value of "s" (or "S") is special and denotes the unshared secret (see section "Unshared Secret").
-** A payload which is a sequence of up to 69 bech32 characters. (However, see '''Long codex32''' below for an exception to this limit.)
-** A checksum which consists of 13 bech32 characters as described below.
+** A header consisting of the first six data characters:
+*** A threshold parameter, which MUST be a single digit between "2" and "9", or the digit "0".
+**** If the threshold parameter is "0" then the share index, defined below, MUST have a value of "s" (or "S").
+*** An identifier consisting of 4 bech32 characters.
+*** A share index, which is any bech32 character. Note that a share index value of "s" (or "S") is special and denotes the unshared secret (see [[#Unshared_Secret|Unshared secret]]).
+** A payload which is a sequence of up to 73 - 2''n'' bech32 characters, where ''n'' is the length of the human-readable part. (However, see [[#Long_Checksum|Long checksum]] below for an exception to this limit.)
+** A checksum which consists of 13 or 15 bech32 characters as described below.
-String validity may be further restricted by specific applications, see '''Master seed format''' below.
+BIP-0032 master seeds and their shares use the human-readable part "ms"; see [[#Master_seed_format|Master seed format]] for their other requirements.
+
+'''Uppercase/lowercase'''
As with bech32 strings, a codex32 string MUST be entirely uppercase or entirely lowercase.
Note that per BIP-0173, the lowercase form is used when determining a character's value for checksum purposes.
-In particular, given an all uppercase codex32 string, we still use lowercase ms as the human-readable part during checksum construction.
+In particular, given an all uppercase codex32 string, we still use the lowercase form of the human-readable part during checksum construction.
For presentation, lowercase is usually preferable, but uppercase SHOULD be used for handwritten codex32 strings.
If a codex32 string is encoded in a QR code, it SHOULD use the uppercase form, as this is encoded more compactly.
+
+'''Unshared secret'''
+
+When the share index of a valid codex32 string (converted to lowercase) is the letter "s", we call the string a codex32 secret.
+
+The secret's payload is decoded by application-specific rules.
+
+For an unshared secret, the threshold parameter (the first character of the data part) is ignored (beyond the fact it must be a digit for the codex32 string to be valid).
+We recommend using the digit "0" for the threshold parameter in this case.
+The 4 character identifier also has no effect beyond aiding users in distinguishing between multiple different secrets in cases where they have more than one.
+
====Checksum====
The last thirteen characters of a regular codex32 data part form a checksum and contain no information.
Valid strings MUST pass the criteria for validity specified by the Python 3 code snippet below.
-The function ms32_verify_checksum selects the checksum variant required by codex32 and MUST return true when its argument is the data part as a list of integers representing the characters converted using the bech32 character table from BIP-0173.
-The functions ms32_verify_regular_checksum and ms32_verify_long_checksum verify only their respective checksum variants within their stated periods.
+The function codex32_verify_checksum selects the checksum variant required by codex32 and MUST return true when its arguments are the human-readable part, converted to lowercase, and the data part as a list of integers representing the characters converted using the bech32 character table from BIP-0173.
+The functions codex32_verify_regular_checksum and codex32_verify_long_checksum verify only their respective checksum variants within their stated periods, given the expanded codeword as a list of integers.
Checksum selection depends on the expanded codeword length: the BIP-0173 expansion of the human-readable part followed by the complete data part.
-For the required human-readable part ms, the expansion contributes five values.
+A human-readable part of ''n'' characters contributes 2''n'' + 1 values to the expansion, so ms contributes five.
The regular checksum MUST be used when this length is at most 93, and the long checksum MUST be used when this length is between 96 and 1023, inclusive.
Expanded lengths 94 and 95, and lengths greater than 1023, are invalid.
-The functions ms32_create_regular_checksum and ms32_create_long_checksum construct the individual checksum variants.
-To construct the checksum variant required by codex32 given the data-part characters (excluding the checksum), the ms32_create_checksum function can be used.
+The functions codex32_create_regular_checksum and codex32_create_long_checksum construct the individual checksum variants from the expanded human-readable part and data-part characters (excluding the checksum).
+To construct the checksum variant required by codex32 given the human-readable part and the data-part characters (excluding the checksum), the codex32_create_checksum function can be used.
+
+'''Regular checksum'''
-MS32_CONST = 0x10ce0795c2fd1e62a
-MS32_HRP_EXPANDED_LENGTH = 5 # bech32_hrp_expand("ms")
+CODEX32_CONST = 0x10ce0795c2fd1e62a
-def ms32_polymod(values):
+def codex32_polymod(values):
GEN = [
0x19dc500ce73fde210,
0x1bfae00def77fe529,
@@ -112,7 +128,7 @@ def ms32_polymod(values):
0x1739640bdeee3fdad,
0x07729a039cfc75f5a,
]
- residue = 0x23181b3
+ residue = 1
for v in values:
b = (residue >> 60)
residue = (residue & 0x0fffffffffffffff) << 5 ^ v
@@ -120,38 +136,86 @@ def ms32_polymod(values):
residue ^= GEN[i] if ((b >> i) & 1) else 0
return residue
-def ms32_verify_regular_checksum(data):
- if MS32_HRP_EXPANDED_LENGTH + len(data) > 93:
+def bech32_hrp_expand(hrp):
+ return [ord(x) >> 5 for x in hrp] + [0] + [ord(x) & 31 for x in hrp]
+
+def codex32_verify_regular_checksum(values):
+ if len(values) > 93:
return False
- return ms32_polymod(data) == MS32_CONST
+ return codex32_polymod(values) == CODEX32_CONST
-def ms32_verify_checksum(data):
- expanded_length = MS32_HRP_EXPANDED_LENGTH + len(data)
- if expanded_length >= 96: # See Long codex32
- return ms32_verify_long_checksum(data)
- return ms32_verify_regular_checksum(data)
+def codex32_verify_checksum(hrp, data):
+ values = bech32_hrp_expand(hrp) + data
+ if len(values) >= 96: # See Long checksum
+ return codex32_verify_long_checksum(values)
+ return codex32_verify_regular_checksum(values)
-def ms32_create_regular_checksum(data):
- values = data
- polymod = ms32_polymod(values + [0] * 13) ^ MS32_CONST
+def codex32_create_regular_checksum(values):
+ polymod = codex32_polymod(values + [0] * 13) ^ CODEX32_CONST
return [(polymod >> 5 * (12 - i)) & 31 for i in range(13)]
-def ms32_create_checksum(data):
- if MS32_HRP_EXPANDED_LENGTH + len(data) + 13 > 93: # See Long codex32
- return ms32_create_long_checksum(data)
- return ms32_create_regular_checksum(data)
+def codex32_create_checksum(hrp, data):
+ values = bech32_hrp_expand(hrp) + data
+ if len(values) + 13 > 93: # See Long checksum
+ return codex32_create_long_checksum(values)
+ return codex32_create_regular_checksum(values)
This implements a [https://en.wikipedia.org/wiki/BCH_code BCH code] that
guarantees detection of '''any error changing at most 8 symbols''' in expanded codewords up to 93 symbols long
and has less than a 3 in 1020 chance of failing to detect more
random errors.
-====Error Correction====
+
+'''Long checksum'''
+
+
+CODEX32_LONG_CONST = 0x43381e570bf4798ab26
+
+def codex32_long_polymod(values):
+ GEN = [
+ 0x3d59d273535ea62d897,
+ 0x7a9becb6361c6c51507,
+ 0x543f9b7e6c38d8a2a0e,
+ 0x0c577eaeccf1990d13c,
+ 0x1887f74f8dc71b10651,
+ ]
+ residue = 1
+ for v in values:
+ b = (residue >> 70)
+ residue = (residue & 0x3fffffffffffffffff) << 5 ^ v
+ for i in range(5):
+ residue ^= GEN[i] if ((b >> i) & 1) else 0
+ return residue
+
+def codex32_verify_long_checksum(values):
+ if len(values) > 1023:
+ return False
+ return codex32_long_polymod(values) == CODEX32_LONG_CONST
+
+def codex32_create_long_checksum(values):
+ polymod = codex32_long_polymod(values + [0] * 15) ^ CODEX32_LONG_CONST
+ return [(polymod >> 5 * (14 - i)) & 31 for i in range(15)]
+
+This implements a [https://en.wikipedia.org/wiki/BCH_code BCH code] that
+guarantees detection of '''any error changing at most 8 symbols''' in expanded codewords up to 1023 symbols long
+and has less than a 3 in 1023 chance of failing to detect more
+random errors.
+
+A codex32 string using the long checksum follows the same specification as one using the regular checksum, with the following changes.
+
+* The payload is a sequence of up to 1001 - 2''n'' bech32 characters, where ''n'' is the length of the human-readable part.
+* The checksum consists of 15 bech32 characters as defined above.
+
+
+====Error correction====
A codex32 string without a valid checksum MUST NOT be used.
-The checksum is designed to be an error correcting code that can correct up to 4 character substitutions, up to 8 unreadable characters (called erasures), or up to 13 consecutive erasures.
+Both checksums are designed to correct up to 4 character substitutions or up to 8 unreadable characters (called erasures) in the data part.
+In the data part, the regular checksum can also correct up to 13 consecutive erasures, and the long checksum up to 15 consecutive erasures.
+The following recommendations apply to both checksums.
Implementations SHOULD provide the user with a corrected valid codex32 string if possible.
However, implementations SHOULD NOT automatically proceed with a corrected codex32 string without user confirmation of the corrected string, either by prompting the user, or returning a corrected string in an error message and allowing the user to repeat their action.
+Implementations SHOULD NOT correct errors in the human-readable part unless its application specifies how to do so.
We do not specify how an implementation should implement error correction. However, we recommend that:
* Implementations make suggestions to substitute non-bech32 characters with bech32 characters in some situations, such as replacing "B" with "8", "O" with "0", "I" with "l", etc.
@@ -160,102 +224,22 @@ We do not specify how an implementation should implement error correction. Howev
* If a string with 8 or fewer erasures can have those erasures filled in to make a valid codex32 string, then the implementation suggests such a string as a correction.
* If a string consisting of valid bech32 characters in the proper case can be made valid by substituting 4 or fewer characters, then the implementation suggests such a string as a correction.
-===Unshared Secret===
-
-When the share index of a valid codex32 string (converted to lowercase) is the letter "s", we call the string a codex32 secret.
-
-The secret's payload is decoded by application-specific rules.
-
-For an unshared secret, the threshold parameter (the first character of the data part) is ignored (beyond the fact it must be a digit for the codex32 string to be valid).
-We recommend using the digit "0" for the threshold parameter in this case.
-The 4 character identifier also has no effect beyond aiding users in distinguishing between multiple different secrets in cases where they have more than one.
-
-The function ms32_encode constructs a codex32 string with the required ms human-readable part when its argument is the converted data-part characters (excluding the checksum).
-
-To validate an ms master-seed share or secret and determine the data-part (excluding the checksum) as a list of 5-bit values, the ms32_decode function can be used.
-
-
-CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
-MS32_VALID_LENGTHS = (48, 54, 61, 67, 74, 127)
-
-def ms32_encode(data):
- combined = data + ms32_create_checksum(data)
- return "ms" + "1" + ''.join([CHARSET[d] for d in combined])
-
-def ms32_decode(codex):
- if ((any(ord(x) < 33 or ord(x) > 126 for x in codex)) or
- (codex.lower() != codex and codex.upper() != codex)):
- return None
- codex = codex.lower()
- pos = codex.rfind("1")
- if pos < 2 or len(codex) not in MS32_VALID_LENGTHS:
- return None
- if not all(x in CHARSET for x in codex[pos+1:]):
- return None
- if codex[:pos] != "ms" or codex[pos+1].isalpha() or codex[pos+1] == "0" and codex[pos+6] != "s":
- return None
- data = [CHARSET.index(x) for x in codex[pos+1:]]
- if not ms32_verify_checksum(data):
- return None
- return data[:-13 if MS32_HRP_EXPANDED_LENGTH + len(data) < 94 else -15]
-
-
-===Master seed format===
-
-When the human-readable part of a valid codex32 secret (converted to lowercase) is the string "ms", we call it a codex32-encoded master seed or secret seed. The payload in this case is a direct encoding of a BIP-0032 HD master seed.
-
-A secret seed is a codex32 encoding of:
-
-* The human-readable part "ms" for master seed.
-* The data-part values:
-** A threshold parameter, which MUST be a single digit between "2" and "9", or the digit "0".
-** An identifier consisting of 4 bech32 characters.
-*** We do not define how to choose the identifier, beyond noting that it SHOULD be distinct for every master seed and master seed share set the user may need to disambiguate.
-** The share index "s".
-** A conversion of a 16-, 20-, 24-, 28-, 32-, or 64-byte BIP-0032 HD master seed to bech32:
-*** Start with the bits of the master seed, most significant bit per byte first.
-*** Re-arrange those bits into groups of 5, and pad with arbitrary bits at the end if needed.
-*** Translate those bits to characters using the bech32 character table from BIP-0173.
-** A valid checksum in accordance with the Checksum section.
-
-The payload is decoded to a master seed as follows:
-
-* Translate the characters to 5-bit values using the bech32 character table from BIP-0173, most significant bit first.
-* Re-arrange those bits into groups of 8 bits. Any incomplete group at the end MUST be 4 bits or less, and is discarded.
-
-Unlike the decoding process in BIP-0173, master-seed decoding does not require that the discarded incomplete group contain only zero bits.
-The decoded master seed MUST be exactly 16, 20, 24, 28, 32, or 64 bytes.
-
-The supported master seed sizes map to codex32 as follows:
-
-{| class="wikitable"
-! Bits !! Bytes !! Payload characters !! Encoded length !! Checksum
-|-
-| 128 || 16 || 26 || 48 || Regular
-|-
-| 160 || 20 || 32 || 54 || Regular
-|-
-| 192 || 24 || 39 || 61 || Regular
-|-
-| 224 || 28 || 45 || 67 || Regular
-|-
-| 256 || 32 || 52 || 74 || Regular
-|-
-| 512 || 64 || 103 || 127 || Long
-|}
-
-===Recovering Secret===
+===SSSS-awareness===
When the share index of a valid codex32 string (converted to lowercase) is not the letter "s", we call the string a codex32 share.
The first character of the data part indicates the threshold of the share, and it is required to be a non-"0" digit.
+The corresponding secret has index "s", as described in [[#Unshared_Secret|Unshared secret]].
-In order to recover a secret, one needs a set of valid shares such that:
+The share generation and secret recovery procedures below are the same for both checksum variants.
-* All shares have the same threshold value, the same identifier, and the same length.
-* All of the share index values are distinct.
-* The number of shares is exactly equal to the (common) threshold value.
+The functions in this section represent each codex32 string as a list of integers obtained by converting the data-part characters to their values using the bech32 character table from BIP-0173.
+This representation omits the human-readable part, which is the same for the input strings and the result.
+The functions do not check the conditions on their inputs stated below, so implementations MUST check them before using the functions.
+
+The first argument to the codex32_interpolate function is a list of codex32 strings in this representation.
+Its second argument is a target share index converted to its integer value using the same character table, distinct from all input share indexes.
+The result represents the codex32 string at that index.
-If all the above conditions are satisfied, the ms32_recover function will return a codex32 secret when its argument is the list of codex32 shares with each share represented as a list of integers representing the characters converted using the bech32 character table from BIP-0173.
BECH32_INV = [
0, 1, 20, 24, 10, 8, 12, 29, 5, 11, 4, 9, 6, 28, 26, 31,
@@ -281,7 +265,7 @@ def bech32_lagrange(l, x):
c.append(m)
return [bech32_mul(n, BECH32_INV[i]) for i in c]
-def ms32_interpolate(l, x):
+def codex32_interpolate(l, x):
w = bech32_lagrange([s[5] for s in l], x)
res = []
for i in range(len(l[0])):
@@ -290,113 +274,120 @@ def ms32_interpolate(l, x):
n ^= bech32_mul(w[j], l[j][i])
res.append(n)
return res
-
-def ms32_recover(shares):
- return ms32_interpolate(shares, 16)
-===Generating Shares===
+
+====Generating shares====
If we already have ''k'' valid codex32 strings such that:
-* All strings have the same threshold value ''k'', the same identifier, and the same length
+* All strings have the same human-readable part, the same threshold value ''k'', the same identifier, and the same length
* All of the share index values are distinct
-Then we can derive additional shares with the ms32_interpolate function by passing it a list of exactly ''k'' of these codex32 strings, together with a fresh share index distinct from all of the existing share indexes.
-The newly derived share will have the provided share index.
+Then we can derive additional shares with the codex32_interpolate function.
+Pass a list of exactly ''k'' of these codex32 strings in the representation defined above, together with the integer value of a fresh share index distinct from all of the existing share indexes.
Once a user has generated ''n'' shares, they may discard the codex32 secret (if it exists).
The ''n'' shares form a ''k'' of ''n'' Shamir's secret sharing scheme of a codex32 secret.
There are two ways to create an initial set of ''k'' valid codex32 strings, depending on whether the user already has an existing secret to split.
-====For a fresh secret====
+
+'''For a fresh secret'''
-In the case that the user wishes to generate a fresh secret, the user generates random initial shares, as follows:
+In the case that the user wishes to generate a fresh secret, the user generates random initial shares, as follows.
+This requires an application that accepts every payload of the chosen length as a secret, as the master seed format does.
+If the application does not accept every payload of the chosen length, it MAY use rejection sampling: retry with a fresh set of shares until the resulting secret is valid for the application.
-# Choose a bit size from 128, 160, 192, 224, 256, or 512
+# Choose the human-readable part of the application and a payload length it accepts
+#* For a master seed, use ms and a payload length permitted by [[#Master_seed_format|Master seed format]]
# Choose a threshold value ''k'' between 2 and 9, inclusive
# Choose a 4 bech32 character identifier
#* We do not define how to choose the identifier, beyond noting that it SHOULD be distinct for every secret the user may need to disambiguate
# ''k'' many times, generate a random share by:
## Take the next available letter from the bech32 alphabet, in alphabetical order, as a, c, d, ..., to be the share index
-## Set the first nine characters to be the prefix ms1, the threshold value ''t'', the 4-character identifier, and then the share index
-## Choose the next ceil(''bitlength / 5'') characters uniformly at random
+## Start with the human-readable part, the separator 1, the threshold value ''k'', the 4-character identifier, and then the share index
+## Choose the payload characters uniformly at random
## Generate a valid checksum in accordance with the Checksum section, and append this to the resulting shares
-The result will be ''k'' distinct shares, all with the same initial 8 characters, and a distinct share index as the 9th character.
+The result will be ''k'' distinct shares, all with the same human-readable part and first five data characters, and a distinct share index as the sixth data character.
With this set of ''k'' shares, new shares can be derived as discussed above. This process generates a fresh secret, whose value can be retrieved by running the recovery process on any ''k'' of these shares.
-====For an existing secret====
+
+'''For an existing secret'''
Before generating shares for an existing secret, it first must be codex32-encoded.
The conversion process consists of:
+# Use the human-readable part of the application (ms for a master seed)
# Choose a threshold value ''k'' between 2 and 9, inclusive
# Choose a 4 bech32 character identifier
#* We do not define how to choose the identifier, beyond noting that it SHOULD be distinct for every set of shares the user may need to disambiguate
# Set the share index to s
-# Set the payload to a bech32 encoding of the application-specified secret payload bits; for a master seed, follow "Master seed format".
+# Set the payload to a bech32 encoding of the application-specified secret payload bits; for a master seed, follow [[#Master_seed_format|Master seed format]].
# Generate a valid checksum in accordance with the Checksum section
-Along with the codex32 secret, the user must generate ''k''-1 other codex32 shares, each with the same threshold value, the same identifier, and a distinct share index.
-These shares should be generated as described in the "fresh secret" section.
+Along with the codex32 secret, the user must generate ''k''-1 other codex32 shares, each with the same human-readable part, the same threshold value, the same identifier, and a distinct share index.
+These shares should be generated as described in [[#For_a_fresh_secret|For a fresh secret]].
The codex32 secret and the ''k''-1 codex32 shares form a set of ''k'' valid initial codex32 strings from which additional shares can be derived as described above.
-===Long codex32===
+
+====Recovering secret====
+
+In order to recover a secret, one needs a set of valid shares such that:
-The 13 character checksum design only supports expanded codewords of up to 93 values.
-After accounting for the expanded ms human-readable part, header, and checksum, this limits the payload of a regular codex32 string to 69 characters.
-While this is enough to support the 32-byte advised size of BIP-0032 master seeds, BIP-0032 allows seeds to be up to 64 bytes in size.
-We define a long codex32 format to support these longer seeds by defining an alternative checksum.
+* All shares have the same human-readable part, the same threshold value, the same identifier, and the same length.
+* All of the share index values are distinct.
+* The number of shares is exactly equal to the (common) threshold value.
+If all the above conditions are satisfied, the codex32_recover function returns the corresponding codex32 secret from a list of the shares.
+Both the input shares and the returned secret use the representation defined above.
-MS32_LONG_CONST = 0x43381e570bf4798ab26
+def codex32_recover(shares):
+ return codex32_interpolate(shares, 16)
+
-def ms32_long_polymod(values):
- GEN = [
- 0x3d59d273535ea62d897,
- 0x7a9becb6361c6c51507,
- 0x543f9b7e6c38d8a2a0e,
- 0x0c577eaeccf1990d13c,
- 0x1887f74f8dc71b10651,
- ]
- residue = 0x23181b3
- for v in values:
- b = (residue >> 70)
- residue = (residue & 0x3fffffffffffffffff) << 5 ^ v
- for i in range(5):
- residue ^= GEN[i] if ((b >> i) & 1) else 0
- return residue
+===Master seed format===
-def ms32_verify_long_checksum(data):
- if MS32_HRP_EXPANDED_LENGTH + len(data) > 1023:
- return False
- return ms32_long_polymod(data) == MS32_LONG_CONST
+When the human-readable part of a valid codex32 secret (converted to lowercase) is the string "ms", we call it a codex32-encoded master seed or secret seed. The payload in this case is a direct encoding of a BIP-0032 HD master seed.
-def ms32_create_long_checksum(data):
- values = data
- polymod = ms32_long_polymod(values + [0] * 15) ^ MS32_LONG_CONST
- return [(polymod >> 5 * (14 - i)) & 31 for i in range(15)]
-
-This implements a [https://en.wikipedia.org/wiki/BCH_code BCH code] that
-guarantees detection of '''any error changing at most 8 symbols''' in expanded codewords up to 1023 symbols long
-and has less than a 3 in 1023 chance of failing to detect more
-random errors.
+The header and checksum follow the [[#codex32|codex32 format]] requirements above, with share index "s".
+We do not define how to choose the identifier, beyond noting that it SHOULD be distinct for every master seed and master seed share set the user may need to disambiguate.
-A long codex32 string follows the same specification as a regular codex32 string with the following changes.
+A 128-, 160-, 192-, 224-, 256-, or 512-bit BIP-0032 HD master seed is converted to the payload as follows:
-* The payload is a sequence of up to 997 bech32 characters.
-* The checksum consists of 15 bech32 characters as defined above.
-* The expanded codeword length MUST be between 96 and 1023 values, inclusive.
+* Start with the bits of the master seed, most significant bit per byte first.
+* Re-arrange those bits into groups of 5, and pad with arbitrary bits at the end if needed.
+* Translate those bits to characters using the bech32 character table from BIP-0173.
-A codex32 string with an expanded codeword length of 94 or 95 values is never legal.
-Generation of long shares and recovery of the long secret from long shares proceeds in exactly the same way as for regular shares with the ms32_interpolate function.
+The payload is decoded to a master seed as follows:
+
+* Translate the characters to 5-bit values using the bech32 character table from BIP-0173, most significant bit first.
+* Re-arrange those bits into groups of 8 bits. Any incomplete group at the end MUST be 4 bits or less, and is discarded.
-The long checksum is designed to be an error correcting code that can correct up to 4 character substitutions, up to 8 unreadable characters (called erasures), or up to 15 consecutive erasures.
-As with regular checksums we do not specify how an implementation should implement error correction, and all our recommendations for error correction of regular codex32 strings also apply to long codex32 strings.
+Unlike the decoding process in BIP-0173, master-seed decoding does not require that the discarded incomplete group contain only zero bits.
+The decoded master seed MUST be exactly 16, 20, 24, 28, 32, or 64 bytes.
+
+A codex32-encoded master seed or a share of one MUST have an encoded length listed in the table below.
+The supported master seed sizes map to codex32 as follows:
+
+{| class="wikitable"
+! Bits !! Bytes !! Payload characters !! Encoded length !! Checksum
+|-
+| 128 || 16 || 26 || 48 || Regular
+|-
+| 160 || 20 || 32 || 54 || Regular
+|-
+| 192 || 24 || 39 || 61 || Regular
+|-
+| 224 || 28 || 45 || 67 || Regular
+|-
+| 256 || 32 || 52 || 74 || Regular
+|-
+| 512 || 64 || 103 || 127 || Long
+|}
==Rationale==
@@ -409,28 +400,29 @@ This fact allows the header data to be covered by the checksum.
The checksum size and identifier size have been chosen so that the encoding of 128-bit master seeds and shares fit within 48 characters.
This is a standard size for many common seed storage formats, which has been popularized by the 12 four-letter word format of the BIP-0039 mnemonic.
-The 13 character checksum is adequate to correct 4 errors in expanded codewords of up to 93 values.
-We can correct up to 8 erasures (errors with known locations), and up to 13 consecutive errors (burst errors).
-Beyond that, our code is guaranteed to detect up to 8 errors.
-More generally, any number of random errors will be detected with overwhelming (1 - 2^65) probability. However, the checksum does not protect against maliciously constructed errors.
-These parameters are slightly better than those of the checksum used in SLIP-0039.
+The error detection and correction properties described above are slightly better than those of the checksum used in SLIP-0039.
+However, the checksum does not protect against maliciously constructed errors.
For 256-bit seeds and shares our strings are 74 characters, which fits into the 96 character format of the 24 four-letter word format of the BIP-0039 mnemonic, with plenty of room to spare.
The supported 128-, 160-, 192-, 224-, and 256-bit sizes are the entropy sizes defined by BIP-0039, while 512 bits is the BIP-0032 seed size produced by BIP-0039 recovery.
-These encoded lengths have at least six-character gaps, reducing target length ambiguity for optional insert/delection correction workflows.
+These encoded lengths have at least six-character gaps, reducing target length ambiguity for optional insertion/deletion correction.
-A longer checksum is needed to support up to 512-bit seeds, the longest seed length specified in BIP-0032, because their expanded codewords exceed the regular checksum's 93-symbol limit.
+While the regular checksum is enough to support the 256-bit advised size of BIP-0032 master seeds, BIP-0032 allows seeds to be up to 512 bits in size.
+We define a long checksum to support the maximum seed size because its expanded codewords exceed the regular checksum's limit.
While we could use the 15 character checksum for both cases, we prefer to keep the strings as short as possible for the more common cases of 128-bit and 256-bit master seeds.
-We only guarantee to correct 4 characters no matter how long the string is.
Longer strings mean more chances for transcription errors, so shorter strings are better.
-Checksum selection includes the expanded ms human-readable part, so every regular codex32 codeword remains within the 93-value checksum period.
-If the prefix is damaged and a user is guessing that the data might be using this scheme, then the user can enter the available data explicitly using the suspected MS1 prefix.
+The checksum covers the expanded human-readable part, as in BIP-0173, and the expansion counts toward the checksum length limits.
+Beyond those limits, some errors in the human-readable part cannot be distinguished from errors elsewhere in the string, so counting the expansion keeps the error detection guarantees for the entire string.
+It also lets implementations select the checksum variant from the string alone, without knowing the application.
+
+For master seeds, if the human-readable part is damaged, the user can enter the available data explicitly using the suspected MS1 prefix.
-===Not BIP-0039 Entropy===
+
+===Not BIP-0039 entropy===
Instead of encoding a BIP-0032 master seed, an alternative would be to encode BIP-0039 entropy.
However this alternative approach is fraught with difficulties.
@@ -462,14 +454,19 @@ The main advantage of this alternative approach would be that wallets could give
In practice, we do not expect users in switch back and forth between backup formats, and instead just generate a fresh master seed using Codex32.
Seeing little value with BIP-0039 compatibility (English-only), all the difficulties with BIP-0039 language choice, not to mention the PBKDF2 overhead of using BIP-0039, we think it is best to abandon BIP-0039 and encode BIP-0032 master seeds directly.
-Our approach is semi-convertible with BIP-0039's 512-bit master seeds (in all languages, see Backwards Compatibility) and interconvertible with SLIP-0039 master seeds or any other encoding of BIP-0032 master seeds with a supported length.
+Our approach is semi-convertible with BIP-0039's 512-bit master seeds (in all languages, see [[#Backwards_Compatibility|Backwards compatibility]]) and interconvertible with SLIP-0039 master seeds or any other encoding of BIP-0032 master seeds with a supported length.
-==Backwards Compatibility==
+
+==Backwards compatibility==
-Earlier revisions accepted every master seed length from 16 through 64 bytes using regular checksum up to 93 data characters and long checksum from 96 data characters.
-This revision retains 16-, 20-, 24-, 28-, 32-, and 64-byte master seeds.
+Versions before 0.2.0 accepted every master seed length from 16 through 64 bytes using regular checksum up to 93 data characters and long checksum from 96 data characters.
+Version 0.2.0 retains 128-, 160-, 192-, 224-, 256-, and 512-bit master seeds.
Encodings at retained sizes are unchanged; all other formerly valid 16-to-64-byte strings are now invalid.
+Versions before 0.3.0 required the human-readable part "ms".
+Other human-readable parts are now allowed, and strings with the human-readable part "ms" are unchanged.
+The checksum of a string with another human-readable part covers the expansion of that human-readable part, so a checksum computed as if the human-readable part were "ms" is not valid for it.
+
codex32 is an alternative to BIP-0039 and SLIP-0039.
It is technically possible to derive the BIP32 master seed from seed words encoded in one of these schemes, and then to encode this seed in codex32.
For BIP-0039 this process is irreversible, since it involves hashing the original words.
@@ -481,13 +478,15 @@ However, SLIP-0039 '''shares''' cannot be converted to codex32 shares because th
The authors of this BIP do not recommend interconversion.
Instead, users who wish to switch to codex32 should generate a fresh seed and sweep their coins.
-==Reference Implementation==
+
+==Reference implementation==
-The inline code in this BIP text can be used as a Python reference.
+The inline code in this BIP text provides Python reference implementations of the checksum and interpolation primitives.
A complete Python implementation is available in the [https://github.com/BenWestgate/python-codex32 python-codex32 repository].
The [https://github.com/BlockstreamResearch/codex32 original project repository] contains implementations in Rust and PostScript.
-==Test Vectors==
+
+==Test vectors==
===Test vector 1===
@@ -583,7 +582,7 @@ Note that the choice to append four zero bits was arbitrary, and any of the foll
This example shows generating a new 512-bit master seed using "random" bech32 characters and appending a checksum.
The payload contains 103 bech32 characters, which corresponds to 515 bits. The last three bits are discarded when converting to a 512-bit master seed.
-This is an example of a '''Long codex32''' string.
+This example uses the '''long checksum'''.
k value (bech32): 0
@@ -609,8 +608,49 @@ These unshared codex32-encoded master seeds use the identifier seed
** The discarded bit has the value 1.
** codex32 secret: ms10seedsgpq5ys6yg4rywjzfff95cn2wfag9z5jn2324v46ct9d9hrcduqw8c3lccl
+===Test vector 9===
+
+This example shows a codex32 secret with a human-readable part other than ms.
+The human-readable part cl is registered in SLIP-0173 for Core Lightning HSM secrets; that application, not this document, defines the payload.
+
+codex32 secret: cl10peevst6cqh0wu7p5ssjyf4z4ez42ks9jlt3zneju9uuypr2hddak6tlqsjhsks4laxts8q
+
+* human-readable part: cl
+* separator: 1
+* k value: 0 (no secret splitting)
+* identifier: peev
+* share index: s (the secret)
+* payload: t6cqh0wu7p5ssjyf4z4ez42ks9jlt3zneju9uuypr2hddak6tlqs
+* checksum: jhsks4laxts8q
+
+The checksum covers the human-readable part.
+With the human-readable part ms, the same header and payload form a 256-bit codex32-encoded master seed with a different checksum: ms10peevst6cqh0wu7p5ssjyf4z4ez42ks9jlt3zneju9uuypr2hddak6tlqstxmpzl24l6e0d
+
+===Test vector 10===
+
+This example shows generating shares with the 11-character human-readable part test_vector, using ''k''=2 and an identifier of span.
+The payloads have 52 characters, as for a 256-bit master seed.
+Each string has an expanded codeword length of 96, so it uses the long checksum even though its data part has only 73 characters.
+
+Share with index a: test_vector12spana320zyxwvutsrqpnmlkjhgfedca320zyxwvutsrqpnmlkjhgfedca304ppsqh4l7v3dh
+
+Share with index c: test_vector12spancacdefghjklmnpqrstuvwxyz023acdefghjklmnpqrstuvwxyz023jxmjy7q9xl7d3ul
+
+* Derived share with index d: test_vector12spandll4f8jlh4e5vdvuldlfxu2jhdnll4f8jlh4e5vdvuldlfxu2jhdnx3pe3yqzdl7p30y
+* Recovered secret with index s: test_vector12spans6xqguzttxkeqnjsjzv4jv3nz5k6xqguzttxkeqnjsjzv4jv3nz5kdf37v5qm2l7l3az
+
+===Test vector 11===
+
+This example shows a codex32 secret with an empty payload and the longest allowed human-readable part, which has 83 characters.
+The human-readable part contains 1, so the last 1 is the separator, and it contains b, i, and o, which cannot appear in the data part.
+Its expanded codeword length of 188 requires the long checksum.
+
+codex32 secret: a83characterlongcodex32humanreadablepartforsecretsharewiththedigit1andthelettersbio10keyss9mfjjk25y05e3nq
+
===Invalid test vectors===
+None of the following examples are valid codex32-encoded master seeds or master seed shares, although some are valid codex32 strings for decoders that do not apply the master seed rules.
+
These examples have incorrect checksums.
* ms10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxve740yyge2ghq
@@ -666,15 +706,21 @@ This example has a threshold that is not a digit.
* ms1fauxxxxxxxxxxxxxxxxxxxxxxxxxxxxxda3kr3s0s2swg
-These examples do not begin with the required "ms" or "MS" prefix and/or are missing the "1" separator.
+These examples are missing the "1" separator or have an empty human-readable part.
* 0fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
* 10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
* ms0fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
-* m10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
-* s10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
* 0fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxhkd4f70m8lgws
* 10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxhkd4f70m8lgws
+
+These examples have a checksum computed for the human-readable part "ms", but a different human-readable part.
+
+* m10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
+* s10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxuqxkk05lyf3x2
+
+These examples are valid codex32 strings, but not master seeds, because their human-readable part is not "ms".
+
* m10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxx8t28z74x8hs4l
* s10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxh9d0fhnvfyx3x
@@ -688,9 +734,52 @@ These examples all incorrectly mix upper and lower case characters.
* ms10fauxsXXXXXXXXXXXXXXXXXXXXXXXXXXuqxkk05lyf3x2
* ms10fauxsxxxxxxxxxxxxxxxxxxxxxxxxxxUQXKK05LYF3X2
+These examples have a human-readable part other than "ms" and the invalid expanded codeword lengths 94 and 95. They use the regular and long checksums, respectively.
+
+* test_vector12spans6xqguzttxkeqnjsjzv4jv3nz5k6xqguzttxkeqnjsjzv4jv3nz5kp0f0tlr2cxh0t
+* test_vector12spans6xqguzttxkeqnjsjzv4jv3nz5k6xqguzttxkeqnjsjzv4jv3nz5c2m7mxmk8s5qecp
+
+This example has a checksum computed using the uppercase form of the human-readable part.
+
+* CL10PEEVST6CQH0WU7P5SSJYF4Z4EZ42KS9JLT3ZNEJU9UUYPR2HDDAK6TLQS3J5AYX4Y08079
+
+This example has a human-readable part longer than 83 characters.
+
+* a84characterslongcodex32humanreadablepartforsecretsharewiththedigit1andthelettersbio10keyss9hqxu3pxsnkdkth
+
+==Changelog==
+
+Versions before 0.2.1 are assigned retrospectively to significant revisions.
+
+* '''0.3.0''' (2026-10-01): [https://github.com/bitcoin/bips/pull/2320 #2320]
+** Allow human-readable parts other than "ms"; the checksum covers them and counts their expansion toward its length limits.
+** Rename the inline ms32 functions to codex32 and pass the human-readable part to the checksum functions.
+** Require all shares in a set to have the same human-readable part.
+** Add test vectors for other human-readable parts.
+* '''0.2.1''' (2026-09-13): [https://github.com/bitcoin/bips/pull/2285 #2285]
+** Separate the codex32 format, optional secret sharing, and master seed encoding into distinct sections.
+** Remove duplicate explanations and inline encoding and decoding helpers, reorganize headings, and clarify seed-size units without changing behavior.
+* '''0.2.0''' (2026-09-11): [https://github.com/bitcoin/bips/pull/2258 #2258]
+** Count the expanded human-readable part in checksum length limits.
+** Restrict master seed sizes to 128, 160, 192, 224, 256, and 512 bits; encodings at retained sizes are unchanged.
+** Update validation, rationale, compatibility notes, and test vectors.
+* '''0.1.3''' (2026-01-14): [https://github.com/bitcoin/bips/pull/1820 #1820]
+** Update the preamble to the BIP-0003 format.
+* '''0.1.2''' (2025-12-15): [https://github.com/bitcoin/bips/pull/2052 #2052]
+** Add Python encoding and decoding helpers, clarify header and checksum handling, and standardize terminology and presentation.
+* '''0.1.1''' (2023-03-30): [https://github.com/bitcoin/bips/pull/1439 #1439]
+** Add invalid test vectors, correct capitalization and typos, fix the reference implementation link, and update the author list.
+* '''0.1.0''' (2023-03-17): [https://github.com/bitcoin/bips/pull/1425 #1425]
+** Publish the initial draft.
+
+==Registered human-readable parts==
+
+SatoshiLabs maintains a non-normative list of registered codex32 human-readable parts in [https://github.com/satoshilabs/slips/blob/master/slip-0173.md#uses-of-codex32 SLIP-0173].
+
==Appendix==
-===Mathematical Companion===
+
+===Mathematical companion===
Below we use the bech32 character set to denote values in GF[32].
In bech32, the letter Q denotes zero and the letter P denotes one.