chiark / gitweb /
Use nettle for hash functions.
authorian <ian>
Sat, 21 Sep 2002 16:42:31 +0000 (16:42 +0000)
committerian <ian>
Sat, 21 Sep 2002 16:42:31 +0000 (16:42 +0000)
base/troglodyte-Makefile
crypto/algtables.c

index fbcfc8f..df294af 100644 (file)
@@ -10,15 +10,11 @@ OBJS=               tables.o \
                misc.o \
                algtables.o \
                serpent.o \
-               sha1.o \
-               md5.o \
                crypto.o \
                parse.o
 
 HDRS=          hbytes.h \
                serpent.h \
-               md5.h \
-               sha1.h \
                $(AUTO_HDRS)
 
 AUTO_HDRS=     tables.h
@@ -28,6 +24,9 @@ AUTOS=                $(AUTO_HDRS) $(AUTO_SRCS)
 TARGETS=       hbytes.so autocode.tcl autococo.tcl
 
 CC_CRYPTO=     $(CC) $(CFLAGS) $(CPPFLAGS) -O3
+CPPFLAGS=      -I../plocal/include
+LDFLAGS=       -L../plocal/lib
+LDLIBS=                -lnettle
 CFLAGS=                -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Werror \
                $(OPTIMISE)
 OPTIMISE=      -O2
@@ -53,11 +52,5 @@ autoco%.tcl: deco%gen.tcl decobogen.tcl general.tcl ./hbytes.so \
 serpent.o:     serpent.c serpent.h serpentsboxes.h
                $(CC_CRYPTO) -o $@ -c $<
 
-md5.o:         md5.c md5.h
-               $(CC_CRYPTO) -o $@ -c $<
-
-sha1.o:                sha1.c sha1.h
-               $(CC_CRYPTO) -o $@ -c $<
-
 clean:
                rm -f $(OBJS) $(TARGETS) *~ ./#*#
index 8fa24e4..6f7a81c 100644 (file)
@@ -6,8 +6,9 @@
 
 #include "hbytes.h"
 #include "serpent.h"
-#include "sha1.h"
-#include "md5.h"
+
+#include <nettle/md5.h>
+#include <nettle/sha.h>
 
 static void alg_serpent_makekey(void *schedule, const void *key, int keylen) {
   serpent_makekey(schedule, key, keylen);
@@ -29,35 +30,36 @@ const BlockCipherAlgInfo blockcipheralginfos[]= {
   { 0 }
 };
 
-static void alg_sha1_init(void *state) { sha1_init(state); }
-static void alg_sha1_update(void *state, const void *data, int len) {
-  sha1_update(state, data, len);
-}
-static void alg_sha1_final(void *state, void *digest) {
-  sha1_final(state, digest);
-}
-static void alg_sha1_oneshot(void *digest, const void *data, int len) {
-  sha1(data,len,digest);
-}
+#define NETTLE_DIGESTS                         \
+  DO(sha1,   SHA1)                             \
+  DO(sha256, SHA256)                           \
+  DO(md5,    MD5)
 
-static void alg_md5_init(void *state) { MD5Init(state); }
-static void alg_md5_update(void *state, const void *data, int len) {
-  MD5Update(state, data, len);
-}
-static void alg_md5_final(void *state, void *digest) {
-  MD5Final(digest, state);
-}
-static void alg_md5_oneshot(void *digest, const void *data, int len) {
-  struct MD5Context ctx;
-  MD5Init(&ctx);
-  MD5Update(&ctx,data,len);
-  MD5Final(digest,&ctx);
-}
+#define DO(name,NAME)                                                        \
+  static void alg_##name##_init(void *state) {                               \
+    name##_init(state);                                                              \
+  }                                                                          \
+  static void alg_##name##_update(void *state, const void *data, int len) {   \
+    name##_update(state, len, data);                                         \
+  }                                                                          \
+  static void alg_##name##_final(void *state, void *digest) {                \
+    name##_digest(state,NAME##_DIGEST_SIZE,digest);                          \
+  }                                                                          \
+  static void alg_##name##_oneshot(void *digest, const void *data, int len) { \
+    struct name##_ctx ctx;                                                   \
+    name##_init(&ctx);                                                       \
+    name##_update(&ctx, len, data);                                          \
+    name##_digest(&ctx,NAME##_DIGEST_SIZE,digest);                           \
+  }
+  NETTLE_DIGESTS
+#undef DO
 
 const HashAlgInfo hashalginfos[]= {
-  { "sha1", 20, 64, sizeof(struct sha1_state),
-    alg_sha1_init, alg_sha1_update, alg_sha1_final, alg_sha1_oneshot },
-  { "md5", 16, 64, sizeof(struct MD5Context),
-    alg_md5_init, alg_md5_update, alg_md5_final, alg_md5_oneshot },
+#define DO(name,NAME)                                                      \
+  { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
+    alg_##name##_init, alg_##name##_update, alg_##name##_final,                    \
+    alg_##name##_oneshot },
+  NETTLE_DIGESTS
+#undef DO
   { 0 }
 };