From d83027b19bd25835cdfb467f56ac3481d75f7976 Mon Sep 17 00:00:00 2001
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Date: Wed, 23 Mar 2011 11:34:47 +0100
Subject: [PATCH] Contributed by Daniel Kahn Gillmor: * testsuite/Makefile.in
 (TS_NETTLE_SOURCES): Added meta-hash-test.c, meta-cipher-test.c, and
 meta-armor-test.c.

* nettle.texinfo: Document nettle_hashes and nettle_ciphers.

* nettle-meta.h: Declare algorithm lists nettle_ciphers,
nettle_hashes, nettle_armors.

* Makefile.in (nettle_SOURCES): Added nettle-meta-hashes.c,
nettle-meta-ciphers.c, and nettle-meta-armors.c.

* nettle-meta-armors.c: New file.
* nettle-meta-ciphers.c: New file.
* nettle-meta-hashes.c: New file.

Rev: nettle/ChangeLog:1.159
Rev: nettle/Makefile.in:1.32
Rev: nettle/nettle-meta-armors.c:1.1
Rev: nettle/nettle-meta-ciphers.c:1.1
Rev: nettle/nettle-meta-hashes.c:1.1
Rev: nettle/nettle-meta.h:1.10
Rev: nettle/nettle.texinfo:1.22
---
 ChangeLog             | 22 +++++++++++++++++++
 Makefile.in           |  2 ++
 nettle-meta-armors.c  | 34 +++++++++++++++++++++++++++++
 nettle-meta-ciphers.c | 50 +++++++++++++++++++++++++++++++++++++++++++
 nettle-meta-hashes.c  | 40 ++++++++++++++++++++++++++++++++++
 nettle-meta.h         |  9 ++++++++
 nettle.texinfo        | 13 +++++++++++
 7 files changed, 170 insertions(+)
 create mode 100644 nettle-meta-armors.c
 create mode 100644 nettle-meta-ciphers.c
 create mode 100644 nettle-meta-hashes.c

diff --git a/ChangeLog b/ChangeLog
index 13441372..f0f8bf36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2011-03-23  Niels M�ller  <nisse@lysator.liu.se>
+
+	Contributed by Daniel Kahn Gillmor:
+	* testsuite/Makefile.in (TS_NETTLE_SOURCES): Added
+	meta-hash-test.c, meta-cipher-test.c, and meta-armor-test.c.
+
+	* testsuite/meta-hash-test.c: New file.
+	* testsuite/meta-cipher-test.c: New file.
+	* testsuite/meta-armor-test.c: New file.
+
+	* nettle.texinfo: Document nettle_hashes and nettle_ciphers.
+
+	* nettle-meta.h: Declare algorithm lists nettle_ciphers,
+	nettle_hashes, nettle_armors.
+
+	* Makefile.in (nettle_SOURCES): Added nettle-meta-hashes.c,
+	nettle-meta-ciphers.c, and nettle-meta-armors.c.
+
+	* nettle-meta-armors.c: New file.
+	* nettle-meta-ciphers.c: New file.
+	* nettle-meta-hashes.c: New file.
+
 2011-02-18  Niels M�ller  <nisse@lysator.liu.se>
 
 	* arcfour.c (arcfour_stream): Deleted function. It's not very
diff --git a/Makefile.in b/Makefile.in
index 1020fd7b..d71a7127 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -75,6 +75,8 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
 		 twofish.c twofish-meta.c \
 		 yarrow256.c yarrow_key_event.c \
 		 buffer.c buffer-init.c realloc.c \
+		 nettle-meta-hashes.c nettle-meta-ciphers.c \
+		 nettle-meta-armors.c \
 		 nettle-internal.c write-be32.c
 
 hogweed_SOURCES = sexp.c sexp-format.c \
