☕
Pause for minutes until .
Remaining:
Pius Walter
T4INF1202: Kryptologie
Part 7: LFSR stream ciphers and their cryptanalysis
2026-05-13
Table of Contents
Recap
Basic security assurance
  • As we've discussed numerous times, the two critical pillars ciphers rely on are confusion and diffusion
  • One implication of having good diffusion is a resulting avalanche property of the cipher
  • Essentially, the output looks like random data, regardless of the input – it is indistinguishable from random
Security compromise
  • Security is always a compromise between performance and assurance
  • Good slow ciphers are easy. Bad fast ciphers are easy. Good fast ciphers are difficult.
  • Coming from the performance side of things, it is understandable that implementations that are particularly efficient in hardware end up being used for cryptographic purposes.
Galois fields and polynomials
  • Think about the implementation we have developed last week which does polynomial reduction after multiplication with Q4mta4Ck5NLHxZf1qH71g5gJY
  • This was a particularly efficient algorithm, since it depended only on a shift and (possibly) one XOR operation
  • Exceptionally cheap in hardware, single-cycle operation
Galois fields and polynomials
  • If the division polynomial is irreducible, we are guaranteed to get maximum periodicity when repeatedly applying this operation
  • In other words, we are walking through all field elements in a deterministic fashion
  • True for any initialization state that is different from zero
Hardware implementation
  • So how would an implementation look in hardware?
  • In other words, what are the macroblocks and/or gates required to implement this?
  • Recall that we need storage of Q4mta4Ck5NLHmZf1qH71g5gJY bits and conditional XOR
Hardware implementation
  • A shift register is a string of D-flipflops, each capable of storing one bit (SRAMStatic RAM)
  • They are cascaded in a way that the output of one is the input of the next
  • All clocks are connected in parallel
LFSRs in hardware
  • An LFSRLinear-feedback shift register has a feedback loop: the start and end of the shift register are connected
  • This feedback bit (also known as output bit) is a linear combination of the inputs
  • Linear combination is the XOR operation and, therefore, cheap in hardware
LFSRs in hardware
  • Using a simulator you can easily visualize what is happening in hardware
  • You can also write some Python code to do the same thing in software
  • In my example, both generate the continued multiplication with Q4mta4Ck5NLHxZf1qH71g5gJY and residual after division by Q4mta4Ck5NLHx^7 + x^5 + x^4 + x^3 + 1Zf1qH71g5gJY
LFSR in software
# x^7 + x^5 + x^4 + x^3 + 1
exponents = [ 7, 5, 4, 3, 0 ]
poly = sum(2 ** exponent for exponent in exponents)
highbit = max(exponents) - 1

state = 1
for i in range(2 ** (highbit + 1)):
    feedback_bit = (state >> highbit) & 1
    print(f"{state:4d} {state:4x} -> feedback {feedback_bit}")
    state <<= 1
    if feedback_bit:
        state ^= poly
LFSR in hardware (Galois)
LFSRs in hardware
  • An LFSRLinear-feedback shift register in this topology is called a Galois representation; its internal state corresponds exactly to the Galois field arithmetic
  • Another way of expressing the same LFSRLinear-feedback shift register is called the Fibonacci representation, and it is more prevalent in hardware
  • The advantage of a Fibonacci LFSRLinear-feedback shift register is that there is only one feedback/output bit which is a linear combination of the state – no XOR gates between the D-flipflops are needed
LFSR in hardware (Fibonacci)
LFSR in software (Fibonacci)
# x^7 + x^5 + x^4 + x^3 + 1
degree = 7
taps = [ degree - 1 - 5, degree - 1 - 4, degree - 1 - 3, degree - 1 ]
mask = (1 << degree) - 1

state = 0x79
for i in range(2 ** degree):
    nextbit = 0
    for tap in taps:
        nextbit ^= (state >> tap) & 1
    print(f"{state:4d} {state:4x} -> feedback {nextbit}")
    state = ((state << 1) & mask) | nextbit
