Hi Nettle folks--
In the course of writing Crypt::Nettle, it occurs to me that i'm going
to need to update the list of available ciphers and digests for each new
version of nettle that comes out. This also means that newer versions
of the perl bindings won't work by default against older versions of
libnettle, which seems like it might make the perl bindings less useful
for people who are stuck (for whatever reason) with an older version of
libnettle.
The attached patch would present an interface to dynamically enumerate
the available ciphers and digest algorithms (and armor methods)
supported by the current version of libnettle. bindings built against
this meta-interface wouldn't need to be closely tied to any particular
version of nettle, and so could be both forward- and backward-compatible.
I'd be happy with any other interface that would give me the same
effect, of course, and i'm not convinced that this is the best way to do
it -- it just seemed the simplest in the current implementation.
It would also be nice to make a similar interface to genericize cipher
modes (ECB, CBC, CTR, and GCM), if that's possible; i'm not sure what
the best approach is for doing that.
Feedback welcome, of course.
--dkg
diff --git a/nettle/Makefile.in b/nettle/Makefile.in
index 1020fd7..06accb4 100644
--- a/nettle/Makefile.in
+++ b/nettle/Makefile.in
@@ -75,7 +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-internal.c write-be32.c
+ nettle-meta.c \
+ nettle-internal.c write-be32.c
hogweed_SOURCES = sexp.c sexp-format.c \
sexp-transport.c sexp-transport-format.c \
diff --git a/nettle/nettle-meta.c b/nettle/nettle-meta.c
new file mode 100644
index 0000000..184abc1
--- /dev/null
+++ b/nettle/nettle-meta.c
@@ -0,0 +1,69 @@
+/* nettle-meta.c */
+
+/* nettle, low-level cryptographics library
+ *
+ * This file contains an aggregate list of all algorithms
+ * generically-expressed by nettle. It can be useful for exposing
+ * algorithm lists to higher-level languages or providing user choices.
+ *
+ * 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 "nettle-meta.h"
+
+const struct nettle_armor *nettle_armors[] = {
+ &nettle_base64,
+ &nettle_base16,
+ NULL
+};
+
+const struct nettle_hash *nettle_hashes[] = {
+ &nettle_md2,
+ &nettle_md4,
+ &nettle_md5,
+ &nettle_sha1,
+ &nettle_sha224,
+ &nettle_sha256,
+ &nettle_sha384,
+ &nettle_sha512,
+ NULL
+};
+
+const struct nettle_cipher *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/nettle-meta.h b/nettle/nettle-meta.h
index 2a00954..6cbb0a6 100644
--- a/nettle/nettle-meta.h
+++ b/nettle/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 *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 *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 *nettle_armors[];
+
extern const struct nettle_armor nettle_base64;
extern const struct nettle_armor nettle_base16;
_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs