From 3ebed7b6a607af166646a161cddfacddd528b6e0 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Wed, 12 Oct 2005 09:28:48 +0000 Subject: [PATCH] Add gc-hmac-sha1. --- lib/ChangeLog | 6 ++++++ lib/gc-gnulib.c | 10 ++++++++++ lib/gc-libgcrypt.c | 40 ++++++++++++++++++++++++++++++++++++++++ m4/ChangeLog | 2 ++ m4/gc-hmac-sha1.m4 | 17 +++++++++++++++++ modules/gc-hmac-sha1 | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 m4/gc-hmac-sha1.m4 create mode 100644 modules/gc-hmac-sha1 diff --git a/lib/ChangeLog b/lib/ChangeLog index 9b74d153b1..bf2ead8b4a 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2005-10-12 Simon Josefsson + + * gc-libgcrypt.c (gc_hmac_sha1): New function. + + * gc-gnulib.c (gc_hmac_sha1): New function. + 2005-10-12 Simon Josefsson * gc.h, gc-gnulib.c, gc-libgcrypt.c: Support SHA-1. diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c index dfe4edc2cf..e0e37b059d 100644 --- a/lib/gc-gnulib.c +++ b/lib/gc-gnulib.c @@ -195,3 +195,13 @@ gc_hmac_md5 (const void *key, size_t keylen, 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 diff --git a/lib/gc-libgcrypt.c b/lib/gc-libgcrypt.c index 4f4ae10e41..7652356772 100644 --- a/lib/gc-libgcrypt.c +++ b/lib/gc-libgcrypt.c @@ -229,3 +229,43 @@ gc_hmac_md5 (const void *key, size_t keylen, 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 diff --git a/m4/ChangeLog b/m4/ChangeLog index 2918785425..cebd285944 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,5 +1,7 @@ 2005-10-12 Simon Josefsson + * gc-hmac-sha1.m4: New file. + * gc-sha1: New file. * hmac-sha1.m4: New file. diff --git a/m4/gc-hmac-sha1.m4 b/m4/gc-hmac-sha1.m4 new file mode 100644 index 0000000000..b6a3fa47d4 --- /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 +]) diff --git a/modules/gc-hmac-sha1 b/modules/gc-hmac-sha1 new file mode 100644 index 0000000000..8fcf9fd6df --- /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 -- 2.30.2