-
Notifications
You must be signed in to change notification settings - Fork 212
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
cipher: parallel in-place encrypt/decrypt with offset #764
Comments
`aes-siv` and `xsalsa20poly1305` use a prepended authentication tag, which means during in-place encryption/decryption, they need the message shifted by the tag size. It would be nice if this could happen during encryption/decryption: https://github.com/RustCrypto/block-ciphers/issues/59 ...but barring that, using `copy_within` (which performs a `memmove` behind the scenes) should be the fastest available option. This commit replaces a previous `for` loop which performed this copy with `copy_within`. Note that `copy_within` is MSRV 1.37+, so this bumps the project MSRV up by a single version (from 1.36).
@tarcieri |
I'd say it's no big deal if we don't address this. There are two AEAD modes in our current portfolio that could benefit: If it were more than these two I'd be a bit more concerned. Both of them are effectively obsoleted by |
This is a request for the
aes
crate specifically, but ideally it would work for anyBlockCipher
.AES-SIV is a bit unique in that it prepends the authentication tag, rather than using a postfix tag like practically every other AEAD mode.
Ideally it would be nice to support an offset parameter when encrypting (as a counter mode cipher, that's all AES-SIV cares about, but it seems like supporting a decryption offset would be nice for symmetry if nothing else).
For the AES-SIV case specifically, it's a 1-block offset, that is to say, when encrypting the ciphertext is written with an offset of the block size (16-bytes) forward from the original start of the buffer. I understand there are some other use cases for an offset API which need to be finer grained than that (i.e. byte-level), such as parsing multiple AEAD messages in the same buffer as part of some framed packet protocol, but I'm not the one to ask about those.
Something which makes things a bit trickier is AES-SIV, as a counter mode cipher, uses the AES encryption block function to decrypt as well, and needs a "negative" offset in that case, decrypting a ciphertext which begins 1-block into the buffer, and then writing the resulting plaintext out at the beginning of the buffer.
I suppose this can be modeled by taking an
isize
as a parameter, checking its sign, and using that to determine if the offset is relative to the input or the output. Not sure that's the greatest API, but it would get the job done.The text was updated successfully, but these errors were encountered: