Skip to content

Commit

Permalink
add fuzz target for unhardened key derivation, signing and verification
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Nov 1, 2022
1 parent b603aee commit 9c717c4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chia-bls/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
corpus
artifacts
25 changes: 25 additions & 0 deletions chia-bls/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "chia-bls-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.chia-bls]
path = ".."

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

[[bin]]
name = "derive"
path = "fuzz_targets/derive.rs"
test = false
doc = false
32 changes: 32 additions & 0 deletions chia-bls/fuzz/fuzz_targets/derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use chia_bls::secret_key::SecretKey;
use chia_bls::public_key::PublicKey;
use chia_bls::signature::{sign, verify};
use chia_bls::derivable_key::DerivableKey;

fuzz_target!(|data: &[u8]| {
if data.len() < 32 {
return;
}

let sk = SecretKey::from_seed(data);
let pk = sk.public_key();

// round-trip SecretKey
let bytes = sk.to_bytes();
assert_eq!(sk, SecretKey::from_bytes(&bytes).unwrap());

// round-trip PublicKey
let bytes = pk.to_bytes();
assert_eq!(pk, PublicKey::from_bytes(&bytes).unwrap());

// unhardened derivation
let sk1 = sk.derive_unhardened(1337);
let pk1 = pk.derive_unhardened(1337);

let sig = sign(&sk1, b"foobar");
assert!(verify(&sig, &pk1, b"foobar"));

});

0 comments on commit 9c717c4

Please sign in to comment.