pub struct SHAKE<PARAMS: SHAKEParams> { /* private fields */ }Expand description
Note: FIPS 202 section 7 states:
“SHAKE128 and SHAKE256 are approved XOFs, whose approved uses will be specified in NIST Special Publications. Although some of those uses may overlap with the uses of approved hash functions, the XOFs are not approved as hash functions, due to the property that is discussed in Sec. A.2.”
Section A.2 describes how SHAKE does not internally diversify its output based on the requested length. For example, the first 32 bytes of SHAKE128(“message”, 64) and SHAKE128(“message”, 128), will be identical and equal to SHAKE128(“message”, 32). Proper hash functions don’t do this, and NIST is concerned that this could lead to application vulnerabilities.
As such, even though SHAKE is physically capable of acting as a hash function, and in fact is secure as such if the provided message includes the requested length, SHAKE does not implement the Hash trait.
Implementations§
Trait Implementations§
Source§impl<PARAMS: SHAKEParams> Algorithm for SHAKE<PARAMS>
impl<PARAMS: SHAKEParams> Algorithm for SHAKE<PARAMS>
const ALG_NAME: &'static str = PARAMS::ALG_NAME
const MAX_SECURITY_STRENGTH: SecurityStrength = PARAMS::MAX_SECURITY_STRENGTH
Source§impl<PARAMS: SHAKEParams> KDF for SHAKE<PARAMS>
impl<PARAMS: SHAKEParams> KDF for SHAKE<PARAMS>
Source§fn derive_key(
self,
key: &impl KeyMaterial,
additional_input: &[u8],
) -> Result<Box<dyn KeyMaterial>, KDFError>
fn derive_key( self, key: &impl KeyMaterial, additional_input: &[u8], ) -> Result<Box<dyn KeyMaterial>, KDFError>
Returns a KeyMaterialInternal. For the KDF to be considered “fully-seeded” and be capable of outputting full-entropy KeyMaterials, it requires full-entropy input that is at least 2x the bit size (ie 256 bits for SHAKE128, and 512 bits for SHAKE256). Returns a 32 byte key for SHAKE128 and a 64 byte key for SHAKE256. To produce longer keys, use KDF::derive_key_out. To produce shorter keys, either use KDF::derive_key_out or truncate this result down with KeyMaterialInternal::truncate.
Source§fn derive_key_from_multiple(
self,
keys: &[&impl KeyMaterial],
additional_input: &[u8],
) -> Result<Box<dyn KeyMaterial>, KDFError>
fn derive_key_from_multiple( self, keys: &[&impl KeyMaterial], additional_input: &[u8], ) -> Result<Box<dyn KeyMaterial>, KDFError>
Always returns a full KeyMaterialInternal; ie that fills the internal buffer of the appropriately-sized key material for the underlying cryptographic hash function. This can be truncated down with KeyMaterialInternal::truncate. Returns a 32 byte key for SHAKE128 and a 64 byte key for SHAKE256. To produce longer keys, use KDF::derive_key_out. To produce shorter keys, either use KDF::derive_key_out or truncate this result down with KeyMaterialInternal::truncate.
Source§fn derive_key_out(
self,
key: &impl KeyMaterial,
additional_input: &[u8],
output_key: &mut impl KeyMaterial,
) -> Result<usize, KDFError>
fn derive_key_out( self, key: &impl KeyMaterial, additional_input: &[u8], output_key: &mut impl KeyMaterial, ) -> Result<usize, KDFError>
Source§fn derive_key_from_multiple_out(
self,
keys: &[&impl KeyMaterial],
additional_input: &[u8],
output_key: &mut impl KeyMaterial,
) -> Result<usize, KDFError>
fn derive_key_from_multiple_out( self, keys: &[&impl KeyMaterial], additional_input: &[u8], output_key: &mut impl KeyMaterial, ) -> Result<usize, KDFError>
Source§fn max_security_strength(&self) -> SecurityStrength
fn max_security_strength(&self) -> SecurityStrength
Source§impl<PARAMS: SHAKEParams> XOF for SHAKE<PARAMS>
impl<PARAMS: SHAKEParams> XOF for SHAKE<PARAMS>
Source§fn absorb_last_partial_byte(
&mut self,
partial_byte: u8,
num_partial_bits: usize,
) -> Result<(), HashError>
fn absorb_last_partial_byte( &mut self, partial_byte: u8, num_partial_bits: usize, ) -> Result<(), HashError>
Switches to squeezing.
Source§fn squeeze_partial_byte_final_out(
self,
num_bits: usize,
output: &mut u8,
) -> Result<(), HashError>
fn squeeze_partial_byte_final_out( self, num_bits: usize, output: &mut u8, ) -> Result<(), HashError>
Result is the number of bits squezed into output.
Source§fn hash_xof(self, data: &[u8], result_len: usize) -> Vec<u8> ⓘ
fn hash_xof(self, data: &[u8], result_len: usize) -> Vec<u8> ⓘ
result_len bytes of output.Source§fn hash_xof_out(self, data: &[u8], output: &mut [u8]) -> usize
fn hash_xof_out(self, data: &[u8], output: &mut [u8]) -> usize
result_len bytes of output.
Fills the provided output slice.fn absorb(&mut self, data: &[u8]) -> Result<(), HashError>
Source§fn squeeze_partial_byte_final(self, num_bits: usize) -> Result<u8, HashError>
fn squeeze_partial_byte_final(self, num_bits: usize) -> Result<u8, HashError>
num_bits bits of the returned u8 (ie Big Endian).
This is a final call and consumes self.