rules:
  # =============================================================================
  # CLOJURE POST-QUANTUM CRYPTOGRAPHIC VULNERABILITY RULES
  # =============================================================================
  # These rules detect cryptographic algorithms vulnerable to quantum attacks
  # using Shor's algorithm (asymmetric) or Grover's algorithm (symmetric/hash)
  # =============================================================================

  # ---------------------------------------------------------------------------
  # HASH FUNCTION VULNERABILITIES (Grover's Algorithm)
  # ---------------------------------------------------------------------------

  - id: clojure-use-of-md5-quantum
    patterns:
      - pattern-either:
          - pattern: (MessageDigest/getInstance "MD5")
          - pattern: (java.security.MessageDigest/getInstance "MD5")
          - pattern: (digest/md5 ...)
          - pattern: (buddy.core.hash/md5 ...)
          - pattern: (pandect.algo.md5/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.
    severity: ERROR
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: HIGH
      impact: HIGH
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 9
      post_quantum_alternatives:
        - "SHA-256"
        - "SHA-3"
        - "SPHINCS+"

  - id: clojure-use-of-sha1-quantum
    patterns:
      - pattern-either:
          - pattern: (MessageDigest/getInstance "SHA-1")
          - pattern: (MessageDigest/getInstance "SHA1")
          - pattern: (java.security.MessageDigest/getInstance "SHA-1")
          - pattern: (java.security.MessageDigest/getInstance "SHA1")
          - pattern: (digest/sha-1 ...)
          - pattern: (digest/sha1 ...)
          - pattern: (buddy.core.hash/sha1 ...)
          - pattern: (pandect.algo.sha1/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.
    severity: ERROR
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: HIGH
      impact: HIGH
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 9

  # ---------------------------------------------------------------------------
  # ASYMMETRIC CRYPTOGRAPHY VULNERABILITIES (Shor's Algorithm)
  # ---------------------------------------------------------------------------

  - id: clojure-use-of-rsa-quantum
    patterns:
      - pattern-either:
          - pattern: (KeyPairGenerator/getInstance "RSA")
          - pattern: (java.security.KeyPairGenerator/getInstance "RSA")
          - pattern: (KeyFactory/getInstance "RSA")
          - pattern: (Cipher/getInstance "RSA")
          - pattern: (buddy.core.keys/rsa-keypair ...)
    message: >-
      RSA is broken by Shor's algorithm regardless of key size. Migrate to ML-KEM (FIPS 203) for key
      encapsulation or ML-DSA (FIPS 204) for signatures.
    severity: WARNING
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: MEDIUM
      impact: CRITICAL
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8
      post_quantum_alternatives:
        - "CRYSTALS-Kyber (ML-KEM)"
        - "CRYSTALS-Dilithium (ML-DSA)"
        - "SPHINCS+"

  - id: clojure-use-of-dsa-quantum
    patterns:
      - pattern-either:
          - pattern: (KeyPairGenerator/getInstance "DSA")
          - pattern: (java.security.KeyPairGenerator/getInstance "DSA")
          - pattern: (Signature/getInstance "DSA")
    message: >-
      DH/DSA is broken by Shor's algorithm. Migrate to ML-KEM (FIPS 203) for key exchange or ML-DSA (FIPS
      204) for signatures.
    severity: WARNING
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: MEDIUM
      impact: CRITICAL
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8
      post_quantum_alternatives:
        - "CRYSTALS-Dilithium (ML-DSA)"
        - "FALCON"
        - "SPHINCS+"

  - id: clojure-use-of-ec-quantum
    patterns:
      - pattern-either:
          - pattern: (KeyPairGenerator/getInstance "EC")
          - pattern: (KeyPairGenerator/getInstance "ECDSA")
          - pattern: (java.security.KeyPairGenerator/getInstance "EC")
          - pattern: (KeyAgreement/getInstance "ECDH")
          - pattern: (buddy.core.keys/ec-keypair ...)
    message: >-
      ECC (ECDSA/ECDH) is broken by Shor's algorithm -- all curves (P-256, P-384, secp256k1, Curve25519)
      are equally vulnerable regardless of key size. Migrate: ECDSA  ML-DSA (FIPS 204)  ECDH  ML-KEM
      (FIPS 203).
    severity: WARNING
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: MEDIUM
      impact: CRITICAL
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8
      post_quantum_alternatives:
        - "CRYSTALS-Kyber (ML-KEM)"
        - "CRYSTALS-Dilithium (ML-DSA)"
        - "SPHINCS+"

  - id: clojure-use-of-dh-quantum
    patterns:
      - pattern-either:
          - pattern: (KeyPairGenerator/getInstance "DH")
          - pattern: (KeyPairGenerator/getInstance "DiffieHellman")
          - pattern: (KeyAgreement/getInstance "DH")
    message: >-
      DH/DSA is broken by Shor's algorithm. Migrate to ML-KEM (FIPS 203) for key exchange or ML-DSA (FIPS
      204) for signatures.
    severity: WARNING
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: MEDIUM
      impact: CRITICAL
      quantum_vulnerable: true
      quantum_attack: "Shor's Algorithm"
      quantum_risk_score: 8
      post_quantum_alternatives:
        - "CRYSTALS-Kyber (ML-KEM)"

  # ---------------------------------------------------------------------------
  # SYMMETRIC CRYPTOGRAPHY VULNERABILITIES (Grover's Algorithm)
  # ---------------------------------------------------------------------------

  - id: clojure-use-of-des-quantum
    patterns:
      - pattern-either:
          - pattern: (Cipher/getInstance "DES")
          - pattern: (Cipher/getInstance "DES/...")
          - pattern: (javax.crypto.Cipher/getInstance "DES")
          - pattern: (KeyGenerator/getInstance "DES")
          - pattern: (javax.crypto.KeyGenerator/getInstance "DES")
    message: >-
      DES has a 56-bit key -- completely broken classically and trivially quantum-vulnerable. Migrate to
      AES-256-GCM.
    severity: ERROR
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: HIGH
      impact: CRITICAL
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 10
      post_quantum_alternatives:
        - "AES-256"

  - id: clojure-use-of-3des-quantum
    patterns:
      - pattern-either:
          - pattern: (Cipher/getInstance "DESede")
          - pattern: (Cipher/getInstance "DESede/...")
          - pattern: (Cipher/getInstance "TripleDES")
          - pattern: (KeyGenerator/getInstance "DESede")
          - pattern: (javax.crypto.KeyGenerator/getInstance "DESede")
    message: >-
      3DES has 112-bit effective key strength -- broken classically and quantum-vulnerable. NIST deprecated
      3DES in 2023. Migrate to AES-256-GCM.
    severity: ERROR
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: MEDIUM
      impact: HIGH
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 8
      post_quantum_alternatives:
        - "AES-256"

  - id: clojure-use-of-rc4-quantum
    patterns:
      - pattern-either:
          - pattern: (Cipher/getInstance "RC4")
          - pattern: (Cipher/getInstance "ARCFOUR")
    message: >-
      RC4 is completely broken and banned by RFC 7465. Migrate to AES-256-GCM or ChaCha20-Poly1305.
    severity: ERROR
    languages: [clojure]
    metadata:
      category: security
      technology:
        - clojure
        - java
        - post-quantum
      cwe:
        - "CWE-327: Use of a Broken or Risky Cryptographic Algorithm"
      owasp:
        - A02:2021 - Cryptographic Failures
      confidence: HIGH
      likelihood: HIGH
      impact: CRITICAL
      quantum_vulnerable: true
      quantum_attack: "Classical + Grover's Algorithm"
      quantum_risk_score: 10
      post_quantum_alternatives:
        - "AES-256-GCM"
        - "ChaCha20-Poly1305"

  - id: clojure-use-of-aes128-quantum
    pattern: (.init $GEN 128)
    message: >-
      AES-128/192 provide only 64/96-bit quantum security under Grover's algorithm. Use AES-256 for
      128-bit post-quantum security.
    severity: WARNING
    languages: [clojure]
    metadata:
      category: security
      technology: [clojure, java, post-quantum]
      cwe: ["CWE-326: Inadequate Encryption Strength"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 7

  - id: clojure-use-of-aes192-quantum
    pattern: (.init $GEN 192)
    message: >-
      AES-128/192 provide only 64/96-bit quantum security under Grover's algorithm. Use AES-256 for
      128-bit post-quantum security.
    severity: WARNING
    languages: [clojure]
    metadata:
      category: security
      technology: [clojure, java, post-quantum]
      cwe: ["CWE-326: Inadequate Encryption Strength"]
      owasp: ["A02:2021 - Cryptographic Failures"]
      quantum_vulnerable: true
      quantum_attack: "Grover's Algorithm"
      quantum_risk_score: 6
