+2005-10-19 Simon Josefsson <jas@extundo.com>
+
+ * modules/gc-md4, modules/gc-md4-tests: New file.
+
+ * tests/test-gc-md4.c: New file.
+
2005-10-18 Simon Josefsson <jas@extundo.com>
* tests/test-md4.c: New file.
+2005-10-19 Simon Josefsson <jas@extundo.com>
+
+ * gc.h, gc-gnulib.c, gc-libgcrypt.c: Support MD4.
+
2005-10-18 Simon Josefsson <jas@extundo.com>
* md4.h, md4.c: New files, based on md5.?.
#include <fcntl.h>
#include <errno.h>
+#ifdef GC_USE_MD4
+# include "md4.h"
+#endif
#ifdef GC_USE_MD5
# include "md5.h"
#endif
{
switch (hash)
{
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ md4_buffer (in, inlen, resbuf);
+ break;
+#endif
+
#ifdef GC_USE_MD5
case GC_MD5:
md5_buffer (in, inlen, resbuf);
return GC_OK;
}
+#ifdef GC_USE_MD4
+Gc_rc
+gc_md4 (const void *in, size_t inlen, void *resbuf)
+{
+ md4_buffer (in, inlen, resbuf);
+ return GC_OK;
+}
+#endif
+
#ifdef GC_USE_MD5
Gc_rc
gc_md5 (const void *in, size_t inlen, void *resbuf)
switch (hash)
{
+ case GC_MD4:
+ gcryalg = GCRY_MD_MD4;
+ break;
+
case GC_MD5:
gcryalg = GCRY_MD_MD5;
break;
switch (hash)
{
+ case GC_MD4:
+ gcryalg = GCRY_MD_MD4;
+ break;
+
case GC_MD5:
gcryalg = GCRY_MD_MD5;
break;
switch (hash)
{
+#ifdef GC_USE_MD4
+ case GC_MD4:
+ gcryalg = GCRY_MD_MD4;
+ break;
+#endif
+
#ifdef GC_USE_MD5
case GC_MD5:
gcryalg = GCRY_MD_MD5;
/* One-call interface. */
+#ifdef GC_USE_MD4
+Gc_rc
+gc_md4 (const void *in, size_t inlen, void *resbuf)
+{
+ size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_MD4);
+ gcry_md_hd_t hd;
+ gpg_error_t err;
+ unsigned char *p;
+
+ assert (outlen == GC_MD4_DIGEST_SIZE);
+
+ err = gcry_md_open (&hd, GCRY_MD_MD4, 0);
+ if (err != GPG_ERR_NO_ERROR)
+ return GC_INVALID_HASH;
+
+ gcry_md_write (hd, in, inlen);
+
+ p = gcry_md_read (hd, GCRY_MD_MD4);
+ if (p == NULL)
+ {
+ gcry_md_close (hd);
+ return GC_INVALID_HASH;
+ }
+
+ memcpy (resbuf, p, outlen);
+
+ gcry_md_close (hd);
+
+ return GC_OK;
+}
+#endif
+
#ifdef GC_USE_MD5
Gc_rc
gc_md5 (const void *in, size_t inlen, void *resbuf)
/* Hash types. */
enum Gc_hash
{
+ GC_MD4,
GC_MD5,
GC_SHA1,
GC_MD2,
typedef void *gc_hash_handle;
+#define GC_MD4_DIGEST_SIZE 16
#define GC_MD5_DIGEST_SIZE 16
#define GC_SHA1_DIGEST_SIZE 20
+2005-10-19 Simon Josefsson <jas@extundo.com>
+
+ * gc-md4.m4: New file.
+
2005-10-18 Simon Josefsson <jas@extundo.com>
* md4.m4: New file.
--- /dev/null
+# gc-md4.m4 serial 1
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_GC_MD4],
+[
+ AC_REQUIRE([gl_GC])
+ AC_DEFINE(GC_USE_MD4, 1, [Define to if you want to support MD4 through GC.])
+ if test "$ac_cv_libgcrypt" != yes; then
+ gl_MD4
+ fi
+])
--- /dev/null
+Description:
+Generic crypto wrappers for MD4 functions.
+
+Files:
+m4/gc-md4.m4
+lib/md4.h
+lib/md4.c
+m4/md4.m4
+
+Depends-on:
+stdint
+gc
+
+configure.ac:
+gl_GC_MD4
+
+Makefile.am:
+
+Include:
+"gc.h"
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson
--- /dev/null
+Files:
+tests/test-gc-md4.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-gc-md4
+noinst_PROGRAMS += test-gc-md4
+test_gc_md4_SOURCES = test-gc-md4.c
--- /dev/null
+/*
+ * Copyright (C) 2005 Free Software Foundation
+ * Written by Simon Josefsson
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include "gc.h"
+
+int
+main (int argc, char *argv[])
+{
+ Gc_rc rc;
+
+ rc = gc_init ();
+ if (rc != GC_OK)
+ {
+ printf ("gc_init() failed\n");
+ return 1;
+ }
+
+ /* Test vectors from RFC 1320. */
+
+ {
+ const char *in = "abc";
+ size_t inlen = strlen (in);
+ const char *expect =
+ "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d";
+ char out[16];
+
+ /* MD4 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */
+
+ if (gc_md4 (in, inlen, out) != 0)
+ {
+ printf ("gc_md4 call failed\n");
+ return 1;
+ }
+
+ if (memcmp (out, expect, 16) != 0)
+ {
+ size_t i;
+ printf ("md4 1 missmatch. expected:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", expect[i] & 0xFF);
+ printf ("\ncomputed:\n");
+ for (i = 0; i < 16; i++)
+ printf ("%02x ", out[i] & 0xFF);
+ printf ("\n");
+ return 1;
+ }
+ }
+
+ gc_done ();
+
+ return 0;
+}