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

cipher: stream cipher seeking by counter value #336

Closed
tarcieri opened this issue Oct 14, 2020 · 2 comments
Closed

cipher: stream cipher seeking by counter value #336

tarcieri opened this issue Oct 14, 2020 · 2 comments
Labels
cipher Block and stream cipher crate

Comments

@tarcieri
Copy link
Member

tarcieri commented Oct 14, 2020

Seeking by a counter value (e.g. NIST SP800-38D) is an exceedingly common operation, whether a stream cipher is a block cipher in counter mode (e.g. AES-CTR), or if a stream cipher uses an underlying block-based construction (ChaCha20, Salsa20). As it were, such seeking is necessary to implement AES-GCM, ChaCha20Poly1305, and XSalsa20Poly1305.

The current SyncStreamCipherSeek trait provides the ability to seek anywhere in the keystream at a byte-level granularity. This complicates the internal buffering logic by requiring stream ciphers to work at non-block-oriented offsets.

I think it'd be nice to have a trait that just accepts a counter value, rather than one which specifies a SeekNum-style byte offset. If we had such a trait, I think we could implement SyncStreamCipherSeek-like behavior in a single place, as opposed to the current state of affairs where internally the chacha20 and salsa20 crates contain copy-pasted code from ctr::Ctr128.

cc @newpavlov

@tarcieri tarcieri added stream-cipher cipher Block and stream cipher crate labels Oct 14, 2020
@tarcieri tarcieri changed the title stream-cipher: counter-based seeking cipher: stream cipher seeking by counter value Oct 15, 2020
@newpavlov
Copy link
Member

Yes, it seems worth looking into providing more fundamental non-buffering primitives, on top of which will be constructed convenient buffering ones using a generic wrapper similar to BlockBuffer. It should also help with composability (e.g. we can share buffer between MAC function and stream cipher).

@newpavlov
Copy link
Member

cipher v0.4 now exposes the StreamCipherSeekCore trait which should handle this issue.

dns2utf8 pushed a commit to dns2utf8/traits that referenced this issue Jan 24, 2023
I suspect that most users of this crate care about the low-level
`pbkdf2` API as opposed to the higher-level password hashing API which
implements the PHC string format.

The `simple` API pulls in quite a few dependencies (to the point I'm
encountering dependency conflicts).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cipher Block and stream cipher crate
Projects
None yet
Development

No branches or pull requests

2 participants