Commit 25528fda authored by Herbert Xu's avatar Herbert Xu

mac802154: Switch to new AEAD interface

This patch makes use of the new AEAD interface which uses a single
SG list instead of separate lists for the AD and plain text.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 000ae7b2
...@@ -650,7 +650,7 @@ llsec_do_encrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -650,7 +650,7 @@ llsec_do_encrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,
u8 iv[16]; u8 iv[16];
unsigned char *data; unsigned char *data;
int authlen, assoclen, datalen, rc; int authlen, assoclen, datalen, rc;
struct scatterlist src, assoc[2], dst[2]; struct scatterlist sg;
struct aead_request *req; struct aead_request *req;
authlen = ieee802154_sechdr_authtag_len(&hdr->sec); authlen = ieee802154_sechdr_authtag_len(&hdr->sec);
...@@ -660,30 +660,23 @@ llsec_do_encrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -660,30 +660,23 @@ llsec_do_encrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
sg_init_table(assoc, 2);
sg_set_buf(&assoc[0], skb_mac_header(skb), skb->mac_len);
assoclen = skb->mac_len; assoclen = skb->mac_len;
data = skb_mac_header(skb) + skb->mac_len; data = skb_mac_header(skb) + skb->mac_len;
datalen = skb_tail_pointer(skb) - data; datalen = skb_tail_pointer(skb) - data;
if (hdr->sec.level & IEEE802154_SCF_SECLEVEL_ENC) { skb_put(skb, authlen);
sg_set_buf(&assoc[1], data, 0);
} else { sg_init_one(&sg, skb_mac_header(skb), assoclen + datalen + authlen);
sg_set_buf(&assoc[1], data, datalen);
if (!(hdr->sec.level & IEEE802154_SCF_SECLEVEL_ENC)) {
assoclen += datalen; assoclen += datalen;
datalen = 0; datalen = 0;
} }
sg_init_one(&src, data, datalen);
sg_init_table(dst, 2);
sg_set_buf(&dst[0], data, datalen);
sg_set_buf(&dst[1], skb_put(skb, authlen), authlen);
aead_request_set_callback(req, 0, NULL, NULL); aead_request_set_callback(req, 0, NULL, NULL);
aead_request_set_assoc(req, assoc, assoclen); aead_request_set_crypt(req, &sg, &sg, datalen, iv);
aead_request_set_crypt(req, &src, dst, datalen, iv); aead_request_set_ad(req, assoclen);
rc = crypto_aead_encrypt(req); rc = crypto_aead_encrypt(req);
...@@ -859,7 +852,7 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -859,7 +852,7 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,
u8 iv[16]; u8 iv[16];
unsigned char *data; unsigned char *data;
int authlen, datalen, assoclen, rc; int authlen, datalen, assoclen, rc;
struct scatterlist src, assoc[2]; struct scatterlist sg;
struct aead_request *req; struct aead_request *req;
authlen = ieee802154_sechdr_authtag_len(&hdr->sec); authlen = ieee802154_sechdr_authtag_len(&hdr->sec);
...@@ -869,27 +862,21 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, ...@@ -869,27 +862,21 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
sg_init_table(assoc, 2);
sg_set_buf(&assoc[0], skb_mac_header(skb), skb->mac_len);
assoclen = skb->mac_len; assoclen = skb->mac_len;
data = skb_mac_header(skb) + skb->mac_len; data = skb_mac_header(skb) + skb->mac_len;
datalen = skb_tail_pointer(skb) - data; datalen = skb_tail_pointer(skb) - data;
if (hdr->sec.level & IEEE802154_SCF_SECLEVEL_ENC) { sg_init_one(&sg, skb_mac_header(skb), assoclen + datalen);
sg_set_buf(&assoc[1], data, 0);
} else { if (!(hdr->sec.level & IEEE802154_SCF_SECLEVEL_ENC)) {
sg_set_buf(&assoc[1], data, datalen - authlen);
assoclen += datalen - authlen; assoclen += datalen - authlen;
data += datalen - authlen;
datalen = authlen; datalen = authlen;
} }
sg_init_one(&src, data, datalen);
aead_request_set_callback(req, 0, NULL, NULL); aead_request_set_callback(req, 0, NULL, NULL);
aead_request_set_assoc(req, assoc, assoclen); aead_request_set_crypt(req, &sg, &sg, datalen, iv);
aead_request_set_crypt(req, &src, &src, datalen, iv); aead_request_set_ad(req, assoclen);
rc = crypto_aead_decrypt(req); rc = crypto_aead_decrypt(req);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment