rust-lightning/src/util/sha2.rs

36 lines
668 B
Rust
Raw Normal View History

2018-03-19 20:34:27 -04:00
#[cfg(not(feature = "fuzztarget"))]
pub use crypto::sha2::Sha256;
#[cfg(feature = "fuzztarget")]
mod fuzzy_sha {
use crypto::digest::Digest;
pub struct Sha256 {
state: u8,
2018-03-19 20:34:27 -04:00
}
impl Sha256 {
pub fn new() -> Sha256 {
Sha256 {
state: 0,
2018-03-19 20:34:27 -04:00
}
}
}
impl Digest for Sha256 {
fn result(&mut self, data: &mut [u8]) {
data[0] = self.state;
2018-03-19 20:34:27 -04:00
for i in 1..32 {
data[i] = 0;
}
}
fn input(&mut self, data: &[u8]) { for i in data { self.state ^= i; } }
fn reset(&mut self) { self.state = 0; }
fn output_bits(&self) -> usize { 256 }
fn block_size(&self) -> usize { 64 }
2018-03-19 20:34:27 -04:00
}
}
#[cfg(feature = "fuzztarget")]
pub use self::fuzzy_sha::Sha256;