Skip to content

Tighten Kyber decrypt parsing and deterministic malformed-ciphertext errors#184

Merged
Psychevus merged 4 commits intomainfrom
codex/fix-kyber-ciphertext-parsing-errors
Feb 25, 2026
Merged

Tighten Kyber decrypt parsing and deterministic malformed-ciphertext errors#184
Psychevus merged 4 commits intomainfrom
codex/fix-kyber-ciphertext-parsing-errors

Conversation

@Psychevus
Copy link
Copy Markdown
Owner

@Psychevus Psychevus commented Feb 25, 2026

Motivation

  • Ensure kyber_decrypt strictly validates ciphertext structure to prevent out-of-bounds parsing and avoid accepting truncated inputs.
  • Make error reporting deterministic: malformed ciphertext must raise DecryptionError rather than leaking lower-level exceptions like ValueError or InvalidTag.

Description

  • Enforced a minimum ciphertext length by requiring ct_size + 16 + 12 + 16 (KEM ciphertext + salt(16) + nonce(12) + tag(16)) before parsing.
  • Wrapped KEM decapsulation (alg.decrypt) errors and AES-GCM decryption errors in DecryptionError("Invalid ciphertext") to normalize failure reporting.
  • Added tests that assert malformed inputs produce DecryptionError, and imported DecryptionError into the test module.
  • New tests cover short ciphertext rejection and corruption of the nonce and tag regions in the Kyber payload.

Testing

  • Ran pytest -q tests/test_pqc.py, which completed successfully with 6 passed.
  • New negative tests added: short ciphertext path and corrupted nonce/tag paths each assert DecryptionError is raised (these tests passed).

@Psychevus Psychevus removed the codex label Feb 25, 2026
@Psychevus Psychevus merged commit 9f48dbe into main Feb 25, 2026
6 checks passed
@Psychevus Psychevus deleted the codex/fix-kyber-ciphertext-parsing-errors branch February 25, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant