+2005-10-12 Simon Josefsson <jas@extundo.com>
+
+ * modules/gc-sha1: New file.
+
2005-10-12 Simon Josefsson <jas@extundo.com>
* tests/test-hmac-sha1.c: New file.
+2005-10-12 Simon Josefsson <jas@extundo.com>
+
+ * gc.h, gc-gnulib.c, gc-libgcrypt.c: Support SHA-1.
+
2005-10-12 Simon Josefsson <jas@extundo.com>
* gc-gnulib.c: Condition MD5 and HMAC-MD5 use on GC_USE_MD5 and
#ifdef GC_USE_MD5
# include "md5.h"
#endif
+#ifdef GC_USE_SHA1
+# include "sha1.h"
+#endif
#ifdef GC_USE_HMAC_MD5
# include "hmac.h"
#endif
break;
#endif
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ sha1_buffer (in, inlen, resbuf);
+ break;
+#endif
+
default:
return GC_INVALID_HASH;
}
}
#endif
+#ifdef GC_USE_SHA1
+int
+gc_sha1 (const void *in, size_t inlen, void *resbuf)
+{
+ sha1_buffer (in, inlen, resbuf);
+ return 0;
+}
+#endif
+
#ifdef GC_USE_HMAC_MD5
int
gc_hmac_md5 (const void *key, size_t keylen,
break;
#endif
+#ifdef GC_USE_SHA1
+ case GC_SHA1:
+ gcryalg = GCRY_MD_SHA1;
+ break;
+#endif
+
default:
return GC_INVALID_HASH;
}
}
#endif
+#ifdef GC_USE_SHA1
+int
+gc_sha1 (const void *in, size_t inlen, void *resbuf)
+{
+ size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA1);
+ gcry_md_hd_t hd;
+ gpg_error_t err;
+ unsigned char *p;
+
+ assert (outlen == GC_SHA1_DIGEST_SIZE);
+
+ err = gcry_md_open (&hd, GCRY_MD_SHA1, 0);
+ if (err != GPG_ERR_NO_ERROR)
+ return GC_INVALID_HASH;
+
+ gcry_md_write (hd, in, inlen);
+
+ p = gcry_md_read (hd, GCRY_MD_SHA1);
+ 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_HMAC_MD5
int
gc_hmac_md5 (const void *key, size_t keylen,
/* Hash types. */
enum Gc_hash
{
- GC_MD5
+ GC_MD5,
+ GC_SHA1
};
typedef enum Gc_hash Gc_hash;
#define GC_MD5_DIGEST_SIZE 16
+#define GC_SHA1_DIGEST_SIZE 20
/* Call before respectively after any other functions. */
extern int gc_init (void);
/* One-call interface. */
extern int gc_md5 (const void *in, size_t inlen, void *resbuf);
+extern int gc_sha1 (const void *in, size_t inlen, void *resbuf);
extern int gc_hmac_md5 (const void *key, size_t keylen,
const void *in, size_t inlen,
char *resbuf);
+extern int gc_hmac_sha1 (const void *key, size_t keylen,
+ const void *in, size_t inlen,
+ char *resbuf);
/*
TODO:
2005-10-12 Simon Josefsson <jas@extundo.com>
+ * gc-sha1: New file.
+
* hmac-sha1.m4: New file.
2005-10-12 Simon Josefsson <jas@extundo.com>
--- /dev/null
+# gc-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_SHA1],
+[
+ AC_REQUIRE([gl_GC])
+ AC_DEFINE(GC_USE_SHA1, 1,
+ [Define to if you want to support SHA-1 through GC.])
+ if test "$ac_cv_libgcrypt" != yes; then
+ gl_SHA1
+ fi
+])
--- /dev/null
+Description:
+Generic crypto wrappers for SHA-1 functions.
+
+Files:
+m4/gc-sha1.m4
+lib/sha1.h
+lib/sha1.c
+m4/sha1.m4
+
+Depends-on:
+stdint
+gc
+
+configure.ac:
+gl_GC_SHA1
+
+Makefile.am:
+
+Include:
+"gc.h"
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson