When Simon added the "generic crypto" modules (= modules that can use
libgcrypt, libcrypt from openssl, or just gnulib code), he prepared
the code for use of modules named gc-sha256, gc-sha384, gc-sha512
2007-02-05. But these modules did not exist, since there was no fallback
code available in gnulib at that time.

On 2008-05-11, the modules crypto/sha256 and crypto/sha512 were added.
This makes it possible to create these two more "generic crypto" modules.


>From 387edff2fbcea3bfbf52ff60e31e4890192a3d37 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 24 Aug 2019 17:34:29 +0200
Subject: [PATCH 1/3] crypto/gc-sha256, crypto/gc-sha512: New modules.

* lib/gc.h (gc_sha256, gc_sha512): New declarations.
* lib/gc-gnulib.c: Include sha256.h, sha512.h.
(MAX_DIGEST_SIZE): Set to 64.
(_gc_hash_ctx, gc_hash_open, gc_hash_digest_length, gc_hash_write,
gc_hash_read, gc_hash_buffer): Add support for sha256 and sha512.
(gc_sha256, gc_sha512): New functions.
* lib/gc-libgcrypt.c (gc_sha256, gc_sha512): New functions.
* modules/crypto/gc-sha256: New file, based on modules/crypto/gc-sha1.
* modules/crypto/gc-sha512: New file, based on modules/crypto/gc-sha1.
---
 ChangeLog                | 13 +++++++
 lib/gc-gnulib.c          | 90 +++++++++++++++++++++++++++++++++++++++++++++++-
 lib/gc-libgcrypt.c       | 64 ++++++++++++++++++++++++++++++++++
 lib/gc.h                 |  2 ++
 modules/crypto/gc-sha256 | 24 +++++++++++++
 modules/crypto/gc-sha512 | 24 +++++++++++++
 6 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 modules/crypto/gc-sha256
 create mode 100644 modules/crypto/gc-sha512

diff --git a/ChangeLog b/ChangeLog
index 53e5b25..3d701d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2019-08-24  Bruno Haible  <[email protected]>
 
+	crypto/gc-sha256, crypto/gc-sha512: New modules.
+	* lib/gc.h (gc_sha256, gc_sha512): New declarations.
+	* lib/gc-gnulib.c: Include sha256.h, sha512.h.
+	(MAX_DIGEST_SIZE): Set to 64.
+	(_gc_hash_ctx, gc_hash_open, gc_hash_digest_length, gc_hash_write,
+	gc_hash_read, gc_hash_buffer): Add support for sha256 and sha512.
+	(gc_sha256, gc_sha512): New functions.
+	* lib/gc-libgcrypt.c (gc_sha256, gc_sha512): New functions.
+	* modules/crypto/gc-sha256: New file, based on modules/crypto/gc-sha1.
+	* modules/crypto/gc-sha512: New file, based on modules/crypto/gc-sha1.
+
+2019-08-24  Bruno Haible  <[email protected]>
+
 	crypto/gc-sha1 tests: Improve output when the test fails.
 	* tests/test-gc-sha1.c (main): In case of mismatch, print the entire
 	output.
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index 6fcb4a1..2140591 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -48,6 +48,12 @@
 #if GNULIB_GC_SHA1
 # include "sha1.h"
 #endif
+#if GNULIB_GC_SHA256
+# include "sha256.h"
+#endif
+#if GNULIB_GC_SHA512
+# include "sha512.h"
+#endif
 #if GNULIB_GC_SM3
 # include "sm3.h"
 #endif
@@ -602,7 +608,7 @@ gc_cipher_close (gc_cipher_handle handle)
 
 /* Hashes. */
 
-#define MAX_DIGEST_SIZE 32
+#define MAX_DIGEST_SIZE 64
 
 typedef struct _gc_hash_ctx
 {
@@ -621,6 +627,12 @@ typedef struct _gc_hash_ctx
 #if GNULIB_GC_SHA1
   struct sha1_ctx sha1Context;
 #endif
+#if GNULIB_GC_SHA256
+  struct sha256_ctx sha256Context;
+#endif
+#if GNULIB_GC_SHA512
+  struct sha512_ctx sha512Context;
+#endif
 #if GNULIB_GC_SM3
   struct sm3_ctx sm3Context;
 #endif
@@ -669,6 +681,18 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
       break;
 #endif
 
+#if GNULIB_GC_SHA256
+    case GC_SHA256:
+      sha256_init_ctx (&ctx->sha256Context);
+      break;
+#endif
+
+#if GNULIB_GC_SHA512
+    case GC_SHA512:
+      sha512_init_ctx (&ctx->sha512Context);
+      break;
+#endif
+
 #if GNULIB_GC_SM3
     case GC_SM3:
       sm3_init_ctx (&ctx->sm3Context);
@@ -730,6 +754,14 @@ gc_hash_digest_length (Gc_hash hash)
       len = GC_SHA1_DIGEST_SIZE;
       break;
 
+    case GC_SHA256:
+      len = GC_SHA256_DIGEST_SIZE;
+      break;
+
+    case GC_SHA512:
+      len = GC_SHA512_DIGEST_SIZE;
+      break;
+
     case GC_SM3:
       len = GC_SM3_DIGEST_SIZE;
       break;
@@ -772,6 +804,18 @@ gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
       break;
 #endif
 
+#if GNULIB_GC_SHA256
+    case GC_SHA256:
+      sha256_process_bytes (data, len, &ctx->sha256Context);
+      break;
+#endif
+
+#if GNULIB_GC_SHA512
+    case GC_SHA512:
+      sha512_process_bytes (data, len, &ctx->sha512Context);
+      break;
+#endif
+
 #if GNULIB_GC_SM3
     case GC_SM3:
       sm3_process_bytes (data, len, &ctx->sm3Context);
@@ -819,6 +863,20 @@ gc_hash_read (gc_hash_handle handle)
       break;
 #endif
 
+#if GNULIB_GC_SHA256
+    case GC_SHA256:
+      sha256_finish_ctx (&ctx->sha256Context, ctx->hash);
+      ret = ctx->hash;
+      break;
+#endif
+
+#if GNULIB_GC_SHA512
+    case GC_SHA512:
+      sha512_finish_ctx (&ctx->sha512Context, ctx->hash);
+      ret = ctx->hash;
+      break;
+#endif
+
 #if GNULIB_GC_SM3
     case GC_SM3:
       sm3_finish_ctx (&ctx->sm3Context, ctx->hash);
@@ -870,6 +928,18 @@ gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
       break;
 #endif
 
+#if GNULIB_GC_SHA256
+    case GC_SHA256:
+      sha256_buffer (in, inlen, resbuf);
+      break;
+#endif
+
+#if GNULIB_GC_SHA512
+    case GC_SHA512:
+      sha512_buffer (in, inlen, resbuf);
+      break;
+#endif
+
 #if GNULIB_GC_SM3
     case GC_SM3:
       sm3_buffer (in, inlen, resbuf);
@@ -919,6 +989,24 @@ gc_sha1 (const void *in, size_t inlen, void *resbuf)
 }
 #endif
 
+#if GNULIB_GC_SHA256
+Gc_rc
+gc_sha256 (const void *in, size_t inlen, void *resbuf)
+{
+  sha256_buffer (in, inlen, resbuf);
+  return GC_OK;
+}
+#endif
+
+#if GNULIB_GC_SHA512
+Gc_rc
+gc_sha512 (const void *in, size_t inlen, void *resbuf)
+{
+  sha512_buffer (in, inlen, resbuf);
+  return GC_OK;
+}
+#endif
+
 #if GNULIB_GC_SM3
 Gc_rc
 gc_sm3 (const void *in, size_t inlen, void *resbuf)
diff --git a/lib/gc-libgcrypt.c b/lib/gc-libgcrypt.c
index 3ca17c2..8ea121a 100644
--- a/lib/gc-libgcrypt.c
+++ b/lib/gc-libgcrypt.c
@@ -707,6 +707,70 @@ gc_sha1 (const void *in, size_t inlen, void *resbuf)
 }
 #endif
 
+#if GNULIB_GC_SHA256
+Gc_rc
+gc_sha256 (const void *in, size_t inlen, void *resbuf)
+{
+  size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA256);
+  gcry_md_hd_t hd;
+  gpg_error_t err;
+  unsigned char *p;
+
+  assert (outlen == GC_SHA256_DIGEST_SIZE);
+
+  err = gcry_md_open (&hd, GCRY_MD_SHA256, 0);
+  if (err != GPG_ERR_NO_ERROR)
+    return GC_INVALID_HASH;
+
+  gcry_md_write (hd, in, inlen);
+
+  p = gcry_md_read (hd, GCRY_MD_SHA256);
+  if (p == NULL)
+    {
+      gcry_md_close (hd);
+      return GC_INVALID_HASH;
+    }
+
+  memcpy (resbuf, p, outlen);
+
+  gcry_md_close (hd);
+
+  return GC_OK;
+}
+#endif
+
+#if GNULIB_GC_SHA512
+Gc_rc
+gc_sha512 (const void *in, size_t inlen, void *resbuf)
+{
+  size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SHA512);
+  gcry_md_hd_t hd;
+  gpg_error_t err;
+  unsigned char *p;
+
+  assert (outlen == GC_SHA512_DIGEST_SIZE);
+
+  err = gcry_md_open (&hd, GCRY_MD_SHA512, 0);
+  if (err != GPG_ERR_NO_ERROR)
+    return GC_INVALID_HASH;
+
+  gcry_md_write (hd, in, inlen);
+
+  p = gcry_md_read (hd, GCRY_MD_SHA512);
+  if (p == NULL)
+    {
+      gcry_md_close (hd);
+      return GC_INVALID_HASH;
+    }
+
+  memcpy (resbuf, p, outlen);
+
+  gcry_md_close (hd);
+
+  return GC_OK;
+}
+#endif
+
 #if GNULIB_GC_SM3
 Gc_rc
 gc_sm3  (const void *in, size_t inlen, void *resbuf)
