# Inside AirShield, the encryption between Meta's glasses and the phone

> After four handshake messages, everything between Meta glasses and the phone is sealed by AirShield. The handshake, the key schedule, a frame byte by byte, and the two hidden values that made every attempt to guess the MAC fail.

Write-up · 12 Nov 2026 · 6 min read

[Visor](https://www.marco.win/work/visor) is my open-source Android app that replaces the Meta AI app for Ray-Ban Meta and Meta's other smart glasses. Before it can ask the glasses anything, it has to speak AirShield. That's the name the glasses' code gives the layer that seals every message after the first four. This is how it works, down to the byte, and how I found out.

## Four messages, and no secret from Meta

A link starts with a handshake on service 5. Each side sends two messages, RequestEncryption and EnableEncryption.

RequestEncryption carries a fresh P-256 public key, 64 bytes, `x` then `y` with no `04` prefix. With it come a 16-byte challenge, the curve (0, for P-256), a bit set of supported parameters (31), and a version: the phone sends 16, and the glasses send 17. Its header has the most going on of the four:

```
80 62        a header with tags, 98 bytes after the first 4
80 01        channel 0x8001
81 00 00 05  tag 1, the service: 5, more tags follow
02 00 00 01  tag 2, the message type: 1, the last tag
```

EnableEncryption repeats the public key and adds a 32-byte seed, a 16-byte IV and a random 32-bit number to start the sequence from.

Nothing in the handshake needs a secret from Meta. The keys are made fresh on every connect, so anyone can open an encrypted link to the glasses. Who you are comes afterwards, inside that link: on service 36 the phone signs a digest of this handshake with its own key, and the glasses decide from there what it may do. So AirShield keeps the link private, and the question of who gets in is settled one layer up.

## Three ciphers it wasn't

I worked the cipher out months before Visor existed, with a client of my own in Python, and the Meta AI app's native library open in [Ghidra](https://ghidra-sre.org).

The library holds strings for AES-128-CTR, and it exports OpenSSL's cipher functions, so AES-128-CTR was the first reading. Those exports are never called on this path. The next one was XChaCha20-Poly1305, in the shape of libsodium's secretstream, and scanning the app's memory for its state found nothing.

The third looked the most convincing. The library has seal and unseal functions built on ChaCha20-Poly1305, next to helpers named for a bidirectional key and nonce. They are real, and they do seal things, but for another system entirely: HPKE for requests to Meta's private cloud. That code works on X25519 keys, which are 32 bytes. The keys in the handshake are 64 bytes, a point on P-256. The curve didn't match, and that's what gave it away.

The real code sets up exactly one cipher, through mbedtls: AES with 256-bit keys, in CBC mode.

## Catching it live

Static reading gave me the shape, not the details. So I watched the Meta AI app while it talked to real glasses, with [Frida](https://frida.re) hooks on `mbedtls_cipher_setkey` and on the start of the HMAC inside `libstartup.so`. That gave me the real keys at the moment they were set, next to the real frames they sealed. Eight frames across two sessions checked out, MAC and decryption both.

Three things in the static reading were wrong:

1. **Each direction has its own keys.** A link has two AES keys and two HMAC keys, one pair for each way.
2. **The MAC covers eight bytes nobody sends.** Before the block count and the ciphertext come a fixed word, `02 02 00 00`, and the sequence number. Every guess at the MAC so far had started with the sequence alone.
3. **The sequence doesn't start at zero.** It starts at a random 32-bit number, like 2,671,239,201, and it travels in EnableEncryption field 4.

With a hidden word in front and a counter that starts anywhere, no amount of guessing would have matched a tag. Once the frames were settled, I hooked the ECDH output and the bytes going into SHA-256, and rebuilt the device's keys from scratch, three sets of them.

## The key schedule

Both sides use P-256. The shared secret `S` is the 32-byte `x` coordinate of the ECDH point, and each direction gets its keys from HKDF over SHA-256:

```
salt_aes  = SHA-256(nonce || seed)
salt_hmac = SHA-256(seed || nonce || "hmac_derive")
aes_key   = HKDF-Expand(HKDF-Extract(salt_aes,  S), "AirShield", 32)
hmac_key  = HKDF-Expand(HKDF-Extract(salt_hmac, S), "AirShield", 32)
```

The two keys share the `info` string and differ only in their salt: the order of the two inputs, and the label `hmac_derive`. Thirty-two bytes is exactly one HMAC block, so the expand step is a single `HMAC-SHA-256(PRK, info || 01)`.

The inputs cross between the two sides. The nonce is the receiver's challenge, and the seed, the IV and the starting sequence come from the sender. So the keys for the glasses' frames take the phone's challenge and the glasses' EnableEncryption, and the keys for the phone's frames take the glasses' challenge and the phone's EnableEncryption. The two directions share `S` and nothing else.

## One frame, byte by byte

Every frame after the handshake starts with a header byte. Its top two bits are the frame's type, and its low six bits are a stream id. A DATA frame on stream 0 starts with `40`:

| Bytes  | Field                                     |
| ------ | ----------------------------------------- |
| 0      | header, `40` for DATA on stream 0         |
| 1 to 8 | tag, the first 8 bytes of an HMAC-SHA-256 |
| 9      | block count, minus one                    |
| 10 on  | AES-256-CBC ciphertext, 16 bytes a block  |

The tag is computed over the fixed word, the sequence, the block count and the ciphertext, in that order. It's encrypt-then-MAC, and the receiver checks the tag in constant time before it decrypts anything. This is Visor's sealing side:

```kotlin
private fun mac(blockCount: Int, ciphertext: ByteArray): ByteArray {
    val macInput = macPrefix + AirShieldCipher.le32(seq) +
        byteArrayOf(blockCount.toByte()) + ciphertext
    val hmac = Mac.getInstance("HmacSHA256")
    hmac.init(SecretKeySpec(hmacKey, "HmacSHA256"))
    return hmac.doFinal(macInput).copyOf(AirShieldCipher.TAG_SIZE)
}

fun seal(plaintext: ByteArray): ByteArray {
    val ciphertext = AirShieldCipher.aesCbc(aesKey, iv, AirShieldCipher.pad(plaintext), encrypt = true)
    val blockCount = (ciphertext.size / AirShieldCipher.BLOCK) - 1
    require(blockCount in 0..0xFF) { "plaintext too large for a single AirShield frame" }
    val tag = mac(blockCount, ciphertext)
    val frame = tag + byteArrayOf(blockCount.toByte()) + ciphertext
    iv = ciphertext.copyOfRange(ciphertext.size - AirShieldCipher.BLOCK, ciphertext.size)
    seq += 1
    return frame
}
```

The padding is PKCS#7 with a twist. There are always between 1 and 16 pad bytes, and each one holds the pad length plus `0xC0`:

| Plaintext | Pad                |
| --------- | ------------------ |
| 46 bytes  | `C2` twice         |
| 8 bytes   | `C8` eight times   |
| 32 bytes  | `D0` sixteen times |

A block count of one byte allows 256 blocks, and the pad takes at least one byte, so a frame holds at most 4,095 bytes of plaintext. Anything longer continues in the next frame.

## Why one lost frame ends the link

Each frame's IV is the last ciphertext block of the frame before it, and the sequence goes up by one per frame, inside the MAC. Lose a frame and the receiver checks the next one against the wrong sequence, so its tag fails, and so does the tag of every frame after it. Visor ends the link at the first bad tag and connects again with new keys.

The same counters mean only one thread may send at a time. Two writers at once move the IV and the sequence out of step, and every later frame fails with no error to say why. Visor's send path takes a lock.

## One key or two

The parameter bits both sides offer decide part of the schedule. The glasses offer 31. The Neural Band offers 27, which is 31 without bit `0x04`, Multikey. Without Multikey there is no separate HMAC key, and the AES key does both jobs. A phone that keeps two keys against the band gets through the whole handshake and then fails the MAC on the very first frame.

## When a command looks like data

Not every frame is DATA. A COMMAND frame is two bytes in the clear, `[80 | stream][code]`, for opening and closing streams: code 1 is LOST, the glasses' way of hanging up.

The trouble is that the transport measures every incoming message before AirShield sees it, and it treats any first byte with the top bit set as a DataX header. A COMMAND header has the top bit set. Read as DataX, its two bytes give a length of `4 + (((b0 & 0x3F) << 8) | b1)`. For a LOST on stream 0, `80 01`, that's 5 bytes, so the reader takes three bytes of the next message along with it.

It happened for real once the phone started relaying between the Meta Ray-Ban Display and its Neural Band. Both send COMMAND frames on sub-stream 1. Read as DataX, `81 80` claimed 388 bytes, the reader swallowed the frames that followed, and the link dropped on the next byte it couldn't frame, every few seconds.

The length rule alone can't tell the two apart, but the session's phase can. Bare DataX only crosses during the handshake. Once both of the glasses' handshake messages are in, a first byte with the top bit set starts a COMMAND frame, of 2 bytes, or of 5 plus a length when the code itself has the top bit set. With that rule the relay held.

## The cipher belongs to the session

The last surprise came with Wi-Fi. When a session moves from Bluetooth to a Wi-Fi link, the second link runs its own handshake and gets its own keys, but they only carry its trust exchange and its end of setup. After that, both sides go on with the first link's cipher: its keys, its sequence and its IV chain carry on as if the frames still crossed the first link. The cipher belongs to the session, not to the radio.

The handshake fields, the parameters and the failure modes are all on [Visor's protocol pages](https://visor.macedonga.com/protocol/airshield-frames-and-ciphers/).
