Section 7.27

Encryption key size

Definition

Encryption key size, in BLE §7.1 (Bluetooth Low Energy), is the number of bytes of the link encryption key that are secret, a whole number from 7 to 16. The two devices agree on it during pairing §7.17: each states the largest size it accepts, and the smaller of the two is used. The cipher always takes a 16-byte key, so a key of nn bytes is a 16-byte key whose 16−n16 - n most significant bytes are zero. An attacker therefore searches 28n2^{8n} keys, not 21282^{128}.

The idea

A datasheet says that a device encrypts its BLE link with AES-128, the AES (Advanced Encryption Standard) block cipher §15.3 with a 128-bit key. That statement describes the cipher, not the key. An attacker who wants to decrypt a recording does not care how wide the key is; the attacker cares how many key values remain possible. A 128-bit key with 72 bits known to be zero leaves 56 unknown bits, and a search over 2562^{56} values is within reach of a well-funded attacker.

BLE allows such keys on purpose. The Bluetooth specification gives the reason for allowing shorter encryption keys: in some countries, governments restrict the strength of encryption algorithms §14.1. So the key size is negotiated, and the negotiation runs in the first, unencrypted pairing messages. An attacker who can change those messages can lower the size; this is the KNOB (Key Negotiation Of Bluetooth) attack [272]. The defense is each device’s own minimum, checked at the right moments. Picture a combination lock with 16 dials, where the negotiation can glue up to 9 of them at zero: from outside, the lock looks the same.

How it works

Each device has a minimum and a maximum key size, each from 7 to 16 bytes, set by the product’s software. Pairing and later use then proceed as follows.

  1. Negotiation, in the first phase of pairing. The initiating device sends a Pairing Request and the responding device a Pairing Response, and each message carries its sender’s maximum key size. Both messages travel unencrypted. Each device takes the smaller of the two maxima as the key size nn.

  2. Check at negotiation. Each device compares nn with its own minimum. If nn is smaller, the device stops and sends Pairing Failed with the reason “Encryption Key Size”. This check runs before any key exists.

  3. Masking. The pairing produces a 16-byte key. If n<16n < 16, the device sets the 16−n16 - n most significant bytes of the key to zero before it uses, sends or stores the key.

  4. Storage. A device that bonds, meaning it stores the keys for later connections, can store nn with the key, so that later checks can read it.

  5. Check when the link is encrypted. Each time a connection is encrypted, right after pairing or on a reconnection that reuses a stored key, the device’s software can compare the size of the key in use with what it requires. The highest security level §7.33, level 4, requires a 16-byte key from LE Secure Connections §7.21 pairing (LE stands for Low Energy).

  6. Check at access. When a peer asks to read or write data that has a stated key-size requirement, the device that holds the data compares the current link’s key size with the requirement and, if the key is too short, refuses with an error saying so.

The session key that actually encrypts each connection is computed from the stored key and fresh random values, and is 16 bytes long. It adds no unknown bits: an attacker who has found the stored key computes the session key from the random values, which travel unencrypted.

The KNOB attack. An attacker in radio range intercepts the Pairing Request and the Pairing Response and changes the maximum key size in each to 7 bytes. Both devices compute n=7n = 7. Under LE Secure Connections, the final check values that the devices exchange cover each device’s input and output capabilities, out-of-band flag and authentication §1.6 requirements, but not the key-size field, so the change goes undetected. If both devices accept 7 bytes, the pairing succeeds with a 56-bit key. The attacker records the encrypted traffic and tests candidate keys: a wrong candidate fails the integrity §1.9 check that every encrypted packet carries. Antonioli, Tippenhauer and Rasmussen described the attack against Bluetooth Classic in 2019, and showed in a 2020 journal paper that BLE keys can be lowered to 7 bytes in the same way [280]. The defense is the check of step 2 with a minimum of 16: a device that requires 16 bytes computes n=7n = 7, finds it below its minimum and fails the pairing.

Worked example

Masking. The specification gives this example of a 16-byte key reduced to 7 bytes. The key

0x123456789ABCDEF0123456789ABCDEF0

becomes

0x0000000000000000003456789ABCDEF0.

The 9 most significant bytes, the first 18 hexadecimal digits, are zero, and the 7 bytes 34 56 78 9A BC DE F0 remain.

Search effort. An attacker who knows the key size nn searches 28n2^{8n} keys.

Assume, for illustration, an attacker who tests 101210^{12} keys per second. For 7 bytes, the whole space takes 7.2×1016/1012=7.2×1047.2 \times 10^{16} / 10^{12} = 7.2 \times 10^{4} seconds, which is 20 hours, and on average the key turns up after half of that, 10 hours. For 16 bytes, it takes 3.4×1038/1012=3.4×10263.4 \times 10^{38} / 10^{12} = 3.4 \times 10^{26} seconds, about 1.1×10191.1 \times 10^{19} years.

