X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=blobdiff_plain;f=transform-eax.c;h=04cd0e65d7648b28c4f0afd29437c53d139156de;hp=5c7a1203c41a4dd3159d7513317d229e0d969a8c;hb=147b444d6faa9a621e33d653b7a72c29724203c3;hpb=b02b720ac62afd3a45c44e7ced37c090e7b39da9 diff --git a/transform-eax.c b/transform-eax.c index 5c7a120..04cd0e6 100644 --- a/transform-eax.c +++ b/transform-eax.c @@ -1,6 +1,25 @@ /* * eax-transform.c: EAX-Serpent 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 3 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. + */ +/* * We use EAX with the following parameters: * * Plaintext: @@ -55,7 +74,8 @@ #define SEQLEN 4 struct transform_params { - uint32_t max_seq_skew, tag_length, padding_mask; + SEQNUM_PARAMS_FIELDS; + uint32_t tag_length, padding_mask; }; struct transform { @@ -67,11 +87,9 @@ struct transform { struct transform_inst { struct transform_inst_if ops; struct transform_params p; - unsigned keyed:1; /* remaining valid iff keyed */ unsigned direction:1; - uint32_t sendseq; - uint32_t lastrecvseq; + SEQNUM_KEYED_FIELDS; struct keyInstance key; uint8_t info_b[BLOCK_SIZE], info_p[BLOCK_SIZE]; }; @@ -127,11 +145,10 @@ static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen, TEAX_DEBUG(hash_out+32,8); ti->direction=direction; - ti->sendseq=get_uint32(hash_out+32+direction*4); - ti->lastrecvseq=get_uint32(hash_out+32+!direction*4); serpent_makekey(&ti->key, 32*8, hash_out); eax_setup(ti); - ti->keyed=True; + SEQNUM_KEYED_INIT(get_uint32(hash_out+32+!direction*4), + get_uint32(hash_out+32+direction*4)); return True; } @@ -150,8 +167,8 @@ static void transform_delkey(void *sst) ti->keyed=False; } -static uint32_t transform_forward(void *sst, struct buffer_if *buf, - const char **errmsg) +static transform_apply_return transform_forward(void *sst, + struct buffer_if *buf, const char **errmsg) { struct transform_inst *ti=sst; @@ -179,7 +196,7 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, TEAX_DEBUG(buf->start,buf->size); - memcpy(buf_append(buf,SEQLEN), nonce, SEQLEN); + BUF_ADD_BYTES(append,buf,nonce,SEQLEN); TEAX_DEBUG(nonce,SEQLEN); @@ -188,8 +205,8 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, return 0; } -static uint32_t transform_reverse(void *sst, struct buffer_if *buf, - const char **errmsg) +static transform_apply_return transform_reverse(void *sst, + struct buffer_if *buf, const char **errmsg) { struct transform_inst *ti=sst; @@ -216,7 +233,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, if (!ok) { TEAX_DEBUG(0,0); *errmsg="EAX decryption failed"; - return 1; + return transform_apply_err; } assert(buf->size >= (int)ti->p.tag_length); buf->size -= ti->p.tag_length; @@ -231,7 +248,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, size_t padlen = *padp; if (!buf_unappend(buf,padlen-1)) goto too_short; - SEQNUM_CHECK(seqnum, ti->p.max_seq_skew); + SEQNUM_CHECK(seqnum, &ti->p); TEAX_DEBUG(buf->start,buf->size); @@ -239,7 +256,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, too_short: *errmsg="ciphertext or plaintext too short"; - return 1; + return transform_apply_err; } static struct transform_inst_if *transform_create(void *sst) @@ -260,7 +277,7 @@ static list_t *transform_apply(closure_t *self, struct cloc loc, item_t *item; dict_t *dict; - st=safe_malloc(sizeof(*st),"eax-serpent"); + NEW(st); st->cl.description="eax-serpent"; st->cl.type=CL_TRANSFORM; st->cl.apply=NULL; @@ -273,8 +290,9 @@ static list_t *transform_apply(closure_t *self, struct cloc loc, cfgfatal(loc,"eax-serpent","parameter must be a dictionary\n"); dict=item->data.dict; - st->p.max_seq_skew=dict_read_number(dict, "max-sequence-skew", - False, "eax-serpent", loc, 10); + SET_CAPAB_BIT(CAPAB_BIT_EAXSERPENT); + + SEQNUM_PARAMS_INIT(dict,&st->p,"eax-serpent",loc); st->p.tag_length=dict_read_number(dict, "tag-length-bytes", False, "eax-serpent", loc, 128/8); @@ -292,8 +310,7 @@ static list_t *transform_apply(closure_t *self, struct cloc loc, padding_round = 1; st->p.padding_mask = padding_round-1; - st->ops.max_start_pad=0; - st->ops.max_end_pad= padding_round + st->p.tag_length + SEQLEN; + update_max_start_pad(&transform_max_start_pad, 0); st->ops.keylen=0; st->ops.create=transform_create;