<div>Greetings, I hope this is the right place to ask Noise implementation questions.<br></div><div><br></div><div>I am working on a project that uses Noise. We want to:<br></div><div> 1. Exchange payloads during handshaking (i.e. use the payload fields in WriteMessage/ReadMessage),<br></div> 2. Ensure that all transmitted bytes are indistinguishable from random noise, and<br><div><div> 3. Have variable-length payloads.<br></div><div><br></div></div><div>And #3  is where the problem comes in, because it seems to me that the spec indicates that everything in the 'payload' field will be passed to a single call of the EncryptAndHash/DecryptAndHash functions. This appears to require the caller to know the length of the payload in advance to know when they've got the whole ciphertext.<br></div><div><br></div><div>Below is a possible workaround that is a deviation from the spec. Here is what it looks on the write side:<br></div><div><br></div><div>---begin pseudocode---<br></div><div>Let:<br></div><div>  payload be a variable-length byte sequence<br></div><div>  zerolen be a zero-length byte sequence<br></div><div><br></div><div>// encrypt a blank, sort of like in REKEY()<br></div><div>lengthObfuscator = EncryptAndHash(zerolen)<br></div><div><br></div><div>// calculate what the ciphertext length will be for our plaintext payload<br></div><div>ctLength = calculateCiphertextLength( len(payload) )<br></div><div><br></div><div>// xor the first two bytes of the ciphertext with the length<br></div><div>obfuscatedLength = ctLength ^ (lengthObfuscator[0] << 8 | lengthObfuscator[1])<br></div><div><br></div><div>// mix the obfuscated length into the hash, since it will be sent on the wire<br></div><div>MixHash(obfuscatedLength)<br></div><div><br></div><div>// cat the two together to get a modified payload<br></div><div>modifiedPayload = obfuscatedLength || EncryptAndHash(payload)<br></div><div><br></div><div>// the modified payload is what is actually sent on the wire at the end of a message pattern<br></div><div>transmit(modifiedPayload)<br></div><div>---end pseudocode---<br></div><div><br></div><div class="protonmail_signature_block protonmail_signature_block-empty"><div class="protonmail_signature_block-user protonmail_signature_block-empty"><br></div><div class="protonmail_signature_block-proton protonmail_signature_block-empty"><br></div></div><div>This is a deviation from the specification, because we have 1) a two-byte field that is NOT passed to DecryptAndHash by the reader, and 2) an extra call to EncryptAndHash by both parties that does not appear in the spec at all.<br></div><div><br></div><div>My questions are:<br></div><div><br></div><div>1. Is there an established way to do variable-length payloads during handshaking in Noise that I can use instead?<br></div><div><div>2. If there is not, does this approach make sense, and would it be wrong to claim that we are using Noise if this approach is used?<br></div><div><br></div></div><div>Thanks,<br></div><div>Jonas<br></div>