Uh oh!
There was an error while loading. Please reload this page.
Conversation
Uh oh!
There was an error while loading. Please reload this page.
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
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
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
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
#266)" This reverts commit ab1f278. The latest versions of `cbc` and `ctr` no longer impl `Clone` deliberately, so this can no longer be implemented in this manner: RustCrypto/block-modes#91 The cipher needs to be fully reinitialized from the original key instead.
This reverts commit ab1f278 (#266). The latest versions of `cbc` and `ctr` no longer impl `Clone` deliberately, so this can no longer be implemented in this manner: RustCrypto/block-modes#91 The cipher needs to be fully reinitialized from the original key instead.
…e" (#416) This reverts commit ab1f278 (#266). The latest versions of `cbc` and `ctr` no longer impl `Clone` deliberately, so this can no longer be implemented in this manner: RustCrypto/block-modes#91 The cipher needs to be fully reinitialized from the original key instead.
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
Most crates contain the following changelog: ### Removed - `std` feature ([#76]) - `Clone` impl ([#91]) ### Changed - Bump `cipher` from `0.4` to `0.5` ([#56]) - Edition changed to 2024 and MSRV bumped to 1.85 ([#76]) - Relax MSRV policy and allow MSRV bumps in patch releases [#56]: #56 [#76]: #76 [#91]: #91
Eugeny
commented
May 17, 2026
Could we at least get an |
Having looked at it more, instead of being a footgun the inability to "branch" off the cipher state is going to basically shoot any SSH stream implementation using RustCrypto right in the head 😓
|
tarcieri
commented
May 17, 2026
Perhaps an explicit API to get and resume states/positions? |
Eugeny
commented
May 17, 2026
I'm open to anything really - an opaque "checkpoint" type is useful if you want to obstruct the user from manipulating the state or for it to work with ciphers that do not have an "any value is valid" state like AES-Cxx, but in the end it does not matter much and could just be hidden behind a hazmat feature |
tarcieri
commented
May 17, 2026
Perhaps the |
Note that you can retrieve current IV using
It would be a bad fit since we generally do not implement it for block cipher states. |
@newpavlov that's what I ended up doing, but that leaks the implementation detail of IV being the "state" into the userspace. And ofc having to reconstruct the cipher on every turn, including cloning the IV |
tarcieri
commented
May 17, 2026
We could at least make an abstraction for it in |
newpavlov
commented
May 17, 2026
Could you link the relevant code? I guess we could add something like this: /// Call the closure with current mode state and reset the mode/// to the original state before returning from the method.fnpeek<T>(&mutself,f:implFnOnce(&mutSelf) -> T) -> T; |
newpavlov
commented
May 18, 2026
Your code does not look too terrible to me, the IV stuff is isolated to the linked module. I think it's fine to have some amount of inconvenience while dealing with a potentially dangerous stuff. Also note that you do not need to clone the cipher every time. You can create |
BTW if you only need to peek the first block, then you could just decrypt it and XOR the result with IV (retrieved from It also looks like you unnecessarily duplicate the cipher. IMO it would be better to store |
Eugeny
commented
May 19, 2026
Neat, I didn't know
I also need to support 3DES-CBC, so it's multiple blocks anyway - besides I precisely wanted to avoid reimplementing crypto primitives |
tarcieri
commented
May 19, 2026
I tried to add a RustCrypto/SSH@3283b7e#diff-95d2927818f6bc686a4400d3646948a0003eb90dcc87fa54abe148ed6b4db5edR179 Likewise there's not a way to access the inner cipher of I think what would probably be most helpful here is a way to set the IV as functionality analogous to "seeking" in a stream cipher. |
tarcieri
commented
May 19, 2026
@Eugeny separately I'd be curious if that kind of API would work for your use cases |
Eugeny
commented
May 19, 2026
Yup, I like it |
I meant to implement it as part of the
Yeah, some sort of But in the case of the provided example, I think that it's better to have |
As discussed in RustCrypto/block-modes#91
As discussed in RustCrypto/block-modes#91
As discussed in RustCrypto/block-modes#91
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
IvStatetrait).Previous discussion: rust-random/rand#1101
Note that we previously had people complaining about
Clone: #23