Skip to content

Commit

Permalink
Merge branch 'v5.3.9' of https://github.com/OpenHD/rtl8188eus into Op…
Browse files Browse the repository at this point in the history
…enHD-v5.3.9
  • Loading branch information
kimocoder committed May 4, 2021
2 parents 9679ca4 + baaa092 commit cc5f31b
Show file tree
Hide file tree
Showing 9 changed files with 13,737 additions and 94 deletions.
12 changes: 5 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ CONFIG_PLATFORM_PPC64LE = n

CONFIG_DRVEXT_MODULE = n

export TopDIR ?= $(shell pwd)

########### COMMON #################################
ifeq ($(CONFIG_GSPI_HCI), y)
HCI_NAME = gspi
Expand Down Expand Up @@ -780,16 +778,16 @@ endif
ifeq ($(CONFIG_AUTOCFG_CP), y)

ifeq ($(CONFIG_MULTIDRV), y)
$(shell cp $(TopDIR)/autoconf_multidrv_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h)
$(shell cp autoconf_multidrv_$(HCI_NAME)_linux.h include/autoconf.h)
else
ifeq ($(CONFIG_RTL8188E)$(CONFIG_SDIO_HCI),yy)
$(shell cp $(TopDIR)/autoconf_rtl8189e_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h)
$(shell cp autoconf_rtl8189e_$(HCI_NAME)_linux.h include/autoconf.h)
else ifeq ($(CONFIG_RTL8188F)$(CONFIG_SDIO_HCI),yy)
$(shell cp $(TopDIR)/autoconf_rtl8189f_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h)
$(shell cp autoconf_rtl8189f_$(HCI_NAME)_linux.h include/autoconf.h)
else ifeq ($(CONFIG_RTL8723C),y)
$(shell cp $(TopDIR)/autoconf_rtl8723c_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h)
$(shell cp autoconf_rtl8723c_$(HCI_NAME)_linux.h include/autoconf.h)
else
$(shell cp $(TopDIR)/autoconf_$(RTL871X)_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h)
$(shell cp autoconf_$(RTL871X)_$(HCI_NAME)_linux.h include/autoconf.h)
endif
endif

