-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #660 from cryspen/franziskus/ml-kem-fuzzing
Basic ml kem fuzzing
- Loading branch information
Showing
8 changed files
with
177 additions
and
33 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
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,35 @@ | ||
[package] | ||
name = "libcrux-ml-kem-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4" | ||
|
||
[dependencies.libcrux-ml-kem] | ||
path = ".." | ||
|
||
[[bin]] | ||
name = "keygen" | ||
path = "fuzz_targets/keygen.rs" | ||
test = false | ||
doc = false | ||
bench = false | ||
|
||
[[bin]] | ||
name = "encaps" | ||
path = "fuzz_targets/encaps.rs" | ||
test = false | ||
doc = false | ||
bench = false | ||
|
||
[[bin]] | ||
name = "decaps" | ||
path = "fuzz_targets/decaps.rs" | ||
test = false | ||
doc = false | ||
bench = 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,25 @@ | ||
#![no_main] | ||
|
||
use libcrux_ml_kem::{mlkem768, ENCAPS_SEED_SIZE, KEY_GENERATION_SEED_SIZE}; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < KEY_GENERATION_SEED_SIZE + ENCAPS_SEED_SIZE { | ||
// Not enough entropy | ||
return; | ||
} | ||
|
||
let mut randomness = [0u8; KEY_GENERATION_SEED_SIZE]; | ||
randomness.copy_from_slice(&data[..KEY_GENERATION_SEED_SIZE]); | ||
|
||
let key_pair = mlkem768::generate_key_pair(randomness); | ||
|
||
let mut randomness = [0u8; ENCAPS_SEED_SIZE]; | ||
randomness.copy_from_slice( | ||
&data[KEY_GENERATION_SEED_SIZE..KEY_GENERATION_SEED_SIZE + ENCAPS_SEED_SIZE], | ||
); | ||
|
||
let (ct, _ss) = mlkem768::encapsulate(key_pair.public_key(), randomness); | ||
|
||
let _ = core::hint::black_box(mlkem768::decapsulate(key_pair.private_key(), &ct)); | ||
}); |
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,23 @@ | ||
#![no_main] | ||
|
||
use libcrux_ml_kem::{mlkem768, ENCAPS_SEED_SIZE, KEY_GENERATION_SEED_SIZE}; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
if data.len() < KEY_GENERATION_SEED_SIZE + ENCAPS_SEED_SIZE { | ||
// Not enough entropy | ||
return; | ||
} | ||
|
||
let mut randomness = [0u8; KEY_GENERATION_SEED_SIZE]; | ||
randomness.copy_from_slice(&data[..KEY_GENERATION_SEED_SIZE]); | ||
|
||
let key_pair = mlkem768::generate_key_pair(randomness); | ||
|
||
let mut randomness = [0u8; ENCAPS_SEED_SIZE]; | ||
randomness.copy_from_slice( | ||
&data[KEY_GENERATION_SEED_SIZE..KEY_GENERATION_SEED_SIZE + ENCAPS_SEED_SIZE], | ||
); | ||
|
||
let _ = core::hint::black_box(mlkem768::encapsulate(key_pair.public_key(), randomness)); | ||
}); |
Oops, something went wrong.