diff options
author | David S. Miller <davem@davemloft.net> | 2006-09-22 18:17:35 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-09-22 18:17:35 -0400 |
commit | e4bec827feda76d5e7417a2696a75424834d564f (patch) | |
tree | bd899e0c2fbf7f6dd1d33ce0610d88fc4a8864ee /net/ipv6 | |
parent | 44e36b42a8378be1dcf7e6f8a1cb2710a8903387 (diff) |
[IPSEC] esp: Defer output IV initialization to first use.
First of all, if the xfrm_state only gets used for input
packets this entropy is a complete waste.
Secondly, it is often the case that a configuration loads
many rules (perhaps even dynamically) and they don't all
necessarily ever get used.
This get_random_bytes() call was showing up in the profiles
for xfrm_state inserts which is how I noticed this.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6')
-rw-r--r-- | net/ipv6/esp6.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index ae50b9511151..e78680a9985b 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c | |||
@@ -99,8 +99,13 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) | |||
99 | esph->seq_no = htonl(++x->replay.oseq); | 99 | esph->seq_no = htonl(++x->replay.oseq); |
100 | xfrm_aevent_doreplay(x); | 100 | xfrm_aevent_doreplay(x); |
101 | 101 | ||
102 | if (esp->conf.ivlen) | 102 | if (esp->conf.ivlen) { |
103 | if (unlikely(!esp->conf.ivinitted)) { | ||
104 | get_random_bytes(esp->conf.ivec, esp->conf.ivlen); | ||
105 | esp->conf.ivinitted = 1; | ||
106 | } | ||
103 | crypto_blkcipher_set_iv(tfm, esp->conf.ivec, esp->conf.ivlen); | 107 | crypto_blkcipher_set_iv(tfm, esp->conf.ivec, esp->conf.ivlen); |
108 | } | ||
104 | 109 | ||
105 | do { | 110 | do { |
106 | struct scatterlist *sg = &esp->sgbuf[0]; | 111 | struct scatterlist *sg = &esp->sgbuf[0]; |
@@ -353,7 +358,7 @@ static int esp6_init_state(struct xfrm_state *x) | |||
353 | esp->conf.ivec = kmalloc(esp->conf.ivlen, GFP_KERNEL); | 358 | esp->conf.ivec = kmalloc(esp->conf.ivlen, GFP_KERNEL); |
354 | if (unlikely(esp->conf.ivec == NULL)) | 359 | if (unlikely(esp->conf.ivec == NULL)) |
355 | goto error; | 360 | goto error; |
356 | get_random_bytes(esp->conf.ivec, esp->conf.ivlen); | 361 | esp->conf.ivinitted = 0; |
357 | } | 362 | } |
358 | if (crypto_blkcipher_setkey(tfm, esp->conf.key, esp->conf.key_len)) | 363 | if (crypto_blkcipher_setkey(tfm, esp->conf.key, esp->conf.key_len)) |
359 | goto error; | 364 | goto error; |