Skip to content

switch the BLAKE2 implementation to blake2b_simd/blake2s_simd #88

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/blake2.yml
Original file line number Diff line number Diff line change
@@ -53,15 +53,3 @@ jobs:
override: true
- run: cargo test --no-default-features
- run: cargo test
simd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: cargo test --features simd
- run: cargo test --features simd_opt
- run: cargo test --features simd_asm
44 changes: 43 additions & 1 deletion Cargo.lock

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

7 changes: 3 additions & 4 deletions blake2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ keywords = ["crypto", "blake2", "hash", "digest"]
categories = ["cryptography", "no-std"]

[dependencies]
blake2b_simd = { version = "0.5.10", default-features = false }
blake2s_simd = { version = "0.5.10", default-features = false }
digest = "0.9"
crypto-mac = "0.8"
opaque-debug = "0.3"
@@ -23,7 +25,4 @@ hex-literal = "0.2"

[features]
default = ["std"]
std = ["digest/std", "crypto-mac/std"]
simd = []
simd_opt = ["simd"]
simd_asm = ["simd_opt"]
std = ["digest/std", "crypto-mac/std", "blake2b_simd/std", "blake2s_simd/std"]
4 changes: 4 additions & 0 deletions blake2/benches/blake2bp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![no_std]
#![feature(test)]

digest::bench!(blake2::Blake2bp);
4 changes: 4 additions & 0 deletions blake2/benches/blake2sp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![no_std]
#![feature(test)]

digest::bench!(blake2::Blake2sp);
44 changes: 0 additions & 44 deletions blake2/src/as_bytes.rs

This file was deleted.

323 changes: 45 additions & 278 deletions blake2/src/blake2.rs

Large diffs are not rendered by default.

44 changes: 35 additions & 9 deletions blake2/src/blake2b.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
use crate::consts::BLAKE2B_IV;
use digest::generic_array::typenum::{U128, U64};

blake2_impl!(
VarBlake2b,
Blake2b,
u64,
u64x4,
U64,
blake2b_simd::State,
blake2b_simd::Params,
U128,
32,
24,
16,
63,
BLAKE2B_IV,
U64,
U64,
"Blake2b instance with a variable output.",
"Blake2b instance with a fixed output.",
);

impl VarBlake2b {
/// Creates a new hashing context with the full set of sequential-mode parameters.
pub fn with_params(key: &[u8], salt: &[u8], persona: &[u8], output_size: usize) -> Self {
let mut upstream_params = blake2b_simd::Params::new();
upstream_params
.key(key)
.salt(salt)
.personal(persona)
.hash_length(output_size);
let upstream_state = upstream_params.to_state();
Self {
upstream_params,
upstream_state,
output_size,
}
}
}

impl Blake2b {
/// Creates a new hashing context with the full set of sequential-mode parameters.
pub fn with_params(key: &[u8], salt: &[u8], persona: &[u8]) -> Self {
let mut upstream_params = blake2b_simd::Params::new();
upstream_params.key(key).salt(salt).personal(persona);
let upstream_state = upstream_params.to_state();
Self {
upstream_params,
upstream_state,
}
}
}
13 changes: 13 additions & 0 deletions blake2/src/blake2bp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use digest::generic_array::typenum::{U128, U64};

blake2_impl!(
VarBlake2bp,
Blake2bp,
blake2b_simd::blake2bp::State,
blake2b_simd::blake2bp::Params,
U128,
U64,
U64,
"Blake2bp instance with a variable output.",
"Blake2bp instance with a fixed output.",
);
44 changes: 35 additions & 9 deletions blake2/src/blake2s.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
use crate::consts::BLAKE2S_IV;
use digest::generic_array::typenum::{U32, U64};

blake2_impl!(
VarBlake2s,
Blake2s,
u32,
u32x4,
U32,
blake2s_simd::State,
blake2s_simd::Params,
U64,
16,
12,
8,
7,
BLAKE2S_IV,
U32,
U32,
"Blake2s instance with a variable output.",
"Blake2s instance with a fixed output.",
);

impl VarBlake2s {
/// Creates a new hashing context with the full set of sequential-mode parameters.
pub fn with_params(key: &[u8], salt: &[u8], persona: &[u8], output_size: usize) -> Self {
let mut upstream_params = blake2s_simd::Params::new();
upstream_params
.key(key)
.salt(salt)
.personal(persona)
.hash_length(output_size);
let upstream_state = upstream_params.to_state();
Self {
upstream_params,
upstream_state,
output_size,
}
}
}

impl Blake2s {
/// Creates a new hashing context with the full set of sequential-mode parameters.
pub fn with_params(key: &[u8], salt: &[u8], persona: &[u8]) -> Self {
let mut upstream_params = blake2s_simd::Params::new();
upstream_params.key(key).salt(salt).personal(persona);
let upstream_state = upstream_params.to_state();
Self {
upstream_params,
upstream_state,
}
}
}
13 changes: 13 additions & 0 deletions blake2/src/blake2sp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use digest::generic_array::typenum::{U32, U64};

blake2_impl!(
VarBlake2sp,
Blake2sp,
blake2s_simd::blake2sp::State,
blake2s_simd::blake2sp::Params,
U64,
U32,
U32,
"Blake2sp instance with a variable output.",
"Blake2sp instance with a fixed output.",
);
47 changes: 0 additions & 47 deletions blake2/src/consts.rs

This file was deleted.

11 changes: 4 additions & 7 deletions blake2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -84,25 +84,22 @@
#![no_std]
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
#![warn(missing_docs, rust_2018_idioms)]
#![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))]
#![cfg_attr(feature = "simd_asm", feature(asm))]

#[cfg(feature = "std")]
extern crate std;

mod as_bytes;
mod consts;

mod simd;

#[macro_use]
mod blake2;

mod blake2b;
mod blake2bp;
mod blake2s;
mod blake2sp;

pub use crypto_mac;
pub use digest::{self, Digest};

pub use crate::blake2b::{Blake2b, VarBlake2b};
pub use crate::blake2bp::{Blake2bp, VarBlake2bp};
pub use crate::blake2s::{Blake2s, VarBlake2s};
pub use crate::blake2sp::{Blake2sp, VarBlake2sp};
138 changes: 0 additions & 138 deletions blake2/src/simd.rs

This file was deleted.

51 changes: 0 additions & 51 deletions blake2/src/simd/simd_opt.rs

This file was deleted.

67 changes: 0 additions & 67 deletions blake2/src/simd/simd_opt/u32x4.rs

This file was deleted.

140 changes: 0 additions & 140 deletions blake2/src/simd/simd_opt/u64x4.rs

This file was deleted.

22 changes: 0 additions & 22 deletions blake2/src/simd/simdint.rs

This file was deleted.

103 changes: 0 additions & 103 deletions blake2/src/simd/simdop.rs

This file was deleted.

77 changes: 0 additions & 77 deletions blake2/src/simd/simdty.rs

This file was deleted.