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

cbc: tweak code to help with codegen #15

Merged
merged 2 commits into from Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cbc/CHANGELOG.md
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion 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"
Expand Down
26 changes: 15 additions & 11 deletions cbc/src/decrypt.rs
Expand Up @@ -170,22 +170,26 @@ where
{
#[inline(always)]
fn proc_block(&mut self, mut block: InOut<'_, '_, Block<Self>>) {
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<Self>>) {
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();
}
}
5 changes: 3 additions & 2 deletions cbc/src/encrypt.rs
Expand Up @@ -173,7 +173,8 @@ where
fn proc_block(&mut self, mut block: InOut<'_, '_, Block<Self>>) {
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;
}
}
2 changes: 1 addition & 1 deletion cbc/src/lib.rs
Expand Up @@ -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))]
Expand Down