Struct blake2b_simd::Params
source · pub struct Params { /* private fields */ }
Expand description
A parameter builder that exposes all the non-default BLAKE2 features.
Apart from hash_length
, which controls the length of the final Hash
,
all of these parameters are just associated data that gets mixed with the
input. For more details, see the BLAKE2 spec.
Several of the parameters have a valid range defined in the spec and documented below. Trying to set an invalid parameter will panic.
Example
// Create a Params object with a secret key and a non-default length.
let mut params = Params::new();
params.key(b"my secret key");
params.hash_length(16);
// Use those params to hash an input all at once.
let hash = params.hash(b"my input");
// Or use those params to build an incremental State.
let mut state = params.to_state();
Implementations§
source§impl Params
impl Params
sourcepub fn to_state(&self) -> State
pub fn to_state(&self) -> State
Construct a State
object based on these parameters, for hashing input
incrementally.
sourcepub fn hash_length(&mut self, length: usize) -> &mut Self
pub fn hash_length(&mut self, length: usize) -> &mut Self
Set the length of the final hash in bytes, from 1 to OUTBYTES
(64). Apart from
controlling the length of the final Hash
, this is also associated data, and changing it
will result in a totally different hash.
sourcepub fn key(&mut self, key: &[u8]) -> &mut Self
pub fn key(&mut self, key: &[u8]) -> &mut Self
Use a secret key, so that BLAKE2 acts as a MAC. The maximum key length is KEYBYTES
(64).
An empty key is equivalent to having no key at all.
sourcepub fn salt(&mut self, salt: &[u8]) -> &mut Self
pub fn salt(&mut self, salt: &[u8]) -> &mut Self
At most SALTBYTES
(16). Shorter salts are padded with null bytes. An empty salt is
equivalent to having no salt at all.
sourcepub fn personal(&mut self, personalization: &[u8]) -> &mut Self
pub fn personal(&mut self, personalization: &[u8]) -> &mut Self
At most PERSONALBYTES
(16). Shorter personalizations are padded with null bytes. An empty
personalization is equivalent to having no personalization at all.
sourcepub fn fanout(&mut self, fanout: u8) -> &mut Self
pub fn fanout(&mut self, fanout: u8) -> &mut Self
From 0 (meaning unlimited) to 255. The default is 1 (meaning sequential).
sourcepub fn max_depth(&mut self, depth: u8) -> &mut Self
pub fn max_depth(&mut self, depth: u8) -> &mut Self
From 0 (meaning BLAKE2X B2 hashes), through 1 (the default, meaning sequential) to 255 (meaning unlimited).
sourcepub fn max_leaf_length(&mut self, length: u32) -> &mut Self
pub fn max_leaf_length(&mut self, length: u32) -> &mut Self
From 0 (the default, meaning unlimited or sequential) to 2^32 - 1
.
sourcepub fn node_offset(&mut self, offset: u64) -> &mut Self
pub fn node_offset(&mut self, offset: u64) -> &mut Self
From 0 (the default, meaning first, leftmost, leaf, or sequential) to 2^64 - 1
.
sourcepub fn node_depth(&mut self, depth: u8) -> &mut Self
pub fn node_depth(&mut self, depth: u8) -> &mut Self
From 0 (the default, meaning leaf or sequential) to 255.
sourcepub fn inner_hash_length(&mut self, length: usize) -> &mut Self
pub fn inner_hash_length(&mut self, length: usize) -> &mut Self
From 0 (the default, meaning sequential) to OUTBYTES
(64).
sourcepub fn last_node(&mut self, last_node: bool) -> &mut Self
pub fn last_node(&mut self, last_node: bool) -> &mut Self
Indicates the rightmost node in a row. This can also be changed on the
State
object, potentially after hashing has begun. See
State::set_last_node
.