Skip to content
Snippets Groups Projects
Commit 44a1ef08 authored by Vincent Texier's avatar Vincent Texier Committed by Éloïs
Browse files

[RFC17] reworf presentation and add example values

parent dd3b6d9f
No related branches found
No related tags found
1 merge request!13Tx comment encrypt
...@@ -37,14 +37,15 @@ The symmetric encryption key `k` is obtained as follows: ...@@ -37,14 +37,15 @@ The symmetric encryption key `k` is obtained as follows:
With following parameters for scrypt: With following parameters for scrypt:
```txt | Parameter | Value |
password = R |:-----------:|:-------:|
Salt = s |**password** | R |
N = 1024 |**Salt** | s |
r = 8 |**N** | 1024 |
p = 1 |**r** | 8 |
dkLen = message length |**p** | 1 |
``` |**dkLen** | message length |
## Encrypt with XOR cipher ## Encrypt with XOR cipher
...@@ -52,9 +53,21 @@ Encrypt bit per bit with XOR cipher. ...@@ -52,9 +53,21 @@ Encrypt bit per bit with XOR cipher.
## Serialize encrypted message with meta data ## Serialize encrypted message with meta data
| Magic value | Version | Message type | Nonce | Real message length | Encrypted UTF8 message | Random extra bytes | | Metadata | Encrypted Data |
|:-----------:|:-------:|:------------:|:--------:|:-------------------:|:----------------------:|:------------------:| | ------ | -------------- |
| `0x27b6` | `0x01` | 1 byte | 16 bytes | 1 byte (encrypted) | Any bytes | Any bytes | | 20 bytes | max. 171 bytes |
### Metadata
| Magic value | Version | Message type | Nonce |
|:-----------:|:-------:|:------------:|:--------:|
| `0x27b6` | `0x01` | 1 byte | 16 bytes |
### Encrypted Data
| Real message length | UTF8 message | Random extra bytes |
|:-------------------:|:------------:|:------------------:|
| 1 byte | Any byte | Any bytes |
The message must be encoded in UTF8. The message must be encoded in UTF8.
...@@ -75,6 +88,10 @@ Future versions of the present format must increment this byte. ...@@ -75,6 +88,10 @@ Future versions of the present format must increment this byte.
| 0x00 | For a human | | 0x00 | For a human |
| 0x01 | For a machine | | 0x01 | For a machine |
### Nonce
An sequence of 16 random bytes to use as scrypt salt
### Real message length ### Real message length
Indicates the real size of the message in bytes. That is, the number of bytes that should be interpreted as an UTF8 string. There may be extra bytes, the extra bytes should be ignored (see section "Random extra bytes"). Indicates the real size of the message in bytes. That is, the number of bytes that should be interpreted as an UTF8 string. There may be extra bytes, the extra bytes should be ignored (see section "Random extra bytes").
...@@ -100,7 +117,7 @@ There are at least 21 bytes of metadata, so the maximum size of a message is **1 ...@@ -100,7 +117,7 @@ There are at least 21 bytes of metadata, so the maximum size of a message is **1
Let `m` the user message bytes encoded in UTF8. Let `m` the user message bytes encoded in UTF8.
Let `t` the message type. Let `t` the message type.
1. Generate 16 random bytes a stores them in a byte array `nonce`. 1. Generate 16 random bytes and stores them in a byte array `nonce`.
1. Compute `l = m.lenght` 1. Compute `l = m.lenght`
1. Generate a random integer `x` between `0` and `170 - l` 1. Generate a random integer `x` between `0` and `170 - l`
1. Generate `x` random bytes and add them at end of `m`. 1. Generate `x` random bytes and add them at end of `m`.
...@@ -124,7 +141,7 @@ Let `t` the message type. ...@@ -124,7 +141,7 @@ Let `t` the message type.
Let `source` a base64 string read from comment field of a transaction document. Let `source` a base64 string read from comment field of a transaction document.
1. compute `b = base64.decode(source)` 1. Compute `b = base64.decode(source)`
1. Ensure that `b.length >= 3` 1. Ensure that `b.length >= 3`
1. Ensure that `b[0] = 0x27` and `b[1] = 0xb6` (magic value check) 1. Ensure that `b[0] = 0x27` and `b[1] = 0xb6` (magic value check)
1. Ensure that `b[2] = 0x01` (version check) 1. Ensure that `b[2] = 0x01` (version check)
...@@ -133,14 +150,29 @@ Let `source` a base64 string read from comment field of a transaction document. ...@@ -133,14 +150,29 @@ Let `source` a base64 string read from comment field of a transaction document.
1. compute `Sr'` and `Pi'`. 1. compute `Sr'` and `Pi'`.
1. Compute `R = crypto_box_beforenm(Sr', Pi')` 1. Compute `R = crypto_box_beforenm(Sr', Pi')`
1. compute `L = b.length - 20` 1. compute `L = b.length - 20`
1. Let `nonce` a bytes array from `b[4]` to `b[19]` 1. Read `nonce`: the bytes array from `b[4]` to `b[19]`
1. Generate symmetric encryption key `k = scrypt(R, salt: nonce, N: 1024, r: 8, p: 1, dkLen: L)` 1. Generate symmetric encryption key `k = scrypt(R, salt: nonce, N: 1024, r: 8, p: 1, dkLen: L)`
1. Let `encryptedMessage` a bytes array from `b[20]` to `b[b.length -1]` 1. Read `encryptedMessage`: the bytes array from `b[20]` to `b[b.length -1]`
1. compute `m = encryptedMessage ^ k` 1. Compute `m = encryptedMessage ^ k`
1. Read `l = m[0]` 1. Read `l = m[0]`
1. Ensure that `m.length > l` 1. Ensure that `m.length > l`
1. Interpret bytes `m[1]` to `m[l]` as an UTF8 string 1. Interpret bytes `m[1]` to `m[l]` as an UTF8 string
## Example
| Parameter | Value |
| --------- | ----- |
|Sender Public Key| EVfy1VoZwbuN7L69kYiHxeosJLh5azkHV8G6TaSLy94r |
|Sender Seed |0x0c6a15d0004d24a40f6503300d4971032fb057ff7dc229d651683b413c96a216 |
|Receiver Public Key| 8txjWNFZhMJbKPijvnFybeksN1QpKaKJrM4jW8HhnFsX |
|Receiver Seed| 0x214955b558c7793268589e557eda2ab69b5293b73d3907f82c82e12d69c47221 |
|Comment| My taylor is rich ? Isn't it ? Un été 42...|
|Nonce| 0x16740285721adeb10da04106c9eb9e34 |
|Extra Bytes| 0x17968f2f344679fe23ef483a53adcaa18ecd753036dd2cdab1 |
|Scrypt Password| 0xe63c31edb6e9e4fa04142cd73f30423aa7fb09e404fb60f154dcc913a7e3657c|
|XOR Key| 0x691114edf5f3da4f4c04b77842da44a4fa97cd59fee742c98244441897e91532de8bcf883d279d4cf4ab3715014cf417a309c979ee4058613668698e1f0df8edf4ac556868e64f|
|Encrypted comment| J7YBABZ0AoVyGt6xDaBBBsnrnjREXG3NgZKjIyN2lxEx+jbNmf/tZt6uMaelMGRx48kqEovl70uUU17l1J8FOy9i44EsJv0/l757jn5SOiPVrHYggZxjtUQ8/g|
[crypto_box_beforenm]: https://nacl.cr.yp.to/box.html [crypto_box_beforenm]: https://nacl.cr.yp.to/box.html
[Null character]: https://en.wikipedia.org/wiki/Null_character [Null character]: https://en.wikipedia.org/wiki/Null_character
[XOR cipher]: https://en.wikipedia.org/wiki/XOR_cipher [XOR cipher]: https://en.wikipedia.org/wiki/XOR_cipher
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment