-
Notifications
You must be signed in to change notification settings - Fork 175
Implement implicit rejection for PKCS#1 v1.5 decryption to prevent timing attacks #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…gnatures and variable initializations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements implicit rejection for PKCS#1 v1.5 RSA decryption to mitigate Bleichenbacher/Marvin timing attacks. Instead of returning errors on invalid padding (which leaks timing information), the implementation returns a deterministic synthetic plaintext derived from the ciphertext using HMAC-SHA256-based PRF keyed by the private key. This prevents attackers from distinguishing valid from invalid ciphertexts based on timing or error responses.
Key changes:
- Added new
ImplicitRejectionDecryptortrait with methods for implicit rejection decryption with optional blinding - Implemented cryptographic primitives for key derivation and PRF-based synthetic plaintext generation
- Added comprehensive test coverage for various edge cases and security properties
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| Cargo.toml | Adds optional hmac dependency and new implicit-rejection feature flag |
| Cargo.lock | Updates lock file with hmac dependency |
| src/traits/encryption.rs | Defines ImplicitRejectionDecryptor trait with methods for constant-time decryption |
| src/traits.rs | Re-exports the new trait when feature is enabled |
| src/pkcs1v15/decrypting_key.rs | Implements ImplicitRejectionDecryptor trait for DecryptingKey |
| src/pkcs1v15.rs | Adds decrypt_implicit_rejection function and comprehensive test suite |
| src/algorithms/pkcs1v15.rs | Implements core cryptographic primitives: PRF, key derivation, and constant-time unpadding logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…citRejectionDecryptor trait
Removed mention of the Marvin Attack vulnerability.
This pull request introduces support for implicit rejection in PKCS#1 v1.5 RSA decryption to mitigate Bleichenbacher/Marvin timing attacks. The main change is the addition of a new feature,
implicit-rejection, which uses a deterministic synthetic plaintext on padding errors, preventing attackers from distinguishing valid from invalid ciphertexts based on timing. This involves new cryptographic primitives, trait extensions, and key derivation logic, all gated behind the feature flag.Implicit Rejection Feature for PKCS#1 v1.5 Decryption:
hmacand updated the feature set inCargo.tomlto supportimplicit-rejection, which also requiressha2. [1] [2]ImplicitRejectionDecryptortrait insrc/traits/encryption.rs, providing methods for decryption with implicit rejection and optional blinding, along with documentation and feature gating.ImplicitRejectionDecryptortrait forDecryptingKeyinsrc/pkcs1v15/decrypting_key.rs, enabling usage of the new decryption methods. [1] [2]src/algorithms/pkcs1v15.rs, providing the cryptographic operations required for the new feature. [1] [2]ImplicitRejectionDecryptortrait insrc/traits.rswhen the feature is enabled.Ref: #626