Differences
  • Note that the output sequence of every Galois LFSRLinear-feedback shift register can be expressed as a Fibonacci LFSRLinear-feedback shift register and vice versa
  • The internal state, however, differs – only the output sequence is identical
  • Also note that the taps are inverted in Fibonacci, while in Galois representation they correspond directly to the exponents
Differences
  • In the example above, the sequence produced by the Fibonacci generator with state 0x79 is the same as that of the Galois generator at state 0x01
LFSRs in hardware
  • This sort of pseudo-random sequence generator is cheap in hardware – energy-efficient and little silicon area
  • It matters in embedded implementations where energy is scare such as passive NFCNear-field communication, this matters greatly
  • Less energy means full operation with worse coupling, which equals greater reading distance
State recovery
  • What this means is that for a sufficiently long internal state and unknown polynomial and internal state, the output seems fairly random
  • However, note that the output bit of such a generator always is a linear function of the state bits of the previous clock cycle
  • This becomes especially clear when the LFSRLinear-feedback shift register is arranged in Fibonacci representation
State recovery
State recovery
  • For example, let's say for a 6-bit LFSRLinear-feedback shift register there is a bit sequence output which is Q4mta4Ck5NLH(1, 0, 0, 0, 0, 1, 1)Zf1qH71g5gJY
  • The keystream is extracted at Q4mta4Ck5NLHb_0Zf1qH71g5gJY
  • What this means is the first six bits of the keystream can be interpreted as state bits; the last bit is the linear combination (next bit to become Q4mta4Ck5NLHb_0Zf1qH71g5gJY)
State recovery
QBEntEozXWiob_x \in \mathbb{F}_2kIt7msRdzcHK
QBEntEozXWio1 b_0 + 0 b_1 + 0 b_2 + 0 b_3 + 0 b_4 + 1 b_5 = 1kIt7msRdzcHK
State recovery
  • We can simply process an ongoing keystream this way, always taking Q4mta4Ck5NLHn+1Zf1qH71g5gJY consecutive bits for a Q4mta4Ck5NLHnZf1qH71g5gJY-bit LFSRLinear-feedback shift register
  • At Q4mta4Ck5NLH2nZf1qH71g5gJY bits we can form Q4mta4Ck5NLHnZf1qH71g5gJY equations
  • Those can then be simply solved, revealing the taps of the LFSRLinear-feedback shift register
State recovery
QBEntEozXWioS = (1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0)kIt7msRdzcHK
Q4mta4Ck5NLH1 b_0 + 0 b_1 + 0 b_2 + 0 b_3 + 0 b_4 + 1 b_5 = 1Zf1qH71g5gJY Q4mta4Ck5NLH0 b_0 + 0 b_1 + 0 b_2 + 0 b_3 + 1 b_4 + 1 b_5 = 0Zf1qH71g5gJY Q4mta4Ck5NLH0 b_0 + 0 b_1 + 0 b_2 + 1 b_3 + 1 b_4 + 0 b_5 = 0Zf1qH71g5gJY Q4mta4Ck5NLH0 b_0 + 0 b_1 + 1 b_2 + 1 b_3 + 0 b_4 + 0 b_5 = 0Zf1qH71g5gJY Q4mta4Ck5NLH0 b_0 + 1 b_1 + 1 b_2 + 0 b_3 + 0 b_4 + 0 b_5 = 1Zf1qH71g5gJY Q4mta4Ck5NLH1 b_0 + 1 b_1 + 0 b_2 + 0 b_3 + 0 b_4 + 1 b_5 = 0Zf1qH71g5gJY
State recovery
QBEntEozXWioAx = bkIt7msRdzcHK
QBEntEozXWio\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 0 & 1 & 1\\ 0 & 0 & 0 & 1 & 1 & 0\\ 0 & 0 & 1 & 1 & 0 & 0\\ 0 & 1 & 1 & 0 & 0 & 0\\ 1 & 1 & 0 & 0 & 0 & 1\\ \end{pmatrix}x = \begin{pmatrix} 1\\ 0\\ 0\\ 0\\ 1\\ 0\\ \end{pmatrix}kIt7msRdzcHK
State recovery
QBEntEozXWioAx = bkIt7msRdzcHK
QBEntEozXWiox = \begin{pmatrix} b_0\\ b_1\\ b_2\\ b_3\\ b_4\\ b_5\\ \end{pmatrix} = \begin{pmatrix} 1\\ 1\\ 0\\ 0\\ 0\\ 0\\ \end{pmatrix} \rightarrow x^6 + x + 1kIt7msRdzcHK
Polynomial recovery
Improving LFSR-based stream ciphers
Mifare Classic
30
Kerckhoffs's Principle
  • We've talked numerous times about Kerckhoffs's Principle
  • Postulated by Auguste Kerckhoffs, 1835-1903, Dutch cryptographer
  • “The system should not require secrecy except for the keys it uses”
