chiark / gitweb /
dh: move write_mpbin in to dh.c
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Dec 2019 13:13:34 +0000 (13:13 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:54 +0000 (21:56 +0000)
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 <ijackson@chiark.greenend.org.uk>
dh.c
util.c
util.h

diff --git a/dh.c b/dh.c
index 0616a43e4007dc330137431cbf8908b34823861c..f94665c9b52637fd4fda9988da612214a2e539df 100644 (file)
--- 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 cc2f9fa6b17f2ce43fe0cf5760ed550ed0d1f040..3e8d56eaebbc50855ed2cde7026b5bf5be7c0767 100644 (file)
--- 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 3929abe366b90365bca126fa917f83df0b7dd587..f28a00da7c538823e22957cbf52f06cf121a811b 100644 (file)
--- 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,