-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add fuzz target for unhardened key derivation, signing and verification
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
corpus | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
|
||
}); |