Skip to main content

Hash

Trait Hash 

Source
pub trait Hash: Default {
    // Required methods
    fn block_bitlen(&self) -> usize;
    fn output_len(&self) -> usize;
    fn hash(self, data: &[u8]) -> Vec<u8> ;
    fn hash_out(self, data: &[u8], output: &mut [u8]) -> usize;
    fn do_update(&mut self, data: &[u8]);
    fn do_final(self) -> Vec<u8> ;
    fn do_final_out(self, output: &mut [u8]) -> usize;
    fn do_final_partial_bits(
        self,
        partial_byte: u8,
        num_partial_bits: usize,
    ) -> Result<Vec<u8>, HashError>;
    fn do_final_partial_bits_out(
        self,
        partial_byte: u8,
        num_partial_bits: usize,
        output: &mut [u8],
    ) -> Result<usize, HashError>;
    fn max_security_strength(&self) -> SecurityStrength;
}

Required Methods§

Source

fn block_bitlen(&self) -> usize

The size of the internal block in bits – needed by functions such as HMAC to compute security parameters.

Source

fn output_len(&self) -> usize

The size of the output in bytes.

Source

fn hash(self, data: &[u8]) -> Vec<u8>

A static one-shot API that hashes the provided data. data can be of any length, including zero bytes.

Source

fn hash_out(self, data: &[u8], output: &mut [u8]) -> usize

A static one-shot API that hashes the provided data into the provided output slice. data can be of any length, including zero bytes. The return value is the number of bytes written.

Source

fn do_update(&mut self, data: &[u8])

Provide a chunk of data to be absorbed into the hashes. data can be of any length, including zero bytes. do_update() is intended to be used as part of a streaming interface, and so may by called multiple times.

Source

fn do_final(self) -> Vec<u8>

Finish absorbing input and produce the hashes output. Consumes self, so this must be the final call to this object.

Source

fn do_final_out(self, output: &mut [u8]) -> usize

Finish absorbing input and produce the hashes output. Consumes self, so this must be the final call to this object.

If the provided buffer is smaller than the hash’s output length, the output will be truncated. If the provided buffor is larger than the hash’s output length, the output will be placed in the first Hash::output_len bytes.

The return value is the number of bytes written.

Source

fn do_final_partial_bits( self, partial_byte: u8, num_partial_bits: usize, ) -> Result<Vec<u8>, HashError>

The same as Hash::do_final, but allows for supplying a partial byte as the last input. Assumes that the input is in the least significant bits (big endian).

Source

fn do_final_partial_bits_out( self, partial_byte: u8, num_partial_bits: usize, output: &mut [u8], ) -> Result<usize, HashError>

The same as Hash::do_final_out, but allows for supplying a partial byte as the last input. Assumes that the input is in the least significant bits (big endian). will be placed in the first Hash::output_len bytes. The return value is the number of bytes written.

Source

fn max_security_strength(&self) -> SecurityStrength

Returns the maximum security strength that this KDF is capable of supporting, based on the underlying primitives.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§