From f40e69880966707cbea4d8cb804474a2ad67d9e9 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Wed, 30 Dec 2020 06:50:00 -0800 Subject: [PATCH] cipher: block cipher trait blanket impls for refs (#441) Previously `cipher` contained blanket impls of block cipher traits for reference types, which was leveraged in e.g. `aes-gcm` and `aes-gcm-siv`. However, somewhere in the course of refactoring they were removed. This commit adds them back. --- cipher/src/block.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/cipher/src/block.rs b/cipher/src/block.rs index 4e08dc259..8643fcad9 100644 --- a/cipher/src/block.rs +++ b/cipher/src/block.rs @@ -156,3 +156,44 @@ impl BlockDecryptMut for Alg { self.decrypt_block(block); } } + +// Impls of block cipher traits for reference types + +impl BlockCipher for &Alg { + type BlockSize = Alg::BlockSize; + type ParBlocks = Alg::ParBlocks; +} + +impl BlockEncrypt for &Alg { + #[inline] + fn encrypt_block(&self, block: &mut Block) { + Alg::encrypt_block(self, block); + } + + #[inline] + fn encrypt_par_blocks(&self, blocks: &mut ParBlocks) { + Alg::encrypt_par_blocks(self, blocks); + } + + #[inline] + fn encrypt_blocks(&self, blocks: &mut [Block]) { + Alg::encrypt_blocks(self, blocks); + } +} + +impl BlockDecrypt for &Alg { + #[inline] + fn decrypt_block(&self, block: &mut Block) { + Alg::decrypt_block(self, block); + } + + #[inline] + fn decrypt_par_blocks(&self, blocks: &mut ParBlocks) { + Alg::decrypt_par_blocks(self, blocks); + } + + #[inline] + fn decrypt_blocks(&self, blocks: &mut [Block]) { + Alg::decrypt_blocks(self, blocks); + } +}