From: Ian Jackson Date: Sun, 8 Dec 2019 13:13:34 +0000 (+0000) Subject: dh: move write_mpbin in to dh.c X-Git-Tag: v0.6.0~21 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=commitdiff_plain;h=ed2b0c2a90657c4f5f1e38ec5bca9d05aef1864a dh: move write_mpbin in to dh.c This function has a hazardous API. In fact, the one call site misuses it, as we shall see in a moment. If we wanted a thing like this with a less hazardous API we probably wouldn't base it on mpz_get_str nowadays. Signed-off-by: Ian Jackson --- diff --git a/dh.c b/dh.c index 0616a43..f94665c 100644 --- a/dh.c +++ b/dh.c @@ -61,6 +61,16 @@ static string_t dh_makepublic(void *sst, uint8_t *secret, int32_t secretlen) return r; } +static int32_t write_mpbin(MP_INT *a, uint8_t *buffer, + int32_t buflen) +{ + char *hb = write_mpstring(a); + int32_t len; + hex_decode(buffer, buflen, &len, hb, True); + free(hb); + return len; +} + static dh_makeshared_fn dh_makeshared; static void dh_makeshared(void *sst, uint8_t *secret, int32_t secretlen, cstring_t rempublic, uint8_t *sharedsecret, diff --git a/util.c b/util.c index cc2f9fa..3e8d56e 100644 --- a/util.c +++ b/util.c @@ -183,15 +183,6 @@ char *write_mpstring(MP_INT *a) return buff; } -int32_t write_mpbin(MP_INT *a, uint8_t *buffer, int32_t buflen) -{ - char *hb = write_mpstring(a); - int32_t len; - hex_decode(buffer, buflen, &len, hb, True); - free(hb); - return len; -} - #define DEFINE_SETFDFLAG(fn,FL,FLAG) \ void fn(int fd) { \ int r=fcntl(fd, F_GET##FL); \ diff --git a/util.h b/util.h index 3929abe..f28a00d 100644 --- a/util.h +++ b/util.h @@ -148,9 +148,6 @@ extern void read_mpbin(MP_INT *a, uint8_t *bin, int binsize); extern char *write_mpstring(MP_INT *a); /* Convert a MP_INT into a hex string */ -extern int32_t write_mpbin(MP_INT *a, uint8_t *buffer, int32_t buflen); - /* Convert a MP_INT into a buffer; return length; truncate if necessary */ - extern struct log_if *init_log(list_t *loglist); extern void send_nak(const struct comm_addr *dest, uint32_t our_index,