In WEP, how do the IV and the root key form the RC4 key, and why is keystream reuse expected on a busy network?
answer
- stream cipher, same key twice
- IV then root key
- about 2^24 values
- birthday collisions
- ciphertexts XOR to plaintexts
basics
~20 sWEP's per-frame RC4 key is the clear 24-bit IV followed by the static root key. Only the IV changes, and only about 16.8 million values exist, so IVs repeat, and two frames under one IV and key share a keystream.
solid answer
~40 sThe sender picks a 24-bit IV, puts it in front of the static root key (5 octets for WEP-40, 13 for WEP-104) and uses those 8 or 16 octets as the RC4 key for that frame. The IV is sent in the clear. Because RC4 is a stream cipher, two frames encrypted under the same IV and root key use the same keystream, and the XOR of their ciphertexts equals the XOR of their plaintexts, so one known plaintext exposes the other. With fewer than 17 million IVs and a root key that never changes, reuse is a matter of when: NIST SP 800-97 puts a random-IV collision at even odds after roughly 2^12 frames, and a sequential counter can exhaust the space in hours on a busy WLAN.
go deeper
Recall that the IV is 24 bits, sent in the clear, and prepended to the shared key, so the keystream can repeat.
Explain the 8-octet and 16-octet RC4 keys, the 2^24 IV space, and why two frames under one IV give the combination of two plaintexts.
Quote the NIST figures at their strength (under 17 million values, about 2^12 frames for a random collision) and explain why no IV policy or rotation schedule fixes it.
Use it to argue that a protocol whose only varying input is public cannot be tuned into safety and has to be retired.
## The construction in one line A stream cipher turns a key into a keystream and XORs it into the data. It is safe only if no key is used for two messages. WEP builds a *per-frame* key from two parts: a short, public, changing part (the **IV**) and a long, secret, unchanging part (the **root key**). Everything that varies from frame to frame sits in the short part. | Label | Root key | IV | Per-frame RC4 key | Where it comes from | |---|---|---|---|---| | WEP-40, "64-bit" | 5 octets | 3 octets | 8 octets | `WLAN_KEY_LEN_WEP40`, selector 00-0F-AC:1 in the Linux header | | WEP-104, "128-bit" | 13 octets | 3 octets | 16 octets | `WLAN_KEY_LEN_WEP104`, selector 00-0F-AC:5 | | 16-character key, "152-bit" | 16 octets | 3 octets | 19 octets | hostapd.conf's `wep_key0` comment (a non-standard extension) | The frame carries a 4-octet IV field (`IEEE80211_WEP_IV_LEN`) holding the 24-bit IV and a key index, because up to four root keys can be configured (hostapd's `wep_default_key` accepts 0 to 3). NIST SP 800-97 adds that the standard itself specifies only the 40-bit key; longer ones are vendor extensions. ## Why reuse is expected, not unlucky 1. **Small space.** A 24-bit IV has 2^24 = 16,777,216 values, which NIST SP 800-97 rounds to "less than 17 million". 2. **No rule for choosing it.** WEP does not say how the IV is set or changed. The guide records products that use a static, well-known value or reset to zero. 3. **Sequential counters wrap.** On a busy WLAN the whole space can be used up in a few hours, and devices that share one root key each run their own counters, so collisions across devices need no wrap at all. 4. **Random choice collides early.** By the birthday effect, two randomly chosen IVs have a 50 % chance of colliding after about 2^12 frames, the guide's figure. 5. **The root key never changes.** Only the IV varies, so a repeated IV means a repeated keystream. Without key management in the standard, replacing the root key is a manual job on every device. ## What a repeat gives away If two frames are encrypted under the same IV and root key, the keystream cancels when their ciphertexts are combined, and the result is the combination of the two plaintexts. NIST SP 800-97 states the consequence: if the plaintext of either message is known, the plaintext of the second is "relatively trivial" to determine, and because many frames start with common protocol headers, a plaintext is often easy to identify. The root key itself is not needed for this. That is a property of any stream cipher used with a repeated key, and the theory belongs to the material on cipher modes and nonces; here it matters because WEP makes the repeat unavoidable. ## What it puts at risk, and what to do - **Confidentiality** of traffic on the SSID, even before any key recovery. - **Nothing a setting can narrow.** A random IV, a sequential IV or a quarterly key change does not remove the exposure, because the IV space and the key sharing are fixed by the protocol. - **The decision** is to move the devices to CCMP-based WPA2 or later, the generation that carries a packet number instead of a short IV; TKIP was the interim retrofit and is itself a deprecated stopgap. ## Reading a configuration In hostapd, which builds WEP only when `CONFIG_WEP=y` is set, the key length is read from the value of `wep_key0` to `wep_key3`: 5, 13 or 16 characters, or 10, 26 or 32 hexadecimal digits. A 13-character key is therefore a WEP-104 key and a "128-bit" SSID, and the 24 bits of IV are on top of it. ## How it is noticed An operator normally cannot see an IV collision: the access point does not report one, and the traffic looks normal. The exposure is found from configuration and monitoring, as a WEP security type on an SSID, a `wep_key0` to `wep_key3` entry in a hostapd configuration, or a weak-protocol finding in a wireless IDPS or scanner report. Because collisions cannot be seen or prevented, the finding is treated as present for as long as the SSID exists. ## Common slips - Calling the IV secret, or an "extra key", when it is a clear counter-like value. - Believing a sequential IV is safe: it only postpones the repeat. - Counting WEP-104 as a 128-bit secret.
- Does a sequential IV counter avoid the reuse problem?No. A counter cannot repeat until it wraps, but it wraps: NIST SP 800-97 notes the space can be exhausted in a few hours on a busy WLAN. Devices sharing one root key each keep their own counters, and some products reset the counter to zero or use a static value, so repeats also occur earlier.
- How do two frames with the same IV reveal data when the root key stays unknown?Both ciphertexts were XORed with the same keystream, so combining them cancels it and leaves the combination of the two plaintexts. If one plaintext is known or guessable, as standard protocol headers often are, the other follows. The key is not recovered by this step, only the content.
- How do the 40-bit, 104-bit and 16-character key forms in hostapd's sample file map to the 64, 128 and 152-bit labels?The labels add the 24-bit IV: 5 characters is WEP-40 (64-bit), 13 characters is WEP-104 (128-bit), and 16 characters is the non-standard 128-bit secret that hostapd.conf calls 152-bit WEP. In every case the IV is clear and the root key is static.
- The IV is a second secret that protects the root key.
- A sequential IV counter can never produce a repeat.
- Choosing IVs randomly removes the collision problem.
- WEP-104 gives a 128-bit secret key.
- Changing the IV is the same as rekeying the network.