chiark / gitweb /
test-example: Provide a polypath test
[secnet.git] / transform-cbcmac.c
index 69201654da6f9e7c6e80f297f2b92e501f038c15..e371659fc0715dc5d7b79ceabc0f354763c345fa 100644 (file)
 /* Required key length in bytes */
 #define REQUIRED_KEYLEN ((512+64+32)/8)
 
+#include "transform-common.h"
+
+struct transform_params {
+    SEQNUM_PARAMS_FIELDS;
+};
+
 struct transform {
     closure_t cl;
     struct transform_if ops;
-    uint32_t max_seq_skew;
+    struct transform_params p;
 };
 
 struct transform_inst {
     struct transform_inst_if ops;
+    struct transform_params p;
     struct keyInstance cryptkey;
     struct keyInstance mackey;
     uint32_t cryptiv;
     uint32_t maciv;
-    uint32_t sendseq;
-    uint32_t lastrecvseq;
-    uint32_t max_skew;
-    bool_t keyed;
+    SEQNUM_KEYED_FIELDS;
 };
 
-#include "transform-common.h"
-
 #define PKCS5_MASK 15
 
 static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen,
@@ -63,9 +65,8 @@ static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen,
     serpentbe_makekey(&ti->mackey,256,key+32);
     ti->cryptiv=get_uint32(key+64);
     ti->maciv=get_uint32(key+68);
-    ti->sendseq=get_uint32(key+72);
-    ti->lastrecvseq=ti->sendseq;
-    ti->keyed=True;
+    uint32_t firstseq=get_uint32(key+72);
+    SEQNUM_KEYED_INIT(firstseq,firstseq);
 
     return True;
 }
@@ -230,7 +231,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf,
     /* Sequence number must be within max_skew of lastrecvseq; lastrecvseq
        is only allowed to increase. */
     seqnum=buf_unprepend_uint32(buf);
-    SEQNUM_CHECK(seqnum, ti->max_skew);
+    SEQNUM_CHECK(seqnum, &ti->p);
     
     return 0;
 }
@@ -243,7 +244,7 @@ static struct transform_inst_if *transform_create(void *sst)
 
     TRANSFORM_CREATE_CORE;
 
-    ti->max_skew=st->max_seq_skew;
+    ti->p=st->p;
 
     return &ti->ops;
 }
@@ -261,8 +262,8 @@ static list_t *transform_apply(closure_t *self, struct cloc loc,
     st->cl.apply=NULL;
     st->cl.interface=&st->ops;
     st->ops.st=st;
-    st->ops.max_start_pad=28; /* 4byte seqnum, 16byte pad, 4byte MACIV,
-                                4byte IV */
+    update_max_start_pad(&transform_max_start_pad, 28);
+        /* 4byte seqnum, 16byte pad, 4byte MACIV, 4byte IV */
 
     /* We need 256*2 bits for serpent keys, 32 bits for CBC-IV and 32 bits
        for CBCMAC-IV, and 32 bits for init sequence number */
@@ -275,8 +276,10 @@ static list_t *transform_apply(closure_t *self, struct cloc loc,
        cfgfatal(loc,"userv-ipif","parameter must be a dictionary\n");
     
     dict=item->data.dict;
-    st->max_seq_skew=dict_read_number(dict, "max-sequence-skew",
-                                     False, "serpent-cbc256", loc, 10);
+
+    SEQNUM_PARAMS_INIT(dict,&st->p,"serpent-cbc256",loc);
+
+    SET_CAPAB_TRANSFORMNUM(CAPAB_TRANSFORMNUM_SERPENT256CBC);
 
     return new_closure(&st->cl);
 }