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: add encrypt/decrypt-only block cipher traits #352

Merged
merged 3 commits into from
Nov 24, 2020

Conversation

tarcieri
Copy link
Member

@tarcieri tarcieri commented Nov 1, 2020

Closes #349

Adds BlockEncrypt and BlockDecrypt traits which can be used in cases where e.g. only the encryption portion of a block cipher is used, as in CTR mode.

This PR does not otherwise attempt to add things like a blanket impl.

@tarcieri
Copy link
Member Author

tarcieri commented Nov 1, 2020

Note: I used the new suggested method names here: *_block, *_par_blocks, *_blocks.

Perhaps it would make more sense to leave them the same for consistency for now, then change them all in the next breaking release.

cipher/src/block.rs Outdated Show resolved Hide resolved
cipher/src/block.rs Outdated Show resolved Hide resolved
@tarcieri tarcieri force-pushed the cipher/encrypt-and-decrypt-only-block-cipher-traits branch from 0bf6fd0 to 59097cc Compare November 1, 2020 16:30
@tarcieri
Copy link
Member Author

tarcieri commented Nov 1, 2020

After a few attempts at eliminating the redundancy, I think it might make more sense to transform the BlockCipher trait (via a breaking change) into a marker trait for the case where a type impls both Encrypt and Decrypt with compatible BlockSize/ParBlocks.

Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't Encrypt/Decrypt too generic? It could be worth to use something like BlockEncrypt instead of block::Encrypt. Such naming would also allow us to simplify the crate structure by removing stream and block modules.

cipher/src/block.rs Outdated Show resolved Hide resolved
@tarcieri
Copy link
Member Author

tarcieri commented Nov 1, 2020

It could be worth to use something like BlockEncrypt instead of block::Encrypt. Such naming would also allow us to simplify the crate structure by removing stream and block modules.

That's a potential alternative, yes. I think it makes sense for the code to still be factored into two modules, but we could re-export everything at the toplevel rather than using modules.

@tarcieri
Copy link
Member Author

tarcieri commented Nov 1, 2020

In 5096a41 I renamed the traits to BlockEncrypt and BlockDecrypt, and added a BlockSizeMarker trait for carrying the BlockSize associated type/constant.

@newpavlov
Copy link
Member

I think it makes sense for the code to still be factored into two modules

I agree, I meant how API will look on outside.

@tarcieri
Copy link
Member Author

tarcieri commented Nov 1, 2020

@newpavlov does this look ok now, or would you rather hold off until cipher v0.3?

@newpavlov
Copy link
Member

I think it will be better to release these changes in v0.3.

Closes #349

Adds `Encrypt` and `Decrypt` traits which can be used in cases where
e.g. only the encryption portion of a block cipher is used, as in
CTR mode.

This PR does not otherwise attempt to add things like a blanket impl.
Adds a single trait for carrying the `BlockSize` associated
type/constant.

Prefixes `Encrypt` and `Decrypt` traits with `Block*`, i.e.
`BlockEncrypt` and `BlockDecrypt`.
@tarcieri tarcieri force-pushed the cipher/encrypt-and-decrypt-only-block-cipher-traits branch from 5096a41 to 2c61ca2 Compare November 23, 2020 15:34
@tarcieri
Copy link
Member Author

tarcieri commented Nov 23, 2020

@newpavlov I've gone ahead and made the discussed breaking changes (targeting cipher v0.3) in 2c61ca2, including splitting BlockCipherMut into BlockEncryptMut and BlockDecryptMut which require the given type impls BlockCipher.

This had the added benefit of eliminating the need for a stream::FromBlockCipherMut trait.

@tarcieri tarcieri force-pushed the cipher/encrypt-and-decrypt-only-block-cipher-traits branch from 2c61ca2 to 72593c0 Compare November 24, 2020 14:23
@tarcieri tarcieri merged commit 590f545 into master Nov 24, 2020
@tarcieri tarcieri deleted the cipher/encrypt-and-decrypt-only-block-cipher-traits branch November 24, 2020 14:28
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 24, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 24, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 24, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 25, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
tarcieri added a commit to RustCrypto/block-ciphers that referenced this pull request Nov 25, 2020
Splits the `BlockCipher` impl into the `BlockEncrypt` and `BlockDecrypt`
traits added in RustCrypto/traits#352.
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.

cipher: traits for encrypt-only (and decrypt-only) block ciphers?
2 participants