From 5781d3f8d8667426fedc21d74f45f92b371bce2c Mon Sep 17 00:00:00 2001 From: Artyom Pavlov Date: Thu, 24 Mar 2022 13:39:45 +0000 Subject: [PATCH] cbc: tweak code to help with codegen (#15) --- Cargo.lock | 18 +++++++++--------- cbc/CHANGELOG.md | 6 ++++++ cbc/Cargo.toml | 2 +- cbc/src/decrypt.rs | 26 +++++++++++++++----------- cbc/src/encrypt.rs | 5 +++-- cbc/src/lib.rs | 2 +- 6 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f925a1..3b6fd98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,16 +21,16 @@ checksum = "847495c209977a90e8aad588b959d0ca9f5dc228096d29a6bd3defd53f35eaec" [[package]] name = "block-padding" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5808df4b2412175c4db3afb115c83d8d0cd26ca4f30a042026cddef8580e526a" +checksum = "0a90ec2df9600c28a01c56c4784c9207a96d2451833aeceb8cc97e4c9548bb78" dependencies = [ "generic-array", ] [[package]] name = "cbc" -version = "0.1.1" +version = "0.1.2" dependencies = [ "aes", "cipher", @@ -75,9 +75,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" dependencies = [ "libc", ] @@ -149,9 +149,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.119" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" [[package]] name = "magma" @@ -194,6 +194,6 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "zeroize" -version = "1.5.2" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c88870063c39ee00ec285a2f8d6a966e5b6fb2becc4e8dac77ed0d370ed6006" +checksum = "7eb5728b8afd3f280a869ce1d4c554ffaed35f45c231fc41bfbd0381bef50317" diff --git a/cbc/CHANGELOG.md b/cbc/CHANGELOG.md index 2535672..2a55e5a 100644 --- a/cbc/CHANGELOG.md +++ b/cbc/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.1.2 (2022-03-24) +### Changed +- Minor code tweaks to help compiler with codegen ([#15]) + +[#15]: https://github.com/RustCrypto/block-modes/pull/15 + ## 0.1.1 (2022-02-17) ### Fixed - Minimal versions build ([#9]) diff --git a/cbc/Cargo.toml b/cbc/Cargo.toml index 31f5f00..493c38e 100644 --- a/cbc/Cargo.toml +++ b/cbc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cbc" -version = "0.1.1" # Also update html_root_url in lib.rs when bumping this +version = "0.1.2" # Also update html_root_url in lib.rs when bumping this description = "Cipher Block Chaining (CBC) block cipher mode of operation" authors = ["RustCrypto Developers"] license = "MIT OR Apache-2.0" diff --git a/cbc/src/decrypt.rs b/cbc/src/decrypt.rs index b3fe6a5..4d1635e 100644 --- a/cbc/src/decrypt.rs +++ b/cbc/src/decrypt.rs @@ -170,22 +170,26 @@ where { #[inline(always)] fn proc_block(&mut self, mut block: InOut<'_, '_, Block>) { - let enc_block = block.clone_in(); - self.backend.proc_block(block.reborrow()); - xor(block.get_out(), self.iv); - *self.iv = enc_block; + let in_block = block.clone_in(); + let mut t = block.clone_in(); + self.backend.proc_block((&mut t).into()); + xor(&mut t, self.iv); + *block.get_out() = t; + *self.iv = in_block; } #[inline(always)] fn proc_par_blocks(&mut self, mut blocks: InOut<'_, '_, ParBlocks>) { - let t = blocks.clone_in(); - self.backend.proc_par_blocks(blocks.reborrow()); - let out = blocks.get_out(); - let n = out.len(); - xor(&mut out[0], self.iv); + let in_blocks = blocks.clone_in(); + let mut t = blocks.clone_in(); + + self.backend.proc_par_blocks((&mut t).into()); + let n = t.len(); + xor(&mut t[0], self.iv); for i in 1..n { - xor(&mut out[i], &t[i - 1]) + xor(&mut t[i], &in_blocks[i - 1]) } - *self.iv = t[n - 1].clone(); + *blocks.get_out() = t; + *self.iv = in_blocks[n - 1].clone(); } } diff --git a/cbc/src/encrypt.rs b/cbc/src/encrypt.rs index cb19070..50284fb 100644 --- a/cbc/src/encrypt.rs +++ b/cbc/src/encrypt.rs @@ -173,7 +173,8 @@ where fn proc_block(&mut self, mut block: InOut<'_, '_, Block>) { let mut t = block.clone_in(); xor(&mut t, self.iv); - self.backend.proc_block((&t, block.get_out()).into()); - *self.iv = block.get_out().clone(); + self.backend.proc_block((&mut t).into()); + *self.iv = t.clone(); + *block.get_out() = t; } } diff --git a/cbc/src/lib.rs b/cbc/src/lib.rs index a6d4171..d5b6cb4 100644 --- a/cbc/src/lib.rs +++ b/cbc/src/lib.rs @@ -90,7 +90,7 @@ #![doc( html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg", html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg", - html_root_url = "https://docs.rs/cbc/0.1.1" + html_root_url = "https://docs.rs/cbc/0.1.2" )] #![forbid(unsafe_code)] #![cfg_attr(docsrs, feature(doc_cfg))]