Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ jobs:
- run: cargo test --features= --release
- run: cargo test --features=prefer_intrinsics --release
- run: cargo test --features=pure --release
# const fn
- run: cargo test --features=const
- run: cargo test --features=const --release
# No AVX-512.
- run: cargo test --features=no_avx512
- run: cargo test --features=no_avx512,prefer_intrinsics
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ wasm32_simd = []
# entire build, with e.g. RUSTFLAGS="-C target-cpu=native".
std = []

# This feature enables `const fn` variants of functions, but requires Rust 1.85.0+
const = []

# The `rayon` feature (disabled by default, but enabled for docs.rs) adds the
# `update_rayon` and (in combination with `mmap` below) `update_mmap_rayon`
# methods, for multithreaded hashing. However, even if this feature is enabled,
Expand Down Expand Up @@ -114,7 +117,7 @@ arrayref = "0.3.5"
arrayvec = { version = "0.7.4", default-features = false }
constant_time_eq = { version = "0.3.1", default-features = false }
cfg-if = "1.0.0"
digest = { version = "0.10.1", features = [ "mac" ], optional = true }
digest = { version = "0.10.1", features = ["mac"], optional = true }
memmap2 = { version = "0.9", optional = true }
rayon-core = { version = "1.12.1", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
Expand Down
11 changes: 10 additions & 1 deletion src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ fn test_max_subtree_len() {
/// # }
/// ```
#[inline(always)]
pub fn left_subtree_len(input_len: u64) -> u64 {
pub const fn left_subtree_len(input_len: u64) -> u64 {
debug_assert!(input_len > CHUNK_LEN as u64);
// Note that .next_power_of_two() is greater than *or equal*.
((input_len + 1) / 2).next_power_of_two()
Expand Down Expand Up @@ -555,6 +555,15 @@ pub fn hash_derive_key_context(context: &str) -> ContextKey {
.0
}

/// Hash a [`derive_key`](crate::derive_key) context like [`hash_derive_key_context`], but
/// `const fn`.
#[cfg(feature = "const")]
pub const fn const_hash_derive_key_context(context: &str) -> ContextKey {
crate::const_hash_all_at_once(context.as_bytes(), IV, crate::DERIVE_KEY_CONTEXT)
.root_hash()
.0
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading
Loading