CCT: Cryptography Attacks

A breakdown of the major attack techniques used against cryptographic systems — from known-plaintext and chosen-ciphertext attacks to brute force, birthday attacks, timing attacks, and rubber hose coercion.

Why Cryptography Gets Attacked

Cryptography is designed to protect data in transit and at rest by making it computationally infeasible to access without the correct key. But cryptographic systems are not invincible — they can be attacked through:

  • Weaknesses in the algorithm itself
  • Poor implementation choices
  • Exposure of key material
  • Side-channel information leakage
  • Physical coercion

Understanding cryptography attacks is essential for implementing systems that are genuinely secure, not just theoretically strong.


Known-Plaintext Attack

In a known-plaintext attack, the attacker has access to both a piece of plaintext and its corresponding ciphertext. Using this pair, they attempt to deduce the encryption key used to generate the ciphertext, which can then be used to decrypt other messages encrypted with the same key.

md
Attacker has:
  Plaintext:   "HELLO"
  Ciphertext:  "X7K9Q"

Goal: Deduce the key used to transform HELLO → X7K9Q
Result: Key recovered → all other ciphertexts can be decrypted

This attack is particularly effective against weak or historical cipher systems.


Chosen-Ciphertext Attack

In a chosen-ciphertext attack, the attacker selects a set of ciphertexts of their own choosing and obtains their corresponding plaintexts (typically through access to a decryption oracle). By analyzing the patterns between chosen ciphertexts and their plaintexts, the attacker can deduce the key.

This attack is relevant when an attacker has temporary access to a decryption service but not the key itself.


Chosen-Key Attack

In a chosen-key attack, the attacker typically reduces the complexity of breaking an n-bit key cipher from 2^n operations to 2^(n/2) operations by exploiting structural weaknesses in the cipher. This attack targets the key schedule or key derivation mechanism.


Brute-Force Attack

A brute-force attack systematically tries every possible key combination until the correct one is found.

md
Key Space for n-bit key:
2^128 combinations for 128-bit key
2^256 combinations for 256-bit key

Modern hardware can attempt billions of keys per second,
but even so, 256-bit keys remain computationally infeasible to brute-force.

Brute-force is the last resort when all other techniques fail. It is effective against weak passwords and short key lengths but impractical against modern, properly implemented cryptography.


Birthday Attack

A birthday attack is a class of brute-force attacks against cryptographic hash functions that exploits the birthday paradox — a mathematical phenomenon where collision probability grows much faster than intuition suggests.

The attack targets hash functions that are not collision resistant: two different inputs (P1 and P2) that produce the same hash value (H(P1) = H(P2)).

md
Birthday Paradox Applied to Hashing:
In a room of 23 people, there is a 50% chance two share a birthday.
In a hash space of n bits, collisions become probable after ~2^(n/2) operations.

128-bit hash: collision probable after ~2^64 operations (feasible with modern hardware)
256-bit hash: collision probable after ~2^128 operations (still infeasible)

MD5 and SHA-1 are vulnerable to birthday attacks and should not be used for security-critical applications.


Timing Attack

A timing attack exploits differences in the time taken to perform cryptographic operations. By repeatedly measuring the exact execution time of operations like modular exponentiation, an attacker can make inferences about the secret key.

md
Different key bits cause different execution paths
→ different operation times
→ measured time differences reveal bits of the key

Timing attacks are a class of side-channel attacks — they do not attack the mathematics of the algorithm but instead exploit physical implementation characteristics.

Defenses include: constant-time implementations and adding random delays.


Man-in-the-Middle Attack on Cryptographic Key Exchange

A MITM attack on public-key cryptography intercepts the key exchange process before communication begins.

md
Normal Key Exchange:
Alice --[Public Key A]--> Bob
Bob --[Public Key B]--> Alice
(secure encrypted channel established)

MITM Attack:
Alice --[Public Key A]--> Attacker --[Fake Key M]--> Bob
Bob --[Public Key B]--> Attacker --[Fake Key M]--> Alice

Result:
- Alice encrypts to attacker (thinking it's Bob)
- Bob encrypts to attacker (thinking it's Alice)
- Attacker decrypts, reads, re-encrypts, and forwards everything

This attack is why certificate authorities and public key infrastructure (PKI) exist — to verify that a public key genuinely belongs to its claimed owner.


Rubber Hose Attack

The rubber hose attack is not a mathematical or technical attack. It refers to extracting cryptographic secrets — such as a password to an encrypted file — from a person through coercion or torture.

The name is darkly humorous but the concept is serious: even the strongest encryption algorithm provides no protection if an adversary can physically compel a person to reveal the key.

md
Best cryptographic defense:
A person who does not know the key cannot reveal it
→ Split key custody
→ Key escrow
→ Plausible deniability (e.g., VeraCrypt hidden volumes)


Summary: Cryptography Attack Comparison

AttackTargetMethod
Known-PlaintextKey recoveryUses known message pairs to deduce the key
Chosen-CiphertextKey recoveryObtains plaintexts for attacker-chosen ciphertexts
Chosen-KeyKey weaknessReduces breaking complexity to 2^(n/2)
Brute-ForceKey or passwordTries all possible combinations
Birthday AttackHash collisionsExploits probability of hash collisions
Timing AttackKey bits via timingMeasures operation execution time differences
MITMKey exchangeIntercepts and replaces public keys
Rubber HoseKey materialPhysical coercion to extract secrets from a person

Cryptographic Best Practices

Understanding these attacks leads directly to mitigation strategies:

  • Use modern algorithms: AES-256 for symmetric encryption, RSA-4096 or ECC for asymmetric
  • Use strong, collision-resistant hash functions: SHA-256 or SHA-3 (avoid MD5 and SHA-1)
  • Implement constant-time operations in cryptographic code to prevent timing attacks
  • Use authenticated key exchange with certificate validation to prevent MITM
  • Store keys in hardware security modules (HSMs) to prevent extraction
  • Apply key splitting and threshold schemes where physical coercion is a concern