summaryrefslogtreecommitdiff
path: root/lib/gc-gnulib.c
diff options
context:
space:
mode:
authorJia Zhang <qianyue.zj@alibaba-inc.com>2017-10-28 23:58:20 -0400
committerBruno Haible <bruno@clisp.org>2017-10-29 09:11:25 +0100
commite128f7fb2f0be16d96e5cc274bdd61bcb68313eb (patch)
tree9b919f579d914e1e6f1c402e305a13b3fff19da6 /lib/gc-gnulib.c
parent61f381e0f7daffe7bbef904070d5ca5f81fc2273 (diff)
downloadgnulib-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-gnulib.c')
-rw-r--r--lib/gc-gnulib.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index 61d5d980a6..f888cf5970 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -48,6 +48,9 @@
#ifdef GNULIB_GC_SHA1
# include "sha1.h"
#endif
+#ifdef GNULIB_GC_SM3
+# include "sm3.h"
+#endif
#if defined(GNULIB_GC_HMAC_MD5) || defined(GNULIB_GC_HMAC_SHA1) || defined(GNULIB_GC_HMAC_SHA256) || defined(GNULIB_GC_HMAC_SHA512)
# include "hmac.h"
#endif
@@ -618,6 +621,9 @@ typedef struct _gc_hash_ctx
#ifdef GNULIB_GC_SHA1
struct sha1_ctx sha1Context;
#endif
+#ifdef GNULIB_GC_SM3
+ struct sm3_ctx sm3Context;
+#endif
} _gc_hash_ctx;
Gc_rc
@@ -662,6 +668,12 @@ gc_hash_open (Gc_hash hash, Gc_hash_mode mode, gc_hash_handle * outhandle)
break;
#endif
+#ifdef GNULIB_GC_SM3
+ case GC_SM3:
+ sm3_init_ctx (&ctx->sm3Context);
+ break;
+#endif
+
default:
rc = GC_INVALID_HASH;
break;
@@ -717,6 +729,10 @@ gc_hash_digest_length (Gc_hash hash)
len = GC_SHA1_DIGEST_SIZE;
break;
+ case GC_SM3:
+ len = GC_SM3_DIGEST_SIZE;
+ break;
+
default:
return 0;
}
@@ -755,6 +771,12 @@ gc_hash_write (gc_hash_handle handle, size_t len, const char *data)
break;
#endif
+#ifdef GNULIB_GC_SM3
+ case GC_SM3:
+ sm3_process_bytes (data, len, &ctx->sm3Context);
+ break;
+#endif
+
default:
break;
}
@@ -796,6 +818,13 @@ gc_hash_read (gc_hash_handle handle)
break;
#endif
+#ifdef GNULIB_GC_SM3
+ case GC_SM3:
+ sm3_finish_ctx (&ctx->sm3Context, ctx->hash);
+ ret = ctx->hash;
+ break;
+#endif
+
default:
return NULL;
}
@@ -840,6 +869,12 @@ gc_hash_buffer (Gc_hash hash, const void *in, size_t inlen, char *resbuf)
break;
#endif
+#ifdef GNULIB_GC_SM3
+ case GC_SM3:
+ sm3_buffer (in, inlen, resbuf);
+ break;
+#endif
+
default:
return GC_INVALID_HASH;
}
@@ -883,6 +918,15 @@ 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)
+{
+ sm3_buffer (in, inlen, resbuf);
+ return GC_OK;
+}
+#endif
+
#ifdef GNULIB_GC_HMAC_MD5
Gc_rc
gc_hmac_md5 (const void *key, size_t keylen,