-
Notifications
You must be signed in to change notification settings - Fork 216
aead: add explicit nonce API #1818
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
Conversation
Building towards a full solution to #1666, this adds an initial API which supports explicit nonces, implemented as a prefix to the AEAD message. Putting the nonce in any other position than the message prefix doesn't make sense. Nothing else works that way. There are multiple possible permutations like putting the nonce between the ciphertext, or at the end, but nobody does that, and the best thing we can do for users is eliminate unnecessary choices.
Marked as draft for some initial bikeshedding, because it has no tests, and because the blanket impl of |
6c40df1
to
6798400
Compare
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.
This looks fine to me. But I am not quite sure about naming. i think it can confusing to have encrypt
and encrypt_with_explicit_nonce
with the exactly same API. It may be worth to somehow indicate what the methods include nonce into ciphertext.
Also encrypt_with_explicit_nonce
is implemented somewhat inefficiently. The ciphertext
allocation is not necessary, we could write directly into zero-initialized out
. But I guess we can leave it for a later PR.
It also may be worth to implement these methods generically over the Buffer
trait.
That's literally what |
I meant something like
|
The trait name can group logical functionality, like |
I also thought about making encrypt/decrypt methods generic over ciphertext layout. Something like
The trait name is not present where we use the methods unless you use the fully qualified syntax. In code we have just |
Reiterating this:
Oh god please no we don't need to support arbitrary permutations of orderings of the nonce, ciphertext, and tag. That is the canonical ordering used for explicit messages. Anything else is unnecessarily complex and foisting too much choice onto users. |
We always can keep the non-default layouts in the hazmat module or gate behind a crate feature. The point is to introduce a type parameter to change ciphertext layout instead of adding a bunch of new methods. |
Unnecessary complexity for complexity's sake is an antipattern. Let's just support the most commonly used pattern to make it easy for users. |
Are you absolutely sure that nonces are always prepended and that we will not have users asking us to add similar methods which append nonces (e.g. because it allows a more efficient implementation)? |
I have never seen a counterexample |
As a general comment, I think unnecessary choices in cryptographic APIs lead to confusion and incompatibilities, and even if you can find a counterexample, a nonce prefix is the overwhelming preference in other libraries I've seen. We should give users the most commonly used protocol, and if someone needs to support something weird like a postfix nonce, they can do it themselves. |
The name is still explicit (literally) and unambiguous in case, but the trait provides further clarity.
"explicit nonce" versus "included nonce" is just bikeshedding the name, and IMO "explicit nonce" is the name you'll find in the literature for a nonce concatenated with the ciphertext |
Fine, you can limit the layout types provided by
IIUC the name "explicit nonce" primarily comes from TLS. If you insist on this terminology, then I think we should rename the other methods to use "implict" for symmetry. |
The existing methods can be used for either purpose, so that doesn't make sense. |
Also I don't think we should add undue complexity to the existing interface just to accommodate nonce prefixes which are an added protocol on top of the existing methods |
(This, again, is a problem with trying to lump unrelated concepts/protocols into a single trait, which IMO is the source of confusion) |
I meant the existing |
This PR literally implements explicit nonces in terms of that API. Surely you'd agree that explicit nonces can't be implemented in terms of "implicit nonces"? The existing API leaves handling of nonces to the user. That doesn't de facto mean it's an "implicit nonce". That depends on the usage. |
Also regarding the name "explicit nonce", I'd say there's ample precedent for that term in the IETF/IRTF literature: |
This is an internal implementation detail. "Implicit" in this context means that we handle transfer of nonces outside of the ciphertext, Usually, it's a shared algorithm (e.g. counter), but it could be a separate channel as well. You could argue that the latter no longer can be called "implicit", but it's a debatable point. If your goal is to provide a high-level misuasable and convinient API, then wouldn't it be better for |
I'm going to close this. I don't think it makes sense to put these methods in the same trait as the other methods. It's an implementation of a concrete explicit nonce protocol, whereas the other methods are lower-level and protocol agnostic. I certainly don't think it makes any sense to go around labeling all of the methods with I also think it really doesn't make any sense to try to change the definitions of the existing trait methods to start operating on explicit nonces where they didn't before. I'm going to play around with this some more but implementing the protocol as a struct rather than a trait. That gives us a fresh method namespace where we can use names like |
As I wrote in my initial comment, I am fine with the added methods and don't have strong objections. But I have concerns about their relation to the I think we should answer the following questions:
|
Building towards a full solution to #1666, this adds an initial API which supports explicit nonces, implemented as a prefix to the AEAD message.
Putting the nonce in any other position than the message prefix doesn't make sense. Nothing else works that way. There are multiple possible permutations like putting the nonce between the ciphertext, or at the end, but nobody does that, and the best thing we can do for users is eliminate unnecessary choices.