Skip to content

Commit

Permalink
staging: ks7010: removed custom Michael MIC implementation.
Browse files Browse the repository at this point in the history
Changed the driver to use the kernel's own implementation.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Jeremy Sowden authored and Greg Kroah-Hartman committed Feb 28, 2019
1 parent 050bd74 commit 8b523f2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 170 deletions.
2 changes: 1 addition & 1 deletion drivers/staging/ks7010/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
obj-$(CONFIG_KS7010) += ks7010.o

ks7010-y := michael_mic.o ks_hostif.o ks_wlan_net.o ks7010_sdio.o
ks7010-y := ks_hostif.o ks_wlan_net.o ks7010_sdio.o
2 changes: 0 additions & 2 deletions drivers/staging/ks7010/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Now the TODOs:
- fix the 'card removal' event when card is inserted when booting
- check what other upstream wireless mechanisms can be used instead of the
custom ones here
- replace custom Michael MIC implementation with the kernel
implementation. This task is only required for a *clean* WEXT interface.

Please send any patches to:
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Expand Down
111 changes: 92 additions & 19 deletions drivers/staging/ks7010/ks_hostif.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
* Copyright (C) 2009 Renesas Technology Corp.
*/

#include <crypto/hash.h>
#include <linux/circ_buf.h>
#include <linux/if_arp.h>
#include <net/iw_handler.h>
#include <uapi/linux/llc.h>
#include "eap_packet.h"
#include "ks_wlan.h"
#include "michael_mic.h"
#include "ks_hostif.h"

#define MICHAEL_MIC_KEY_LEN 8
#define MICHAEL_MIC_LEN 8

static inline void inc_smeqhead(struct ks_wlan_private *priv)
{
priv->sme_i.qhead = (priv->sme_i.qhead + 1) % SME_EVENT_BUFF_SIZE;
Expand Down Expand Up @@ -191,6 +194,68 @@ static u8 read_ie(unsigned char *bp, u8 max, u8 *body)
return size;
}

static int
michael_mic(u8 *key, u8 *data, unsigned int len, u8 priority, u8 *result)
{
u8 pad_data[4] = { priority, 0, 0, 0 };
struct crypto_shash *tfm = NULL;
struct shash_desc *desc = NULL;
int ret;

tfm = crypto_alloc_shash("michael_mic", 0, 0);
if (IS_ERR(tfm)) {
ret = PTR_ERR(tfm);
goto err;
}

ret = crypto_shash_setkey(tfm, key, MICHAEL_MIC_KEY_LEN);
if (ret < 0)
goto err_free_tfm;

desc = kmalloc(sizeof(*desc) + crypto_shash_descsize(tfm), GFP_KERNEL);
if (!desc) {
ret = -ENOMEM;
goto err_free_tfm;
}

desc->tfm = tfm;
desc->flags = 0;

ret = crypto_shash_init(desc);
if (ret < 0)
goto err_free_desc;

// Compute the MIC value
/*
* IEEE802.11i page 47
* Figure 43g TKIP MIC processing format
* +--+--+--------+--+----+--+--+--+--+--+--+--+--+
* |6 |6 |1 |3 |M |1 |1 |1 |1 |1 |1 |1 |1 | Octet
* +--+--+--------+--+----+--+--+--+--+--+--+--+--+
* |DA|SA|Priority|0 |Data|M0|M1|M2|M3|M4|M5|M6|M7|
* +--+--+--------+--+----+--+--+--+--+--+--+--+--+
*/

ret = crypto_shash_update(desc, data, 12);
if (ret < 0)
goto err_free_desc;

ret = crypto_shash_update(desc, pad_data, 4);
if (ret < 0)
goto err_free_desc;

ret = crypto_shash_finup(desc, data + 12, len - 12, result);

err_free_desc:
kzfree(desc);

err_free_tfm:
crypto_free_shash(tfm);

err:
return ret;
}

static
int get_ap_information(struct ks_wlan_private *priv, struct ap_info *ap_info,
struct local_ap *ap)
Expand Down Expand Up @@ -273,11 +338,11 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
{
struct ether_hdr *eth_hdr;
unsigned short eth_proto;
unsigned char recv_mic[8];
unsigned char recv_mic[MICHAEL_MIC_LEN];
char buf[128];
unsigned long now;
struct mic_failure *mic_failure;
struct michael_mic michael_mic;
u8 mic[MICHAEL_MIC_LEN];
union iwreq_data wrqu;
unsigned int key_index = auth_type - 1;
struct wpa_key *key = &priv->wpa.key[key_index];
Expand All @@ -300,14 +365,20 @@ int hostif_data_indication_wpa(struct ks_wlan_private *priv,
netdev_dbg(priv->net_dev, "TKIP: protocol=%04X: size=%u\n",
eth_proto, priv->rx_size);
/* MIC save */
memcpy(&recv_mic[0], (priv->rxp) + ((priv->rx_size) - 8), 8);
priv->rx_size = priv->rx_size - 8;
memcpy(&recv_mic[0],
(priv->rxp) + ((priv->rx_size) - sizeof(recv_mic)),
sizeof(recv_mic));
priv->rx_size = priv->rx_size - sizeof(recv_mic);
if (auth_type > 0 && auth_type < 4) { /* auth_type check */
michael_mic_function(&michael_mic, key->rx_mic_key,
priv->rxp, priv->rx_size,
0, michael_mic.result);
int ret;

ret = michael_mic(key->rx_mic_key,
priv->rxp, priv->rx_size,
0, mic);
if (ret < 0)
return ret;
}
if (memcmp(michael_mic.result, recv_mic, 8) != 0) {
if (memcmp(mic, recv_mic, sizeof(mic)) != 0) {
now = jiffies;
mic_failure = &priv->wpa.mic_failure;
/* MIC FAILURE */
Expand Down Expand Up @@ -1002,7 +1073,6 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
int result = 0;
unsigned short eth_proto;
struct ether_hdr *eth_hdr;
struct michael_mic michael_mic;
unsigned short keyinfo = 0;
struct ieee802_1x_hdr *aa1x_hdr;
struct wpa_eapol_key *eap_key;
Expand Down Expand Up @@ -1109,17 +1179,20 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
pp->auth_type = cpu_to_le16(TYPE_AUTH);
} else {
if (priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) {
michael_mic_function(&michael_mic,
priv->wpa.key[0].tx_mic_key,
&pp->data[0], skb_len,
0, michael_mic.result);
memcpy(p, michael_mic.result, 8);
length += 8;
skb_len += 8;
p += 8;
u8 mic[MICHAEL_MIC_LEN];

ret = michael_mic(priv->wpa.key[0].tx_mic_key,
&pp->data[0], skb_len,
0, mic);
if (ret < 0)
goto err_kfree;

memcpy(p, mic, sizeof(mic));
length += sizeof(mic);
skb_len += sizeof(mic);
p += sizeof(mic);
pp->auth_type =
cpu_to_le16(TYPE_DATA);

} else if (priv->wpa.pairwise_suite ==
IW_AUTH_CIPHER_CCMP) {
pp->auth_type =
Expand Down
127 changes: 0 additions & 127 deletions drivers/staging/ks7010/michael_mic.c

This file was deleted.

21 changes: 0 additions & 21 deletions drivers/staging/ks7010/michael_mic.h

This file was deleted.

0 comments on commit 8b523f2

Please sign in to comment.