Skip to content

aead: rework traits API#2427

Open
newpavlov wants to merge 20 commits into
masterfrom
aead/minimize
Open

aead: rework traits API#2427
newpavlov wants to merge 20 commits into
masterfrom
aead/minimize

Conversation

@newpavlov
Copy link
Copy Markdown
Member

@newpavlov newpavlov commented May 25, 2026

TODO:

  • Update changelog.
  • Update docs.
  • Test new methods.
  • Migrate implementation crates.
  • Variable tag size support in into/within methods.

Unresolved questions:

  • Solution for potential incorrect reordering of arguments (nonce, aad, plaintext/ciphertext) with the same type (&[u8]).

@newpavlov newpavlov requested a review from tarcieri May 25, 2026 17:09
Comment thread aead/src/lib.rs Outdated
Comment thread aead/src/high_aead.rs Outdated
@newpavlov newpavlov changed the title aead: minimize API surface aead: minimize API surface and add support for variable size nonces May 29, 2026
@newpavlov

This comment was marked as outdated.

@newpavlov newpavlov changed the title aead: minimize API surface and add support for variable size nonces aead: rework traits API May 29, 2026
Comment thread aead/src/tag_pos.rs Outdated
&self,
nonce: &[u8],
aad: &[u8],
ciphertext: &[u8],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 3 arguments with the same type may cause bugs, so it may be worth to use Payload here as well.

Comment thread aead/src/high_aead.rs Outdated
Comment thread aead/src/lib.rs Outdated
Comment thread aead/src/tag_pos.rs Outdated
@tarcieri
Copy link
Copy Markdown
Member

Overall this doesn't feel like an improvement to me. Several things have changed but I don't think they've changed in ways that make more sense.

@newpavlov
Copy link
Copy Markdown
Member Author

newpavlov commented May 31, 2026

IMO variable nonce support, merging AeadCore and AeadInOut, significantly reducing number of crate features, and making Aead properly dyn-compatible (and potentially implementable by IO-based tokens) make a fair amount of sense.

Comment thread aead/src/utils.rs
};

let buf = InOutBuf::new(plaintext, ct_dst)
.expect("`plaintext` and `ct_dst` always have the same length");
Copy link
Copy Markdown
Member Author

@newpavlov newpavlov Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace it with .map_err(|_| Error) to remove #[allow(clippy::unwrap_in_result)]?

Comment thread aead/src/aead.rs
///
/// # Errors
/// AEAD algorithm implementations may return an error if the plaintext or AAD are too long.
fn encrypt_into_vec(&self, nonce: &[u8], aad: &[u8], plaintext: &[u8]) -> Result<Vec<u8>>;
Copy link
Copy Markdown
Member Author

@newpavlov newpavlov Jun 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the Payload type for now. I think we either need a more general solution which would help with other methods as well (e.g. Nonce, Aad, Plaintext, etc. wrappers), or we could just tolerate the potential incorrect reordering of arguments, which hopefully is somewhat unlikely in modern conditions (IDEs and stuff).

Comment thread aead/src/lib.rs
) -> Result<()>;
aad: &[u8],
plaintext: &[u8],
allocate: impl FnOnce(usize) -> B,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle potential fallibility here and in extend/truncate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants