Skip to content

Commit

Permalink
tests: add fuzzing of secret key
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Aug 27, 2023
1 parent 1e6f603 commit 3710e60
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
27 changes: 27 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "tari_crypto-fuzz"
version = "0.0.0"
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.tari_crypto]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "keys"
path = "fuzz_targets/keys.rs"
test = false
doc = false
24 changes: 24 additions & 0 deletions fuzz/fuzz_targets/keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![no_main]

use libfuzzer_sys::fuzz_target;
use tari_crypto::ristretto::RistrettoSecretKey;
use tari_crypto::tari_utilities::ByteArray;

fuzz_target!(|data: &[u8]| {

if data.len() < 32 {
return;
}
match RistrettoSecretKey::from_bytes(&data[0..32]) {
Ok(r) => {
// WIP: this should fail because we do a mod.
// We should implement from_bytes_canonical
assert_eq!(&r.to_vec(), &data[0..32]);
}
Err(e) => {
// This is unlikely to fail
todo!()
}
}

});

0 comments on commit 3710e60

Please sign in to comment.