libsoliton/soliton/fuzz/fuzz_targets/fuzz_storage_encrypt_blob.rs
Kamal Tufekcic 1d99048c95
Some checks failed
CI / lint (push) Successful in 1m37s
CI / test-python (push) Successful in 1m49s
CI / test-zig (push) Successful in 1m39s
CI / test-wasm (push) Successful in 1m54s
CI / test (push) Successful in 14m44s
CI / miri (push) Successful in 14m18s
CI / build (push) Successful in 1m9s
CI / fuzz-regression (push) Successful in 9m9s
CI / publish (push) Failing after 1m10s
CI / publish-python (push) Failing after 1m46s
CI / publish-wasm (push) Has been cancelled
initial commit
Signed-off-by: Kamal Tufekcic <kamal@lo.sh>
2026-04-02 23:48:10 +03:00

35 lines
1.4 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#![no_main]
use libfuzzer_sys::fuzz_target;
use soliton::storage::{encrypt_blob, decrypt_blob, StorageKey, StorageKeyRing};
const FUZZ_KEY: [u8; 32] = [0x42; 32];
fuzz_target!(|data: &[u8]| {
if data.is_empty() {
return;
}
// Cap input size to prevent OOM on CI runners — compress_to_vec allocates
// working buffers proportional to input size (~2× for zstd).
if data.len() > 1_048_576 {
return;
}
let key = StorageKey::new(1, FUZZ_KEY).unwrap();
let compress = data[0] & 0x01 != 0;
let plaintext = &data[1..];
// encrypt_blob must never panic regardless of plaintext size, content, or
// compress flag. Exercises: capacity calculation, optional ruzstd compression,
// nonce generation, AAD construction, XChaCha20-Poly1305 encryption.
let blob = match encrypt_blob(&key, plaintext, "fuzz-channel", "fuzz-segment", compress) {
Ok(b) => b,
Err(_) => return,
};
// Roundtrip verification: decrypt must recover the original plaintext.
// Catches malformed blob layout, wrong AAD, header byte errors, and
// compression flag mismatches that a crash-only target would miss.
let keyring = StorageKeyRing::new(StorageKey::new(1, FUZZ_KEY).unwrap()).unwrap();
let recovered = decrypt_blob(&keyring, &blob, "fuzz-channel", "fuzz-segment")
.expect("decrypt_blob failed on freshly encrypted blob");
assert_eq!(&*recovered, plaintext, "roundtrip mismatch");
});