Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

26/WAKU-PAYLOAD #413

Merged
merged 43 commits into from
Jul 7, 2021
Merged
Changes from 19 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9f22c22
26/WAKU-PAYLOAD Init with 7/WAKU-DATA
oskarth Jul 1, 2021
6c075b0
Import 6/WAKU1 payload encryption
oskarth Jul 1, 2021
1664e90
Clarify purpose and cryptographic primitives
oskarth Jul 1, 2021
2aa723a
Clarify Waku v1 vs Waku v2 usage
oskarth Jul 1, 2021
822dd54
fmt
oskarth Jul 2, 2021
24a7b9c
Add section on ECIES encryption
oskarth Jul 2, 2021
f1c4f0a
typo
oskarth Jul 2, 2021
8c75b10
credit
oskarth Jul 2, 2021
0fc0fe2
typos
oskarth Jul 2, 2021
6d6789b
Add design requirements
oskarth Jul 2, 2021
7842b63
tweaks
oskarth Jul 2, 2021
ee198af
move encryption details section
oskarth Jul 2, 2021
47782f5
tweak
oskarth Jul 2, 2021
10969ea
add references
oskarth Jul 2, 2021
9975710
fix salt field typo
oskarth Jul 2, 2021
939e2f1
design goals
oskarth Jul 2, 2021
48c2872
overhaul spec sec
oskarth Jul 2, 2021
754150e
updat references
oskarth Jul 2, 2021
136b7ba
remove scratch
oskarth Jul 2, 2021
36f42fe
Update content/docs/rfcs/26/README.md
oskarth Jul 5, 2021
96bfd33
Update content/docs/rfcs/26/README.md
oskarth Jul 5, 2021
a524081
Update content/docs/rfcs/26/README.md
oskarth Jul 5, 2021
0bb3d98
Update content/docs/rfcs/26/README.md
oskarth Jul 5, 2021
1ff0f01
Update content/docs/rfcs/26/README.md
oskarth Jul 5, 2021
a9bcd89
remove iv and tag from abnf
oskarth Jul 5, 2021
c204a6b
must to may encryption
oskarth Jul 5, 2021
37aa51a
typo
oskarth Jul 5, 2021
befd948
Update content/docs/rfcs/26/README.md
oskarth Jul 7, 2021
0ade60d
Update content/docs/rfcs/26/README.md
oskarth Jul 7, 2021
e7d7eb2
Update content/docs/rfcs/26/README.md
oskarth Jul 7, 2021
5050292
Update content/docs/rfcs/26/README.md
oskarth Jul 7, 2021
79745f3
Update content/docs/rfcs/26/README.md
oskarth Jul 7, 2021
2334f72
typo
oskarth Jul 7, 2021
3267e54
clarify
oskarth Jul 7, 2021
51f6ab8
clarify
oskarth Jul 7, 2021
80c00c4
restructure
oskarth Jul 7, 2021
1b91f02
tweak
oskarth Jul 7, 2021
ba496e1
Update content/docs/rfcs/26/README.md
oskarth Jul 7, 2021
5cc019f
Revert "Update content/docs/rfcs/26/README.md"
oskarth Jul 7, 2021
28ebeef
clarify field names
oskarth Jul 7, 2021
ad22cd9
add ethereum yellow paper
oskarth Jul 7, 2021
7202dbd
Add to menu
oskarth Jul 7, 2021
6b3d828
Merge branch 'master' into 26/WAKU-PAYLOAD
oskarth Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions content/docs/rfcs/26/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
slug: 26
title: 26/WAKU-PAYLOAD
name: Waku Message Payload Encryption
status: draft
editor: Oskar Thoren <[email protected]>
contributors:
---

