From 54e1450a0ebdd24cdf6234741e5275bb3d83ebda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Mon, 23 Oct 2017 22:05:32 +0200
Subject: [PATCH] Undo added underscores on public symbols.

---
 ChangeLog                |  4 ++++
 ecc-192.c                |  4 ++--
 ecc-224.c                |  4 ++--
 ecc-256.c                |  4 ++--
 ecc-384.c                |  4 ++--
 ecc-521.c                |  4 ++--
 ecc-internal.h           | 19 ++++++++++++++-----
 examples/ecc-benchmark.c | 10 +++++-----
 nettle-lookup-hash.c     |  2 --
 nettle-meta-aeads.c      |  6 ++++--
 nettle-meta-armors.c     |  6 ++++--
 nettle-meta-ciphers.c    |  6 ++++--
 nettle-meta-hashes.c     |  6 ++++--
 nettle-meta.h            | 20 ++++++++++++++++----
 testsuite/Makefile.in    |  5 +++--
 testsuite/testutils.c    | 10 +++++-----
 16 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9a407deb..cf37b0b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-10-23  Niels Möller  <nisse@lysator.liu.se>
+
+	Undo added underscores on public symbols.
+
 2017-04-09  Niels Möller  <nisse@lysator.liu.se>
 
 	* ecc-curve.h (nettle_get_secp_192r1, nettle_get_secp_224r1)
diff --git a/ecc-192.c b/ecc-192.c
index 4f428113..57a7650b 100644
--- a/ecc-192.c
+++ b/ecc-192.c
@@ -110,7 +110,7 @@ ecc_192_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
 #define ecc_192_modp ecc_mod
 #endif
 
