summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2018-02-17 14:55:31 +0000
committerjsing <>2018-02-17 14:55:31 +0000
commit3b7cdf9c768759bfba3e3afd3a234cc44ef4c7c1 (patch)
tree271d4b947a3db41c5ba023d0c3030ac88f62bafa /src
parentb32a945103cc4488bb232840251fc0a861837051 (diff)
downloadopenbsd-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 'src')
-rw-r--r--src/lib/libcrypto/Symbols.list3
-rw-r--r--src/lib/libcrypto/evp/digest.c59
-rw-r--r--src/lib/libcrypto/evp/evp.h8
3 files changed, 49 insertions, 21 deletions
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list
index 1da0493c73..d633575397 100644
--- a/src/lib/libcrypto/Symbols.list
+++ b/src/lib/libcrypto/Symbols.list
@@ -1274,8 +1274,11 @@ EVP_MD_CTX_copy_ex
1274EVP_MD_CTX_create 1274EVP_MD_CTX_create
1275EVP_MD_CTX_ctrl 1275EVP_MD_CTX_ctrl
1276EVP_MD_CTX_destroy 1276EVP_MD_CTX_destroy
1277EVP_MD_CTX_free
1277EVP_MD_CTX_init 1278EVP_MD_CTX_init
1278EVP_MD_CTX_md 1279EVP_MD_CTX_md
1280EVP_MD_CTX_new
1281EVP_MD_CTX_reset
1279EVP_MD_CTX_set_flags 1282EVP_MD_CTX_set_flags
1280EVP_MD_CTX_test_flags 1283EVP_MD_CTX_test_flags
1281EVP_MD_block_size 1284EVP_MD_block_size
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}
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index c8da89844d..148e15274f 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp.h,v 1.55 2018/02/17 13:47:36 tb Exp $ */ 1/* $OpenBSD: evp.h,v 1.56 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 *
@@ -535,15 +535,19 @@ int EVP_Cipher(EVP_CIPHER_CTX *c, unsigned char *out, const unsigned char *in,
535#define EVP_delete_digest_alias(alias) \ 535#define EVP_delete_digest_alias(alias) \
536 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); 536 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
537 537
538EVP_MD_CTX *EVP_MD_CTX_new(void);
539void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
538void EVP_MD_CTX_init(EVP_MD_CTX *ctx); 540void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
539int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); 541int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
540EVP_MD_CTX *EVP_MD_CTX_create(void); 542EVP_MD_CTX *EVP_MD_CTX_create(void);
541void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); 543void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
544int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
542int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); 545int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
543void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); 546void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
544void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); 547void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
545int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr); 548int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
546int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags); 549int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
550
547int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); 551int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
548int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 552int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
549int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s); 553int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);