diff options
author | Jia Zhang <qianyue.zj@alibaba-inc.com> | 2017-10-28 23:58:20 -0400 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2017-10-29 09:11:25 +0100 |
commit | e128f7fb2f0be16d96e5cc274bdd61bcb68313eb (patch) | |
tree | 9b919f579d914e1e6f1c402e305a13b3fff19da6 /lib/gc-libgcrypt.c | |
parent | 61f381e0f7daffe7bbef904070d5ca5f81fc2273 (diff) | |
download | gnulib-e128f7fb2f0be16d96e5cc274bdd61bcb68313eb.tar.gz |
New module: crypto/gc-sm3
* lib/gc.h: Declare SM3-related stuffs.
* lib/gc-gnulib.c: Support sm3 in internal functions.
* lib/gc-libgcrypt.c: Support sm3 with libgcrypt.
* m4/gc-sm3.m4: m4 file for gc-sm3 module.
* modules/crypto/gc-sm3: Define gc-sm3 module.
* tests/test-gc-sm3.c: Implement SM3 test case with libgcrypt.
* modules/crypto/gc-sm3-tests: Define gc-sm3 test module.
* MODULES.html.sh: List gc-sm3 module.
Diffstat (limited to 'lib/gc-libgcrypt.c')
-rw-r--r-- | lib/gc-libgcrypt.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/gc-libgcrypt.c b/lib/gc-libgcrypt.c index f0c8d82293..49ba0e13cb 100644 --- a/lib/gc-libgcrypt.c +++ b/lib/gc-libgcrypt.c @@ -304,6 +304,10 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle) gcryalg = GCRY_MD_RMD160; break; + case GC_SM3: + gcryalg = GCRY_MD_SM3; + break; + default: rc = GC_INVALID_HASH; } @@ -403,6 +407,10 @@ gc_hash_digest_length (Gc_hash hash) len = GC_SHA224_DIGEST_SIZE; break; + case GC_SM3: + len = GC_SM3_DIGEST_SIZE; + break; + default: return 0; } @@ -530,6 +538,12 @@ gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf) break; #endif +#ifdef GNULIB_GC_SM3 + case GC_SM3: + gcryalg = GCRY_MD_SM3; + break; +#endif + default: return GC_INVALID_HASH; } @@ -646,6 +660,38 @@ gc_sha1 (const void *in, size_t inlen, void *resbuf) } #endif +#ifdef GNULIB_GC_SM3 +Gc_rc +gc_sm3 (const void *in, size_t inlen, void *resbuf) +{ + size_t outlen = gcry_md_get_algo_dlen (GCRY_MD_SM3); + gcry_md_hd_t hd; + gpg_error_t err; + unsigned char *p; + + assert (outlen == GC_SM3_DIGEST_SIZE); + + err = gcry_md_open (&hd, GCRY_MD_SM3, 0); + if (err != GPG_ERR_NO_ERROR) + return GC_INVALID_HASH; + + gcry_md_write (hd, in, inlen); + + p = gcry_md_read (hd, GCRY_MD_SM3); + if (p == NULL) + { + gcry_md_close (hd); + return GC_INVALID_HASH; + } + + memcpy (resbuf, p, outlen); + + gcry_md_close (hd); + + return GC_OK; +} +#endif + #ifdef GNULIB_GC_HMAC_MD5 Gc_rc gc_hmac_md5 (const void *key, size_t keylen, |