diff options
Diffstat (limited to 'drivers/staging/rtl8188eu/core/rtw_security.c')
-rw-r--r-- | drivers/staging/rtl8188eu/core/rtw_security.c | 93 |
1 files changed, 10 insertions, 83 deletions
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index e08845729772..c4b16ea6348a 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -41,7 +41,6 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len) u32 stateindex; u8 *state; u32 counter; -_func_enter_; state = parc4ctx->state; parc4ctx->x = 0; parc4ctx->y = 0; @@ -58,7 +57,6 @@ _func_enter_; if (++keyindex >= key_len) keyindex = 0; } -_func_exit_; } static u32 arcfour_byte(struct arc4context *parc4ctx) @@ -67,7 +65,6 @@ static u32 arcfour_byte(struct arc4context *parc4ctx) u32 y; u32 sx, sy; u8 *state; -_func_enter_; state = parc4ctx->state; x = (parc4ctx->x + 1) & 0xff; sx = state[x]; @@ -77,17 +74,14 @@ _func_enter_; parc4ctx->y = y; state[y] = (u8)sx; state[x] = (u8)sy; -_func_exit_; return state[(sx + sy) & 0xff]; } static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32 len) { u32 i; -_func_enter_; for (i = 0; i < len; i++) dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx); -_func_exit_; } static int bcrc32initialized; @@ -102,9 +96,8 @@ static u8 crc32_reverseBit(u8 data) static void crc32_init(void) { -_func_enter_; if (bcrc32initialized == 1) { - goto exit; + return; } else { int i, j; u32 c; @@ -126,15 +119,12 @@ _func_enter_; } bcrc32initialized = 1; } -exit: -_func_exit_; } static __le32 getcrc32(u8 *buf, int len) { u8 *p; u32 crc; -_func_enter_; if (bcrc32initialized == 0) crc32_init(); @@ -142,7 +132,6 @@ _func_enter_; for (p = buf; len > 0; ++p, --len) crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8); -_func_exit_; return cpu_to_le32(~crc); /* transmit complement, per CRC-32 spec */ } @@ -165,7 +154,6 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe) struct security_priv *psecuritypriv = &padapter->securitypriv; struct xmit_priv *pxmitpriv = &padapter->xmitpriv; -_func_enter_; if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL) return; @@ -206,7 +194,6 @@ _func_enter_; } } -_func_exit_; } void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) @@ -218,12 +205,11 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe) u32 keylength; u8 *pframe, *payload, *iv, wepkey[16]; u8 keyindex; - struct rx_pkt_attrib *prxattrib = &(((union recv_frame *)precvframe)->u.hdr.attrib); + struct rx_pkt_attrib *prxattrib = &(((struct recv_frame *)precvframe)->attrib); struct security_priv *psecuritypriv = &padapter->securitypriv; -_func_enter_; - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; + pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; /* start to decrypt recvframe */ if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) { @@ -232,7 +218,7 @@ _func_enter_; keylength = psecuritypriv->dot11DefKeylen[keyindex]; memcpy(&wepkey[0], iv, 3); memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength); - length = ((union recv_frame *)precvframe)->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len; + length = ((struct recv_frame *)precvframe)->len-prxattrib->hdrlen-prxattrib->iv_len; payload = pframe+prxattrib->iv_len+prxattrib->hdrlen; @@ -252,7 +238,6 @@ _func_enter_; &crc, &payload[length-4])); } } -_func_exit_; return; } @@ -263,10 +248,8 @@ static u32 secmicgetuint32(u8 *p) { s32 i; u32 res = 0; -_func_enter_; for (i = 0; i < 4; i++) res |= ((u32)(*p++)) << (8*i); -_func_exit_; return res; } @@ -274,39 +257,32 @@ static void secmicputuint32(u8 *p, u32 val) /* Convert from Us3232 to Byte[] in a portable way */ { long i; -_func_enter_; for (i = 0; i < 4; i++) { *p++ = (u8) (val & 0xff); val >>= 8; } -_func_exit_; } static void secmicclear(struct mic_data *pmicdata) { /* Reset the state to the empty message. */ -_func_enter_; pmicdata->L = pmicdata->K0; pmicdata->R = pmicdata->K1; pmicdata->nBytesInM = 0; pmicdata->M = 0; -_func_exit_; } void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key) { /* Set the key */ -_func_enter_; pmicdata->K0 = secmicgetuint32(key); pmicdata->K1 = secmicgetuint32(key + 4); /* and reset the message */ secmicclear(pmicdata); -_func_exit_; } void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b) { -_func_enter_; /* Append the byte to our word-sized buffer */ pmicdata->M |= ((unsigned long)b) << (8*pmicdata->nBytesInM); pmicdata->nBytesInM++; @@ -325,23 +301,19 @@ _func_enter_; pmicdata->M = 0; pmicdata->nBytesInM = 0; } -_func_exit_; } void rtw_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nbytes) { -_func_enter_; /* This is simple */ while (nbytes > 0) { rtw_secmicappendbyte(pmicdata, *src++); nbytes--; } -_func_exit_; } void rtw_secgetmic(struct mic_data *pmicdata, u8 *dst) { -_func_enter_; /* Append the minimum padding */ rtw_secmicappendbyte(pmicdata, 0x5a); rtw_secmicappendbyte(pmicdata, 0); @@ -356,14 +328,12 @@ _func_enter_; secmicputuint32(dst+4, pmicdata->R); /* Reset to the empty message. */ secmicclear(pmicdata); -_func_exit_; } void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len, u8 *mic_code, u8 pri) { struct mic_data micdata; u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; -_func_enter_; rtw_secmicsetkey(&micdata, key); priority[0] = pri; @@ -386,7 +356,6 @@ _func_enter_; rtw_secmicappend(&micdata, data, data_len); rtw_secgetmic(&micdata, mic_code); -_func_exit_; } @@ -505,7 +474,6 @@ static const unsigned short Sbox1[2][256] = { /* Sbox for hash (can be in ROM) static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, u32 iv32) { int i; -_func_enter_; /* Initialize the 80 bits of P1K[] from IV32 and TA[0..5] */ p1k[0] = Lo16(iv32); p1k[1] = Hi16(iv32); @@ -523,7 +491,6 @@ _func_enter_; p1k[4] += _S_(p1k[3] ^ TK16((i&1)+0)); p1k[4] += (unsigned short)i; /* avoid "slide attacks" */ } -_func_exit_; } /* @@ -553,7 +520,6 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16) { int i; u16 PPK[6]; /* temporary key for mixing */ -_func_enter_; /* Note: all adds in the PPK[] equations below are mod 2**16 */ for (i = 0; i < 5; i++) PPK[i] = p1k[i]; /* first, copy P1K to PPK */ @@ -590,7 +556,6 @@ _func_enter_; rc4key[4+2*i] = Lo8(PPK[i]); rc4key[5+2*i] = Hi8(PPK[i]); } -_func_exit_; } /* The hlen isn't include the IV */ @@ -612,7 +577,6 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe) struct security_priv *psecuritypriv = &padapter->securitypriv; struct xmit_priv *pxmitpriv = &padapter->xmitpriv; u32 res = _SUCCESS; -_func_enter_; if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL) return _FAIL; @@ -672,7 +636,6 @@ _func_enter_; res = _FAIL; } } -_func_exit_; return res; } @@ -690,13 +653,12 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe) u8 *pframe, *payload, *iv, *prwskey; union pn48 dot11txpn; struct sta_info *stainfo; - struct rx_pkt_attrib *prxattrib = &((union recv_frame *)precvframe)->u.hdr.attrib; + struct rx_pkt_attrib *prxattrib = &((struct recv_frame *)precvframe)->attrib; struct security_priv *psecuritypriv = &padapter->securitypriv; u32 res = _SUCCESS; -_func_enter_; - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; + pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; /* 4 start to decrypt recvframe */ if (prxattrib->encrypt == _TKIP_) { @@ -716,7 +678,7 @@ _func_enter_; iv = pframe+prxattrib->hdrlen; payload = pframe+prxattrib->iv_len+prxattrib->hdrlen; - length = ((union recv_frame *)precvframe)->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len; + length = ((struct recv_frame *)precvframe)->len-prxattrib->hdrlen-prxattrib->iv_len; GET_TKIP_PN(iv, dot11txpn); @@ -747,7 +709,6 @@ _func_enter_; res = _FAIL; } } -_func_exit_; exit: return res; } @@ -821,19 +782,15 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext); static void xor_128(u8 *a, u8 *b, u8 *out) { int i; -_func_enter_; for (i = 0; i < 16; i++) out[i] = a[i] ^ b[i]; -_func_exit_; } static void xor_32(u8 *a, u8 *b, u8 *out) { int i; -_func_enter_; for (i = 0; i < 4; i++) out[i] = a[i] ^ b[i]; -_func_exit_; } static u8 sbox(u8 a) @@ -849,7 +806,6 @@ static void next_key(u8 *key, int round) 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x36, 0x36 }; -_func_enter_; sbox_key[0] = sbox(key[13]); sbox_key[1] = sbox(key[14]); sbox_key[2] = sbox(key[15]); @@ -863,21 +819,17 @@ _func_enter_; xor_32(&key[4], &key[0], &key[4]); xor_32(&key[8], &key[4], &key[8]); xor_32(&key[12], &key[8], &key[12]); -_func_exit_; } static void byte_sub(u8 *in, u8 *out) { int i; -_func_enter_; for (i = 0; i < 16; i++) out[i] = sbox(in[i]); -_func_exit_; } static void shift_row(u8 *in, u8 *out) { -_func_enter_; out[0] = in[0]; out[1] = in[5]; out[2] = in[10]; @@ -894,7 +846,6 @@ _func_enter_; out[13] = in[1]; out[14] = in[6]; out[15] = in[11]; -_func_exit_; } static void mix_column(u8 *in, u8 *out) @@ -908,7 +859,6 @@ static void mix_column(u8 *in, u8 *out) u8 rotr[4]; u8 temp[4]; u8 tempb[4]; -_func_enter_; for (i = 0 ; i < 4; i++) { if ((in[i] & 0x80) == 0x80) add1b[i] = 0x1b; @@ -952,7 +902,6 @@ _func_enter_; xor_32(add1bf7, rotr, temp); xor_32(swap_halfs, rotl, tempb); xor_32(temp, tempb, out); -_func_exit_; } static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext) @@ -962,7 +911,6 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext) u8 intermediatea[16]; u8 intermediateb[16]; u8 round_key[16]; -_func_enter_; for (i = 0; i < 16; i++) round_key[i] = key[i]; for (round = 0; round < 11; round++) { @@ -984,7 +932,6 @@ _func_enter_; next_key(round_key, round); } } -_func_exit_; } /************************************************/ @@ -995,7 +942,6 @@ static void construct_mic_iv(u8 *mic_iv, int qc_exists, int a4_exists, u8 *mpdu, uint payload_length, u8 *pn_vector) { int i; -_func_enter_; mic_iv[0] = 0x59; if (qc_exists && a4_exists) mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */ @@ -1009,7 +955,6 @@ _func_enter_; mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */ mic_iv[14] = (unsigned char) (payload_length / 256); mic_iv[15] = (unsigned char) (payload_length % 256); -_func_exit_; } /************************************************/ @@ -1019,7 +964,6 @@ _func_exit_; /************************************************/ static void construct_mic_header1(u8 *mic_header1, int header_length, u8 *mpdu) { -_func_enter_; mic_header1[0] = (u8)((header_length - 2) / 256); mic_header1[1] = (u8)((header_length - 2) % 256); mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */ @@ -1036,7 +980,6 @@ _func_enter_; mic_header1[13] = mpdu[13]; mic_header1[14] = mpdu[14]; mic_header1[15] = mpdu[15]; -_func_exit_; } /************************************************/ @@ -1047,7 +990,6 @@ _func_exit_; static void construct_mic_header2(u8 *mic_header2, u8 *mpdu, int a4_exists, int qc_exists) { int i; -_func_enter_; for (i = 0; i < 16; i++) mic_header2[i] = 0x00; @@ -1079,7 +1021,6 @@ _func_enter_; mic_header2[15] = mpdu[31] & 0x00; } -_func_exit_; } /************************************************/ @@ -1090,7 +1031,6 @@ _func_exit_; static void construct_ctr_preload(u8 *ctr_preload, int a4_exists, int qc_exists, u8 *mpdu, u8 *pn_vector, int c) { int i; -_func_enter_; for (i = 0; i < 16; i++) ctr_preload[i] = 0x00; i = 0; @@ -1107,7 +1047,6 @@ _func_enter_; ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */ ctr_preload[14] = (unsigned char) (c / 256); /* Ctr */ ctr_preload[15] = (unsigned char) (c % 256); -_func_exit_; } /************************************/ @@ -1117,10 +1056,8 @@ _func_exit_; static void bitwise_xor(u8 *ina, u8 *inb, u8 *out) { int i; -_func_enter_; for (i = 0; i < 16; i++) out[i] = ina[i] ^ inb[i]; -_func_exit_; } static int aes_cipher(u8 *key, uint hdrlen, u8 *pframe, uint plen) @@ -1142,7 +1079,6 @@ static int aes_cipher(u8 *key, uint hdrlen, u8 *pframe, uint plen) uint frtype = GetFrameType(pframe); uint frsubtype = GetFrameSubType(pframe); -_func_enter_; frsubtype = frsubtype>>4; _rtw_memset((void *)mic_iv, 0, 16); @@ -1253,7 +1189,6 @@ _func_enter_; bitwise_xor(aes_out, padded_buffer, chain_buffer); for (j = 0; j < 8; j++) pframe[payload_index++] = chain_buffer[j]; -_func_exit_; return _SUCCESS; } @@ -1274,7 +1209,6 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe) /* uint offset = 0; */ u32 res = _SUCCESS; -_func_enter_; if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL) return _FAIL; @@ -1318,7 +1252,6 @@ _func_enter_; } -_func_exit_; return res; } @@ -1344,7 +1277,6 @@ static int aes_decipher(u8 *key, uint hdrlen, /* uint offset = 0; */ uint frtype = GetFrameType(pframe); uint frsubtype = GetFrameSubType(pframe); -_func_enter_; frsubtype = frsubtype>>4; _rtw_memset((void *)mic_iv, 0, 16); @@ -1514,7 +1446,6 @@ _func_enter_; res = _FAIL; } } -_func_exit_; return res; } @@ -1524,11 +1455,10 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe) int length; u8 *pframe, *prwskey; /* *payload,*iv */ struct sta_info *stainfo; - struct rx_pkt_attrib *prxattrib = &((union recv_frame *)precvframe)->u.hdr.attrib; + struct rx_pkt_attrib *prxattrib = &((struct recv_frame *)precvframe)->attrib; struct security_priv *psecuritypriv = &padapter->securitypriv; u32 res = _SUCCESS; -_func_enter_; - pframe = (unsigned char *)((union recv_frame *)precvframe)->u.hdr.rx_data; + pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; /* 4 start to encrypt each fragment */ if ((prxattrib->encrypt == _AES_)) { stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); @@ -1552,14 +1482,13 @@ _func_enter_; } else { prwskey = &stainfo->dot118021x_UncstKey.skey[0]; } - length = ((union recv_frame *)precvframe)->u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len; + length = ((struct recv_frame *)precvframe)->len-prxattrib->hdrlen-prxattrib->iv_len; res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length); } else { RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_encrypt: stainfo==NULL!!!\n")); res = _FAIL; } } -_func_exit_; exit: return res; } @@ -1767,7 +1696,6 @@ void rtw_use_tkipkey_handler(void *FunctionContext) { struct adapter *padapter = (struct adapter *)FunctionContext; -_func_enter_; RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("^^^rtw_use_tkipkey_handler ^^^\n")); @@ -1775,5 +1703,4 @@ _func_enter_; RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("^^^rtw_use_tkipkey_handler padapter->securitypriv.busetkipkey=%d^^^\n", padapter->securitypriv.busetkipkey)); -_func_exit_; } |