diff --git a/hashes/embedded/Cargo.toml b/hashes/embedded/Cargo.toml deleted file mode 100644 index 43d0afafb..000000000 --- a/hashes/embedded/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -authors = ["Riccardo Casatta "] -edition = "2024" -readme = "README.md" -name = "embedded" -version = "0.1.0" - -# Prevent this from interfering with workspaces -[workspace] -members = ["."] - -[features] -alloc = ["alloc-cortex-m", "dashcore_hashes/alloc"] - -[dependencies] -cortex-m = "0.6.0" -cortex-m-rt = "0.6.10" -cortex-m-semihosting = "0.3.3" -panic-halt = "0.2.0" -alloc-cortex-m = { version = "0.4.1", optional = true } -dashcore_hashes = { path="../", default-features = false, features = ["core2"] } -core2 = { version = "0.3.0", default-features = false } - -[[bin]] -name = "embedded" -test = false -bench = false - -[profile.release] -codegen-units = 1 # better optimizations -debug = true # symbols are nice and they don't increase the size on Flash -lto = true # better optimizations diff --git a/hashes/embedded/memory.x b/hashes/embedded/memory.x deleted file mode 100644 index 95de161be..000000000 --- a/hashes/embedded/memory.x +++ /dev/null @@ -1,5 +0,0 @@ -MEMORY -{ - FLASH : ORIGIN = 0x00000000, LENGTH = 256K - RAM : ORIGIN = 0x20000000, LENGTH = 64K -} diff --git a/hashes/embedded/src/main.rs b/hashes/embedded/src/main.rs deleted file mode 100644 index 3d52aa3d4..000000000 --- a/hashes/embedded/src/main.rs +++ /dev/null @@ -1,74 +0,0 @@ -#![cfg_attr(feature = "alloc", feature(alloc_error_handler))] -#![no_std] -#![no_main] - -#[macro_use] -extern crate dashcore_hashes; - -#[cfg(feature = "alloc")] extern crate alloc; -#[cfg(feature = "alloc")] use alloc_cortex_m::CortexMHeap; -#[cfg(feature = "alloc")] use core::alloc::Layout; -#[cfg(feature = "alloc")] use cortex_m::asm; -#[cfg(feature = "alloc")] use alloc::string::ToString; - -use dashcore_hashes::{sha256, Hash, HashEngine}; -use core2::io::Write; -use core::str::FromStr; -use cortex_m_rt::entry; -use cortex_m_semihosting::{debug, hprintln}; -use panic_halt as _; - -hash_newtype! { - struct TestType(sha256::Hash); -} - -// this is the allocator the application will use -#[cfg(feature = "alloc")] -#[global_allocator] -static ALLOCATOR: CortexMHeap = CortexMHeap::empty(); - -#[cfg(feature = "alloc")] -const HEAP_SIZE: usize = 1024; // in bytes - -#[entry] -fn main() -> ! { - #[cfg(feature = "alloc")] - unsafe { ALLOCATOR.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE) } - - let mut engine = TestType::engine(); - engine.write_all(b"abc").unwrap(); - check_result(engine); - - let mut engine = TestType::engine(); - engine.input(b"abc"); - check_result(engine); - - debug::exit(debug::EXIT_SUCCESS); - loop {} -} - -fn check_result(engine: sha256::HashEngine) { - let hash = TestType::from_engine(engine); - - let hash_check = - TestType::from_str("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") - .unwrap(); - hprintln!("hash:{} hash_check:{}", hash, hash_check).unwrap(); - if hash != hash_check { - debug::exit(debug::EXIT_FAILURE); - } - - #[cfg(feature = "alloc")] - if hash.to_string() != hash_check.to_string() { - debug::exit(debug::EXIT_FAILURE); - } -} - -// define what happens in an Out Of Memory (OOM) condition -#[cfg(feature = "alloc")] -#[alloc_error_handler] -fn alloc_error(_layout: Layout) -> ! { - asm::bkpt(); - - loop {} -} diff --git a/hashes/extended_tests/schemars/Cargo.toml b/hashes/extended_tests/schemars/Cargo.toml deleted file mode 100644 index c8ff4670b..000000000 --- a/hashes/extended_tests/schemars/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "schemars" -version = "0.1.0" -authors = ["Jeremy Rubin "] -edition = "2024" - -# Prevent this from interfering with workspaces -[workspace] -members = ["."] - -[dependencies.dashcore_hashes] -path = "../.." -features = ['schemars', 'serde'] - -[dependencies] -jsonschema-valid = "^0.4.0" -serde = { version = "1.0", default-features = false} -schemars = { version = "<=0.8.3"} -serde_test = "1.0" -serde_json = "1.0" diff --git a/hashes/extended_tests/schemars/src/main.rs b/hashes/extended_tests/schemars/src/main.rs deleted file mode 100644 index dd68ec9d3..000000000 --- a/hashes/extended_tests/schemars/src/main.rs +++ /dev/null @@ -1,191 +0,0 @@ -fn main() {} -#[cfg(test)] -mod tests { - use dashcore_hashes::*; - - #[test] - fn hash160() { - static HASH_BYTES: [u8; 20] = [ - 0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, 0x5e, 0xb8, 0xb6, 0xad, 0x0b, 0x77, - 0xe7, 0xb6, 0xf1, 0x4a, 0xca, 0xd7, - ]; - - let hash = hash160::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(hash160::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn hmac_sha512() { - static HASH_BYTES: [u8; 64] = [ - 0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, - 0x1b, 0x8e, 0x0a, 0x19, 0x57, 0x54, 0xaa, 0x52, 0x7f, 0xcd, 0x00, 0xa4, 0x11, 0x62, - 0x0b, 0x46, 0xf2, 0x0f, 0xff, 0xfb, 0x80, 0x88, 0xcc, 0xf8, 0x54, 0x97, 0x12, 0x1a, - 0xd4, 0x49, 0x9e, 0x08, 0x45, 0xb8, 0x76, 0xf6, 0xdd, 0x66, 0x40, 0x08, 0x8a, 0x2f, - 0x0b, 0x2d, 0x8a, 0x60, 0x0b, 0xdf, 0x4c, 0x0c, - ]; - - let hash = Hmac::::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(Hmac::); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn ripemd160() { - static HASH_BYTES: [u8; 20] = [ - 0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, 0x5e, 0xb8, 0xb6, 0xad, 0x0b, 0x77, - 0xe7, 0xb6, 0xf1, 0x4a, 0xca, 0xd7, - ]; - - let hash = ripemd160::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(ripemd160::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn sha1() { - static HASH_BYTES: [u8; 20] = [ - 0x13, 0x20, 0x72, 0xdf, 0x69, 0x09, 0x33, 0x83, 0x5e, 0xb8, 0xb6, 0xad, 0x0b, 0x77, - 0xe7, 0xb6, 0xf1, 0x4a, 0xca, 0xd7, - ]; - - let hash = sha1::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(sha1::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn sha256d() { - static HASH_BYTES: [u8; 32] = [ - 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, - 0x3d, 0x97, 0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2, 0xb7, 0x65, 0x44, 0x8c, - 0x86, 0x35, 0xfb, 0x6c, - ]; - - let hash = sha256d::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(sha256d::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn sha256() { - static HASH_BYTES: [u8; 32] = [ - 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, - 0x3d, 0x97, 0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2, 0xb7, 0x65, 0x44, 0x8c, - 0x86, 0x35, 0xfb, 0x6c, - ]; - - let hash = sha256::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(sha256::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn test_hash() { - const TEST_MIDSTATE: [u8; 32] = [ - 156, 224, 228, 230, 124, 17, 108, 57, 56, 179, 202, 242, 195, 15, 80, 137, 211, 243, - 147, 108, 71, 99, 110, 96, 125, 179, 62, 234, 221, 198, 240, 201, - ]; - - #[derive( - Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Default, Hash, schemars::JsonSchema, - )] - pub struct TestHashTag; - - impl sha256t::Tag for TestHashTag { - fn engine() -> sha256::HashEngine { - // The TapRoot TapLeaf midstate. - let midstate = sha256::Midstate::from_byte_array(TEST_MIDSTATE); - sha256::HashEngine::from_midstate(midstate, 64) - } - } - - /// A hash tagged with `$name`. - pub type TestHash = sha256t::Hash; - - sha256t_hash_newtype! { - struct NewTypeTag = raw(TEST_MIDSTATE, 64); - - #[hash_newtype(backward)] - struct NewTypeHash(_); - } - static HASH_BYTES: [u8; 32] = [ - 0xef, 0x53, 0x7f, 0x25, 0xc8, 0x95, 0xbf, 0xa7, 0x82, 0x52, 0x65, 0x29, 0xa9, 0xb6, - 0x3d, 0x97, 0xaa, 0x63, 0x15, 0x64, 0xd5, 0xd7, 0x89, 0xc2, 0xb7, 0x65, 0x44, 0x8c, - 0x86, 0x35, 0xfb, 0x6c, - ]; - - let hash = TestHash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(TestHash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn sha512() { - static HASH_BYTES: [u8; 64] = [ - 0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21, 0x11, 0x3c, 0x52, 0xff, 0x18, 0x2a, - 0x1b, 0x8e, 0x0a, 0x19, 0x57, 0x54, 0xaa, 0x52, 0x7f, 0xcd, 0x00, 0xa4, 0x11, 0x62, - 0x0b, 0x46, 0xf2, 0x0f, 0xff, 0xfb, 0x80, 0x88, 0xcc, 0xf8, 0x54, 0x97, 0x12, 0x1a, - 0xd4, 0x49, 0x9e, 0x08, 0x45, 0xb8, 0x76, 0xf6, 0xdd, 0x66, 0x40, 0x08, 0x8a, 0x2f, - 0x0b, 0x2d, 0x8a, 0x60, 0x0b, 0xdf, 0x4c, 0x0c, - ]; - - let hash = sha512::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(sha512::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } - - #[test] - fn siphash24() { - static HASH_BYTES: [u8; 8] = [0x8b, 0x41, 0xe1, 0xb7, 0x8a, 0xd1, 0x15, 0x21]; - - let hash = siphash24::Hash::from_slice(&HASH_BYTES).expect("right number of bytes"); - let js = serde_json::from_str(&serde_json::to_string(&hash).unwrap()).unwrap(); - let s = schemars::schema_for!(siphash24::Hash); - let schema = serde_json::from_str(&serde_json::to_string(&s).unwrap()).unwrap(); - assert!(jsonschema_valid::Config::from_schema(&schema, None) - .unwrap() - .validate(&js) - .is_ok()); - } -} diff --git a/hashes/fuzz/Cargo.toml b/hashes/fuzz/Cargo.toml deleted file mode 100644 index 7f327f6a6..000000000 --- a/hashes/fuzz/Cargo.toml +++ /dev/null @@ -1,53 +0,0 @@ -[package] -name = "dashcore_hashes-fuzz" -version = "0.0.1" -authors = ["copied from rust-bitcoin"] -publish = false - -[package.metadata] -cargo-fuzz = true - -[features] -honggfuzz_fuzz = ["honggfuzz"] - -[dependencies] -honggfuzz = { version = "0.5", optional = true } -dashcore_hashes = { path = "..", features = ["serde"] } -rust-crypto = "0.2" - -serde = "1.0" -serde_derive = "1.0" -serde_json = "1.0" -serde_cbor = "0.9" - -# Prevent this from interfering with workspaces -[workspace] -members = ["."] - -[[bin]] -name = "sha1" -path = "fuzz_targets/sha1.rs" - -[[bin]] -name = "ripemd160" -path = "fuzz_targets/ripemd160.rs" - -[[bin]] -name = "sha256" -path = "fuzz_targets/sha256.rs" - -[[bin]] -name = "sha512" -path = "fuzz_targets/sha512.rs" - -[[bin]] -name = "sha512_256" -path = "fuzz_targets/sha512_256.rs" - -[[bin]] -name = "cbor" -path = "fuzz_targets/cbor.rs" - -[[bin]] -name = "json" -path = "fuzz_targets/json.rs" diff --git a/hashes/fuzz/fuzz_targets/cbor.rs b/hashes/fuzz/fuzz_targets/cbor.rs deleted file mode 100644 index d2c356e35..000000000 --- a/hashes/fuzz/fuzz_targets/cbor.rs +++ /dev/null @@ -1,66 +0,0 @@ - -extern crate serde; -#[macro_use] extern crate serde_derive; -extern crate dashcore_hashes; -extern crate serde_cbor; - -use dashcore_hashes::Hmac; -use dashcore_hashes::{sha1, sha512, ripemd160, sha256d}; - -#[derive(Deserialize, Serialize)] -struct Hmacs { - sha1: Hmac, - sha512: Hmac, -} - -#[derive(Deserialize, Serialize)] -struct Main { - hmacs: Hmacs, - ripemd: ripemd160::Hash, - sha2d: sha256d::Hash, -} - -fn do_test(data: &[u8]) { - if let Ok(m) = serde_cbor::from_slice::
(data) { - let vec = serde_cbor::to_vec(&m).unwrap(); - assert_eq!(data, &vec[..]); - } -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/fuzz_targets/json.rs b/hashes/fuzz/fuzz_targets/json.rs deleted file mode 100644 index 3c5c29aea..000000000 --- a/hashes/fuzz/fuzz_targets/json.rs +++ /dev/null @@ -1,66 +0,0 @@ - -extern crate serde; -#[macro_use] extern crate serde_derive; -extern crate dashcore_hashes; -extern crate serde_json; - -use dashcore_hashes::Hmac; -use dashcore_hashes::{sha1, sha512, ripemd160, sha256d}; - -#[derive(Deserialize, Serialize)] -struct Hmacs { - sha1: Hmac, - sha512: Hmac, -} - -#[derive(Deserialize, Serialize)] -struct Main { - hmacs: Hmacs, - ripemd: ripemd160::Hash, - sha2d: sha256d::Hash, -} - -fn do_test(data: &[u8]) { - if let Ok(m) = serde_json::from_slice::
(data) { - let vec = serde_json::to_vec(&m).unwrap(); - assert_eq!(data, &vec[..]); - } -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/fuzz_targets/ripemd160.rs b/hashes/fuzz/fuzz_targets/ripemd160.rs deleted file mode 100644 index deb7a7df7..000000000 --- a/hashes/fuzz/fuzz_targets/ripemd160.rs +++ /dev/null @@ -1,57 +0,0 @@ - -extern crate dashcore_hashes; -extern crate crypto; - -use dashcore_hashes::Hash; -use dashcore_hashes::ripemd160; -use crypto::digest::Digest; -use crypto::ripemd160::Ripemd160; - -fn do_test(data: &[u8]) { - let our_hash = ripemd160::Hash::hash(data); - - let mut rc_hash = [0u8; 20]; - let mut rc_engine = Ripemd160::new(); - rc_engine.input(data); - rc_engine.result(&mut rc_hash); - - assert_eq!(&our_hash[..], &rc_hash[..]); -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/fuzz_targets/sha1.rs b/hashes/fuzz/fuzz_targets/sha1.rs deleted file mode 100644 index 92fbf8ffb..000000000 --- a/hashes/fuzz/fuzz_targets/sha1.rs +++ /dev/null @@ -1,57 +0,0 @@ - -extern crate dashcore_hashes; -extern crate crypto; - -use dashcore_hashes::Hash; -use dashcore_hashes::sha1; -use crypto::digest::Digest; -use crypto::sha1::Sha1; - -fn do_test(data: &[u8]) { - let our_hash = sha1::Hash::hash(data); - - let mut rc_hash = [0u8; 20]; - let mut rc_sha1 = Sha1::new(); - rc_sha1.input(data); - rc_sha1.result(&mut rc_hash); - - assert_eq!(&our_hash[..], &rc_hash[..]); -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/fuzz_targets/sha256.rs b/hashes/fuzz/fuzz_targets/sha256.rs deleted file mode 100644 index ec86e6762..000000000 --- a/hashes/fuzz/fuzz_targets/sha256.rs +++ /dev/null @@ -1,57 +0,0 @@ - -extern crate dashcore_hashes; -extern crate crypto; - -use dashcore_hashes::Hash; -use dashcore_hashes::sha256; -use crypto::digest::Digest; -use crypto::sha2::Sha256; - -fn do_test(data: &[u8]) { - let our_hash = sha256::Hash::hash(data); - - let mut rc_hash = [0u8; 32]; - let mut rc_engine = Sha256::new(); - rc_engine.input(data); - rc_engine.result(&mut rc_hash); - - assert_eq!(&our_hash[..], &rc_hash[..]); -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/fuzz_targets/sha512.rs b/hashes/fuzz/fuzz_targets/sha512.rs deleted file mode 100644 index ff1c7a932..000000000 --- a/hashes/fuzz/fuzz_targets/sha512.rs +++ /dev/null @@ -1,57 +0,0 @@ - -extern crate dashcore_hashes; -extern crate crypto; - -use dashcore_hashes::Hash; -use dashcore_hashes::sha512; -use crypto::digest::Digest; -use crypto::sha2::Sha512; - -fn do_test(data: &[u8]) { - let our_hash = sha512::Hash::hash(data); - - let mut rc_hash = [0u8; 64]; - let mut rc_engine = Sha512::new(); - rc_engine.input(data); - rc_engine.result(&mut rc_hash); - - assert_eq!(&our_hash[..], &rc_hash[..]); -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/fuzz_targets/sha512_256.rs b/hashes/fuzz/fuzz_targets/sha512_256.rs deleted file mode 100644 index d277217f5..000000000 --- a/hashes/fuzz/fuzz_targets/sha512_256.rs +++ /dev/null @@ -1,57 +0,0 @@ - -extern crate dashcore_hashes; -extern crate crypto; - -use dashcore_hashes::Hash; -use dashcore_hashes::sha512_256; -use crypto::digest::Digest; -use crypto::sha2::Sha512Trunc256; - -fn do_test(data: &[u8]) { - let our_hash = sha512_256::Hash::hash(data); - - let mut rc_hash = [0u8; 32]; - let mut rc_engine = Sha512Trunc256::new(); - rc_engine.input(data); - rc_engine.result(&mut rc_hash); - - assert_eq!(&our_hash[..], &rc_hash[..]); -} - -#[cfg(feature = "honggfuzz")] -#[macro_use] -extern crate honggfuzz; - -#[cfg(feature = "honggfuzz")] -fn main() { - loop { - fuzz!(|d| { do_test(d) }); - } -} - -#[cfg(test)] -mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - let mut b = 0; - for (idx, c) in hex.as_bytes().iter().enumerate() { - b <<= 4; - match *c { - b'A'...b'F' => b |= c - b'A' + 10, - b'a'...b'f' => b |= c - b'a' + 10, - b'0'...b'9' => b |= c - b'0', - _ => panic!("Bad hex"), - } - if (idx & 1) == 1 { - out.push(b); - b = 0; - } - } - } - - #[test] - fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00000", &mut a); - super::do_test(&a); - } -} diff --git a/hashes/fuzz/travis-fuzz.sh b/hashes/fuzz/travis-fuzz.sh deleted file mode 100755 index aebd1aa46..000000000 --- a/hashes/fuzz/travis-fuzz.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -set -e -cargo install --force honggfuzz -for TARGET in fuzz_targets/*; do - FILENAME=$(basename $TARGET) - FILE="${FILENAME%.*}" - if [ -d hfuzz_input/$FILE ]; then - HFUZZ_INPUT_ARGS="-f hfuzz_input/$FILE/input" - fi - - rm -f hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT - - HFUZZ_BUILD_ARGS="--features honggfuzz_fuzz" HFUZZ_RUN_ARGS="-N1000000 --exit_upon_crash -v $HFUZZ_INPUT_ARGS" cargo hfuzz run $FILE - - if [ -f hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT ]; then - cat hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT - for CASE in hfuzz_workspace/$FILE/SIG*; do - cat $CASE | xxd -p - done - exit 1 - fi -done