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

Unify buffering logic between chacha20, salsa20, and ctr #95

Closed
tarcieri opened this issue Jan 17, 2020 · 5 comments · Fixed by #276
Closed

Unify buffering logic between chacha20, salsa20, and ctr #95

tarcieri opened this issue Jan 17, 2020 · 5 comments · Fixed by #276

Comments

@tarcieri
Copy link
Member

All three of these crates use highly similar (copypasta) buffering logic:

Original ctr code:

Derived chacha20 and salsa20 code:

The main problem is the ctr is presently specialized to Ctr128 and intended to operate in conjunction with a block cipher, whereas it'd be nice if ChaCha20 and Salsa20 took an integer (32-bit and 64-bit respectively) used to compute the block, but reused the same buffering logic as Ctr128.

ChaCha20 could also benefit from parallel block computation via its AVX2 backend.

@tarcieri
Copy link
Member Author

I guess I'll note one of the main motivations for copying the buffering logic into the chacha20 crate was to make it easier to experiment with different APIs for the block function with the goal of further optimizations.

It'd be good to further optimize chacha20 first before attempting to abstract the buffering logic.

@newpavlov
Copy link
Member

It may be also worth to unify with the rand_core::block code. I think ideally we should remove it from rand_core and have a single crate which will be reused for both RNGs and stream ciphers.

cc @dhardy

@dhardy
Copy link
Contributor

dhardy commented Jan 20, 2020

I see two different APIs: one with try_apply_keystream and the other with next_u32 / u64 / try_fill_bytes. Is it really worth trying to unify these?

@newpavlov
Copy link
Member

For RNGs we may use bit-level counters, so unification probably will not worth the trouble.

@tarcieri
Copy link
Member Author

See also: RustCrypto/traits#336

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 a pull request may close this issue.

3 participants