feat(fuzzing): Add initial set of fuzzing targets

These targets can be used with rust nightly and cargo-fuzz to fuzz
several bits of Rosenpass's API. Fuzzing is an automated way of
exploring code paths that may not be hit in unit tests or normal
operation. For example the `handle_msg` target exposed the DoS condition
fixed in 0.2.1.

The other targets focus on the FFI with libsodium and liboqs.

Co-authored-by: Karolin Varner <karo@cupdev.net>
This commit is contained in:
Morgan Hill
2023-11-19 16:52:44 +01:00
committed by Karolin Varner
parent 86300ca936
commit a49254a021
10 changed files with 1501 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#![no_main]
extern crate arbitrary;
extern crate rosenpass;
use libfuzzer_sys::fuzz_target;
use rosenpass::sodium::mac_into;
use rosenpass_sodium::init as sodium_init;
#[derive(arbitrary::Arbitrary, Debug)]
pub struct Blake2b {
pub key: [u8; 32],
pub data: Box<[u8]>,
}
fuzz_target!(|input: Blake2b| {
sodium_init().unwrap();
let mut out = [0u8; 32];
mac_into(&mut out, &input.key, &input.data).unwrap();
});