# hash.rs - source
Source of the Rust file `crates/core/src/transcript/hash.rs`.

Skip to main content

#
tlsn_core/transcript/
hash.rs

    1//! Plaintext hash commitments.
    2
    3use serde::{Deserialize, Serialize};
    4
    5use crate::{
    6    hash::{Blinder, HashAlgId, HashAlgorithm, TypedHash},
    7    transcript::{Direction, RangeSet},
    8};
    9
    10/// Hashes plaintext with a blinder.
    11///
    12/// By convention, plaintext is hashed as `H(msg | blinder)`.
    13pub fn hash_plaintext(hasher: &dyn HashAlgorithm, msg: &[u8], blinder: &Blinder) -> TypedHash {
    14    TypedHash {
    15        alg: hasher.id(),
    16        value: hasher.hash_prefixed(msg, blinder.as_bytes()),
    17    }
    18}
    19
    20/// Hash of plaintext in the transcript.
    21#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
    22pub struct PlaintextHash {
    23    /// Direction of the plaintext.
    24    pub direction: Direction,
    25    /// Index of plaintext.
    26    pub idx: RangeSet<usize>,
    27    /// The hash of the data.
    28    pub hash: TypedHash,
    29}
    30
    31/// Secret component of [`PlaintextHash`].
    32#[derive(Clone, Serialize, Deserialize)]
    33pub struct PlaintextHashSecret {
    34    /// Direction of the plaintext.
    35    pub direction: Direction,
    36    /// Index of plaintext.
    37    pub idx: RangeSet<usize>,
    38    /// The algorithm of the hash.
    39    pub alg: HashAlgId,
    40    /// Blinder for the hash.
    41    pub blinder: Blinder,
    42}
    43
    44opaque_debug::implement!(PlaintextHashSecret);