Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-CRYPTO-SEC-004 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects calls to `Crypto.Cipher.ARC2.new()` from the PyCryptodome library. RC2 (also known as ARC2 to avoid trademark issues) is a 64-bit block cipher designed in 1987. Its effective key length can be configured independently of its nominal key size via the `effective_keylen` parameter, making it possible to silently operate with only 40 bits of security -- a level brute-forceable in minutes with commodity hardware.
RC2 was designed during the US export control era, when algorithms were deliberately weakened to 40-bit effective strength for export. Many protocol implementations default to or accept 40-bit effective key length. The algorithm also has a known-plaintext attack that is more efficient than brute force for certain key lengths. NIST SP 800-131A does not approve RC2 for any use case.
The rule matches `PyCryptoCipherARC2.method("new")`. Even at maximum effective key strength, RC2 retains a 64-bit block size (Sweet32 risk) and an aging design. There is no justification for RC2 in new code.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Effective Key Length Configurable Down to 40 Bits
PyCryptodome's ARC2.new() accepts an `effective_keylen` parameter that controls the actual security level independently of key length. The default and common export-era setting is 40 bits -- a search space of 2^40, which a modern GPU cluster can exhaust in minutes. Code that omits `effective_keylen` or sets it to a low value provides minimal encryption strength regardless of how many bytes the key contains.
64-Bit Block Size -- Sweet32 Birthday Attack
Like Blowfish, DES, and 3DES, RC2 uses 8-byte blocks. After approximately 32GB of ciphertext under the same key, block collisions become probable. In CBC mode, these collisions can be exploited to recover plaintext segments, particularly in long-lived encrypted channels or bulk data stores.
Known-Plaintext Attacks More Efficient Than Brute Force
RC2's key schedule has structural weaknesses that allow related-key attacks and known-plaintext attacks that reduce the effective search space below the nominal key length. At 128-bit key length, the algorithm has not been comprehensively vetted against modern cryptanalytic techniques the way AES has been through its public competition and standardization process.
Export Control Legacy -- Deliberate Weakening for Compliance
RC2 was designed in an era when US export regulations required algorithms to be no stronger than 40-bit effective key length for non-US users. The algorithm was intentionally designed with configurable weakening. Code that inherits or copies RC2 usage from old sources may unknowingly retain 40-bit effective key settings, providing nearly no cryptographic protection.
How to Fix
Recommended remediation steps
- 1Replace Crypto.Cipher.ARC2 with AES in GCM mode (AES.new(key, AES.MODE_GCM)) for authenticated encryption
- 2Use ChaCha20-Poly1305 via the cryptography library as an alternative AEAD cipher
- 3Never use RC2 with effective_keylen below 128 -- even at maximum strength, RC2 is not recommended for new code
- 4Re-encrypt any data stored under RC2 using AES-256-GCM and rotate all key material
- 5Audit any protocol negotiation code to ensure 40-bit or 56-bit effective key lengths cannot be selected
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule matches calls to `Crypto.Cipher.ARC2.new()` in PyCryptodome via the QueryType pattern `PyCryptoCipherARC2.method("new")`. It fires on any ARC2 cipher object instantiation regardless of the effective_keylen or mode parameter. Even at maximum effective key length, RC2 retains a 64-bit block size and is not approved for new use by any current standard. No sanitizer exclusions are defined.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
RC4 (ARC4) Cipher Usage via cryptography Library
Detects use of the RC4 stream cipher through the cryptography library's ARC4 algorithm, which has known keystream biases and is prohibited by RFC 7465.
RC4 (ARC4) Cipher Usage via PyCryptodome
Detects use of the RC4 stream cipher through PyCryptodome's ARC4 module, which has known keystream biases and is prohibited by RFC 7465.
DES Cipher Usage via PyCryptodome
Detects use of single DES through PyCryptodome, which has only a 56-bit key that has been publicly brute-forceable since 1999 and is disallowed by FIPS 46-3 (withdrawn 2005).
Frequently Asked Questions
Common questions about RC2 (ARC2) Cipher Usage via PyCryptodome
New feature
Get these findings posted directly on your GitHub pull requests
The RC2 (ARC2) Cipher Usage via PyCryptodome rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.