2009-02-05 07:05:51 +08:00
|
|
|
/* 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>
|
2016-01-24 21:16:47 +08:00
|
|
|
#include <crypto/hash.h>
|
2009-02-05 07:05:51 +08:00
|
|
|
|
|
|
|
#include "orinoco.h"
|
|
|
|
#include "mic.h"
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Michael MIC crypto setup */
|
|
|
|
/********************************************************************/
|
|
|
|
int orinoco_mic_init(struct orinoco_private *priv)
|
|
|
|
{
|
2016-12-13 04:55:55 +08:00
|
|
|
priv->tx_tfm_mic = crypto_alloc_shash("michael_mic", 0,
|
2016-01-24 21:16:47 +08:00
|
|
|
CRYPTO_ALG_ASYNC);
|
2009-02-05 07:05:51 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-13 04:55:55 +08:00
|
|
|
priv->rx_tfm_mic = crypto_alloc_shash("michael_mic", 0,
|
2016-01-24 21:16:47 +08:00
|
|
|
CRYPTO_ALG_ASYNC);
|
2009-02-05 07:05:51 +08:00
|
|
|
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)
|
2016-12-13 04:55:55 +08:00
|
|
|
crypto_free_shash(priv->tx_tfm_mic);
|
2009-02-05 07:05:51 +08:00
|
|
|
if (priv->rx_tfm_mic)
|
2016-12-13 04:55:55 +08:00
|
|
|
crypto_free_shash(priv->rx_tfm_mic);
|
2009-02-05 07:05:51 +08:00
|
|
|
}
|
|
|
|
|
2016-12-13 04:55:55 +08:00
|
|
|
int orinoco_mic(struct crypto_shash *tfm_michael, u8 *key,
|
2009-02-05 07:05:51 +08:00
|
|
|
u8 *da, u8 *sa, u8 priority,
|
|
|
|
u8 *data, size_t data_len, u8 *mic)
|
|
|
|
{
|
2016-12-13 04:55:55 +08:00
|
|
|
SHASH_DESC_ON_STACK(desc, tfm_michael);
|
2009-02-05 07:05:51 +08:00
|
|
|
u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
|
2016-01-24 21:16:47 +08:00
|
|
|
int err;
|
2009-02-05 07:05:51 +08:00
|
|
|
|
|
|
|
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);
|
2011-07-13 23:19:57 +08:00
|
|
|
hdr[ETH_ALEN * 2] = priority;
|
|
|
|
hdr[ETH_ALEN * 2 + 1] = 0;
|
|
|
|
hdr[ETH_ALEN * 2 + 2] = 0;
|
|
|
|
hdr[ETH_ALEN * 2 + 3] = 0;
|
2009-02-05 07:05:51 +08:00
|
|
|
|
2016-12-13 04:55:55 +08:00
|
|
|
desc->tfm = tfm_michael;
|
|
|
|
desc->flags = 0;
|
2009-02-05 07:05:51 +08:00
|
|
|
|
2016-12-13 04:55:55 +08:00
|
|
|
err = crypto_shash_setkey(tfm_michael, key, MIC_KEYLEN);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = crypto_shash_init(desc);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = crypto_shash_update(desc, hdr, sizeof(hdr));
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = crypto_shash_update(desc, data, data_len);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = crypto_shash_final(desc, mic);
|
|
|
|
shash_desc_zero(desc);
|
2009-02-05 07:05:51 +08:00
|
|
|
|
2016-01-24 21:16:47 +08:00
|
|
|
return err;
|
2009-02-05 07:05:51 +08:00
|
|
|
}
|