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

Support non-cloneable BlockCiphers #47

Closed
Dirbaio opened this issue Jun 15, 2020 · 3 comments · Fixed by RustCrypto/traits#210
Closed

Support non-cloneable BlockCiphers #47

Dirbaio opened this issue Jun 15, 2020 · 3 comments · Fixed by RustCrypto/traits#210
Assignees

Comments

@Dirbaio
Copy link

Dirbaio commented Jun 15, 2020

Currently the MACs that use block ciphers (CMAC, PMAC) require the BlockCipher in use to be Clone.

It seems to me that it should be possible to not require Clone. Instead, conditionally implement Clone for the Mac if the BlockCipher is Clone?

This would be a breaking change though. Generic code that needs cloning is now requiring just Mac, and it'll now have to require Mac + Clone

My use case is using a custom block cipher that contains &mut's inside, so it can't be cloned. (I know it's weird, it's a cipher that does very expensive calculations that sometimes can be cached so it has a mutable ref to a cache).

@tarcieri
Copy link
Member

tarcieri commented Jun 15, 2020

It might be possible to support a blanket impl of BlockCipher for reference types of BlockCipher, which in theory could eliminate the Clone bound by leveraging immutable borrows.

See @newpavlov's suggestion here:

RustCrypto/block-ciphers#132 (comment)

I wonder if we can add impl<T: BlockCipher> BlockCipher for &T, this could make it possible to instantiate a block mode using block cipher reference (although we would have to slightly change BlockCipher definition to accommodate for that).

@Dirbaio
Copy link
Author

Dirbaio commented Jun 16, 2020

That makes sense! I was looking for the possibility of using a &mut but a & would work too, I guess I can use interior mutability.

@tarcieri
Copy link
Member

tarcieri commented Jun 16, 2020

We also (very) recently added BlockCipherMut but aren't using it for anything yet.

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