Skip to content
4 changes: 2 additions & 2 deletions blake2/src/as_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use core::mem;
use core::slice;

#[allow(clippy::missing_safety_doc)]
pub unsafe trait Safe {}
pub(crate) unsafe trait Safe {}

pub trait AsBytes {
pub(crate) trait AsBytes {
fn as_bytes(&self) -> &[u8];
}

Expand Down
6 changes: 3 additions & 3 deletions blake2/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::unreadable_literal)]

pub static SIGMA: [[usize; 16]; 12] = [
pub(super) 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],
[11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
Expand All @@ -15,7 +15,7 @@ pub static SIGMA: [[usize; 16]; 12] = [
[14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
];

pub static BLAKE2B_IV: [u64; 8] = [
pub(super) static BLAKE2B_IV: [u64; 8] = [
0x6a09e667f3bcc908,
0xbb67ae8584caa73b,
0x3c6ef372fe94f82b,
Expand All @@ -34,7 +34,7 @@ pub const BLAKE2B_SALTBYTES : usize = 16;
pub const BLAKE2B_PERSONALBYTES : usize = 16;
*/

pub static BLAKE2S_IV: [u32; 8] = [
pub(super) static BLAKE2S_IV: [u32; 8] = [
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19,
];

Expand Down
1 change: 1 addition & 0 deletions blake2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(unexpected_cfgs)] // `simd` feature is broken
#![warn(missing_docs)]
#![warn(unreachable_pub)]
#![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))]
#![cfg_attr(feature = "simd", allow(incomplete_features))]

Expand Down
4 changes: 2 additions & 2 deletions blake2/src/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ mod simdint;
mod simdop;
mod simdty;

pub use self::simdty::{u32x4, u64x4};
pub(super) use self::simdty::{u32x4, u64x4};

pub trait Vector4<T>: Copy {
pub(super) trait Vector4<T>: Copy {
fn gather(src: &[T], i0: usize, i1: usize, i2: usize, i3: usize) -> Self;

#[allow(clippy::wrong_self_convention)]
Expand Down
4 changes: 2 additions & 2 deletions blake2/src/simd/simd_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ pub mod u64x4;
#[cfg(not(feature = "simd"))]
macro_rules! simd_opt {
($vec:ident) => {
pub mod $vec {
pub(super) mod $vec {
use crate::simd::simdty::$vec;

#[inline(always)]
pub fn rotate_right_const(vec: $vec, n: u32) -> $vec {
pub(crate) fn rotate_right_const(vec: $vec, n: u32) -> $vec {
$vec::new(
vec.0.rotate_right(n),
vec.1.rotate_right(n),
Expand Down
52 changes: 27 additions & 25 deletions blake2/src/simd/simdty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@ macro_rules! decl_simd {
}

decl_simd! {
pub struct Simd2<T>(pub T, pub T);
pub struct Simd4<T>(pub T, pub T, pub T, pub T);
pub struct Simd8<T>(pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T);
pub struct Simd16<T>(pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T);
pub struct Simd32<T>(pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T,
pub T, pub T, pub T, pub T);
pub(crate) struct Simd2<T>(pub(crate) T, pub(crate) T);
pub(crate) struct Simd4<T>(pub(crate) T, pub(crate) T, pub(crate) T, pub(crate) T);
pub(crate) struct Simd8<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 Simd16<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) struct Simd32<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, pub(crate) T);
}

#[cfg(feature = "zeroize")]
Expand All @@ -63,22 +65,22 @@ impl<T: Zeroize> Zeroize for Simd4<T> {
}
}

pub type u64x2 = Simd2<u64>;
pub(crate) type u64x2 = Simd2<u64>;

pub type u32x4 = Simd4<u32>;
pub type u64x4 = Simd4<u64>;
pub(crate) type u32x4 = Simd4<u32>;
pub(crate) type u64x4 = Simd4<u64>;

pub type u16x8 = Simd8<u16>;
pub type u32x8 = Simd8<u32>;
pub(crate) type u16x8 = Simd8<u16>;
pub(crate) type u32x8 = Simd8<u32>;

pub type u8x16 = Simd16<u8>;
pub type u16x16 = Simd16<u16>;
pub(crate) type u8x16 = Simd16<u8>;
pub(crate) type u16x16 = Simd16<u16>;

pub type u8x32 = Simd32<u8>;
pub(crate) type u8x32 = Simd32<u8>;

impl<T> Simd4<T> {
#[inline(always)]
pub fn new(e0: T, e1: T, e2: T, e3: T) -> Simd4<T> {
pub(crate) fn new(e0: T, e1: T, e2: T, e3: T) -> Simd4<T> {
Simd4(e0, e1, e2, e3)
}
}
Expand Down
3 changes: 2 additions & 1 deletion md5/src/block_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use digest::{
typenum::{U16, U24, U64, Unsigned},
};

use crate::{compress::compress, consts};
pub use crate::compress::compress;
use crate::consts;

const STATE_LEN: usize = 4;

Expand Down
11 changes: 8 additions & 3 deletions md5/src/compress.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
cfg_if::cfg_if! {
if #[cfg(feature = "force-soft")] {
mod soft;
pub use soft::compress;
use soft::compress as compress_inner;
} else if #[cfg(target_arch = "loongarch64")] {
mod loongarch64_asm;
pub use loongarch64_asm::compress;
use loongarch64_asm::compress as compress_inner;
} else {
mod soft;
pub use soft::compress;
use soft::compress as compress_inner;
}
}

/// md5 compression function
pub fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) {
compress_inner(state, blocks)
}
4 changes: 2 additions & 2 deletions md5/src/compress/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn op_i(w: u32, x: u32, y: u32, z: u32, m: u32, c: u32, s: u32) -> u32 {
}

#[inline]
pub fn compress_block(state: &mut [u32; 4], input: &[u8; 64]) {
fn compress_block(state: &mut [u32; 4], input: &[u8; 64]) {
let mut a = state[0];
let mut b = state[1];
let mut c = state[2];
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn compress_block(state: &mut [u32; 4], input: &[u8; 64]) {
}

#[inline]
pub fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) {
pub(super) fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) {
for block in blocks {
compress_block(state, block)
}
Expand Down
1 change: 1 addition & 0 deletions md5/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(unreachable_pub)]

pub use digest::{self, Digest};

Expand Down
1 change: 1 addition & 0 deletions sha1-checked/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(unreachable_pub)]

//! Collision checked Sha1.
//!
Expand Down
14 changes: 7 additions & 7 deletions sha1-checked/src/ubc_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ const DV_II_55_0_BIT: u32 = 1 << 30;
const DV_II_56_0_BIT: u32 = 1 << 31;

/// Disturbance Vector (DV).
pub struct Info {
pub(crate) struct Info {
/// The step to do the recompression from for collision detection.
pub testt: Testt,
pub(crate) testt: Testt,
/// Defines the bit to check for each DV in the dvmask returned by [`ubc_check`].
pub maskb: i32,
pub(crate) maskb: i32,
/// The expanded message block XOR-difference defined by the DV.
pub dm: [u32; 80],
pub(crate) dm: [u32; 80],
}

#[derive(Copy, Clone)]
#[repr(u32)]
pub enum Testt {
pub(crate) enum Testt {
T58 = 58,
T65 = 65,
}

/// The list of SHA-1 Disturbance Vectors (DV) to check.
pub const SHA1_DVS: [Info; 32] = [
pub(crate) const SHA1_DVS: [Info; 32] = [
// DV: type=1, K=43, B=0,
Info {
testt: Testt::T58,
Expand Down Expand Up @@ -599,7 +599,7 @@ pub const SHA1_DVS: [Info; 32] = [
/// all unavoidable bitconditions for that DV have been met thus one needs to do the
/// recompression check for each DV that has its bit set.
#[inline]
pub const fn ubc_check(w: &[u32; 80]) -> u32 {
pub(crate) const fn ubc_check(w: &[u32; 80]) -> u32 {
let mut mask: u32 = !0;
mask &= (((w[44] ^ w[45]) >> 29) & 1).wrapping_sub(1)
| !(DV_I_48_0_BIT
Expand Down
2 changes: 1 addition & 1 deletion sha1/src/compress/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ unsafe fn compress_sha1_neon(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
state[4] = e0;
}

pub fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
pub(super) fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
// TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725 after stabilization
if sha1_hwcap::get() {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion sha1/src/compress/loongarch64_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ macro_rules! roundtail {
};
}

pub fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
pub(super) fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
if blocks.is_empty() {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions sha1/src/compress/soft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn xor(a: [u32; 4], b: [u32; 4]) -> [u32; 4] {
}

#[inline]
pub fn sha1_first_add(e: u32, w0: [u32; 4]) -> [u32; 4] {
fn sha1_first_add(e: u32, w0: [u32; 4]) -> [u32; 4] {
let [a, b, c, d] = w0;
[e.wrapping_add(a), b, c, d]
}
Expand Down Expand Up @@ -242,7 +242,7 @@ fn sha1_digest_block_u32(state: &mut [u32; 5], block: &[u32; 16]) {
state[4] = state[4].wrapping_add(e);
}

pub fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
pub(super) fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
let mut block_u32 = [0u32; 16];
// since LLVM can't properly use aliasing yet it will make
// unnecessary state stores without this copy
Expand Down
2 changes: 1 addition & 1 deletion sha1/src/compress/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ unsafe fn digest_blocks(state: &mut [u32; 5], blocks: &[[u8; 64]]) {

cpufeatures::new!(shani_cpuid, "sha", "sse2", "ssse3", "sse4.1");

pub fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
pub(super) fn compress(state: &mut [u32; 5], blocks: &[[u8; 64]]) {
// TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725
// after stabilization
if shani_cpuid::get() {
Expand Down
1 change: 1 addition & 0 deletions sha1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(unreachable_pub)]

pub use digest::{self, Digest};

Expand Down
24 changes: 12 additions & 12 deletions sha2/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
#![allow(dead_code)]

pub type State256 = [u32; 8];
pub type State512 = [u64; 8];
pub(crate) type State256 = [u32; 8];
pub(crate) type State512 = [u64; 8];

pub const H256_224: State256 = [
pub(crate) const H256_224: State256 = [
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,
];

pub const H256_256: State256 = [
pub(crate) const H256_256: State256 = [
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
];

pub const H512_224: State512 = [
pub(crate) const H512_224: State512 = [
0x8c3d37c819544da2, 0x73e1996689dcd4d6, 0x1dfab7ae32ff9c82, 0x679dd514582f9fcf,
0x0f6d2b697bd44da8, 0x77e36f7304c48942, 0x3f9d85a86a1d36c8, 0x1112e6ad91d692a1,
];

pub const H512_256: State512 = [
pub(crate) const H512_256: State512 = [
0x22312194fc2bf72c, 0x9f555fa3c84c64c2, 0x2393b86b6f53b151, 0x963877195940eabd,
0x96283ee2a88effe3, 0xbe5e1e2553863992, 0x2b0199fc2c85b8aa, 0x0eb72ddc81c52ca2,
];

pub const H512_384: State512 = [
pub(crate) const H512_384: State512 = [
0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939,
0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4,
];

pub const H512_512: State512 = [
pub(crate) const H512_512: State512 = [
0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
0x510e527fade682d1, 0x9b05688c2b3e6c1f, 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179,
];

/// Round constants for SHA-256 family of digests
pub static K32: [u32; 64] = [
pub(crate) static K32: [u32; 64] = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
Expand All @@ -46,7 +46,7 @@ pub static K32: [u32; 64] = [
];

/// Round constants for SHA-512 family of digests
pub const K64: [u64; 80] = [
pub(crate) const K64: [u64; 80] = [
0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc,
0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118,
0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2,
Expand All @@ -70,7 +70,7 @@ pub const K64: [u64; 80] = [
];

/// Swapped round constants for SHA-256 family of digests
pub static K32X4: [[u32; 4]; 16] = {
pub(crate) static K32X4: [[u32; 4]; 16] = {
let mut res = [[0u32; 4]; 16];
let mut i = 0;
while i < 16 {
Expand All @@ -81,7 +81,7 @@ pub static K32X4: [[u32; 4]; 16] = {
};

/// Swapped round constants for SHA-512 family of digests
pub const K64X2: [[u64; 2]; 40] = {
pub(crate) const K64X2: [[u64; 2]; 40] = {
let mut res = [[0u64; 2]; 40];
let mut i = 0;
while i < 16 {
Expand Down
1 change: 1 addition & 0 deletions sha2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs)]
#![warn(unreachable_pub)]
#![cfg_attr(
any(sha2_backend = "riscv-zknh", sha2_backend = "riscv-zknh-compact"),
feature(riscv_ext_intrinsics)
Expand Down
2 changes: 1 addition & 1 deletion sha2/src/sha256/aarch64_sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::consts::K32;

cpufeatures::new!(sha2_hwcap, "sha2");

pub fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
pub(super) fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]]) {
// TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725
// after stabilization
if sha2_hwcap::get() {
Expand Down
Loading
Loading