Cryptography

Cryptography rules for Python

23
Security Rules

Run All Cryptography Rules

pathfinder scan --ruleset python/cryptography --project .

Rules

RC4 (ARC4) Cipher Usage via cryptography Library

HIGH

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.

pythoncryptographyrc4arc4stream-cipherbroken-cryptoCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

RC4 (ARC4) Cipher Usage via PyCryptodome

HIGH

Detects use of the RC4 stream cipher through PyCryptodome's ARC4 module, which has known keystream biases and is prohibited by RFC 7465.

pythonpycryptodomerc4arc4stream-cipherbroken-cryptoCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Blowfish Cipher Usage via cryptography Library

HIGH

Detects use of the Blowfish cipher through the cryptography library, which has a 64-bit block size making it vulnerable to Sweet32 birthday attacks after approximately 32GB of data.

pythoncryptographyblowfishsweet32birthday-attack64-bit-blockCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Blowfish Cipher Usage via PyCryptodome

HIGH

Detects use of the Blowfish cipher through PyCryptodome, which has a 64-bit block size making it vulnerable to Sweet32 birthday attacks after approximately 32GB of data.

pythonpycryptodomeblowfishsweet32birthday-attack64-bit-blockCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

IDEA Cipher Usage via cryptography Library

HIGH

Detects use of the IDEA cipher through the cryptography library, which has a 64-bit block size making it vulnerable to Sweet32 birthday attacks and is deprecated in modern cryptographic standards.

pythoncryptographyidea64-bit-blocksweet32deprecated-cipherCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

RC2 (ARC2) Cipher Usage via PyCryptodome

HIGH

Detects use of the RC2/ARC2 cipher through PyCryptodome, which has a weak key schedule and an effective key length that can be reduced to 40 bits by protocol negotiation, making it vulnerable to brute-force attacks.

pythonpycryptodomerc2arc2weak-key-scheduleeffective-key-lengthCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

DES Cipher Usage via PyCryptodome

HIGH

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).

pythonpycryptodomedes56-bit-keybrute-forcebroken-cryptoCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Triple DES (3DES) Cipher Usage via PyCryptodome

MEDIUM

Detects use of Triple DES (3DES) through PyCryptodome, which has a 64-bit block size vulnerable to Sweet32 birthday attacks and was deprecated by NIST after 2023.

pythonpycryptodome3destriple-desdes3sweet32nist-deprecated64-bit-blockCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

XOR Cipher Usage via PyCryptodome

HIGH

Detects use of the XOR cipher through PyCryptodome, which is not encryption -- it is a weak cipher that provides no real confidentiality. XOR encryption is trivially breakable regardless of key and should never be used for protecting sensitive data.

pythonpycryptodomexorxor-cipherno-encryptiontrivially-reversibleCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Insecure MD5 Hash (cryptography)

MEDIUM

MD5 is cryptographically broken due to collision attacks since 2004. Use SHA-256 or SHA-3 instead.

pythoncryptographymd5weak-hashCWE-327OWASP-A02
CWE-327, CWE-328
Updated 2026-03-22

Insecure SHA1 Hash (cryptography)

MEDIUM

SHA-1 was broken by the SHAttered collision attack in 2017 and is deprecated by NIST for all digital signature uses. Use SHA-256 or SHA-3 instead.

pythoncryptographysha1weak-hashCWE-327OWASP-A02
CWE-327, CWE-328
Updated 2026-03-22

Insecure MD5 Hash (PyCryptodome)

MEDIUM

MD5 is cryptographically broken due to practical collision attacks since 2004. Use SHA-256 or SHA-3 via PyCryptodome instead.

pythonpycryptodomemd5weak-hashCWE-327OWASP-A02
CWE-327, CWE-328
Updated 2026-03-22

Insecure MD4 Hash (PyCryptodome)

HIGH

MD4 has been completely broken since 1995 with full collisions computable in seconds. It has no legitimate security use. Use SHA-256 or SHA-3 instead.

pythonpycryptodomemd4weak-hashCWE-327OWASP-A02
CWE-327, CWE-328
Updated 2026-03-22

Insecure MD2 Hash (PyCryptodome)

HIGH

MD2 is an obsolete 1989 algorithm with known preimage attacks, extremely poor performance, and no valid modern use case. Use SHA-256 or SHA-3 instead.

pythonpycryptodomemd2weak-hashCWE-327OWASP-A02
CWE-327, CWE-328
Updated 2026-03-22

Insecure SHA1 Hash (PyCryptodome)

MEDIUM

SHA-1 was broken by the SHAttered collision attack in 2017 and is deprecated by NIST for digital signatures. Use SHA-256 or SHA-3 via PyCryptodome instead.

pythonpycryptodomesha1weak-hashCWE-327OWASP-A02
CWE-327, CWE-328
Updated 2026-03-22

Insufficient RSA Key Size (cryptography lib)

HIGH

RSA key size is less than 2048 bits. NIST minimum is 2048 bits; 3072+ recommended for new systems.

pythoncryptographyrsakey-sizeCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

Insufficient DSA Key Size (cryptography lib)

HIGH

DSA key size is less than 2048 bits. NIST SP 800-131A requires 2048-bit minimum.

pythoncryptographydsakey-sizeCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

EC Key Generation Audit (cryptography lib)

MEDIUM

Audit all EC key generation calls — verify the curve is SECP256R1, SECP384R1, or stronger. Weak curves like SECP192R1 must not be used.

pythoncryptographyecelliptic-curvekey-sizeauditCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

Insufficient RSA Key Size (PyCryptodome)

HIGH

RSA key size is less than 3072 bits in PyCryptodome. Use RSA.generate(3072) or higher.

pythonpycryptodomersakey-sizeCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

Insufficient DSA Key Size (PyCryptodome)

HIGH

DSA key size is less than 2048 bits in PyCryptodome. Use DSA.generate(2048) or higher.

pythonpycryptodomedsakey-sizeCWE-326OWASP-A02
CWE-326
Updated 2026-03-22

ECB Mode Usage (cryptography lib)

HIGH

ECB mode is deterministic and leaks plaintext patterns. Use AES-GCM or AES-CTR+HMAC instead.

pythoncryptographyecbcipher-modeweak-modeCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

Unauthenticated Cipher Mode Audit (cryptography lib)

MEDIUM

CBC/CTR/CFB/OFB mode detected — these modes provide confidentiality but NOT authentication. Verify HMAC is applied or migrate to GCM.

pythoncryptographycipher-modeunauthenticatedcbcctrcfbofbCWE-327OWASP-A02
CWE-327
Updated 2026-03-22

AES Cipher Mode Audit (PyCryptodome)

MEDIUM

Audit all AES.new() calls — verify the cipher mode is MODE_GCM, MODE_EAX, MODE_SIV, or MODE_CCM. Unauthenticated modes (MODE_ECB, MODE_CBC without HMAC) must not be used.

pythonpycryptodomecipher-modeunauthenticatedaesauditCWE-327OWASP-A02
CWE-327
Updated 2026-03-22