Skip to content
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

Consider adding an API that takes the nonce size and tag size as parameters #544

Open
d3lm opened this issue Jul 24, 2023 · 3 comments
Open

Comments

@d3lm
Copy link

d3lm commented Jul 24, 2023

We are building a Node.js runtime for the browser so you can run Node.js entirely in your browser without relying on cloud servers. That means we run arbitrary code and right now it's only possible to specify the nonce size and tag size statically via types so we are forced to always call from_slice(...). Ideally we can create it once and not rely on a match that matches nonce size and tag size, e.g.

 match nonce.len() {
   12 => match tag_size {
     12 => AesGcm::<Aes, U12, U12>::new_from_slice(key),
     ...
   },
   ...
 }

So it'd be nice if we could do from_slice(key, nonce_size, tag_size).

@tarcieri
Copy link
Member

tarcieri commented Jul 24, 2023

Alternatively an operation similar to encrypt_in_place_detached could accept an additional &mut [u8] slice to write the tag into, returning an error if its length isn't in the range 12..=16 (see #541 regarding lengths of 4 and 8, which require special care to support correctly).

I think that could be done as a completely additive change. I think it's otherwise nice to have monomorphized tag sizes for type safety reasons in every other use case than "I am implementing a dynamic API for a scripting language which needs to choose the tag size completely at runtime"

@d3lm
Copy link
Author

d3lm commented Jul 25, 2023

Hm but that means that the tag size still needs to be configured statically right?

@tarcieri
Copy link
Member

No, it would take a slice, and return an error if it wasn't a valid size

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

No branches or pull requests

3 participants
@tarcieri @d3lm and others