aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/tcp.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2016-01-24 08:20:23 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2016-01-27 07:36:18 -0500
commitcf80e0e47e0e7a8994dfadefec0e1395c622817a (patch)
tree65f0d15e1420f2a1567afea63b032ac7e55cb900 /net/ipv4/tcp.c
parent5821c769706561da81e9fcec4a6ca6dbbb2f30cb (diff)
tcp: Use ahash
This patch replaces uses of the long obsolete hash interface with ahash. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Acked-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp.c')
-rw-r--r--net/ipv4/tcp.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index fd17eec93525..91ffef3a55d2 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -247,6 +247,7 @@
247 247
248#define pr_fmt(fmt) "TCP: " fmt 248#define pr_fmt(fmt) "TCP: " fmt
249 249
250#include <crypto/hash.h>
250#include <linux/kernel.h> 251#include <linux/kernel.h>
251#include <linux/module.h> 252#include <linux/module.h>
252#include <linux/types.h> 253#include <linux/types.h>
@@ -266,7 +267,6 @@
266#include <linux/swap.h> 267#include <linux/swap.h>
267#include <linux/cache.h> 268#include <linux/cache.h>
268#include <linux/err.h> 269#include <linux/err.h>
269#include <linux/crypto.h>
270#include <linux/time.h> 270#include <linux/time.h>
271#include <linux/slab.h> 271#include <linux/slab.h>
272 272
@@ -2939,17 +2939,26 @@ static bool tcp_md5sig_pool_populated = false;
2939 2939
2940static void __tcp_alloc_md5sig_pool(void) 2940static void __tcp_alloc_md5sig_pool(void)
2941{ 2941{
2942 struct crypto_ahash *hash;
2942 int cpu; 2943 int cpu;
2943 2944
2945 hash = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
2946 if (IS_ERR_OR_NULL(hash))
2947 return;
2948
2944 for_each_possible_cpu(cpu) { 2949 for_each_possible_cpu(cpu) {
2945 if (!per_cpu(tcp_md5sig_pool, cpu).md5_desc.tfm) { 2950 struct ahash_request *req;
2946 struct crypto_hash *hash;
2947 2951
2948 hash = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC); 2952 if (per_cpu(tcp_md5sig_pool, cpu).md5_req)
2949 if (IS_ERR_OR_NULL(hash)) 2953 continue;
2950 return; 2954
2951 per_cpu(tcp_md5sig_pool, cpu).md5_desc.tfm = hash; 2955 req = ahash_request_alloc(hash, GFP_KERNEL);
2952 } 2956 if (!req)
2957 return;
2958
2959 ahash_request_set_callback(req, 0, NULL, NULL);
2960
2961 per_cpu(tcp_md5sig_pool, cpu).md5_req = req;
2953 } 2962 }
2954 /* before setting tcp_md5sig_pool_populated, we must commit all writes 2963 /* before setting tcp_md5sig_pool_populated, we must commit all writes
2955 * to memory. See smp_rmb() in tcp_get_md5sig_pool() 2964 * to memory. See smp_rmb() in tcp_get_md5sig_pool()
@@ -2999,7 +3008,6 @@ int tcp_md5_hash_header(struct tcp_md5sig_pool *hp,
2999{ 3008{
3000 struct scatterlist sg; 3009 struct scatterlist sg;
3001 struct tcphdr hdr; 3010 struct tcphdr hdr;
3002 int err;
3003 3011
3004 /* We are not allowed to change tcphdr, make a local copy */ 3012 /* We are not allowed to change tcphdr, make a local copy */
3005 memcpy(&hdr, th, sizeof(hdr)); 3013 memcpy(&hdr, th, sizeof(hdr));
@@ -3007,8 +3015,8 @@ int tcp_md5_hash_header(struct tcp_md5sig_pool *hp,
3007 3015
3008 /* options aren't included in the hash */ 3016 /* options aren't included in the hash */
3009 sg_init_one(&sg, &hdr, sizeof(hdr)); 3017 sg_init_one(&sg, &hdr, sizeof(hdr));
3010 err = crypto_hash_update(&hp->md5_desc, &sg, sizeof(hdr)); 3018 ahash_request_set_crypt(hp->md5_req, &sg, NULL, sizeof(hdr));
3011 return err; 3019 return crypto_ahash_update(hp->md5_req);
3012} 3020}
3013EXPORT_SYMBOL(tcp_md5_hash_header); 3021EXPORT_SYMBOL(tcp_md5_hash_header);
3014 3022
@@ -3017,7 +3025,7 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *hp,
3017{ 3025{
3018 struct scatterlist sg; 3026 struct scatterlist sg;
3019 const struct tcphdr *tp = tcp_hdr(skb); 3027 const struct tcphdr *tp = tcp_hdr(skb);
3020 struct hash_desc *desc = &hp->md5_desc; 3028 struct ahash_request *req = hp->md5_req;
3021 unsigned int i; 3029 unsigned int i;
3022 const unsigned int head_data_len = skb_headlen(skb) > header_len ? 3030 const unsigned int head_data_len = skb_headlen(skb) > header_len ?
3023 skb_headlen(skb) - header_len : 0; 3031 skb_headlen(skb) - header_len : 0;
@@ -3027,7 +3035,8 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *hp,
3027 sg_init_table(&sg, 1); 3035 sg_init_table(&sg, 1);
3028 3036
3029 sg_set_buf(&sg, ((u8 *) tp) + header_len, head_data_len); 3037 sg_set_buf(&sg, ((u8 *) tp) + header_len, head_data_len);
3030 if (crypto_hash_update(desc, &sg, head_data_len)) 3038 ahash_request_set_crypt(req, &sg, NULL, head_data_len);
3039 if (crypto_ahash_update(req))
3031 return 1; 3040 return 1;
3032 3041
3033 for (i = 0; i < shi->nr_frags; ++i) { 3042 for (i = 0; i < shi->nr_frags; ++i) {
@@ -3037,7 +3046,8 @@ int tcp_md5_hash_skb_data(struct tcp_md5sig_pool *hp,
3037 3046
3038 sg_set_page(&sg, page, skb_frag_size(f), 3047 sg_set_page(&sg, page, skb_frag_size(f),
3039 offset_in_page(offset)); 3048 offset_in_page(offset));
3040 if (crypto_hash_update(desc, &sg, skb_frag_size(f))) 3049 ahash_request_set_crypt(req, &sg, NULL, skb_frag_size(f));
3050 if (crypto_ahash_update(req))
3041 return 1; 3051 return 1;
3042 } 3052 }
3043 3053
@@ -3054,7 +3064,8 @@ int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct tcp_md5sig_key *ke
3054 struct scatterlist sg; 3064 struct scatterlist sg;
3055 3065
3056 sg_init_one(&sg, key->key, key->keylen); 3066 sg_init_one(&sg, key->key, key->keylen);
3057 return crypto_hash_update(&hp->md5_desc, &sg, key->keylen); 3067 ahash_request_set_crypt(hp->md5_req, &sg, NULL, key->keylen);
3068 return crypto_ahash_update(hp->md5_req);
3058} 3069}
3059EXPORT_SYMBOL(tcp_md5_hash_key); 3070EXPORT_SYMBOL(tcp_md5_hash_key);
3060 3071