pakery-core 0.2.0

Shared utilities for PAKE protocol implementations
Documentation
//! Hash function trait.

use alloc::vec::Vec;

/// A cryptographic hash function.
pub trait Hash: Sized + Clone {
    /// Output size in bytes (e.g. 32 for SHA-256, 64 for SHA-512).
    const OUTPUT_SIZE: usize;

    /// Create a new hasher.
    fn new() -> Self;

    /// Feed data into the hasher.
    fn update(&mut self, data: &[u8]);

    /// Finalize and return the hash digest.
    fn finalize(self) -> Vec<u8>;

    /// One-shot: hash data and return the digest.
    fn digest(data: &[u8]) -> Vec<u8> {
        let mut h = Self::new();
        h.update(data);
        h.finalize()
    }
}