diff --git a/lib/gc.h b/lib/gc.h
index b5f8327..d591408 100644
--- a/lib/gc.h
+++ b/lib/gc.h
@@ -159,6 +159,8 @@ extern Gc_rc gc_md2 (const void *in, size_t inlen, void *resbuf);
 extern Gc_rc gc_md4 (const void *in, size_t inlen, void *resbuf);
 extern Gc_rc gc_md5 (const void *in, size_t inlen, void *resbuf);
 extern Gc_rc gc_sha1 (const void *in, size_t inlen, void *resbuf);
+extern Gc_rc gc_sha256 (const void *in, size_t inlen, void *resbuf);
+extern Gc_rc gc_sha512 (const void *in, size_t inlen, void *resbuf);
 extern Gc_rc gc_sm3 (const void *in, size_t inlen, void *resbuf);
 extern Gc_rc gc_hmac_md5 (const void *key, size_t keylen,
                           const void *in, size_t inlen, char *resbuf);
diff --git a/modules/crypto/gc-sha256 b/modules/crypto/gc-sha256
new file mode 100644
index 0000000..ee3156f
--- /dev/null
+++ b/modules/crypto/gc-sha256
@@ -0,0 +1,24 @@
+Description:
+Generic crypto wrappers for SHA-256 functions.
+
+Files:
+m4/gc-sha256.m4
+
+Depends-on:
+crypto/gc
+crypto/sha256 [test "$ac_cv_libgcrypt" != yes]
+
+configure.ac:
+gl_GC_SHA256
+gl_MODULE_INDICATOR([gc-sha256])
+
+Makefile.am:
+
+Include:
+"gc.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+Simon Josefsson
diff --git a/modules/crypto/gc-sha512 b/modules/crypto/gc-sha512
new file mode 100644
index 0000000..7372fec
--- /dev/null
+++ b/modules/crypto/gc-sha512
@@ -0,0 +1,24 @@
+Description:
+Generic crypto wrappers for SHA-512 functions.
+
+Files:
+m4/gc-sha512.m4
+
+Depends-on:
+crypto/gc
+crypto/sha512 [test "$ac_cv_libgcrypt" != yes]
+
+configure.ac:
+gl_GC_SHA512
+gl_MODULE_INDICATOR([gc-sha512])
+
+Makefile.am:
+
+Include:
+"gc.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+Simon Josefsson
-- 
2.7.4

>From cfac16920c6be7b9a2c71c34c3fab8446704d241 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 24 Aug 2019 17:36:28 +0200
Subject: [PATCH 2/3] crypto/gc-sha256: Add tests.

* tests/test-gc-sha256.c: New file, based on tests/test-gc-sha1.c.
* modules/crypto/gc-sha256-tests: New file.
---
 ChangeLog                      |   4 ++
 modules/crypto/gc-sha256-tests |  11 ++++
 tests/test-gc-sha256.c         | 127 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+)
 create mode 100644 modules/crypto/gc-sha256-tests
 create mode 100644 tests/test-gc-sha256.c

diff --git a/ChangeLog b/ChangeLog
index 3d701d7..a70fbfd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2019-08-24  Bruno Haible  <[email protected]>
 
+	crypto/gc-sha256: Add tests.
+	* tests/test-gc-sha256.c: New file, based on tests/test-gc-sha1.c.
+	* modules/crypto/gc-sha256-tests: New file.
+
 	crypto/gc-sha256, crypto/gc-sha512: New modules.
 	* lib/gc.h (gc_sha256, gc_sha512): New declarations.
 	* lib/gc-gnulib.c: Include sha256.h, sha512.h.
