rules:
- id: hashlib-use-of-md5
  message: >-
    MD5 is cryptographically broken and quantum-weakened by Grover's algorithm -- effective security
    drops from 128 to 64 bits. Use SHA-256, SHA-384, or SHA-3.
  metadata:
    cwe:
    - 'CWE-327: Use of a Broken or Risky Cryptographic Algorithm'
    - 'CWE-328: Use of Weak Hash'
    owasp:
    - A02:2021 - Cryptographic Failures
    - A03:2017 - Sensitive Data Exposure
    category: security
    technology:
    - python
    - hashlib
    - pycryptodome
    subcategory:
    - vuln
    likelihood: HIGH
    impact: HIGH
    confidence: HIGH
    quantum_vulnerable: true
    quantum_attack: "Grover's Algorithm"
    quantum_risk_score: 9
    post_quantum_alternatives:
    - "SHA-256"
    - "SHA-3 (Keccak)"
    - "BLAKE2b/BLAKE3"
    references:
    - https://docs.python.org/3/library/hashlib.html
    - https://csrc.nist.gov/projects/hash-functions
    - https://csrc.nist.gov/projects/post-quantum-cryptography
  severity: ERROR
  languages: [python]
  pattern-either:
    - pattern: hashlib.md5(...)
    - pattern: Crypto.Hash.MD5.new(...)
    - pattern: Cryptodome.Hash.MD5.new(...)

- id: hashlib-use-of-sha1
  message: >-
    SHA-1 is deprecated and quantum-weakened by Grover's algorithm -- effective security drops from 160
    to 80 bits. Use SHA-256, SHA-384, or SHA-3.
  metadata:
    cwe:
    - 'CWE-327: Use of a Broken or Risky Cryptographic Algorithm'
    - 'CWE-328: Use of Weak Hash'
    owasp:
    - A02:2021 - Cryptographic Failures
    - A03:2017 - Sensitive Data Exposure
    category: security
    technology:
    - python
    - hashlib
    - pycryptodome
    subcategory:
    - vuln
    likelihood: HIGH
    impact: HIGH
    confidence: HIGH
    quantum_vulnerable: true
    quantum_attack: "Grover's Algorithm"
    quantum_risk_score: 9
    post_quantum_alternatives:
    - "SHA-256"
    - "SHA-3 (Keccak)"
    - "BLAKE2b/BLAKE3"
    references:
    - https://docs.python.org/3/library/hashlib.html
    - https://csrc.nist.gov/projects/hash-functions
    - https://csrc.nist.gov/projects/post-quantum-cryptography
  severity: ERROR
  languages: [python]
  pattern-either:
    - pattern: hashlib.sha1(...)
    - pattern: hashlib.sha(...)
    - pattern: Crypto.Hash.SHA.new(...)
    - pattern: Crypto.Hash.SHA1.new(...)
    - pattern: Cryptodome.Hash.SHA.new(...)
    - pattern: Cryptodome.Hash.SHA1.new(...)

- id: hashlib-use-of-md4
  message: >-
    MD4 is completely broken classically and quantum-weakened by Grover's algorithm. Use SHA-256,
    SHA-384, or SHA-3.
  metadata:
    cwe:
    - 'CWE-327: Use of a Broken or Risky Cryptographic Algorithm'
    - 'CWE-328: Use of Weak Hash'
    owasp:
    - A02:2021 - Cryptographic Failures
    - A03:2017 - Sensitive Data Exposure
    category: security
    technology:
    - python
    - hashlib
    - pycryptodome
    subcategory:
    - vuln
    likelihood: HIGH
    impact: HIGH
    confidence: HIGH
    quantum_vulnerable: true
    quantum_attack: "Grover's Algorithm"
    quantum_risk_score: 9
    post_quantum_alternatives:
    - "SHA-256"
    - "SHA-3 (Keccak)"
    - "BLAKE2b/BLAKE3"
    references:
    - https://docs.python.org/3/library/hashlib.html
    - https://csrc.nist.gov/projects/hash-functions
    - https://csrc.nist.gov/projects/post-quantum-cryptography
  severity: ERROR
  languages: [python]
  pattern-either:
    - pattern: hashlib.md4(...)
    - pattern: Crypto.Hash.MD4.new(...)
    - pattern: Cryptodome.Hash.MD4.new(...)
