Section 7.20

LE legacy pairing

Full name: Low Energy legacy pairing.

Definition

LE legacy pairing is the pairing §7.17 procedure of Bluetooth Low Energy (BLE) §7.1 as first specified in Bluetooth 4.0, kept in later versions for devices without LE Secure Connections §7.21. The devices share a 128-bit temporary key (TK) that the association method fixes: zero for Just Works §7.22, the six-digit passkey for passkey entry §7.23, or a random value exchanged out of band. From the TK and two exchanged random numbers each computes a short-term key (STK). Legacy pairing uses no public-key cryptography §5.15, so the secrecy of every key rests on the TK alone.

The idea

A user pairs a phone with a fitness band by passkey entry. The band shows 019655 and the user types it on the phone. Those six digits are the only secret the two devices share; everything else they send before encryption starts travels over the air in the clear. An eavesdropper who records the pairing can later try every six-digit number on a laptop and test each guess against the recorded messages, without ever talking to either device, and neither device can notice. There are only one million numbers to try.

Picture a box with a six-digit combination lock. The devices put their real key in the box and send the box over the air. Anyone who records the box can try every combination at leisure. A bigger lock body does not help: the 128-bit short-term key that locks the box has no more possible values than the six digits it was computed from. The picture is incomplete in one respect: the eavesdropper also needs a way to recognize the right combination. Legacy pairing supplies one, the confirm value, a check value computed from the TK that each device sends to prove it knows the TK.

LE Secure Connections, added in Bluetooth 4.2, removes this search by adding a key agreement whose result an eavesdropper cannot compute.

How it works

Notation: e(k,m)e(k, m) is AES-128 encryption of the 16-byte block mm under the 16-byte key kk, where AES is the Advanced Encryption Standard block cipher §15.3; ⊕\oplus is bitwise exclusive-or; a‖ba \mathbin{\Vert} b is aa followed by bb. Let rIr_I and rRr_R be 128-bit random numbers chosen by the initiator (the central) and by the responder (the peripheral). Version 6.2 of the specification names them LP_RAND_I and LP_RAND_R; older versions named them Mrand and Srand.

  1. Feature exchange. The devices exchange Pairing Request and Pairing Response, the first two messages of the Security Manager Protocol (SMP) §7.19. At least one of them does not support LE Secure Connections, so LE legacy pairing runs, and the association method follows from their declared input and output capabilities and flags.

  2. Temporary key. Just Works: TK = 0. Passkey entry: TK is the passkey as a 128-bit number; passkey 019655 gives TK = 0x4CC7, because 4×4096+12×256+12×16+7=196554 \times 4096 + 12 \times 256 + 12 \times 16 + 7 = 19655. Out-of-band association §7.25: TK is a 128-bit random value passed over another channel, such as NFC (near-field communication).

  3. Confirm values. Each device computes a confirm value from the TK, its own random number, both feature-exchange messages and both device addresses, with a function the specification calls c1c_1 (stated below): CI=c1(TK,rI)C_I = c_1(\mathrm{TK}, r_I) and CR=c1(TK,rR)C_R = c_1(\mathrm{TK}, r_R).

  4. Exchange in a fixed order. The initiator sends CIC_I; the responder sends CRC_R; the initiator sends rIr_I; the responder recomputes CIC_I from rIr_I and, if it matches, sends rRr_R; the initiator recomputes CRC_R. Each device thus commits to its random number before it sees the other’s. A mismatch ends pairing with reason confirm value failed. An initiator that receives a CRC_R equal to its own CIC_I also aborts, which stops an attacker from simply sending a device’s own values back to it.

  5. Short-term key. Both compute STK = e(TK,rR′‖rI′)e(\mathrm{TK}, r_R' \mathbin{\Vert} r_I'), where r′r' denotes the 64 least significant bits of rr, and shorten it to the negotiated key size.

  6. Encryption. The initiator starts Link Layer §7.6 encryption with the STK.

  7. Key distribution. Over the encrypted link, each device that was asked to sends its own long-term key §7.28 (LTK), a 128-bit key it generates itself, with two values that identify it, EDIV (encrypted diversifier) and Rand. It may also send its identity resolving key §7.29 and its signing key. The distributed keys inherit the security properties of the STK.

  8. Later connections are encrypted with the stored LTK.

Under out-of-band association with a secret, uniformly random 128-bit TK, the eavesdropper’s search below is infeasible. Under Just Works and passkey entry it is easy.

Worked example

The specification’s own example for c1c_1 uses TK = 0, exactly the Just Works case. Its values are written as hexadecimal numbers with the most significant byte first:

rIr_I = 5783d52156ad6f0e6388274ec6702ee0
p1p_1 = 05000800000302070710000001010001
p2p_2 = 00000000a1a2a3a4a5a6b1b2b3b4b5b6

Here p1p_1 holds the 7-byte Pairing Response, the 7-byte Pairing Request, the responder’s address type 00 (public) and the initiator’s address type 01 (random); in this notation the first byte sent is the rightmost, so the command codes 02 and 01 stand at the right end of each message. p2p_2 holds four zero bytes, the initiator’s address a1a2a3a4a5a6 and the responder’s address b1b2b3b4b5b6. An eavesdropper reads all of these off the air.

The eavesdropper tests the candidate TK = 0, one step at a time, naming each intermediate value:

x1=rI⊕p1x_1 = r_I \oplus p_1 = 5283dd2156ae6d096498274ec7712ee1
x2=e(0,x1)x_2 = e(0, x_1) = 02c7aa2a9857ac866ff91232df0e3c95
x3=x2⊕p2x_3 = x_2 \oplus p_2 = 02c7aa2a39f50f22ca5fa3806cba8923
e(0,x3)e(0, x_3) = 1e1e3fef878988ead2a74dc5bef13b86

The last value equals the recorded CIC_I, the value the specification prints, so TK = 0 is confirmed after two AES operations. Take as the responder’s random number the invented value rRr_R = 000f0e0d0c0b0a091122334455667788. The 64 least significant bits of rRr_R are 1122334455667788 and those of rIr_I are 6388274ec6702ee0, so

rR′‖rI′r_R' \mathbin{\Vert} r_I' = 11223344556677886388274ec6702ee0
STK = e(0,rR′‖rI′)e(0, r_R' \mathbin{\Vert} r_I') = d3e03c8f30742a6167262dd688f8a4a4

With the STK the eavesdropper decrypts the key distribution and reads the LTK.

Had the user typed passkey 123456 instead, TK would be 0x1E240, because 1×65536+14×4096+2×256+4×16+0=1234561 \times 65536 + 14 \times 4096 + 2 \times 256 + 4 \times 16 + 0 = 123456. With the same rIr_I, p1p_1 and p2p_2, the initiator would send CIC_I = e291fa937ed0b3fe22dc3712484e7acf. An eavesdropper that tries the candidates 0, 1, 2 and so on matches at candidate 123456, after 123,457123{,}457 trials and 2×123,457=246,9142 \times 123{,}457 = 246{,}914 AES operations. The worst case is 10610^6 trials, 2×1062 \times 10^6 AES operations, which an ordinary computer finishes within seconds.

Count the possibilities. Six decimal digits give 106=1,000,00010^6 = 1{,}000{,}000 values. A uniformly random choice among NN values has log2N\log_2 N bits of entropy §5.26, the number of bits needed to count the values. For the passkey this is log2106=6log210≈6×3.3219=19.93\log_2 10^6 = 6 \log_2 10 \approx 6 \times 3.3219 = 19.93; as a check, 219=524,288<106<220=1,048,5762^{19} = 524{,}288 < 10^6 < 2^{20} = 1{,}048{,}576. A uniformly random 128-bit key has 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38} values, about 3.4×10323.4 \times 10^{32} times as many. The STK is 128 bits long, but given the recorded messages each TK candidate determines it, so it has at most 10610^6 possible values.

Stated precisely

Let preq\mathrm{preq} and pres\mathrm{pres} be the 7-byte Pairing Request and Pairing Response, iat\mathrm{iat} and rat\mathrm{rat} the one-byte address types of the initiator and the responder, ia\mathrm{ia} and ra\mathrm{ra} their 6-byte addresses, 0320^{32} a string of 32 zero bits, and r′r' the 64 least significant bits of rr. For one pairing these values are fixed, and the specification’s function c1c_1 reduces to the two-argument form used here: p1=pres‖preq‖rat‖iat,p2=032‖ia‖ra,c1(k,r)=e(k,e(k,r⊕p1)⊕p2),CI=c1(TK,rI),CR=c1(TK,rR),STK=e(TK,rR′‖rI′).\begin{aligned} p_1 &= \mathrm{pres} \mathbin{\Vert} \mathrm{preq} \mathbin{\Vert} \mathrm{rat} \mathbin{\Vert} \mathrm{iat}, \qquad p_2 = 0^{32} \mathbin{\Vert} \mathrm{ia} \mathbin{\Vert} \mathrm{ra}, \\ c_1(k, r) &= e\bigl(k,\ e(k,\ r \oplus p_1) \oplus p_2\bigr), \\ C_I &= c_1(\mathrm{TK}, r_I), \qquad C_R = c_1(\mathrm{TK}, r_R), \\ \mathrm{STK} &= e(\mathrm{TK},\ r_R' \mathbin{\Vert} r_I'). \end{aligned}

Every input except the TK is sent in the clear. Therefore, for an eavesdropper who records the pairing, the STK and every key sent under it are fixed by the TK. If the TK is uniformly distributed over NN values, the eavesdropper finds it after at most NN trials of c1c_1, and after (N+1)/2(N + 1)/2 trials on average, each trial costing two AES operations. N=1N = 1 for Just Works, N=106N = 10^6 for a fresh random passkey, and N=2128N = 2^{128} for a uniformly random out-of-band TK that the eavesdropper cannot read. A TK that is not uniform, such as a passkey a person chose or a passkey printed on the device and used at every pairing, is easier still.

Version 6.2 of the specification says that legacy passkey entry “does not provide protection against active ‘man-in-the-middle §7.26’ (MITM) attacks” and gives “very limited protection against eavesdroppers”, and it classes the resulting keys as unauthenticated. The reason is that an active attacker can run the eavesdropper’s search during the pairing itself. Posing as the responder, it sends an arbitrary CRC_R, receives rIr_I, and finds the passkey by testing the candidates against CIC_I, which takes at most seconds. Since c1c_1 consists of AES encryptions under a key the attacker now knows, the attacker can run them backwards and compute an rRr_R whose confirm value is exactly the CRC_R it already sent, so the initiator’s check passes. Under LE legacy pairing, only out-of-band association over a channel safe from eavesdropping gives an authenticated key.

The eavesdropping attack

Mike Ryan described the attack in “Bluetooth: With Low Energy Comes Low Security” at the 2013 USENIX Workshop on Offensive Technologies [278] (USENIX is a computing-systems professional association), and released a tool, crackle, that carries it out. The eavesdropper records one pairing:

Then, offline:

  1. For each candidate TK, compute c1(TK,rI)c_1(\mathrm{TK}, r_I) and compare it with the recorded CIC_I. Only the true TK matches, except with negligible probability.

  2. Compute the STK from the TK, rRr_R and rIr_I.

  3. Compute the Link Layer session key from the STK and the recorded random values, decrypt the key-distribution messages, and read the LTK.

  4. Decrypt every later recorded connection between the two devices: each connection’s session key is computed from the LTK and random values sent in the clear.

Limits and common mistakes

A long key computed from a short secret is still a short secret. Output length does not create uncertainty that the input lacked.

The attack is silent. The eavesdropper sends nothing, so neither device can detect it, and limits on repeated pairing attempts do not slow it, because every trial runs on the attacker’s computer.

Just Works under LE legacy pairing protects against nobody who recorded the pairing. Later connections are confidential only if no attacker was present during pairing.

One recorded pairing exposes the future and the past: every later connection encrypted with the LTK can be decrypted, including connections recorded before the LTK was found.

The specification requires a new random passkey for every pairing. A fixed passkey, printed on the device and used at every pairing, is revealed by one recorded pairing and stays revealed.

Identify the procedure from the Secure Connections bits (the SC flags) of the feature exchange, not from the user interface: LE legacy pairing and LE Secure Connections can both show six digits. Statements about the security of passkey entry or Just Works are wrong unless they name the procedure.

Out-of-band association under LE legacy pairing is only as secret as the out-of-band channel and only as strong as the randomness of the TK.

Questions answered

Why is a short human passkey not equivalent to a uniformly random long-term key?

A short passkey is not equivalent because an attacker’s work depends on how many values the secret can take, not on how long the derived key is: a six-digit passkey has 10610^6 values, about 20 bits, against 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38} for a uniformly random 128-bit key. In LE legacy pairing, the Bluetooth Low Energy pairing procedure without public-key cryptography, the passkey is the temporary key (TK). The short-term key (STK) is computed from the TK and two random numbers sent in the clear, and the STK protects the long-term key (LTK) when it is sent across. Each of these keys is 128 bits long, but given the recorded messages each is fixed by the passkey, so there are still only 10610^6 possibilities.

The pairing transcript also lets an eavesdropper test guesses offline. Each device sends a confirm value computed from the TK and values sent in the clear, so the eavesdropper computes it for each candidate passkey and keeps the one that matches. At two AES (Advanced Encryption Standard) operations per candidate, all 10610^6 candidates take 2×1062 \times 10^6 operations, seconds on an ordinary computer; Mike Ryan’s tool crackle (2013) does exactly this. A uniformly random 128-bit key would need up to 21282^{128} trials. LE Secure Connections removes the offline test: its key comes from an elliptic-curve Diffie–Hellman §19.1.5 exchange that an eavesdropper cannot compute, and the passkey only authenticates that exchange.

Related entries: LE Secure Connections (§7.21), Passkey entry (§7.23), Entropy and min-entropy (§5.26), Key derivation function (KDF) (§5.20), Security Manager Protocol (SMP) (§7.19), Just Works (§7.22), Out-of-band (OOB) association (§7.25), Long-term key (LTK) (§7.28), Block cipher (§15.3). Further reading: [18, 278].