-
Notifications
You must be signed in to change notification settings - Fork 200
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
Add trait AeadInto so callers can provide separate input and output buffers #1663
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
I think a better path forward is to use |
It might make sense to change the existing detached APIs to use |
Having implemented parts of the Noise CipherState protocol using these crates, I don't see the issue here. Noise should work fine with in-place encryption. That said, I do think there would be value in exposing APIs based on |
To clarify -- are you proposing a backwards-incompatible change to the signature of I haven't yet had coffee, so take this with a grain of salt, but I believe merging the in-place and in-out APIs (in a way that would be ergonomic for developers who need either one) might be troublesome in Rust; I don't believe it's possible to actively use both a mutable and immutable reference to overlapping memory (at the same time) without some That said, I'm personally fine with looking into this; I just didn't want to destabilize your API out of the blue.
It probably would have been more accurate for me to phrase my last point as "an optimal, specification-compliant, and pedantic implementation of the Noise Protocol Framework" -- at least according to my own personal reading of the spec, which is obviously not the be-all, end-all of interpretations. Of course, from a cryptographic perspective, there's no meaningful difference between an encryption function which reuses one buffer versus one which uses separate buffers. |
Yes. We are in the process of preparing the next release cycle, so it's a good time to introduce it.
See the |
I've taken a closer look at That said -- if breaking API changes are on the table, perhaps we should rename Edit: Wow, that was a fast reply! :) |
Edit: sorry, that is to say, there are two sets of methods, and only the Separately I thought we split |
Can do. I haven't had much time to spare on this, but I've been in progress on an updated proposal based on the above conversation. I'm almost done; I've just been trying to provide a higher quality implementation for the One thing I'd like to ask: I found it quite surprising that there's no It appears that the primary purpose of The order (ciphertext then tag or tag then ciphertext) is already algorithm-dependent; it doesn't look like Would it not make more sense to simply accept an |
Every AEAD makes use of it via the default provided implementations of https://docs.rs/aead/0.5.2/src/aead/lib.rs.html#287 It's also used by the blanket impl of These are the primary user-facing APIs for these crates, so yes, they're very much used!
Actually, Someone using the current API doesn't have to worry about such details, because the current API abstracts over them, allowing truly generic usage over AEAD modes regardless of how they structure the AEAD message. Just accepting a slice as input means that the user needs to include additional space for the AEAD tag, and its position may vary depending on the algorithm. This means the end user needs to have to have some awareness of how the AEAD message is formatted when constructing the buffer, i.e. algorithm-specific details leak out, and it's just onerous.
|
After some rumination, I think I understand what you're trying to convey.
From that perspective, I can see how this would be very convenient in a trait that (for example) a TLS library would want to consume -- clearly, it should stay in! That said, if we're open to further API changes, it would be ideal if we could also make the "I have a simple From that perspective -- the one I was seeing from before the above realization -- it seems quite surprising that From the caller's perspective, the simplest option I could see would likely be to add a separate pair of methods (e.g. Alternatively, one could include an ergonomic route by which a |
If the We can potentially add some explicit methods that work directly on slices too but the Note that there are two cases for slice-based APIs to consider: in-place and working over separate input and output buffers. Also it would probably be good to open a new issue for this. |
And identical counterpart
AeadIntoMut
for completeness' sake.Resolves issue #1311.
Rationale
trait Aead
allocates a newVec
every time a message is encrypted or decrypted.trait AeadInPlace
forces the caller to use one buffer for input and output.It's not currently possible to write an optimal and specification-compliant implementation of the Noise Protocol Framework using either of the existing traits.