Kerckhoffs's Principle
  • Reformulated by Claude Shannon as “Shannon's maxim”
  • “one ought to design systems under the assumption that the enemy will immediately gain full familiarity with them”
  • Algorithm public knowledge, keys secret
Security by obscurity
  • The opposite principle is called “security by obscurity” and often used by clueless people to justify the use of shoddy practices
  • “Nobody will be able to find out how it works, therefore it is secure”
  • Great fallacy in the world of cryptography. Don't fall for it.
Security by obscurity
  • Security by obscurity can make a system more difficult to reverse engineer, but its power is widely overestimated
  • Computer game copy protection or app obfuscation are two examples of commonly applied security by obscurity mechanisms
  • Can be annoying, but are also notoriously unreliable in protecting anything
MIFARE Classic overview
MIFARE Classic propagation
  • In the next 10+ years, MIFARE classic pops up everywhere:
    • Payment terminals for public transport (e.g., London Oyster Card)
    • Hotel doors
    • Cafeterias
  • Roughly 200 million cards in circulation by then
MIFARE Classic propagation
  • In his diploma thesis, Plötz opened up a MIFARE Classic transponder.
  • Made pictures of the chip layers. Used image recognition to recover the netlist of the processor.
  • Then reverse engineered the hardware and revealed the “secret” algorithm.
  • Plötz/Nohl 24C3 2007: “Mifare: Little Security, Despite Obscurity”
MIFARE Classic propagation
  • LFSRLinear-feedback shift register-based design with 48 bit key. Algorithm called “Crypto-1”
  • When the algorithm is known, can easily be broken in seconds using the mathematical relationships between keystream bits
  • Crypto community nickname for the algorithm: “Crapto-1”
MIFARE Classic propagation
MIFARE Classic analysis
MIFARE Classic legal battle
  • NXP tried – unsuccessfully – to stop various security-related publications via lawsuit
  • Dutch court denied injunction in 2008: “It should be considered that the publication of scientific studies carries a lot of weight in a democratic society, as does informing society about serious issues in the chip, because it allows for mitigating of the risks.”
  • Streisand effect made it much worse for NXP
MIFARE Classic legal battle
  • Numerous – partially or fully backwards-compatible – successors were implemented (e.g., MIFARE Plus)
  • “Hardened” MIFARE Classic variant: MIFARE EV1
  • New attacks developed continuously, creating better and more effective ways of breaking security; Meijer, Verdult 2015: “Ciphertext-only Cryptanalysis on Hardened Mifare Classic Cards”
MIFARE Classic improved attacks
  • After the latest attacks, NXP conceded and now recommends migrating away from MIFARE Classic for security-relevant applications
  • However, MIFARE Classic haunts us to this day and is likely not going away for an even longer time
  • Knockoff transponders are incredibly cheap and installations (e.g., in hospitality business) are expensive to replace
Conclusion
44
Takeaway
  • Creating good cryptographic algorithms is incredibly difficult
  • What performs well in hardware does not necessarily make a good cipher
  • Security by obscurity is the dumbest idea
  • Be able to compute the internal polynomial from a keystream of an LFSRLinear-feedback shift register
Thank you!
Any questions?
Acronyms