mirror of
https://github.com/bitcoin/bips.git
synced 2026-10-19 19:29:18 +00:00
bip-138: clarify CONTENT is a single TLV and forbid all-zero nonce
This commit is contained in:
1 parent
72d8a9533f
commit
b7ba2840a9
1 file changed
+16
-8
+16
-8
@@ -167,6 +167,9 @@ and integrity.
|
|||||||
* let $nonce$ = random(96 bits)
|
* let $nonce$ = random(96 bits)
|
||||||
* let $ciphertext$ = encrypt($payload$, $secret$, $nonce$)
|
* let $ciphertext$ = encrypt($payload$, $secret$, $nonce$)
|
||||||
|
|
||||||
|
The $nonce$ MUST NOT be all zero. If the random source yields an all-zero nonce,
|
||||||
|
the encoder MUST generate a new one.
|
||||||
|
|
||||||
### Decryption
|
### Decryption
|
||||||
|
|
||||||
In order to decrypt the payload of a backup, the owner of a certain public key p
|
In order to decrypt the payload of a backup, the owner of a certain public key p
|
||||||
@@ -309,6 +312,10 @@ it follows this format:
|
|||||||
|
|
||||||
`TYPE` (`LENGTH`) `DATA`
|
`TYPE` (`LENGTH`) `DATA`
|
||||||
|
|
||||||
|
`CONTENT` is a single `TYPE (LENGTH) DATA` triple, one blob describing `PLAINTEXT`.
|
||||||
|
It is not a sequence of entries; it is immediately followed by the payload `LENGTH`
|
||||||
|
and `PLAINTEXT`.
|
||||||
|
|
||||||
`TYPE`: 1-byte unsigned integer identifying how to interpret `DATA`.
|
`TYPE`: 1-byte unsigned integer identifying how to interpret `DATA`.
|
||||||
|
|
||||||
| Value | Definition |
|
| Value | Definition |
|
||||||
@@ -332,16 +339,17 @@ For `TYPE` values defined above:
|
|||||||
For all `TYPE` values except `0x01`, parsers MUST reject `CONTENT` if `LENGTH` exceeds
|
For all `TYPE` values except `0x01`, parsers MUST reject `CONTENT` if `LENGTH` exceeds
|
||||||
the remaining payload bytes.
|
the remaining payload bytes.
|
||||||
|
|
||||||
Parsers MUST skip unknown `TYPE` values less than `0x80`, by consuming `LENGTH` bytes
|
For an unknown `TYPE` less than `0x80`, parsers MUST consume its `LENGTH` bytes of
|
||||||
of `DATA`.
|
`DATA`, treat the content type as unknown, and continue with the payload `LENGTH`
|
||||||
|
and `PLAINTEXT`.
|
||||||
|
|
||||||
For unknown `TYPE` values greater than or equal to `0x80`, parsers MUST stop parsing
|
For an unknown `TYPE` greater than or equal to `0x80`, parsers MUST reject the
|
||||||
`CONTENT`.[^type-upgrade]
|
payload.[^type-upgrade]
|
||||||
|
|
||||||
[^type-upgrade]: **Why the 0x80 threshold?**
|
[^type-upgrade]: **Why the 0x80 threshold?**
|
||||||
The `TYPE >= 0x80` rule means we're not stuck with the current TLV encoding.
|
The `TYPE >= 0x80` rule keeps the encoding upgradeable. A future version can
|
||||||
It has a nice upgrade property: you can still encode backward compatible stuff
|
define a new content type at or above `0x80` that older parsers reject rather
|
||||||
at the start.
|
than misread, while types below `0x80` stay backward compatible.
|
||||||
|
|
||||||
#### Encrypted Payload
|
#### Encrypted Payload
|
||||||
|
|
||||||
@@ -349,7 +357,7 @@ For unknown `TYPE` values greater than or equal to `0x80`, parsers MUST stop par
|
|||||||
|
|
||||||
`NONCE` `LENGTH` `CIPHERTEXT`
|
`NONCE` `LENGTH` `CIPHERTEXT`
|
||||||
|
|
||||||
`NONCE`: 12-byte (96-bit) nonce.
|
`NONCE`: 12-byte (96-bit) nonce. Parsers MUST reject a backup whose `NONCE` is all zero.
|
||||||
`LENGTH`: variable-length integer representing ciphertext length.
|
`LENGTH`: variable-length integer representing ciphertext length.
|
||||||
`CIPHERTEXT`: variable-length ciphertext.
|
`CIPHERTEXT`: variable-length ciphertext.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user