Pairing, Bonding and Privacy

Two Bluetooth devices must agree on a secret while a stranger listens, and maybe stands in between. One check, six digits on two screens, separates a safe pairing from a hijacked one.

Learn how a ring and a phone make a secret in public, what they store afterwards, why the ring’s address keeps changing, and what a thief really gets from a stolen phone or a stolen ring.

Press Pair them with the attacker off. Then switch the attacker on and pair with Just Works, then with Numeric Comparison. Watch which keys each side ends up holding. Then we build, piece by piece: the three phases, the key exchange, the check, the bond, the changing address, and the thief.

You need to know that two devices swap packets over a radio (BLE from radio to GATT covers it) and why a chip keeps secrets in flash (secure boot and device security). We build the cryptography from zero.

Part of Firmware from Zero to Expertise. Built from the Bluetooth LE pairing material in the Nordic Developer Academy, NIST SP 800-121 Rev. 2 and the Zephyr source. Every idea is re-taught here in our own words and devices.

Pair them, with an attacker watching

A model, not a real radio. It does the real shape of LE Secure Connections: a key agreement, two nonces, and a six digit check value. The numbers are toy: a 31-bit prime instead of the P-256 curve, and a simple mixing function instead of AES-CMAC, so the keys are not safe. The one-in-a-million odds are the real six-digit figure.

Chapter 0

Why a Ring Needs a Handshake

See what a stranger hears from a ring, and name the three jobs that pairing, bonding and privacy each do

You wear a smart ring. All night it counts heartbeats and movement. In the morning your phone shows how you slept. Between the ring and the phone there is no wire. There are only radio packets, and every phone, laptop and cheap scanner within about ten metres can hear them.

Someone at the next table in a cafe can hear them too. Two bad things could happen. They could read your sleep data. Worse, they could send the ring a packet of their own, and the ring would have to decide whether to trust it.

A packet is a short burst of bytes with a header and a payload. The ring cannot tell who sent a packet by looking at it. A radio packet carries no return address that you can trust. Anyone can write any address into the header.

The first fix: scramble the payload with a shared secret

The ring and the phone can scramble every payload with a secret number that only they know. This is encryption. The scrambled bytes look like noise to a stranger. The two devices unscramble them with the same number, called a key. Try it. Pick a message, then switch encryption on.

What the air shows a stranger

Each line shows the 16 payload bytes as hex, then as text. Switch encryption on and see which line stays readable. Press Next packet to try other messages.

A model. The scrambling here is a simple byte-by-byte XOR with a pseudo-random stream, only to show the idea. Real BLE links use AES-CCM, an authenticated cipher (NIST SP 800-121 Rev. 2). The messages are made up.

On real hardware. Use an nRF52840 DK as a sniffer (Nordic’s nRF Sniffer for Bluetooth LE with Wireshark, set up in the Nordic Academy Bluetooth LE Fundamentals lesson 6). Capture a phone talking to a second DK that runs a Zephyr peripheral. Compare the payload bytes of an unencrypted read with an encrypted one.

Encryption solves reading. It does not solve the harder question. To scramble with a shared key, the two devices must first have the same key. They cannot send it over the air, because the stranger hears that too. So they need a way to agree on a secret in public. That is the whole job of pairing.

Three jobs, three words

The Bluetooth standard splits the work into three jobs. Each job gets a word. People mix the words up, so fix them now.

Pairing makes the shared key. It happens once, with a conversation of a few messages. Bonding stores that key in flash memory, so the two devices recognise each other next time without a new conversation. NIST defines the pair this way: “creating one or more shared secret keys and the storing of these keys for use in subsequent connections in order to form a trusted device pair” (SP 800-121 Rev. 2).

Privacy is a third job. Even with perfect encryption, the ring shouts its own address in every advertisement. A scanner that logs that address learns when you enter a building. Privacy makes the address change, so only your phone can link the changes back to one ring.

Three symptoms you will meet

Each job has a failure that you can see on a bench. They are the reason this lesson exists.

Symptom one: pairing seems to work, but an attacker sat in the middle all along. This is the hero at the top of the page. Chapters 3 to 5 explain why it happens and what stops it.

Symptom two: the phone says “paired”, but the ring refuses to talk after a reboot, or the other way round. One side lost the key. Chapter 6 explains what each side stores and why they must agree.

Symptom three: a scanner logs your ring at the same cafe every day. Chapter 7 shows the address trick that stops it. Chapters 8 and 9 then ask the question in the title of this lesson: if someone steals the phone, what exactly do they get, and why is that different from stealing the ring?

The road

  1. The air is public: why the old pairing method fell to a million guesses.
  2. The pairing conversation: three phases and the real bytes in them.
  3. Who has a screen? How the devices pick one of four methods.
  4. Key exchange: agreeing on a secret in public.
  5. The check: how six digits catch the man in the middle.
  6. Bonding: what is stored, and what goes wrong when it is not.
  7. Privacy: an address that changes every 15 minutes.
  8. Security levels: making the stack refuse weak links.
  9. The thief: a stolen phone, a stolen ring, and the design that limits each.
  10. Field guide: numbers, checklist, core code.
Two devices have never met. A stranger hears every packet they exchange. What must pairing achieve that encryption alone cannot?

Chapter 1

The Air Is Public: The Million-Guess Lock

See why the first Bluetooth LE pairing method fell to anyone who recorded one pairing, and why six digits were never enough

Picture a researcher at a cafe table with a small radio sniffer. It looks like a USB stick. A customer sits down and pairs a new fitness band with a phone. The whole pairing lasts under a second. The sniffer records it, and the researcher goes home with a file.

An hour later, the researcher can read everything that band ever says to that phone. This was a real result. Mike Ryan published a tool called crackle in 2013 that does exactly this against the first generation of BLE pairing. The next sections show why it works.

How the first pairing method hid its secret

The first BLE pairing method is now called LE Legacy Pairing. It shipped in Bluetooth 4.0 and 4.1 and got that name in 4.2 (NIST SP 800-121 Rev. 2). Its idea is simple. Both devices start from a small shared number, the Temporary Key, or TK. Then they prove to each other that they know it.

Where does the TK come from? It depends on the method. With Just Works, the TK is simply zero. With Passkey Entry, one device shows a six-digit number and the user types it on the other. The TK is that number, padded out to 128 bits. NIST puts it plainly: the passkey is 6 digits, “therefore, a maximum of 20 bits of entropy can be provided.”

Entropy is the number of yes-or-no guesses an attacker needs, counted in bits. A 20-bit secret has about a million possible values. Six digits give exactly 1,000,000 values, from 000000 to 999999. Since 219 is 524,288 and 220 is 1,048,576, that is a little under 20 bits.

Why the proof leaks the secret

To prove it knows the TK, each device sends a confirm value. This is the output of a scrambling function, fed with the TK, a fresh random number and some addresses. The other side repeats the calculation and checks that the answer matches. The random numbers go over the air in plain view. So do the confirm values.

That is the leak. A listener holds the random numbers and the confirm value. The only unknown is the TK. So the listener tries every TK, from 000000 up. For each guess, it recomputes the confirm value. When one matches, that guess is the TK.

With the TK in hand, the listener recomputes the next key in the chain, the Short Term Key (STK). The STK encrypts the rest of the pairing. In that encrypted rest, the devices send the long-lived keys: the Long Term Key (LTK), the Identity Resolving Key and the Connection Signature Resolving Key. The listener decrypts them all. NIST sums it up: with legacy pairing, “if an attacker can capture the pairing frames, he or she can determine the resulting LTK,” and it calls legacy pairing “broken” for every method except Out of Band with a 128-bit TK.

Run the attack yourself. The device below captures one pairing, then tries all 1,000,000 values in your browser.

Crack a captured pairing

The three captured values are what a sniffer hears. Choose how the two devices picked their TK, then press Search all 1,000,000 keys. Watch the bar and the clock.

A model. The confirm function here is a toy mixing function, not the real AES-based c1 of the specification, so each try costs less than a real one. The search loop, the 1,000,000 candidates and the measured speed on your device are real. The real attack needs the pairing frames, which an Ubertooth-class sniffer can record; crackle reports a search of under a second on a modern CPU.

On real hardware. Use two nRF52840 DK boards, one as sniffer and one as a Zephyr peripheral built with CONFIG_BT_SMP_SC_PAIR_ONLY=n so legacy pairing is allowed. Capture one pairing from a phone and filter on SMP. Check whether your capture format works with crackle, and time the search. Then rebuild with the default (y) and see the pairing become an LE Secure Connections one.

The just-works key falls on the very first try, because it is zero. The passkey falls at try 482,914. The 128-bit key does not fall at all, because it is not one of the million values. But look at what the read-out says about the cost of guessing it. That gap, 20 bits against 128 bits, is the whole story of this chapter.

The worked numbers

Take your measured speed, say 3 million tries per second. A million guesses cost 1,000,000 ÷ 3,000,000, about 0.33 seconds. A real confirm function is slower, perhaps one microsecond per try on a laptop, and then the cost is one second. Either way the human waits less than a heartbeat.

Now take a random 128-bit key. There are 2128, about 3.4 × 1038, possible values. At 3 million tries per second that is 1.1 × 1032 seconds, or roughly 250 trillion times the age of the universe (about 4.4 × 1017 seconds). Nobody searches that. The difference is not a bit of extra effort. It is a different universe of effort.

The failure mode

Symptom. A product ships with a six-digit passkey printed on the box and the feature name “secure pairing”. Measurement. Record one pairing with a sniffer, run a search over 000000 to 999999, and read the LTK. It takes about a second. Fix. Stop using Legacy Pairing. Use LE Secure Connections, the 4.2 method in the next chapters. In Zephyr, the Kconfig option BT_SMP_SC_PAIR_ONLY (“Disable legacy pairing”) defaults to y, so a fresh project already refuses legacy pairing.

Notice what went wrong in the design. The secret was small, and the proof of it was visible. LE Secure Connections fixes both: the secret becomes a number the attacker never sees, built by the two devices together.

Why can a sniffer that records one Legacy Pairing with a six-digit passkey recover the long-term key?

Chapter 2

The Pairing Conversation: Three Phases, Real Bytes

Read the first seven bytes of a pairing and see how they decide which of the next chapters' methods can run at all

A ring sits on its charger. You open the app and tap Add device. The phone connects to the ring (Chapter 1 of BLE from radio to GATT shows how). At this moment the link is open and unprotected. Before any key exists, the two devices must have a short, awkward conversation: what can each of us do, and what do we want?

This conversation runs on a protocol with a plain name, the Security Manager Protocol, or SMP. It rides inside ordinary BLE packets, on its own fixed channel, and every message starts with a one-byte code that says what kind of message it is. Zephyr’s smp.h lists them: 0x01 Pairing Request, 0x02 Pairing Response, 0x03 Pairing Confirm, 0x04 Pairing Random, 0x05 Pairing Failed, 0x0b Security Request, 0x0c Public Key and 0x0d DHKey Check.

Three phases

The conversation has three phases. Think of two strangers who must meet, agree on a language, build a secret, and then swap business cards.

Phase 1, feature exchange. The phone sends a Pairing Request. The ring answers with a Pairing Response. Each states what it can do. No secrets move. Everything here is plain text on the air.

Phase 2, key generation. The devices build the key that will encrypt the link. In LE Secure Connections this uses the key exchange of Chapter 4 and the check of Chapter 5. It ends with each side holding a Long Term Key. They switch encryption on with it.

Phase 3, key distribution. Now that the link is encrypted, the devices hand over the extra keys. The most important one is the Identity Resolving Key, which Chapter 7 uses for privacy. In Secure Connections each side builds the LTK itself, so the LTK is never sent. NIST notes this: “each device independently generates the LTK.”

The seven bytes of phase 1

Look at the Pairing Request. After the code, it carries six fields. Together they are only seven bytes, yet they decide how the whole pairing goes.

FieldBytesMeaning
Code10x01 request, 0x02 response
IO capability10 display only, 1 display with yes/no, 2 keyboard only, 3 no input no output, 4 keyboard and display
OOB flag10 or 1: does this device hold out-of-band data?
AuthReq1A byte of flags, shown below
Max key size1At most 16 bytes, which is 128 bits
Initiator key dist.1Which keys the phone will hand over in phase 3
Responder key dist.1Which keys the ring will hand over in phase 3

The AuthReq byte (authentication requirements) is a row of flag bits. Zephyr names them in smp.h: 0x01 bonding, 0x04 MITM, 0x08 SC, 0x10 keypress and 0x20 CT2. MITM means man in the middle: “I want protection against one.” SC means Secure Connections: “I can do the elliptic-curve method.” Both devices must set SC, or they fall back to Legacy Pairing and the million-guess lock of Chapter 1.

The key distribution bytes also use flag bits: 0x01 encryption key, 0x02 identity key, 0x04 signing key, 0x08 link key. Build a request below and watch the bytes change.

Build the Pairing Request

