Skip to content

test(fuzz): add coverage for derive_encrypt and key_derivation parsing#402

Open
mmorrissette-devolutions wants to merge 2 commits into
masterfrom
feat/fuzz-derive-encrypt-coverage
Open

test(fuzz): add coverage for derive_encrypt and key_derivation parsing#402
mmorrissette-devolutions wants to merge 2 commits into
masterfrom
feat/fuzz-derive-encrypt-coverage

Conversation

@mmorrissette-devolutions

Copy link
Copy Markdown
Contributor

Summary

Adds fuzz coverage for three untrusted-byte paths in the derive_encrypt and key_derivation modules that previously had no fuzz target.

The derive_encrypt module was entirely unfuzzed, and DerivationParameters deserialization — another public TryFrom<&[u8]> parser of attacker-controllable bytes — had no coverage.

New targets

Target Path covered
kdf_encrypted_data_deserialization KdfEncryptedData::try_from(&[u8])
derivation_parameters_deserialization DerivationParameters::try_from(&[u8])
decrypt_with_password encrypt_with_password_and_aaddecrypt_with_password_and_aad round-trip

For decrypt_with_password, the Argon2 parameters are clamped (length/lanes/memory/iterations + small salt, same approach as the existing derive_key_argon2 target) so key derivation stays cheap enough for fuzzing — an unclamped Arbitrary value could request billions of iterations and blow the per-target time budget.

The CI action discovers targets via cargo fuzz list, so no workflow change is needed.

Testing

Built and ran all three targets in WSL (nightly + cargo-fuzz 0.13.1), no crashes:

  • kdf_encrypted_data_deserialization — 18.6M runs
  • derivation_parameters_deserialization — 19.4M runs
  • decrypt_with_password — full KDF round-trip, no timeout

Add three fuzz targets covering untrusted-byte paths that previously had
no coverage:

- kdf_encrypted_data_deserialization: KdfEncryptedData::try_from(&[u8])
- derivation_parameters_deserialization: DerivationParameters::try_from(&[u8])
- decrypt_with_password: encrypt/decrypt round-trip via KdfEncryptedData,
  with Argon2 parameters clamped to keep key derivation cheap enough for
  fuzzing.

CI discovers targets via `cargo fuzz list`, so no workflow change is needed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29a942193b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread fuzz/fuzz_targets/derive_encrypt/decrypt_with_password.rs Outdated
A SecretKey requires exactly 32 raw bytes, so an arbitrary Argon2 output
length (previously clamped to 1..128) made encrypt_with_password_and_aad
fail before the decrypt path for ~127/128 of inputs. Pin the length to 32
so the password-decrypt path is actually exercised; arbitrary output
lengths remain covered by the derive_key_argon2 target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants