Skip to content

Commit

Permalink
fuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
eschorn1 committed Jan 2, 2024
1 parent 5007999 commit 6ccd44a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/target
/Cargo.lock
/.idea
/.idea
/fuzz/corpus/
/fuzz/Cargo.lock
/fuzz/target/
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 = "fips203-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.fips203]
path = ".."

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

[profile.release]
debug = 1

[[bin]]
name = "fuzz_all"
path = "fuzz_targets/fuzz_all.rs"
test = false
doc = false
Binary file added fuzz/corpus/fuzz_all/seed1
Binary file not shown.
18 changes: 18 additions & 0 deletions fuzz/fuzz_targets/fuzz_all.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![no_main]
// rustup default nightly
// head -c 3200 </dev/urandom > seed1
// cargo fuzz run fuzz_all -j 4

use fips203::ml_kem_512;
use fips203::traits::{Decaps, Encaps, SerDes};
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: [u8; 1632+800+768]| { // dk_len + ek+len + ct_len = 3200

let ek = ml_kem_512::EncapsKey::try_from_bytes(data[0..800].try_into().unwrap()).unwrap();
let dk = ml_kem_512::DecapsKey::try_from_bytes(data[800..800+1632].try_into().unwrap()).unwrap();
let ct = ml_kem_512::CipherText::try_from_bytes(data[800+1632..800+1632+768].try_into().unwrap()).unwrap();

let _result = ek.try_encaps_vt();
let _result = dk.try_decaps_vt(&ct);
});

0 comments on commit 6ccd44a

Please sign in to comment.