HashAlgorithm

Trait HashAlgorithm 

Source
pub trait HashAlgorithm:
    Clone
    + Send
    + Sync
    + 'static {
    const OUTPUT_SIZE: usize;
    const ALGORITHM_NAME: &'static str;

    // Required method
    fn hash(data: &[u8]) -> Vec<u8> ;

    // Provided methods
    fn hash_concat(data1: &[u8], data2: &[u8]) -> Vec<u8>  { ... }
    fn expand_seed(seed: &[u8]) -> (Vec<u8>, Vec<u8>) { ... }
}
Available on crate feature hash only.
Expand description

Trait for hash algorithms used in KES schemes

This trait provides a simple interface for hash algorithms used in Key Evolving Signature (KES) constructions, particularly for the binary sum composition where verification keys are hashed.

Required Associated Constants§

Source

const OUTPUT_SIZE: usize

Output size in bytes

Source

const ALGORITHM_NAME: &'static str

Algorithm name for debugging

Required Methods§

Source

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

Hash the input data

§Example
use cardano_crypto::hash::{Blake2b256, HashAlgorithm};

let data = b"input data";
let hash = Blake2b256::hash(data);
assert_eq!(hash.len(), Blake2b256::OUTPUT_SIZE);

Provided Methods§

Source

fn hash_concat(data1: &[u8], data2: &[u8]) -> Vec<u8>

Hash two inputs concatenated together

§Example
use cardano_crypto::hash::{Blake2b256, HashAlgorithm};

let hash = Blake2b256::hash_concat(b"hello", b"world");
assert_eq!(hash.len(), 32);
Source

fn expand_seed(seed: &[u8]) -> (Vec<u8>, Vec<u8>)

Expand a seed into two new seeds using domain separation

§Example
use cardano_crypto::hash::{Blake2b256, HashAlgorithm};

let seed = b"original seed";
let (seed0, seed1) = Blake2b256::expand_seed(seed);
assert_eq!(seed0.len(), 32);
assert_eq!(seed1.len(), 32);
assert_ne!(seed0, seed1);

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§

Source§

impl HashAlgorithm for Blake2b224

Source§

const OUTPUT_SIZE: usize = 28usize

Source§

const ALGORITHM_NAME: &'static str = "blake2b_224"

Source§

impl HashAlgorithm for Blake2b256

Source§

const OUTPUT_SIZE: usize = 32usize

Source§

const ALGORITHM_NAME: &'static str = "blake2b_256"

Source§

impl HashAlgorithm for Blake2b512

Source§

const OUTPUT_SIZE: usize = 64usize

Source§

const ALGORITHM_NAME: &'static str = "blake2b_512"