Why one check is not enough. A device D requires 16-byte keys. First, an attacker runs the KNOB attack while D pairs with a new phone: D computes n=7n = 7, which is less than 16, and fails the pairing at step 2. Second, D also holds a bond stored years ago, when its software accepted 10-byte keys. Reconnection reuses that stored key without pairing, so step 2 never runs for it. The check at encryption reads the stored size 10, which is less than 16, and refuses the link; or the check at access refuses data that needs 16 bytes.

A device reports a maximum of 16 bytes during pairing. The same peer offers 12 bytes on each of two fresh pairing attempts, so the smaller maximum is 12 both times. Assume the peer accepts this size and all other pairing checks succeed. On the first attempt the device’s effective minimum is 12 bytes. Equality passes the size check, and pairing can proceed. On the second attempt the device requires 16 bytes. The offered 12 falls below 16, so the device rejects pairing at the size check.

Stated precisely

Let MAM_A and mAm_A be the largest and smallest key sizes, in bytes, that device A accepts, and MBM_B and mBm_B those of device B, all between 7 and 16. Device A computes n=min(MA,MB)n = \min(M_A, M_B) with MBM_B as A received it, which an attacker may have changed; B does the same with MAM_A as B received it. Device A continues the pairing only if n≥mAn \ge m_A, and B only if n≥mBn \ge m_B. The key KK that the pairing produces is replaced by KK with its 16−n16 - n most significant bytes set to zero. If the nn remaining bytes are uniformly random and unknown to the attacker, the attacker must search 28n2^{8n} candidates, and a single guess is right with probability 2−8n2^{-8n}. The count 28n2^{8n} is an upper limit on the attacker’s work, not a guarantee: it holds only if the key has 8n8n bits of entropy §5.26, meaning unpredictability, from the attacker’s point of view.

The contract of a minimum mm: a device that checks n≥mn \ge m at pairing, checks the stored size of every key when it encrypts a link, and checks the current link’s key size whenever a peer asks for data that requires mm, never serves that data over a link whose key has fewer than mm secret bytes. The contract assumes that the device records the true size with every key, and that no path, such as reconnection with an old bond, reaches the data without passing one of the checks.

Limits and common mistakes

Key size is not key strength. A 16-byte key from LE legacy pairing §7.20 with Just Works §7.22, in which the temporary key is zero, can be computed by anyone who recorded the pairing. Key size counts the bytes that are not forced to zero; it says nothing about how they were generated or who saw them.

Key size is not authentication. A 16-byte key from Just Works may be shared with a man-in-the-middle §7.26 (MITM) attacker. Security level 4 requires both: 16 bytes and an authenticated key.

The requested maximum proves nothing about the result, because under LE Secure Connections the negotiation is not authenticated. Read the size of the key actually in use.

A check that runs only at pairing misses keys that were created earlier, under a weaker setting, and are reused on reconnection.

A 16-byte minimum locks out peers whose maximum is smaller. They cannot pair with the device at all, which is the intended outcome of such a minimum.

The cipher’s key width never changes: the mode in which BLE encrypts the content of each packet and checks its integrity always takes a 16-byte AES key. A tool that reports “128-bit encryption” for a 7-byte key is describing the cipher, not the key.

Questions answered

Which checks enforce a minimum size, and when do they run?

Three checks enforce a minimum encryption key size in BLE (Bluetooth Low Energy), and they run at pairing, when a link is encrypted, and at access. The encryption key size is the number of secret bytes in the link key, from 7 to 16; a shorter key is a 16-byte key with its most significant bytes set to zero.

  1. At pairing, in the first phase, after the Pairing Request and the Pairing Response: each device takes the smaller of the two stated maximum sizes as the key size and, if that is below its own minimum, fails the pairing with the reason “Encryption Key Size”. This check runs before any key exists, on every pairing.

  2. When a link is encrypted, after pairing and on every reconnection that reuses a stored key: the device’s software compares the key size stored with the key against its requirement and refuses the link if the key is too short. Security level 4 requires 16 bytes.

  3. At access: when a peer asks for data, the device that holds the data compares the current link’s key size with the data’s requirement and refuses the request if the key is too short.

The first check, with a minimum of 16 bytes, defeats the KNOB (Key Negotiation Of Bluetooth) attack, in which an attacker rewrites both unencrypted pairing messages to request 7 bytes: the device computes 7, sees that it is below 16 and stops. The later checks catch what the first cannot: keys stored earlier under a weaker setting, which reconnection reuses without pairing again, and data that needs a larger key than the device’s pairing minimum. A requested maximum, or the name of the cipher, proves nothing; only the size of the key in use counts.

Related entries: Entropy and min-entropy (§5.26), Security level (§7.33), Security Manager Protocol (SMP) (§7.19), Signed versus unsigned comparison (§2.12), Downgrade attack (§1.27), Long-term key (LTK) (§7.28). Further reading: [18, 91, 272, 280].