Commit bd757b5d authored by Kees Cook's avatar Kees Cook Committed by Greg Kroah-Hartman

staging: rtl8192e: ieee80211: Convert from ahash to shash

This is an identical change to the wireless/lib80211 of the same name.
In preparing to remove all stack VLA usage from the kernel[1], this
removes the discouraged use of AHASH_REQUEST_ON_STACK in favor of
the smaller SHASH_DESC_ON_STACK by converting from ahash-wrapped-shash
to direct shash. By removing a layer of indirection this both improves
performance and reduces stack usage. The stack allocation will be made
a fixed size in a later patch to the crypto subsystem.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.comSigned-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent bb8a14a3
...@@ -50,9 +50,9 @@ struct rtllib_tkip_data { ...@@ -50,9 +50,9 @@ struct rtllib_tkip_data {
int key_idx; int key_idx;
struct crypto_skcipher *rx_tfm_arc4; struct crypto_skcipher *rx_tfm_arc4;
struct crypto_ahash *rx_tfm_michael; struct crypto_shash *rx_tfm_michael;
struct crypto_skcipher *tx_tfm_arc4; struct crypto_skcipher *tx_tfm_arc4;
struct crypto_ahash *tx_tfm_michael; struct crypto_shash *tx_tfm_michael;
/* scratch buffers for virt_to_page() (crypto API) */ /* scratch buffers for virt_to_page() (crypto API) */
u8 rx_hdr[16]; u8 rx_hdr[16];
u8 tx_hdr[16]; u8 tx_hdr[16];
...@@ -74,8 +74,7 @@ static void *rtllib_tkip_init(int key_idx) ...@@ -74,8 +74,7 @@ static void *rtllib_tkip_init(int key_idx)
goto fail; goto fail;
} }
priv->tx_tfm_michael = crypto_alloc_ahash("michael_mic", 0, priv->tx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0);
CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->tx_tfm_michael)) { if (IS_ERR(priv->tx_tfm_michael)) {
pr_debug("Could not allocate crypto API michael_mic\n"); pr_debug("Could not allocate crypto API michael_mic\n");
priv->tx_tfm_michael = NULL; priv->tx_tfm_michael = NULL;
...@@ -90,8 +89,7 @@ static void *rtllib_tkip_init(int key_idx) ...@@ -90,8 +89,7 @@ static void *rtllib_tkip_init(int key_idx)
goto fail; goto fail;
} }
priv->rx_tfm_michael = crypto_alloc_ahash("michael_mic", 0, priv->rx_tfm_michael = crypto_alloc_shash("michael_mic", 0, 0);
CRYPTO_ALG_ASYNC);
if (IS_ERR(priv->rx_tfm_michael)) { if (IS_ERR(priv->rx_tfm_michael)) {
pr_debug("Could not allocate crypto API michael_mic\n"); pr_debug("Could not allocate crypto API michael_mic\n");
priv->rx_tfm_michael = NULL; priv->rx_tfm_michael = NULL;
...@@ -101,9 +99,9 @@ static void *rtllib_tkip_init(int key_idx) ...@@ -101,9 +99,9 @@ static void *rtllib_tkip_init(int key_idx)
fail: fail:
if (priv) { if (priv) {
crypto_free_ahash(priv->tx_tfm_michael); crypto_free_shash(priv->tx_tfm_michael);
crypto_free_skcipher(priv->tx_tfm_arc4); crypto_free_skcipher(priv->tx_tfm_arc4);
crypto_free_ahash(priv->rx_tfm_michael); crypto_free_shash(priv->rx_tfm_michael);
crypto_free_skcipher(priv->rx_tfm_arc4); crypto_free_skcipher(priv->rx_tfm_arc4);
kfree(priv); kfree(priv);
} }
...@@ -117,9 +115,9 @@ static void rtllib_tkip_deinit(void *priv) ...@@ -117,9 +115,9 @@ static void rtllib_tkip_deinit(void *priv)
struct rtllib_tkip_data *_priv = priv; struct rtllib_tkip_data *_priv = priv;
if (_priv) { if (_priv) {
crypto_free_ahash(_priv->tx_tfm_michael); crypto_free_shash(_priv->tx_tfm_michael);
crypto_free_skcipher(_priv->tx_tfm_arc4); crypto_free_skcipher(_priv->tx_tfm_arc4);
crypto_free_ahash(_priv->rx_tfm_michael); crypto_free_shash(_priv->rx_tfm_michael);
crypto_free_skcipher(_priv->rx_tfm_arc4); crypto_free_skcipher(_priv->rx_tfm_arc4);
} }
kfree(priv); kfree(priv);
...@@ -504,29 +502,31 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv) ...@@ -504,29 +502,31 @@ static int rtllib_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
} }
static int michael_mic(struct crypto_ahash *tfm_michael, u8 *key, u8 *hdr, static int michael_mic(struct crypto_shash *tfm_michael, u8 *key, u8 *hdr,
u8 *data, size_t data_len, u8 *mic) u8 *data, size_t data_len, u8 *mic)
{ {
AHASH_REQUEST_ON_STACK(req, tfm_michael); SHASH_DESC_ON_STACK(desc, tfm_michael);
struct scatterlist sg[2];
int err; int err;
if (tfm_michael == NULL) { desc->tfm = tfm_michael;
pr_warn("michael_mic: tfm_michael == NULL\n"); desc->flags = 0;
return -1;
}
sg_init_table(sg, 2);
sg_set_buf(&sg[0], hdr, 16);
sg_set_buf(&sg[1], data, data_len);
if (crypto_ahash_setkey(tfm_michael, key, 8)) if (crypto_shash_setkey(tfm_michael, key, 8))
return -1; return -1;
ahash_request_set_tfm(req, tfm_michael); err = crypto_shash_init(desc);
ahash_request_set_callback(req, 0, NULL, NULL); if (err)
ahash_request_set_crypt(req, sg, mic, data_len + 16); goto out;
err = crypto_ahash_digest(req); err = crypto_shash_update(desc, hdr, 16);
ahash_request_zero(req); if (err)
goto out;
err = crypto_shash_update(desc, data, data_len);
if (err)
goto out;
err = crypto_shash_final(desc, mic);
out:
shash_desc_zero(desc);
return err; return err;
} }
...@@ -663,9 +663,9 @@ static int rtllib_tkip_set_key(void *key, int len, u8 *seq, void *priv) ...@@ -663,9 +663,9 @@ static int rtllib_tkip_set_key(void *key, int len, u8 *seq, void *priv)
{ {
struct rtllib_tkip_data *tkey = priv; struct rtllib_tkip_data *tkey = priv;
int keyidx; int keyidx;
struct crypto_ahash *tfm = tkey->tx_tfm_michael; struct crypto_shash *tfm = tkey->tx_tfm_michael;
struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4; struct crypto_skcipher *tfm2 = tkey->tx_tfm_arc4;
struct crypto_ahash *tfm3 = tkey->rx_tfm_michael; struct crypto_shash *tfm3 = tkey->rx_tfm_michael;
struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4; struct crypto_skcipher *tfm4 = tkey->rx_tfm_arc4;
keyidx = tkey->key_idx; keyidx = tkey->key_idx;
......
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