mirror of https://gitee.com/openkylin/linux.git
orinoco: Move MIC helpers into new file
No functional change. Signed-off-by: David Kilroy <kilroyd@googlemail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
This commit is contained in:
parent
fb791b1cfb
commit
4adb474b6b
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# Makefile for the orinoco wireless device drivers.
|
||||
#
|
||||
orinoco-objs := main.o scan.o
|
||||
orinoco-objs := main.o mic.o scan.o
|
||||
|
||||
obj-$(CONFIG_HERMES) += orinoco.o hermes.o hermes_dld.o
|
||||
obj-$(CONFIG_PCMCIA_HERMES) += orinoco_cs.o
|
||||
|
|
|
@ -90,12 +90,10 @@
|
|||
#include <linux/ieee80211.h>
|
||||
#include <net/iw_handler.h>
|
||||
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/crypto.h>
|
||||
|
||||
#include "hermes_rid.h"
|
||||
#include "hermes_dld.h"
|
||||
#include "scan.h"
|
||||
#include "mic.h"
|
||||
|
||||
#include "orinoco.h"
|
||||
|
||||
|
@ -254,74 +252,6 @@ struct orinoco_rx_data {
|
|||
static int __orinoco_program_rids(struct net_device *dev);
|
||||
static void __orinoco_set_multicast_list(struct net_device *dev);
|
||||
|
||||
/********************************************************************/
|
||||
/* Michael MIC crypto setup */
|
||||
/********************************************************************/
|
||||
#define MICHAEL_MIC_LEN 8
|
||||
static int orinoco_mic_init(struct orinoco_private *priv)
|
||||
{
|
||||
priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
|
||||
if (IS_ERR(priv->tx_tfm_mic)) {
|
||||
printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
|
||||
"crypto API michael_mic\n");
|
||||
priv->tx_tfm_mic = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
|
||||
if (IS_ERR(priv->rx_tfm_mic)) {
|
||||
printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
|
||||
"crypto API michael_mic\n");
|
||||
priv->rx_tfm_mic = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void orinoco_mic_free(struct orinoco_private *priv)
|
||||
{
|
||||
if (priv->tx_tfm_mic)
|
||||
crypto_free_hash(priv->tx_tfm_mic);
|
||||
if (priv->rx_tfm_mic)
|
||||
crypto_free_hash(priv->rx_tfm_mic);
|
||||
}
|
||||
|
||||
static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
|
||||
u8 *da, u8 *sa, u8 priority,
|
||||
u8 *data, size_t data_len, u8 *mic)
|
||||
{
|
||||
struct hash_desc desc;
|
||||
struct scatterlist sg[2];
|
||||
u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
|
||||
|
||||
if (tfm_michael == NULL) {
|
||||
printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Copy header into buffer. We need the padding on the end zeroed */
|
||||
memcpy(&hdr[0], da, ETH_ALEN);
|
||||
memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
|
||||
hdr[ETH_ALEN*2] = priority;
|
||||
hdr[ETH_ALEN*2+1] = 0;
|
||||
hdr[ETH_ALEN*2+2] = 0;
|
||||
hdr[ETH_ALEN*2+3] = 0;
|
||||
|
||||
/* Use scatter gather to MIC header and data in one go */
|
||||
sg_init_table(sg, 2);
|
||||
sg_set_buf(&sg[0], hdr, sizeof(hdr));
|
||||
sg_set_buf(&sg[1], data, data_len);
|
||||
|
||||
if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
|
||||
return -1;
|
||||
|
||||
desc.tfm = tfm_michael;
|
||||
desc.flags = 0;
|
||||
return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
|
||||
mic);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/* Internal helper functions */
|
||||
/********************************************************************/
|
||||
|
@ -1001,7 +931,7 @@ static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
|
|||
len = MICHAEL_MIC_LEN;
|
||||
}
|
||||
|
||||
michael_mic(priv->tx_tfm_mic,
|
||||
orinoco_mic(priv->tx_tfm_mic,
|
||||
priv->tkip_key[priv->tx_key].tx_mic,
|
||||
eh->h_dest, eh->h_source, 0 /* priority */,
|
||||
skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
|
||||
|
@ -1479,7 +1409,7 @@ static void orinoco_rx(struct net_device *dev,
|
|||
skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
|
||||
length -= MICHAEL_MIC_LEN;
|
||||
|
||||
michael_mic(priv->rx_tfm_mic,
|
||||
orinoco_mic(priv->rx_tfm_mic,
|
||||
priv->tkip_key[key_id].rx_mic,
|
||||
desc->addr1,
|
||||
src,
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/* Orinoco MIC helpers
|
||||
*
|
||||
* See copyright notice in main.c
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/crypto.h>
|
||||
|
||||
#include "orinoco.h"
|
||||
#include "mic.h"
|
||||
|
||||
/********************************************************************/
|
||||
/* Michael MIC crypto setup */
|
||||
/********************************************************************/
|
||||
int orinoco_mic_init(struct orinoco_private *priv)
|
||||
{
|
||||
priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
|
||||
if (IS_ERR(priv->tx_tfm_mic)) {
|
||||
printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
|
||||
"crypto API michael_mic\n");
|
||||
priv->tx_tfm_mic = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
|
||||
if (IS_ERR(priv->rx_tfm_mic)) {
|
||||
printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
|
||||
"crypto API michael_mic\n");
|
||||
priv->rx_tfm_mic = NULL;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void orinoco_mic_free(struct orinoco_private *priv)
|
||||
{
|
||||
if (priv->tx_tfm_mic)
|
||||
crypto_free_hash(priv->tx_tfm_mic);
|
||||
if (priv->rx_tfm_mic)
|
||||
crypto_free_hash(priv->rx_tfm_mic);
|
||||
}
|
||||
|
||||
int orinoco_mic(struct crypto_hash *tfm_michael, u8 *key,
|
||||
u8 *da, u8 *sa, u8 priority,
|
||||
u8 *data, size_t data_len, u8 *mic)
|
||||
{
|
||||
struct hash_desc desc;
|
||||
struct scatterlist sg[2];
|
||||
u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
|
||||
|
||||
if (tfm_michael == NULL) {
|
||||
printk(KERN_WARNING "orinoco_mic: tfm_michael == NULL\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Copy header into buffer. We need the padding on the end zeroed */
|
||||
memcpy(&hdr[0], da, ETH_ALEN);
|
||||
memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
|
||||
hdr[ETH_ALEN*2] = priority;
|
||||
hdr[ETH_ALEN*2+1] = 0;
|
||||
hdr[ETH_ALEN*2+2] = 0;
|
||||
hdr[ETH_ALEN*2+3] = 0;
|
||||
|
||||
/* Use scatter gather to MIC header and data in one go */
|
||||
sg_init_table(sg, 2);
|
||||
sg_set_buf(&sg[0], hdr, sizeof(hdr));
|
||||
sg_set_buf(&sg[1], data, data_len);
|
||||
|
||||
if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
|
||||
return -1;
|
||||
|
||||
desc.tfm = tfm_michael;
|
||||
desc.flags = 0;
|
||||
return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
|
||||
mic);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/* Orinoco MIC helpers
|
||||
*
|
||||
* See copyright notice in main.c
|
||||
*/
|
||||
#ifndef _ORINOCO_MIC_H_
|
||||
#define _ORINOCO_MIC_H_
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define MICHAEL_MIC_LEN 8
|
||||
|
||||
/* Forward declarations */
|
||||
struct orinoco_private;
|
||||
struct crypto_hash;
|
||||
|
||||
int orinoco_mic_init(struct orinoco_private *priv);
|
||||
void orinoco_mic_free(struct orinoco_private *priv);
|
||||
int orinoco_mic(struct crypto_hash *tfm_michael, u8 *key,
|
||||
u8 *da, u8 *sa, u8 priority,
|
||||
u8 *data, size_t data_len, u8 *mic);
|
||||
|
||||
#endif /* ORINOCO_MIC_H */
|
Loading…
Reference in New Issue