diff --git a/nettle-meta-armors.c b/nettle-meta-armors.c
new file mode 100644
index 00000000..360006d8
--- /dev/null
+++ b/nettle-meta-armors.c
@@ -0,0 +1,34 @@
+/* nettle-meta-armors.c */
+
+/* nettle, low-level cryptographics library
+ *
+ * Copyright (C) 2011 Daniel Kahn Gillmor
+ * 
+ * The nettle library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ * 
+ * The nettle library 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 Lesser General Public
+ * License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the nettle library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stddef.h>
+#include "nettle-meta.h"
+
+const struct nettle_armor * const nettle_armors[] = {
+  &nettle_base64,
+  &nettle_base16,
+  NULL
+};
diff --git a/nettle-meta-ciphers.c b/nettle-meta-ciphers.c
new file mode 100644
index 00000000..1f07595b
--- /dev/null
+++ b/nettle-meta-ciphers.c
@@ -0,0 +1,50 @@
+/* nettle-meta-ciphers.c */
+
+/* nettle, low-level cryptographics library
+ *  
+ * Copyright (C) 2011 Daniel Kahn Gillmor
+ * 
+ * The nettle library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ * 
+ * The nettle library 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 Lesser General Public
+ * License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the nettle library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stddef.h>
+#include "nettle-meta.h"
+
+const struct nettle_cipher * const nettle_ciphers[] = {
+  &nettle_aes128,
+  &nettle_aes192,
+  &nettle_aes256,
+  &nettle_arcfour128,
+  &nettle_camellia128,
+  &nettle_camellia192,
+  &nettle_camellia256,
+  &nettle_cast128,
+  &nettle_serpent128,
+  &nettle_serpent192,
+  &nettle_serpent256,
+  &nettle_twofish128,
+  &nettle_twofish192,
+  &nettle_twofish256,
+  &nettle_arctwo40,
+  &nettle_arctwo64,
+  &nettle_arctwo128,
+  &nettle_arctwo_gutmann128,
+  NULL
+};
diff --git a/nettle-meta-hashes.c b/nettle-meta-hashes.c
new file mode 100644
index 00000000..9007ea1b
--- /dev/null
+++ b/nettle-meta-hashes.c
@@ -0,0 +1,40 @@
+/* nettle-meta-hashes.c */
+
+/* nettle, low-level cryptographics library
+ *  
+ * Copyright (C) 2011 Daniel Kahn Gillmor
+ * 
+ * The nettle library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ * 
+ * The nettle library 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 Lesser General Public
+ * License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the nettle library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stddef.h>
+#include "nettle-meta.h"
+
+const struct nettle_hash * const nettle_hashes[] = {
+  &nettle_md2,
+  &nettle_md4,
+  &nettle_md5,
+  &nettle_sha1,
+  &nettle_sha224,
+  &nettle_sha256,
+  &nettle_sha384,
+  &nettle_sha512,
+  NULL
+};
diff --git a/nettle-meta.h b/nettle-meta.h
index 2a009546..0fbfc031 100644
--- a/nettle-meta.h
+++ b/nettle-meta.h
@@ -96,6 +96,9 @@ struct nettle_cipher
   (nettle_crypt_func *) name##_decrypt,			\
 }
 
+/* null-terminated list of ciphers implemented by this version of nettle */
+extern const struct nettle_cipher * const nettle_ciphers[];
+
 extern const struct nettle_cipher nettle_aes128;
 extern const struct nettle_cipher nettle_aes192;
 extern const struct nettle_cipher nettle_aes256;
@@ -149,6 +152,9 @@ struct nettle_hash
  (nettle_hash_digest_func *) name##_digest	\
 } 
 
+/* null-terminated list of digests implemented by this version of nettle */
+extern const struct nettle_hash * const nettle_hashes[];
+
 extern const struct nettle_hash nettle_md2;
 extern const struct nettle_hash nettle_md4;
 extern const struct nettle_hash nettle_md5;
@@ -207,6 +213,9 @@ struct nettle_armor
   (nettle_armor_decode_final_func *) name##_decode_final,	\
 }
 
+/* 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 nettle_base64;
 extern const struct nettle_armor nettle_base16;
 
diff --git a/nettle.texinfo b/nettle.texinfo
index 797ea069..ec35e255 100644
--- a/nettle.texinfo
+++ b/nettle.texinfo
@@ -683,6 +683,12 @@ The last three attributes are function pointers, of types
 @deftypevrx {Constant Struct} {struct nettle_hash} nettle_sha512
 
 These are all the hash functions that Nettle implements.
+
+Nettle also exports a list of all these hashes.  This list can be used
+to dynamically enumerate or search the supported algorithms:
+
+@deftypevrx {Constant Struct} {struct nettle_hash **} nettle_hashes
+
 @end deftypevr
 
 @node Cipher functions, Cipher modes, Hash functions, Reference
@@ -1330,6 +1336,13 @@ struct, which is of size @code{context_size}.
 
 Nettle includes such structs for all the @emph{regular} ciphers, i.e.
 ones without weak keys or other oddities.
+
+Nettle also exports a list of all these ciphers without weak keys or
+other oddities.  This list can be used to dynamically enumerate or
+search the supported algorithms:
+
+@deftypevrx {Constant Struct} {struct nettle_cipher **} nettle_ciphers
+
 @end deftypevr
 
 @node Cipher modes, Keyed hash functions, Cipher functions, Reference
-- 
GitLab