diff --git a/modules/crypto/gc-sha256-tests b/modules/crypto/gc-sha256-tests
new file mode 100644
index 0000000..677ed62
--- /dev/null
+++ b/modules/crypto/gc-sha256-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-gc-sha256.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-gc-sha256
+check_PROGRAMS += test-gc-sha256
+test_gc_sha256_LDADD = $(LDADD) @LIB_CRYPTO@
diff --git a/tests/test-gc-sha256.c b/tests/test-gc-sha256.c
new file mode 100644
index 0000000..2faab99
--- /dev/null
+++ b/tests/test-gc-sha256.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2005, 2010-2019 Free Software Foundation, Inc.
+ * 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 3, 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, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include "gc.h"
+
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+  Gc_rc rc;
+  gc_hash_handle h;
+
+  rc = gc_init ();
+  if (rc != GC_OK)
+    {
+      printf ("gc_init() failed\n");
+      return 1;
+    }
+
+  {
+    char *in = "abcdefghijklmnopqrstuvwxyz";
+    size_t inlen = strlen (in);
+    char *expect =
+      "\x71\xc4\x80\xdf\x93\xd6\xae\x2f\x1e\xfa\xd1\x44\x7c\x66\xc9\x52"
+      "\x5e\x31\x62\x18\xcf\x51\xfc\x8d\x9e\xd8\x32\xf2\xda\xf1\x8b\x73";
+    char out[32];
+    const char *p;
+
+    if (gc_sha256 (in, inlen, out) != 0)
+      {
+        printf ("gc_sha256 call failed\n");
+        return 1;
+      }
+
+    if (memcmp (out, expect, 32) != 0)
+      {
+        size_t i;
+        printf ("sha256 test1 mismatch. expected:\n");
+        for (i = 0; i < 32; i++)
+          printf ("%02x ", expect[i] & 0xFF);
+        printf ("\ncomputed:\n");
+        for (i = 0; i < 32; i++)
+          printf ("%02x ", out[i] & 0xFF);
+        printf ("\n");
+        return 1;
+      }
+
+    rc = gc_hash_buffer (GC_SHA256, "abcdefghijklmnopqrstuvwxyz", 26, out);
+    if (rc != GC_OK)
+      {
+        printf ("gc_hash_buffer(sha256) call failed: %d\n", rc);
+        return 1;
+      }
+
+    if (memcmp (out, expect, 32) != 0)
+      {
+        size_t i;
+        printf ("sha256 test2 mismatch. expected:\n");
+        for (i = 0; i < 32; i++)
+          printf ("%02x ", expect[i] & 0xFF);
+        printf ("\ncomputed:\n");
+        for (i = 0; i < 32; i++)
+          printf ("%02x ", out[i] & 0xFF);
+        printf ("\n");
+        return 1;
+      }
+
+    if (gc_hash_digest_length (GC_SHA256) != 32)
+      {
+        printf ("gc_hash_digest_length (GC_SHA256) failed\n");
+        return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_SHA256, 0, &h)) != GC_OK)
+      {
+        printf ("gc_hash_open(GC_SHA256) failed (%d)\n", rc);
+        return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+        printf ("gc_hash_read failed\n");
+        return 1;
+      }
+
+    if (memcmp (p, expect, 32) != 0)
+      {
+        size_t i;
+        printf ("sha256 test3 mismatch. expected:\n");
+        for (i = 0; i < 32; i++)
+          printf ("%02x ", expect[i] & 0xFF);
+        printf ("\ncomputed:\n");
+        for (i = 0; i < 32; i++)
+          printf ("%02x ", p[i] & 0xFF);
+        printf ("\n");
+        return 1;
+      }
+
+    gc_hash_close (h);
+  }
+
+  gc_done ();
+
+  return 0;
+}
-- 
2.7.4

>From 024ca9ce6930b8f111cdbfa33ca022b582bee9b3 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 24 Aug 2019 17:37:10 +0200
Subject: [PATCH 3/3] crypto/gc-sha512: Add tests.

* tests/test-gc-sha512.c: New file, based on tests/test-gc-sha1.c.
* modules/crypto/gc-sha512-tests: New file.
---
 ChangeLog                      |   4 ++
 modules/crypto/gc-sha512-tests |  11 ++++
 tests/test-gc-sha512.c         | 129 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 modules/crypto/gc-sha512-tests
 create mode 100644 tests/test-gc-sha512.c

diff --git a/ChangeLog b/ChangeLog
index a70fbfd..1438799 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2019-08-24  Bruno Haible  <[email protected]>
 