Expand Down
59 changes: 22 additions & 37 deletions core/rtw_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -2133,8 +2133,7 @@ u32 rtw_BIP_verify(_adapter *padapter, u8 *whdr_pos, sint flen
#ifndef PLATFORM_FREEBSD
#if defined(CONFIG_TDLS)
/* compress 512-bits */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static int sha256_compress(struct sha256_state *md, unsigned char *buf)
static int rtw_sha256_compress(struct rtw_sha256_state *md, unsigned char *buf)
{
u32 S[8], W[64], t0, t1;
u32 t;
Expand Down Expand Up @@ -2180,11 +2179,9 @@ static int sha256_compress(struct sha256_state *md, unsigned char *buf)
md->state[i] = md->state[i] + S[i];
return 0;
}
#endif

/* Initialize the hash state */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static void sha256_init(struct sha256_state *md)
static void rtw_sha256_init(struct rtw_sha256_state *md)
{
md->curlen = 0;
md->length = 0;
Expand All @@ -2197,7 +2194,6 @@ static void sha256_init(struct sha256_state *md)
md->state[6] = 0x1F83D9ABUL;
md->state[7] = 0x5BE0CD19UL;
}
#endif

/**
Process a block of memory though the hash
Expand All @@ -2206,9 +2202,7 @@ static void sha256_init(struct sha256_state *md)
@param inlen The length of the data (octets)
@return CRYPT_OK if successful
*/

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static int sha256_process(struct sha256_state *md, unsigned char *in,
static int rtw_sha256_process(struct rtw_sha256_state *md, unsigned char *in,
unsigned long inlen)
{
unsigned long n;
Expand All @@ -2219,7 +2213,7 @@ static int sha256_process(struct sha256_state *md, unsigned char *in,

while (inlen > 0) {
if (md->curlen == 0 && inlen >= block_size) {
if (sha256_compress(md, (unsigned char *) in) < 0)
if (rtw_sha256_compress(md, (unsigned char *) in) < 0)
return -1;
md->length += block_size * 8;
in += block_size;
Expand All @@ -2231,7 +2225,7 @@ static int sha256_process(struct sha256_state *md, unsigned char *in,
in += n;
inlen -= n;
if (md->curlen == block_size) {
if (sha256_compress(md, md->buf) < 0)
if (rtw_sha256_compress(md, md->buf) < 0)
return -1;
md->length += 8 * block_size;
md->curlen = 0;
Expand All @@ -2241,16 +2235,15 @@ static int sha256_process(struct sha256_state *md, unsigned char *in,

return 0;
}
#endif


/**
Terminate the hash to get the digest
@param md The hash state
@param out [out] The destination of the hash (32 bytes)
@return CRYPT_OK if successful
*/
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static int sha256_done(struct sha256_state *md, unsigned char *out)
static int rtw_sha256_done(struct rtw_sha256_state *md, unsigned char *out)
{
int i;

Expand All @@ -2270,7 +2263,7 @@ static int sha256_done(struct sha256_state *md, unsigned char *out)
if (md->curlen > 56) {
while (md->curlen < 64)
md->buf[md->curlen++] = (unsigned char) 0;
sha256_compress(md, md->buf);
rtw_sha256_compress(md, md->buf);
md->curlen = 0;
}

Expand All @@ -2280,15 +2273,14 @@ static int sha256_done(struct sha256_state *md, unsigned char *out)

/* store length */
WPA_PUT_BE64(md->buf + 56, md->length);
sha256_compress(md, md->buf);
rtw_sha256_compress(md, md->buf);

/* copy output */
for (i = 0; i < 8; i++)
WPA_PUT_BE32(out + (4 * i), md->state[i]);

return 0;
}
#endif

/**
* sha256_vector - SHA256 hash for data vector
Expand All @@ -2298,23 +2290,20 @@ static int sha256_done(struct sha256_state *md, unsigned char *out)
* @mac: Buffer for the hash
* Returns: 0 on success, -1 of failure
*/

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static int sha256_vector(size_t num_elem, u8 *addr[], size_t *len,
static int rtw_sha256_vector(size_t num_elem, u8 *addr[], size_t *len,
u8 *mac)
{
struct sha256_state ctx;
struct rtw_sha256_state ctx;
size_t i;

sha256_init(&ctx);
rtw_sha256_init(&ctx);
for (i = 0; i < num_elem; i++)
if (sha256_process(&ctx, addr[i], len[i]))
if (rtw_sha256_process(&ctx, addr[i], len[i]))
return -1;
if (sha256_done(&ctx, mac))
if (rtw_sha256_done(&ctx, mac))
return -1;
return 0;
}
#endif

static u8 os_strlen(const char *s)
{
Expand Down Expand Up @@ -2355,7 +2344,6 @@ static int os_memcmp(const void *s1, const void *s2, u8 n)
* @mac: Buffer for the hash (32 bytes)
*/
#if defined(CONFIG_TDLS)
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static void hmac_sha256_vector(u8 *key, size_t key_len, size_t num_elem,
u8 *addr[], size_t *len, u8 *mac)
{
Expand All @@ -2374,7 +2362,7 @@ static void hmac_sha256_vector(u8 *key, size_t key_len, size_t num_elem,

/* if key is longer than 64 bytes reset it to key = SHA256(key) */
if (key_len > 64) {
sha256_vector(1, &key, &key_len, tk);
rtw_sha256_vector(1, &key, &key_len, tk);
key = tk;
key_len = 32;
}
Expand Down Expand Up @@ -2402,7 +2390,7 @@ static void hmac_sha256_vector(u8 *key, size_t key_len, size_t num_elem,
_addr[i + 1] = addr[i];
_len[i + 1] = len[i];
}
sha256_vector(1 + num_elem, _addr, _len, mac);
rtw_sha256_vector(1 + num_elem, _addr, _len, mac);

_rtw_memset(k_pad, 0, sizeof(k_pad));
_rtw_memcpy(k_pad, key, key_len);
Expand All @@ -2415,9 +2403,8 @@ static void hmac_sha256_vector(u8 *key, size_t key_len, size_t num_elem,
_len[0] = 64;
_addr[1] = mac;
_len[1] = 32;
sha256_vector(2, _addr, _len, mac);
rtw_sha256_vector(2, _addr, _len, mac);
}
#endif
#endif /* CONFIG_TDLS */
#endif /* PLATFORM_FREEBSD */
/**
Expand All @@ -2435,8 +2422,7 @@ static void hmac_sha256_vector(u8 *key, size_t key_len, size_t num_elem,
*/
#ifndef PLATFORM_FREEBSD /* Baron */
#if defined(CONFIG_TDLS)
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
static void sha256_prf(u8 *key, size_t key_len, char *label,
static void rtw_sha256_prf(u8 *key, size_t key_len, char *label,
u8 *data, size_t data_len, u8 *buf, size_t buf_len)
{
u16 counter = 1;
Expand All @@ -2460,10 +2446,10 @@ static void sha256_prf(u8 *key, size_t key_len, char *label,
while (pos < buf_len) {
plen = buf_len - pos;
WPA_PUT_LE16(counter_le, counter);
if (plen >= SHA256_MAC_LEN) {
if (plen >= RTW_SHA256_MAC_LEN) {
hmac_sha256_vector(key, key_len, 4, addr, len,
&buf[pos]);
pos += SHA256_MAC_LEN;
pos += RTW_SHA256_MAC_LEN;
} else {
hmac_sha256_vector(key, key_len, 4, addr, len, hash);
_rtw_memcpy(&buf[pos], hash, plen);
Expand All @@ -2473,7 +2459,6 @@ static void sha256_prf(u8 *key, size_t key_len, char *label,
}
}
#endif
#endif
#endif /* PLATFORM_FREEBSD Baron */

/* AES tables*/
Expand Down Expand Up @@ -3123,7 +3108,7 @@ void wpa_tdls_generate_tpk(_adapter *padapter, void *sta)
nonce[1] = SNonce;
}

sha256_vector(2, nonce, len, key_input);
rtw_sha256_vector(2, nonce, len, key_input);

/*
* TPK-Key-Data = KDF-N_KEY(TPK-Key-Input, "TDLS PMK",
Expand All @@ -3142,7 +3127,7 @@ void wpa_tdls_generate_tpk(_adapter *padapter, void *sta)
}
_rtw_memcpy(data + 2 * ETH_ALEN, get_bssid(pmlmepriv), ETH_ALEN);

sha256_prf(key_input, SHA256_MAC_LEN, "TDLS PMK", data, sizeof(data), (u8 *) &psta->tpk, sizeof(psta->tpk));
rtw_sha256_prf(key_input, RTW_SHA256_MAC_LEN, "TDLS PMK", data, sizeof(data), (u8 *) &psta->tpk, sizeof(psta->tpk));


}
Expand Down
6 changes: 2 additions & 4 deletions include/rtw_security.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const char *security_type_str(u8 value);
#define _WPA_IE_ID_ 0xdd
#define _WPA2_IE_ID_ 0x30

#define SHA256_MAC_LEN 32
#define RTW_SHA256_MAC_LEN 32
#define AES_BLOCK_SIZE 16
#define AES_PRIV_SIZE (4 * 44)

Expand Down Expand Up @@ -249,13 +249,11 @@ struct security_priv {
#define SEC_IS_BIP_KEY_INSTALLED(sec) _FALSE
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 8, 0))
struct sha256_state {
struct rtw_sha256_state {
u64 length;
u32 state[8], curlen;
u8 buf[64];
};
#endif

#define GET_ENCRY_ALGO(psecuritypriv, psta, encry_algo, bmcst)\
do {\
Expand Down
Loading

0 comments on commit cc5f31b

Please sign in to comment.