summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/digest.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/evp/digest.c59
1 files changed, 40 insertions, 19 deletions
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index 7471c1e822..b69a928ab8 100644
--- a/src/lib/libcrypto/evp/digest.c
+++ b/src/lib/libcrypto/evp/digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: digest.c,v 1.28 2017/05/02 03:59:44 deraadt Exp $ */ 1/* $OpenBSD: digest.c,v 1.29 2018/02/17 14:55:31 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -122,18 +122,6 @@
122#include <openssl/engine.h> 122#include <openssl/engine.h>
123#endif 123#endif
124 124
125void
126EVP_MD_CTX_init(EVP_MD_CTX *ctx)
127{
128 memset(ctx, 0, sizeof *ctx);
129}
130
131EVP_MD_CTX *
132EVP_MD_CTX_create(void)
133{
134 return calloc(1, sizeof(EVP_MD_CTX));
135}
136
137int 125int
138EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) 126EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
139{ 127{
@@ -339,20 +327,53 @@ EVP_Digest(const void *data, size_t count,
339 return ret; 327 return ret;
340} 328}
341 329
330EVP_MD_CTX *
331EVP_MD_CTX_new(void)
332{
333 return calloc(1, sizeof(EVP_MD_CTX));
334}
335
336void
337EVP_MD_CTX_free(EVP_MD_CTX *ctx)
338{
339 if (ctx == NULL)
340 return;
341
342 EVP_MD_CTX_cleanup(ctx);
343
344 free(ctx);
345}
346
347void
348EVP_MD_CTX_init(EVP_MD_CTX *ctx)
349{
350 memset(ctx, 0, sizeof(*ctx));
351}
352
353int
354EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
355{
356 return EVP_MD_CTX_cleanup(ctx);
357}
358
359EVP_MD_CTX *
360EVP_MD_CTX_create(void)
361{
362 return EVP_MD_CTX_new();
363}
364
342void 365void
343EVP_MD_CTX_destroy(EVP_MD_CTX *ctx) 366EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
344{ 367{
345 if (ctx) { 368 EVP_MD_CTX_free(ctx);
346 EVP_MD_CTX_cleanup(ctx);
347 free(ctx);
348 }
349} 369}
350 370
351/* This call frees resources associated with the context */ 371/* This call frees resources associated with the context */
352int 372int
353EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) 373EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
354{ 374{
355 /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final, 375 /*
376 * Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
356 * because sometimes only copies of the context are ever finalised. 377 * because sometimes only copies of the context are ever finalised.
357 */ 378 */
358 if (ctx->digest && ctx->digest->cleanup && 379 if (ctx->digest && ctx->digest->cleanup &&
@@ -368,7 +389,7 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
368 * functional reference we held for this reason. */ 389 * functional reference we held for this reason. */
369 ENGINE_finish(ctx->engine); 390 ENGINE_finish(ctx->engine);
370#endif 391#endif
371 memset(ctx, 0, sizeof *ctx); 392 memset(ctx, 0, sizeof(*ctx));
372 393
373 return 1; 394 return 1;
374} 395}