summaryrefslogtreecommitdiff
path: root/src/ne_openssl.c
diff options
context:
space:
mode:
authorjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2016-09-10 19:23:22 +0000
committerjoe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845>2016-09-10 19:23:22 +0000
commiteb90170613bec4856332c0e5e6113acfe4e7c17f (patch)
tree5657f18af811ec3cf1a39b6e6acfe99cb162dd5a /src/ne_openssl.c
parent93c4cb8ffab8bd76fa95545777d0bb1beae23e55 (diff)
downloadneon-eb90170613bec4856332c0e5e6113acfe4e7c17f.tar.gz
* src/ne_md5.c: Re-order, #ifdef mostly out for OpenSSL build.
* src/ne_openssl.c (init_md5_ctx, ne_md5_create_ctx, ne_md5_process_block, ne_md5_process_bytes, ne_md5_finish_ctx, ne_md5_dup_ctx, ne_md5_reset_ctx), ne_md5_destroy_ctx): Implement using EVP API. git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@1971 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845
Diffstat (limited to 'src/ne_openssl.c')
-rw-r--r--src/ne_openssl.c77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/ne_openssl.c b/src/ne_openssl.c
index b2bad39..41fdcae 100644
--- a/src/ne_openssl.c
+++ b/src/ne_openssl.c
@@ -35,6 +35,7 @@
#include <openssl/x509v3.h>
#include <openssl/rand.h>
#include <openssl/opensslv.h>
+#include <openssl/evp.h>
#ifdef NE_HAVE_TS_SSL
#include <stdlib.h> /* for abort() */
@@ -47,7 +48,7 @@
#include "ne_string.h"
#include "ne_session.h"
#include "ne_internal.h"
-
+#include "ne_md5.h"
#include "ne_private.h"
#include "ne_privssl.h"
@@ -1263,3 +1264,77 @@ void ne__ssl_exit(void)
}
#endif
}
+
+struct ne_md5_ctx {
+ EVP_MD_CTX ctx;
+};
+
+/* Returns zero on succes, non-zero on failure. */
+static int init_md5_ctx(struct ne_md5_ctx *ctx)
+{
+ EVP_MD_CTX_init(&ctx->ctx);
+
+ if (EVP_DigestInit_ex(&ctx->ctx, EVP_md5(), NULL) != 1) {
+ EVP_MD_CTX_cleanup(&ctx->ctx);
+ return 1;
+ }
+
+ return 0;
+}
+
+struct ne_md5_ctx *ne_md5_create_ctx(void)
+{
+#if 1
+ return NULL;
+#else
+ struct ne_md5_ctx *ctx = ne_malloc(sizeof *ctx);
+
+ if (init_md5_ctx(ctx)) {
+ ne_free(ctx);
+ return NULL;
+ }
+
+ return ctx;
+#endif
+}
+
+void ne_md5_process_block(const void *buffer, size_t len,
+ struct ne_md5_ctx *ctx)
+{
+ EVP_DigestUpdate(&ctx->ctx, buffer, len);
+}
+
+void ne_md5_process_bytes(const void *buffer, size_t len,
+ struct ne_md5_ctx *ctx)
+{
+ EVP_DigestUpdate(&ctx->ctx, buffer, len);
+}
+
+void *ne_md5_finish_ctx(struct ne_md5_ctx *ctx, void *resbuf)
+{
+ EVP_DigestFinal(&ctx->ctx, resbuf, NULL);
+
+ return resbuf;
+}
+
+struct ne_md5_ctx *ne_md5_dup_ctx(struct ne_md5_ctx *ctx)
+{
+ struct ne_md5_ctx *r = ne_md5_create_ctx();
+
+ EVP_MD_CTX_copy_ex(&r->ctx, &ctx->ctx);
+
+ return r;
+}
+
+void ne_md5_reset_ctx(struct ne_md5_ctx *ctx)
+{
+ EVP_MD_CTX_cleanup(&ctx->ctx);
+
+ init_md5_ctx(ctx);
+}
+
+void ne_md5_destroy_ctx(struct ne_md5_ctx *ctx)
+{
+ EVP_MD_CTX_cleanup(&ctx->ctx);
+ ne_free(ctx);
+}