Choose the ring’s IO capability, then switch the AuthReq flags and the key distribution bits on and off. The seven bytes at the top are what goes on the air.

The field layout and the flag values are the ones in Zephyr’s subsys/bluetooth/host/smp.h, which implements the Bluetooth Core Specification Vol 3 Part H. The default shown (bonding, MITM and SC, with an identity key) is a typical request, chosen for illustration.

On real hardware. On an nRF52840 DK with the sniffer running, filter Wireshark on SMP and open the Pairing Request. Compare its seven bytes with the AuthReq and key distribution flags your Kconfig and callbacks produce. Repeat with the SC bit off in a test build.

A worked example

Take the defaults. The IO capability is 1 (display with yes/no). The OOB flag is 0. For AuthReq, add the flags: bonding 0x01 + MITM 0x04 + SC 0x08 + CT2 0x20 = 0x2d. The max key size is 16, which is 0x10. Each key distribution byte holds the identity bit, 0x02. The request is therefore 01 01 00 2d 10 02 02. Seven bytes, and no secret in them.

The ring compares this with its own capabilities and sends back its Pairing Response in the same format. From the two IO capability bytes, both sides compute the same answer to one question: which method do we use? That table is Chapter 3. Notice that nothing here is protected. An attacker can read these bytes, and can also change them in flight. That is one more reason Chapter 5 matters.

The failure mode

Symptom. The phone shows “pairing failed” and the ring log shows a Pairing Failed message. The message carries a one-byte reason. Measurement. Read that reason against the list in smp.h: 0x03 authentication requirements, 0x05 pairing not supported, 0x06 encryption key size, 0x0c numeric comparison failed. Fix. Match what the ring asks for with what the phone can give. A ring built with Secure Connections only, for example, answers 0x03 to an old phone that cannot do SC (Zephyr’s smp.c returns it when the request lacks the SC bit).

One more message belongs to phase 1. The ring can send a Security Request (0x0b) to ask the phone to start pairing. A small device often does this, because the ring knows when it needs protection and the phone only knows what it is told.

The ring sets the SC bit in its AuthReq byte, but the phone does not. What happens?

Chapter 3

Who Has a Screen? IO Capabilities and the Four Methods

Look up which method a ring and a phone will use, and see why a ring with no screen cannot check anything

A product manager asks for one-tap pairing. No numbers, no typing, just a tap on the phone. It sounds friendly. The ring is a small band of metal with a battery and no screen. The engineer asks a harder question: how will the ring know the phone is the right phone?

Chapter 2 showed that the Pairing Request names what each device can show and what it can accept. That field is the IO capability (input and output). Here is the idea in plain words. A human can only check something if a device lets the human see it or type it. A ring with no screen and no keys gives the human nothing to check.

Four ways to prove you are talking to the right device

Just Works. Nobody checks anything. The devices make a key and trust whoever answered. Think of handing a house key to the first person who knocks. In Secure Connections, NIST describes it this way: the Numeric Comparison procedure runs, “but the user is not shown the 6-digit values and the final commitment checks are not performed.” The key that results is unauthenticated: no human ever confirmed who is on the other end.

Numeric Comparison. Both devices show a six-digit number. The user checks that the two numbers match and says yes on each. It is like two friends in a noisy room who each read a code word aloud. If they hear the same word, nobody swapped the messages. It needs a screen and a yes/no input on both devices. Chapter 5 shows exactly how the number is computed.

Passkey Entry. One device shows a six-digit number. The user types it into the other device. The typed number takes part in the key agreement, bit by bit. NIST notes that an attacker has “a one-in-a-million chance of guessing the correct passkey to perform a MITM attack.” It needs a display on one side and a keyboard on the other.

Out of Band (OOB). The two devices swap some data through a different channel than the radio, such as an NFC tap or a QR code. An attacker would need to break both channels at once. It needs hardware for that second channel.

The lookup table

The devices do not negotiate this. Each runs the same table and arrives at the same answer. The table sits in Zephyr’s smp.c as gen_method_sc, with the comment that it is “based on table 2.8 Core Spec 2.3.5.1 Vol. 3 Part H”. The inputs are the two IO capability bytes. Two more conditions sit on top: if neither side asks for MITM protection, the answer is Just Works, and if out-of-band data is available, OOB wins. Try the table.

Look up the pairing method

Pick the ring’s capability and the phone’s. The highlighted cell is the method for that pair, in LE Secure Connections. Or press a preset product.

The 5 by 5 table is the gen_method_sc table in Zephyr’s smp.c (Secure Connections), with rows for the phone and columns for the ring. Letters: JW Just Works, NC Numeric Comparison, PD this side displays the passkey, PI this side types the passkey. PD and PI are named from the ring’s point of view.

On real hardware. On an nRF52840 DK running a Zephyr peripheral, register different bt_conn_auth_cb callbacks (none, pairing_confirm, passkey_confirm, passkey_display) and pair with a phone each time. After each pairing, log bt_conn_get_security() and note which method the phone chose.

Start with the screenless ring and the phone with keyboard and display. The table says Just Works. Every row of the ring’s “no input, no output” column says Just Works, whatever the phone offers, because the human has nothing to check on the ring. Now try the watch with a screen and a tap: both sides show a number, so Numeric Comparison applies.

What it means for the key

A pairing produces a key, and the key carries a label: authenticated or not. Just Works yields an unauthenticated key. The other three methods yield an authenticated key. Later, the GATT permissions of Chapter 8 can ask for the label. A characteristic marked “authenticated” refuses a link whose key is unauthenticated.

NIST is blunt about the cost: for Low Energy, “Just Works pairing should not be used.” The ring in your pocket is exactly the case where the guideline and the hardware collide. Chapter 9 shows what a screenless device can do about it.

The failure mode

Symptom. The product page says “secure pairing”, yet pairing is one tap. Measurement. After pairing, read the link’s security level with bt_conn_get_security() in Zephyr. A Just Works pairing reports level 2, which means encryption without authentication. Fix. Either add something a human can check (a button press that confirms a pairing mode, an NFC tap for OOB), or accept level 2 and keep sensitive actions behind a second gate.

A ring has no screen, no buttons and no NFC. It pairs with a phone that has a screen and keyboard. Which method results, and what kind of key?

Chapter 4

Agreeing on a Secret in Public

Follow two devices that shout numbers across a room and still end up with a number the room cannot compute

Two painters stand in a crowded hall. They want to share one secret colour without whispering it. Each starts with the same public tin of yellow paint. Each secretly picks a private colour and mixes a spoonful into the yellow. Then they swap the mixed tins in public. Everyone sees both tins.

