--- src/sys/netproto/802_11/wlan_wep/ieee80211_crypto_wep.c 2006/12/22 23:57:53 1.4 +++ src/sys/netproto/802_11/wlan_wep/ieee80211_crypto_wep.c 2007/05/07 14:12:16 1.5 @@ -59,6 +59,11 @@ static int wep_encap(struct ieee80211_ke static int wep_decap(struct ieee80211_key *, struct mbuf *, int hdrlen); static int wep_enmic(struct ieee80211_key *, struct mbuf *, int); static int wep_demic(struct ieee80211_key *, struct mbuf *, int); +static int wep_getiv(struct ieee80211_key *, struct ieee80211_crypto_iv *, + uint8_t); +static int wep_update(struct ieee80211_key *, + const struct ieee80211_crypto_iv *, + const struct ieee80211_frame *); static const struct ieee80211_cipher wep = { .ic_name = "WEP", @@ -73,6 +78,8 @@ static const struct ieee80211_cipher wep .ic_decap = wep_decap, .ic_enmic = wep_enmic, .ic_demic = wep_demic, + .ic_getiv = wep_getiv, + .ic_update = wep_update }; static int wep_encrypt(struct ieee80211_key *, struct mbuf *, int hdrlen); @@ -241,6 +248,13 @@ wep_decap(struct ieee80211_key *k, struc return 1; } +static int +wep_update(struct ieee80211_key *k, const struct ieee80211_crypto_iv *iv, + const struct ieee80211_frame *wh) +{ + return 1; +} + /* * Verify and strip MIC from the frame. */ @@ -250,6 +264,43 @@ wep_demic(struct ieee80211_key *k, struc return 1; } +static int +wep_getiv(struct ieee80211_key *k, struct ieee80211_crypto_iv *ivp, + uint8_t keyid) +{ + struct wep_ctx *ctx = k->wk_private; + uint32_t iv; + + /* + * Skip 'bad' IVs from Fluhrer/Mantin/Shamir: + * (B, 255, N) with 3 <= B < 16 and 0 <= N <= 255 + */ + iv = ctx->wc_iv; + if ((iv & 0xff00) == 0xff00) { + int B = (iv & 0xff0000) >> 16; + if (3 <= B && B < 16) + iv += 0x0100; + } + ctx->wc_iv = iv + 1; + + /* + * NB: Preserve byte order of IV for packet + * sniffers; it doesn't matter otherwise. + */ +#if _BYTE_ORDER == _BIG_ENDIAN + ivp->ic_iv[0] = iv >> 0; + ivp->ic_iv[1] = iv >> 8; + ivp->ic_iv[2] = iv >> 16; +#else + ivp->ic_iv[2] = iv >> 0; + ivp->ic_iv[1] = iv >> 8; + ivp->ic_iv[0] = iv >> 16; +#endif + ivp->ic_iv[3] = keyid; + + return 1; +} + static const uint32_t crc32_table[256] = { 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,