This specification describes how Waku provides provides confidentiality, authenticity, and integrity, as well as some form unlinkability.
oskarth marked this conversation as resolved.
Show resolved Hide resolved
Specifically, it describes how encryption, decryption and signing works in [6/WAKU1](/spec/6) and in [10/WAKU2](/spec/10) with [14/WAKU-MESSAGE version 1](/spec/14/#version1).

This specification effectively replaces [7/WAKU-DATA](/spec/7) as well as [6/WAKU1 Payload encryption](/spec/6/#payload-encryption) but written in a way that is agnostic and self-contained for Waku v1 and Waku v2.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

Large sections of the specification originate from [EIP-627: Whisper spec](https://eips.ethereum.org/EIPS/eip-627) as well from [RLPx Transport Protocol spec (ECIES encryption)](https://github.com/ethereum/devp2p/blob/master/rlpx.md#ecies-encryption) with some modifications.

## Design requirements

- *Confidentiality*: The adversary should not be able to learn what data is being sent from one Waku node to one or several other Waku nodes.
- *Authenticity*: The adversary should not be able to cause Waku endpoint to accept data from any third party as though it came from the other endpoint.
- *Integrity*: The adversary should not be able to cause a Waku endpoint to accept data that has been tampered with.

Notable, *forward secrecy* is not provided for at this layer.
If this property is desired, a more fully featured secure communication protocol can be used on top, such as [Status 5/SECURE-TRANSPORT](https://specs.status.im/spec/5).

It also provides some form of *unlinkability* since:
- only participants who are able to decrypt a message can see its signature
- payload are padded to a fixed length
oskarth marked this conversation as resolved.
Show resolved Hide resolved

## Cryptographic primitives
oskarth marked this conversation as resolved.
Show resolved Hide resolved

- AES-256-GCM
oskarth marked this conversation as resolved.
Show resolved Hide resolved
- ECIES
- ECSDA
oskarth marked this conversation as resolved.
Show resolved Hide resolved
oskarth marked this conversation as resolved.
Show resolved Hide resolved
- KECCAK-256

ECIES is using the following cryptosystem:
- Curve: secp256k1
- KDF: NIST SP 800-56 Concatenation Key Derivation Function
oskarth marked this conversation as resolved.
Show resolved Hide resolved
- MAC: HMAC with SHA-256
- AES: AES-128-CTR

## Specification

For 6/WAKU1, the `data` field is used in the `waku envelope`, and the field MUST contain the encrypted payload.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

For 10/WAKU2, the `payload` field is used in `WakuMessage` and MUST contain the encrypted payload.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

The fields that are concatenated and encrypted as part of the field are:
oskarth marked this conversation as resolved.
Show resolved Hide resolved
- flags
- auxiliary field
oskarth marked this conversation as resolved.
Show resolved Hide resolved
- payload
- padding
- signature

### ABNF

Using [Augmented Backus-Naur form (ABNF)](https://tools.ietf.org/html/rfc5234) we have the following format:
oskarth marked this conversation as resolved.
Show resolved Hide resolved

```abnf
oskarth marked this conversation as resolved.
Show resolved Hide resolved
; 1 byte; first two bits contain the size of auxiliary field,
oskarth marked this conversation as resolved.
Show resolved Hide resolved
; third bit indicates whether the signature is present.
flags = 1OCTET

; contains the size of payload.
payload-length = 4*OCTET

; byte array of arbitrary size (may be zero).
payload = *OCTET

; byte array of arbitrary size (may be zero).
padding = *OCTET

; 65 bytes, if present.
signature = 65OCTET

; 12 bytes, if present (in case of symmetric encryption).
iv = 12OCTET
oskarth marked this conversation as resolved.
Show resolved Hide resolved

; 16 bytes, if present (in case of symmetric encryption).
tag = 16OCTET

data = flags auxiliary-field payload padding [signature]
oskarth marked this conversation as resolved.
Show resolved Hide resolved
```

### Asymmetric encryption
oskarth marked this conversation as resolved.
Show resolved Hide resolved

Asymmetric encryption uses the standard Elliptic Curve Integrated Encryption Scheme (ECIES) with SECP-256k1 public key.
For more details, see the section below on ECIES encryption.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

### Symmetric encryption

Symmetric encryption uses AES-256-GCM for [authenticated encryption](https://en.wikipedia.org/wiki/Authenticated_encryption), with a 16 byte authentication tag and a 12 byte IV (nonce).
oskarth marked this conversation as resolved.
Show resolved Hide resolved
The message authentication `tag` and initialization vector `iv` field MUST be appended to the resulting `ciphertext`, in that order.
kdeme marked this conversation as resolved.
Show resolved Hide resolved
Note that previous specifications and some implementations might refer to `iv` as `nonce` or `salt`.

### Signature

Those unable to decrypt the envelope data are also unable to access the signature.
The signature, if provided, is the ECDSA signature of the Keccak-256 hash of the unencrypted data using the secret key of the originator identity.
oskarth marked this conversation as resolved.
Show resolved Hide resolved
The signature is serialized as the concatenation of the `r`, `s` and `v` parameters of the SECP-256k1 ECDSA signature, in that order.
`r` and `s` MUST be big-endian encoded, fixed-width 256-bit unsigned.
oskarth marked this conversation as resolved.
Show resolved Hide resolved
`v` MUST be an 8-bit big-endian encoded, non-normalized and should be either 27 or 28.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

### Padding

The padding field is used to align data size, since data size alone might reveal important metainformation.
Padding can be arbitrary size.
However, it is recommended that the size of Data Field (excluding the IV) before encryption (i.e. plain text) SHOULD be factor of 256 bytes.
oskarth marked this conversation as resolved.
Show resolved Hide resolved
oskarth marked this conversation as resolved.
Show resolved Hide resolved

### ECIES encryption

oskarth marked this conversation as resolved.
Show resolved Hide resolved
This section originates from the [RLPx Transport Protocol spec](https://github.com/ethereum/devp2p/blob/master/rlpx.md#ecies-encryption) spec with minor modifications.

The cryptosystem used is:

- The elliptic curve secp256k1 with generator `G`.
- `KDF(k, len)`: the NIST SP 800-56 Concatenation Key Derivation Function.
- `MAC(k, m)`: HMAC using the SHA-256 hash function.
- `AES(k, iv, m)`: the AES-128 encryption function in CTR mode.

Special notation used: `X || Y` denotes concatenation of X and Y.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

Alice wants to send an encrypted message that can be decrypted by Bobs static private key `kB`. Alice knows about Bobs static public key `KB`.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

To encrypt the message `m`, Alice generates a random number `r` and corresponding elliptic curve public key `R = r * G` and computes the shared secret `S = Px` where `(Px, Py) = r * KB`.
She derives key material for encryption and authentication as `kE || kM = KDF(S, 32)` as well as a random initialization vector `iv`.
Alice sends the encrypted message `R || iv || c || d` where `c = AES(kE, iv , m)` and `d = MAC(sha256(kM), iv || c)` to Bob.

For Bob to decrypt the message `R || iv || c || d`, he derives the shared secret `S = Px` where `(Px, Py) = kB * R` as well as the encryption and authentication keys `kE || kM = KDF(S, 32)`.
Bob verifies the authenticity of the message by checking whether `d == MAC(sha256(kM), iv || c)` then obtains the plaintext as `m = AES(kE, iv || c)`.

### Decoding a message

In order to decode a message, a node SHOULD try to apply both symmetric and asymmetric decryption operations.
oskarth marked this conversation as resolved.
Show resolved Hide resolved

## References

1. [6/WAKU1](/spec/6)
2. [10/WAKU2](/spec/10)
3. [14/WAKU-MESSAGE version 1](/spec/14/#version1)
4. [7/WAKU-DATA](/spec/7)
5. [6/WAKU1 Payload encryption](/spec/6/#payload-encryption)
6. [EIP-627: Whisper spec](https://eips.ethereum.org/EIPS/eip-627)
7. [RLPx Transport Protocol spec (ECIES encryption)](https://github.com/ethereum/devp2p/blob/master/rlpx.md#ecies-encryption)
8. [Status 5/SECURE-TRANSPORT](https://specs.status.im/spec/5)
9. [Augmented Backus-Naur form (ABNF)](https://tools.ietf.org/html/rfc5234)
10. [authenticated encryption](https://en.wikipedia.org/wiki/Authenticated_encryption)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).