Does ESP support 64 bit sequence numbering for authentication hash ?
Subsystems (3)
Hi,
Does ESP support 64 bit sequence numbering for use with the authentication HMAC ?
I've looked at struct aead_givcrypt_request and it has a u64 seq member. Does ESP populate this with a 64 bit sequence number ?
If 32 bit sequence numbering negotiated then how does the HMAC routine know that it should not use the top 32 bits of seq ? Or is it simply that if the top 32 bits are zero then the HMAC just uses the lower 32 bits ?
Thanks for any insight.
Regards,
Dean Jenkins
MontaVista Software
Herbert Xu
maintainerQuoted 3 lines · Dean Jenkins
Does ESP support 64 bit sequence numbering for use with the authentication HMAC ?
We don't support 64-bit sequence numbers yet. If you look at struct xfrm_replay_state which is where we store the sequence number internally you'll find that it uses u32s.
Patches for 64-bit support are welcome of course.
Quoted 2 lines
I've looked at struct
aead_givcrypt_requestand it has a u64 seq member. Does ESP populate this with a 64 bit sequence number ?
That's different. That's a generic value used to construct the IV.
Quoted 4 lines
If 32 bit sequence numbering negotiated then how does the HMAC routine know that it should not use the top 32 bits of seq ? Or is it simply that if the top 32 bits are zero then the HMAC just uses the lower 32 bits ?
Because the value we start out with is a u32, the high bits are never set for IPsec.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 11 lines · Herbert Xu
Quoted 3 lines · Dean Jenkins
Does ESP support 64 bit sequence numbering for use with the authentication HMAC ?
We don't support 64-bit sequence numbers yet. If you look at struct
xfrm_replay_statewhich is where we store the sequence number internally you'll find that it uses u32s.Patches for 64-bit support are welcome of course.
Is there actually anybody working on 64-bit sequence number support? If not, I'd start to look at it.
Herbert Xu
maintainerQuoted 5 lines · Steffen Klassert
Quoted 2 lines
Patches for 64-bit support are welcome of course.
Is there actually anybody working on 64-bit sequence number support? If not, I'd start to look at it.
I certainly am not :)
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtQuoted 8 lines · Steffen Klassert
Quoted 7 lines · Herbert Xu
Quoted 2 lines · Dean Jenkins
Does ESP support 64 bit sequence numbering for use with the authentication HMAC ?
We don't support 64-bit sequence numbers yet. If you look at struct
xfrm_replay_statewhich is where we store the sequence number internally you'll find that it uses u32s.
Quoted 5 lines
Quoted 2 lines
Patches for 64-bit support are welcome of course.
Is there actually anybody working on 64-bit sequence number support? If not, I'd start to look at it.
A while ago I implemented a rough version of ESN support. It's against an ancient 2.6.7 kernel though, and is only superficially tested.
I suppose there's no reason not to publish them here, if only for historical reasons. My apologies to anyone not interested :)
Alex Badea (6):
xfrm: move xfrm_replay_{check,advance} to their own source file
xfrm: introduce XFRM_STATE_ESN flag, and extended replay structure
xfrm: add generic support for replay protection with Extended
Sequence Numbers
ipsec: Extended Sequence Numbers support for ESP
ipsec: Extended Sequence Numbers support for AH
xfrm: add test harness for Extended Sequence Numbers replay
protection algorithm
Best regards,
Alex
Quoted 1 line
From
2831af26b9783da9b311e8442b0cd19df3f4b422Mon Sep 17 00:00:00 2001
From: Alex Badea <[email protected]>
Date: Thu, 18 Jun 2009 16:41:06 +0300
Subject: [PATCH] xfrm: move xfrm_replay_{check,advance} to their own source file
--- src/net/xfrm/Makefile | 2 +- src/net/xfrm/xfrm_replay.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/net/xfrm/xfrm_state.c | 44 ------------------------------------------ 3 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 src/net/xfrm/xfrm_replay.c
src/net/xfrm/Makefile +1 -1
@@ -3,6 +3,6 @@ # obj-$(CONFIG_CAVIUM) += xfrm_cavium_stub.o obj-$(CONFIG_XFRM) += xfrm_policy.o xfrm_state.o xfrm_input.o xfrm_algo.o xfrm_output.o \ - xfrm_export.o + xfrm_replay.o xfrm_export.o obj-$(CONFIG_XFRM_USER) += xfrm_user.o
src/net/xfrm/xfrm_replay.c new file +46 -0
46 lines not on this page · raw message
src/net/xfrm/xfrm_state.c +0 -44
50 lines not on this page · raw message
Signature · 1 line
1.5.4.3
Quoted 1 line
From
dcfe6e052d43cac53d40e031b857b5f1ce06a26bMon Sep 17 00:00:00 2001
From: Alex Badea <[email protected]>
Date: Thu, 18 Jun 2009 16:46:44 +0300
Subject: [PATCH] xfrm: introduce XFRM_STATE_ESN flag, and extended replay structure
--- src/include/linux/xfrm.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
src/include/linux/xfrm.h +7 -0
@@ -74,6 +74,12 @@ struct xfrm_replay_state__u32 bitmap; }; +struct xfrm_replay_state_ext +{ +__u32 oseq_hi; +__u32 seq_hi; +}; +struct xfrm_algo {char alg_name[64 ];int alg_key_len;/* in bits */
@@ -171,6 +177,7 @@ struct xfrm_usersa_info {__u8 replay_window;__u8 flags;#define XFRM_STATE_NOECN 1 +#define XFRM_STATE_ESN 64/* Extended Sequence Numbers */ };struct xfrm_usersa_id {
Signature · 1 line
1.5.4.3
Quoted 1 line
From
7aa47cdff60f5a1a7b48bc6100daea710f0ffa37Mon Sep 17 00:00:00 2001
From: Alex Badea <[email protected]>
Date: Thu, 18 Jun 2009 17:03:39 +0300
Subject: [PATCH] xfrm: add generic support for replay protection with Extended Sequence Numbers
--- src/include/net/xfrm.h | 2 + src/net/ipv4/xfrm4_input.c | 2 +- src/net/ipv6/xfrm6_input.c | 2 +- src/net/xfrm/xfrm_export.c | 1 + src/net/xfrm/xfrm_replay.c | 77 +++++++++++++++++++++++++++++++++++++++---- 5 files changed, 74 insertions(+), 10 deletions(-)
src/include/net/xfrm.h +2 -0
@@ -132,6 +132,7 @@ struct xfrm_state/* State for replay detection */ struct xfrm_replay_state replay; +struct xfrm_replay_state_ext replay_ext;/* Statistics */ struct xfrm_stats stats;
@@ -819,6 +820,7 @@ extern struct xfrm_state *xfrm_find_acq_byseq(u32 seq);extern void xfrm_state_delete (struct xfrm_state *x);extern void xfrm_state_flush (u8 proto);extern int xfrm_replay_check (struct xfrm_state *x,u32 seq); +extern u32 xfrm_replay_seqhi (struct xfrm_state *x,u32 seq);extern void xfrm_replay_advance (struct xfrm_state *x,u32 seq);extern int xfrm_check_selectors (struct xfrm_state **x,int n,struct flowi *fl);extern int xfrm_check_output (struct xfrm_state *x,struct sk_buff *skb,unsigned short family);
src/net/ipv4/xfrm4_input.c +1 -1
@@ -91,7 +91,7 @@ int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)/* only the first xfrm gets the encap type */ encap_type =0 ; -if (x->props.replay_window) +if (x->props.replay_window || (x->props.flags &XFRM_STATE_ESN ))xfrm_replay_advance (x, seq); x->curlft.bytes += skb->len;
src/net/ipv6/xfrm6_input.c +1 -1
@@ -75,7 +75,7 @@ int xfrm6_rcv(struct sk_buff **pskb, unsigned int *nhoffp)if (nexthdr <=0 ) goto drop_unlock; -if (x->props.replay_window) +if (x->props.replay_window || (x->props.flags &XFRM_STATE_ESN ))xfrm_replay_advance (x, seq); x->curlft.bytes += skb->len;
src/net/xfrm/xfrm_export.c +1 -0
@@ -25,6 +25,7 @@ EXPORT_SYMBOL(xfrm_state_get_afinfo);EXPORT_SYMBOL (xfrm_state_put_afinfo);EXPORT_SYMBOL (xfrm_state_delete_tunnel);EXPORT_SYMBOL (xfrm_replay_check); +EXPORT_SYMBOL (xfrm_replay_seqhi);EXPORT_SYMBOL (xfrm_replay_advance);EXPORT_SYMBOL (xfrm_check_selectors);EXPORT_SYMBOL (xfrm_check_output);
src/net/xfrm/xfrm_replay.c +69 -8
106 lines not on this page · raw message
Signature · 1 line
1.5.4.3
Quoted 1 line
From
d503604d592dac8232780d9442b67c4b051cf602Mon Sep 17 00:00:00 2001
From: Alex Badea <[email protected]>
Date: Thu, 18 Jun 2009 17:07:45 +0300
Subject: [PATCH] ipsec: Extended Sequence Numbers support for ESP
--- src/include/net/esp.h | 14 ++++++++++++-- src/net/ipv4/esp4.c | 18 +++++++++++++++--- src/net/ipv6/esp6.c | 15 +++++++++++++-- 3 files changed, 40 insertions(+), 7 deletions(-)
src/include/net/esp.h +12 -2
@@ -2,6 +2,7 @@#define _NET_ESP_H#include <net/xfrm.h> +#include <asm/scatterlist.h> struct esp_data {
@@ -28,8 +29,10 @@ struct esp_dataint icv_trunc_len;void (*icv)(struct esp_data *,struct sk_buff *skb, -int offset,int len,u8 *icv); +int offset,int len, +u32 seq_hi,u8 *icv);struct crypto_tfm *tfm; + unsigned esn:1; /* Extended Sequence Number enabled */ } auth; };
@@ -39,7 +42,7 @@ extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);static inline void esp_hmac_digest (struct esp_data *esp,struct sk_buff *skb,int offset, -int len,u8 *auth_data) +int len,u32 seq_hi,u8 *auth_data) {struct crypto_tfm *tfm = esp->auth.tfm;char *icv = esp->auth.work_icv;
@@ -47,6 +50,13 @@ esp_hmac_digest(struct esp_data *esp, struct sk_buff *skb, int offset,memset (auth_data,0 , esp->auth.icv_trunc_len);crypto_hmac_init (tfm, esp->auth.key, &esp->auth.key_len);skb_icv_walk (skb, tfm, offset, len, crypto_hmac_update); +if (unlikely (esp->auth.esn)) { +struct scatterlist sg; + sg.page =virt_to_page (&seq_hi); + sg.offset =offset_in_page (&seq_hi); + sg.length =sizeof (u32); +crypto_hmac_update (tfm, &sg,1 ); + }crypto_hmac_final (tfm, esp->auth.key, &esp->auth.key_len, icv);memcpy (auth_data, icv, esp->auth.icv_trunc_len); }
src/net/ipv4/esp4.c +15 -3
@@ -209,6 +209,8 @@ int esp_output(struct sk_buff **pskb) esph->spi = x->id.spi; esph->seq_no =htonl (++x->replay.oseq); +if (unlikely (!x->replay.oseq)) + x->replay_ext.oseq_hi++;if (esp->conf.ivlen)crypto_cipher_set_iv (tfm, esp->conf.ivec,crypto_tfm_alg_ivsize (tfm));
@@ -234,8 +236,11 @@ int esp_output(struct sk_buff **pskb) }if (esp->auth.icv_full_len) { +printk ("%s: oseq=%u oseq_hi=%d\n" , __FUNCTION__, x->replay.oseq, x->replay_ext.oseq_hi); esp->auth.icv (esp, *pskb, (u8 *)esph-(*pskb)->data, -sizeof (struct ip_esp_hdr ) + esp->conf.ivlen+clen, trailer->tail); +sizeof (struct ip_esp_hdr ) + esp->conf.ivlen+clen, + x->replay_ext.oseq_hi, + trailer->tail);pskb_put (*pskb, trailer, alen); }
@@ -286,8 +291,13 @@ int esp_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buif (esp->auth.icv_full_len) {u8 sum[esp->auth.icv_full_len];u8 sum1[alen]; - - esp->auth.icv (esp, skb,0 , skb->len-alen, sum); + +u32 seq_hi =0 ; +if (x->props.flags &XFRM_STATE_ESN ) { +u32 seq = ((struct ip_esp_hdr *) skb->data)->seq_no; + seq_hi =xfrm_replay_seqhi (x, seq); + } + esp->auth.icv (esp, skb,0 , skb->len-alen, seq_hi, sum);if (skb_copy_bits (skb, skb->len-alen, sum1, alen))BUG ();
@@ -539,6 +549,8 @@ int esp_init_state(struct xfrm_state *x, void *args)if (esp->auth.tfm ==NULL ) goto error; esp->auth.icv = esp_hmac_digest; +if (x->props.flags &XFRM_STATE_ESN ) + esp->auth.esn =1 ; aalg_desc =xfrm_aalg_get_byname (x->aalg->alg_name);BUG_ON (!aalg_desc);
src/net/ipv6/esp6.c +13 -2
@@ -163,6 +163,8 @@ int esp6_output(struct sk_buff **pskb) esph->spi = x->id.spi; esph->seq_no =htonl (++x->replay.oseq); +if (unlikely (!x->replay.oseq)) + x->replay_ext.oseq_hi++;if (esp->conf.ivlen)crypto_cipher_set_iv (tfm, esp->conf.ivec,crypto_tfm_alg_ivsize (tfm));
@@ -189,7 +191,9 @@ int esp6_output(struct sk_buff **pskb)if (esp->auth.icv_full_len) { esp->auth.icv (esp, *pskb, (u8 *)esph-(*pskb)->data, -sizeof (struct ipv6_esp_hdr ) + esp->conf.ivlen+clen, trailer->tail); +sizeof (struct ipv6_esp_hdr ) + esp->conf.ivlen+clen, + x->replay_ext.oseq_hi, + trailer->tail);pskb_put (*pskb, trailer, alen); }
@@ -248,7 +252,12 @@ int esp6_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_bu8 sum[esp->auth.icv_full_len];u8 sum1[alen]; - esp->auth.icv (esp, skb,0 , skb->len-alen, sum); +u32 seq_hi =0 ; +if (x->props.flags &XFRM_STATE_ESN ) { +u32 seq = ((struct ipv6_esp_hdr *) skb->data)->seq_no; + seq_hi =xfrm_replay_seqhi (x, seq); + } + esp->auth.icv (esp, skb,0 , skb->len-alen, seq_hi, sum);if (skb_copy_bits (skb, skb->len-alen, sum1, alen))BUG ();
@@ -409,6 +418,8 @@ int esp6_init_state(struct xfrm_state *x, void *args)if (esp->auth.tfm ==NULL ) goto error; esp->auth.icv = esp_hmac_digest; +if (x->props.flags &XFRM_STATE_ESN ) + esp->auth.esn =1 ; aalg_desc =xfrm_aalg_get_byname (x->aalg->alg_name);BUG_ON (!aalg_desc);
Signature · 1 line
1.5.4.3
Quoted 1 line
From
8c573d0716e88e514a7064991838f6a482e861f4Mon Sep 17 00:00:00 2001
From: Alex Badea <[email protected]>
Date: Thu, 18 Jun 2009 17:12:23 +0300
Subject: [PATCH] ipsec: Extended Sequence Numbers support for AH
--- src/include/net/ah.h | 14 ++++++++++++-- src/net/ipv4/ah4.c | 12 ++++++++++-- src/net/ipv6/ah6.c | 12 ++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-)
src/include/net/ah.h +12 -2
@@ -2,6 +2,7 @@#define _NET_AH_H#include <net/xfrm.h> +#include <asm/scatterlist.h> /* This is the maximum truncated ICV length that we know of. */ #define MAX_AH_AUTH_LEN 12
@@ -15,19 +16,28 @@ struct ah_dataint icv_trunc_len;void (*icv)(struct ah_data *, -struct sk_buff *skb,u8 *icv); +struct sk_buff *skb, +u32 seq_hi,u8 *icv);struct crypto_tfm *tfm; + unsigned esn:1; };static inline void -ah_hmac_digest (struct ah_data *ahp,struct sk_buff *skb,u8 *auth_data) +ah_hmac_digest (struct ah_data *ahp,struct sk_buff *skb,u32 seq_hi,u8 *auth_data) {struct crypto_tfm *tfm = ahp->tfm;memset (auth_data,0 , ahp->icv_trunc_len);crypto_hmac_init (tfm, ahp->key, &ahp->key_len);skb_icv_walk (skb, tfm,0 , skb->len, crypto_hmac_update); +if (unlikely (ahp->esn)) { +struct scatterlist sg; + sg.page =virt_to_page (&seq_hi); + sg.offset =offset_in_page (&seq_hi); + sg.length =sizeof (u32); +crypto_hmac_update (tfm, &sg,1 ); + }crypto_hmac_final (tfm, ahp->key, &ahp->key_len, ahp->work_icv);memcpy (auth_data, ahp->work_icv, ahp->icv_trunc_len); }
src/net/ipv4/ah4.c +10 -2
@@ -121,7 +121,9 @@ static int ah_output(struct sk_buff **pskb) ah->reserved =0 ; ah->spi = x->id.spi; ah->seq_no =htonl (++x->replay.oseq); - ahp->icv (ahp, *pskb, ah->auth_data); +if (unlikely (!x->replay.oseq)) + x->replay_ext.oseq_hi++; + ahp->icv (ahp, *pskb, x->replay_ext.oseq_hi, ah->auth_data); top_iph->tos = iph->tos; top_iph->ttl = iph->ttl;if (x->props.mode) {
@@ -202,9 +204,13 @@ int ah_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buf {u8 auth_data[MAX_AH_AUTH_LEN ]; +u32 seq_hi =0 ; +if (x->props.flags &XFRM_STATE_ESN ) + seq_hi =xfrm_replay_seqhi (x, ah->seq_no); +memcpy (auth_data, ah->auth_data, ahp->icv_trunc_len);skb_push (skb, skb->data - skb->nh.raw); - ahp->icv (ahp, skb, ah->auth_data); + ahp->icv (ahp, skb, seq_hi, ah->auth_data);if (memcmp (ah->auth_data, auth_data, ahp->icv_trunc_len)) { x->stats.integrity_failed++; goto out;
@@ -265,6 +271,8 @@ static int ah_init_state(struct xfrm_state *x, void *args)if (!ahp->tfm) goto error; ahp->icv = ah_hmac_digest; +if (x->props.flags &XFRM_STATE_ESN ) + ahp->esn =1 ;/* * Lookup the algorithm description maintained by xfrm_algo,
src/net/ipv6/ah6.c +10 -2
@@ -213,7 +213,9 @@ int ah6_output(struct sk_buff **pskb) ah->reserved =0 ; ah->spi = x->id.spi; ah->seq_no =htonl (++x->replay.oseq); - ahp->icv (ahp, *pskb, ah->auth_data); +if (unlikely (!x->replay.oseq)) + x->replay_ext.oseq_hi++; + ahp->icv (ahp, *pskb, x->replay_ext.oseq_hi, ah->auth_data);if (x->props.mode) { (*pskb)->nh.ipv6h->hop_limit = iph->hop_limit;
@@ -320,10 +322,14 @@ int ah6_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_bu {u8 auth_data[MAX_AH_AUTH_LEN ]; +u32 seq_hi =0 ; +if (x->props.flags &XFRM_STATE_ESN ) + seq_hi =xfrm_replay_seqhi (x, ah->seq_no); +memcpy (auth_data, ah->auth_data, ahp->icv_trunc_len);memset (ah->auth_data,0 , ahp->icv_trunc_len);skb_push (skb, skb->data - skb->nh.raw); - ahp->icv (ahp, skb, ah->auth_data); + ahp->icv (ahp, skb, seq_hi, ah->auth_data);if (memcmp (ah->auth_data, auth_data, ahp->icv_trunc_len)) {LIMIT_NETDEBUG (printk (KERN_WARNING "ipsec ah authentication error\n" ));
@@ -402,6 +408,8 @@ static int ah6_init_state(struct xfrm_state *x, void *args)if (!ahp->tfm) goto error; ahp->icv = ah_hmac_digest; +if (x->props.flags &XFRM_STATE_ESN ) + ahp->esn =1 ;/* * Lookup the algorithm description maintained by xfrm_algo,
Signature · 1 line
1.5.4.3
Quoted 1 line
From
813d3e12e5f207d037bb1570a35519da77227f0eMon Sep 17 00:00:00 2001
From: Alex Badea <[email protected]>
Date: Mon, 29 Jun 2009 12:29:25 +0300
Subject: [PATCH] xfrm: add test harness for Extended Sequence Numbers replay protection algorithm
--- test/esn/SConstruct | 15 +++ test/esn/harness.c | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/esn/harness.h | 37 ++++++++ 3 files changed, 309 insertions(+), 0 deletions(-) create mode 100644 test/esn/SConstruct create mode 100644 test/esn/harness.c create mode 100644 test/esn/harness.h
test/esn/SConstruct new file +15 -0
@@ -0,0 +1,15 @@ +env = Environment( + CCFLAGS = ['-g', '-Wall', '-Werror', '--include=harness.h'], + LINKFLAGS = ['-g'], + CPPPATH = ['.', '../../src/include'], +) + +env.Append( + CCFLAGS = ['-fprofile-arcs', '-ftest-coverage'], + LINKFLAGS = ['-fprofile-arcs', '-ftest-coverage'], +) + +env.Program('test-esn', [ + 'harness.c', + '../../src/net/xfrm/xfrm_replay.c', +])
test/esn/harness.c new file +257 -0
257 lines not on this page · raw message
test/esn/harness.h new file +37 -0
@@ -0,0 +1,37 @@ +#ifndef _HARNESS_H +#define _HARNESS_H + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <linux/xfrm.h> + +#define printk printf +#define likely (x) x +#define unlikely (x) x +#define BUG () abort() +#define _NET_XFRM_H + +typedef u_int8_t u8 ; +typedef u_int32_t u32 ; +typedef u_int64_t u64 ; + +struct xfrm_state { +struct { +u8 flags; +u8 replay_window; + } props; +struct xfrm_replay_state replay; +struct xfrm_replay_state_ext replay_ext; +struct xfrm_stats stats; +}; + +#define XFRM_STATE_ESN 64 + +extern int xfrm_replay_check (struct xfrm_state *x,u32 seq); +extern u32 xfrm_replay_seqhi (struct xfrm_state *x,u32 seq); +extern void xfrm_replay_advance (struct xfrm_state *x,u32 seq); + +#endif
Signature · 1 line
1.5.4.3
Quoted 7 lines · Alex Badea
A while ago I implemented a rough version of ESN support. It's against an ancient 2.6.7 kernel though, and is only superficially tested.
I suppose there's no reason not to publish them here, if only for historical reasons. My apologies to anyone not interested :)
I'll have a look whether I can use some parts of it, thanks.