From e0760797720b861087067346513dc61e55dcd3e4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 19 May 2017 16:44:05 -0700 Subject: [PATCH] Add cargo-fuzz --- fuzz/.gitignore | 4 ++++ fuzz/Cargo.toml | 24 ++++++++++++++++++++++++ fuzz/fuzzers/decaf.rs | 21 +++++++++++++++++++++ src/decaf.rs | 2 +- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 fuzz/.gitignore create mode 100644 fuzz/Cargo.toml create mode 100644 fuzz/fuzzers/decaf.rs diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..572e03b --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,4 @@ + +target +corpus +artifacts diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..5245cbe --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,24 @@ + +[package] +name = "curve25519-dalek-fuzz" +version = "0.0.1" +authors = ["Automatically generated"] +publish = false + +[package.metadata] +cargo-fuzz = true + +[dependencies.curve25519-dalek] +path = ".." +features = ["yolocrypto"] + +[dependencies.libfuzzer-sys] +git = "https://github.com/rust-fuzz/libfuzzer-sys.git" + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "decaf" +path = "fuzzers/decaf.rs" diff --git a/fuzz/fuzzers/decaf.rs b/fuzz/fuzzers/decaf.rs new file mode 100644 index 0000000..5199183 --- /dev/null +++ b/fuzz/fuzzers/decaf.rs @@ -0,0 +1,21 @@ +#![no_main] +#[macro_use] extern crate libfuzzer_sys; +extern crate curve25519_dalek; + +use curve25519_dalek::curve::ValidityCheck; +use curve25519_dalek::decaf::DecafPoint; +use curve25519_dalek::field::FieldElement; + +fuzz_target!(|data: &[u8]| { + if data.len() != 32 { + return; + } + let mut field_bytes = [0u8; 32]; + for (by, data) in field_bytes.iter_mut().zip(data.iter()) { + *by = *data; + } + let fe = FieldElement::from_bytes(&field_bytes); + let p = DecafPoint::elligator_decaf_flavour(&fe); + assert!(p.0.is_valid()); + p.compress(); +}); diff --git a/src/decaf.rs b/src/decaf.rs index a97347f..6a12816 100644 --- a/src/decaf.rs +++ b/src/decaf.rs @@ -264,7 +264,7 @@ impl DecafPoint { /// /// This method is not public because it's just used for hashing /// to a point -- proper elligator support is deferred for now. - fn elligator_decaf_flavour(r_0: &FieldElement) -> DecafPoint { + pub fn elligator_decaf_flavour(r_0: &FieldElement) -> DecafPoint { // Follows Appendix C of the Decaf paper. // Use n = 2 as the quadratic nonresidue so that n*x = x + x.