summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2018-02-17 14:55:31 +0000
committerjsing <jsing@openbsd.org>2018-02-17 14:55:31 +0000
commitfcd881a003531dbaf7bd91a0ad45e0a940b45a90 (patch)
treecdcea1aa26e553c6e8d2697dd5831fdf7b8bf953
parentProvide HMAC_CTX_new(), HMAC_CTX_free(), HMAC_CTX_reset() and (diff)
downloadwireguard-openbsd-fcd881a003531dbaf7bd91a0ad45e0a940b45a90.tar.xz
wireguard-openbsd-fcd881a003531dbaf7bd91a0ad45e0a940b45a90.zip
Provide EVP_MD_CTX_new(), EVP_MD_CTX_free() and EVP_MD_CTX_reset().
-rw-r--r--lib/libcrypto/Symbols.list3
-rw-r--r--lib/libcrypto/evp/digest.c59
-rw-r--r--lib/libcrypto/evp/evp.h8
3 files changed, 49 insertions, 21 deletions
diff --git a/lib/libcrypto/Symbols.list b/lib/libcrypto/Symbols.list
index 1da0493c73e..d633575397f 100644
--- a/lib/libcrypto/Symbols.list
+++ b/lib/libcrypto/Symbols.list
@@ -1274,8 +1274,11 @@ EVP_MD_CTX_copy_ex
EVP_MD_CTX_create
EVP_MD_CTX_ctrl
EVP_MD_CTX_destroy
+EVP_MD_CTX_free
EVP_MD_CTX_init
EVP_MD_CTX_md
+EVP_MD_CTX_new
+EVP_MD_CTX_reset
EVP_MD_CTX_set_flags
EVP_MD_CTX_test_flags
EVP_MD_block_size
diff --git a/lib/libcrypto/evp/digest.c b/lib/libcrypto/evp/digest.c
index 7471c1e8225..b69a928ab82 100644
--- a/lib/libcrypto/evp/digest.c
+++ b/lib/libcrypto/evp/digest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: digest.c,v 1.28 2017/05/02 03:59:44 deraadt Exp $ */
+/* $OpenBSD: digest.c,v 1.29 2018/02/17 14:55:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -122,18 +122,6 @@
#include <openssl/engine.h>
#endif
-void
-EVP_MD_CTX_init(EVP_MD_CTX *ctx)
-{
- memset(ctx, 0, sizeof *ctx);
-}
-
-EVP_MD_CTX *
-EVP_MD_CTX_create(void)
-{
- return calloc(1, sizeof(EVP_MD_CTX));
-}
-
int
EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
{
@@ -339,20 +327,53 @@ EVP_Digest(const void *data, size_t count,
return ret;
}
+EVP_MD_CTX *
+EVP_MD_CTX_new(void)
+{
+ return calloc(1, sizeof(EVP_MD_CTX));
+}
+
+void
+EVP_MD_CTX_free(EVP_MD_CTX *ctx)
+{
+ if (ctx == NULL)
+ return;
+
+ EVP_MD_CTX_cleanup(ctx);
+
+ free(ctx);
+}
+
+void
+EVP_MD_CTX_init(EVP_MD_CTX *ctx)
+{
+ memset(ctx, 0, sizeof(*ctx));
+}
+
+int
+EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
+{
+ return EVP_MD_CTX_cleanup(ctx);
+}
+
+EVP_MD_CTX *
+EVP_MD_CTX_create(void)
+{
+ return EVP_MD_CTX_new();
+}
+
void
EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
{
- if (ctx) {
- EVP_MD_CTX_cleanup(ctx);
- free(ctx);
- }
+ EVP_MD_CTX_free(ctx);
}
/* This call frees resources associated with the context */
int
EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
{
- /* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
+ /*
+ * Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
* because sometimes only copies of the context are ever finalised.
*/
if (ctx->digest && ctx->digest->cleanup &&
@@ -368,7 +389,7 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
* functional reference we held for this reason. */
ENGINE_finish(ctx->engine);
#endif
- memset(ctx, 0, sizeof *ctx);
+ memset(ctx, 0, sizeof(*ctx));
return 1;
}
diff --git a/lib/libcrypto/evp/evp.h b/lib/libcrypto/evp/evp.h
index c8da89844d5..148e15274f3 100644
--- a/lib/libcrypto/evp/evp.h
+++ b/lib/libcrypto/evp/evp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: evp.h,v 1.55 2018/02/17 13:47:36 tb Exp $ */
+/* $OpenBSD: evp.h,v 1.56 2018/02/17 14:55:31 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -535,15 +535,19 @@ int EVP_Cipher(EVP_CIPHER_CTX *c, unsigned char *out, const unsigned char *in,
#define EVP_delete_digest_alias(alias) \
OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
+EVP_MD_CTX *EVP_MD_CTX_new(void);
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
-int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
EVP_MD_CTX *EVP_MD_CTX_create(void);
void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
+int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in);
void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags);
void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags);
int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int type, int arg, void *ptr);
int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags);
+
int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt);
int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *s);