0025 XLS-25d: Enhanced Secret Numbers (XLS-12 Extension) #63
Replies: 2 comments
-
Great proposal @nbougalis, thank you. I agree with you on the less than optimal checksum for the existing Secret numbers, and the combined ed+secp compatibility is a great idea as well. When I find some spare time I will work on an implementation in https://github.com/WietseWind/xrpl-secret-numbers/ 👍 |
Beta Was this translation helpful? Give feedback.
-
@WietseWind's comment above stems from a conversation in the "Technical" channel on Mattermost. He wrote:
I responded that:
I thought about it some more and there might be a further improvement on my potential improvement. By construction, no valid XLS12 block can have a value greater than Again, assume that
The end result is an If you think this is a reasonable approach, I'll make the necessary tweaks to the spec above. |
Beta Was this translation helpful? Give feedback.
-
Enhanced Secret Numbers
Abstract
The Secret Numbers proposal XLS-12 introduces a new format for secrets - based on blocks of numbers/digits (0-9) with block-level checksums - to generate XRP Ledger account keys and address. This draft proposes augmenting and enhancing XLS-12 to make the format more flexible and more robust.
Motivation
The XRP Ledger typically uses 128-bit seeds as the cryptographic material from which cryptographic keys for accounts are derived. Such seeds are generally too long for humans to remember and the existing formats are hard to transcribe. Prior to XLS-12, there were 4 canonical encoding for the seed data:
s
(in this format, the result is often, but incorrectly, referred to as a private key); orBy way of example, let's use the well-known genesis account,
rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh
, which has an associatedsecp256k
key:snoPBrXtMeMyMHUVTgbuqAfg1SUTb
;I IRE BOND BOW TRIO LAID SEAT GOAL HEN IBIS IBIS DARE
;DEDCE9CE67B451D852FD4E846FCDE31C
; andmasterpassphrase
.The XLS-12 standard introduced a new format, secret mumbers, which consists of 8 blocks of 6 digits, where the first five digits correspoding to a 16-bit number (from 0 to 65535) and the 6th digit is a checksum based on the five preceding digits and the index of the block. The XLS-12 secret numbers for the genesis account are:
570521-598543-265488-209520-212450-201006-286214-581400
.Issues with XLS-12
The XLS-12 specification, while convenient and easier to transcribe, has several drawbacks:
First, it encodes no ancillary information about the information encoded (e.g. whether it is meant to derive a secp256k1 or an Ed25519 key) and is limited to only encoding seeds, from which keys are then derived. Second, the block-level checksum is inefficient and detects only a small percentage of errors.
Lastly, it's unclear whether the secret numbers should be used to create a secp256k1 or an Ed25519 key. For example, given the above
570521-598543-265488-209520-212450-201006-286214-581400
secret numbers, an implementation could derive an Ed25519 and, therefore, an account that is not the well-known genesis account. Tools that support secret numbers typically resort to detecting the type of account, usually in a semi- automated fashion, but on occasion by resorting to asking the user to confirm their intended public address.Enhancements to XLS-12
This proposal aims to address these problems by proposing extensions to XLS-12 which retaining backwards compatibility. There are three primary changes:
Secret numbers compatible with this specification will always be composed of an odd number of blocks; secret numbers compatible with the XLS-12 specification will always be composed of an even number of blocks—or more specifically, precisely 8 blocks. This makes it possible to seamlessly detect which standard was used and allows for backwards compatibility.
Per-block checksusm
Under XLS-12 the Nth block consists of 16 bits of raw key material, and an additional checksum digit. Assuming the keying material has value
X
the Nth block would be:(X * 10) + ((X * (N * 2 + 1)) % 9)
.In theory, the checksum digit can take any value from [0,...,9] but, by construction, not all checksum digits are equally likely across all blocks, reducing their usefulness. For blocks at positions 2 and 8, the only valid checksum digits are
0
,3
and6
; blocks at position 5 are worse, with0
being the only valid checksum digit.This proposal simplifies the checksum function for key blocks by reducing it to a simple multiplication by 13, a prime number. That is, the Nth key block simply becomes:
X * 13
. Under this scheme, the possible values are multiple of 13 and and the range is from [0,...,851955]. This scheme avoids the position-dependent behavior observed with the existing scheme and allows for more efficient error detection.Information Block
This proposal prepends an additional 6-digit block, composed of two 16-bit values, that encodes ancillary information about the content and a checksum of the blocks that can be used to detect whole-block transposition, or incorrect blocks.
First, calculate the checksum of all blocks as
(∑(𝑥[i] * π[i]>)) mod 256
, where𝑥[i]
is the ith 16-bit block of data being encoded andπ[i]
is the ith prime number. The result is an 8-bit value,C
.Flags
The proposal also defines an 8-bit field, that can be used to specify details or ancillary information about the key. This proposal defines this as a bitfield named
F
. The following flags are defined:0x01
rippled
.0x02
0x04
0x08
0x10
PREIMAGE-SHA256
cryptocondition. This flag cannot be combined with any other flags.Using Flags
The different flags used with extended keys make it possible to directly encode different types of keys as well as allow for 128-bit and 256-bit keys.
For example:
secp256k
(orEd25519
, if the0x08
flag is included) key can be directly encoded as 17 groups, if they information block does not include the0x01
flag.0x10
flag.Other flags may be added in the future. A compliant implementation of this proposal SHOULD fail if any flags other than the ones it understands are used.
Information Block Checksum
By construction, no valid XLS12 block can have a value greater than 655356 (i.e. 65535 * 10 + (65535 % 9)). This means that any block that begins with a 7, 8 or 9 cannot be a valid XLS12 block. This means that we can construct the first block in such a way so as to allow for automatic detection of "classic" XLS-12 keys and "extended" keys as defined in this proposal.
Again, assume that C is the checksum described above and F is the flag bitfield, then the information block checksum
X
is defined as:The information block itself is then calculated as:
The end result is an A block that begins with 7, 8 or 9, which means it cannot be a valid XLS12 block, while still retaining a checksum in the A block.
Beta Was this translation helpful? Give feedback.
All reactions