X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=blobdiff_plain;f=transform-cbcmac.c;h=ca260f013c94bed03216c2e703cbaadf84b8424f;hp=fac8649587e58cb9451bf88317fed943f36ad82a;hb=ce53e0ea9aad729511e8b315dcbed7122272c2a1;hpb=c921f0c57414017ae53f7a14513e8f2188d4a61e diff --git a/transform-cbcmac.c b/transform-cbcmac.c index fac8649..ca260f0 100644 --- a/transform-cbcmac.c +++ b/transform-cbcmac.c @@ -1,5 +1,24 @@ /* Transform module - bulk data transformation */ +/* + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version d of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. + */ + /* For now it's hard-coded to do sequence number/pkcs5/serpent-cbcmac/serpent with a 256 bit key for each instance of serpent. We also require key material for the IVs for @@ -18,26 +37,28 @@ /* 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 +84,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 +250,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 +263,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; } @@ -255,7 +275,7 @@ static list_t *transform_apply(closure_t *self, struct cloc loc, item_t *item; dict_t *dict; - st=safe_malloc(sizeof(*st),"serpent"); + NEW(st); st->cl.description="serpent-cbc256"; st->cl.type=CL_TRANSFORM; st->cl.apply=NULL; @@ -275,8 +295,8 @@ 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); @@ -336,7 +356,7 @@ void transform_cbcmac_module(dict_t *dict) const char *errmsg; int i; - tr = safe_malloc(sizeof(struct transform),"test transform"); + NEW(tr); tr->max_seq_skew = 20; ti = transform_create(tr);