+	crypto/gc-sha512: Add tests.
+	* tests/test-gc-sha512.c: New file, based on tests/test-gc-sha1.c.
+	* modules/crypto/gc-sha512-tests: New file.
+
 	crypto/gc-sha256: Add tests.
 	* tests/test-gc-sha256.c: New file, based on tests/test-gc-sha1.c.
 	* modules/crypto/gc-sha256-tests: New file.
diff --git a/modules/crypto/gc-sha512-tests b/modules/crypto/gc-sha512-tests
new file mode 100644
index 0000000..b007cd1
--- /dev/null
+++ b/modules/crypto/gc-sha512-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-gc-sha512.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-gc-sha512
+check_PROGRAMS += test-gc-sha512
+test_gc_sha512_LDADD = $(LDADD) @LIB_CRYPTO@
diff --git a/tests/test-gc-sha512.c b/tests/test-gc-sha512.c
new file mode 100644
index 0000000..b3efd29
--- /dev/null
+++ b/tests/test-gc-sha512.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2005, 2010-2019 Free Software Foundation, Inc.
+ * 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 3, 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, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include "gc.h"
+
+#include <stdio.h>
+#include <string.h>
+
+int
+main (int argc, char *argv[])
+{
+  Gc_rc rc;
+  gc_hash_handle h;
+
+  rc = gc_init ();
+  if (rc != GC_OK)
+    {
+      printf ("gc_init() failed\n");
+      return 1;
+    }
+
+  {
+    char *in = "abcdefghijklmnopqrstuvwxyz";
+    size_t inlen = strlen (in);
+    char *expect =
+      "\x4d\xbf\xf8\x6c\xc2\xca\x1b\xae\x1e\x16\x46\x8a\x05\xcb\x98\x81"
+      "\xc9\x7f\x17\x53\xbc\xe3\x61\x90\x34\x89\x8f\xaa\x1a\xab\xe4\x29"
+      "\x95\x5a\x1b\xf8\xec\x48\x3d\x74\x21\xfe\x3c\x16\x46\x61\x3a\x59"
+      "\xed\x54\x41\xfb\x0f\x32\x13\x89\xf7\x7f\x48\xa8\x79\xc7\xb1\xf1";
+    char out[64];
+    const char *p;
+
+    if (gc_sha512 (in, inlen, out) != 0)
+      {
+        printf ("gc_sha512 call failed\n");
+        return 1;
+      }
+
+    if (memcmp (out, expect, 64) != 0)
+      {
+        size_t i;
+        printf ("sha512 test1 mismatch. expected:\n");
+        for (i = 0; i < 64; i++)
+          printf ("%02x ", expect[i] & 0xFF);
+        printf ("\ncomputed:\n");
+        for (i = 0; i < 64; i++)
+          printf ("%02x ", out[i] & 0xFF);
+        printf ("\n");
+        return 1;
+      }
+
+    rc = gc_hash_buffer (GC_SHA512, "abcdefghijklmnopqrstuvwxyz", 26, out);
+    if (rc != GC_OK)
+      {
+        printf ("gc_hash_buffer(sha512) call failed: %d\n", rc);
+        return 1;
+      }
+
+    if (memcmp (out, expect, 64) != 0)
+      {
+        size_t i;
+        printf ("sha512 test2 mismatch. expected:\n");
+        for (i = 0; i < 64; i++)
+          printf ("%02x ", expect[i] & 0xFF);
+        printf ("\ncomputed:\n");
+        for (i = 0; i < 64; i++)
+          printf ("%02x ", out[i] & 0xFF);
+        printf ("\n");
+        return 1;
+      }
+
+    if (gc_hash_digest_length (GC_SHA512) != 64)
+      {
+        printf ("gc_hash_digest_length (GC_SHA512) failed\n");
+        return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_SHA512, 0, &h)) != GC_OK)
+      {
+        printf ("gc_hash_open(GC_SHA512) failed (%d)\n", rc);
+        return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+        printf ("gc_hash_read failed\n");
+        return 1;
+      }
+
+    if (memcmp (p, expect, 64) != 0)
+      {
+        size_t i;
+        printf ("sha512 test3 mismatch. expected:\n");
+        for (i = 0; i < 64; i++)
+          printf ("%02x ", expect[i] & 0xFF);
+        printf ("\ncomputed:\n");
+        for (i = 0; i < 64; i++)
+          printf ("%02x ", p[i] & 0xFF);
+        printf ("\n");
+        return 1;
+      }
+
+    gc_hash_close (h);
+  }
+
+  gc_done ();
+
+  return 0;
+}
-- 
2.7.4

Reply via email to