Re: [PATCH] staging:r8188eu: use lib80211 CCMP decrypt
Hm... Sorry. I was looking at the wrong code. I was looking at aes_decipher() instead of rtw_aes_decrypt(). The aes_decipher() was acceptable style (although, it's of course good that you deleted it). rtw_aes_decrypt() was always really really awful. That's fine then. Sorry again. regards, dan carpenter
Re: [PATCH] staging:r8188eu: use lib80211 CCMP decrypt
Hm... Sorry. I was looking at the wrong code. I was looking at aes_decipher() instead of rtw_aes_decrypt(). The aes_decipher() was acceptable style (although, it's of course good that you deleted it). rtw_aes_decrypt() was always really really awful. That's fine then. Sorry again. regards, dan carpenter
Re: [PATCH] staging:r8188eu: use lib80211 CCMP decrypt
On 02/26/2018 10:56 AM, Dan Carpenter wrote: On Fri, Feb 23, 2018 at 05:57:42PM +0300, Ivan Safonov wrote: Custom AES decrypt implementation replaced with lib80211 library. Signed-off-by: Ivan SafonovThe new code looks like original RTL code (really bad) so I'm guessing you copy and pasted the code from somewhere else? Unfortunately, your assumption is wrong. Rather, bad code is created because I'm not a good programmer =). Seriously, after each patch the driver gets better, does not it? The idea is good, but RTL code is painful to look at. The basic idea is to replace a _small_ (or trivial) parts of the program, because I can not test my patches. regards, dan carpenter Ivan Safonov.
Re: [PATCH] staging:r8188eu: use lib80211 CCMP decrypt
On 02/26/2018 10:56 AM, Dan Carpenter wrote: On Fri, Feb 23, 2018 at 05:57:42PM +0300, Ivan Safonov wrote: Custom AES decrypt implementation replaced with lib80211 library. Signed-off-by: Ivan Safonov The new code looks like original RTL code (really bad) so I'm guessing you copy and pasted the code from somewhere else? Unfortunately, your assumption is wrong. Rather, bad code is created because I'm not a good programmer =). Seriously, after each patch the driver gets better, does not it? The idea is good, but RTL code is painful to look at. The basic idea is to replace a _small_ (or trivial) parts of the program, because I can not test my patches. regards, dan carpenter Ivan Safonov.
Re: [PATCH] staging:r8188eu: use lib80211 CCMP decrypt
On Fri, Feb 23, 2018 at 05:57:42PM +0300, Ivan Safonov wrote: > Custom AES decrypt implementation replaced with lib80211 library. > > Signed-off-by: Ivan SafonovThe new code looks like original RTL code (really bad) so I'm guessing you copy and pasted the code from somewhere else? The idea is good, but RTL code is painful to look at. regards, dan carpenter
Re: [PATCH] staging:r8188eu: use lib80211 CCMP decrypt
On Fri, Feb 23, 2018 at 05:57:42PM +0300, Ivan Safonov wrote: > Custom AES decrypt implementation replaced with lib80211 library. > > Signed-off-by: Ivan Safonov The new code looks like original RTL code (really bad) so I'm guessing you copy and pasted the code from somewhere else? The idea is good, but RTL code is painful to look at. regards, dan carpenter
[PATCH] staging:r8188eu: use lib80211 CCMP decrypt
Custom AES decrypt implementation replaced with lib80211 library. Signed-off-by: Ivan Safonov--- drivers/staging/rtl8188eu/Kconfig | 1 + drivers/staging/rtl8188eu/core/rtw_security.c | 266 +- 2 files changed, 51 insertions(+), 216 deletions(-) diff --git a/drivers/staging/rtl8188eu/Kconfig b/drivers/staging/rtl8188eu/Kconfig index d787a091d3c1..ff7832798a77 100644 --- a/drivers/staging/rtl8188eu/Kconfig +++ b/drivers/staging/rtl8188eu/Kconfig @@ -6,6 +6,7 @@ config R8188EU select WEXT_PRIV select LIB80211 select LIB80211_CRYPT_WEP + select LIB80211_CRYPT_CCMP ---help--- This option adds the Realtek RTL8188EU USB device such as TP-Link TL-WN725N. If built as a module, it will be called r8188eu. diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index 72da86fdd264..68e2c6790ee6 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -1275,217 +1275,24 @@ u32rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe) return res; } -static int aes_decipher(u8 *key, uint hdrlen, - u8 *pframe, uint plen) +u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe) { - static u8 message[MAX_MSG_SIZE]; - uintqc_exists, a4_exists, i, j, payload_remainder, - num_blocks, payload_index; - int res = _SUCCESS; - - u8 pn_vector[6]; - u8 mic_iv[16]; - u8 mic_header1[16]; - u8 mic_header2[16]; - u8 ctr_preload[16]; - - /* Intermediate Buffers */ - u8 chain_buffer[16]; - u8 aes_out[16]; - u8 padded_buffer[16]; - u8 mic[8]; - -/* uintoffset = 0; */ - uintfrtype = GetFrameType(pframe); - uintfrsubtype = GetFrameSubType(pframe); - frsubtype >>= 4; - - memset(mic_iv, 0, 16); - memset(mic_header1, 0, 16); - memset(mic_header2, 0, 16); - memset(ctr_preload, 0, 16); - memset(chain_buffer, 0, 16); - memset(aes_out, 0, 16); - memset(padded_buffer, 0, 16); - - /* start to decrypt the payload */ - - num_blocks = (plen-8) / 16; /* plen including llc, payload_length and mic) */ - - 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]; - - if ((hdrlen == WLAN_HDR_A3_LEN) || (hdrlen == WLAN_HDR_A3_QOS_LEN)) - a4_exists = 0; - else - a4_exists = 1; - - if ((frtype == WIFI_DATA_CFACK) || (frtype == WIFI_DATA_CFPOLL) || - (frtype == WIFI_DATA_CFACKPOLL)) { - qc_exists = 1; - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - } else if ((frsubtype == 0x08) || (frsubtype == 0x09) || - (frsubtype == 0x0a) || (frsubtype == 0x0b)) { - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - qc_exists = 1; - } else { - qc_exists = 0; - } - - /* now, decrypt pframe with hdrlen offset and plen long */ - - payload_index = hdrlen + 8; /* 8 is for extiv */ - - for (i = 0; i < num_blocks; i++) { - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, pn_vector, i+1); - - aes128k128d(key, ctr_preload, aes_out); - bitwise_xor(aes_out, [payload_index], chain_buffer); - - for (j = 0; j < 16; j++) - pframe[payload_index++] = chain_buffer[j]; - } - - if (payload_remainder > 0) {/* If there is a short final block, then pad it,*/ - /* encrypt it and copy the unpadded part back */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, 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]; - aes128k128d(key, ctr_preload, aes_out); - bitwise_xor(aes_out, padded_buffer, chain_buffer); - for (j = 0; j < payload_remainder; j++) - pframe[payload_index++] = chain_buffer[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 */ - - pn_vector[0] = pframe[hdrlen]; - pn_vector[1] = pframe[hdrlen+1]; - pn_vector[2] = pframe[hdrlen+4]; - pn_vector[3]
[PATCH] staging:r8188eu: use lib80211 CCMP decrypt
Custom AES decrypt implementation replaced with lib80211 library. Signed-off-by: Ivan Safonov --- drivers/staging/rtl8188eu/Kconfig | 1 + drivers/staging/rtl8188eu/core/rtw_security.c | 266 +- 2 files changed, 51 insertions(+), 216 deletions(-) diff --git a/drivers/staging/rtl8188eu/Kconfig b/drivers/staging/rtl8188eu/Kconfig index d787a091d3c1..ff7832798a77 100644 --- a/drivers/staging/rtl8188eu/Kconfig +++ b/drivers/staging/rtl8188eu/Kconfig @@ -6,6 +6,7 @@ config R8188EU select WEXT_PRIV select LIB80211 select LIB80211_CRYPT_WEP + select LIB80211_CRYPT_CCMP ---help--- This option adds the Realtek RTL8188EU USB device such as TP-Link TL-WN725N. If built as a module, it will be called r8188eu. diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c index 72da86fdd264..68e2c6790ee6 100644 --- a/drivers/staging/rtl8188eu/core/rtw_security.c +++ b/drivers/staging/rtl8188eu/core/rtw_security.c @@ -1275,217 +1275,24 @@ u32rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe) return res; } -static int aes_decipher(u8 *key, uint hdrlen, - u8 *pframe, uint plen) +u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe) { - static u8 message[MAX_MSG_SIZE]; - uintqc_exists, a4_exists, i, j, payload_remainder, - num_blocks, payload_index; - int res = _SUCCESS; - - u8 pn_vector[6]; - u8 mic_iv[16]; - u8 mic_header1[16]; - u8 mic_header2[16]; - u8 ctr_preload[16]; - - /* Intermediate Buffers */ - u8 chain_buffer[16]; - u8 aes_out[16]; - u8 padded_buffer[16]; - u8 mic[8]; - -/* uintoffset = 0; */ - uintfrtype = GetFrameType(pframe); - uintfrsubtype = GetFrameSubType(pframe); - frsubtype >>= 4; - - memset(mic_iv, 0, 16); - memset(mic_header1, 0, 16); - memset(mic_header2, 0, 16); - memset(ctr_preload, 0, 16); - memset(chain_buffer, 0, 16); - memset(aes_out, 0, 16); - memset(padded_buffer, 0, 16); - - /* start to decrypt the payload */ - - num_blocks = (plen-8) / 16; /* plen including llc, payload_length and mic) */ - - 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]; - - if ((hdrlen == WLAN_HDR_A3_LEN) || (hdrlen == WLAN_HDR_A3_QOS_LEN)) - a4_exists = 0; - else - a4_exists = 1; - - if ((frtype == WIFI_DATA_CFACK) || (frtype == WIFI_DATA_CFPOLL) || - (frtype == WIFI_DATA_CFACKPOLL)) { - qc_exists = 1; - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - } else if ((frsubtype == 0x08) || (frsubtype == 0x09) || - (frsubtype == 0x0a) || (frsubtype == 0x0b)) { - if (hdrlen != WLAN_HDR_A3_QOS_LEN) - hdrlen += 2; - qc_exists = 1; - } else { - qc_exists = 0; - } - - /* now, decrypt pframe with hdrlen offset and plen long */ - - payload_index = hdrlen + 8; /* 8 is for extiv */ - - for (i = 0; i < num_blocks; i++) { - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, pn_vector, i+1); - - aes128k128d(key, ctr_preload, aes_out); - bitwise_xor(aes_out, [payload_index], chain_buffer); - - for (j = 0; j < 16; j++) - pframe[payload_index++] = chain_buffer[j]; - } - - if (payload_remainder > 0) {/* If there is a short final block, then pad it,*/ - /* encrypt it and copy the unpadded part back */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pframe, 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]; - aes128k128d(key, ctr_preload, aes_out); - bitwise_xor(aes_out, padded_buffer, chain_buffer); - for (j = 0; j < payload_remainder; j++) - pframe[payload_index++] = chain_buffer[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 */ - - pn_vector[0] = pframe[hdrlen]; - pn_vector[1] = pframe[hdrlen+1]; - pn_vector[2] = pframe[hdrlen+4]; - pn_vector[3] = pframe[hdrlen+5];