]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
New functions nettle_get_hashes and nettle_lookup_hash.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 12 Jan 2017 20:54:38 +0000 (21:54 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 12 Jan 2017 20:54:38 +0000 (21:54 +0100)
ChangeLog
Makefile.in
nettle-lookup-hash.c [new file with mode: 0644]
nettle-meta-hashes.c
nettle-meta.h

index cf860feebe17a78e05781440cf8ba59b114cd751..29b04c016ba9993b56bdf026e463c60aa9b48c8d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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.
index 135542f588df50170e29c978dc7d94cc89c75484..5288662290bffb45b120136146d0a0a5b8aa219d 100644 (file)
@@ -110,6 +110,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
                 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 \
diff --git a/nettle-lookup-hash.c b/nettle-lookup-hash.c
new file mode 100644 (file)
index 0000000..adf9188
--- /dev/null
@@ -0,0 +1,53 @@
+/* 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;
+}
index 2220968c070b41e2e27cfd9d735f693656543e55..37552edec5caca37a8bd43e7e4734205cb78e7eb 100644 (file)
 #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,
@@ -52,3 +53,9 @@ const struct nettle_hash * const nettle_hashes[] = {
   &nettle_sha3_512,
   NULL
 };
+
+const struct nettle_hash * const *
+nettle_get_hashes (void)
+{
+  return _nettle_hashes;
+}
index 14b5e48ed0c166c1fa30059f5c1235c69127c4d4..fd1667172c7602d1b309dde4669282caac5b3423 100644 (file)
@@ -115,7 +115,18 @@ struct nettle_hash
 } 
 
 /* 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;