Keelog Code Hopping
Keelog Code Hopping
Applications
Abstract. KeeLoq remote keyless entry systems are widely used for
access control purposes such as garage door openers or car anti-theft sys-
tems. We present the first successful differential power analysis attacks
on numerous commercially available products employing KeeLoq code
hopping. Our new techniques combine side-channel cryptanalysis with
specific properties of the KeeLoq algorithm. They allow for efficiently
revealing both the secret key of a remote transmitter and the manu-
facturer key stored in a receiver. As a result, a remote control can be
cloned from only ten power traces, allowing for a practical key recovery
in few minutes. Once knowing the manufacturer key, we demonstrate
how to disclose the secret key of a remote control and replicate it from a
distance, just by eavesdropping at most two messages. This key-cloning
without physical access to the device has serious real-world security im-
plications. Finally, we mount a denial-of-service attack on a KeeLoq
access control system. All the proposed attacks have been verified on
several commercial KeeLoq products.
1 Motivation
The KeeLoq block cipher is widely used for security relevant applications, e.g.,
in the form of passive Radio Frequency Identification (RFID) transponders for
car immobilizers [15] and in various access control and Remote Keyless Entry
(RKE) systems. In the last months, the KeeLoq algorithm has moved into
the focus of international cryptographic research community. Shortly after the
first cryptanalysis of the cipher [1], more analytical attacks were proposeed [4,
5], revealing mathematical weaknesses of the cipher. The best known analyti-
cal attacks targeting Identify Friend or Foe (IFF) systems require at least 216
plaintext-ciphertext pairs in order to recover the secret key of one transponder
employing the KeeLoq algorithm. The described approach allows, after several
⋆
Amir Moradi performed most of the work described in this contribution as a visiting
researcher at the Ruhr-University of Bochum.
days of calculations, for a simple cloning of the transponder and, only in case
of a very weak key derivation method1 , for obtaining the manufacturer key that
is required to generate keys for new valid transponders. Despite the impressive
contribution to the cryptanalysis of the cipher, the real-world impact of the pre-
vious attacks are somewhat limited: First, they cannot be directly applied to the
widespread KeeLoq code hopping applications[9] on which most RKE systems
rely (which appears to be the dominant commercial application of KeeLoq).
The required minimum of 216 plaintext-ciphertext pairs cannot be obtained in
case of a code hopping scheme, because an adversary has only access to the
ciphertexts that are transmitted by a remote control, while the corresponding
plaintexts remain a secret stored in the device. Second, physical access to the
transmitter device is needed in order to obtain the 216 plaintext-ciphertext pairs.
Third, and perhaps most importantly, the manufacturer key which is located in
the receiver can only be recovered if a weak key derivation function is being used
which is not the case in many commercial systems. An overview on the previous
work is given in Sect. 2.4.
Motivated by the ongoing research we investigate the vulnerability of real-
world KeeLoq implementations with respect to side-channel analysis, in order
to tackle the security of code hopping applications in a realistic manner. As
a result, we present three very practical key recovery attacks and a denial-of-
service attack with severe implications for RKE systems that are currently used
in the field. These new attacks — which combine side-channel cryptanalysis with
specific properties of the KeeLoq algorithm — can be applied to various imple-
mentations of KeeLoq. In particular, we have been able to successfully attack
hardware realizations, i.e., the Microchip HCSXXX family of chips, as well as
software implementations running on Microchip PIC microcontrollers. In con-
trast to the hitherto existing attacks, the techniques proposed by us are also
applicable in case of more sophisticated key derivation schemes (c.f. Sect. 2.3)
and are appropriate for the KeeLoq code hopping schemes. We elaborate in
Sect. 3 how the secret key of a transmitter and the manufacturer key used in a
receiver can be revealed in less than one hour and less than one day, respectively.
Finally, we describe how to recover the secret key of a transmitter and hence
clone it from a distance, just by eavesdropping at most two hopping code mes-
sages. We detail how an attacker can gain access to sites that are protected with
KeeLoq code hopping systems with our methods and show how to put the access
control out of operation, i.e., illustrate how to mount a denial-of-service attack.
In contrast to the hitherto existing work, the techniques proposed by us are also
applicable in case of more sophisticated key derivation schemes (c.f. Sect. 2.3)
and are appropriate for the KeeLoq code hopping schemes. Note that our key
recovery attacks can also be applied to IFF applications. All our attacks have
been extensively tested and verified. We present various experimental results and
provide ascertained figures for attacks both based on the current consumption
and the electromagnetic (EM) emanation of different KeeLoq devices.
1
If the key of the transmitter is derived from XORing a simple function of the device
serial number with the manufacturer key, the latter can easily be obtained
Since the introduction of power analysis in 1999 [6], it has become an es-
tablished measure to access protected information from security related systems
by exploiting power consumption traces of cryptographic hardware. Almost ten
years later, the most powerful attack in this area, called Differential Power Anal-
ysis (DPA), remains an attack mostly performed in smart card test labs and uni-
versities. The targets are often own or known implementations on platforms that
are well-known to be vulnerable to side-channel attacks, employing no counter-
measures and examined in an ideal environment [18, 8, 16], for example with an
artificially generated trigger signal for the measurements. The practical relevance
for real-world realizations of cryptography sometimes remains an open question.
During our investigations, we were confronted with black box implementations,
i.e., with no previous knowledge or information about the devices except for the
known cipher and the characterization in the data sheet, which demanded for
some extra efforts and reverse engineering of the unknown targets. Despite these
obstructions, we were able to mount highly effective attacks with considerable
implications on the security of KeeLoq code hopping systems that allow for
– recovering the secret key of a KeeLoq code hopping encoder with as few as
ten power traces and only minutes of computation time,
– obtaining the manufacturer key used in a receiver in less than one day,
– cloning a remote control from the distance by eavesdropping at most two
hopping codes2 , and
– putting an access control system out of service.
The described complete break of the KeeLoq code hopping mechanism was
performed with no previous knowledge about the implementations and is appli-
cable to all KeeLoq key derivation schemes we are aware of. Our DPA attacks
were performed on commercial KeeLoq implementations and are highly effec-
tive with regard to complexity and computational cost — for example finding
the 64 bit key of a transmitter is possible after measuring the power consumption
of only ten encryptions, i.e., press the button of a transmitter ten times, with a
sample rate as low as 20 MS/s. The required time for the post-processing is in
the order of minutes.
2 Background
2.1 Description of KeeLoq
KeeLoq is a block cipher with a 64-bit key and 32-bit plaintext and ciphertext.
As illustrated in Fig. 1, it can be viewed as a non-linear feedback shift register
(NLFSR) where the feedback depends linearly on two register bits, one key
bit, and a non-linear function (NLF). The NLF maps five other register bits to
a single bit with the output vector 3A5C742Ex 3 . Prior to an encryption, the
2
The manufacturer key is assumed to be known, e.g., from a previous attack
3
NLF (i) is the ith bit of this hexadecimal constant, where bit 0 is the least significant
bit [1, 4, 5]
given key and plaintext are loaded in the key register and the state register,
respectively. In each clock cycle, the key register is rotated to the right and the
state register is shifted to the right so that the fresh bit prepared by the XOR
function becomes part of the state. After 528 clock cycles, the state register
contains the ciphertext. The decryption process is similar to the encryption,
except for the direction of shifts and the taps for the NLF and the XOR function.
State Register, y
Discrimination
7 2 4 0 1 10 Synchronization Counter Func.
Value
32
Secret 64
Key
32
Key Register, k
0
Hopping Code
Due to their simplicity, the last two key derivation schemes, including the
‘Secure Key Generation’ method, allow for directly concluding to the manufac-
turer key if the adversary has access to the transmitter. In contrast to the first
two (more sophisticated) derivation schemes, they can be broken by the exist-
ing attacks that are described below. Note that a manufacturer may develop a
proprietary key derivation scheme not included in the above list.
1 2 1 2
32 32 32 32
Manufacturer Manufacturer
Key Key
64 64 64 64
32 32 32 32
(a) (b)
1 2 1 2
32 32 32 32
64 64
Manufacturer 64 Manufacturer 64
Key Key
64 64
(c) (d)
The first two attacks on the KeeLoq algorithm were published by Bogdanov [1].
One attack is based on slide and guess-and-determine techniques and needs about
250.6 KeeLoq encryptions. The other one additionally uses a cycle structure
analysis technique and requires 237 encryptions. However, both attacks require
the entire codebook, i.e. all 232 plaintext-ciphertext pairs.
Afterwards, Courtois et. al [4] proposed two attacks. One is a slide-algebraic
attack demanding for 251.4 KeeLoq encryptions and 216 known plaintext-ciphertext
pairs. The second slide attack can be carried out knowing almost the entire code-
book. It reveals the secret key with a complexity of approximately 227 KeeLoq
encryptions.
Recently, Indesteege et. al improved the existing work significantly and pre-
sented more practical attacks on the KeeLoq algorithm [5]. All of them are also
based on slide and meet-in-the-middle attacks. The best one requires 216 known
plaintext-ciphertext pairs and has a complexity of 244.5 KeeLoq encryptions.
It allows for finding the secret key of the transmitter (and thus the manufac-
turer key for the weak key derivation schemes) in two days using 50 Dual Core
machines.
The above attacks are appropriate for KeeLoq IFF systems because it is
possible to collect 216 plaintext-ciphertext pairs in about one hour [5] from a
commercial KeeLoq IFF system. However, none of these attacks works on ap-
plications employing the KeeLoq code hopping technique, because the plain-
text of the hopping codes is not known to an attacker. It is mentioned in [5]
that knowing the sequence of 216 ciphertexts of a code hopping application is
sufficient to perform their attack as this sequence is simply repeated. However,
just two products of Microchip (HCS200 and HCS201) use a 16-bit synchroniza-
tion counter [10, 11] and the other ones (such as HCS300, HCS301, HCS361,
...) employ two overflow bits to not repeat a hopping code message for more
than 64K transmissions [12–14], i.e. extend the number of unique transmissions
to more than 192K. Even if the sequence of the synchronization counter was
known, the discrimination value would still be required to perform the men-
tioned attack. The commercial products employing the KeeLoq code hopping
protocol, i.e., HCS modules, do not allow an attacker to access this informa-
tion. To our knowledge, most of the commercial applications using KeeLoq as
a remote entry system employ the code hopping mechanism5 , and the attacks
described above are not considered a major threat to their security.
3 DPA on KeeLoq
Measurement The power traces are gathered by measuring the current via
a shunt resistor connected to the ground pin of the target chip. In addition,
we acquire the EM radiation of the device by means of near field probes6 . For
convenience, we have built a special printed circuit board (PCB) that allows for
emulating KeeLoq chips and for controlling the transmitter or receiver from a
PC so that a measurement sequence can be executed automatically. The power
traces were acquired using an Agilent Infiniium 54832D digital oscilloscope with
a maximum sampling rate of 4 GS/s.
6
RF U 5-2 from www.langer-emv.de
Data Pre-Processing and Alignment One problem of aligning the power
traces of an unknown implementation is the absence of a suitable trigger signal.
The solution for this is target-specific and detailed in Sect. 3.2 and Sect. 3.3 for
transmitters and receivers, respectively. Another problem is that all of the target
devices are clocked by a noisy internal RC-oscillator. Hence we had to find a way
to remove the clock jitter. We know that most of the data-dependent leakage
occurs in the instant when the registers are clocked, a point in time which the
power consumption peaks within each clock period. These peaks directly cor-
respond to the dynamic power consumption of the target circuit and thus hold
most of the information we are looking for. We developed an application to ex-
tract the peaks from the power consumption, and to base our DPA attack solely
on the amplitude of the peaks. This peak extraction step has two advantages
for the subsequent analysis: (i) the amount of data is greatly reduced, which
facilitates the post-processing, the data storage and furthermore speeds up the
subsequent steps significantly. (ii) more importantly, the peak extraction allows
for an accurate alignment of the traces. Other methods for removing the clock
jitter, such as Fourier transform, filtering, etc., turned out to be much more
complicated and less effective.
Developing and Performing the DPA After the peak extraction and align-
ment steps have been performed, the traces can be processed by the DPA al-
gorithm. For the transmitter modules we only knew the ciphertext and hence
had to perform our attacks starting from the last round of the encryption. For
the software implementation of the PICs we knew the plaintexts and started the
attack of the first round of the decryption. The algorithms for a known plaintext
attack on the decryption and for a known ciphertext attack on the encryption
are the same, due to the simple structure and key management of the KeeLoq
cipher.
(i)
where k0 is the rightmost bit of the key register in the ith round. Resolving
(i) (i)
Eq. (2) to y0 and knowing that kj = k(i+j) mod 64 , we obtain
(527) (527) (528) (527) (527) (527) (527) (527)
y0 = k15 ⊕ y16 ⊕ y31 ⊕ NLF y31 , y26 , y20 , y9 , y1 (3)
(527)
Thus, recovering y0 directly reveals one bit of the key register. This pro-
cess is the same for recovering the LSB of the state register of the previous
(i)
rounds, i.e., y0 , i = (526, 525, . . .). However, Eq. (3), and hence the whole state
(527)
y depends linearly on the key bit k15 . Above we stated that nonlinearity
helps distinguishing correct key hypotheses from wrong ones. Hence, recovering
the key bit by bit might not be the best choice. Simulations show that an attack
recovering the key bit by bit is much weaker than an attack that recovers several
key bits at a time. Still, the key can also be recovered for single bit key guesses –
in other words even a classical DPA on the LSB of the state register is feasible.
(i)
Fortunately, according to Fig. 1, the LSB of the round state, y0 , enters the
NLF leading to a nonlinear relation between the key bit k15 and the state y (526) .
Accordingly, the nonlinearity for one key bit kj increases in each round after it
was clocked into the state.
7
both attacks target state y (l) of the decryption, which is the same as state y (528−l)
of the encryption.
Algorithm 1 A Scalable DPA for KeeLoq
Input: m : length of key guess, n: number of surviving key guesses, k: known previous
key bits
Output: SurvivingKeys
1: KeyHyp ← {0, 1}m
2: for all KeyHypi ; 0 ≤ i < 2m do
3: Perform CPA on round (528 − m) using PHyp and k
4: end for
5: SurvivingKeys ← n most probable partial keys of KeyHyp
0.9
Correlation
0.8
0.7
0.6
526 524 522 520 518 516 514
Round
Fig. 5. Simulated correlation of key hypotheses over the KeeLoq rounds. Correct key
guess (black solid line) vs. wrong key guesses (thin gray lines).
Correlation Coefficient
Correlation Coefficient
0.6 0.6
0.4 0.4
0.2 0.2
0 0
Ŧ0.2 Ŧ0.2
Ŧ0.4 Ŧ0.4
5 10 15 20 25 30 35 40 45 50 5 10 15 20 25 30 35 40 45 50
Number of traces Number of traces
1000
750
500
Fig. 8. The number of the needed measurements for different sampling rates. The
numbers in parentheses give the exact coordinates of the points.
For the hardware attack it was very likely that one KeeLoq round was
performed in each clock cycle. This is not true for the software implementation.
Accordingly, we correlated the power traces for a single intermediate state only
for each iteration of the attack.
We performed the attack by putting the receiver into learning mode and
sending hopping code messages with random serial numbers to the receiver.
Lacking any special features in the power consumption of the PIC that could
have been used as trigger, we triggered the oscilloscope directly after transmitting
the last bit via the RF interface. This results in our power traces not being
well-aligned, leading to a high number of power samples needed to perform
a successful DPA attack. We then generated an arbitrary number of random
ciphertexts (the serial number) to perform a successful DPA on the decryption.
Since we did not know how much time the KeeLoq decryption needed, we chose
a low sampling frequency (125MS/s) to be able to gather a long time span with
each measurement.
While performing the attack we noticed that the correlation of the correct
key became continuously worse with an increasing number of rounds. For the
first few key bits 1000 traces sampled at 125 MS/s are roughly sufficient to find
the key. Surprisingly, we need roughly ten times as many to be able to recover the
full 64-bit key. This gradual decrease of the correlation is due to a misalignment
that occurs during the execution of the KeeLoq algorithm. It is not due to the
bad trigger condition, since the trigger affects all time instances in the same way.
Also we were pretty confident that it is not due to the clock jitter, since this was
removed easily using the peak detection. We conclude that the code is likely to
have a data-dependent execution time, resulting in an increasing misalignment
with an increasing number of rounds.
4 Attack Scenarios
In the previous section we showed how the keys of hardware and software imple-
mentations of KeeLoq can be recovered. We will now evaluate the vulnerability
of real-world systems to our attacks and illustrate the implications, assuming a
moderately skilled adversary. We detail four different attack scenarios, which
allow for breaking basically any system using KeeLoq with modest efforts. We
focus on code hopping applications, since they are more commonly used and,
due to the lack of known plaintexts, harder to cryptanalyze than IFF systems.
Still, IFF systems are just as vulnerable to our DPA attacks as the code hopping
devices. Some of the transmitters we analyzed even offer both operating modes.
The success of some of our attacks depends on the knowledge about the
particular key derivation scheme, as described in Sect. 2.3. However, the attacks
are appropriate for all the key derivation schemes we are aware of.
For cloning a transmitter using power analysis, an adversary needs physical ac-
cess to it to acquire at least 10 to 30 power traces. Hence, the button of the
remote control has to be pressed several times, while measuring the power con-
sumption and monitoring the transmitted hopping code messages. After recov-
ering the device key kDev with the side-channel attack described in Sect. 3.2, the
recorded messages can be decrypted, disclosing the discrimination and counter
values of the original transmitter at the time of the attack. Now, the HCS module
of a spare remote control can be programmed with the serial number, counter
value and discrimination value of the master. Consequently, the freshly produced
transmitter appears to be genuine to a receiver and allows for accessing the same
target as the original.
4.2 Recovering a Manufacturer Key
The actual key recovery of the manufacturer key kM depends on the applied key
derivation scheme.
If scheme (c) or (d) of Sect. 2.3 is used, i.e., an XOR of a known input and
the manufacturer key kM , disclosing the latter is trivial. After a successful key
recovery attack on one transmitter of the same brand, kM is found by reversing
the XOR function. The known input is either part of each hopping code message,
in case of the serial number, or can be extracted from the remote control, in
case of a seed. The derived manufacturer key can be verified with a second
transmitter.
An adversary targeting the manufacturer key for scheme (a) or (b) of Sect. 2.3
requires physical access to one receiver of the same brand and model as is used
at the destination site. Obtaining these is a realistic assumption, as the number
of manufacturers of access systems is small. The different brands can even be
distinguished from only viewing a remote control or receiver from the distance,
as each manufacturer likes to invent its own special design for the product.
Prior to attacking the receiver, an adversary performs the above attack from
Sect. 4.1 on one transmitter, to get known to its device key KDev . Then, the
key of the KeeLoq decryption performed inside the receiver during the key
derivation step can be recovered, according to the attack described in Sect. 3.3.
The adversary now possesses the manufacturer key kM of that device family and
can hence generate an arbitrary number of new valid remote controls with chosen
serial numbers and counter values. In this case, all the prior cryptanalyses [5,
1, 4] of KeeLoq will fail, unless they recovered the key of at least 216 different
transmitter devices.
Assuming an adversary that knows the result of the previous attack, namely the
manufacturer key kM , and the key derivation method of a target device family,
a remote control can be cloned by eavesdropping. The attacker has to intercept
at most two hopping code messages, c1 and c2 , sent by an unknown transmitter
of the same brand. The process of finding the secret key of the eavesdropped
transmitter and copying it depends on the key derivation scheme.
If the key is derived from the serial number of the transmitter, finding its
device key is straightforward, since the intercepted messages contain the serial
number. Knowing the manufacturer key, the attacker can simply perform the
key derivation process to obtain the device key.
5 Conclusion