[PATCH 18/25] transform: Pass a direction flag to the transform

Ian Jackson ijackson at chiark.greenend.org.uk
Sat Jul 20 00:39:02 BST 2013


The same transform is used for inbound and outbound packets.

The transform should know which direction these packets are flowing
in; that (a) allows a transform to reject packets which are "looping
back" so to speak, and (b) makes it easier for a transform to generate
unique nonces.

This will be used by the forthcoming EAX transform.  It is combined
with the sequence number (the same values of which are used by both
ends) to make the nonce, which must be unique across the single shared
key, ie unique across both flows.

Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
 secnet.h           |    7 +++++--
 site.c             |    4 ++--
 transform-cbcmac.c |    3 ++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/secnet.h b/secnet.h
index 23d62ba..6ad8fc9 100644
--- a/secnet.h
+++ b/secnet.h
@@ -383,10 +383,13 @@ struct site_if {
    also depend on internal factors (eg. time) and keep internal
    state. A struct transform_if only represents a particular type of
    transformation; instances of the transformation (eg. with
-   particular key material) have a different C type. */
+   particular key material) have a different C type. The same
+   secret key will be used in opposite directions between a pair of
+   secnets; one of these pairs will get direction==False, the other True. */
 
 typedef struct transform_inst_if *transform_createinstance_fn(void *st);
-typedef bool_t transform_setkey_fn(void *st, uint8_t *key, int32_t keylen);
+typedef bool_t transform_setkey_fn(void *st, uint8_t *key, int32_t keylen,
+				   bool_t direction);
 typedef bool_t transform_valid_fn(void *st); /* 0: no key; 1: ok */
 typedef void transform_delkey_fn(void *st);
 typedef void transform_destroyinstance_fn(void *st);
diff --git a/site.c b/site.c
index a0416d8..5042af5 100644
--- a/site.c
+++ b/site.c
@@ -642,7 +642,7 @@ static bool_t process_msg3(struct site *st, struct buffer_if *msg3,
 
     /* Set up the transform */
     st->new_transform->setkey(st->new_transform->st,st->sharedsecret,
-			      st->sharedsecretlen);
+			      st->sharedsecretlen,st->setup_priority);
 
     return True;
 }
@@ -689,7 +689,7 @@ static bool_t process_msg4(struct site *st, struct buffer_if *msg4,
 		       st->sharedsecret,st->sharedsecretlen);
     /* Set up the transform */
     st->new_transform->setkey(st->new_transform->st,st->sharedsecret,
-			      st->sharedsecretlen);
+			      st->sharedsecretlen,st->setup_priority);
 
     return True;
 }
diff --git a/transform-cbcmac.c b/transform-cbcmac.c
index 7b97ce9..b163d33 100644
--- a/transform-cbcmac.c
+++ b/transform-cbcmac.c
@@ -39,7 +39,8 @@ struct transform_inst {
 
 #define PKCS5_MASK 15
 
-static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen)
+static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen,
+			       bool_t direction)
 {
     struct transform_inst *ti=sst;
 
-- 
1.7.2.5




More information about the sgo-software-discuss mailing list