hashes: rename fuzzing cfg parameter to bitcoin_hashes_fuzz
This commit is contained in:
parent
936f2ee3bb
commit
283b7d6e51
|
@ -77,7 +77,7 @@
|
||||||
#![allow(ellipsis_inclusive_range_patterns)]
|
#![allow(ellipsis_inclusive_range_patterns)]
|
||||||
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
|
||||||
// Instead of littering the codebase for non-fuzzing code just globally allow.
|
// Instead of littering the codebase for non-fuzzing code just globally allow.
|
||||||
#![cfg_attr(fuzzing, allow(dead_code, unused_imports))]
|
#![cfg_attr(hashes_fuzz, allow(dead_code, unused_imports))]
|
||||||
|
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
|
@ -17,7 +17,7 @@ crate::internal_macros::hash_type! {
|
||||||
"crate::util::json_hex_string::len_20"
|
"crate::util::json_hex_string::len_20"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn from_engine(mut e: HashEngine) -> Hash {
|
fn from_engine(mut e: HashEngine) -> Hash {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
||||||
let data_len = e.length as u64;
|
let data_len = e.length as u64;
|
||||||
|
@ -37,7 +37,7 @@ fn from_engine(mut e: HashEngine) -> Hash {
|
||||||
Hash(e.midstate())
|
Hash(e.midstate())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn from_engine(e: HashEngine) -> Hash {
|
fn from_engine(e: HashEngine) -> Hash {
|
||||||
let mut res = e.midstate();
|
let mut res = e.midstate();
|
||||||
res[0] ^= (e.length & 0xff) as u8;
|
res[0] ^= (e.length & 0xff) as u8;
|
||||||
|
@ -67,7 +67,7 @@ impl Default for HashEngine {
|
||||||
impl crate::HashEngine for HashEngine {
|
impl crate::HashEngine for HashEngine {
|
||||||
type MidState = [u8; 20];
|
type MidState = [u8; 20];
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn midstate(&self) -> [u8; 20] {
|
fn midstate(&self) -> [u8; 20] {
|
||||||
let mut ret = [0; 20];
|
let mut ret = [0; 20];
|
||||||
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(4)) {
|
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(4)) {
|
||||||
|
@ -76,7 +76,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn midstate(&self) -> [u8; 20] {
|
fn midstate(&self) -> [u8; 20] {
|
||||||
let mut ret = [0; 20];
|
let mut ret = [0; 20];
|
||||||
ret.copy_from_slice(&self.buffer[..20]);
|
ret.copy_from_slice(&self.buffer[..20]);
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl Default for HashEngine {
|
||||||
impl crate::HashEngine for HashEngine {
|
impl crate::HashEngine for HashEngine {
|
||||||
type MidState = [u8; 20];
|
type MidState = [u8; 20];
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn midstate(&self) -> [u8; 20] {
|
fn midstate(&self) -> [u8; 20] {
|
||||||
let mut ret = [0; 20];
|
let mut ret = [0; 20];
|
||||||
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(4)) {
|
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(4)) {
|
||||||
|
@ -68,7 +68,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn midstate(&self) -> [u8; 20] {
|
fn midstate(&self) -> [u8; 20] {
|
||||||
let mut ret = [0; 20];
|
let mut ret = [0; 20];
|
||||||
ret.copy_from_slice(&self.buffer[..20]);
|
ret.copy_from_slice(&self.buffer[..20]);
|
||||||
|
|
|
@ -17,7 +17,7 @@ crate::internal_macros::hash_type! {
|
||||||
"crate::util::json_hex_string::len_32"
|
"crate::util::json_hex_string::len_32"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn from_engine(mut e: HashEngine) -> Hash {
|
fn from_engine(mut e: HashEngine) -> Hash {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 8 bytes remaining
|
||||||
let data_len = e.length as u64;
|
let data_len = e.length as u64;
|
||||||
|
@ -37,7 +37,7 @@ fn from_engine(mut e: HashEngine) -> Hash {
|
||||||
Hash(e.midstate().to_byte_array())
|
Hash(e.midstate().to_byte_array())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn from_engine(e: HashEngine) -> Hash {
|
fn from_engine(e: HashEngine) -> Hash {
|
||||||
let mut hash = e.midstate().to_byte_array();
|
let mut hash = e.midstate().to_byte_array();
|
||||||
if hash == [0; 32] {
|
if hash == [0; 32] {
|
||||||
|
@ -74,7 +74,7 @@ impl Default for HashEngine {
|
||||||
impl crate::HashEngine for HashEngine {
|
impl crate::HashEngine for HashEngine {
|
||||||
type MidState = Midstate;
|
type MidState = Midstate;
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn midstate(&self) -> Midstate {
|
fn midstate(&self) -> Midstate {
|
||||||
let mut ret = [0; 32];
|
let mut ret = [0; 32];
|
||||||
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(4)) {
|
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(4)) {
|
||||||
|
@ -83,7 +83,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
Midstate(ret)
|
Midstate(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn midstate(&self) -> Midstate {
|
fn midstate(&self) -> Midstate {
|
||||||
let mut ret = [0; 32];
|
let mut ret = [0; 32];
|
||||||
ret.copy_from_slice(&self.buffer[..32]);
|
ret.copy_from_slice(&self.buffer[..32]);
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl Default for HashEngine {
|
||||||
impl crate::HashEngine for HashEngine {
|
impl crate::HashEngine for HashEngine {
|
||||||
type MidState = [u8; 64];
|
type MidState = [u8; 64];
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn midstate(&self) -> [u8; 64] {
|
fn midstate(&self) -> [u8; 64] {
|
||||||
let mut ret = [0; 64];
|
let mut ret = [0; 64];
|
||||||
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(8)) {
|
for (val, ret_bytes) in self.h.iter().zip(ret.chunks_exact_mut(8)) {
|
||||||
|
@ -48,7 +48,7 @@ impl crate::HashEngine for HashEngine {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn midstate(&self) -> [u8; 64] {
|
fn midstate(&self) -> [u8; 64] {
|
||||||
let mut ret = [0; 64];
|
let mut ret = [0; 64];
|
||||||
ret.copy_from_slice(&self.buffer[..64]);
|
ret.copy_from_slice(&self.buffer[..64]);
|
||||||
|
@ -80,7 +80,7 @@ impl Hash {
|
||||||
fn internal_engine() -> HashEngine { Default::default() }
|
fn internal_engine() -> HashEngine { Default::default() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
pub(crate) fn from_engine(mut e: HashEngine) -> Hash {
|
pub(crate) fn from_engine(mut e: HashEngine) -> Hash {
|
||||||
// pad buffer with a single 1-bit then all 0s, until there are exactly 16 bytes remaining
|
// pad buffer with a single 1-bit then all 0s, until there are exactly 16 bytes remaining
|
||||||
let data_len = e.length as u64;
|
let data_len = e.length as u64;
|
||||||
|
@ -101,7 +101,7 @@ pub(crate) fn from_engine(mut e: HashEngine) -> Hash {
|
||||||
Hash(e.midstate())
|
Hash(e.midstate())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
pub(crate) fn from_engine(e: HashEngine) -> Hash {
|
pub(crate) fn from_engine(e: HashEngine) -> Hash {
|
||||||
let mut hash = e.midstate();
|
let mut hash = e.midstate();
|
||||||
hash[0] ^= 0xff; // Make this distinct from SHA-256
|
hash[0] ^= 0xff; // Make this distinct from SHA-256
|
||||||
|
|
|
@ -16,10 +16,10 @@ crate::internal_macros::hash_type! {
|
||||||
"crate::util::json_hex_string::len_8"
|
"crate::util::json_hex_string::len_8"
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn from_engine(e: HashEngine) -> Hash { Hash::from_u64(Hash::from_engine_to_u64(e)) }
|
fn from_engine(e: HashEngine) -> Hash { Hash::from_u64(Hash::from_engine_to_u64(e)) }
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn from_engine(e: HashEngine) -> Hash {
|
fn from_engine(e: HashEngine) -> Hash {
|
||||||
let state = e.midstate();
|
let state = e.midstate();
|
||||||
Hash::from_u64(state.v0 ^ state.v1 ^ state.v2 ^ state.v3)
|
Hash::from_u64(state.v0 ^ state.v1 ^ state.v2 ^ state.v3)
|
||||||
|
|
|
@ -68,7 +68,7 @@ macro_rules! borrow_slice_impl(
|
||||||
|
|
||||||
macro_rules! engine_input_impl(
|
macro_rules! engine_input_impl(
|
||||||
() => (
|
() => (
|
||||||
#[cfg(not(fuzzing))]
|
#[cfg(not(hashes_fuzz))]
|
||||||
fn input(&mut self, mut inp: &[u8]) {
|
fn input(&mut self, mut inp: &[u8]) {
|
||||||
while !inp.is_empty() {
|
while !inp.is_empty() {
|
||||||
let buf_idx = self.length % <Self as crate::HashEngine>::BLOCK_SIZE;
|
let buf_idx = self.length % <Self as crate::HashEngine>::BLOCK_SIZE;
|
||||||
|
@ -85,7 +85,7 @@ macro_rules! engine_input_impl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(hashes_fuzz)]
|
||||||
fn input(&mut self, inp: &[u8]) {
|
fn input(&mut self, inp: &[u8]) {
|
||||||
for c in inp {
|
for c in inp {
|
||||||
self.buffer[0] ^= *c;
|
self.buffer[0] ^= *c;
|
||||||
|
|
Loading…
Reference in New Issue