-
Notifications
You must be signed in to change notification settings - Fork 220
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
fix(dht): updates to message padding #4594
fix(dht): updates to message padding #4594
Conversation
Adds better length checks. Simplifies the padding algorithm and handles an edge case hitting a base length multiple.
1536a77
to
d8b4a6a
Compare
Manually tested the case where the plaintext message is too large for the length encoding. |
Very nice ! LGTM :) PS: the failing tests seem to be unrelated with the current code refactoring, and probably are due to some previous PR merge to development. |
Is it worth it (or even possible) to add the plaintext-is-too-long test in a way that won't horribly clog up the CI runners? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks looks good. Some fairly minor comments.
Description
PR 4362 mitigates a metadata leak whereby encrypted messages are the same length as plaintext messages due to the use of a stream cipher. This work adds more complete length checks, such that padding can fail. It also more efficiently handles the edge case where no padding is needed.
Motivation and Context
To avoid directly leaking the length of plaintext messages after stream cipher encryption, PR 4362 pads such messages to a multiple of a fixed base length after first prepending the original message length using a fixed encoding.
However, the following cases do not appear to be handled by the padding and unpadding code:
Further, in the case where the message length (after length prepending) is exactly a multiple of the base length, an entire base length of padding is unnecessarily applied.
This work addresses these issues. The padding process now checks that the plaintext message does not exceed the limit enforced by the length encoding; as a result, it can now return an error that propagates to the encryption function caller. The padding algorithm has been simplified and now handles the multiple-of-the-base-length edge case by correctly applying no padding. The unpadding process now checks that it can safely extract the message length, and checks that the ciphertext message is a multiple of the base length.
How Has This Been Tested?
No test has been added for the case where the message length exceeds the limit allowed by the encoding, as this would imply very high memory usage (or swapping) exceeding 4 GB. Existing tests pass. A new test exercises the other failure modes.