-
Notifications
You must be signed in to change notification settings - Fork 198
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
aead: API with separate buffers for input and output #1311
Comments
We could potentially add something like this, but I'll note the API surface is already pretty complicated. I'm not sure it makes sense to add these to |
I agree the current API is complicated but may I suggest to make it more complicated to possibly make it simpler:
|
Pretty much all of our AEADs impl The We don't really have a distinction of "implementer" versus "user" traits: each trait is independently useful to end users. Such a distinction exists in the |
Yes I understand the current design, I'm suggesting to fix its limitations, in particular the fact that blanket impls force extra copy when implemented and used interfaces differ. Here's a concrete example:
By dissociating implementer and user interfaces you provide as much choice to the user as possible, paying only the minimum interface mismatch cost. I can see how it may be more complicated by having much more traits, but the design is also easier to understand: if you're a user, just use the trait (possibly multiple) you want from those, if you're an implementer, just implement the trait (and only one) you want from those. No worries if that's too much complexity. I'm anyway currently adding the missing traits myself. It's just that it could be useful for others too. |
To back up, what you want isn't an in-place API, but one which has an immutable reference to the source and a mutable reference to the destination buffer. So, it doesn't make sense to put such methods on the So what you're asking for only makes sense as a new trait.
I don't think this scenario would happen. The blanket impl would exist for types which impl Note that What might make sense is adding methods to the |
Indeed, the naming is wrong. I called it like that because I also consider in-place the version of an API that takes an output buffer compared to one that allocates and returns a new buffer, because it essentially operates in-place instead of creating a new-place. But let's stick to the current naming which makes more sense when there's both an input and an output buffer.
Yes, that's also an option. But then, you put the weight to handle this impedance on the user. Because now users can't just use an in-place API and be portable over all implementations. They need somehow to check whether the implementation supports an in-place API and if not, use another API. This argument is symmetric, I used in-place, but the user should be able to use any API A regardless of whether the implementation implements A, B, or C, since they're all equivalent modulo possible copy and/or allocation.
Yes, I think any solution will be a breaking change. Only adding a new independent trait would not be a breaking change. That would not be the best user experience, but that would be fine for me. I'll implement my own impedance matching traits on top. |
...but you want to offer a trait specifically for implementations which don't offer an in-place API and require two separate and unaliased input and output buffers as opposed to being able to operate over the same buffer for input and output. If we offer such a trait, definitionally it will be for implementations which don't support in-place operation. Them's the brakes. The |
We have the UPD: I forgot about |
Adding |
Yes, the Just to make sure we understand ourselves correctly, let me try to illustrate the situation as I see it. I'll focus only on encryption and ignore the nonce and aad. I'll also abuse notations to mention the length. We have the following functions:
You cannot create a blanket impl topological order between those 6 equivalent functions. That's maybe where I'm wrong, so please provide such order if it exists. Here is my proof that there are no such order:
My suggestion is to duplicate those 6 functions (or equivalently traits) with one version for implementers only and one version for users only, and provide the blanket impls to connect all implementers to all users (this is not quadratic because there can be blanket impls among those traits that are used transitively and shared). That's essentially what I was saying in #1311 (comment). And again, I understand that it may be too much complexity and closing as Regarding |
Would it make sense to add the following methods to
AeadInPlace
(similarly forAeadMutInPlace
) with default implementations based on the existing methods?This would add support (without extra copies or allocation) for implementations that don't support aliasing input and output. They would implement the
_mut
version and use a copy to implement the_in_place
version using the_mut
version.The text was updated successfully, but these errors were encountered: