Section 7.23

Passkey entry

Definition

Passkey entry is one of the four association models of BLE §7.1 (Bluetooth Low Energy) pairing §7.17: the alternative ways in which pairing checks that a new shared key is shared with the intended device and not with an attacker. In passkey entry, the user carries a six-digit decimal number, the passkey, between the two devices. Either one device displays the passkey and the user types it into the other, or the user types the same number into both. Each device then checks that the other knows the passkey.

The idea

Pairing lets two BLE devices that share no secret create a key for encrypting their link. Every pairing message travels by radio, so an attacker within range can pose as each device to the other and complete one pairing with each: a man-in-the-middle §7.26 (MITM) attack, which the radio messages alone cannot reveal. The devices need a secret that reached both of them over a path the attacker cannot touch. In passkey entry that path is the user, whose eyes read the number on one device and whose fingers type it into the other.

A person cannot carry a 128-bit key by hand, so the passkey is short: six decimal digits, 10610^6 possible values. The protection therefore depends on how an attacker can test guesses at the passkey. In online guessing, each guess must be tried in a live pairing with a real device, which sees every failure and can slow down or refuse further attempts. In offline analysis, the attacker holds a recording that lets the attacker test a guess by computation alone, with no device involved, so only computing speed limits the number of guesses. A bank card PIN (personal identification number) is guessed online, at a cash machine that keeps the card after three wrong tries; a password-protected file copied to a laptop is attacked offline, at millions of tries per second. The analogy stops at one point: for a pairing, the protocol itself decides whether a recording allows offline tests, and the two BLE pairing protocols differ exactly there.

How it works

Choosing the model and the passkey. The devices choose passkey entry in the first phase of pairing, from what each states it can display and type: typically one device has a keyboard and the other a display. The Pairing entry gives the full rule. The passkey is a number from 000000 to 999999. A device that displays it generates it at random; if both devices have only keyboards, the user makes up a number and types it into both. The Bluetooth Core Specification requires a new random passkey for every pairing.

Under LE legacy pairing §7.20, the original BLE pairing protocol, the passkey becomes the temporary key (TK): the passkey read as a number and padded with zeros to 128 bits. The passkey 019655, for example, gives the TK 0x00000000000000000000000000004CC7, because 19655 in hexadecimal is 4CC7. Then:

  1. each device picks a 128-bit random number and sends a confirm value, computed with AES (Advanced Encryption Standard) from the TK, its random number and the earlier pairing messages;

  2. each device reveals its random number, and the other device recomputes the confirm value and aborts if it differs;

  3. both devices compute the short-term key (STK) from the TK and the two random numbers, encrypt the link with the STK, and over that link hand over the long-term key §7.28 (LTK) for later connections.

Every input to the confirm value except the TK crosses the radio unencrypted.

Under LE Secure Connections §7.21, the pairing protocol added in Bluetooth 4.2 (LE stands for Low Energy), the devices first exchange public keys for ECDH §19.1.5 (elliptic-curve Diffie–Hellman key agreement). Each device keeps a private number, sends a public key derived from it, and combines its own private number with the other’s public key; both arrive at the same shared secret, which a listener who sees only the public keys cannot compute. The passkey then authenticates the public keys, one bit at a time. Six decimal digits fit in 20 bits, because 999999 is 0xF423F, so the devices run 20 rounds. In round ii:

  1. each device picks a nonce §5.18, a fresh 128-bit random value, and sends a commitment: a value computed with AES from both public keys, its nonce and bit ii of the passkey, which fixes that bit without revealing it;

  2. the initiating device, the one that started the pairing, reveals its nonce, and the responding device recomputes the commitment with its own copy of bit ii and aborts if it differs;

  3. the responding device reveals its nonce, and the initiating device checks it in the same way.

After 20 rounds, the devices derive the LTK from the ECDH shared secret and the nonces, and each sends a final check value that proves it computed the same key. Because both public keys enter every commitment, an attacker who substituted a public key must still guess each passkey bit before it is revealed.

Worked example

Take the passkey 019655 and three attackers. Assume a computer that performs 10710^7 AES encryptions per second, a modest rate for one processor core.

Online guessing against Secure Connections. An attacker in the middle of a live pairing must commit to each passkey bit before learning it. The specification bounds the success of one such attempt at 0.000004, 4 in a million. Each attempt is a real pairing that a device sees and can refuse, so three attempts succeed with probability at most 3×0.000004=0.0000123 \times 0.000004 = 0.000012, about one chance in 83,000.

Offline analysis against legacy pairing. A listener recorded the pairing, including both confirm values and both random numbers. For each candidate passkey, the listener computes a confirm value, which costs 2 AES encryptions, and compares it with the recorded one. All 10610^6 candidates cost 2×1062 \times 10^6 encryptions, which take 2×106/107=0.22 \times 10^6 / 10^7 = 0.2 seconds; on average the match comes halfway, after 0.1 seconds. No device saw these guesses, so no failure counter applied. The recovered passkey 019655 gives the TK, the TK gives the STK, and the STK decrypts the handed-over LTK.

Offline analysis against Secure Connections. The recording also contains every commitment and nonce. For each round, the listener computes the commitment with bit 0 and with bit 1 and keeps the bit that matches: at most 2×20=402 \times 20 = 40 computations, which is instant, and the listener has read 019655. The LTK stays unknown, because it depends on the ECDH shared secret, so the recorded pairing stays protected. But if the device uses 019655 again, the listener already knows the secret that is supposed to stop a MITM attack in the next pairing.

Stated precisely

Let NN be the number of possible passkeys, N=106N = 10^6, and let qq be the number of complete guesses an attacker can test. If the passkey is chosen uniformly at random, meaning every value is equally likely, and a test reveals only whether the guessed value is right, the attacker succeeds with probability at most min(1,q/N)\min(1, q/N). If the passkey is not uniform, replace q/Nq/N by the sum of the qq largest probabilities among the passkeys. For one guess, that is the probability pmaxp_{\max} of the most likely passkey, and −log2pmax-\log_2 p_{\max} is the passkey’s min-entropy §5.26 in bits: −log210−6≈19.93-\log_2 10^{-6} \approx 19.93 bits for a uniform passkey.

Online guessing limits qq to the number of live pairing attempts; offline analysis limits qq only by computing power. For legacy passkey entry, q=Nq = N takes under a second, so the success probability is 1. For passkey entry under LE Secure Connections, the Bluetooth Core Specification states that an active MITM attacker succeeds in one pairing with probability at most 0.000004. The bound assumes:

  1. the passkey is uniformly random and new for this pairing;

  2. the attacker does not learn the passkey before the pairing ends, so the path from one device’s display to the other device’s keyboard is out of the attacker’s reach;

  3. the attacker cannot compute the ECDH shared secret from the public keys;

  4. the commitment hides its bit until the nonce is revealed, and nobody can find a second nonce that opens it to the other bit.

Legacy passkey entry has no such bound. Version 6.2 of the specification states that it does not protect against an active MITM attack and gives very limited protection against a listener during the pairing.

Limits and common mistakes

Six digits are about 20 bits. That is enough only because Secure Connections forces guessing online; as an encryption key, which an attacker tests offline, 20 bits would protect nothing.

A fixed or reused passkey loses its protection. Under Secure Connections, a listener learns the whole passkey from any completed pairing, and an active attacker who fails at round jj has still learned bits 1 to jj. A passkey printed on a label or written into the firmware therefore stops a MITM attack at most until one pairing has been observed. This is why the specification requires a new random passkey for each pairing.

A predictable passkey breaks the count of a million. People who make up a passkey choose values such as 000000, 123456 or 111111, and a device with a poor random number generator may produce few distinct values. An attacker tries the likeliest values first, so the success probability is the total probability of the values tried, not q/106q/10^6. A device can refuse a list of known weak values at the moment it learns the passkey: before displaying a passkey it generated or was given, and when the user types one. Against passkeys that people make up, the list removes the likeliest guesses. Against a uniformly random passkey it changes almost nothing: 20 refused values are 0.002% of 10610^6. The list does not repair a fixed passkey that is not on it, a weak random number generator, or legacy pairing.

The specification’s waiting rule slows online guessing: after a failed pairing, a device waits before pairing again with a device that claims the same identity, and the wait grows exponentially with each failure. A BLE attacker can change the claimed identity, so the rule slows attempts but does not cap them.

If a script copies the passkey from one device’s serial console to the other device in place of a person, the wire must keep the passkey secret from the attacker until the pairing ends and deliver it unchanged; the Numeric comparison §7.24 entry discusses this case.

Passkey entry authenticates the device that the user read from and typed into, nothing more. It says nothing about the device’s name, its maker, or the honesty of its software.

Questions answered

How does online guessing differ from offline analysis of a recorded procedure?

Online guessing tests each guess by running the protocol with a live, honest device, while offline analysis tests guesses by computation on a recording, without any device taking part. An online guess costs a real attempt that the device sees, so the device can count failures, wait between attempts and refuse further pairings. A six-digit passkey with 10610^6 values then gives an attacker about one chance in a million per attempt. An offline test needs only processor time, nobody sees it, and no limit applies, so a million candidates take well under a second.

Which model applies is a property of the protocol: it depends on whether the recording contains a value against which a guessed secret can be checked. In BLE (Bluetooth Low Energy) passkey entry under LE legacy pairing it does: the recorded confirm values let a listener test every passkey and recover the keys. Under LE Secure Connections, the recording reveals the passkey but not the key, because the key comes from an elliptic-curve Diffie–Hellman key agreement that the listener cannot complete. The passkey then helps an attacker only online, and only if it is used again. A short secret is acceptable only where the protocol forces guessing online.

Related entries: LE legacy pairing (§7.20), LE Secure Connections (§7.21), Entropy and min-entropy (§5.26), Pairing (§7.17), Numeric comparison (§7.24). Further reading: [18].