Now each painter adds their own private colour to the tin they received. Both tins end with yellow plus both private colours. Order does not matter for paint, so the two tins match. The crowd saw only the mixed tins. Un-mixing paint to find a private colour is very hard. The crowd cannot reach the final tin.

That is the whole idea of the Diffie-Hellman key exchange. Replace the paint with a calculation that is easy to do forward and very hard to undo.

The calculation

The easy-forward calculation is a power with a remainder. Pick a prime number p and a number g, both public. Raise g to a secret power a, then keep only the remainder after dividing by p. Written A = ga mod p. Going forward takes a few steps. Going backward, finding a from A, has no known shortcut for large p. This is the discrete logarithm problem.

Each device does the same. The ring keeps secret a and sends A. The phone keeps secret b and sends B. The ring then computes Ba mod p. The phone computes Ab mod p. Both equal gab mod p, because exponents multiply in either order.

A worked example you can check by hand

Take p = 23 and g = 5. The ring picks a = 6. Then A = 56 mod 23. Compute 52 = 25, which is 2 mod 23. Then 56 = 23 = 8. So the ring sends 8.

The phone picks b = 15. Then B = 515 mod 23 = 19. The ring now computes 196 mod 23. Since 19 is −4 mod 23, 196 is 46 = 4096, and 4096 mod 23 is 2. The phone computes 815 mod 23, which is also 2. Both hold the shared secret 2. An eavesdropper saw 23, 5, 8 and 19, never 6 or 15, and cannot easily name 2.

With a prime this small, the eavesdropper just tries every exponent. The prime is too small. Try it, then make the prime bigger.

Agree on a secret, then try to steal it

Drag the two private exponents and watch both sides reach the same secret. Then press Eavesdropper searches and switch the size of the prime.

6
15

A model. The first three sizes are finite-field Diffie-Hellman with toy primes; the larger two secrets come from the sliders by a fixed formula. Real LE Secure Connections uses the P-256 elliptic curve instead, where each public key is 64 bytes (two 32-byte coordinates, as in Zephyr’s bt_smp_public_key). The 2128 figure is the usual 128-bit security level for P-256, not a measurement.

On real hardware. On an nRF52840 DK (Cortex-M4F at 64 MHz) toggle a GPIO pin when the Public Key message arrives and again when the DHKey Check is sent, and read the gap on a logic analyzer. That gap is the real cost of the elliptic-curve step on your part. Repeat on an STM32 Nucleo if you can.

With p = 23 the search ends in a handful of tries. With 10,007 it still ends in a blink. With 231 − 1 the worst case is over two billion tries, which the read-out turns into seconds at your measured speed. A real curve is far beyond any search. The trick is not that the maths is secret. The maths is public. It is that the reverse step is hopeless at real sizes.

What the real protocol does with it

In LE Secure Connections, each device makes a new private key (32 random bytes) and the matching public key. The public key goes in a Public Key message (0x0c) with the x and y coordinates, 32 bytes each. Each side computes the shared value from its own private key and the other’s public key, the DHKey. Then a scrambling function, called f5 in the specification and implemented in Zephyr as bt_crypto_f5, mixes the DHKey with the two nonces and both device addresses. Its output is the LTK. The LTK is never sent. Each side computes it, which is why NIST says each device independently generates it.

Zephyr also checks a small trap. If the peer sends a public key equal to your own, it rejects the pairing, because that could mean a reflected message.

The flaw: this does not tell you who you are talking to

Back to the hall. Suppose a third person stands between the two painters. The ring thinks it receives the phone’s tin. It actually receives the third person’s tin. The phone does the same. Now the ring shares a secret with the stranger, and the phone shares a different secret with the stranger. Each side did the maths correctly. Each side is wrong about who it is talking to.

Key exchange hides the secret from a passive listener. It does nothing against someone who plays both parts. For that, the devices need an extra step that a human can verify. That is the next chapter.

An eavesdropper records the public key from the ring and the public key from the phone. Why can it not compute the shared secret?

Chapter 5

The Check That Catches the Man in the Middle

Trace Numeric Comparison step by step and count the odds an attacker has of making two screens agree

You tap Add device on a watch with a screen. Both screens light up. The phone says 482 913. The watch says 071 556. Your thumb hovers over Yes. The numbers differ, so you tap No, and a message says pairing failed. Somebody was in the middle. You just caught them with your eyes.

The numbers on the screens are the whole defence. Here is why they work. Each number is computed from everything the device saw: both public keys and both nonces. If an attacker swapped a public key, each device saw a different set of inputs. So each computes a different number.

The six steps

A nonce is a random number used once. Let A be the device that starts pairing (the phone) and B the one that answers (the ring). In LE Secure Connections with Numeric Comparison, the messages go like this.

  1. Swap public keys. A sends PKa, B sends PKb (Chapter 4, message 0x0c).
  2. B commits. B picks a random nonce Nb and sends a confirm value Cb, a scrambled fingerprint of Nb and the keys (Pairing Confirm, 0x03). B has locked in Nb but not revealed it.
  3. A reveals. A picks Na and sends it (Pairing Random, 0x04).
  4. B reveals. B sends Nb (0x04). A recomputes the fingerprint and checks it against Cb. A mismatch ends pairing with the error code 0x04, confirm failed.
  5. Both compute the number. Each device calculates g2(PKa, PKb, Na, Nb), takes the result modulo 106, and shows six digits. Zephyr’s test applies % 1000000 to the 32-bit output of g2.
  6. You compare. If the numbers match, you press Yes on both. Each side then sends a DHKey Check (0x0d) that proves it holds the same DHKey. If you press No, the pairing fails with 0x0c, numeric comparison failed.

Why step 2 first? Imagine B revealed Nb freely. An attacker could try many nonces of its own until the two numbers happened to match. By committing early, each side locks in its nonce before it sees the other’s. The attacker cannot grind. That is a commitment: a sealed envelope, opened later.

What the attacker faces

The attacker sits between ring and phone. It must run two pairings: one with the ring, pretending to be the phone, and one with the phone, pretending to be the ring. In the first, the ring sees the attacker’s public key M1. In the second, the phone sees the attacker’s key M2. The inputs to g2 differ on the two sides, since the keys and nonces differ. The two numbers are two unrelated six-digit draws. They match only by luck.

Six digits give 1,000,000 possible values. The chance that two unrelated draws match is 1 in 1,000,000 per attempt. NIST records the same one-in-a-million figure for passkey entry, which uses the same six digits. Each failed attempt also shows the user a visible refusal. Play with it: change the number of digits and run many attempts.

Count the lucky matches

