diff --git a/rfc/0017_transaction_comment_encryption.md b/rfc/0017_transaction_comment_encryption.md new file mode 100644 index 0000000000000000000000000000000000000000..d57d9d91794c504ff8024d9d89c9ed5e703dad77 --- /dev/null +++ b/rfc/0017_transaction_comment_encryption.md @@ -0,0 +1,62 @@ +# RFC 17: Transaction Comment Encryption + +Alice wants to send a transaction to bob with an encrypted comment. + +Let `Sa` the private key of Alice and `Pa` its associated public key. +Let `Sb` the private key of Bob and `Pb` its associated public key. + +## generate symetric encryption key + +We use nacl function [crypto_box_beforenm]. Then use scrypt with a random nonce. + +Let `R = crypto_box_beforenm(Sa, Pb) = crypto_box_beforenm(Sb, Pa)`. + +Let `n` be a random nonce of 12 bytes. + +The symmetric encryption key `k` is obtained as follows: + +`k = scrypt(R, SHA256(n))` + +With following parameters for scrypt: + +```txt +N = 4096 +r = 16 +p = 1 +dkLen = message length +``` + +## encrypt zith XOR cipher + +Encrypt bit per bit with XOR cipher. + +## Serialize encrypted message with meta data + +| Prefix | Message type | Message length | Nonce | Encrypted message | Padding | +|:-------:|:------------:|:--------------:|:--------:|:-----------------:|:--------------------------:| +| 2 bytes | 1 byte | 1 byte | 12 bytes | Any bytes | `Message length % 4` bytes | + +The padding is used so that the quantity of bytes to be serialized is always a multiple of 4. This is necessary for the encoding in base z85. + +### Prefix + +A constant value that indicates the type of format. For the present format defined in this RFC, the prefix is `0x0100`. A possible future new format should choose a different prefix. This prefix can also be incremented for a future version of the present format. + +### Message type + +| Code | Significance | +|:----:|:--------------------------------:| +| 0x00 | Write by a human for a human | +| 0x01 | Write by a human for a machine | +| 0x10 | Write by a machine for a human | +| 0x11 | Write by a machine for a machine | + +## Encodinq in transaction document + +Encrypted message in encoded in [base z85] in transaction comment directly. + +DUBP protocol accept all [base z85] characters except `$`. We replace `$` by `_`. + +[base z85]: https://rfc.zeromq.org/spec/32/ +[crypto_box_beforenm]: https://nacl.cr.yp.to/box.html +[XOR cipher]: https://en.wikipedia.org/wiki/XOR_cipher