[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gc-md4 and gc-md4-tests
From: |
Simon Josefsson |
Subject: |
gc-md4 and gc-md4-tests |
Date: |
Wed, 19 Oct 2005 01:09:08 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
I have installed this.
Index: m4/ChangeLog
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/ChangeLog,v
retrieving revision 1.746
diff -u -p -r1.746 ChangeLog
--- m4/ChangeLog 18 Oct 2005 22:59:17 -0000 1.746
+++ m4/ChangeLog 18 Oct 2005 23:08:34 -0000
@@ -1,3 +1,7 @@
+2005-10-19 Simon Josefsson <address@hidden>
+
+ * gc-md4.m4: New file.
+
2005-10-18 Simon Josefsson <address@hidden>
* md4.m4: New file.
Index: m4/gc-md4.m4
===================================================================
RCS file: m4/gc-md4.m4
diff -N m4/gc-md4.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ m4/gc-md4.m4 18 Oct 2005 23:08:34 -0000
@@ -0,0 +1,14 @@
+# 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
+])
Index: lib/ChangeLog
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/ChangeLog,v
retrieving revision 1.1020
diff -u -p -r1.1020 ChangeLog
--- lib/ChangeLog 18 Oct 2005 22:59:17 -0000 1.1020
+++ lib/ChangeLog 18 Oct 2005 23:08:35 -0000
@@ -1,3 +1,7 @@
+2005-10-19 Simon Josefsson <address@hidden>
+
+ * gc.h, gc-gnulib.c, gc-libgcrypt.c: Support MD4.
+
2005-10-18 Simon Josefsson <address@hidden>
* md4.h, md4.c: New files, based on md5.?.
Index: lib/gc.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gc.h,v
retrieving revision 1.12
diff -u -p -r1.12 gc.h
--- lib/gc.h 17 Oct 2005 13:41:56 -0000 1.12
+++ lib/gc.h 18 Oct 2005 23:08:35 -0000
@@ -41,6 +41,7 @@ typedef enum Gc_rc Gc_rc;
/* Hash types. */
enum Gc_hash
{
+ GC_MD4,
GC_MD5,
GC_SHA1,
GC_MD2,
@@ -56,6 +57,7 @@ typedef enum Gc_hash_mode Gc_hash_mode;
typedef void *gc_hash_handle;
+#define GC_MD4_DIGEST_SIZE 16
#define GC_MD5_DIGEST_SIZE 16
#define GC_SHA1_DIGEST_SIZE 20
Index: lib/gc-gnulib.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gc-gnulib.c,v
retrieving revision 1.7
diff -u -p -r1.7 gc-gnulib.c
--- lib/gc-gnulib.c 12 Oct 2005 11:57:13 -0000 1.7
+++ lib/gc-gnulib.c 18 Oct 2005 23:08:35 -0000
@@ -37,6 +37,9 @@
#include <fcntl.h>
#include <errno.h>
+#ifdef GC_USE_MD4
+# include "md4.h"
+#endif
#ifdef GC_USE_MD5
# include "md5.h"
#endif
@@ -149,6 +152,12 @@ gc_hash_buffer (Gc_hash hash, const void
{
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);
@@ -167,6 +176,15 @@ gc_hash_buffer (Gc_hash hash, const void
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
Index: lib/gc-libgcrypt.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gc-libgcrypt.c,v
retrieving revision 1.10
diff -u -p -r1.10 gc-libgcrypt.c
--- lib/gc-libgcrypt.c 17 Oct 2005 14:33:14 -0000 1.10
+++ lib/gc-libgcrypt.c 18 Oct 2005 23:08:35 -0000
@@ -222,6 +222,10 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode
switch (hash)
{
+ case GC_MD4:
+ gcryalg = GCRY_MD_MD4;
+ break;
+
case GC_MD5:
gcryalg = GCRY_MD_MD5;
break;
@@ -278,6 +282,10 @@ gc_hash_digest_length (Gc_hash hash)
switch (hash)
{
+ case GC_MD4:
+ gcryalg = GCRY_MD_MD4;
+ break;
+
case GC_MD5:
gcryalg = GCRY_MD_MD5;
break;
@@ -333,6 +341,12 @@ gc_hash_buffer (Gc_hash hash, const void
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;
@@ -361,6 +375,38 @@ gc_hash_buffer (Gc_hash hash, const void
}
/* 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
Index: modules/gc-md4
===================================================================
RCS file: modules/gc-md4
diff -N modules/gc-md4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/gc-md4 18 Oct 2005 23:08:35 -0000
@@ -0,0 +1,26 @@
+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
Index: modules/gc-md4-tests
===================================================================
RCS file: modules/gc-md4-tests
diff -N modules/gc-md4-tests
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/gc-md4-tests 18 Oct 2005 23:08:35 -0000
@@ -0,0 +1,11 @@
+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
Index: tests/test-gc-md4.c
===================================================================
RCS file: tests/test-gc-md4.c
diff -N tests/test-gc-md4.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-gc-md4.c 18 Oct 2005 23:08:35 -0000
@@ -0,0 +1,74 @@
+/*
+ * 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;
+}
Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnulib/gnulib/ChangeLog,v
retrieving revision 1.428
diff -u -p -r1.428 ChangeLog
--- ChangeLog 18 Oct 2005 22:59:17 -0000 1.428
+++ ChangeLog 18 Oct 2005 23:08:35 -0000
@@ -1,3 +1,9 @@
+2005-10-19 Simon Josefsson <address@hidden>
+
+ * modules/gc-md4, modules/gc-md4-tests: New file.
+
+ * tests/test-gc-md4.c: New file.
+
2005-10-18 Simon Josefsson <address@hidden>
* tests/test-md4.c: New file.
- gc-md4 and gc-md4-tests,
Simon Josefsson <=