Replace various calls to memcpy and memset with equivalent calls to
these macros.
There are still a couple of open-coded memcpy(,buf_unprepend(),)
in udp.c's proxy code which will be done later.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
len=netlink_icmp_reply_len(buf);
h=netlink_icmp_tmpl(st,icmpsource,icmpdest,len);
h->type=type; h->code=code; h->d=info;
len=netlink_icmp_reply_len(buf);
h=netlink_icmp_tmpl(st,icmpsource,icmpdest,len);
h->type=type; h->code=code; h->d=info;
- memcpy(buf_append(&st->icmp,len),buf->start,len);
+ BUF_ADD_BYTES(append,&st->icmp,buf->start,len);
netlink_icmp_csum(h);
if (!st->ptp) {
netlink_icmp_csum(h);
if (!st->ptp) {
long avail = mtu - hl;
long remain = endindata - indata;
long use = avail < remain ? (avail & ~(long)7) : remain;
long avail = mtu - hl;
long remain = endindata - indata;
long use = avail < remain ? (avail & ~(long)7) : remain;
- memcpy(buf_append(buf, use), indata, use);
+ BUF_ADD_BYTES(append, buf, indata, use);
indata += use;
_Bool last_frag = indata >= endindata;
indata += use;
_Bool last_frag = indata >= endindata;
append_string_xinfo_done(&st->buffer,&xia);
buf_append_string(&st->buffer,st->remotename);
append_string_xinfo_done(&st->buffer,&xia);
buf_append_string(&st->buffer,st->remotename);
- memcpy(buf_append(&st->buffer,NONCELEN),st->localN,NONCELEN);
+ BUF_ADD_OBJ(append,&st->buffer,st->localN);
if (type==LABEL_MSG1) return True;
if (type==LABEL_MSG1) return True;
- memcpy(buf_append(&st->buffer,NONCELEN),st->remoteN,NONCELEN);
+ BUF_ADD_OBJ(append,&st->buffer,st->remoteN);
if (type==LABEL_MSG2) return True;
if (hacky_par_mid_failnow()) return False;
if (type==LABEL_MSG2) return True;
if (hacky_par_mid_failnow()) return False;
st->setup_session_id=0;
transport_peers_clear(st,&st->setup_peers);
st->setup_session_id=0;
transport_peers_clear(st,&st->setup_peers);
- memset(st->localN,0,NONCELEN);
- memset(st->remoteN,0,NONCELEN);
+ FILLZERO(st->localN);
+ FILLZERO(st->remoteN);
dispose_transform(&st->new_transform);
memset(st->dhsecret,0,st->dh->len);
memset(st->sharedsecret,0,st->sharedsecretlen);
dispose_transform(&st->new_transform);
memset(st->dhsecret,0,st->dh->len);
memset(st->sharedsecret,0,st->sharedsecretlen);
static void transport_peers_copy(struct site *st, transport_peers *dst,
const transport_peers *src) {
dst->npeers=src->npeers;
static void transport_peers_copy(struct site *st, transport_peers *dst,
const transport_peers *src) {
dst->npeers=src->npeers;
- memcpy(dst->peers, src->peers, sizeof(*dst->peers) * dst->npeers);
+ COPY_ARRAY(dst->peers, src->peers, dst->npeers);
transport_peers_debug(st,dst,"copy",
src->npeers, &src->peers->addr, sizeof(*src->peers));
}
transport_peers_debug(st,dst,"copy",
src->npeers, &src->peers->addr, sizeof(*src->peers));
}
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.) */
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.) */
put_uint32(iv, ti->maciv);
serpentbe_encrypt(&ti->mackey,iv,macacc);
put_uint32(iv, ti->maciv);
serpentbe_encrypt(&ti->mackey,iv,macacc);
serpentbe_encrypt(&ti->mackey,macplain,macacc);
}
serpentbe_encrypt(&ti->mackey,macacc,macacc);
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. */
/* Serpent-CBC. We expand the ID as for CBCMAC, do the encryption,
and prepend the IV before increasing it. */
put_uint32(iv, ti->cryptiv);
serpentbe_encrypt(&ti->cryptkey,iv,iv);
put_uint32(iv, ti->cryptiv);
serpentbe_encrypt(&ti->cryptkey,iv,iv);
{
uint32_t ivword = buf_unprepend_uint32(buf);
put_uint32(iv, ivword);
{
uint32_t ivword = buf_unprepend_uint32(buf);
put_uint32(iv, ivword);
serpentbe_decrypt(&ti->cryptkey,n,n);
for (i = 0; i < 16; i++)
n[i] ^= iv[i];
serpentbe_decrypt(&ti->cryptkey,n,n);
for (i = 0; i < 16; i++)
n[i] ^= iv[i];
}
/* CBCMAC */
macexpected=buf_unappend(buf,16);
}
/* CBCMAC */
macexpected=buf_unappend(buf,16);
put_uint32(iv, ti->maciv);
serpentbe_encrypt(&ti->mackey,iv,macacc);
put_uint32(iv, ti->maciv);
serpentbe_encrypt(&ti->mackey,iv,macacc);
buf.base = malloc(4096);
buffer_init(&buf, 2048);
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);
}
if (transform_forward(ti, &buf, &errmsg)) {
fatal("transform_forward test: %s", errmsg);
}
TEAX_DEBUG(buf->start,buf->size);
TEAX_DEBUG(buf->start,buf->size);
- memcpy(buf_append(buf,SEQLEN), nonce, SEQLEN);
+ BUF_ADD_BYTES(append,buf,nonce,SEQLEN);
TEAX_DEBUG(nonce,SEQLEN);
TEAX_DEBUG(nonce,SEQLEN);
len=strlen(s);
/* fixme: if string is longer than 65535, result is a corrupted packet */
buf_append_uint16(buf,len);
len=strlen(s);
/* fixme: if string is longer than 65535, result is a corrupted packet */
buf_append_uint16(buf,len);
- memcpy(buf_append(buf,len),s,len);
+ BUF_ADD_BYTES(append,buf,s,len);
}
void buffer_new(struct buffer_if *buf, int32_t len)
}
void buffer_new(struct buffer_if *buf, int32_t len)