Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
test: add quickcheck for hash functions
Browse files Browse the repository at this point in the history
  • Loading branch information
codahale committed Nov 9, 2023
1 parent 81654b7 commit 1dbe761
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ hex-literal = "0.4.1"
divan = "0.1.2"
expect-test = "1.4.1"
hex = "0.4.3"
quickcheck = "1.0.3"
quickcheck_macros = "1.0.0"

[workspace]
members = ["benchmarks"]
8 changes: 8 additions & 0 deletions src/haifa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub type AreionHaifa512 = AreionHaifa<U64>;
#[cfg(test)]
mod tests {
use digest::Digest;
use quickcheck_macros::quickcheck;

use super::*;

Expand All @@ -179,4 +180,11 @@ mod tests {
.chain_update(b"this is a potato")
.finalize();
}

#[quickcheck]
fn different_inputs_yield_different_digests(a: Vec<u8>, b: Vec<u8>) -> bool {
let aa = AreionHaifa512::new().chain_update(&a).finalize();
let bb = AreionHaifa512::new().chain_update(&b).finalize();
aa == bb || a != b
}
}
8 changes: 8 additions & 0 deletions src/md.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ mod tests {

use digest::Digest;
use expect_test::expect;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn different_inputs_yield_different_digests(a: Vec<u8>, b: Vec<u8>) -> bool {
let aa = Areion512Md::new().chain_update(&a).finalize();
let bb = Areion512Md::new().chain_update(&b).finalize();
aa == bb || a != b
}

#[test]
fn areion512_md_test_vector_1() {
Expand Down
15 changes: 15 additions & 0 deletions src/mmo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,18 @@ impl AlgorithmName for Core {
}

pub type Areion512Mmo = CoreWrapper<Core>;

#[cfg(test)]
mod tests {
use super::*;

use digest::Digest;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn different_inputs_yield_different_digests(a: Vec<u8>, b: Vec<u8>) -> bool {
let aa = Areion512Mmo::new().chain_update(&a).finalize();
let bb = Areion512Mmo::new().chain_update(&b).finalize();
aa == bb || a != b
}
}
15 changes: 15 additions & 0 deletions src/sponge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,18 @@ impl AlgorithmName for Core {
}

pub type Areion256Sponge = CoreWrapper<Core>;

#[cfg(test)]
mod tests {
use super::*;

use digest::Digest;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn different_inputs_yield_different_digests(a: Vec<u8>, b: Vec<u8>) -> bool {
let aa = Areion256Sponge::new().chain_update(&a).finalize();
let bb = Areion256Sponge::new().chain_update(&b).finalize();
aa == bb || a != b
}
}

0 comments on commit 1dbe761

Please sign in to comment.