Each attempt gives the ring and the phone two unrelated numbers, as in a man-in-the-middle attack. Choose how many digits are compared, then run 200,000 attempts and count the lucky matches.

6

A model. Each attempt draws fresh random inputs for the ring side and the phone side and hashes them with the toy mixing function from the hero, then keeps the last N digits. Real g2 uses AES-CMAC. The six-digit figure is the specification’s; the other digit counts are what-ifs. The run uses your browser’s random numbers, so each run differs.

On real hardware. With two nRF52840 DK boards running the Zephyr numeric comparison callbacks, print the six digits over RTT or serial on both, pair them, and check they match. Then answer No on one side and read the failure code in the sniffer: 0x0c, numeric comparison failed.

At 6 digits, 200,000 attempts should give about 0.2 lucky matches, so most runs show none. At 3 digits you will see about 200. At 1 digit, about 20,000. The spec’s six digits are a balance: few enough that a human can compare them in a second, many enough that one attempt is a lottery.

A worked example of the odds

One attempt succeeds with probability 10−6. Suppose the attacker can force the pairing to restart 10 times, and the user taps No each time. The chance that any attempt slips through is 1 − (1 − 10−6)10, which is about 0.00001, or 1 in 100,000. To reach even odds the attacker needs about 693,000 attempts, and the user would have refused 693,000 times. No sane user keeps tapping Yes after a failure.

The defence has a human in the loop, and it holds only if the human really compares. Honest use matters: if a UI shows the number but accepts a tap on Yes without looking, the check is a ritual.

The failure mode

Symptom. A user reports that pairing worked, but a second phone reads the ring. Measurement. Check which method ran. If it was Just Works, nothing was compared (Chapter 3). If it was Numeric Comparison, check that the app showed the six digits and waited for an explicit Yes. Fix. Register the numeric comparison callback so the stack asks for a confirmation (passkey_confirm in Zephyr’s bt_conn_auth_cb), show the six digits, and call bt_conn_auth_passkey_confirm() only after the user presses Yes; call bt_conn_auth_cancel() on No.

Why do the two screens show different numbers when an attacker relays the pairing with its own keys?

Chapter 6

Bonding: Remembering the Secret

Store the key so devices reconnect with no ceremony, and see what breaks when only one side remembers

Next morning you walk into the kitchen. The phone in your hand and the ring on your finger find each other. Nothing appears on screen. No numbers, no prompt. A second later the phone shows last night’s sleep. The two devices recognised each other and switched encryption on, all without you.

That quiet reconnect is bonding. At the end of pairing, each side wrote the new key to non-volatile memory, next to the identity of its partner. A bond is that stored record. The record is why a device can say “I know you” after a reboot.

What a bond contains

Zephyr keeps one record per bonded device in a struct called bt_keys (keys.h). The important fields are these.

FieldSizeWhat it is for
Peer address7 bytes (type + 6)Which device this bond belongs to (the identity address)
LTK value16 bytesThe long term key that encrypts every future link
LTK rand and ediv8 + 2 bytesLabels used by Legacy Pairing; unused in Secure Connections
IRK16 bytesResolves the peer’s changing address (Chapter 7)
Key size, flagsa few bytesHow long the key is, and whether it is authenticated

The essentials add up: 7 + 16 + 16 = 39 bytes of address and key material per bond. That is small. Zephyr writes it through its settings subsystem when BT_SETTINGS is on. The flags matter as much as the keys. They record whether the key came from an authenticated method (Chapter 3), because the stack must refuse to treat an unauthenticated key as an authenticated one later.

Reconnecting

On reconnect, the phone tells the ring to start encryption with the key it holds for that ring. The ring looks up its own record for the phone’s identity, finds the same key, and the link is encrypted. No pairing conversation runs. It costs a few packets, not a human.

This only works if both sides remember. That is the catch. Two devices hold two copies of one secret, in two flash chips, written at slightly different moments. Either copy can be lost. Try the failure cases.

Break the bond on one side

Press Pair A, then Reconnect A. Then make one side forget and reconnect again. Watch the ring’s slots and the phones’ copies.

A model of the bond table and the checks around it. Default values are Zephyr’s: BT_MAX_PAIRED is 1, and BT_SMP_ALLOW_UNAUTH_OVERWRITE is off. The clone is an attacker who copies phone A’s address and starts a Just Works pairing; the ring cannot tell it from A returning after a reset. The error name for a missing key on the ring side is the standard HCI code 0x06, “PIN or Key Missing”.

On real hardware. On an nRF52840 DK with CONFIG_BT_SETTINGS=y, pair a phone, reboot the DK and reconnect: no pairing runs. Then clear the DK’s bond with bt_unpair but keep the phone’s, reconnect, and record the disconnect reason on the phone.

Three things to try. First, press Pair A, Phone A forgets, Reconnect A: the phone has no key, so it starts pairing, and the ring (still holding the old bond) refuses. Second, Pair A, Ring forgets A, Reconnect A: the phone presents a key the ring has lost, and encryption fails. Third, turn on the overwrite switch, pair A over Just Works, and let the clone pair: the clone replaces your bond, and your own phone can no longer reconnect.

Why the ring refuses by default

Zephyr’s help text for BT_SMP_ALLOW_UNAUTH_OVERWRITE states the risk: “an attacker could copy the peer device address to connect and start an unauthenticated pairing procedure to replace the existing bond.” When the option is off, “the old bond has to be explicitly deleted with bt_unpair.” The default is the safe choice: a stranger cannot replace your bond, and you must remove it on purpose.

The cost shows up in support. A user who resets the phone but not the ring cannot pair. The ring says it already knows that address. The product needs a clear way to clear the ring’s bond, and that way must itself be protected (Chapter 9).

Slots and power cuts

BT_MAX_PAIRED sets how many bonds the ring keeps. Its default is 1. A ring that is meant for one owner should keep it at 1, because every extra slot is one more phone that can read the ring. Bonds also live in flash. A power cut in the middle of a write can leave the ring without its copy while the phone still has its own, the first failure above. The flash lessons in flash filesystems and power fail cover how to write such records safely.

The failure mode

Symptom. The phone shows the ring as paired but cannot connect, or the ring connects but nothing works until you remove and add the device. Measurement. Log the disconnect reason on the phone. HCI code 0x06 means the ring had no key for it. Compare bond lists: the stack can list bonded addresses on both sides. Fix. If one side has a bond and the other does not, delete the surviving half on purpose and pair again. Never keep a bond that its partner cannot confirm.

The phone says the ring is paired, but encryption on reconnect fails with “PIN or Key Missing”. What is the most likely cause?

