+2017-01-12 Niels Möller <nisse@lysator.liu.se>
+
+ * nettle-meta.h (nettle_hashes): New macro, expanding to a call to
+ nettle_get_hashes. Direct access to the array causes the array
+ size to leak into the ABI, since a plain un-relocatable executable
+ linking with libnettle.so gets copy relocations for any referenced
+ data items in the shared library.
+
+ * nettle-meta-hashes.c (_nettle_hashes): Renamed array, from...
+ (nettle_hashes): ... old name.
+ (nettle_get_hashes): New function.
+
2016-10-10 Niels Möller <nisse@lysator.liu.se>
* write-be32.c (_nettle_write_be32): Use const for source argument.
md2.c md2-meta.c md4.c md4-meta.c \
md5.c md5-compress.c md5-compat.c md5-meta.c \
memeql-sec.c memxor.c memxor3.c \
+ nettle-lookup-hash.c \
nettle-meta-aeads.c nettle-meta-armors.c \
nettle-meta-ciphers.c nettle-meta-hashes.c \
pbkdf2.c pbkdf2-hmac-sha1.c pbkdf2-hmac-sha256.c \
--- /dev/null
+/* nettle-lookup-hash.c
+
+ Copyright (C) 2016 Niels Möller.
+
+ This file is part of GNU Nettle.
+
+ GNU Nettle is free software: you can redistribute it and/or
+ modify it under the terms of either:
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ or both in parallel, as here.
+
+ GNU Nettle is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see http://www.gnu.org/licenses/.
+*/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stddef.h>
+#include <string.h>
+
+#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)
+{
+ unsigned i;
+ for (i = 0; nettle_hashes[i]; i++)
+ if (!strcmp (name, nettle_hashes[i]->name))
+ return nettle_hashes[i];
+ return NULL;
+}
#endif
#include <stddef.h>
+
#include "nettle-meta.h"
-const struct nettle_hash * const nettle_hashes[] = {
+const struct nettle_hash * const _nettle_hashes[] = {
&nettle_md2,
&nettle_md4,
&nettle_md5,
&nettle_sha3_512,
NULL
};
+
+const struct nettle_hash * const *
+nettle_get_hashes (void)
+{
+ return _nettle_hashes;
+}
}
/* 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__
+__attribute__((pure))
+#endif
+nettle_get_hashes (void);
+
+#define nettle_hashes (nettle_get_hashes())
+
+const struct nettle_hash *
+nettle_lookup_hash (const char *name);
extern const struct nettle_hash nettle_md2;
extern const struct nettle_hash nettle_md4;