summaryrefslogtreecommitdiff
path: root/lib/gc-libgcrypt.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-08-24 17:34:29 +0200
committerBruno Haible <bruno@clisp.org>2019-08-24 17:34:29 +0200
commit387edff2fbcea3bfbf52ff60e31e4890192a3d37 (patch)
tree9054c574d21960cb067d8bb203d576b7297ee3d7 /lib/gc-libgcrypt.c
parent06ba5700871cfae584c604dafa93a3e3a4f23048 (diff)
downloadgnulib-387edff2fbcea3bfbf52ff60e31e4890192a3d37.tar.gz
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.
Diffstat (limited to 'lib/gc-libgcrypt.c')
-rw-r--r--lib/gc-libgcrypt.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/gc-libgcrypt.c b/lib/gc-libgcrypt.c
index 3ca17c2639..8ea121a247 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)