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

blake2: add Cargo feature to optimize for code size. #440

Merged
merged 1 commit into from Dec 16, 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
1 change: 1 addition & 0 deletions blake2/Cargo.toml
Expand Up @@ -25,3 +25,4 @@ reset = [] # Enable reset functionality
simd = []
simd_opt = ["simd"]
simd_asm = ["simd_opt"]
size_opt = [] # Optimize for code size. Removes some `inline(always)`
8 changes: 4 additions & 4 deletions blake2/src/macros.rs
Expand Up @@ -107,29 +107,29 @@ macro_rules! blake2_impl {
fn compress(&mut self, block: &Block<Self>, f0: $word, f1: $word) {
use $crate::consts::SIGMA;

#[inline(always)]
#[cfg_attr(not(feature = "size_opt"), inline(always))]
fn quarter_round(v: &mut [$vec; 4], rd: u32, rb: u32, m: $vec) {
v[0] = v[0].wrapping_add(v[1]).wrapping_add(m.from_le());
v[3] = (v[3] ^ v[0]).rotate_right_const(rd);
v[2] = v[2].wrapping_add(v[3]);
v[1] = (v[1] ^ v[2]).rotate_right_const(rb);
}

#[inline(always)]
#[cfg_attr(not(feature = "size_opt"), inline(always))]
fn shuffle(v: &mut [$vec; 4]) {
v[1] = v[1].shuffle_left_1();
v[2] = v[2].shuffle_left_2();
v[3] = v[3].shuffle_left_3();
}

#[inline(always)]
#[cfg_attr(not(feature = "size_opt"), inline(always))]
fn unshuffle(v: &mut [$vec; 4]) {
v[1] = v[1].shuffle_right_1();
v[2] = v[2].shuffle_right_2();
v[3] = v[3].shuffle_right_3();
}

#[inline(always)]
#[cfg_attr(not(feature = "size_opt"), inline(always))]
fn round(v: &mut [$vec; 4], m: &[$word; 16], s: &[usize; 16]) {
quarter_round(v, $R1, $R2, $vec::gather(m, s[0], s[2], s[4], s[6]));
quarter_round(v, $R3, $R4, $vec::gather(m, s[1], s[3], s[5], s[7]));
Expand Down