- markus@cvs.openbsd.org 2014/01/27 18:58:14
     [Makefile.in digest.c digest.h hostfile.c kex.h mac.c hmac.c hmac.h]
     replace openssl HMAC with an implementation based on our ssh_digest_*
     ok and feedback djm@
diff --git a/digest.c b/digest.c
index a221819..1a11b2b 100644
--- a/digest.c
+++ b/digest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: digest.c,v 1.3 2014/01/20 00:08:48 djm Exp $ */
+/* $OpenBSD: digest.c,v 1.4 2014/01/27 18:58:14 markus Exp $ */
 /*
  * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
  *
@@ -72,6 +72,12 @@
 	return digest == NULL ? 0 : digest->digest_len;
 }
 
+size_t
+ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
+{
+	return EVP_MD_CTX_block_size(&ctx->mdctx);
+}
+
 struct ssh_digest_ctx *
 ssh_digest_start(int alg)
 {
@@ -90,6 +96,15 @@
 }
 
 int
+ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to)
+{
+	/* we have bcopy-style order while openssl has memcpy-style */
+	if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
+		return -1;
+	return 0;
+}
+
+int
 ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
 {
 	if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
@@ -123,9 +138,11 @@
 void
 ssh_digest_free(struct ssh_digest_ctx *ctx)
 {
-	EVP_MD_CTX_cleanup(&ctx->mdctx);
-	memset(ctx, 0, sizeof(*ctx));
-	free(ctx);
+	if (ctx != NULL) {
+		EVP_MD_CTX_cleanup(&ctx->mdctx);
+		memset(ctx, 0, sizeof(*ctx));
+		free(ctx);
+	}
 }
 
 int