X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=transform-cbcmac.c;h=1390ee884a9ff70eefb5e17b970be05637839033;hp=95c64e859a7abfbaba2839df15e3d7da92fac48b;hb=6b30affc1ec14bf38a73994e8fdd39f26b5bccb3;hpb=5b5f297f9a9d47ee7e9804d5bdaa552f1953c6b6 diff --git a/transform-cbcmac.c b/transform-cbcmac.c index 95c64e8..1390ee8 100644 --- a/transform-cbcmac.c +++ b/transform-cbcmac.c @@ -114,7 +114,7 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, bother sending the IV - it's the same each time. (If we wanted to send it we've have to add 16 bytes to each message, not 4, so that the message stays a multiple of 16 bytes long.) */ - memset(iv,0,16); + FILLZERO(iv); put_uint32(iv, ti->maciv); serpentbe_encrypt(&ti->mackey,iv,macacc); @@ -127,11 +127,11 @@ static uint32_t transform_forward(void *sst, struct buffer_if *buf, serpentbe_encrypt(&ti->mackey,macplain,macacc); } serpentbe_encrypt(&ti->mackey,macacc,macacc); - memcpy(buf_append(buf,16),macacc,16); + BUF_ADD_BYTES(append,buf,macacc,16); /* Serpent-CBC. We expand the ID as for CBCMAC, do the encryption, and prepend the IV before increasing it. */ - memset(iv,0,16); + FILLZERO(iv); put_uint32(iv, ti->cryptiv); serpentbe_encrypt(&ti->cryptkey,iv,iv); @@ -175,7 +175,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, } /* CBC */ - memset(iv,0,16); + FILLZERO(iv); { uint32_t ivword = buf_unprepend_uint32(buf); put_uint32(iv, ivword); @@ -193,12 +193,12 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf, serpentbe_decrypt(&ti->cryptkey,n,n); for (i = 0; i < 16; i++) n[i] ^= iv[i]; - memcpy(iv, pct, 16); + COPY_OBJ(iv, pct); } /* CBCMAC */ macexpected=buf_unappend(buf,16); - memset(iv,0,16); + FILLZERO(iv); put_uint32(iv, ti->maciv); serpentbe_encrypt(&ti->mackey,iv,macacc); @@ -261,8 +261,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 */ @@ -344,7 +344,7 @@ void transform_cbcmac_module(dict_t *dict) buf.base = malloc(4096); buffer_init(&buf, 2048); - memcpy(buf_append(&buf, sizeof(text)), text, sizeof(text)); + BUF_ADD_OBJ(append, buf, text, sizeof(text)); if (transform_forward(ti, &buf, &errmsg)) { fatal("transform_forward test: %s", errmsg); }