diff options
author | jsing <> | 2018-02-17 14:55:31 +0000 |
---|---|---|
committer | jsing <> | 2018-02-17 14:55:31 +0000 |
commit | 3b7cdf9c768759bfba3e3afd3a234cc44ef4c7c1 (patch) | |
tree | 271d4b947a3db41c5ba023d0c3030ac88f62bafa /src/lib/libcrypto/evp/digest.c | |
parent | b32a945103cc4488bb232840251fc0a861837051 (diff) | |
download | openbsd-3b7cdf9c768759bfba3e3afd3a234cc44ef4c7c1.tar.gz openbsd-3b7cdf9c768759bfba3e3afd3a234cc44ef4c7c1.tar.bz2 openbsd-3b7cdf9c768759bfba3e3afd3a234cc44ef4c7c1.zip |
Provide EVP_MD_CTX_new(), EVP_MD_CTX_free() and EVP_MD_CTX_reset().
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 59 |
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 | ||
125 | void | ||
126 | EVP_MD_CTX_init(EVP_MD_CTX *ctx) | ||
127 | { | ||
128 | memset(ctx, 0, sizeof *ctx); | ||
129 | } | ||
130 | |||
131 | EVP_MD_CTX * | ||
132 | EVP_MD_CTX_create(void) | ||
133 | { | ||
134 | return calloc(1, sizeof(EVP_MD_CTX)); | ||
135 | } | ||
136 | |||
137 | int | 125 | int |
138 | EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) | 126 | EVP_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 | ||
330 | EVP_MD_CTX * | ||
331 | EVP_MD_CTX_new(void) | ||
332 | { | ||
333 | return calloc(1, sizeof(EVP_MD_CTX)); | ||
334 | } | ||
335 | |||
336 | void | ||
337 | EVP_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 | |||
347 | void | ||
348 | EVP_MD_CTX_init(EVP_MD_CTX *ctx) | ||
349 | { | ||
350 | memset(ctx, 0, sizeof(*ctx)); | ||
351 | } | ||
352 | |||
353 | int | ||
354 | EVP_MD_CTX_reset(EVP_MD_CTX *ctx) | ||
355 | { | ||
356 | return EVP_MD_CTX_cleanup(ctx); | ||
357 | } | ||
358 | |||
359 | EVP_MD_CTX * | ||
360 | EVP_MD_CTX_create(void) | ||
361 | { | ||
362 | return EVP_MD_CTX_new(); | ||
363 | } | ||
364 | |||
342 | void | 365 | void |
343 | EVP_MD_CTX_destroy(EVP_MD_CTX *ctx) | 366 | EVP_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 */ |
352 | int | 372 | int |
353 | EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | 373 | EVP_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 | } |