Skip to content

Conversation

newpavlov
Copy link
Member

Cloning of a block mode state can be considered a footgun. If state has to be cloned for some reason, users should prefer passing key/IV instead (see the IvState trait).

Previous discussion: rust-random/rand#1101

Note that we previously had people complaining about Clone: #23

@newpavlov newpavlov requested a review from tarcieri September 10, 2025 00:22
@newpavlov newpavlov merged commit 0f92e05 into master Sep 10, 2025
58 checks passed
@newpavlov newpavlov deleted the rm_clone branch September 10, 2025 00:27
tarcieri added a commit to RustCrypto/stream-ciphers that referenced this pull request Sep 11, 2025
Allow cloning on a stream cipher or RNG is problematic because it
duplicates internal states, which can lead to keystream reuse / RNG
output duplication, which in cryptographic contexts can be catastrophic.

Instead, for things like tests ciphers can be initialized from the same
seed repeatedly, which is what this PR changes the e.g. `chacha20` tests
to do. This is a much more explicit way of deliberately duplicating
stream ciphers/RNGs for the purposes of testing.

See also:
- #220
- #461
- RustCrypto/block-modes/pull/91
- rust-random/rand#1101
tarcieri added a commit to RustCrypto/stream-ciphers that referenced this pull request Sep 11, 2025
Allow cloning on a stream cipher or RNG is problematic because it
duplicates internal states, which can lead to keystream reuse / RNG
output duplication, which in cryptographic contexts can be catastrophic.

Instead, for things like tests ciphers can be initialized from the same
seed repeatedly, which is what this PR changes the e.g. `chacha20` tests
to do. This is a much more explicit way of deliberately duplicating
stream ciphers/RNGs for the purposes of testing.

See also:
- #220
- #461
- RustCrypto/block-modes/pull/91
- rust-random/rand#1101
tarcieri added a commit to RustCrypto/stream-ciphers that referenced this pull request Sep 11, 2025
Allow cloning on a stream cipher or RNG is problematic because it
duplicates internal states, which can lead to keystream reuse / RNG
output duplication, which in cryptographic contexts can be catastrophic.

Instead, for things like tests ciphers can be initialized from the same
seed repeatedly, which is what this PR changes the e.g. `chacha20` tests
to do. This is a much more explicit way of deliberately duplicating
stream ciphers/RNGs for the purposes of testing.

See also:
- #220
- #461
- RustCrypto/block-modes/pull/91
- rust-random/rand#1101
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