feal-differential-cryptanalysis
FEAL Differential Cryptanalysis
Overview
This skill provides structured guidance for implementing differential cryptanalysis attacks on FEAL and similar Feistel-network block ciphers. Differential cryptanalysis exploits how specific input differences propagate through cipher rounds with predictable probabilities, enabling key recovery.
Core Principles
Theory Before Implementation
Before writing any attack code:
- Understand the cipher structure - Identify the Feistel network layout, round function (F-function), key schedule, and number of rounds
- Study the F-function's differential properties - Determine which input differences produce which output differences with high probability
- Identify differential characteristics - Find high-probability differential trails through the cipher rounds
- Formulate the attack equations - Understand how key bits relate to observable output differences
What Makes Differential Cryptanalysis Work
The attack exploits that for the correct key, decrypted intermediate values represent actual cipher states that satisfy the round function equations. For incorrect keys, these values are essentially random garbage that won't satisfy the differential relationships.
The distinguishing property is consistency with the Feistel structure, not statistical measures like entropy, variance, or Hamming weight.
Approach
Step 1: Analyze the Cipher
- Map out the complete cipher structure (rounds, key mixing, F-function)
- Identify which key bits affect which intermediate computations
- Determine what intermediate values can be computed given partial key guesses
- Document dependencies between plaintext, ciphertext, and key bits
Step 2: Study Differential Properties
- Analyze the F-function for differential characteristics
- Find input XOR differences that produce predictable output XOR differences
- Calculate probabilities for each differential characteristic
- Identify high-probability multi-round differential trails
Step 3: Design Chosen Plaintexts
- Select plaintext pairs with specific XOR differences that exploit identified differentials
- Ensure plaintext differences align with high-probability characteristics
- Document the theoretical basis for each plaintext choice
- Avoid arbitrary plaintexts without theoretical justification
Step 4: Implement the Key Recovery
- For each key candidate, compute the intermediate value using partial decryption
- Check if the computed values satisfy the expected differential relationships
- Count how many plaintext pairs "vote" for each key candidate
- The correct key will have significantly more consistent pairs
Step 5: Validate Incrementally
- Verify each component independently before combining
- For known test cases, confirm intermediate values match expected states
- Compare behavior of correct vs incorrect keys directly
- Build confidence in each attack stage before proceeding
Verification Strategies
Direct Comparison Method
When debugging, compute intermediate values for both correct and incorrect keys:
- Use a known key to generate test cases
- Compute intermediate states for the correct key
- Compute intermediate states for several incorrect keys
- Identify the distinguishing property empirically
Equation Verification
For each plaintext pair and key guess:
- Compute the alleged intermediate state
- Check if state satisfies the expected differential equation
- Track pass/fail counts per key candidate
- Correct key should have near-100% pass rate for good differentials
Sanity Checks
- With random keys, attack should fail (return wrong answer)
- With oracle access, intermediate computations should match actual cipher states
- Reducing to fewer rounds should make attack easier
- Using more plaintext pairs should improve reliability
Common Pitfalls
Pitfall 1: Statistical Heuristics Instead of Differential Equations
Wrong approach: Using entropy, Hamming weight variance, collision counting, or other statistical measures to distinguish correct from incorrect keys.
Why it fails: These measures often show similar values for correct and incorrect keys. The distinguishing property is structural (satisfying differential equations), not statistical.
Correct approach: Check whether computed intermediate values satisfy the expected differential relationships derived from the cipher's structure.
Pitfall 2: Arbitrary Plaintext Selection
Wrong approach: Using plaintexts like i * 0x0101010101010101 or random values without theoretical basis.
Why it fails: Differential attacks require specific plaintext XOR differences that create useful differentials through the cipher.
Correct approach: Choose plaintext pairs where the XOR difference matches high-probability differential characteristics of the F-function.
Pitfall 3: Repeated Heuristic Cycling
Wrong approach: Trying many different scoring functions (entropy, variance, min/max, collisions) hoping one works.
Why it fails: Without understanding why each approach fails, new attempts are equally likely to fail.
Correct approach: When an approach fails, analyze why. Compare correct vs incorrect key behavior directly. Build understanding incrementally.
Pitfall 4: Ignoring Cipher-Specific Literature
Wrong approach: Implementing a generic "differential attack" without studying FEAL's specific weaknesses.
Why it fails: FEAL has well-documented differential characteristics. Ignoring this domain knowledge means reinventing the wheel poorly.
Correct approach: Research existing differential attacks on the specific cipher. Understand which differentials have been proven effective.
Pitfall 5: Incomplete Partial Decrypt Verification
Wrong approach: Assuming partial decryption code is correct without verification against known intermediate states.
Why it fails: Bugs in partial decryption produce meaningless intermediate values, making the attack impossible regardless of the distinguisher.
Correct approach: For a known key, verify that computed intermediate values match the actual cipher's internal states at each round.
Key Insights for FEAL-Specific Attacks
-
Round key independence: Different round keys may affect different intermediate values. Identify which computations depend on the target key bits.
-
Seed constraints: If key generation uses a small seed space (e.g., 16-bit), exhaustive search is feasible but still requires a reliable distinguisher.
-
L/R state separation: In Feistel networks, the left and right halves have different dependencies. Exploit this to isolate key bit effects.
-
F-function weaknesses: FEAL's F-function has known differential weaknesses. Input difference
0x80800000through the F-function has specific high-probability output differences.
Debugging Checklist
When the attack returns incorrect results:
- Verify partial decryption computes correct intermediate values for known keys
- Confirm plaintext pairs have the intended XOR differences
- Check that differential equations correctly model the round structure
- Compare voting counts between correct and incorrect keys with debug output
- Verify F-function implementation matches the cipher specification
- Test with reduced rounds to isolate where the attack breaks down