From 41f37bf6d0c60c1eb2f53e1b940c4826d24a7848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Fri, 10 Jul 2026 17:25:08 +0300 Subject: [PATCH] blake2: remove SIMD support --- blake2/Cargo.toml | 3 - blake2/src/as_bytes.rs | 32 ----- blake2/src/consts.rs | 18 --- blake2/src/lib.rs | 8 +- blake2/src/macros.rs | 5 +- blake2/src/simd.rs | 196 ++++++++++++++++++------------ blake2/src/simd/simd_opt.rs | 52 -------- blake2/src/simd/simd_opt/u32x4.rs | 69 ----------- blake2/src/simd/simd_opt/u64x4.rs | 143 ---------------------- blake2/src/simd/simdint.rs | 22 ---- blake2/src/simd/simdop.rs | 103 ---------------- blake2/src/simd/simdty.rs | 92 -------------- 12 files changed, 125 insertions(+), 618 deletions(-) delete mode 100644 blake2/src/as_bytes.rs delete mode 100644 blake2/src/simd/simd_opt.rs delete mode 100644 blake2/src/simd/simd_opt/u32x4.rs delete mode 100644 blake2/src/simd/simd_opt/u64x4.rs delete mode 100644 blake2/src/simd/simdint.rs delete mode 100644 blake2/src/simd/simdop.rs delete mode 100644 blake2/src/simd/simdty.rs diff --git a/blake2/Cargo.toml b/blake2/Cargo.toml index b6e1bdd6f..6a816f244 100644 --- a/blake2/Cargo.toml +++ b/blake2/Cargo.toml @@ -24,9 +24,6 @@ default = ["alloc"] alloc = ["digest/alloc"] zeroize = ["digest/zeroize"] reset = [] # Enable reset functionality -#simd = [] -#simd_opt = ["simd"] -#simd_asm = ["simd_opt"] size_opt = [] # Optimize for code size. Removes some `inline(always)` [package.metadata.docs.rs] diff --git a/blake2/src/as_bytes.rs b/blake2/src/as_bytes.rs deleted file mode 100644 index c78913697..000000000 --- a/blake2/src/as_bytes.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -use core::mem; -use core::slice; - -#[allow(clippy::missing_safety_doc)] -pub(crate) unsafe trait Safe {} - -pub(crate) trait AsBytes { - fn as_bytes(&self) -> &[u8]; -} - -impl AsBytes for [T] { - #[inline] - fn as_bytes(&self) -> &[u8] { - unsafe { slice::from_raw_parts(self.as_ptr() as *const u8, mem::size_of_val(self)) } - } -} - -unsafe impl Safe for u8 {} -unsafe impl Safe for u16 {} -unsafe impl Safe for u32 {} -unsafe impl Safe for u64 {} -unsafe impl Safe for i8 {} -unsafe impl Safe for i16 {} -unsafe impl Safe for i32 {} -unsafe impl Safe for i64 {} diff --git a/blake2/src/consts.rs b/blake2/src/consts.rs index a77590b30..55cf8b475 100644 --- a/blake2/src/consts.rs +++ b/blake2/src/consts.rs @@ -1,5 +1,3 @@ -#![allow(clippy::unreadable_literal)] - pub(crate) static SIGMA: [[usize; 16]; 12] = [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3], @@ -26,22 +24,6 @@ pub(crate) static BLAKE2B_IV: [u64; 8] = [ 0x5be0cd19137e2179, ]; -/* -pub const BLAKE2B_BLOCKBYTES : usize = 128; -pub const BLAKE2B_OUTBYTES : usize = 64; -pub const BLAKE2B_KEYBYTES : usize = 64; -pub const BLAKE2B_SALTBYTES : usize = 16; -pub const BLAKE2B_PERSONALBYTES : usize = 16; -*/ - pub(crate) static BLAKE2S_IV: [u32; 8] = [ 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19, ]; - -/* -pub const BLAKE2S_BLOCKBYTES : usize = 64; -pub const BLAKE2S_OUTBYTES : usize = 32; -pub const BLAKE2S_KEYBYTES : usize = 32; -pub const BLAKE2S_SALTBYTES : usize = 8; -pub const BLAKE2S_PERSONALBYTES : usize = 8; -*/ diff --git a/blake2/src/lib.rs b/blake2/src/lib.rs index 308d4d5f0..d2ce5524f 100644 --- a/blake2/src/lib.rs +++ b/blake2/src/lib.rs @@ -5,10 +5,6 @@ html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" )] #![cfg_attr(docsrs, feature(doc_cfg))] -#![allow(unexpected_cfgs)] // `simd` feature is broken -#![warn(missing_docs, unreachable_pub)] -#![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))] -#![cfg_attr(feature = "simd", allow(incomplete_features))] pub use digest::{self, Digest}; @@ -31,7 +27,6 @@ use digest::{FixedOutputReset, Reset}; #[cfg(feature = "zeroize")] use digest::zeroize::{Zeroize, ZeroizeOnDrop}; -mod as_bytes; mod consts; mod simd; @@ -39,9 +34,8 @@ mod simd; #[macro_use] mod macros; -use as_bytes::AsBytes; use consts::{BLAKE2B_IV, BLAKE2S_IV}; -use simd::{Vector4, u32x4, u64x4}; +use simd::{u32x4, u64x4}; blake2_impl!( Blake2bVarCore, diff --git a/blake2/src/macros.rs b/blake2/src/macros.rs index a5d0af50c..ea0f26532 100644 --- a/blake2/src/macros.rs +++ b/blake2/src/macros.rs @@ -98,8 +98,9 @@ macro_rules! blake2_impl { out: &mut Output, ) { self.compress(final_block, !0, flag); - let buf = [self.h[0].to_le(), self.h[1].to_le()]; - out.copy_from_slice(buf.as_bytes()) + let n = size_of::<$vec>(); + out[..n].copy_from_slice(self.h[0].to_le().as_bytes()); + out[n..].copy_from_slice(self.h[1].to_le().as_bytes()); } fn compress(&mut self, block: &Block, f0: $word, f1: $word) { diff --git a/blake2/src/simd.rs b/blake2/src/simd.rs index 4e90ca45f..f68f02aa6 100644 --- a/blake2/src/simd.rs +++ b/blake2/src/simd.rs @@ -1,63 +1,46 @@ -// Copyright 2015 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -mod simd_opt; -mod simdint; -mod simdop; -mod simdty; - -pub(crate) use self::simdty::{u32x4, u64x4}; - -pub(crate) trait Vector4: Copy { - fn gather(src: &[T], i0: usize, i1: usize, i2: usize, i3: usize) -> Self; - - #[allow(clippy::wrong_self_convention)] - fn from_le(self) -> Self; - fn to_le(self) -> Self; - - fn wrapping_add(self, rhs: Self) -> Self; - - fn rotate_right_const(self, n: u32) -> Self; - - fn shuffle_left_1(self) -> Self; - fn shuffle_left_2(self) -> Self; - fn shuffle_left_3(self) -> Self; - - #[inline(always)] - fn shuffle_right_1(self) -> Self { - self.shuffle_left_3() - } - #[inline(always)] - fn shuffle_right_2(self) -> Self { - self.shuffle_left_2() - } - #[inline(always)] - fn shuffle_right_3(self) -> Self { - self.shuffle_left_1() - } -} +use core::ops::{Add, BitXor, Shl, Shr}; + +#[cfg(feature = "zeroize")] +use digest::zeroize::Zeroize; macro_rules! impl_vector4 { ($vec:ident, $word:ident) => { - impl Vector4<$word> for $vec { + #[derive(Clone, Copy, Debug)] + #[repr(C)] + pub(crate) struct $vec( + pub(crate) $word, + pub(crate) $word, + pub(crate) $word, + pub(crate) $word, + ); + + impl $vec { + #[inline(always)] + pub(crate) fn new(e0: $word, e1: $word, e2: $word, e3: $word) -> Self { + Self(e0, e1, e2, e3) + } + #[inline(always)] - fn gather(src: &[$word], i0: usize, i1: usize, i2: usize, i3: usize) -> Self { + pub(crate) fn gather( + src: &[$word], + i0: usize, + i1: usize, + i2: usize, + i3: usize, + ) -> Self { $vec::new(src[i0], src[i1], src[i2], src[i3]) } #[cfg(target_endian = "little")] #[inline(always)] - fn from_le(self) -> Self { + #[allow(clippy::wrong_self_convention)] + pub(crate) fn from_le(self) -> Self { self } #[cfg(not(target_endian = "little"))] #[inline(always)] - fn from_le(self) -> Self { + pub(crate) fn from_le(self) -> Self { $vec::new( $word::from_le(self.0), $word::from_le(self.1), @@ -68,13 +51,13 @@ macro_rules! impl_vector4 { #[cfg(target_endian = "little")] #[inline(always)] - fn to_le(self) -> Self { + pub(crate) fn to_le(self) -> Self { self } #[cfg(not(target_endian = "little"))] #[inline(always)] - fn to_le(self) -> Self { + pub(crate) fn to_le(self) -> Self { $vec::new( self.0.to_le(), self.1.to_le(), @@ -84,55 +67,118 @@ macro_rules! impl_vector4 { } #[inline(always)] - fn wrapping_add(self, rhs: Self) -> Self { + pub(crate) fn wrapping_add(self, rhs: Self) -> Self { self + rhs } #[inline(always)] - fn rotate_right_const(self, n: u32) -> Self { - simd_opt::$vec::rotate_right_const(self, n) + pub(crate) fn rotate_right_const(self, n: u32) -> Self { + $vec::new( + self.0.rotate_right(n), + self.1.rotate_right(n), + self.2.rotate_right(n), + self.3.rotate_right(n), + ) } - #[cfg(feature = "simd")] #[inline(always)] - fn shuffle_left_1(self) -> Self { - use crate::simd::simdint::simd_shuffle4; - const IDX: [u32; 4] = [1, 2, 3, 0]; - unsafe { simd_shuffle4(self, self, IDX) } + pub(crate) fn shuffle_left_1(self) -> Self { + $vec::new(self.1, self.2, self.3, self.0) } - #[cfg(not(feature = "simd"))] #[inline(always)] - fn shuffle_left_1(self) -> Self { - $vec::new(self.1, self.2, self.3, self.0) + pub(crate) fn shuffle_left_2(self) -> Self { + $vec::new(self.2, self.3, self.0, self.1) } - #[cfg(feature = "simd")] #[inline(always)] - fn shuffle_left_2(self) -> Self { - use crate::simd::simdint::simd_shuffle4; - const IDX: [u32; 4] = [2, 3, 0, 1]; - unsafe { simd_shuffle4(self, self, IDX) } + pub(crate) fn shuffle_left_3(self) -> Self { + $vec::new(self.3, self.0, self.1, self.2) } - #[cfg(not(feature = "simd"))] #[inline(always)] - fn shuffle_left_2(self) -> Self { - $vec::new(self.2, self.3, self.0, self.1) + pub(crate) fn shuffle_right_1(self) -> Self { + self.shuffle_left_3() + } + #[inline(always)] + pub(crate) fn shuffle_right_2(self) -> Self { + self.shuffle_left_2() + } + #[inline(always)] + pub(crate) fn shuffle_right_3(self) -> Self { + self.shuffle_left_1() } - #[cfg(feature = "simd")] #[inline(always)] - fn shuffle_left_3(self) -> Self { - use crate::simd::simdint::simd_shuffle4; - const IDX: [u32; 4] = [3, 0, 1, 2]; - unsafe { simd_shuffle4(self, self, IDX) } + pub(crate) fn as_bytes(&self) -> &[u8] { + let p = self as *const Self as *const u8; + unsafe { core::slice::from_raw_parts(p, core::mem::size_of::()) } } + } + + impl Add for $vec { + type Output = Self; - #[cfg(not(feature = "simd"))] #[inline(always)] - fn shuffle_left_3(self) -> Self { - $vec::new(self.3, self.0, self.1, self.2) + fn add(self, rhs: Self) -> Self::Output { + $vec::new( + self.0.wrapping_add(rhs.0), + self.1.wrapping_add(rhs.1), + self.2.wrapping_add(rhs.2), + self.3.wrapping_add(rhs.3), + ) + } + } + + impl BitXor for $vec { + type Output = Self; + + #[inline(always)] + fn bitxor(self, rhs: Self) -> Self::Output { + $vec::new( + self.0 ^ rhs.0, + self.1 ^ rhs.1, + self.2 ^ rhs.2, + self.3 ^ rhs.3, + ) + } + } + + impl Shl<$vec> for $vec { + type Output = Self; + + #[inline(always)] + fn shl(self, rhs: Self) -> Self::Output { + $vec::new( + self.0 << rhs.0, + self.1 << rhs.1, + self.2 << rhs.2, + self.3 << rhs.3, + ) + } + } + + impl Shr<$vec> for $vec { + type Output = Self; + + #[inline(always)] + fn shr(self, rhs: Self) -> Self::Output { + $vec::new( + self.0 >> rhs.0, + self.1 >> rhs.1, + self.2 >> rhs.2, + self.3 >> rhs.3, + ) + } + } + + #[cfg(feature = "zeroize")] + impl Zeroize for $vec { + fn zeroize(&mut self) { + self.0.zeroize(); + self.1.zeroize(); + self.2.zeroize(); + self.3.zeroize(); } } }; diff --git a/blake2/src/simd/simd_opt.rs b/blake2/src/simd/simd_opt.rs deleted file mode 100644 index 3d5186167..000000000 --- a/blake2/src/simd/simd_opt.rs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2015 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -#[allow(unused_macros)] -#[cfg(feature = "simd")] -macro_rules! transmute_shuffle { - ($tmp:ident, $shuffle:ident, $vec:expr, $idx_n:expr, $idx:expr) => { - unsafe { - use crate::simd::simdint::$shuffle; - use crate::simd::simdty::$tmp; - use core::mem::transmute; - - const IDX: [u32; $idx_n] = $idx; - let tmp_i: $tmp = transmute($vec); - let tmp_o: $tmp = $shuffle(tmp_i, tmp_i, IDX); - transmute(tmp_o) - } - }; -} - -#[cfg(feature = "simd")] -pub mod u32x4; -#[cfg(feature = "simd")] -pub mod u64x4; - -#[cfg(not(feature = "simd"))] -macro_rules! simd_opt { - ($vec:ident) => { - pub(crate) mod $vec { - use crate::simd::simdty::$vec; - - #[inline(always)] - pub(crate) fn rotate_right_const(vec: $vec, n: u32) -> $vec { - $vec::new( - vec.0.rotate_right(n), - vec.1.rotate_right(n), - vec.2.rotate_right(n), - vec.3.rotate_right(n), - ) - } - } - }; -} - -#[cfg(not(feature = "simd"))] -simd_opt!(u32x4); -#[cfg(not(feature = "simd"))] -simd_opt!(u64x4); diff --git a/blake2/src/simd/simd_opt/u32x4.rs b/blake2/src/simd/simd_opt/u32x4.rs deleted file mode 100644 index 7190d96f7..000000000 --- a/blake2/src/simd/simd_opt/u32x4.rs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2015 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -use crate::simd::simdty::u32x4; - -#[cfg(feature = "simd_opt")] -#[inline(always)] -pub fn rotate_right_const(vec: u32x4, n: u32) -> u32x4 { - match n { - 16 => rotate_right_16(vec), - 8 => rotate_right_8(vec), - _ => rotate_right_any(vec, n), - } -} - -#[cfg(not(feature = "simd_opt"))] -#[inline(always)] -pub fn rotate_right_const(vec: u32x4, n: u32) -> u32x4 { - rotate_right_any(vec, n) -} - -#[inline(always)] -fn rotate_right_any(vec: u32x4, n: u32) -> u32x4 { - let r = n; - let l = 32 - r; - - (vec >> u32x4::new(r, r, r, r)) ^ (vec << u32x4::new(l, l, l, l)) -} - -#[cfg(feature = "simd_opt")] -#[inline(always)] -fn rotate_right_16(vec: u32x4) -> u32x4 { - if cfg!(target_feature = "ssse3") { - // pshufb (SSSE3) / vpshufb (AVX2) - transmute_shuffle!( - u8x16, - simd_shuffle16, - vec, - 16, - [2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13] - ) - } else if cfg!(any(target_feature = "sse2", target_feature = "neon")) { - // pshuflw+pshufhw (SSE2) / vrev (NEON) - transmute_shuffle!(u16x8, simd_shuffle8, vec, 8, [1, 0, 3, 2, 5, 4, 7, 6]) - } else { - rotate_right_any(vec, 16) - } -} - -#[cfg(feature = "simd_opt")] -#[inline(always)] -fn rotate_right_8(vec: u32x4) -> u32x4 { - if cfg!(target_feature = "ssse3") { - // pshufb (SSSE3) / vpshufb (AVX2) - transmute_shuffle!( - u8x16, - simd_shuffle16, - vec, - 16, - [1, 2, 3, 0, 5, 6, 7, 4, 9, 10, 11, 8, 13, 14, 15, 12] - ) - } else { - rotate_right_any(vec, 8) - } -} diff --git a/blake2/src/simd/simd_opt/u64x4.rs b/blake2/src/simd/simd_opt/u64x4.rs deleted file mode 100644 index 350f94587..000000000 --- a/blake2/src/simd/simd_opt/u64x4.rs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2015 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -use crate::simd::simdty::u64x4; - -#[cfg(feature = "simd_opt")] -#[inline(always)] -pub fn rotate_right_const(vec: u64x4, n: u32) -> u64x4 { - match n { - 32 => rotate_right_32(vec), - 24 => rotate_right_24(vec), - 16 => rotate_right_16(vec), - _ => rotate_right_any(vec, n), - } -} - -#[cfg(not(feature = "simd_opt"))] -#[inline(always)] -pub fn rotate_right_const(vec: u64x4, n: u32) -> u64x4 { - rotate_right_any(vec, n) -} - -#[inline(always)] -fn rotate_right_any(vec: u64x4, n: u32) -> u64x4 { - let r = n as u64; - let l = 64 - r; - - (vec >> u64x4::new(r, r, r, r)) ^ (vec << u64x4::new(l, l, l, l)) -} - -#[cfg(feature = "simd_opt")] -#[inline(always)] -fn rotate_right_32(vec: u64x4) -> u64x4 { - if cfg!(any(target_feature = "sse2", target_feature = "neon")) { - // 2 x pshufd (SSE2) / vpshufd (AVX2) / 2 x vrev (NEON) - transmute_shuffle!(u32x8, simd_shuffle8, vec, 8, [1, 0, 3, 2, 5, 4, 7, 6]) - } else { - rotate_right_any(vec, 32) - } -} - -#[cfg(feature = "simd_opt")] -#[inline(always)] -fn rotate_right_24(vec: u64x4) -> u64x4 { - if cfg!(all( - feature = "simd_asm", - target_feature = "neon", - target_arch = "arm" - )) { - // 4 x vext (NEON) - rotate_right_vext(vec, 3) - } else if cfg!(target_feature = "ssse3") { - // 2 x pshufb (SSSE3) / vpshufb (AVX2) - transmute_shuffle!( - u8x32, - simd_shuffle32, - vec, - 32, - [ - 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10, 19, 20, 21, 22, 23, 16, 17, - 18, 27, 28, 29, 30, 31, 24, 25, 26 - ] - ) - } else { - rotate_right_any(vec, 24) - } -} - -#[cfg(feature = "simd_opt")] -#[inline(always)] -fn rotate_right_16(vec: u64x4) -> u64x4 { - if cfg!(all( - feature = "simd_asm", - target_feature = "neon", - target_arch = "arm" - )) { - // 4 x vext (NEON) - rotate_right_vext(vec, 2) - } else if cfg!(target_feature = "ssse3") { - // 2 x pshufb (SSSE3) / vpshufb (AVX2) - transmute_shuffle!( - u8x32, - simd_shuffle32, - vec, - 32, - [ - 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9, 18, 19, 20, 21, 22, 23, 16, - 17, 26, 27, 28, 29, 30, 31, 24, 25 - ] - ) - } else if cfg!(target_feature = "sse2") { - // 2 x pshuflw+pshufhw (SSE2) - transmute_shuffle!( - u16x16, - simd_shuffle16, - vec, - 16, - [1, 2, 3, 0, 5, 6, 7, 4, 9, 10, 11, 8, 13, 14, 15, 12] - ) - } else { - rotate_right_any(vec, 16) - } -} - -#[cfg(all(feature = "simd_asm", target_feature = "neon", target_arch = "arm"))] -mod simd_asm_neon_arm { - use crate::simd::simdty::{u64x2, u64x4}; - - #[inline(always)] - fn vext_u64(vec: u64x2, b: u8) -> u64x2 { - unsafe { - let result: u64x2; - asm!("vext.8 ${0:e}, ${1:e}, ${1:e}, $2\nvext.8 ${0:f}, ${1:f}, ${1:f}, $2" - : "=w" (result) - : "w" (vec), "n" (b)); - result - } - } - - #[inline(always)] - pub fn rotate_right_vext(vec: u64x4, b: u8) -> u64x4 { - use crate::simd::simdint::{simd_shuffle2, simd_shuffle4}; - - unsafe { - let tmp0 = vext_u64(simd_shuffle2(vec, vec, [0, 1]), b); - let tmp1 = vext_u64(simd_shuffle2(vec, vec, [2, 3]), b); - simd_shuffle4(tmp0, tmp1, [0, 1, 2, 3]) - } - } -} - -#[cfg(all(feature = "simd_asm", target_feature = "neon", target_arch = "arm"))] -use self::simd_asm_neon_arm::rotate_right_vext; - -#[cfg(feature = "simd_opt")] -#[cfg(not(all(feature = "simd_asm", target_feature = "neon", target_arch = "arm")))] -fn rotate_right_vext(_vec: u64x4, _n: u8) -> u64x4 { - unreachable!() -} diff --git a/blake2/src/simd/simdint.rs b/blake2/src/simd/simdint.rs deleted file mode 100644 index d876d5538..000000000 --- a/blake2/src/simd/simdint.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2015 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -#![allow(dead_code)] - -#[cfg(feature = "simd")] -extern "platform-intrinsic" { - pub fn simd_add(x: T, y: T) -> T; - pub fn simd_shl(x: T, y: T) -> T; - pub fn simd_shr(x: T, y: T) -> T; - pub fn simd_xor(x: T, y: T) -> T; - - pub fn simd_shuffle2(v: T, w: T, idx: [u32; 2]) -> U; - pub fn simd_shuffle4(v: T, w: T, idx: [u32; 4]) -> U; - pub fn simd_shuffle8(v: T, w: T, idx: [u32; 8]) -> U; - pub fn simd_shuffle16(v: T, w: T, idx: [u32; 16]) -> U; - pub fn simd_shuffle32(v: T, w: T, idx: [u32; 32]) -> U; -} diff --git a/blake2/src/simd/simdop.rs b/blake2/src/simd/simdop.rs deleted file mode 100644 index 891456d9c..000000000 --- a/blake2/src/simd/simdop.rs +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2015 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -#[cfg(feature = "simd")] -use crate::simd::simdint; -use crate::simd::simdty::{u32x4, u64x4}; - -use core::ops::{Add, BitXor, Shl, Shr}; - -macro_rules! impl_ops { - ($vec:ident) => { - impl Add for $vec { - type Output = Self; - - #[cfg(feature = "simd")] - #[inline(always)] - fn add(self, rhs: Self) -> Self::Output { - unsafe { simdint::simd_add(self, rhs) } - } - - #[cfg(not(feature = "simd"))] - #[inline(always)] - fn add(self, rhs: Self) -> Self::Output { - $vec::new( - self.0.wrapping_add(rhs.0), - self.1.wrapping_add(rhs.1), - self.2.wrapping_add(rhs.2), - self.3.wrapping_add(rhs.3), - ) - } - } - - impl BitXor for $vec { - type Output = Self; - - #[cfg(feature = "simd")] - #[inline(always)] - fn bitxor(self, rhs: Self) -> Self::Output { - unsafe { simdint::simd_xor(self, rhs) } - } - - #[cfg(not(feature = "simd"))] - #[inline(always)] - fn bitxor(self, rhs: Self) -> Self::Output { - $vec::new( - self.0 ^ rhs.0, - self.1 ^ rhs.1, - self.2 ^ rhs.2, - self.3 ^ rhs.3, - ) - } - } - - impl Shl<$vec> for $vec { - type Output = Self; - - #[cfg(feature = "simd")] - #[inline(always)] - fn shl(self, rhs: Self) -> Self::Output { - unsafe { simdint::simd_shl(self, rhs) } - } - - #[cfg(not(feature = "simd"))] - #[inline(always)] - fn shl(self, rhs: Self) -> Self::Output { - $vec::new( - self.0 << rhs.0, - self.1 << rhs.1, - self.2 << rhs.2, - self.3 << rhs.3, - ) - } - } - - impl Shr<$vec> for $vec { - type Output = Self; - - #[cfg(feature = "simd")] - #[inline(always)] - fn shr(self, rhs: Self) -> Self::Output { - unsafe { simdint::simd_shr(self, rhs) } - } - - #[cfg(not(feature = "simd"))] - #[inline(always)] - fn shr(self, rhs: Self) -> Self::Output { - $vec::new( - self.0 >> rhs.0, - self.1 >> rhs.1, - self.2 >> rhs.2, - self.3 >> rhs.3, - ) - } - } - }; -} - -impl_ops!(u32x4); -impl_ops!(u64x4); diff --git a/blake2/src/simd/simdty.rs b/blake2/src/simd/simdty.rs deleted file mode 100644 index 828f19131..000000000 --- a/blake2/src/simd/simdty.rs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2016 blake2-rfc Developers -// -// Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be -// copied, modified, or distributed except according to those terms. - -#![allow(dead_code, non_camel_case_types)] - -use crate::as_bytes::Safe; - -#[cfg(feature = "zeroize")] -use digest::zeroize::Zeroize; - -#[cfg(feature = "simd")] -macro_rules! decl_simd { - ($($decl:item)*) => { - $( - #[derive(Clone, Copy, Debug)] - #[repr(simd)] - $decl - )* - } -} - -#[cfg(not(feature = "simd"))] -macro_rules! decl_simd { - ($($decl:item)*) => { - $( - #[derive(Clone, Copy, Debug)] - #[repr(C)] - $decl - )* - } -} - -decl_simd! { - pub(crate) struct Simd2(pub(crate) T, pub(crate) T); - pub(crate) struct Simd4(pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T); - pub(crate) struct Simd8(pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T); - - pub(crate) struct Simd16(pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T); - - pub(crate) struct Simd32(pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T, - pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T); -} - -#[cfg(feature = "zeroize")] -impl Zeroize for Simd4 { - fn zeroize(&mut self) { - self.0.zeroize(); - self.1.zeroize(); - self.2.zeroize(); - self.3.zeroize(); - } -} - -pub(crate) type u64x2 = Simd2; - -pub(crate) type u32x4 = Simd4; -pub(crate) type u64x4 = Simd4; - -pub(crate) type u16x8 = Simd8; -pub(crate) type u32x8 = Simd8; - -pub(crate) type u8x16 = Simd16; -pub(crate) type u16x16 = Simd16; - -pub(crate) type u8x32 = Simd32; - -impl Simd4 { - #[inline(always)] - pub(crate) fn new(e0: T, e1: T, e2: T, e3: T) -> Simd4 { - Simd4(e0, e1, e2, e3) - } -} - -unsafe impl Safe for Simd2 {} -unsafe impl Safe for Simd4 {} -unsafe impl Safe for Simd8 {} -unsafe impl Safe for Simd16 {} -unsafe impl Safe for Simd32 {}