aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_targets
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/fuzz_targets')
-rw-r--r--fuzz/fuzz_targets/zears_vs_aez.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/fuzz/fuzz_targets/zears_vs_aez.rs b/fuzz/fuzz_targets/zears_vs_aez.rs
new file mode 100644
index 0000000..eda644d
--- /dev/null
+++ b/fuzz/fuzz_targets/zears_vs_aez.rs
@@ -0,0 +1,37 @@
+#![no_main]
+
+use libfuzzer_sys::fuzz_target;
+
+use arbitrary::Arbitrary;
+use zears::Aez;
+
+#[derive(Debug, Arbitrary)]
+struct Parameters<'a> {
+ key: &'a [u8],
+ nonce: &'a [u8],
+ ad: Option<&'a [u8]>,
+ tau: u32,
+ message: &'a [u8],
+}
+
+fuzz_target!(|data: Parameters| {
+ // Limitations stem from AEZ's underlying C library
+ if data.nonce.len() >= 1
+ && data.nonce.len() <= 16
+ && data.ad.map(|x| x.len()).unwrap_or(0) <= 16
+ && data.tau <= 16
+ && data.message.len() <= u32::MAX.try_into().unwrap()
+ && (!data.message.is_empty() || data.tau > 0)
+ {
+ let ad = match data.ad {
+ Some(ad) => &[ad] as &[&[u8]],
+ None => &[],
+ };
+ let actual = Aez::new(data.key).encrypt(data.nonce, ad, data.tau, data.message);
+
+ let mut expected = vec![0; data.message.len() + data.tau as usize];
+ aez::Aez::new(data.key).encrypt(data.nonce, data.ad, data.message, &mut expected);
+
+ assert_eq!(actual, expected);
+ }
+});