mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-28 05:12:49 +00:00
mac802154: Use skcipher
This patch replaces uses of blkcipher with skcipher. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com>
This commit is contained in:
parent
e59dd982d3
commit
9695371862
2 changed files with 24 additions and 20 deletions
|
@ -17,9 +17,9 @@
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/bug.h>
|
#include <linux/bug.h>
|
||||||
#include <linux/completion.h>
|
#include <linux/completion.h>
|
||||||
#include <linux/crypto.h>
|
|
||||||
#include <linux/ieee802154.h>
|
#include <linux/ieee802154.h>
|
||||||
#include <crypto/aead.h>
|
#include <crypto/aead.h>
|
||||||
|
#include <crypto/skcipher.h>
|
||||||
|
|
||||||
#include "ieee802154_i.h"
|
#include "ieee802154_i.h"
|
||||||
#include "llsec.h"
|
#include "llsec.h"
|
||||||
|
@ -144,18 +144,18 @@ llsec_key_alloc(const struct ieee802154_llsec_key *template)
|
||||||
goto err_tfm;
|
goto err_tfm;
|
||||||
}
|
}
|
||||||
|
|
||||||
key->tfm0 = crypto_alloc_blkcipher("ctr(aes)", 0, CRYPTO_ALG_ASYNC);
|
key->tfm0 = crypto_alloc_skcipher("ctr(aes)", 0, CRYPTO_ALG_ASYNC);
|
||||||
if (IS_ERR(key->tfm0))
|
if (IS_ERR(key->tfm0))
|
||||||
goto err_tfm;
|
goto err_tfm;
|
||||||
|
|
||||||
if (crypto_blkcipher_setkey(key->tfm0, template->key,
|
if (crypto_skcipher_setkey(key->tfm0, template->key,
|
||||||
IEEE802154_LLSEC_KEY_SIZE))
|
IEEE802154_LLSEC_KEY_SIZE))
|
||||||
goto err_tfm0;
|
goto err_tfm0;
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
err_tfm0:
|
err_tfm0:
|
||||||
crypto_free_blkcipher(key->tfm0);
|
crypto_free_skcipher(key->tfm0);
|
||||||
err_tfm:
|
err_tfm:
|
||||||
for (i = 0; i < ARRAY_SIZE(key->tfm); i++)
|
for (i = 0; i < ARRAY_SIZE(key->tfm); i++)
|
||||||
if (key->tfm[i])
|
if (key->tfm[i])
|
||||||
|
@ -175,7 +175,7 @@ static void llsec_key_release(struct kref *ref)
|
||||||
for (i = 0; i < ARRAY_SIZE(key->tfm); i++)
|
for (i = 0; i < ARRAY_SIZE(key->tfm); i++)
|
||||||
crypto_free_aead(key->tfm[i]);
|
crypto_free_aead(key->tfm[i]);
|
||||||
|
|
||||||
crypto_free_blkcipher(key->tfm0);
|
crypto_free_skcipher(key->tfm0);
|
||||||
kzfree(key);
|
kzfree(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,15 +620,17 @@ llsec_do_encrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
|
||||||
{
|
{
|
||||||
u8 iv[16];
|
u8 iv[16];
|
||||||
struct scatterlist src;
|
struct scatterlist src;
|
||||||
struct blkcipher_desc req = {
|
SKCIPHER_REQUEST_ON_STACK(req, key->tfm0);
|
||||||
.tfm = key->tfm0,
|
int err;
|
||||||
.info = iv,
|
|
||||||
.flags = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
llsec_geniv(iv, sec->params.hwaddr, &hdr->sec);
|
llsec_geniv(iv, sec->params.hwaddr, &hdr->sec);
|
||||||
sg_init_one(&src, skb->data, skb->len);
|
sg_init_one(&src, skb->data, skb->len);
|
||||||
return crypto_blkcipher_encrypt_iv(&req, &src, &src, skb->len);
|
skcipher_request_set_tfm(req, key->tfm0);
|
||||||
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
||||||
|
skcipher_request_set_crypt(req, &src, &src, skb->len, iv);
|
||||||
|
err = crypto_skcipher_encrypt(req);
|
||||||
|
skcipher_request_zero(req);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crypto_aead*
|
static struct crypto_aead*
|
||||||
|
@ -830,11 +832,8 @@ llsec_do_decrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
int datalen;
|
int datalen;
|
||||||
struct scatterlist src;
|
struct scatterlist src;
|
||||||
struct blkcipher_desc req = {
|
SKCIPHER_REQUEST_ON_STACK(req, key->tfm0);
|
||||||
.tfm = key->tfm0,
|
int err;
|
||||||
.info = iv,
|
|
||||||
.flags = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
llsec_geniv(iv, dev_addr, &hdr->sec);
|
llsec_geniv(iv, dev_addr, &hdr->sec);
|
||||||
data = skb_mac_header(skb) + skb->mac_len;
|
data = skb_mac_header(skb) + skb->mac_len;
|
||||||
|
@ -842,7 +841,13 @@ llsec_do_decrypt_unauth(struct sk_buff *skb, const struct mac802154_llsec *sec,
|
||||||
|
|
||||||
sg_init_one(&src, data, datalen);
|
sg_init_one(&src, data, datalen);
|
||||||
|
|
||||||
return crypto_blkcipher_decrypt_iv(&req, &src, &src, datalen);
|
skcipher_request_set_tfm(req, key->tfm0);
|
||||||
|
skcipher_request_set_callback(req, 0, NULL, NULL);
|
||||||
|
skcipher_request_set_crypt(req, &src, &src, datalen, iv);
|
||||||
|
|
||||||
|
err = crypto_skcipher_decrypt(req);
|
||||||
|
skcipher_request_zero(req);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/hashtable.h>
|
#include <linux/hashtable.h>
|
||||||
#include <linux/crypto.h>
|
|
||||||
#include <linux/kref.h>
|
#include <linux/kref.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <net/af_ieee802154.h>
|
#include <net/af_ieee802154.h>
|
||||||
|
@ -30,7 +29,7 @@ struct mac802154_llsec_key {
|
||||||
|
|
||||||
/* one tfm for each authsize (4/8/16) */
|
/* one tfm for each authsize (4/8/16) */
|
||||||
struct crypto_aead *tfm[3];
|
struct crypto_aead *tfm[3];
|
||||||
struct crypto_blkcipher *tfm0;
|
struct crypto_skcipher *tfm0;
|
||||||
|
|
||||||
struct kref ref;
|
struct kref ref;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue