Trait risc0_zkp::core::hash::sha::Sha256

source ·
pub trait Sha256 {
    type DigestPtr: DerefMut<Target = Digest> + Debug;

    // Required methods
    fn hash_bytes(bytes: &[u8]) -> Self::DigestPtr;
    fn compress(
        state: &Digest,
        block_half1: &Digest,
        block_half2: &Digest,
    ) -> Self::DigestPtr;
    fn compress_slice(state: &Digest, blocks: &[Block]) -> Self::DigestPtr;
    fn hash_raw_data_slice<T: NoUninit>(data: &[T]) -> Self::DigestPtr;

    // Provided methods
    fn hash_words(words: &[u32]) -> Self::DigestPtr { ... }
    fn hash_pair(a: &Digest, b: &Digest) -> Self::DigestPtr { ... }
}
Expand description

An implementation of the SHA-256 hashing algorithm of FIPS 180-4.

Required Associated Types§

source

type DigestPtr: DerefMut<Target = Digest> + Debug

A pointer to the digest created as the result of a hashing operation.

This may either be a Box<Digest> or some other pointer in case the implementation wants to manage its own memory. Semantically, holding the DigestPtr denotes ownership of the underlying value. (e.g. DigestPtr does not implement Copy and the owner of DigestPtr can create a mutable reference to the underlying digest).

Required Methods§

source

fn hash_bytes(bytes: &[u8]) -> Self::DigestPtr

Generate a SHA-256 hash from a slice of bytes, padding to block size and adding the SHA-256 hash trailer, as specified in FIPS 180-4.

source

fn compress( state: &Digest, block_half1: &Digest, block_half2: &Digest, ) -> Self::DigestPtr

Execute the SHA-256 compression function on a single block given as two half-blocks and return a pointer to the result.

NOTE: The half blocks do not need to be adjacent.

DANGER: This is the low-level SHA-256 compression function. It is a primitive used to construct SHA-256, but it is NOT the full algorithm and should be used directly only with extreme caution.

source

fn compress_slice(state: &Digest, blocks: &[Block]) -> Self::DigestPtr

Execute the SHA-256 compression function on a slice of blocks following the Merkle–Damgård construction and return a pointer to the result.

DANGER: This is the low-level SHA-256 compression function. It is a primitive used to construct SHA-256, but it is NOT the full algorithm and should be used directly only with extreme caution.

source

fn hash_raw_data_slice<T: NoUninit>(data: &[T]) -> Self::DigestPtr

Generate a hash from a slice of anything that can be represented as a slice of bytes. Pads up to the SHA-256 block boundary, but does not add the standard SHA-256 trailer and so is not a standards compliant hash.

Provided Methods§

source

fn hash_words(words: &[u32]) -> Self::DigestPtr

Generate a SHA-256 hash from a slice of words, padding to block size and adding the SHA-256 hash trailer, as specified in FIPS 180-4.

source

fn hash_pair(a: &Digest, b: &Digest) -> Self::DigestPtr

Generate a hash from a pair of Digest using the SHA-256 compression function. Note that the result is not a standard-compliant hash of any known preimage.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Sha256 for risc0_zkp::core::hash::sha::cpu::Impl

source§

impl Sha256 for risc0_zkp::core::hash::sha::guest::Impl

§

type DigestPtr = &'static mut Digest