aboutsummaryrefslogtreecommitdiff
path: root/guests/sha256/src/lib.rs
blob: 885f58ab210e963ed0f202fcb107849167596507 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#![cfg_attr(feature = "no_std", no_std)]

#[cfg(feature = "no_std")]
extern crate alloc;
#[cfg(feature = "no_std")]
use alloc::vec::Vec;

#[cfg(feature = "sp1")]
use sha2_sp1::{Digest, Sha256};

#[cfg(feature = "risc0")]
use sha2_risc0::{Digest, Sha256};

#[cfg(not(any(feature = "sp1", feature = "risc0")))]
use sha2::{Digest, Sha256};

#[guests_macro::proving_entrypoint]
pub fn main(secret: Vec<u8>, hash: Vec<u8>) -> bool {
    let mut hasher = Sha256::new();
    hasher.update(secret);
    let result = hasher.finalize();

    let output: [u8; 32] = result.into();

    output.to_vec() == hash
}