This specification effectively replaces 7/WAKU-DATA as well as 6/WAKU1 Payload encryption but written in a way that is agnostic and self-contained for Waku v1 and Waku v2.
Large sections of the specification originate from EIP-627: Whisper spec as well from RLPx Transport Protocol spec (ECIES encryption) with some modifications.">
This specification effectively replaces 7/WAKU-DATA as well as 6/WAKU1 Payload encryption but written in a way that is agnostic and self-contained for Waku v1 and Waku v2.
Large sections of the specification originate from EIP-627: Whisper spec as well from RLPx Transport Protocol spec (ECIES encryption) with some modifications." />
<li>Editor: Oskar Thoren <ahref="mailto:oskar@status.im">oskar@status.im</a></li>
</ul><p>This specification describes how Waku provides confidentiality, authenticity, and integrity, as well as some form of unlinkability.
Specifically, it describes how encryption, decryption and signing works in <ahref="/spec/6">6/WAKU1</a> and in <ahref="/spec/10">10/WAKU2</a> with <ahref="/spec/14/#version1">14/WAKU-MESSAGE version 1</a>.</p>
<p>This specification effectively replaces <ahref="/spec/7">7/WAKU-DATA</a> as well as <ahref="/spec/6/#payload-encryption">6/WAKU1 Payload encryption</a> but written in a way that is agnostic and self-contained for Waku v1 and Waku v2.</p>
<p>Large sections of the specification originate from <ahref="https://eips.ethereum.org/EIPS/eip-627">EIP-627: Whisper spec</a> as well from <ahref="https://github.com/ethereum/devp2p/blob/master/rlpx.md#ecies-encryption">RLPx Transport Protocol spec (ECIES encryption)</a> with some modifications.</p>
<h2id="design-requirements">
Design requirements
<aclass="anchor"href="#design-requirements">#</a>
</h2>
<ul>
<li><em>Confidentiality</em>: The adversary should not be able to learn what data is being sent from one Waku node to one or several other Waku nodes.</li>
<li><em>Authenticity</em>: 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.</li>
<li><em>Integrity</em>: The adversary should not be able to cause a Waku endpoint to accept data that has been tampered with.</li>
</ul>
<p>Notable, <em>forward secrecy</em> 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 <ahref="https://specs.status.im/spec/5">Status 5/SECURE-TRANSPORT</a>.</p>
<p>It also provides some form of <em>unlinkability</em> since:</p>
<ul>
<li>only participants who are able to decrypt a message can see its signature</li>
<divclass="highlight"><pretabindex="0"style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><codeclass="language-abnf"data-lang="abnf"><spanstyle="display:flex;"><span><spanstyle="color:#75715e">; 1 byte; first two bits contain the size of payload-length field,</span>
</span></span><spanstyle="display:flex;"><span><spanstyle="color:#75715e">; third bit indicates whether the signature is present.</span>
<p>Those unable to decrypt the payload/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.
The signature is serialized as the concatenation of the <code>r</code>, <code>s</code> and <code>v</code> parameters of the SECP-256k1 ECDSA signature, in that order.
<code>r</code> and <code>s</code> MUST be big-endian encoded, fixed-width 256-bit unsigned.
<code>v</code> MUST be an 8-bit big-endian encoded, non-normalized and should be either 27 or 28.</p>
<p>See <ahref="https://ethereum.github.io/yellowpaper/paper.pdf">Ethereum “Yellow paper”: Appendix F Signing transactions</a> for more information on signature generation, parameters and public key recovery.</p>
<h3id="encryption">
Encryption
<aclass="anchor"href="#encryption">#</a>
</h3>
<h4id="symmetric">
Symmetric
<aclass="anchor"href="#symmetric">#</a>
</h4>
<p>Symmetric encryption uses AES-256-GCM for <ahref="https://en.wikipedia.org/wiki/Authenticated_encryption">authenticated encryption</a>.
The output of encryption is of the form (<code>ciphertext</code>, <code>tag</code>, <code>iv</code>) where <code>ciphertext</code> is the encrypted message, <code>tag</code> is a 16 byte message authentication tag and <code>iv</code> is a 12 byte initialization vector (nonce).
The message authentication <code>tag</code> and initialization vector <code>iv</code> field MUST be appended to the resulting <code>ciphertext</code>, in that order.
Note that previous specifications and some implementations might refer to <code>iv</code> as <code>nonce</code> or <code>salt</code>.</p>
<h4id="asymmetric">
Asymmetric
<aclass="anchor"href="#asymmetric">#</a>
</h4>
<p>Asymmetric encryption uses the standard Elliptic Curve Integrated Encryption Scheme (ECIES) with SECP-256k1 public key.</p>
<h4id="ecies">
ECIES
<aclass="anchor"href="#ecies">#</a>
</h4>
<p>This section originates from the <ahref="https://github.com/ethereum/devp2p/blob/master/rlpx.md#ecies-encryption">RLPx Transport Protocol spec</a> spec with minor modifications.</p>
<p>The cryptosystem used is:</p>
<ul>
<li>The elliptic curve secp256k1 with generator <code>G</code>.</li>
<li><code>KDF(k, len)</code>: the NIST SP 800-56 Concatenation Key Derivation Function.</li>
<li><code>MAC(k, m)</code>: HMAC using the SHA-256 hash function.</li>
<li><code>AES(k, iv, m)</code>: the AES-128 encryption function in CTR mode.</li>
</ul>
<p>Special notation used: <code>X || Y</code> denotes concatenation of <code>X</code> and <code>Y</code>.</p>
<p>Alice wants to send an encrypted message that can be decrypted by Bob’s static private key <code>kB</code>. Alice knows about Bobs static public key <code>KB</code>.</p>
<p>To encrypt the message <code>m</code>, Alice generates a random number <code>r</code> and corresponding elliptic curve public key <code>R = r * G</code> and computes the shared secret <code>S = Px</code> where <code>(Px, Py) = r * KB</code>.
She derives key material for encryption and authentication as <code>kE || kM = KDF(S, 32)</code> as well as a random initialization vector <code>iv</code>.
Alice sends the encrypted message <code>R || iv || c || d</code> where <code>c = AES(kE, iv , m)</code> and <code>d = MAC(sha256(kM), iv || c)</code> to Bob.</p>
<p>For Bob to decrypt the message <code>R || iv || c || d</code>, he derives the shared secret <code>S = Px</code> where <code>(Px, Py) = kB * R</code> as well as the encryption and authentication keys <code>kE || kM = KDF(S, 32)</code>.
Bob verifies the authenticity of the message by checking whether <code>d == MAC(sha256(kM), iv || c)</code> then obtains the plaintext as <code>m = AES(kE, iv || c)</code>.</p>
<h3id="padding">
Padding
<aclass="anchor"href="#padding">#</a>
</h3>
<p>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 and tag) before encryption (i.e. plain text) SHOULD be a multiple of 256 bytes.</p>
<h3id="decoding-a-message">
Decoding a message
<aclass="anchor"href="#decoding-a-message">#</a>
</h3>
<p>In order to decode a message, a node SHOULD try to apply both symmetric and asymmetric decryption operations.
This is because the type of encryption is not included in the message.</p>
<h2id="references">
References
<aclass="anchor"href="#references">#</a>
</h2>
<ol>
<li><ahref="/spec/6">6/WAKU1</a></li>
<li><ahref="/spec/10">10/WAKU2</a></li>
<li><ahref="/spec/14/#version1">14/WAKU-MESSAGE version 1</a></li>