diff options
author | joe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845> | 2006-03-01 17:28:58 +0000 |
---|---|---|
committer | joe <joe@61a7d7f5-40b7-0310-9c16-bb0ea8cb1845> | 2006-03-01 17:28:58 +0000 |
commit | 677665667f66074a7f83cbe044e3d09d2b858105 (patch) | |
tree | 909f8097e79c358d6d3b6b8e84d5946a8323af0f | |
parent | 6d343f91b80eaa97fee9a57564711a9a9a5b24df (diff) | |
download | neon-677665667f66074a7f83cbe044e3d09d2b858105.tar.gz |
Move to opaque MD5 context, avoiding exposure of md5_uint32 type:
* src/ne_md5.h: Make struct ne_md5_ctx opaque. (ne_md5_create_ctx,
ne_md5_reset_ctx, ne_md5_destroy_ctx): New prototypes.
(ne_md5_init_ctx): Removed prototype.
* src/ne_md5.c: Add struct ne_md5_ctx definition; use simpler
autoconf-based md5_uint32 definition.
(ne_md5_create_ctx, ne_md5_destroy_ctx, ne_md5_reset_ctx): New
functions.
(ne_md5_init_ctx): Make static.
* src/ne_auth.c (auth_session): Store a pointer to the MD5 context.
(clean_session): Destroy stored MD5 context if necessary.
(get_cnonce, digest_challenge, request_digest, verify_digest_response):
Adjust to use opaque context constructor/destructor.
* test/auth.c (make_digest): Adjust likewise.
* test/util-test.c (digest_md5, md5_alignment): Adjust likewise.
* config.hw.in: Define SIZEOF_INT, SIZEOF_LONG.
git-svn-id: http://svn.webdav.org/repos/projects/neon/trunk@970 61a7d7f5-40b7-0310-9c16-bb0ea8cb1845
-rw-r--r-- | config.hw.in | 6 | ||||
-rw-r--r-- | src/ne_auth.c | 140 | ||||
-rw-r--r-- | src/ne_md5.c | 71 | ||||
-rw-r--r-- | src/ne_md5.h | 75 | ||||
-rw-r--r-- | test/auth.c | 76 | ||||
-rw-r--r-- | test/util-tests.c | 20 |
6 files changed, 189 insertions, 199 deletions
diff --git a/config.hw.in b/config.hw.in index 5dff0dd..21ac0c4 100644 --- a/config.hw.in +++ b/config.hw.in @@ -1,7 +1,7 @@ /* -*- c -*- Win32 config.h Copyright (C) 1999-2000, Peter Boos <pedib@colorfullife.com> - Copyright (C) 2002-2005, Joe Orton <joe@manyfish.co.uk> + Copyright (C) 2002-2006, Joe Orton <joe@manyfish.co.uk> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -43,6 +43,10 @@ #define NE_FMT_SSIZE_T "d" #define NE_FMT_OFF_T "ld" +/* needs adjusting for Win64... */ +#define SIZEOF_INT 4 +#define SIZEOF_LONG 4 + /* Win32 uses a underscore, so we use a macro to eliminate that. */ #define snprintf _snprintf #define vsnprintf _vsnprintf diff --git a/src/ne_auth.c b/src/ne_auth.c index e3bd481..b9ef22f 100644 --- a/src/ne_auth.c +++ b/src/ne_auth.c @@ -183,7 +183,7 @@ typedef struct { /* Temporary store for half of the Request-Digest * (an optimisation - used in the response-digest calculation) */ - struct ne_md5_ctx stored_rdig; + struct ne_md5_ctx *stored_rdig; /* Details of server... needed to reconstruct absoluteURI's when * necessary */ @@ -248,6 +248,10 @@ static void clean_session(auth_session *sess) if (sess->realm) ne_free(sess->realm); sess->realm = sess->basic = sess->cnonce = sess->nonce = sess->opaque = NULL; + if (sess->stored_rdig) { + ne_md5_destroy_ctx(sess->stored_rdig); + sess->stored_rdig = NULL; + } #ifdef HAVE_GSSAPI { unsigned int major; @@ -272,13 +276,13 @@ static char *get_cnonce(void) { char ret[33]; unsigned char data[256]; - struct ne_md5_ctx hash; + struct ne_md5_ctx *hash; - ne_md5_init_ctx(&hash); + hash = ne_md5_create_ctx(); #ifdef HAVE_OPENSSL if (RAND_status() == 1 && RAND_pseudo_bytes(data, sizeof data) >= 0) - ne_md5_process_bytes(data, sizeof data, &hash); + ne_md5_process_bytes(data, sizeof data, hash); else { #endif /* Fallback sources of random data: all bad, but no good sources @@ -286,18 +290,18 @@ static char *get_cnonce(void) /* Uninitialized stack data; yes, happy valgrinders, this is * supposed to be here. */ - ne_md5_process_bytes(data, sizeof data, &hash); + ne_md5_process_bytes(data, sizeof data, hash); #ifdef HAVE_GETTIMEOFDAY { struct timeval tv; if (gettimeofday(&tv, NULL) == 0) - ne_md5_process_bytes(&tv, sizeof tv, &hash); + ne_md5_process_bytes(&tv, sizeof tv, hash); } #else /* HAVE_GETTIMEOFDAY */ { time_t t = time(NULL); - ne_md5_process_bytes(&t, sizeof t, &hash); + ne_md5_process_bytes(&t, sizeof t, hash); } #endif { @@ -306,14 +310,17 @@ static char *get_cnonce(void) #else pid_t pid = getpid(); #endif - ne_md5_process_bytes(&pid, sizeof pid, &hash); + ne_md5_process_bytes(&pid, sizeof pid, hash); } #ifdef HAVE_OPENSSL } #endif - - return ne_strdup(ne_md5_finish_ascii(&hash, ret)); + + ne_md5_finish_ascii(hash, ret); + ne_md5_destroy_ctx(hash); + + return ne_strdup(ret); } static int get_credentials(auth_session *sess, int attempt, @@ -582,7 +589,6 @@ static int sspi_challenge(auth_session *sess, int attempt, static int digest_challenge(auth_session *sess, int attempt, struct auth_challenge *parms) { - struct ne_md5_ctx tmp; char password[NE_ABUFSIZ]; if (parms->alg == auth_alg_unknown) { @@ -633,36 +639,40 @@ static int digest_challenge(auth_session *sess, int attempt, } if (!parms->stale) { + struct ne_md5_ctx *tmp; + /* Calculate H(A1). * tmp = H(unq(username-value) ":" unq(realm-value) ":" passwd) */ - ne_md5_init_ctx(&tmp); - ne_md5_process_bytes(sess->username, strlen(sess->username), &tmp); - ne_md5_process_bytes(":", 1, &tmp); - ne_md5_process_bytes(sess->realm, strlen(sess->realm), &tmp); - ne_md5_process_bytes(":", 1, &tmp); - ne_md5_process_bytes(password, strlen(password), &tmp); + tmp = ne_md5_create_ctx(); + ne_md5_process_bytes(sess->username, strlen(sess->username), tmp); + ne_md5_process_bytes(":", 1, tmp); + ne_md5_process_bytes(sess->realm, strlen(sess->realm), tmp); + ne_md5_process_bytes(":", 1, tmp); + ne_md5_process_bytes(password, strlen(password), tmp); memset(password, 0, sizeof password); /* done with that. */ if (sess->alg == auth_alg_md5_sess) { - struct ne_md5_ctx a1; + struct ne_md5_ctx *a1; char tmp_md5_ascii[33]; /* Now we calculate the SESSION H(A1) * A1 = H(...above...) ":" unq(nonce-value) ":" unq(cnonce-value) */ - ne_md5_finish_ascii(&tmp, tmp_md5_ascii); - ne_md5_init_ctx(&a1); - ne_md5_process_bytes(tmp_md5_ascii, 32, &a1); - ne_md5_process_bytes(":", 1, &a1); - ne_md5_process_bytes(sess->nonce, strlen(sess->nonce), &a1); - ne_md5_process_bytes(":", 1, &a1); - ne_md5_process_bytes(sess->cnonce, strlen(sess->cnonce), &a1); - ne_md5_finish_ascii(&a1, sess->h_a1); + ne_md5_finish_ascii(tmp, tmp_md5_ascii); + a1 = ne_md5_create_ctx(); + ne_md5_process_bytes(tmp_md5_ascii, 32, a1); + ne_md5_process_bytes(":", 1, a1); + ne_md5_process_bytes(sess->nonce, strlen(sess->nonce), a1); + ne_md5_process_bytes(":", 1, a1); + ne_md5_process_bytes(sess->cnonce, strlen(sess->cnonce), a1); + ne_md5_finish_ascii(a1, sess->h_a1); + ne_md5_destroy_ctx(a1); NE_DEBUG(NE_DBG_HTTPAUTH, "auth: Session H(A1) is [%s]\n", sess->h_a1); } else { - ne_md5_finish_ascii(&tmp, sess->h_a1); + ne_md5_finish_ascii(tmp, sess->h_a1); NE_DEBUG(NE_DBG_HTTPAUTH, "auth: H(A1) is [%s]\n", sess->h_a1); } + ne_md5_destroy_ctx(tmp); } @@ -675,7 +685,7 @@ static int digest_challenge(auth_session *sess, int attempt, * session. */ static char *request_digest(auth_session *sess, struct auth_request *req) { - struct ne_md5_ctx a2, rdig; + struct ne_md5_ctx *a2, *rdig; char a2_md5_ascii[33], rdig_md5_ascii[33]; char nc_value[9] = {0}; const char *qop_value = "auth"; /* qop-value */ @@ -688,46 +698,45 @@ static char *request_digest(auth_session *sess, struct auth_request *req) } /* Calculate H(A2). */ - ne_md5_init_ctx(&a2); - ne_md5_process_bytes(req->method, strlen(req->method), &a2); - ne_md5_process_bytes(":", 1, &a2); - ne_md5_process_bytes(req->uri, strlen(req->uri), &a2); - ne_md5_finish_ascii(&a2, a2_md5_ascii); + a2 = ne_md5_create_ctx(); + ne_md5_process_bytes(req->method, strlen(req->method), a2); + ne_md5_process_bytes(":", 1, a2); + ne_md5_process_bytes(req->uri, strlen(req->uri), a2); + ne_md5_finish_ascii(a2, a2_md5_ascii); + ne_md5_destroy_ctx(a2); NE_DEBUG(NE_DBG_HTTPAUTH, "auth: H(A2): %s\n", a2_md5_ascii); /* Now, calculation of the Request-Digest. * The first section is the regardless of qop value * H(A1) ":" unq(nonce-value) ":" */ - ne_md5_init_ctx(&rdig); + rdig = ne_md5_create_ctx(); /* Use the calculated H(A1) */ - ne_md5_process_bytes(sess->h_a1, 32, &rdig); + ne_md5_process_bytes(sess->h_a1, 32, rdig); - ne_md5_process_bytes(":", 1, &rdig); - ne_md5_process_bytes(sess->nonce, strlen(sess->nonce), &rdig); - ne_md5_process_bytes(":", 1, &rdig); + ne_md5_process_bytes(":", 1, rdig); + ne_md5_process_bytes(sess->nonce, strlen(sess->nonce), rdig); + ne_md5_process_bytes(":", 1, rdig); if (sess->qop != auth_qop_none) { /* Add on: * nc-value ":" unq(cnonce-value) ":" unq(qop-value) ":" */ - ne_md5_process_bytes(nc_value, 8, &rdig); - ne_md5_process_bytes(":", 1, &rdig); - ne_md5_process_bytes(sess->cnonce, strlen(sess->cnonce), &rdig); - ne_md5_process_bytes(":", 1, &rdig); + ne_md5_process_bytes(nc_value, 8, rdig); + ne_md5_process_bytes(":", 1, rdig); + ne_md5_process_bytes(sess->cnonce, strlen(sess->cnonce), rdig); + ne_md5_process_bytes(":", 1, rdig); /* Store a copy of this structure (see note below) */ - sess->stored_rdig = rdig; - ne_md5_process_bytes(qop_value, strlen(qop_value), &rdig); - ne_md5_process_bytes(":", 1, &rdig); - } else { - /* Store a copy of this structure... we do this because the - * calculation of the rspauth= field in the Auth-Info header - * is the same as this digest, up to this point. */ - sess->stored_rdig = rdig; + if (sess->stored_rdig) ne_md5_destroy_ctx(sess->stored_rdig); + sess->stored_rdig = ne_md5_dup_ctx(rdig); + ne_md5_process_bytes(qop_value, strlen(qop_value), rdig); + ne_md5_process_bytes(":", 1, rdig); } + /* And finally, H(A2) */ - ne_md5_process_bytes(a2_md5_ascii, 32, &rdig); - ne_md5_finish_ascii(&rdig, rdig_md5_ascii); - + ne_md5_process_bytes(a2_md5_ascii, 32, rdig); + ne_md5_finish_ascii(rdig, rdig_md5_ascii); + ne_md5_destroy_ctx(rdig); + ret = ne_buffer_create(); ne_buffer_concat(ret, @@ -890,29 +899,32 @@ static int verify_digest_response(struct auth_request *req, auth_session *sess, } else { /* Verify the response-digest field */ - struct ne_md5_ctx a2; + struct ne_md5_ctx *a2; char a2_md5_ascii[33], rdig_md5_ascii[33]; /* Modified H(A2): */ - ne_md5_init_ctx(&a2); - ne_md5_process_bytes(":", 1, &a2); - ne_md5_process_bytes(req->uri, strlen(req->uri), &a2); - ne_md5_finish_ascii(&a2, a2_md5_ascii); - + a2 = ne_md5_create_ctx(); + ne_md5_process_bytes(":", 1, a2); + ne_md5_process_bytes(req->uri, strlen(req->uri), a2); + ne_md5_finish_ascii(a2, a2_md5_ascii); + ne_md5_destroy_ctx(a2); + /* sess->stored_rdig contains digest-so-far of: * H(A1) ":" unq(nonce-value) */ /* Add in qop-value */ ne_md5_process_bytes(qop_value, strlen(qop_value), - &sess->stored_rdig); - ne_md5_process_bytes(":", 1, &sess->stored_rdig); + sess->stored_rdig); + ne_md5_process_bytes(":", 1, sess->stored_rdig); /* Digest ":" H(A2) */ - ne_md5_process_bytes(a2_md5_ascii, 32, &sess->stored_rdig); + ne_md5_process_bytes(a2_md5_ascii, 32, sess->stored_rdig); /* All done */ - ne_md5_finish_ascii(&sess->stored_rdig, rdig_md5_ascii); - + ne_md5_finish_ascii(sess->stored_rdig, rdig_md5_ascii); + ne_md5_destroy_ctx(sess->stored_rdig); + sess->stored_rdig = NULL; + /* And... do they match? */ ret = ne_strcasecmp(rdig_md5_ascii, rspauth) == 0 ? NE_OK : NE_ERROR; diff --git a/src/ne_md5.c b/src/ne_md5.c index aab2a3f..42877af 100644 --- a/src/ne_md5.c +++ b/src/ne_md5.c @@ -24,29 +24,15 @@ #include <sys/types.h> -#if STDC_HEADERS || defined _LIBC -# include <stdlib.h> -# include <string.h> -#else -#ifdef HAVE_STRING_H +#include <stdlib.h> #include <string.h> -#endif -# ifndef HAVE_MEMCPY -# define memcpy(d, s, n) bcopy ((s), (d), (n)) -# endif +#ifdef HAVE_LIMITS_H +# include <limits.h> #endif #include "ne_md5.h" #include "ne_string.h" /* for NE_ASC2HEX */ -#ifdef _LIBC -# include <endian.h> -# if __BYTE_ORDER == __BIG_ENDIAN -# define WORDS_BIGENDIAN 1 -# endif -#endif - -#define md5_init_ctx ne_md5_init_ctx #define md5_process_block ne_md5_process_block #define md5_process_bytes ne_md5_process_bytes #define md5_finish_ctx ne_md5_finish_ctx @@ -61,6 +47,26 @@ # define SWAP(n) (n) #endif +#if SIZEOF_INT == 4 +typedef unsigned int md5_uint32; +#elif SIZEOF_LONG == 4 +typedef unsigned long md5_uint32; +#else +# error "Cannot determine unsigned 32-bit data type." +#endif + +/* Structure to save state of computation between the single steps. */ +struct md5_ctx +{ + md5_uint32 A; + md5_uint32 B; + md5_uint32 C; + md5_uint32 D; + + md5_uint32 total[2]; + md5_uint32 buflen; + char buffer[128]; +}; /* This array contains the bytes used to pad the buffer to the next 64-byte boundary. (RFC 1321, 3.1: Step 1) */ @@ -69,9 +75,8 @@ static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; /* Initialize structure containing state of computation. (RFC 1321, 3.3: Step 3) */ -void -md5_init_ctx (ctx) - struct md5_ctx *ctx; +static void +md5_init_ctx (struct md5_ctx *ctx) { ctx->A = 0x67452301; ctx->B = 0xefcdab89; @@ -82,6 +87,32 @@ md5_init_ctx (ctx) ctx->buflen = 0; } +struct ne_md5_ctx * +ne_md5_create_ctx(void) +{ + struct md5_ctx *ctx = ne_malloc(sizeof *ctx); + md5_init_ctx(ctx); + return ctx; +} + +extern void +ne_md5_reset_ctx(struct ne_md5_ctx *ctx) +{ + md5_init_ctx(ctx); +} + +struct ne_md5_ctx * +ne_md5_dup_ctx(struct ne_md5_ctx *ctx) +{ + return memcpy(ne_malloc(sizeof *ctx), ctx, sizeof *ctx); +} + +void +ne_md5_destroy_ctx(struct ne_md5_ctx *ctx) +{ + ne_free(ctx); +} + /* Put result from CTX in first 16 bytes following RESBUF. The result must be in little endian byte order. diff --git a/src/ne_md5.h b/src/ne_md5.h index 83be457..13f21f6 100644 --- a/src/ne_md5.h +++ b/src/ne_md5.h @@ -1,5 +1,6 @@ /* Declaration of functions and data types used for MD5 sum computing library functions. + Copyright (C) 2006, Joe Orton <joe@manyfish.co.uk> Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -23,74 +24,14 @@ #include <stdio.h> -#if defined HAVE_LIMITS_H || _LIBC -# include <limits.h> -#endif - -/* The following contortions are an attempt to use the C preprocessor - to determine an unsigned integral type that is 32 bits wide. An - alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but - doing that would require that the configure script compile and *run* - the resulting executable. Locally running cross-compiled executables - is usually not possible. */ - -#ifdef _LIBC -# include <sys/types.h> -typedef u_int32_t md5_uint32; -#else -# if defined __STDC__ && __STDC__ -# define UINT_MAX_32_BITS 4294967295U -# else -# define UINT_MAX_32_BITS 0xFFFFFFFF -# endif - -/* If UINT_MAX isn't defined, assume it's a 32-bit type. - This should be valid for all systems GNU cares about because - that doesn't include 16-bit systems, and only modern systems - (that certainly have <limits.h>) have 64+-bit integral types. */ - -# ifndef UINT_MAX -# define UINT_MAX UINT_MAX_32_BITS -# endif - -# if UINT_MAX == UINT_MAX_32_BITS - typedef unsigned int md5_uint32; -# else -# if USHRT_MAX == UINT_MAX_32_BITS - typedef unsigned short md5_uint32; -# else -# if ULONG_MAX == UINT_MAX_32_BITS - typedef unsigned long md5_uint32; -# else - /* The following line is intended to evoke an error. - Using #error is not portable enough. */ - "Cannot determine unsigned 32-bit data type." -# endif -# endif -# endif -#endif - -/* Structure to save state of computation between the single steps. */ -struct ne_md5_ctx -{ - md5_uint32 A; - md5_uint32 B; - md5_uint32 C; - md5_uint32 D; - - md5_uint32 total[2]; - md5_uint32 buflen; - char buffer[128]; -}; - /* * The following three functions are build up the low level used in * the functions `md5_stream' and `md5_buffer'. */ +struct ne_md5_ctx; -/* Initialize structure containing state of computation. - (RFC 1321, 3.3: Step 3) */ -extern void ne_md5_init_ctx(struct ne_md5_ctx *ctx); +/* Create structure containing state of computation. */ +extern struct ne_md5_ctx *ne_md5_create_ctx(void); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes @@ -124,6 +65,14 @@ extern void *ne_md5_finish_ctx(struct ne_md5_ctx *ctx, void *resbuf); aligned for a 32 bits value. */ extern void *ne_md5_read_ctx(const struct ne_md5_ctx *ctx, void *resbuf); +/* Take a copy of the state structure. */ +extern struct ne_md5_ctx *ne_md5_dup_ctx(struct ne_md5_ctx *ctx); + +/* Re-initialize the context structure. */ +extern void ne_md5_reset_ctx(struct ne_md5_ctx *ctx); + +/* Destroy the context structure. */ +extern void ne_md5_destroy_ctx(struct ne_md5_ctx *ctx); /* Compute MD5 message digest for bytes read from STREAM. The resulting message digest number will be written into the 16 bytes diff --git a/test/auth.c b/test/auth.c index 7fd404a..02953bd 100644 --- a/test/auth.c +++ b/test/auth.c @@ -401,63 +401,55 @@ struct digest_state { static void make_digest(struct digest_state *state, struct digest_parms *parms, int auth_info, char digest[33]) { - struct ne_md5_ctx ctx; - md5_uint32 result[4]; + struct ne_md5_ctx *ctx; char h_a1[33], h_a2[33]; /* H(A1) */ - ne_md5_init_ctx(&ctx); - ne_md5_process_bytes(state->username, strlen(state->username), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->realm, strlen(state->realm), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->password, strlen(state->password), &ctx); - ne_md5_finish_ctx(&ctx, result); - - ne_md5_to_ascii((void *)result, h_a1); + ctx = ne_md5_create_ctx(); + ne_md5_process_bytes(state->username, strlen(state->username), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->realm, strlen(state->realm), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->password, strlen(state->password), ctx); + ne_md5_finish_ascii(ctx, h_a1); if (parms->md5_sess) { - ne_md5_init_ctx(&ctx); - ne_md5_process_bytes(h_a1, 32, &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->nonce, strlen(state->nonce), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->cnonce, strlen(state->cnonce), &ctx); - ne_md5_finish_ctx(&ctx, result); - - ne_md5_to_ascii((void *)result, h_a1); + ne_md5_reset_ctx(ctx); + ne_md5_process_bytes(h_a1, 32, ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->nonce, strlen(state->nonce), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->cnonce, strlen(state->cnonce), ctx); + ne_md5_finish_ascii(ctx, h_a1); } /* H(A2) */ - ne_md5_init_ctx(&ctx); + ne_md5_reset_ctx(ctx); if (!auth_info) - ne_md5_process_bytes(state->method, strlen(state->method), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->uri, strlen(state->uri), &ctx); - ne_md5_finish_ctx(&ctx, result); - - ne_md5_to_ascii((void *)result, h_a2); + ne_md5_process_bytes(state->method, strlen(state->method), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->uri, strlen(state->uri), ctx); + ne_md5_finish_ascii(ctx, h_a2); /* request-digest */ - ne_md5_init_ctx(&ctx); - ne_md5_process_bytes(h_a1, strlen(h_a1), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->nonce, strlen(state->nonce), &ctx); - ne_md5_process_bytes(":", 1, &ctx); + ne_md5_reset_ctx(ctx); + ne_md5_process_bytes(h_a1, strlen(h_a1), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->nonce, strlen(state->nonce), ctx); + ne_md5_process_bytes(":", 1, ctx); if (parms->rfc2617) { - ne_md5_process_bytes(state->ncval, strlen(state->ncval), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->cnonce, strlen(state->cnonce), &ctx); - ne_md5_process_bytes(":", 1, &ctx); - ne_md5_process_bytes(state->qop, strlen(state->qop), &ctx); - ne_md5_process_bytes(":", 1, &ctx); + ne_md5_process_bytes(state->ncval, strlen(state->ncval), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->cnonce, strlen(state->cnonce), ctx); + ne_md5_process_bytes(":", 1, ctx); + ne_md5_process_bytes(state->qop, strlen(state->qop), ctx); + ne_md5_process_bytes(":", 1, ctx); } - ne_md5_process_bytes(h_a2, strlen(h_a2), &ctx); - ne_md5_finish_ctx(&ctx, result); - - ne_md5_to_ascii((void *)result, digest); + ne_md5_process_bytes(h_a2, strlen(h_a2), ctx); + ne_md5_finish_ascii(ctx, digest); + ne_md5_destroy_ctx(ctx); } /* Verify that the response-digest matches expected state. */ diff --git a/test/util-tests.c b/test/util-tests.c index b255b3b..1a16cff 100644 --- a/test/util-tests.c +++ b/test/util-tests.c @@ -103,19 +103,20 @@ static int status_lines(void) /* Write MD5 of 'len' bytes of 'str' to 'digest' */ static unsigned char *digest_md5(const char *data, size_t len, unsigned char digest[16]) { - struct ne_md5_ctx ctx; + struct ne_md5_ctx *ctx; #define CHUNK 100 - ne_md5_init_ctx(&ctx); + ctx = ne_md5_create_ctx(); /* exercise the buffering interface */ while (len > CHUNK) { - ne_md5_process_bytes(data, CHUNK, &ctx); + ne_md5_process_bytes(data, CHUNK, ctx); len -= CHUNK; data += CHUNK; } - ne_md5_process_bytes(data, len, &ctx); - ne_md5_finish_ctx(&ctx, digest); - + ne_md5_process_bytes(data, len, ctx); + ne_md5_finish_ctx(ctx, digest); + ne_md5_destroy_ctx(ctx); + return digest; } @@ -146,13 +147,14 @@ static int md5(void) static int md5_alignment(void) { char *bb = ne_malloc(66); - struct ne_md5_ctx ctx; + struct ne_md5_ctx *ctx; /* regression test for a bug in md5.c in <0.15.0 on SPARC, where * the process_bytes function would SIGBUS if the buffer argument * isn't 32-bit aligned. Won't trigger on x86 though. */ - ne_md5_init_ctx(&ctx); - ne_md5_process_bytes(bb + 1, 65, &ctx); + ctx = ne_md5_create_ctx(); + ne_md5_process_bytes(bb + 1, 65, ctx); + ne_md5_destroy_ctx(ctx); ne_free(bb); return OK; |