summaryrefslogtreecommitdiff
path: root/lib/nettle
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2019-06-26 11:00:39 +0300
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2019-06-26 11:01:19 +0300
commitc034cf9f332de9f6ccb878e1b0f0355049489827 (patch)
treedc4a8295710ac0ac9f2593cfafe8a54f9f8994ec /lib/nettle
parent6b41d6ce9f18eac9673279db336f8c84bc839cac (diff)
downloadgnutls-c034cf9f332de9f6ccb878e1b0f0355049489827.tar.gz
lib: add support for gnutls_hash_copy()
Add gnutls_hash_copy() function for copying message digest context. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'lib/nettle')
-rw-r--r--lib/nettle/mac.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/nettle/mac.c b/lib/nettle/mac.c
index 90789d876f..8107f7cea4 100644
--- a/lib/nettle/mac.c
+++ b/lib/nettle/mac.c
@@ -632,6 +632,22 @@ wrap_nettle_hash_init(gnutls_digest_algorithm_t algo, void **_ctx)
return 0;
}
+static void *wrap_nettle_hash_copy(const void *_ctx)
+{
+ const struct nettle_hash_ctx *ctx = _ctx;
+ struct nettle_hash_ctx *new_ctx;
+ ptrdiff_t off = (uint8_t *)ctx->ctx_ptr - (uint8_t *)(&ctx->ctx);
+
+ new_ctx = gnutls_calloc(1, sizeof(struct nettle_hash_ctx));
+ if (new_ctx == NULL)
+ return NULL;
+
+ memcpy(new_ctx, ctx, sizeof(*ctx));
+ new_ctx->ctx_ptr = (uint8_t *)&new_ctx->ctx + off;
+
+ return new_ctx;
+}
+
static int
wrap_nettle_hash_output(void *src_ctx, void *digest, size_t digestsize)
{
@@ -667,4 +683,5 @@ gnutls_crypto_digest_st _gnutls_digest_ops = {
.deinit = wrap_nettle_hash_deinit,
.fast = wrap_nettle_hash_fast,
.exists = wrap_nettle_hash_exists,
+ .copy = wrap_nettle_hash_copy,
};