-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ssh-cipher: add AAD support to ChaCha20Poly1305
#281
Conversation
I still have trouble wrapping my head around chacha poly for ssh. When I parse the packet the length of the payload should be encrypted, I don't know if the payload I'm trying to parse is long enough, or if it even includes the aad and I need to read the first block size worth of payload and bypass the aad check. All that to say, I will ask for some time to make a proper review, because I don't know how to review it yet :D EDIT: ha well, that's is all in |
Yeah, per
|
A test vector extracted from my working implementation (https://github.com/Noratrieb/fakessh/blob/f4ba9a2939104f24390ba168db44fc73c5df4999/ssh-transport/src/crypto.rs#L456) (printed with |
e8caa83
to
9c0bda9
Compare
From PROTOCOL.chacha20poly1305: Once the entire packet has been received, the MAC MUST be checked before decryption. A per-packet Poly1305 key is generated as described above and the MAC tag calculated using Poly1305 with this key over the ciphertext of the packet length and the payload together. This adds an `aad_len` parameter which decomposes the input buffer into a portion to be only authenticated (in packet encryption, this is used for a 4-byte encrypted length header), which comes prior to the portion to be encrypted. Ideally we could implement the `AeadInPlace` trait, however this approach has been used instead because the protocol uses unpadded Poly1305, where we don't support buffered input and it must be computed from a single contiguous slice using `Poly1305::compute_unpadded`. Closes #279
9c0bda9
to
d83646f
Compare
From PROTOCOL.chacha20poly1305:
This implements AAD which pads the input to the Poly1305 block size, inputting it first before the ciphertext.
It should be sufficient for SSH packet encryption use cases, although unfortunately we have no test vectors other than the ones in theTest vectors added.ssh-key
crate (which are unaffected by this change).Closes #279