static u32 getcrc32(u8 *buf, int len)
{
u8 *p;
- u32 crc;
+ u32 crc;
if (bcrc32initialized == 0) crc32_init();
crc = 0xffffffff; /* preload shift register, per CRC-32 spec */
for (p = buf; len > 0; ++p, --len)
- crc = crc32_table[ (crc ^ *p) & 0xff] ^ (crc >> 8);
+ crc = crc32_table[(crc ^ *p) & 0xff] ^ (crc >> 8);
return ~crc; /* transmit complement, per CRC-32 spec */
}
if ((curfragnum + 1) == pattrib->nr_frags) {
/* the last fragment */
length = pattrib->last_txcmdsz - pattrib->hdrlen -
- pattrib->iv_len- pattrib->icv_len;
+ pattrib->iv_len - pattrib->icv_len;
*((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));
s32 i;
u32 res = 0;
- for (i = 0; i<4; i++) {
- res |= ((u32)(*p++)) << (8*i);
+ for (i = 0; i < 4; i++) {
+ res |= ((u32)(*p++)) << (8 * i);
}
return res;
{
long i;
- for (i = 0; i<4; i++) {
+ for (i = 0; i < 4; i++) {
*p++ = (u8) (val & 0xff);
val >>= 8;
}
{
/* Append the byte to our word-sized buffer */
- pmicdata->M |= ((unsigned long)b) << (8*pmicdata->nBytesInM);
+ pmicdata->M |= ((unsigned long)b) << (8 * pmicdata->nBytesInM);
pmicdata->nBytesInM++;
/* Process the word if it is full. */
if (pmicdata->nBytesInM >= 4) {
{
/* This is simple */
- while(nbytes > 0) {
+ while (nbytes > 0) {
rtw_secmicappend23abyte23a(pmicdata, *src++);
nbytes--;
}
rtw_secmicappend23abyte23a(pmicdata, 0);
rtw_secmicappend23abyte23a(pmicdata, 0);
/* and then zeroes until the length is a multiple of 4 */
- while(pmicdata->nBytesInM != 0) {
+ while (pmicdata->nBytesInM != 0) {
rtw_secmicappend23abyte23a(pmicdata, 0);
}
/* The appendByte function has already computed the result. */
secmicputuint32(dst, pmicdata->L);
- secmicputuint32(dst+4, pmicdata->R);
+ secmicputuint32(dst + 4, pmicdata->R);
/* Reset to the empty message. */
secmicclear(pmicdata);
{
struct mic_data micdata;
- u8 priority[4]={0x0, 0x0, 0x0, 0x0};
+ u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
rtw_secmicsetkey23a(&micdata, key);
- priority[0]= pri;
+ priority[0] = pri;
/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
if (header[1]&1) { /* ToDS == 1 */
#define Lo8(v16) ((u8)((v16) & 0x00FF))
#define Hi8(v16) ((u8)(((v16) >> 8) & 0x00FF))
#define Lo16(v32) ((u16)((v32) & 0xFFFF))
-#define Hi16(v32) ((u16)(((v32) >>16) & 0xFFFF))
+#define Hi16(v32) ((u16)(((v32) >> 16) & 0xFFFF))
#define Mk16(hi, lo) ((lo) ^ (((u16)(hi)) << 8))
/* select the Nth 16-bit word of the temporal key unsigned char array TK[] */
-#define TK16(N) Mk16(tk[2*(N)+1], tk[2*(N)])
+#define TK16(N) Mk16(tk[2 * (N) + 1], tk[2 * (N)])
/* S-box lookup: 16 bits --> 16 bits */
#define _S_(v16) (Sbox1[0][Lo8(v16)] ^ Sbox1[1][Hi8(v16)])
#define RC4_KEY_SIZE 16 /* 128-bit RC4KEY (104 bits unknown) */
/* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
-static const unsigned short Sbox1[2][256]= /* Sbox for hash (can be in ROM) */
+static const unsigned short Sbox1[2][256] = /* Sbox for hash (can be in ROM) */
{ {
0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
/* Now compute an unbalanced Feistel cipher with 80-bit block */
/* size on the 80-bit block P1K[], using the 128-bit key TK[] */
- for (i = 0; i < PHASE1_LOOP_CNT ;i++) {
+ for (i = 0; i < PHASE1_LOOP_CNT; i++) {
/* Each add operation here is mod 2**16 */
- p1k[0] += _S_(p1k[4] ^ TK16((i&1)+0));
- p1k[1] += _S_(p1k[0] ^ TK16((i&1)+2));
- p1k[2] += _S_(p1k[1] ^ TK16((i&1)+4));
- p1k[3] += _S_(p1k[2] ^ TK16((i&1)+6));
- p1k[4] += _S_(p1k[3] ^ TK16((i&1)+0));
+ p1k[0] += _S_(p1k[4] ^ TK16((i & 1) + 0));
+ p1k[1] += _S_(p1k[0] ^ TK16((i & 1) + 2));
+ p1k[2] += _S_(p1k[1] ^ TK16((i & 1) + 4));
+ p1k[3] += _S_(p1k[2] ^ TK16((i & 1) + 6));
+ p1k[4] += _S_(p1k[3] ^ TK16((i & 1) + 0));
p1k[4] += (unsigned short)i; /* avoid "slide attacks" */
}
u16 PPK[6]; /* temporary key for mixing */
/* 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 */
- PPK[5] = p1k[4] +iv16; /* next, add in IV16 */
+ for (i = 0; i < 5; i++) PPK[i] = p1k[i]; /* first, copy P1K to PPK */
+ PPK[5] = p1k[4] + iv16; /* next, add in IV16 */
/* Bijective non-linear mixing of the 96 bits of PPK[0..5] */
PPK[0] += _S_(PPK[5] ^ TK16(0)); /* Mix key in each "round" */
rc4key[3] = Lo8((PPK[5] ^ TK16(0)) >> 1);
/* Copy 96 bits of PPK[0..5] to RC4KEY[4..15] (little-endian) */
- for (i = 0;i<6;i++) {
- rc4key[4+2*i] = Lo8(PPK[i]);
- rc4key[5+2*i] = Hi8(PPK[i]);
+ for (i = 0; i < 6; i++) {
+ rc4key[4 + 2 * i] = Lo8(PPK[i]);
+ rc4key[5 + 2 * i] = Hi8(PPK[i]);
}
}
&pattrib->ra[0]);
}
- if (stainfo!= NULL) {
+ if (stainfo != NULL) {
- if (!(stainfo->state &_FW_LINKED)) {
+ if (!(stainfo->state & _FW_LINKED)) {
DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, stainfo->state);
return _FAIL;
}
prwskeylen = 16;
- for (curfragnum = 0;curfragnum<pattrib->nr_frags;curfragnum++) {
- iv = pframe+pattrib->hdrlen;
- payload = pframe+pattrib->iv_len+pattrib->hdrlen;
+ for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
+ iv = pframe + pattrib->hdrlen;
+ payload = pframe + pattrib->iv_len + pattrib->hdrlen;
GET_TKIP_PN(iv, dot11txpn);
pnl = (u16)(dot11txpn.val);
pnh = (u32)(dot11txpn.val>>16);
- phase1((u16 *)&ttkey[0], prwskey,&pattrib->ta[0], pnh);
+ phase1((u16 *)&ttkey[0], prwskey, &pattrib->ta[0], pnh);
phase2(&rc4key[0], prwskey, (u16 *)&ttkey[0], pnl);
- if ((curfragnum+1) == pattrib->nr_frags) { /* 4 the last fragment */
- length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len- pattrib->icv_len;
+ if ((curfragnum + 1) == pattrib->nr_frags) { /* 4 the last fragment */
+ length = (pattrib->last_txcmdsz -
+ pattrib->hdrlen -
+ pattrib->iv_len -
+ pattrib->icv_len);
+
RT_TRACE(_module_rtl871x_security_c_, _drv_info_,
"pattrib->iv_len =%x, pattrib->icv_len =%x\n",
pattrib->iv_len,
arcfour_init(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length);
- arcfour_encrypt(&mycontext, payload+length, crc, 4);
+ arcfour_encrypt(&mycontext, payload + length, crc, 4);
}
- else{
- length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len ;
+ else {
+ length = (pxmitpriv->frag_len -
+ pattrib->hdrlen -
+ pattrib->iv_len -
+ pattrib->icv_len);
+
*((u32 *)crc) = cpu_to_le32(getcrc32(payload, length));/* modified by Amy*/
arcfour_init(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length);
- arcfour_encrypt(&mycontext, payload+length, crc, 4);
+ arcfour_encrypt(&mycontext, payload + length, crc, 4);
- pframe+= pxmitpriv->frag_len;
- pframe = PTR_ALIGN(pframe, 4);
+ pframe += pxmitpriv->frag_len;
+ pframe = PTR_ALIGN(pframe, 4);
}
}
}
- else{
+ else {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
"rtw_tkip_encrypt23a: stainfo == NULL!!!\n");
DBG_8723A("%s, psta == NUL\n", __func__);
stainfo = rtw_get_stainfo23a(&padapter->stapriv,
&prxattrib->ta[0]);
- if (stainfo!= NULL) {
+ if (stainfo != NULL) {
if (is_multicast_ether_addr(prxattrib->ra)) {
if (psecuritypriv->binstallGrpkey == 0) {
prwskeylen = 16;
}
- iv = pframe+prxattrib->hdrlen;
- payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
- length = skb->len - prxattrib->hdrlen-prxattrib->iv_len;
+ iv = pframe + prxattrib->hdrlen;
+ payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;
+ length = skb->len - prxattrib->hdrlen - prxattrib->iv_len;
GET_TKIP_PN(iv, dot11txpn);
pnl = (u16)(dot11txpn.val);
pnh = (u32)(dot11txpn.val>>16);
- phase1((u16 *)&ttkey[0], prwskey,&prxattrib->ta[0], pnh);
+ phase1((u16 *)&ttkey[0], prwskey, &prxattrib->ta[0], pnh);
phase2(&rc4key[0], prwskey, (unsigned short *)&ttkey[0], pnl);
/* 4 decrypt payload include icv */
arcfour_init(&mycontext, rc4key, 16);
arcfour_encrypt(&mycontext, payload, payload, length);
- *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length-4));
+ *((u32 *)crc) = le32_to_cpu(getcrc32(payload, length - 4));
- if (crc[3]!= payload[length-1] || crc[2]!= payload[length-2] || crc[1]!= payload[length-3] || crc[0]!= payload[length-4])
+ if (crc[3] != payload[length - 1] || crc[2] != payload[length - 2] || crc[1] != payload[length - 3] || crc[0] != payload[length - 4])
{
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
"rtw_wep_decrypt23a:icv error crc[3](%x)!= payload[length-1](%x) || crc[2](%x)!= payload[length-2](%x) || crc[1](%x)!= payload[length-3](%x) || crc[0](%x)!= payload[length-4](%x)\n",
- crc[3], payload[length-1],
- crc[2], payload[length-2],
- crc[1], payload[length-3],
- crc[0], payload[length-4]);
+ crc[3], payload[length - 1],
+ crc[2], payload[length - 2],
+ crc[1], payload[length - 3],
+ crc[0], payload[length - 4]);
res = _FAIL;
}
} else {
{
int i;
- for (i = 0;i<16; i++)
+ for (i = 0; i < 16; i++)
out[i] = a[i] ^ b[i];
}
{
int i;
- for (i = 0; i< 16; i++) {
+ for (i = 0; i < 16; i++) {
out[i] = sbox(in[i]);
}
u8 temp[4];
u8 tempb[4];
- for (i = 0 ; i<4; i++) {
+ for (i = 0; i < 4; i++) {
if ((in[i] & 0x80) == 0x80)
add1b[i] = 0x1b;
else
andf7[2] = in[2] & 0x7f;
andf7[3] = in[3] & 0x7f;
- for (i = 3; i>0; i--) { /* logical shift left 1 bit */
+ for (i = 3; i > 0; i--) { /* logical shift left 1 bit */
andf7[i] = andf7[i] << 1;
- if ((andf7[i-1] & 0x80) == 0x80) {
- andf7[i] = (andf7[i] | 0x01);
+ if ((andf7[i - 1] & 0x80) == 0x80) {
+ andf7[i] = (andf7[i] | 0x01);
}
}
andf7[0] = andf7[0] << 1;
u8 intermediateb[16];
u8 round_key[16];
- for (i = 0; i<16; i++) round_key[i] = key[i];
+ for (i = 0; i < 16; i++) round_key[i] = key[i];
for (round = 0; round < 11; round++) {
if (round == 0) {
{
int i;
- for (i = 0; i<16; i++) mic_header2[i]= 0x00;
+ for (i = 0; i < 16; i++) mic_header2[i] = 0x00;
mic_header2[0] = mpdu[16]; /* A3 */
mic_header2[1] = mpdu[17];
mic_header2[7] = 0x00; /* mpdu[23]; */
if (!qc_exists && a4_exists) {
- for (i = 0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
-
+ for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
}
if (qc_exists && !a4_exists) {
}
if (qc_exists && a4_exists) {
- for (i = 0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
+ for (i = 0; i < 6; i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
mic_header2[14] = mpdu[30] & 0x0f;
mic_header2[15] = mpdu[31] & 0x00;
{
int i = 0;
- for (i = 0; i<16; i++) ctr_preload[i] = 0x00;
+ for (i = 0; i < 16; i++) ctr_preload[i] = 0x00;
i = 0;
ctr_preload[0] = 0x01; /* flag */
} else {
qc_exists = 0;
}
- pn_vector[0]= pframe[hdrlen];
- pn_vector[1]= pframe[hdrlen+1];
- pn_vector[2]= pframe[hdrlen+4];
- pn_vector[3]= pframe[hdrlen+5];
- pn_vector[4]= pframe[hdrlen+6];
- pn_vector[5]= pframe[hdrlen+7];
+ pn_vector[0] = pframe[hdrlen];
+ pn_vector[1] = pframe[hdrlen + 1];
+ pn_vector[2] = pframe[hdrlen + 4];
+ pn_vector[3] = pframe[hdrlen + 5];
+ pn_vector[4] = pframe[hdrlen + 6];
+ pn_vector[5] = pframe[hdrlen + 7];
construct_mic_iv(mic_iv, qc_exists, a4_exists, pframe, plen, pn_vector);
/* Insert MIC into payload */
for (j = 0; j < 8; j++)
- pframe[payload_index+j] = mic[j];
+ pframe[payload_index + j] = mic[j];
payload_index = hdrlen + 8;
for (i = 0; i < num_blocks; i++) {
construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
- pframe, pn_vector, i+1);
+ pframe, pn_vector, i + 1);
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, &pframe[payload_index], chain_buffer);
for (j = 0; j < 16; j++)
* encrypt it and copy the unpadded part back
*/
construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe,
- pn_vector, num_blocks+1);
+ pn_vector, num_blocks + 1);
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < payload_remainder; j++)
- padded_buffer[j] = pframe[payload_index+j];
+ padded_buffer[j] = pframe[payload_index + j];
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, padded_buffer, chain_buffer);
- for (j = 0; j < payload_remainder;j++)
+ for (j = 0; j < payload_remainder; j++)
pframe[payload_index++] = chain_buffer[j];
}
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < 8; j++)
- padded_buffer[j] = pframe[j+hdrlen+8+plen];
+ padded_buffer[j] = pframe[j + hdrlen + 8 + plen];
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, padded_buffer, chain_buffer);
- for (j = 0; j < 8;j++)
+ for (j = 0; j < 8; j++)
pframe[payload_index++] = chain_buffer[j];
return _SUCCESS;
res = _FAIL;
goto out;
}
- if (!(stainfo->state &_FW_LINKED)) {
+ if (!(stainfo->state & _FW_LINKED)) {
DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n",
__func__, stainfo->state);
return _FAIL;
/* start to decrypt the payload */
- num_blocks = (plen-8) / 16; /* plen including llc, payload_length and mic) */
+ num_blocks = (plen - 8) / 16; /* plen including llc, payload_length and mic) */
- payload_remainder = (plen-8) % 16;
+ payload_remainder = (plen - 8) % 16;
pn_vector[0] = pframe[hdrlen];
- pn_vector[1] = pframe[hdrlen+1];
- pn_vector[2] = pframe[hdrlen+4];
- pn_vector[3] = pframe[hdrlen+5];
- pn_vector[4] = pframe[hdrlen+6];
- pn_vector[5] = pframe[hdrlen+7];
+ pn_vector[1] = pframe[hdrlen + 1];
+ pn_vector[2] = pframe[hdrlen + 4];
+ pn_vector[3] = pframe[hdrlen + 5];
+ pn_vector[4] = pframe[hdrlen + 6];
+ pn_vector[5] = pframe[hdrlen + 7];
if ((hdrlen == sizeof(struct ieee80211_hdr_3addr) ||
(hdrlen == sizeof(struct ieee80211_qos_hdr))))
for (i = 0; i < num_blocks; i++) {
construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
- pframe, pn_vector, i+1);
+ pframe, pn_vector, i + 1);
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, &pframe[payload_index], chain_buffer);
* encrypt it and copy the unpadded part back
*/
construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe,
- pn_vector, num_blocks+1);
+ pn_vector, num_blocks + 1);
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < payload_remainder; j++)
- padded_buffer[j] = pframe[payload_index+j];
+ padded_buffer[j] = pframe[payload_index + j];
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, padded_buffer, chain_buffer);
for (j = 0; j < payload_remainder; j++)
}
/* start to calculate the mic */
- if ((hdrlen +plen+8) <= MAX_MSG_SIZE)
- memcpy(message, pframe, (hdrlen+plen+8)); /* 8 is for ext iv len */
+ if ((hdrlen + plen + 8) <= MAX_MSG_SIZE)
+ memcpy(message, pframe, (hdrlen + plen + 8)); /* 8 is for ext iv len */
pn_vector[0] = pframe[hdrlen];
- pn_vector[1] = pframe[hdrlen+1];
- pn_vector[2] = pframe[hdrlen+4];
- pn_vector[3] = pframe[hdrlen+5];
- pn_vector[4] = pframe[hdrlen+6];
- pn_vector[5] = pframe[hdrlen+7];
+ pn_vector[1] = pframe[hdrlen + 1];
+ pn_vector[2] = pframe[hdrlen + 4];
+ pn_vector[3] = pframe[hdrlen + 5];
+ pn_vector[4] = pframe[hdrlen + 6];
+ pn_vector[5] = pframe[hdrlen + 7];
construct_mic_iv(mic_iv, qc_exists, a4_exists, message,
- plen-8, pn_vector);
+ plen - 8, pn_vector);
construct_mic_header1(mic_header1, hdrlen, message);
construct_mic_header2(mic_header2, message, a4_exists, qc_exists);
- payload_remainder = (plen-8) % 16;
- num_blocks = (plen-8) / 16;
+ payload_remainder = (plen - 8) % 16;
+ num_blocks = (plen - 8) / 16;
/* Find start of payload */
payload_index = hdrlen + 8;
/* Insert MIC into payload */
for (j = 0; j < 8; j++)
- message[payload_index+j] = mic[j];
+ message[payload_index + j] = mic[j];
payload_index = hdrlen + 8;
- for (i = 0; i< num_blocks; i++) {
+ for (i = 0; i < num_blocks; i++) {
construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
- message, pn_vector, i+1);
+ message, pn_vector, i + 1);
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, &message[payload_index], chain_buffer);
for (j = 0; j < 16; j++)
* encrypt it and copy the unpadded part back
*/
construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
- message, pn_vector, num_blocks+1);
+ message, pn_vector, num_blocks + 1);
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < payload_remainder; j++)
- padded_buffer[j] = message[payload_index+j];
+ padded_buffer[j] = message[payload_index + j];
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, padded_buffer, chain_buffer);
for (j = 0; j < payload_remainder; j++)
for (j = 0; j < 16; j++)
padded_buffer[j] = 0x00;
for (j = 0; j < 8; j++)
- padded_buffer[j] = message[j+hdrlen+8+plen-8];
+ padded_buffer[j] = message[j + hdrlen + 8 + plen - 8];
aes128k128d(key, ctr_preload, aes_out);
bitwise_xor(aes_out, padded_buffer, chain_buffer);
/* compare the mic */
for (i = 0; i < 8; i++) {
- if (pframe[hdrlen+8+plen-8+i] != message[hdrlen+8+plen-8+i]) {
+ if (pframe[hdrlen + 8 + plen - 8 + i] != message[hdrlen + 8 + plen - 8 + i]) {
RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
"aes_decipher:mic check error mic[%d]: pframe(%x) != message(%x)\n",
i, pframe[hdrlen + 8 + plen - 8 + i],
message[hdrlen + 8 + plen - 8 + i]);
DBG_8723A("aes_decipher:mic check error mic[%d]: pframe(%x) != message(%x)\n",
- i, pframe[hdrlen+8+plen-8+i], message[hdrlen+8+plen-8+i]);
+ i, pframe[hdrlen + 8 + plen - 8 + i], message[hdrlen + 8 + plen - 8 + i]);
res = _FAIL;
}
}