-const struct ecc_curve _nettle_secp_192r1 =
+const struct ecc_curve nettle_secp_192r1 =
 {
   {
     192,
@@ -174,5 +174,5 @@ const struct ecc_curve _nettle_secp_192r1 =
 
 const struct ecc_curve *nettle_get_secp_192r1(void)
 {
-  return &_nettle_secp_192r1;
+  return &nettle_secp_192r1;
 }
diff --git a/ecc-224.c b/ecc-224.c
index 5962e1b8..f665db60 100644
--- a/ecc-224.c
+++ b/ecc-224.c
@@ -62,7 +62,7 @@ ecc_224_modp (const struct ecc_modulo *m, mp_limb_t *rp);
 # error Configuration error
 #endif
 
-const struct ecc_curve _nettle_secp_224r1 =
+const struct ecc_curve nettle_secp_224r1 =
 {
   {
     224,
@@ -126,5 +126,5 @@ const struct ecc_curve _nettle_secp_224r1 =
 
 const struct ecc_curve *nettle_get_secp_224r1(void)
 {
-  return &_nettle_secp_224r1;
+  return &nettle_secp_224r1;
 }
diff --git a/ecc-256.c b/ecc-256.c
index 7eed2835..bf5b6b8e 100644
--- a/ecc-256.c
+++ b/ecc-256.c
@@ -239,7 +239,7 @@ ecc_256_modq (const struct ecc_modulo *q, mp_limb_t *rp)
 #error Unsupported parameters
 #endif
 
-const struct ecc_curve _nettle_secp_256r1 =
+const struct ecc_curve nettle_secp_256r1 =
 {
   {
     256,
@@ -303,5 +303,5 @@ const struct ecc_curve _nettle_secp_256r1 =
 
 const struct ecc_curve *nettle_get_secp_256r1(void)
 {
-  return &_nettle_secp_256r1;
+  return &nettle_secp_256r1;
 }
diff --git a/ecc-384.c b/ecc-384.c
index 94b8af91..cba0178a 100644
--- a/ecc-384.c
+++ b/ecc-384.c
@@ -147,7 +147,7 @@ ecc_384_modp (const struct ecc_modulo *p, mp_limb_t *rp)
 #define ecc_384_modp ecc_mod
 #endif
   
-const struct ecc_curve _nettle_secp_384r1 =
+const struct ecc_curve nettle_secp_384r1 =
 {
   {
     384,
@@ -211,5 +211,5 @@ const struct ecc_curve _nettle_secp_384r1 =
 
 const struct ecc_curve *nettle_get_secp_384r1(void)
 {
-  return &_nettle_secp_384r1;
+  return &nettle_secp_384r1;
 }
diff --git a/ecc-521.c b/ecc-521.c
index 52a018dd..39a18714 100644
--- a/ecc-521.c
+++ b/ecc-521.c
@@ -75,7 +75,7 @@ ecc_521_modp (const struct ecc_modulo *m UNUSED, mp_limb_t *rp)
 }
 #endif
 
-const struct ecc_curve _nettle_secp_521r1 =
+const struct ecc_curve nettle_secp_521r1 =
 {
   {
     521,
@@ -139,5 +139,5 @@ const struct ecc_curve _nettle_secp_521r1 =
 
 const struct ecc_curve *nettle_get_secp_521r1(void)
 {
-  return &_nettle_secp_521r1;
+  return &nettle_secp_521r1;
 }
diff --git a/ecc-internal.h b/ecc-internal.h
index 94fc218b..4b45199f 100644
--- a/ecc-internal.h
+++ b/ecc-internal.h
@@ -73,11 +73,20 @@
 #define sec_modinv _nettle_sec_modinv
 #define curve25519_eh_to_x _nettle_curve25519_eh_to_x
 
-extern const struct ecc_curve _nettle_secp_192r1;
-extern const struct ecc_curve _nettle_secp_224r1;
-extern const struct ecc_curve _nettle_secp_256r1;
-extern const struct ecc_curve _nettle_secp_384r1;
-extern const struct ecc_curve _nettle_secp_521r1;
+/* FIXME: Rename with leading underscore, but keep current name (and
+   size!) for now, for ABI compatibility with nettle-3.1, soname
+   libhogweed.so.4. */
+#undef nettle_secp_192r1
+#undef nettle_secp_224r1
+#undef nettle_secp_256r1
+#undef nettle_secp_384r1
+#undef nettle_secp_521r1
+
+extern const struct ecc_curve nettle_secp_192r1;
+extern const struct ecc_curve nettle_secp_224r1;
+extern const struct ecc_curve nettle_secp_256r1;
+extern const struct ecc_curve nettle_secp_384r1;
+extern const struct ecc_curve nettle_secp_521r1;
 
 /* Keep this structure internal for now. It's misnamed (since it's
    really implementing the equivalent twisted Edwards curve, with
diff --git a/examples/ecc-benchmark.c b/examples/ecc-benchmark.c
index ea0be173..8e5e0953 100644
--- a/examples/ecc-benchmark.c
+++ b/examples/ecc-benchmark.c
@@ -330,12 +330,12 @@ bench_curve (const struct ecc_curve *ecc)
 }
 
 const struct ecc_curve * const curves[] = {
-  &_nettle_secp_192r1,
-  &_nettle_secp_224r1,
+  &nettle_secp_192r1,
+  &nettle_secp_224r1,
   &_nettle_curve25519,
-  &_nettle_secp_256r1,
-  &_nettle_secp_384r1,
-  &_nettle_secp_521r1,
+  &nettle_secp_256r1,
+  &nettle_secp_384r1,
+  &nettle_secp_521r1,
 };
 
 #define numberof(x)  (sizeof (x) / sizeof ((x)[0]))
diff --git a/nettle-lookup-hash.c b/nettle-lookup-hash.c
index adf9188b..98cd4ae2 100644
--- a/nettle-lookup-hash.c
+++ b/nettle-lookup-hash.c
@@ -38,9 +38,7 @@
 
 #include "nettle-meta.h"
 
-/* Direct access to the array. */
 #undef nettle_hashes
-#define nettle_hashes _nettle_hashes
 
 const struct nettle_hash *
 nettle_lookup_hash (const char *name)
diff --git a/nettle-meta-aeads.c b/nettle-meta-aeads.c
index c99cc465..51866b6d 100644
--- a/nettle-meta-aeads.c
+++ b/nettle-meta-aeads.c
@@ -37,7 +37,9 @@
 
 #include "nettle-meta.h"
 
-const struct nettle_aead * const _nettle_aeads[] = {
+#undef nettle_aeads
+
+const struct nettle_aead * const nettle_aeads[] = {
   &nettle_gcm_aes128,
   &nettle_gcm_aes192,
   &nettle_gcm_aes256,
@@ -51,5 +53,5 @@ const struct nettle_aead * const _nettle_aeads[] = {
 const struct nettle_aead * const *
 nettle_get_aeads (void)
 {
-  return _nettle_aeads;
+  return nettle_aeads;
 }
diff --git a/nettle-meta-armors.c b/nettle-meta-armors.c
index 17f87fce..b8a81bc2 100644
--- a/nettle-meta-armors.c
+++ b/nettle-meta-armors.c
@@ -36,7 +36,9 @@
 #include <stddef.h>
 #include "nettle-meta.h"
 
-const struct nettle_armor * const _nettle_armors[] = {
+#undef nettle_armors
+
+const struct nettle_armor * const nettle_armors[] = {
   &nettle_base64,
   &nettle_base64url,
   &nettle_base16,
@@ -46,5 +48,5 @@ const struct nettle_armor * const _nettle_armors[] = {
 const struct nettle_armor * const *
 nettle_get_armors (void)
 {
-  return _nettle_armors;
+  return nettle_armors;
 }
diff --git a/nettle-meta-ciphers.c b/nettle-meta-ciphers.c
index 49cb47a7..ef905d8e 100644
--- a/nettle-meta-ciphers.c
+++ b/nettle-meta-ciphers.c
@@ -36,7 +36,9 @@
 #include <stddef.h>
 #include "nettle-meta.h"
 
-const struct nettle_cipher * const _nettle_ciphers[] = {
+#undef nettle_ciphers
+
+const struct nettle_cipher * const nettle_ciphers[] = {
   &nettle_aes128,
   &nettle_aes192,
   &nettle_aes256,
@@ -60,5 +62,5 @@ const struct nettle_cipher * const _nettle_ciphers[] = {
 const struct nettle_cipher * const *
 nettle_get_ciphers (void)
 {
-  return _nettle_ciphers;
+  return nettle_ciphers;
 }
diff --git a/nettle-meta-hashes.c b/nettle-meta-hashes.c
index 37552ede..5df6f794 100644
--- a/nettle-meta-hashes.c
+++ b/nettle-meta-hashes.c
@@ -37,7 +37,9 @@
 
 #include "nettle-meta.h"
 
-const struct nettle_hash * const _nettle_hashes[] = {
+#undef nettle_hashes
+
+const struct nettle_hash * const nettle_hashes[] = {
   &nettle_md2,
   &nettle_md4,
   &nettle_md5,
@@ -57,5 +59,5 @@ const struct nettle_hash * const _nettle_hashes[] = {
 const struct nettle_hash * const *
 nettle_get_hashes (void)
 {
-  return _nettle_hashes;
+  return nettle_hashes;
 }
diff --git a/nettle-meta.h b/nettle-meta.h
index 3c13e9b2..0d16a2b8 100644
--- a/nettle-meta.h
+++ b/nettle-meta.h
@@ -60,8 +60,11 @@ struct nettle_cipher
   nettle_cipher_func *decrypt;
 };
 
+/* FIXME: Rename with leading underscore, but keep current name (and
+   size!) for now, for ABI compatibility with nettle-3.1, soname
+   libnettle.so.6. */
 /* null-terminated list of ciphers implemented by this version of nettle */
-extern const struct nettle_cipher * const _nettle_ciphers[];
+extern const struct nettle_cipher * const nettle_ciphers[];
 
 const struct nettle_cipher * const *
 #ifdef __GNUC__
@@ -122,8 +125,11 @@ struct nettle_hash
  (nettle_hash_digest_func *) name##_digest	\
 } 
 
+/* FIXME: Rename with leading underscore, but keep current name (and
+   size!) for now, for ABI compatibility with nettle-3.1, soname
+   libnettle.so.6. */
 /* null-terminated list of digests implemented by this version of nettle */
-extern const struct nettle_hash * const _nettle_hashes[];
+extern const struct nettle_hash * const nettle_hashes[];
 
 const struct nettle_hash * const *
 #ifdef __GNUC__
@@ -174,9 +180,12 @@ struct nettle_aead
   nettle_hash_digest_func *digest;
 };
 
+/* FIXME: Rename with leading underscore, but keep current name (and
+   size!) for now, for ABI compatibility with nettle-3.1, soname
+   libnettle.so.6. */
 /* null-terminated list of aead constructions implemented by this
    version of nettle */
-extern const struct nettle_aead * const _nettle_aeads[];
+extern const struct nettle_aead * const nettle_aeads[];
 
 const struct nettle_aead * const *
 #ifdef __GNUC__
@@ -243,8 +252,11 @@ struct nettle_armor
   (nettle_armor_decode_final_func *) name##_decode_final,	\
 }
 
+/* FIXME: Rename with leading underscore, but keep current name (and
+   size!) for now, for ABI compatibility with nettle-3.1, soname
+   libnettle.so.6. */
 /* null-terminated list of armor schemes implemented by this version of nettle */
-extern const struct nettle_armor * const _nettle_armors[];
+extern const struct nettle_armor * const nettle_armors[];
 
 const struct nettle_armor * const *
 #ifdef __GNUC__
diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in
index 689d4325..790b3c78 100644
--- a/testsuite/Makefile.in
+++ b/testsuite/Makefile.in
@@ -121,9 +121,10 @@ $(TARGETS) $(EXTRA_TARGETS): testutils.$(OBJEXT) ../nettle-internal.$(OBJEXT) \
 # data.
 VALGRIND = valgrind --error-exitcode=1 --leak-check=full --show-reachable=yes @IF_ASM@ --partial-loads-ok=yes
 
-# The PATH update is for locating dlls on w*ndows.
+# The PATH update is for windows dlls, DYLD_LIBRARY_PATH is for OSX.
 check: $(TS_ALL)
-	LD_LIBRARY_PATH=../.lib PATH="../.lib:$$PATH" srcdir="$(srcdir)" \
+	LD_LIBRARY_PATH=../.lib PATH="../.lib:$$PATH" DYLD_LIBRARY_PATH=../.lib \
+	  srcdir="$(srcdir)" \
 	  EMULATOR="$(EMULATOR)" NM="$(NM)" EXEEXT="$(EXEEXT)" \
           $(top_srcdir)/run-tests $(TS_ALL)
 
diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index 7a23a46d..6f897617 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -1212,11 +1212,11 @@ test_dsa_key(const struct dsa_params *params,
 }
 
 const struct ecc_curve * const ecc_curves[] = {
-  &_nettle_secp_192r1,
-  &_nettle_secp_224r1,
-  &_nettle_secp_256r1,
-  &_nettle_secp_384r1,
-  &_nettle_secp_521r1,
+  &nettle_secp_192r1,
+  &nettle_secp_224r1,
+  &nettle_secp_256r1,
+  &nettle_secp_384r1,
+  &nettle_secp_521r1,
   &_nettle_curve25519,
   NULL
 };
-- 
GitLab