Chapter 7

Privacy: An Address That Changes

Make a ring change its address every 15 minutes, and see how only the bonded phone can still recognise it

A cafe owner puts a cheap Bluetooth scanner behind the counter. It just logs every address it hears, with a time. After a month the log shows one address that appears every weekday at 08:40 and leaves at 09:05. The owner has no name. But a pattern is a fingerprint. If that address is on your ring, the log knows when you come and go.

Pairing, encryption and bonding do nothing about this. The ring still shouts its address in each advertisement, in plain view. NIST explains the risk plainly: when a device keeps a fixed public address and stays discoverable, “its location could easily be tracked by an adversary.”

The idea: an address that looks random and is not

The fix gives the ring a changing address. A stranger sees a fresh, random-looking address every few minutes and cannot link them. But your phone must still know it is the same ring. So the new address is not random. It carries a hidden proof that only a holder of a secret key can check.

That secret is the Identity Resolving Key, or IRK, a 16-byte key. The ring and the phone swapped it in phase 3 of pairing, over the encrypted link (Chapter 2). A stranger never had it. The changing address is called a Resolvable Private Address (RPA): “resolvable” because someone with the IRK can resolve it back to one identity.

How the address is built

A Bluetooth address has 48 bits. For an RPA, Zephyr’s rpa.c and addr.h show the layout.

  1. Draw a random part. The ring takes 3 random bytes, 24 bits, called prand.
  2. Mark it as an RPA. The top two bits of the address are forced to 01. Zephyr tests for this with (val[5] & 0xc0) == 0x40. That leaves 22 free random bits.
  3. Compute a hash. The function ah is defined as ah(k, r) = e(k, r') mod 224. Here e is AES encryption, the key k is the IRK, and r' is prand padded with zeros to 16 bytes. Keep the last 24 bits of the answer.
  4. Join them. The address is prand in the top 24 bits and the hash in the bottom 24.

To resolve an address, the phone does the same sum. It takes the top 24 bits as prand, runs ah with each IRK it has stored, and compares the answer with the bottom 24 bits. In Zephyr this is bt_addr_matches_irk. If the hash matches, the address belongs to that bonded device. A stranger without the IRK cannot do the sum, so the address looks like noise.

How often does it change? Zephyr’s BT_RPA_TIMEOUT says: “how often resolvable private address is rotated. Value is provided in seconds and defaults to 900 seconds (15 minutes).” Turn privacy on with BT_PRIVACY. Slide through a morning below.

What the scanner logs

Choose how the ring advertises, then drag the time. The address shown is what the scanner hears at that moment. Colours on the bar mark each period with one address.

2 h 05 min

A model. The rotation interval and the address layout are real (Zephyr’s defaults and rpa.c). The hash here is a toy mixing function standing in for AES, so the resolving step is the same shape but not secure. The IRK and the times are made up for illustration.

On real hardware. On an nRF52840 DK, enable CONFIG_BT_PRIVACY=y and set CONFIG_BT_RPA_TIMEOUT=60. In the sniffer’s device list, watch the DK’s address change every minute. Then bond a phone and confirm the phone still shows one device.

With a fixed address, the log has one name for all eight hours. With 900-second rotation, the scanner hears 32 different addresses in 480 minutes, since 480 ÷ 15 = 32. With 60 seconds it hears 480. Your phone, holding the IRK, resolves every one of them to the same ring. The scanner cannot.

A worked example of the bits

The address has 2 fixed bits, 22 random bits and 24 hash bits: 2 + 22 + 24 = 48. The 22 random bits allow 4,194,304 values per rotation. A stranger who guesses a random address has no hash to match. For a stranger to fake an address your phone accepts, the hash must also match, which needs the IRK.

The failure mode

Symptom. You turned on privacy, yet a scanner still follows your ring. Measurement. Group the captured advertisements by something other than the address: the device name, the manufacturer data, the advertising interval. If one payload value stays constant across addresses, the group is the ring. Fix. Do not put a unique name or serial number in the advertisement. Put identity behind the encrypted link instead. This is engineering reasoning, not a quote from the specification.

One more consequence. Privacy means the address stops being a label you can type into a log. A bench engineer must read the IRK from the bond to follow one ring across changes. That is the trade, and it is the right one.

How does a bonded phone know that a brand-new address belongs to the same ring?

Chapter 8

Security Levels: Making the Stack Refuse

Mark each piece of ring data with the link strength it needs, and let the Bluetooth stack say no to weaker links

The ring has four things a phone can touch. Battery percentage: harmless. Last night’s sleep log: private. Settings: a bad write could ruin the night. Erase all bonds: a bad write could hand the ring to someone else. Surely these do not all deserve the same lock.

Chapters 1 to 7 built links of different strength. The stack needs a way to say how strong a link is, and a way for the firmware to demand a minimum. Bluetooth calls the first a security level. The second is a permission on each data item.

Four levels

For LE, NIST SP 800-121 describes Security Mode 1 with four levels. Zephyr’s conn.h gives them in short comments.

LevelZephyr nameMeaning
1BT_SECURITY_L1No encryption and no authentication
2BT_SECURITY_L2Encryption and no authentication (no MITM protection)
3BT_SECURITY_L3Encryption and authentication (MITM protection)
4BT_SECURITY_L4Authenticated Secure Connections and a 128-bit key

Map these onto what you built. A Just Works link, with a key nobody checked, reaches level 2. A passkey or numeric comparison link reaches level 3. If that link also used LE Secure Connections with a full 128-bit key, it reaches level 4. NIST singles out level 4 as the strongest: it “requires authenticated low energy Secure Connections.”

Permissions on data

Data on a BLE device lives in a table of attributes (GATT, covered in BLE from radio to GATT). Each attribute has permission flags. Zephyr’s gatt.h defines the strict ones: BT_GATT_PERM_READ_ENCRYPT (needs encryption), BT_GATT_PERM_READ_AUTHEN (“requires encryption using authenticated link-key”) and BT_GATT_PERM_READ_LESC (“requires that LE Secure Connections is used”), each with a WRITE twin. When a phone reads or writes an attribute, the stack checks the link against the flags. If the link falls short, the stack answers with an error code, and your handler never runs. The two common ones are ATT error 0x0f, insufficient encryption, and 0x05, insufficient authentication.

That last point is the useful one. You do not write a check in your handler. You declare a need, and the stack refuses on your behalf. Try all five link types against all four items.

Which link can touch which data?

Choose how the phone linked up, then press a data item to request it. The grid shows every pair; the ring outlines your choice.

A model of the permission checks. The rules follow Zephyr’s documentation for the flags and for BT_SMP_SC_ONLY, which allows only Security Mode 1 Level 4 except for services that need no security. The data items and their permissions are an illustrative ring, not a real product.

On real hardware. On an nRF52840 DK, build the service above, connect with the nRF Connect mobile app without pairing, and try each read and write. Record the ATT error code for each refused request, then pair and repeat.

Read down the grid. The battery level is open to everyone. The sleep log needs encryption, so every paired link passes, even Just Works. The settings write needs an authenticated key, so the Just Works links fail with 0x05. The erase item needs both authentication and LE Secure Connections, so only the last link passes. Turn on Secure Connections only mode and watch the middle links vanish. With that Kconfig option, the ring can only reach level 4 (or level 1 for open data).

Here is the ring’s attribute table, with those permissions, in Zephyr C. The extra comments say what the stack does.

c/* each characteristic declares the link strength it needs */
BT_GATT_SERVICE_DEFINE(ring_svc,
    BT_GATT_PRIMARY_SERVICE(&ring_uuid),
    BT_GATT_CHARACTERISTIC(&battery_uuid.uuid, BT_GATT_CHRC_READ,
        BT_GATT_PERM_READ, read_battery, NULL, NULL),            /* any link */
    BT_GATT_CHARACTERISTIC(&sleep_uuid.uuid, BT_GATT_CHRC_READ,
        BT_GATT_PERM_READ_ENCRYPT, read_sleep, NULL, NULL),       /* level 2 or higher */
    BT_GATT_CHARACTERISTIC(&cfg_uuid.uuid, BT_GATT_CHRC_WRITE,
        BT_GATT_PERM_WRITE_AUTHEN, NULL, write_cfg, NULL),         /* authenticated key */
    BT_GATT_CHARACTERISTIC(&erase_uuid.uuid, BT_GATT_CHRC_WRITE,
        BT_GATT_PERM_WRITE_AUTHEN | BT_GATT_PERM_WRITE_LESC,
        NULL, write_erase, NULL));                            /* authenticated + SC */

/* in prj.conf */
# CONFIG_BT_SMP=y   CONFIG_BT_SETTINGS=y   CONFIG_BT_MAX_PAIRED=1
# CONFIG_BT_SMP_SC_ONLY=y   CONFIG_BT_PRIVACY=y   CONFIG_BT_RPA_TIMEOUT=900

One request, step by step

A phone linked by Secure Connections Just Works asks to write the settings item. Follow the request through the ring.

  1. Arrive. The write request reaches the attribute layer with the handle of the settings item.
  2. Look up. The stack reads the item’s permission: BT_GATT_PERM_WRITE_AUTHEN.
  3. Look at the link. It is encrypted, it used Secure Connections, but the key is not authenticated.
  4. Compare. The item needs an authenticated key. The link has none. Your write_cfg handler is never called.
  5. Answer. The stack sends an error response with code 0x05 and the same handle.

The phone can now ask for more by calling bt_conn_set_security() at level 3 or 4, and pairing runs again. For a screenless ring that retry cannot succeed, because the method is still Just Works. The honest answers are the ones from Chapter 3: add something a human can check, or guard the item another way.

The failure mode

Symptom. A test app that never paired can write the settings, because the developer left the permission at BT_GATT_PERM_WRITE while testing and shipped it. Measurement. Connect with a generic scanner app, never pair, and try to write. Anything that works at level 1 is open to the room. Fix. Give every write the strictest permission its job needs. In your own central code you can ask for more with bt_conn_set_security(conn, BT_SECURITY_L4), which starts pairing if the link is not yet strong enough.

You mark a characteristic BT_GATT_PERM_WRITE_AUTHEN. A phone linked by Just Works tries to write it. What happens?

Chapter 9

The Stolen Phone, the Stolen Ring

Work out what a thief holds in each case, and which firmware choices decide how much damage follows

Two bad days. On the first, someone lifts your unlocked phone from a cafe table. On the second, your ring slips off in a gym and a stranger pockets it. The secrets are the same ones from Chapters 4 to 7. What the thief can do with them is very different.

Start with a fact from Chapter 4. In LE Secure Connections both devices compute the same 16-byte Long Term Key. It is a symmetric secret: the same bytes live in both places. Whoever holds the bytes can play the part of either device. The bond is a bearer credential, like a house key. The ring cannot tell your hand from a thief’s hand holding that phone.

What the thief holds

A stolen phone holds the phone’s half of the bond: the LTK, plus the ring’s IRK from phase 3. At the Bluetooth level the thief is the phone. The ring will talk. It will answer reads. And with the IRK the thief can recognise the ring’s changing address (Chapter 7), so the thief can follow the wearer.

A stolen ring holds the ring’s half: the same LTK, plus the phone’s IRK, plus the ring’s stored data. If a skilled thief can read the chip’s flash, the LTK is enough to pose as the ring when your phone reconnects, and the phone’s IRK is enough to follow the phone. That is why device security matters here: debug lock and flash readout protection decide whether those bytes can be copied out of the chip. The ring has no lock screen, and a ring on a table is a chip in a thief’s hand.

A third attacker steals nothing. A person near you copies your phone’s address from the air and tries to pair with the ring as you. Chapter 6 covered that clone.

The honest limit of Bluetooth

Bluetooth proves one thing: this device holds the key. It does not prove the person is the owner. Nothing in the pairing protocol can fix a stolen unlocked phone. The answer must live one layer up, in firmware and the app. The choices below are design patterns, not Bluetooth rules. They are engineering judgement and each trades something away.

Now try the sandbox. Choose who has what, switch design choices on and off, and watch the outcomes.

What does the thief get?

Pick a scenario. Then toggle the design choices. Each of the five outcomes turns green when the design blocks it.

A reasoning model, not a measurement. The rules encode the argument of this chapter: a bond is a symmetric bearer credential, protected keys stop flash copies, a physical gesture stops only remote clones, and a token check lasts only as long as the token. A real product needs its own threat model.

On real hardware. On an nRF52840 DK or an STM32 Nucleo, enable flash readout protection (APPROTECT on the nRF52840, RDP on STM32; device security shows the steps), then try to read flash with a debugger. Confirm the bond bytes no longer come out.

A worked example

Take the stolen unlocked phone with no design choices on. All five outcomes, except the one that needs the ring itself, go to the thief. Turn on the owner-token check. Nothing changes, because the thief’s phone still holds a valid token. Turn on “owner revoked the phone”. Now reads, writes and takeover all turn green, because the token expires and the ring refuses. Tracking stays red: the phone holds the IRK for as long as the ring keeps this identity.

The token lifetime sets the exposure. Say the app issues a token valid for 24 hours, and the phone was unlocked and had a fresh one at 10:00. The thief can read until 10:00 the next day, 24 hours. With a 15-minute token the window is 15 minutes, but the app must refresh it every 15 minutes, which costs radio time and battery. This is a real design trade, and the numbers are illustrative.

The failure mode

Symptom. A user reports a stolen phone, and support says “we signed the phone out of your account”. The ring still sends data to the thief. Measurement. Pair a test phone, sign it out in the account, and try to read from the ring. If the read works, revocation never reached the ring. Fix. Make the ring check a short-lived token, and give the owner a way to clear the ring’s bond from a new phone with a physical gesture, which also generates a new IRK for the ring.

A thief holds your unlocked phone. Which design choice most directly limits what the ring gives them, after you report the theft?

Chapter 10

Field Guide: Pairing, Bonding and Privacy

Review the numbers, run the checklist and keep the core code for the next ring you build

You can now trace a pairing from the first byte to the last, say why the old method fell to a million guesses, and show on a bench which links can touch which data.

The one-paragraph summary

Pairing makes a shared key in three phases: feature exchange, key generation, key distribution. LE Secure Connections builds the key from an elliptic-curve key exchange, so a listener learns nothing. A plain key exchange cannot tell who is on the other end, so the devices add a check a human can make: Numeric Comparison shows six digits, Passkey Entry types them, Out of Band uses a second channel, and Just Works checks nothing. The IO capabilities of both devices pick the method. Bonding stores the key and the peer’s identity on both sides; privacy makes the ring’s address a changing, resolvable one. Security levels and GATT permissions let the firmware demand a minimum link strength. A bond is a bearer credential, so the stolen-phone question is answered above Bluetooth, in tokens and key protection.

The numbers and terms

WhatValueSource and why it matters
Legacy passkey6 digits, 1,000,000 values, at most 20 bitsNIST SP 800-121 Rev. 2. Searchable offline in about a second.
Numeric Comparison6 digits; match by chance 1 in 1,000,000g2 output modulo 106 in Zephyr; NIST gives the same odds for passkey.
SMP codes0x01 req, 0x02 rsp, 0x03 confirm, 0x04 random, 0x05 failed, 0x0b security request, 0x0c public key, 0x0d DHKey checkZephyr smp.h
Pairing Request7 bytes: code, IO, OOB, AuthReq, max key, two key-dist bytesZephyr smp.h
AuthReq flagsbonding 0x01, MITM 0x04, SC 0x08, keypress 0x10, CT2 0x20Zephyr smp.h. No SC bit means legacy fallback.
IO capabilities0 display only, 1 display yes/no, 2 keyboard only, 3 none, 4 keyboard and displayZephyr smp.h. A screenless ring gets Just Works.
Public key64 bytes (x 32 + y 32), P-256Zephyr bt_smp_public_key; NIST for P-256
KeysLTK 16 bytes, IRK 16 bytes, max key size 16 bytesZephyr keys.h and smp.h. A bond is about 39 bytes of essentials.
Failure codesSMP 0x04 confirm failed, 0x0c numeric comparison failed; ATT 0x05 authentication, 0x0f encryptionZephyr smp.h, att.h
Resolvable private address48 bits = 2 (01) + 22 random + 24 hashZephyr rpa.c and addr.h
RPA rotation900 s (15 minutes) defaultZephyr BT_RPA_TIMEOUT
Bond slotsBT_MAX_PAIRED default 1Zephyr Kconfig
Security levels1 none, 2 encrypted, 3 authenticated, 4 authenticated SC with 128-bit keyZephyr conn.h; NIST Security Mode 1

The checklist for a new device

The core in code

The ring-side pieces that show up in almost every Zephyr project. This is a sketch; show_digits and the button handlers stand for your own display and input code.

c/* prj.conf: CONFIG_BT_SMP=y  CONFIG_BT_SETTINGS=y  CONFIG_BT_MAX_PAIRED=1
              CONFIG_BT_PRIVACY=y  CONFIG_BT_RPA_TIMEOUT=900  CONFIG_BT_SMP_SC_PAIR_ONLY=y */
static struct bt_conn *pending;

static void passkey_confirm(struct bt_conn *conn, unsigned int passkey)
{
    pending = conn;
    show_digits(passkey);                /* six digits, to compare with the phone */
}
static void on_yes(void) { bt_conn_auth_passkey_confirm(pending); }
static void on_no(void)  { bt_conn_auth_cancel(pending); }       /* peer sees 0x0c */
static void cancel(struct bt_conn *conn) { pending = NULL; }

static struct bt_conn_auth_cb auth_cb = {
    .passkey_confirm = passkey_confirm,
    .cancel = cancel,
};
static void pairing_complete(struct bt_conn *conn, bool bonded)
{
    /* bt_conn_get_security(conn) says what level you really got */
}
static struct bt_conn_auth_info_cb info_cb = { .pairing_complete = pairing_complete };

void security_init(void)
{
    bt_conn_auth_cb_register(&auth_cb);
    bt_conn_auth_info_cb_register(&info_cb);
}
/* owner-approved reset: forget every bond and wipe stored readings */
void factory_reset(void) { bt_unpair(BT_ID_DEFAULT, BT_ADDR_LE_ANY); wipe_log(); }

Where this sits

Pairing sits between the radio and the application. BLE from radio to GATT built the link and the attribute table this lesson protects. Secure boot and device security protects the chip that stores the keys. A pairing ends with a record in flash, so flash filesystems and power fail decides whether the record survives a power cut. A signed owner token is the same kind of signature check as a signed firmware image in bootloaders and OTA.

Keep going

The takeaway. Pairing is where two strangers make a secret in public, and the check at the end of it is the only thing between a safe bond and a hijacked one. Bonding makes that secret last. Privacy keeps the ring from being a name tag. And a bond is a key that fits whoever holds it, so a stolen phone is a problem you solve with firmware choices, not with more cryptography.
A screenless ring is shipped with default Zephyr settings and no extra gates. A tester sniffs a first pairing and sees an attacker relay it. Which statement fits?

Sources used

Now press Present or Teach and walk through one pairing out loud: the three phases, why the key exchange needs a check, what the six digits prove, what is stored, and what a thief holds in each case. Then go back to the top, switch the attacker on and pair with each method once more.

Pairing, Bonding and Privacy · Firmware from Zero to Expertise
Nordic Developer Academy, Bluetooth LE Fundamentals · NIST SP 800-121 Rev. 2 · Zephyr · Back to Gleams