Definition
Numeric comparison is an association model of BLE §7.1 (Bluetooth Low Energy) pairing §7.17: one of the alternative ways in which pairing checks that a new shared key is shared with the intended device. Each device displays a six-digit number computed from the public keys and random values it sent and received, and the user confirms on both devices that the numbers are equal. If an attacker altered the exchange, the numbers differ, except with probability about one in a million. Numeric comparison exists only in LE Secure Connections §7.21 pairing.
The idea
Under LE Secure Connections (LE stands for Low Energy), two devices start pairing by exchanging 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 cannot compute. An active attacker can do more than listen. The attacker can replace each device’s public key with the attacker’s own, finish one exchange with each device, and relay traffic between them: a man-in-the-middle §7.26 (MITM) attack. Each device then holds a sound key that it shares with the attacker.
The devices cannot detect the substitution by radio, because any radio message may come from the attacker. They can detect it with the user’s help. Each device reduces the public keys and random values it saw to a short number. Without interference, both devices saw the same values and show the same number. After a substitution, device A saw its own key and the attacker’s, device B saw the attacker’s key and its own, and the numbers differ. The user’s eyes bring the two numbers together over a path the attacker cannot reach, much as two people read out a file’s checksum §4.32 on a telephone call to confirm that the file arrived unchanged. The comparison stops working if the attacker can choose the attacker’s own values after seeing the devices’ values, because a short number can then be steered to match; the protocol’s commitment step prevents exactly that.
How it works
Numeric comparison is selected in the first phase of pairing when both devices support LE Secure Connections, at least one of them requests MITM protection, neither has out-of-band data, and both can display a number and accept a yes or no answer. Let A be the initiating device, the one that started the pairing, and B the responding device.
A and B exchange ECDH public keys on the elliptic curve named P-256. Write and for the public keys as each device sent or received them.
Each device picks a nonce §5.18: a fresh 128-bit random value used for this pairing only. Call them and .
B sends a commitment to its nonce: a value computed from , and with a keyed function built from the AES (Advanced Encryption Standard) block cipher §15.3. The commitment fixes without revealing it.
A sends . Then B sends , and A recomputes and aborts if the result differs.
Each device computes the function that the specification calls over , , and . Its output is a 32-bit number. The device displays the remainder of that number after division by , as six decimal digits including leading zeros.
The user compares the two numbers and presses yes on each device, or no if they differ. A no on either device fails the pairing.
Both devices derive the long-term key §7.28 (LTK) from the ECDH shared secret, the nonces and their addresses, and exchange check values that prove each computed the same key.
The order of steps 3 and 4 defeats a clever attacker. An attacker in the middle runs one exchange with A and one with B. Toward A, the attacker must send a commitment before A reveals . Toward B, the attacker must send a nonce before B reveals . So in whichever exchange the attacker completes second, the attacker’s nonce was fixed before the honest device there revealed its nonce. The honest device’s nonce therefore makes the second displayed number random from the attacker’s point of view, and the attacker cannot steer it to equal the first.
Just Works §7.22 under LE Secure Connections sends the same messages but displays nothing and asks nothing. Numeric comparison differs from Just Works only by the user’s comparison.
Worked example
No attacker. Suppose both devices compute , which is 987,654,321 in decimal. Dividing by gives 987 with remainder 654,321, so both screens show 654321. The user sees equal numbers and presses yes on both devices.
An attacker in the middle. The attacker M substituted M’s own public key in both directions. A computed its number from and ; B computed its number from and . A shows 654321 and B shows, say, 089217. A user who compares sees that the first digits already differ and presses no: the pairing fails and the attack is exposed. A user who presses yes on both devices without looking completes two pairings with M, and both devices record the key as authenticated.
The attacker’s chance. M’s only hope is that the second number happens to equal the first. A 32-bit value has possible values, which is . So each six-digit result from 000000 to 967295 arises from 4295 of the 32-bit values, and each other result from 4294. If M cannot steer the value, it lands on one given result with probability at most , about one in a million. The specification states the same figure: a simple MITM attack makes the two numbers differ with probability 0.999999.
Stated precisely
Let and be the numbers that A and B display. Each device computes from the public keys and nonces as it saw them, where is the remainder of after division by . The contract of numeric comparison is that a device marks the new key as authenticated only after its user has confirmed . The guarantee is that an active attacker who substitutes public keys in one pairing attempt goes undetected with probability about . It rests on five assumptions, and an attacker can target each one separately:
the user actually compares the two numbers and rejects a mismatch;
the two numbers compared are on the two devices being paired, not on a third device;
each display shows what its device computed, and each yes is pressed by the user, not by software or an attacker;
the attacker cannot compute the ECDH shared secret from the public keys;
the nonces are fresh 128-bit random values, and the commitment and behave like random functions to anyone who does not know all their inputs.
The six digits need integrity §1.9, not secrecy. An attacker who reads them gains nothing, because they are computed from values that crossed the radio unencrypted, and the attack is detected as soon as the two numbers differ.
Automating the comparison
On a test bench, or in a product with no person present, a program may take the user’s place. What matters is what the program checks and over which path.
A program that reads both six-digit numbers over wires from the two devices, for example from their serial consoles over a UART §6.23 (universal asynchronous receiver-transmitter), and confirms only if the numbers are equal performs the comparison. The pairing keeps its MITM protection if the wires connect to the intended devices and the attacker cannot alter what travels on them.
A program that presses yes without reading the numbers performs no comparison. The result has the strength of Just Works.
For passkey entry §7.23, a program that reads the passkey from one device’s console and types it into the other device replaces the user’s eyes and fingers. The pairing keeps its MITM protection if the attacker can neither read the passkey on the wire before the pairing ends nor change it. Passkey entry needs secrecy as well as integrity from this path, because an attacker who learns the passkey in time can complete both sides; numeric comparison needs only integrity.
In each case the attacker must not control the computer that runs the program. An attacker who does controls both paths at once.
Limits and common mistakes
Automatic acceptance turns numeric comparison into Just Works without changing the record. Each device still marks the key as authenticated, because it cannot tell whether the user looked. A later service that requires an authenticated key, which BLE expresses as security level §7.33 3 or 4, then trusts a key that may be shared with an attacker.
Numeric comparison authenticates the device whose screen the user looked at. If the user picks the attacker’s device from a list of nearby devices, the attacker’s screen shows the matching number, and the comparison correctly succeeds. The name shown in the list is not authenticated.
The six digits are not a password and not a signature. They are public and valid for one pairing only.
The first phase of pairing can be altered. An attacker who changes the unencrypted first messages to claim that one device has no display steers both devices to Just Works, which shows no number. This is a downgrade attack §1.27; the defense is that a device which needs an authenticated key refuses any pairing that does not produce one.
Numeric comparison needs both devices to support LE Secure Connections; LE legacy pairing §7.20 has no such model.
Each attempt gives the attacker about one chance in a million, but every new attempt needs a user to confirm a pairing; a user who accepts pairing requests they did not start gives the attacker more attempts.
Questions answered
What happens if a user automatically accepts without checking?
The pairing still completes, but it loses its protection against a man-in-the-middle (MITM) attacker, while both devices still record the key as authenticated. In numeric comparison, two BLE (Bluetooth Low Energy) devices each display a six-digit number computed from the public keys and random values they exchanged, and the user should confirm only if the numbers are equal. The comparison is the only step that catches an attacker who substituted public keys, because the substitution makes the numbers differ. Without it, the protocol is Just Works. A listener still cannot compute the key, because it comes from elliptic-curve Diffie–Hellman key agreement, but an active attacker in the middle ends up sharing one key with each device and can read and change all traffic.
The false record is the worse effect. Each device stores the key as authenticated, because it cannot see whether the user looked, so every later service that requires an authenticated key accepts the link. Software that presses yes automatically has the same effect. Automation keeps the protection only if it really compares the two numbers, read over paths that the attacker cannot alter.
Related entries: LE Secure Connections (§7.21), MITM attack (§7.26), Nonce (§5.18), Authentication (§1.6), Just Works (§7.22), Passkey entry (§7.23). Further reading: [18].