summaryrefslogtreecommitdiff
path: root/digest.c
diff options
context:
space:
mode:
Diffstat (limited to 'digest.c')
-rw-r--r--digest.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/digest.c b/digest.c
index a221819eb..1a11b2b1c 100644
--- a/digest.c
+++ b/digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: digest.c,v 1.3 2014/01/20 00:08:48 djm Exp $ */ 1/* $OpenBSD: digest.c,v 1.4 2014/01/27 18:58:14 markus Exp $ */
2/* 2/*
3 * Copyright (c) 2013 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2013 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -72,6 +72,12 @@ ssh_digest_bytes(int alg)
72 return digest == NULL ? 0 : digest->digest_len; 72 return digest == NULL ? 0 : digest->digest_len;
73} 73}
74 74
75size_t
76ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
77{
78 return EVP_MD_CTX_block_size(&ctx->mdctx);
79}
80
75struct ssh_digest_ctx * 81struct ssh_digest_ctx *
76ssh_digest_start(int alg) 82ssh_digest_start(int alg)
77{ 83{
@@ -90,6 +96,15 @@ ssh_digest_start(int alg)
90} 96}
91 97
92int 98int
99ssh_digest_copy_state(struct ssh_digest_ctx *from, struct ssh_digest_ctx *to)
100{
101 /* we have bcopy-style order while openssl has memcpy-style */
102 if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
103 return -1;
104 return 0;
105}
106
107int
93ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen) 108ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
94{ 109{
95 if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1) 110 if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
@@ -123,9 +138,11 @@ ssh_digest_final(struct ssh_digest_ctx *ctx, u_char *d, size_t dlen)
123void 138void
124ssh_digest_free(struct ssh_digest_ctx *ctx) 139ssh_digest_free(struct ssh_digest_ctx *ctx)
125{ 140{
126 EVP_MD_CTX_cleanup(&ctx->mdctx); 141 if (ctx != NULL) {
127 memset(ctx, 0, sizeof(*ctx)); 142 EVP_MD_CTX_cleanup(&ctx->mdctx);
128 free(ctx); 143 memset(ctx, 0, sizeof(*ctx));
144 free(ctx);
145 }
129} 146}
130 147
131int 148int