Blake3Xof

Struct Blake3Xof 

Source
pub struct Blake3Xof { /* private fields */ }
Expand description

BLAKE3 extendable output function

This struct implements the BLAKE3 algorithm as an XOF, capable of producing outputs of arbitrary length. It maintains the internal state required for incremental hashing and supports all three BLAKE3 modes of operation.

§Internal Structure

The implementation uses:

  • A chunk state for processing input data in 1024-byte chunks
  • A stack of chaining values for the tree structure
  • Secure key storage using SecretBuffer
  • Flags to indicate the current mode of operation

§Security

All sensitive data (keys and intermediate values) are:

  • Stored in secure memory containers
  • Properly zeroized on drop
  • Protected against timing attacks

§Thread Safety

Blake3Xof is not thread-safe for concurrent access. Each thread should use its own instance.

Implementations§

Source§

impl Blake3Xof

Source

pub fn generate(data: &[u8], len: usize) -> Result<Vec<u8>>

Utility function for digest generation

This is a convenience function that creates a BLAKE3 XOF instance, processes the input data, and returns the requested number of output bytes.

§Arguments
  • data - The input data to hash
  • len - The desired output length in bytes
§Returns

A vector containing len bytes of output, or an error if the length is invalid.

§Example
let hash = Blake3Xof::generate(b"hello world", 32)?;
assert_eq!(hash.len(), 32);

Trait Implementations§

Source§

impl Clone for Blake3Xof

Source§

fn clone(&self) -> Blake3Xof

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DeriveKeyXof for Blake3Xof

Source§

fn for_derive_key(context: &[u8]) -> Result<Self>

Creates a new BLAKE3 XOF instance in key derivation mode.

This mode is designed for deriving keys from input key material. It first hashes the context string to create a context-specific key, then uses that key to process the actual key material.

§Arguments
  • context - A context string that domain-separates different uses
§Security Note

The context string should be unique for each application to ensure that keys derived for one purpose cannot be used for another.

Source§

fn derive_key(context: &[u8], data: &[u8], len: usize) -> Result<Vec<u8>>
where Self: Sized,

Derives key material in a single call
Source§

impl Drop for Blake3Xof

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ExtendableOutputFunction for Blake3Xof

Source§

fn new() -> Self

Creates a new BLAKE3 XOF instance in standard hashing mode.

The instance is initialized with the standard BLAKE3 IV and is ready to accept input data via the update method.

Source§

fn update(&mut self, input: &[u8]) -> Result<()>

Updates the XOF state with new data
Source§

fn finalize(&mut self) -> Result<()>

Finalizes the XOF state for output
Source§

fn squeeze(&mut self, output: &mut [u8]) -> Result<()>

Squeezes output bytes into the provided buffer
Source§

fn squeeze_into_vec(&mut self, len: usize) -> Result<Vec<u8>>

Squeezes the specified number of output bytes into a new vector
Source§

fn reset(&mut self) -> Result<()>

Resets the XOF state
Source§

fn security_level() -> usize

Returns the security level in bits
Source§

fn generate(data: &[u8], len: usize) -> Result<Vec<u8>>
where Self: Sized,

Convenience method to generate output in a single call
Source§

impl KeyedXof for Blake3Xof

Source§

fn with_key(key: &[u8]) -> Result<Self>

Creates a new BLAKE3 XOF instance in keyed hashing mode.

This mode uses a 256-bit key to create a MAC (Message Authentication Code). The key is mixed into the initial state, providing authentication.

§Arguments
  • key - A 32-byte (256-bit) key
§Errors

Returns an error if the key length is not exactly 32 bytes.

Source§

fn keyed_generate(key: &[u8], data: &[u8], len: usize) -> Result<Vec<u8>>
where Self: Sized,

Generates keyed output in a single call
Source§

impl Zeroize for Blake3Xof

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl ZeroizeOnDrop for Blake3Xof

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V