-/* $OpenBSD: sync.c,v 1.23 2017/02/13 23:04:05 krw Exp $ */
+/* $OpenBSD: sync.c,v 1.24 2022/01/05 11:01:59 tb Exp $ */
/*
* Copyright (c) 2008 Bob Beck <beck@openbsd.org>
char pad[DHCP_ALIGNBYTES];
u_int16_t leaselen, padlen;
int i = 0;
- HMAC_CTX ctx;
+ HMAC_CTX *ctx;
u_int hmac_len;
if (sync_key == NULL)
memset(&lv, 0, sizeof(lv));
memset(&pad, 0, sizeof(pad));
- HMAC_CTX_init(&ctx);
- HMAC_Init(&ctx, sync_key, strlen(sync_key), EVP_sha1());
+ if ((ctx = HMAC_CTX_new()) == NULL)
+ goto bad;
+ if (!HMAC_Init_ex(ctx, sync_key, strlen(sync_key), EVP_sha1(), NULL))
+ goto bad;
leaselen = sizeof(lv);
padlen = DHCP_ALIGN(leaselen) - leaselen;
hdr.sh_length = htons(sizeof(hdr) + sizeof(lv) + padlen + sizeof(end));
iov[i].iov_base = &hdr;
iov[i].iov_len = sizeof(hdr);
- HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
+ if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len))
+ goto bad;
i++;
/* Add single DHCP sync address entry */
piaddr(lease->ip_addr), ntohl(lv.lv_starts), ntohl(lv.lv_ends));
iov[i].iov_base = &lv;
iov[i].iov_len = sizeof(lv);
- HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
+ if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len))
+ goto bad;
i++;
iov[i].iov_base = pad;
iov[i].iov_len = padlen;
- HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
+ if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len))
+ goto bad;
i++;
/* Add end marker */
end.st_length = htons(sizeof(end));
iov[i].iov_base = &end;
iov[i].iov_len = sizeof(end);
- HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
+ if (!HMAC_Update(ctx, iov[i].iov_base, iov[i].iov_len))
+ goto bad;
i++;
- HMAC_Final(&ctx, hdr.sh_hmac, &hmac_len);
+ if (!HMAC_Final(ctx, hdr.sh_hmac, &hmac_len))
+ goto bad;
/* Send message to the target hosts */
sync_send(iov, i);
- HMAC_CTX_cleanup(&ctx);
+
+ bad:
+ HMAC_CTX_free(ctx);
}