changeset 6366:22f41fec10ee

Add gc-hmac-sha1.
author Simon Josefsson <simon@josefsson.org>
date Wed, 12 Oct 2005 09:28:48 +0000
parents d3733bac8f2d
children 69cadd43d0f4
files lib/ChangeLog lib/gc-gnulib.c lib/gc-libgcrypt.c m4/ChangeLog m4/gc-hmac-sha1.m4 modules/gc-hmac-sha1
diffstat 6 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-12  Simon Josefsson  <jas@extundo.com>
+
+	* gc-libgcrypt.c (gc_hmac_sha1): New function.
+
+	* gc-gnulib.c (gc_hmac_sha1): New function.
+
 2005-10-12  Simon Josefsson  <jas@extundo.com>
 
 	* gc.h, gc-gnulib.c, gc-libgcrypt.c: Support SHA-1.
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -195,3 +195,13 @@
   return 0;
 }
 #endif
+
+#ifdef GC_USE_HMAC_SHA1
+int
+gc_hmac_sha1 (const void *key, size_t keylen,
+	      const void *in, size_t inlen, char *resbuf)
+{
+  hmac_sha1 (key, keylen, in, inlen, resbuf);
+  return 0;
+}
+#endif
--- a/lib/gc-libgcrypt.c
+++ b/lib/gc-libgcrypt.c
@@ -229,3 +229,43 @@
   return GC_OK;
 }
 #endif
+
+#ifdef GC_USE_HMAC_SHA1
+int
+gc_hmac_sha1 (const void *key, size_t keylen,
+	      const void *in, size_t inlen, char *resbuf)
+{
+  size_t hlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
+  gcry_md_hd_t mdh;
+  unsigned char *hash;
+  gpg_error_t err;
+
+  assert (hlen == 16);
+
+  err = gcry_md_open (&mdh, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
+  if (err != GPG_ERR_NO_ERROR)
+    return GC_INVALID_HASH;
+
+  err = gcry_md_setkey (mdh, key, keylen);
+  if (err != GPG_ERR_NO_ERROR)
+    {
+      gcry_md_close (mdh);
+      return GC_INVALID_HASH;
+    }
+
+  gcry_md_write (mdh, in, inlen);
+
+  hash = gcry_md_read (mdh, GCRY_MD_SHA1);
+  if (hash == NULL)
+    {
+      gcry_md_close (mdh);
+      return GC_INVALID_HASH;
+    }
+
+  memcpy (resbuf, hash, hlen);
+
+  gcry_md_close (mdh);
+
+  return GC_OK;
+}
+#endif
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,5 +1,7 @@
 2005-10-12  Simon Josefsson  <jas@extundo.com>
 
+	* gc-hmac-sha1.m4: New file.
+
 	* gc-sha1: New file.
 
 	* hmac-sha1.m4: New file.
new file mode 100644
--- /dev/null
+++ b/m4/gc-hmac-sha1.m4
@@ -0,0 +1,17 @@
+# gc-hmac-sha1.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_HMAC_SHA1],
+[
+  AC_REQUIRE([gl_GC])
+  AC_DEFINE(GC_USE_HMAC_SHA1, 1,
+    [Define to if you want to support HMAC-SHA1 through GC.])
+  if test "$ac_cv_libgcrypt" != yes; then
+    gl_SHA1
+    gl_HMAC_SHA1
+    gl_MEMXOR
+  fi
+])
new file mode 100644
--- /dev/null
+++ b/modules/gc-hmac-sha1
@@ -0,0 +1,32 @@
+Description:
+Generic crypto wrappers for HMAC-SHA1 functions.
+
+Files:
+m4/gc-hmac-md5.m4
+lib/sha1.h
+lib/sha1.c
+m4/sha1.m4
+lib/hmac.h
+lib/hmac-sha1.c
+m4/hmac-sha1.m4
+lib/memxor.h
+lib/memxor.c
+m4/memxor.m4
+
+Depends-on:
+stdint
+gc
+
+configure.ac:
+gl_GC_HMAC_SHA1
+
+Makefile.am:
+
+Include:
+"gc.h"
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson