Skip to content

Mitigation for timing attack in PKCS1v15 padding validation#1335

Open
Coralesoft wants to merge 1 commit intoweidai11:masterfrom
Coralesoft:marvin-attack-fix
Open

Mitigation for timing attack in PKCS1v15 padding validation#1335
Coralesoft wants to merge 1 commit intoweidai11:masterfrom
Coralesoft:marvin-attack-fix

Conversation

@Coralesoft
Copy link
Copy Markdown

@Coralesoft Coralesoft commented Oct 26, 2025

This PR addresses the Marvin Attack timing vulnerability reported in #1247.

Replaces variable-time separator search with constant-time implementation to mitigate the Marvin Attack (CVE-2023-50979). Uses bitwise operations to avoid data-dependent timing leaks.

What's fixed:

  • Variable-time while loop during separator search
  • Early return on invalid padding detection
  • Variable-length memcpy operation

Implementation:

  • Constant-time for loop that always scans all bytes
  • Bitwise mask operations instead of conditional branches
  • Single return point to ensure consistent execution time

Testing:
The fix maintains full backward compatibility with existing PKCS#1 v1.5 functionality.
I've tested that RSA encryption/decryption still works correctly while eliminating the timing side channels.

Let me know if you'd like me to make any changes or if you have questions. I can supply test harnesses if needed.

Thanks
Colin

Fixes #1247

Replaces variable-time separator search with constant-time implementation to mitigate Marvin Attack (CVE-2022-4304). Uses bitwise operations to avoid data-dependent timing leaks.

Fixes three timing vulnerabilities:
  - Variable-time while loop
  - Early return on invalid padding
  - Variable-length memcpy operation

Fixes weidai11#1247
@Coralesoft Coralesoft changed the title Fix timing attack in PKCS1v15 padding validation Mitigation for timing attack in PKCS1v15 padding validation Oct 28, 2025
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.

Crypto++ vulnerable to the Marvin Attack

2 participants